<commit_before>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.Workspace.Card.Component
  ( CardComponent
  , makeCardComponent
  , module SlamData.Workspace.Card.Component.Def
  , module CQ
  , module CS
  ) where

import SlamData.Prelude
import SlamData.Config as Config

import Data.Foldable (elem)
import Data.Lens (PrismP, (.~), review, preview, clonePrism)
import Data.Time (Milliseconds(..))

import Halogen as H
import Halogen.Component.Utils (sendAfter')
import Halogen.HTML.Indexed as HH
import Halogen.HTML.Properties.Indexed as HP
import Halogen.HTML.Properties.Indexed.ARIA as ARIA

import Math as Math

import SlamData.Effects (Slam)
import SlamData.Workspace.Card.CardType (CardType(..), cardClasses, cardName, cardGlyph)
import SlamData.Workspace.Card.Component.CSS as CSS
import SlamData.Workspace.Card.Component.Def (CardDef, makeQueryPrism, makeQueryPrism')
import SlamData.Workspace.Card.Component.Query as CQ
import SlamData.Workspace.Card.Component.State as CS
import SlamData.Workspace.Card.Model as Card

import Utils.DOM as DOMUtils

-- | Type synonym for the full type of a card component.
type CardComponent = H.Component CS.CardStateP CQ.CardQueryP Slam
type CardDSL = H.ParentDSL CS.CardState CS.AnyCardState CQ.CardQuery CQ.InnerCardQuery Slam Unit
type CardHTML = H.ParentHTML CS.AnyCardState CQ.CardQuery CQ.InnerCardQuery Slam Unit

-- | Card component factory
makeCardComponent
  ∷ ∀ s f
  . CardDef s f ()
  → CardComponent
makeCardComponent def = makeCardComponentPart def render
  where
  render
    ∷ H.Component CS.AnyCardState CQ.InnerCardQuery Slam
    → CS.AnyCardState
    → CS.CardState
    → CardHTML
  render component initialState = const $
    HH.div
      [ HP.classes $ [ CSS.deckCard ]
      , HP.ref (H.action ∘ CQ.SetHTMLElement)
      ]
      $ fold [cardLabel, card]
    where
    cardLabel :: Array CardHTML
    cardLabel
      | def.cardType `elem` [PendingCard, ErrorCard, NextAction, Draftboard] = []
      | otherwise =
          [ HH.div
              [ HP.classes [CSS.cardHeader]
              , ARIA.label $ (cardName def.cardType) ⊕ " card"
              ]
              [ HH.div
                  [ HP.class_ CSS.cardName ]
                  [ cardGlyph def.cardType
                  , HH.text $ cardName def.cardType
                  ]<commit_msg>Moved aria label to card rather than card header<commit_after>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.Workspace.Card.Component
  ( CardComponent
  , makeCardComponent
  , module SlamData.Workspace.Card.Component.Def
  , module CQ
  , module CS
  ) where

import SlamData.Prelude
import SlamData.Config as Config

import Data.Foldable (elem)
import Data.Lens (PrismP, (.~), review, preview, clonePrism)
import Data.Time (Milliseconds(..))

import Halogen as H
import Halogen.Component.Utils (sendAfter')
import Halogen.HTML.Indexed as HH
import Halogen.HTML.Properties.Indexed as HP
import Halogen.HTML.Properties.Indexed.ARIA as ARIA

import Math as Math

import SlamData.Effects (Slam)
import SlamData.Workspace.Card.CardType (CardType(..), cardClasses, cardName, cardGlyph)
import SlamData.Workspace.Card.Component.CSS as CSS
import SlamData.Workspace.Card.Component.Def (CardDef, makeQueryPrism, makeQueryPrism')
import SlamData.Workspace.Card.Component.Query as CQ
import SlamData.Workspace.Card.Component.State as CS
import SlamData.Workspace.Card.Model as Card

import Utils.DOM as DOMUtils

-- | Type synonym for the full type of a card component.
type CardComponent = H.Component CS.CardStateP CQ.CardQueryP Slam
type CardDSL = H.ParentDSL CS.CardState CS.AnyCardState CQ.CardQuery CQ.InnerCardQuery Slam Unit
type CardHTML = H.ParentHTML CS.AnyCardState CQ.CardQuery CQ.InnerCardQuery Slam Unit

-- | Card component factory
makeCardComponent
  ∷ ∀ s f
  . CardDef s f ()
  → CardComponent
makeCardComponent def = makeCardComponentPart def render
  where
  render
    ∷ H.Component CS.AnyCardState CQ.InnerCardQuery Slam
    → CS.AnyCardState
    → CS.CardState
    → CardHTML
  render component initialState = const $
    HH.div
      [ HP.classes $ [ CSS.deckCard ]
      , ARIA.label $ (cardName def.cardType) ⊕ " card"
      , HP.ref (H.action ∘ CQ.SetHTMLElement)
      ]
      $ fold [cardLabel, card]
    where
    cardLabel :: Array CardHTML
    cardLabel
      | def.cardType `elem` [PendingCard, ErrorCard, NextAction, Draftboard] = []
      | otherwise =
          [ HH.div
              [ HP.classes [CSS.cardHeader]
              ]
              [ HH.div
                  [ HP.class_ CSS.cardName ]
                  [ cardGlyph def.cardType
                  , HH.text $ cardName def.cardType
                  ]
{'fraction_non_alphanumeric': 0.07973421926910298, 'fraction_numerical': 0.002797691904179052, 'mean_word_length': 3.240177909562639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5925525', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1708, 'n_words': 558}