<commit_before>port module Main exposing (..)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Dict exposing (Dict)
import Json.Decode as Json
import Time exposing (Time)
import Helpers exposing (Helpers, Locale)
import Model exposing (Status(..), Platform(..))
import Help
import Icons
import Wizard
import Address
import Folder
import Dashboard
import Settings
import Updater
import StatusBar
import Page.UserActionRequired


main : Program Flags Model Msg
main =
    Html.programWithFlags
        { init = init
        , update = update
        , view = view
        , subscriptions = subscriptions
        }



-- MODEL
-- type Tab
--     = DashboardPage
--     | SettingsPage


type Page
    = WizardPage
    | DashboardPage
    | SettingsPage
    | UpdaterPage
    | HelpPage
    | UserActionRequiredPage UserActionRequiredError


type alias Model =
    { localeIdentifier : String
    , locales : Dict String Locale
    , page : Page
    , wizard : Wizard.Model
    , dashboard : Dashboard.Model
    , settings : Settings.Model
    , updater : Updater.Model
    , status : Status
    , help : Help.Model
    , platform : Platform
    }


type alias Flags =
    { page : String
    , folder : String
    , locale : String
    , locales : Json.Value
    , platform : String
    , version : String
    }


init : Flags -> ( Model, Cmd Msg )
init flags =
    let
        locales =
            case
                Json.decodeValue (Json.dict (Json.dict Json.string)) flags.locales
            of
                Ok value ->
                    value

                Err _ ->
                    Dict.empty

        page =
            case flags.page of
                "onboarding" ->
                    WizardPage

                "help" ->
                    HelpPage

                "dashboard" ->
                    DashboardPage

                "settings" ->
                    SettingsPage

                "updater" ->
                    UpdaterPage

                -- Temporarily use the MsgMechanism to
                -- get to the 2Panes page.
                _ ->
                    WizardPage

        platform =
            case flags.platform of
                "win32" ->
                    Windows

                "darwin" ->
                    Darwin

                _ ->
                    Linux

        model =
            { localeIdentifier = flags.locale
            , wizard = Wizard.init flags.folder flags.platform
            , dashboard = Dashboard.init
            , settings = Settings.init flags.version
            , updater = Updater.init flags.version
            , status = Starting
            , platform = platform
            , help = Help.init
            , locales = locales
            , page = page
            }
    in
        ( model, Cmd.none )



-- UPDATE


type Msg
    = NoOp
    | WizardMsg Wizard.Msg
    | SyncStart ( String, String )
    | Updated
    | StartSyncing Int
    | StartBuffering
    | StartSquashPrepMerging
    | GoOffline
    | SetError String
    | DashboardMsg Dashboard.Msg
    | SettingsMsg Settings.Msg
    | GoToCozy
    | GoToFolder
    | GoToTab Page
    | GoToStrTab String
    | HelpMsg Help.Msg
    | UpdaterMsg Updater.Msg


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        WizardMsg subMsg ->
            let
                ( wizard_, cmd ) =
                    Wizard.update subMsg model.wizard
            in
                ( { model | wizard = wizard_ }, Cmd.map WizardMsg cmd )

        SyncStart info ->
            let
                ( settings, _ ) =
                    Settings.update (Settings.FillAddressAndDevice info) model.settings
            in
                ( { model | page = (DashboardPage), settings = settings }, Cmd.none )

        Updated ->
            ( { model | status = UpToDate }, Cmd.none )

        StartSyncing n ->
            ( { model | status = Syncing n }, Cmd.none )

        StartBuffering ->
            ( { model | status = Buffering }, Cmd.none )

        StartSquashPrepMerging ->
            ( { model | status = SquashPrepMerging }, Cmd.none )

        GoOffline ->
            ( { model | status = Offline }, Cmd.none )

        SetError error ->
            ( { model | status = Error error }, Cmd.none )

        GoToCozy -><commit_msg>gui/elm: Introduce & update according to UserActionRequired Msg<commit_after>port module Main exposing (..)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Dict exposing (Dict)
