{-# OPTIONS_GHC -Wno-missing-role-annotations #-}

module Dashi.Components.Link where

import Clay hiding (Color, action, href, label)
import Dashi.Prelude hiding ((&))
import Dashi.Style.Colour (LightDark (..))
import Dashi.Style.Pseudo (pressable)
import Dashi.Style.Root (tokenDecl)
import Dashi.Style.Text (TextColour (TextColour))
import Dashi.Style.Tokens
import Dashi.Style.Uchu (Uchu (..))
import Dashi.Style.Util (color')
import Miso.Html.Element (a_)
import Miso.Html.Property (href_)

data Text = Text
    deriving stock (Text -> Text -> Bool
(Text -> Text -> Bool) -> (Text -> Text -> Bool) -> Eq Text
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Text -> Text -> Bool
== :: Text -> Text -> Bool
$c/= :: Text -> Text -> Bool
/= :: Text -> Text -> Bool
Eq, Text
Text -> Text -> Bounded Text
forall a. a -> a -> Bounded a
$cminBound :: Text
minBound :: Text
$cmaxBound :: Text
maxBound :: Text
Bounded, Int -> Text
Text -> Int
Text -> [Text]
Text -> Text
Text -> Text -> [Text]
Text -> Text -> Text -> [Text]
(Text -> Text)
-> (Text -> Text)
-> (Int -> Text)
-> (Text -> Int)
-> (Text -> [Text])
-> (Text -> Text -> [Text])
-> (Text -> Text -> [Text])
-> (Text -> Text -> Text -> [Text])
-> Enum Text
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Text -> Text
succ :: Text -> Text
$cpred :: Text -> Text
pred :: Text -> Text
$ctoEnum :: Int -> Text
toEnum :: Int -> Text
$cfromEnum :: Text -> Int
fromEnum :: Text -> Int
$cenumFrom :: Text -> [Text]
enumFrom :: Text -> [Text]
$cenumFromThen :: Text -> Text -> [Text]
enumFromThen :: Text -> Text -> [Text]
$cenumFromTo :: Text -> Text -> [Text]
enumFromTo :: Text -> Text -> [Text]
$cenumFromThenTo :: Text -> Text -> Text -> [Text]
enumFromThenTo :: Text -> Text -> Text -> [Text]
Enum)

instance Token Text where
    tokenName :: forall s. (IsString s, Semigroup s) => Text -> s
tokenName Text
Text = s
"text-link"

instance ValueToken Text where
    type ValueType Text = LightDark Uchu
    tokenValue :: Text -> ValueType Text
tokenValue Text
Text = Uchu -> Uchu -> LightDark Uchu
forall c. c -> c -> LightDark c
LightDark Uchu
Blue5 Uchu
Blue3

data Link model action = Link
    { forall model action. Link model action -> MisoString
href :: MisoString
    , forall model action. Link model action -> [View model action]
label :: [View model action]
    }

instance Widget (Link model action) model action where
    widget' :: [Attribute action] -> Link model action -> View model action
widget' [Attribute action]
attrs Link{[View model action]
MisoString
href :: forall model action. Link model action -> MisoString
label :: forall model action. Link model action -> [View model action]
href :: MisoString
label :: [View model action]
..} = [Attribute action] -> [View model action] -> View model action
forall action model.
[Attribute action] -> [View model action] -> View model action
a_ (MisoString -> Attribute action
forall action. MisoString -> Attribute action
href_ MisoString
href Attribute action -> [Attribute action] -> [Attribute action]
forall a. a -> [a] -> [a]
: [Attribute action]
attrs) [View model action]
label
    style :: Css
style = do
        Selector
":root" Selector -> Css -> Css
? forall t. (ValueToken t, Val (ValueType t)) => Css
tokenDecl @Text
        Selector
a Selector -> Css -> Css
? do
            Css
pressable
            Refinement
"@href" Refinement -> Css -> Css
& do
                Text -> Css
forall t. Token t => t -> Css
color' Text
Text
                Refinement
hover Refinement -> Css -> Css
& TextDecoration -> Css
textDecoration TextDecoration
underline
                Appearance -> Refinement
forall t. Token t => t -> Refinement
byToken Appearance
Subtle Refinement -> Css -> Css
& TextColour -> Css
forall t. Token t => t -> Css
color' (Appearance -> TextColour
TextColour Appearance
Subtle)