<commit_before>module User.View.Profile exposing (..)

import Html exposing (..)
import Html.Attributes exposing (class, href)
import List

import Material.Button as Button
import Material.Card as Card
import Material.Chip as Chip
import Material.Elevation as Elevation
import Material.Grid exposing (..)
import Material.Icon as Icon
import Material.Menu as Menu
import Material.Options as Options exposing (cs, css)
import Material.Spinner as Loading
import Material.Typography as Typo

import Base.Messages exposing (Msg(..))
import Base.Models.Package exposing (Package)
import Base.Network.Url as Url
import Package.Messages as PMsg
import User.Localization as L
import User.Messages as UMsg
import User.Models exposing (UserData)


badge : String -> Html Msg
badge group =
  Chip.button
    [ Options.onClick <| Navigate <| Url.usersByGroup group
    , cs (if group == "admins" then "admin-badge" else "user-badge" )
    ]
    [ Chip.content [] [ text group ] ]

subtitle : String -> Html Msg
subtitle str =
  Options.styled p [ Typo.button, cs "subtitle" ] [ text str ]

checkmark: Bool -> Html Msg
checkmark x =
    if x then
      Icon.view "check" [ cs "menu-icon" ]
    else
      Options.span [ cs "menu-icon" ] []


profile : UserData -> Html Msg
profile data =
  Card.view
    [ Elevation.e3
    , css "z-index" <| toString 10
    ]
    [ Card.title [ Card.border ] [ Card.head [] [ text (L.get data.session.lang L.profile) ] ]
    , Card.menu [ cs "noselect" ]
        ( if List.member "admins" data.session.user.groups then
            [ Menu.render Mdl [20] data.mdl
                [ Menu.ripple, Menu.bottomRight ]
                [ Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "en" ]
                    [ checkmark (data.session.lang == "en"), text "English" ]
                , Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "ru", Menu.divider ]
                    [ checkmark (data.session.lang == "ru"), text "Русский" ]
                , Menu.item
                    [ Menu.onSelect <| Navigate <| Url.editUser data.user.nickname ]
                    [ Icon.view "mode_edit" [ cs "menu-icon" ], text (L.get data.session.lang L.edit) ]
                , Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.RemoveUser data.user.nickname ]
                    [ Icon.view "delete" [ cs "menu-icon danger" ], text (L.get data.session.lang L.delete) ]
                ]
            ]
          else []
        )
    , Card.text [ cs "profile-panel" ]
      [ div [ class "profile-avatar" ] [ Icon.view "account_circle" [ cs "avatar" ] ]
      , div [ class "profile-info" ]
          [ subtitle (L.get data.session.lang L.nickname)
          , div
              [ class "profile-nickname" ]
              [ text data.user.nickname ]
          , subtitle (L.get data.session.lang L.groups)
          , div
              [ class "profile-badges" ]
              ( List.map
                  badge
                  (if List.isEmpty data.user.groups then ["user"] else data.user.groups)
              )
          ]
      ]
    ]


package : UserData -> Int -> Package -> Cell Msg
package data index package =
  cell
    [ size All 6, size Tablet 8 ]<commit_msg>Make language switcher available for unprivileged users<commit_after>module User.View.Profile exposing (..)

import Html exposing (..)
import Html.Attributes exposing (class, href)
import List

import Material.Button as Button
import Material.Card as Card
import Material.Chip as Chip
import Material.Elevation as Elevation
import Material.Grid exposing (..)
import Material.Icon as Icon
import Material.Menu as Menu
import Material.Options as Options exposing (cs, css)
import Material.Spinner as Loading
import Material.Typography as Typo

import Base.Messages exposing (Msg(..))
import Base.Models.Package exposing (Package)
import Base.Network.Url as Url
import Package.Messages as PMsg
import User.Localization as L
import User.Messages as UMsg
import User.Models exposing (UserData)


badge : String -> Html Msg
badge group =
  Chip.button
    [ Options.onClick <| Navigate <| Url.usersByGroup group
    , cs (if group == "admins" then "admin-badge" else "user-badge" )
    ]
    [ Chip.content [] [ text group ] ]

subtitle : String -> Html Msg
subtitle str =
  Options.styled p [ Typo.button, cs "subtitle" ] [ text str ]

checkmark: Bool -> Html Msg
checkmark x =
    if x then
      Icon.view "check" [ cs "menu-icon" ]
    else
      Options.span [ cs "menu-icon" ] []


profile : UserData -> Html Msg
profile data =
  Card.view
    [ Elevation.e3
    , css "z-index" <| toString 10
    ]
    [ Card.title [ Card.border ] [ Card.head [] [ text (L.get data.session.lang L.profile) ] ]
    , Card.menu [ cs "noselect" ]
        ( if List.member "admins" data.session.user.groups then
            [ Menu.render Mdl [20] data.mdl
                [ Menu.ripple, Menu.bottomRight ]
                [ Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "en" ]
                    [ checkmark (data.session.lang == "en"), text "English" ]
                , Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "ru", Menu.divider ]
                    [ checkmark (data.session.lang == "ru"), text "Русский" ]
                , Menu.item
                    [ Menu.onSelect <| Navigate <| Url.editUser data.user.nickname ]
                    [ Icon.view "mode_edit" [ cs "menu-icon" ], text (L.get data.session.lang L.edit) ]
                , Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.RemoveUser data.user.nickname ]
                    [ Icon.view "delete" [ cs "menu-icon danger" ], text (L.get data.session.lang L.delete) ]
                ]
            ]
          else
            [ Menu.render Mdl [20] data.mdl
                [ Menu.ripple, Menu.bottomRight ]
                [ Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "en" ]
                    [ checkmark (data.session.lang == "en"), text "English" ]
                , Menu.item
                    [ Menu.onSelect <| UserMsg <| UMsg.ChangeLanguage "ru" ]
                    [ checkmark (data.session.lang == "ru"), text "Русский" ]
                ]
            ]
        )
    , Card.text [ cs "profile-panel" ]
      [ div [ class "profile-avatar" ] [ Icon.view "account_circle" [ cs "avatar" ] ]
      , div [ class "profile-info" ]
          [ subtitle (L.get data.session.lang L.nickname)
          , div
              [ class "profile-nickname" ]
              [ text data.user.nickname ]
          , subtitle (L.get data.session.lang L.groups)
          , div
              [ class "profile-badges" ]
              ( List.map
                  badge
                  (if List.isEmpty data.user.groups then ["user"] else data.user.groups)
              )
          ]
      ]
    ]


package : UserData -> Int -> Package -> Cell Msg
package data index package =
  cell
    [ size All 6, size Tablet 8 ]
{'fraction_non_alphanumeric': 0.11484474691620587, 'fraction_numerical': 0.0022685382106904864, 'mean_word_length': 1.9233319519270617, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 17, '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': '2101305', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2074, 'n_words': 576}