<commit_before>module Internal.Select.Implementation exposing
    ( Property
    , disabled
    , fullWidth
    , label
    , onSelect
    , option
    , outlined
    , react
    , required
    , selected
    , selectedText
    , subs
    , subscriptions
    , value
    , view
    )

import Browser.Dom
import Html exposing (Html, text)
import Html.Attributes as Html
import Internal.Component as Component exposing (Index, Indexed)
import Internal.Helpers as Helpers
import Internal.Keyboard as Keyboard exposing (decodeMeta, decodeKey, decodeKeyCode)
import Internal.List.Implementation as Lists
import Internal.Menu.Implementation as Menu
import Internal.Menu.Model as Menu
import Internal.Msg
import Internal.Options as Options exposing (aria, cs, role, styled, when)
import Internal.Ripple.Implementation as Ripple
import Internal.Select.Model exposing (Model, Msg(..), defaultModel)
import Json.Decode as Decode
import Task
import Svg exposing (polygon)
import Svg.Attributes as Svg exposing (stroke, fillRule, points, viewBox)


subscriptions : Model -> Sub (Msg m)
subscriptions model =
    Sub.map MenuMsg (Menu.subscriptions model.menu)


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

        Change changedValue ->
            let
                dirty =
                    changedValue /= ""
            in
            ( Just { model | isDirty = dirty }, Cmd.none )

        Blur ->
            ( Just { model | focused = False }, Cmd.none )

        Focus ->
            ( Just { model | focused = True }, Cmd.none )

        RippleMsg msg_ ->
            let
                ( ripple, effects ) =
                    Ripple.update msg_ model.ripple
            in
            ( Just { model | ripple = ripple }, Cmd.map (lift << RippleMsg) effects )

        KeyDown menuIndex key keyCode ->
            let
                isEscape =
                    key == "Escape" || keyCode == 27

                isSpace =
                    key == "Space" || keyCode == 32

                isEnter =
                    key == "Enter" || keyCode == 13

                isArrowDown =
                    key == "ArrowDown" || keyCode == 40
            in
            if isEscape || isSpace || isEnter || isArrowDown then
                ( Nothing, Helpers.delayedCmd 16 (lift (OpenMenu menuIndex)) )
            else
                ( Nothing, Cmd.none )

        OpenMenu menuIndex ->
            ( Nothing, Helpers.cmd ( lift (MenuMsg Menu.Open) ) )

        ToggleMenu ->
            update lift (MenuMsg Menu.Toggle) model

        MenuSelection index onSelect_ v ->
            ( Nothing
            , Cmd.batch
                [ Helpers.cmd (onSelect_ v)
                , Task.attempt (\_ -> lift NoOp) (Browser.Dom.focus index)
                ]
            )

        MenuMsg msg_ ->
            Menu.update (lift << MenuMsg) msg_ model.menu
                |> Tuple.mapFirst
                    (\maybeNewMenu ->
                        case maybeNewMenu of
                            Just newMenu ->
                                Just { model | menu = newMenu }

                            Nothing ->
                                Nothing
                    )


type alias Config m =
    { label : String
    , disabled : Bool
    , required : Bool
    , outlined : Bool
    , id_ : String
    , selectedText : String<commit_msg>refactor(select): make clear id_ is an Index<commit_after>module Internal.Select.Implementation exposing
    ( Property
    , disabled
    , fullWidth
    , label
    , onSelect
    , option
    , outlined
    , react
    , required
    , selected
    , selectedText
    , subs
    , subscriptions
    , value
    , view
    )

import Browser.Dom
import Html exposing (Html, text)
import Html.Attributes as Html
import Internal.Component as Component exposing (Index, Indexed)
import Internal.Helpers as Helpers
import Internal.Keyboard as Keyboard exposing (decodeMeta, decodeKey, decodeKeyCode)
import Internal.List.Implementation as Lists
import Internal.Menu.Implementation as Menu
import Internal.Menu.Model as Menu
import Internal.Msg
import Internal.Options as Options exposing (aria, cs, role, styled, when)
import Internal.Ripple.Implementation as Ripple
import Internal.Select.Model exposing (Model, Msg(..), defaultModel)
import Json.Decode as Decode
import Task
import Svg exposing (polygon)
import Svg.Attributes as Svg exposing (stroke, fillRule, points, viewBox)


subscriptions : Model -> Sub (Msg m)
subscriptions model =
    Sub.map MenuMsg (Menu.subscriptions model.menu)


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

        Change changedValue ->
            let
                dirty =
                    changedValue /= ""
            in
            ( Just { model | isDirty = dirty }, Cmd.none )

        Blur ->
            ( Just { model | focused = False }, Cmd.none )

        Focus ->
            ( Just { model | focused = True }, Cmd.none )

        RippleMsg msg_ ->
            let
                ( ripple, effects ) =
                    Ripple.update msg_ model.ripple
            in
            ( Just { model | ripple = ripple }, Cmd.map (lift << RippleMsg) effects )

        KeyDown menuIndex key keyCode ->
            let
                isEscape =
                    key == "Escape" || keyCode == 27

                isSpace =
                    key == "Space" || keyCode == 32

                isEnter =
                    key == "Enter" || keyCode == 13

                isArrowDown =
                    key == "ArrowDown" || keyCode == 40
            in
            if isEscape || isSpace || isEnter || isArrowDown then
                ( Nothing, Helpers.delayedCmd 16 (lift (OpenMenu menuIndex)) )
            else
                ( Nothing, Cmd.none )

        OpenMenu menuIndex ->
            ( Nothing, Helpers.cmd ( lift (MenuMsg Menu.Open) ) )

        ToggleMenu ->
            update lift (MenuMsg Menu.Toggle) model

        MenuSelection index onSelect_ v ->
            ( Nothing
            , Cmd.batch
                [ Helpers.cmd (onSelect_ v)
                , Task.attempt (\_ -> lift NoOp) (Browser.Dom.focus index)
                ]
            )

        MenuMsg msg_ ->
            Menu.update (lift << MenuMsg) msg_ model.menu
                |> Tuple.mapFirst
                    (\maybeNewMenu ->
                        case maybeNewMenu of
                            Just newMenu ->
                                Just { model | menu = newMenu }

                            Nothing ->
                                Nothing
                    )


type alias Config m =
    { label : String
    , disabled : Bool
    , required : Bool
    , outlined : Bool
    , id_ : Index
    , selectedText : String
{'fraction_non_alphanumeric': 0.0832378223495702, 'fraction_numerical': 0.0028653295128939827, 'mean_word_length': 1.5012540308133286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 43, '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': '916741', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1757, 'n_words': 559}