<commit_before>module BoardView exposing (boardView)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Maybe exposing (withDefault)
import List.Extra


--

import Types.Model exposing (..)
import Types.Card exposing (..)
import Types.Msg exposing (..)
import I18n exposing (..)
import I18n.Translation exposing (..)


boardView : Model -> Html Msg
boardView model =
    let
        cols =
            model.game.cards |> List.length |> toFloat |> sqrt |> truncate

        cardsWithIds =
            List.indexedMap (,) model.game.cards
    in
        div [ class "game row" ]
            [ div [ class "col-md-12 col-lg-12" ]
                [ div
                    [ classList
                        [ ( "active", model.game.turn == model.playerTurn )
                        , ( "memory", True )
                        ]
                    ]
                    ((groupsOf cols cardsWithIds) |> (rows model))
                ]
            ]


rows : Model -> List (List ( Int, Card )) -> List (Html Msg)
rows model cardRows =
    List.indexedMap (row model) cardRows


row : Model -> Int -> List ( Int, Card ) -> Html Msg
row model rowIndex cardsWithIds =
    let
        cols =
            cardsWithIds |> List.length
    in
        div
            [ class "card-row"
            , style
                [ ( "top", (toString (100 / toFloat cols * toFloat rowIndex) ++ "%") )
                , ( "height", (toString (100 / toFloat cols) ++ "%") )
                ]
            ]
            (List.indexedMap
                (card model cols rowIndex)
                cardsWithIds
            )


card : Model -> Int -> Int -> Int -> ( Int, Card ) -> Html Msg
card model dimension row col ( cardId, card ) =
    let
        numberOfPairs =
            toFloat dimension * toFloat dimension / 2 |> truncate

        isClickable =
            model.game.turn == model.playerTurn && (not card.flipped) && (not card.cleared) || model.game.visibility == "local"

        classAttrs =
            [ classList
                [ ( "card", True )
                , ( "card--clickable", isClickable )
                , ( "flipped", card.flipped )
                , ( "cleared", card.cleared )
                ]
            ]

        cardAttrs =
            if isClickable then
                classAttrs ++ [ onMouseDown (FlipCard cardId) ]
            else
                classAttrs

        width =<commit_msg>Fix bug with erroneously clickable cards<commit_after>module BoardView exposing (boardView)

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Maybe exposing (withDefault)
import List.Extra


--

import Types.Model exposing (..)
import Types.Card exposing (..)
import Types.Msg exposing (..)
import I18n exposing (..)
import I18n.Translation exposing (..)


boardView : Model -> Html Msg
boardView model =
    let
        cols =
            model.game.cards |> List.length |> toFloat |> sqrt |> truncate

        cardsWithIds =
            List.indexedMap (,) model.game.cards
    in
        div [ class "game row" ]
            [ div [ class "col-md-12 col-lg-12" ]
                [ div
                    [ classList
                        [ ( "active", model.game.turn == model.playerTurn )
                        , ( "memory", True )
                        ]
                    ]
                    ((groupsOf cols cardsWithIds) |> (rows model))
                ]
            ]


rows : Model -> List (List ( Int, Card )) -> List (Html Msg)
rows model cardRows =
    List.indexedMap (row model) cardRows


row : Model -> Int -> List ( Int, Card ) -> Html Msg
row model rowIndex cardsWithIds =
    let
        cols =
            cardsWithIds |> List.length
    in
        div
            [ class "card-row"
            , style
                [ ( "top", (toString (100 / toFloat cols * toFloat rowIndex) ++ "%") )
                , ( "height", (toString (100 / toFloat cols) ++ "%") )
                ]
            ]
            (List.indexedMap
                (card model cols rowIndex)
                cardsWithIds
            )


card : Model -> Int -> Int -> Int -> ( Int, Card ) -> Html Msg
card model dimension row col ( cardId, card ) =
    let
        numberOfPairs =
            toFloat dimension * toFloat dimension / 2 |> truncate

        isClickable =
            model.game.turn == model.playerTurn && not card.flipped && not card.cleared

        classAttrs =
            [ classList
                [ ( "card", True )
                , ( "card--clickable", isClickable )
                , ( "flipped", card.flipped )
                , ( "cleared", card.cleared )
                ]
            ]

        cardAttrs =
            if isClickable then
                classAttrs ++ [ onMouseDown (FlipCard cardId) ]
            else
                classAttrs

        width =
{'fraction_non_alphanumeric': 0.11063656701240594, 'fraction_numerical': 0.006101281269066504, 'mean_word_length': 1.3920233463035019, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '5910926', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1334, 'n_words': 363}