import Json.Decode as Json
import Time exposing (Time)
import Helpers exposing (Helpers, Locale)
import Model exposing (..)
import Help
import Icons
import Wizard
import Address
import Folder
import Dashboard
import Settings
import Updater
import StatusBar
import Page.UserActionRequired


main : Program Flags Model Msg
main =
    Html.programWithFlags
        { init = init
        , update = update
        , view = view
        , subscriptions = subscriptions
        }



-- MODEL
-- type Tab
--     = DashboardPage
--     | SettingsPage


type Page
    = WizardPage
    | DashboardPage
    | SettingsPage
    | UpdaterPage
    | HelpPage
    | UserActionRequiredPage UserActionRequiredError


type alias Model =
    { localeIdentifier : String
    , locales : Dict String Locale
    , page : Page
    , wizard : Wizard.Model
    , dashboard : Dashboard.Model
    , settings : Settings.Model
    , updater : Updater.Model
    , status : Status
    , help : Help.Model
    , platform : Platform
    }


type alias Flags =
    { page : String
    , folder : String
    , locale : String
    , locales : Json.Value
    , platform : String
    , version : String
    }


init : Flags -> ( Model, Cmd Msg )
init flags =
    let
        locales =
            case
                Json.decodeValue (Json.dict (Json.dict Json.string)) flags.locales
            of
                Ok value ->
                    value

                Err _ ->
                    Dict.empty

        page =
            case flags.page of
                "onboarding" ->
                    WizardPage

                "help" ->
                    HelpPage

                "dashboard" ->
                    DashboardPage

                "settings" ->
                    SettingsPage

                "updater" ->
                    UpdaterPage

                -- Temporarily use the MsgMechanism to
                -- get to the 2Panes page.
                _ ->
                    WizardPage

        platform =
            case flags.platform of
                "win32" ->
                    Windows

                "darwin" ->
                    Darwin

                _ ->
                    Linux

        model =
            { localeIdentifier = flags.locale
            , wizard = Wizard.init flags.folder flags.platform
            , dashboard = Dashboard.init
            , settings = Settings.init flags.version
            , updater = Updater.init flags.version
            , status = Starting
            , platform = platform
            , help = Help.init
            , locales = locales
            , page = page
            }
    in
        ( model, Cmd.none )



-- UPDATE


type Msg
    = NoOp
    | WizardMsg Wizard.Msg
    | SyncStart ( String, String )
    | Updated
    | StartSyncing Int
    | StartBuffering
    | StartSquashPrepMerging
    | GoOffline
    | UserActionRequired UserActionRequiredError
    | SetError String
    | DashboardMsg Dashboard.Msg
    | SettingsMsg Settings.Msg
    | GoToCozy
    | GoToFolder
    | GoToTab Page
    | GoToStrTab String
    | HelpMsg Help.Msg
    | UpdaterMsg Updater.Msg


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        WizardMsg subMsg ->
            let
                ( wizard_, cmd ) =
                    Wizard.update subMsg model.wizard
            in
                ( { model | wizard = wizard_ }, Cmd.map WizardMsg cmd )

        SyncStart info ->
            let
                ( settings, _ ) =
                    Settings.update (Settings.FillAddressAndDevice info) model.settings
            in
                ( { model | page = (DashboardPage), settings = settings }, Cmd.none )

        Updated ->
            ( { model | status = UpToDate }, Cmd.none )

        StartSyncing n ->
            ( { model | status = Syncing n }, Cmd.none )

        StartBuffering ->
            ( { model | status = Buffering }, Cmd.none )

        StartSquashPrepMerging ->
            ( { model | status = SquashPrepMerging }, Cmd.none )

        GoOffline ->
            ( { model | status = Offline }, Cmd.none )

        UserActionRequired error ->
            ( { model
                | status = Model.UserActionRequired
                , page = UserActionRequiredPage error
              }
            , Cmd.none
            )

        SetError error ->
            ( { model | status = Error error }, Cmd.none )

        GoToCozy ->
{'fraction_non_alphanumeric': 0.07771277182912022, 'fraction_numerical': 0.0006623247599072745, 'mean_word_length': 1.3779527559055118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7439034', 'n_tokens_mistral': 2506, 'n_tokens_neox': 2335, 'n_words': 645}