<commit_before>module Main exposing (..)

import Html exposing (..)
import Dict exposing (Dict)
import Json.Decode as Json
import Time exposing (Time)
import Locale exposing (Helpers, Locale)
import Model exposing (..)
import Ports
import Window.Tray as Tray
import Window.Tray.Dashboard as Dashboard
import Window.Tray.Settings as Settings
import Window.Help as Help
import Window.Updater as Updater
import Window.Wizard as Wizard
import Window.Wizard.Address as Address
import Window.Wizard.Folder as Folder


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


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



-- MODEL


type alias Model =
    { localeIdentifier : String
    , locales : Dict String Locale
    , window : Window

    -- TODO: Attach submodels to windows
    , wizard : Wizard.Model
    , tray : Tray.Model
    , updater : Updater.Model
    , help : Help.Model
    }


type Window
    = HelpWindow
    | TrayWindow
    | UpdaterWindow
    | WizardWindow


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

        window =
            case flags.page of
                "onboarding" ->
                    WizardWindow

                "help" ->
                    HelpWindow

                "dashboard" ->
                    TrayWindow

                "settings" ->
                    TrayWindow

                "updater" ->
                    UpdaterWindow

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

        trayPage =
            case flags.page of
                "settings" ->
                    Tray.SettingsPage

                _ ->
                    Tray.DashboardPage

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

                "darwin" ->
                    Darwin

                _ ->
                    Linux

        model =
            { localeIdentifier = flags.locale
            , locales = locales
            , window = window

            -- TODO: Attach submodels to windows
            , wizard = Wizard.init flags.folder flags.platform
            , tray = Tray.init trayPage flags.version platform
            , updater = Updater.init flags.version
            , help = Help.init
            }
    in
        ( model, Cmd.none )



-- UPDATE


type Msg
    = NoOp
    | WizardMsg Wizard.Msg
    | TrayMsg Tray.Msg
    | HelpMsg Help.Msg
    | UpdaterMsg Updater.Msg


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        NoOp ->
            ( model, Cmd.none )

        WizardMsg subMsg ->
            let
                ( wizard_, cmd ) =
                    Wizard.update subMsg model.wizard
            in
                ( { model | wizard = wizard_ }, Cmd.map WizardMsg cmd )

        TrayMsg subMsg ->
            let
                ( tray, cmd ) =
                    Tray.update subMsg model.tray
            in
                ( { model | tray = tray }
                , Cmd.map TrayMsg cmd
                )

        HelpMsg subMsg -><commit_msg>gui/elm: Get rid of Main.NoOp message<commit_after>module Main exposing (..)

import Html exposing (..)
import Dict exposing (Dict)
import Json.Decode as Json
import Time exposing (Time)
import Locale exposing (Helpers, Locale)
import Model exposing (..)
import Ports
import Window.Tray as Tray
import Window.Tray.Dashboard as Dashboard
import Window.Tray.Settings as Settings
import Window.Help as Help
import Window.Updater as Updater
import Window.Wizard as Wizard
import Window.Wizard.Address as Address
import Window.Wizard.Folder as Folder


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


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



-- MODEL


type alias Model =
    { localeIdentifier : String
    , locales : Dict String Locale
    , window : Window

    -- TODO: Attach submodels to windows
    , wizard : Wizard.Model
    , tray : Tray.Model
    , updater : Updater.Model
    , help : Help.Model
    }


type Window
    = HelpWindow
    | TrayWindow
    | UpdaterWindow
    | WizardWindow


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

        window =
            case flags.page of
                "onboarding" ->
                    WizardWindow

                "help" ->
                    HelpWindow

                "dashboard" ->
                    TrayWindow

                "settings" ->
                    TrayWindow

                "updater" ->
                    UpdaterWindow

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

        trayPage =
            case flags.page of
                "settings" ->
                    Tray.SettingsPage

                _ ->
                    Tray.DashboardPage

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

                "darwin" ->
                    Darwin

                _ ->
                    Linux

        model =
            { localeIdentifier = flags.locale
            , locales = locales
            , window = window

            -- TODO: Attach submodels to windows
            , wizard = Wizard.init flags.folder flags.platform
            , tray = Tray.init trayPage flags.version platform
            , updater = Updater.init flags.version
            , help = Help.init
            }
    in
        ( model, Cmd.none )



-- UPDATE


type Msg
    = WizardMsg Wizard.Msg
    | TrayMsg Tray.Msg
    | 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 )

        TrayMsg subMsg ->
            let
                ( tray, cmd ) =
                    Tray.update subMsg model.tray
            in
                ( { model | tray = tray }
                , Cmd.map TrayMsg cmd
                )

        HelpMsg subMsg ->
{'fraction_non_alphanumeric': 0.07034062586541125, 'fraction_numerical': 0.0008307947936859596, 'mean_word_length': 1.2081932130846835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, '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': '7010174', 'n_tokens_mistral': 2003, 'n_tokens_neox': 1849, 'n_words': 543}