{-# LANGUAGE OverloadedStrings #-}
{- |
Helpers and CSS styles for HTML output.
-}
module Hledger.Write.Html.Attribute (
    stylesheet,
    tableStylesheet,
    tableStyle,
    borderStyle,
    bold,
    alignright,
    alignleft,
    aligncenter,
    collapse,
    lpad,
    rpad,
    hpad,
    vpad,
    ) where

import Data.Text qualified as Text
import Data.Text (Text)


stylesheet :: [(Text,Text)] -> Text
stylesheet :: [(Text, Text)] -> Text
stylesheet [(Text, Text)]
elstyles =
    [Text] -> Text
Text.unlines ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$
        Text
"" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text
elText -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>Text
" {"Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>Text
stylesText -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>Text
"}" | (Text
el,Text
styles) <- [(Text, Text)]
elstyles]

tableStylesheet :: Text
tableStylesheet :: Text
tableStylesheet = [(Text, Text)] -> Text
stylesheet [(Text, Text)]
tableStyle

tableStyle :: [(Text, Text)]
tableStyle :: [(Text, Text)]
tableStyle =
  [(Text
"table", Text
collapse),
   (Text
"th, td", Text
lpad),
   (Text
"th.account, td.account", Text
"padding-left:0;"),
   -- prevent wrapping within dates and individual amounts
   (Text
"td.date, span.amount", Text
"white-space:nowrap")]
  [(Text, Text)] -> [(Text, Text)] -> [(Text, Text)]
forall a. [a] -> [a] -> [a]
++ [(Text, Text)]
borderStyle

-- | Rules for the border classes emitted by "Hledger.Write.Html",
-- one per side and line kind, eg @.border-top-double@. No color is given,
-- so the lines take the text color and stay visible on any background.
borderStyle :: [(Text, Text)]
borderStyle :: [(Text, Text)]
borderStyle =
  [ (Text
"." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
cls, Text
side Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
line)
  | (Text
side, Text
sideCls) <- [(Text
"border-left",Text
"left"), (Text
"border-right",Text
"right"),
                        (Text
"border-top",Text
"top"), (Text
"border-bottom",Text
"bottom")]
  , (Text
line, Text
lineCls) <- [(Text
"1px solid",Text
"single"), (Text
"3px double",Text
"double")]
  , let cls :: Text
cls = Text
"border-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
sideCls Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
lineCls
  ]

bold :: Text
bold :: Text
bold = Text
"font-weight:bold"

alignright, alignleft, aligncenter :: Text
alignright :: Text
alignright  = Text
"text-align:right"
alignleft :: Text
alignleft   = Text
"text-align:left"
aligncenter :: Text
aligncenter = Text
"text-align:center"

collapse :: Text
collapse :: Text
collapse = Text
"border-collapse:collapse"

lpad, rpad, hpad, vpad :: Text
lpad :: Text
lpad = Text
"padding-left:1em"
rpad :: Text
rpad = Text
"padding-right:1em"
hpad :: Text
hpad = Text
"padding-left:1em; padding-right:1em"
vpad :: Text
vpad = Text
"padding-top:1em;  padding-bottom:1em"