{-# LANGUAGE DeriveFunctor       #-}
{-# LANGUAGE OverloadedStrings #-}

module Concur.Replica.DOM.Props where

import qualified Data.Text                as T

import           Replica.VDOM             (DOMEvent)

data Prop a
  = PropText T.Text
  | PropBool Bool
  | PropEvent (DOMEvent -> a)
  | PropMap [Props a]
  deriving Functor

data Props a = Props T.Text (Prop a)
  deriving Functor

boolProp :: T.Text -> Bool -> Props a
boolProp k v = Props k (PropBool v)

textProp :: T.Text -> T.Text -> Props a
textProp k v = Props k (PropText v)

key :: T.Text -> Props a
key v = textProp "key" v

style :: [(T.Text, T.Text)] -> Props a
style m = Props "style" (PropMap [ Props k (PropText v) | (k, v) <- m ])

-- | Define multiple classes conditionally
--
  > div [ classList [ ( " empty " , null items ) ] [ ]
--
classList ::  [(T.Text, Bool)] -> Props a
classList xs = textProp "class" $ T.intercalate " " [ t | (t, True) <- xs ]

-- | <-US/docs/Mozilla/Tech/XUL/Props/title>
title ::  T.Text -> Props a
title = textProp "title"

-- | <-US/docs/Mozilla/Tech/XUL/Props/selected>
selected ::  Bool -> Props a
selected = boolProp "selected"

-- | <-US/docs/Mozilla/Tech/XUL/Props/hidden>
hidden ::  Bool -> Props a
hidden             = boolProp "hidden"

-- | <-US/docs/Mozilla/Tech/XUL/Props/value>
value ::  T.Text -> Props a
value             = textProp "value"

-- | <-US/docs/Mozilla/Tech/XUL/Props/defaultValue>
defaultValue ::  T.Text -> Props a
defaultValue      = textProp "defaultValue"

-- | <-US/docs/Mozilla/Tech/XUL/Props/accept>
accept ::  T.Text -> Props a
accept            = textProp "accept"

-- | <-US/docs/Mozilla/Tech/XUL/Props/acceptCharset>
acceptCharset ::  T.Text -> Props a
acceptCharset     = textProp "acceptCharset"

-- | <-US/docs/Mozilla/Tech/XUL/Props/a>
a_ ::  T.Text -> Props a
a_            = textProp "a"

-- | <-US/docs/Mozilla/Tech/XUL/Props/autocomplete>
autocomplete ::  Bool -> Props a
autocomplete b = textProp "autocomplete" (if b then "on" else "off")

-- | <-US/docs/Mozilla/Tech/XUL/Props/autosave>
autosave ::  T.Text -> Props a
autosave          = textProp "autosave"

-- | <-US/docs/Mozilla/Tech/XUL/Props/disabled>
disabled ::  Bool -> Props a
disabled          = boolProp "disabled"

-- | <-US/docs/Mozilla/Tech/XUL/Props/enctype>
enctype ::  T.Text -> Props a
enctype           = textProp "enctype"

-- | <-US/docs/Mozilla/Tech/XUL/Props/formation>
formation ::  T.Text -> Props a
formation         = textProp "formation"

-- | <-US/docs/Mozilla/Tech/XUL/Props/list>
list ::  T.Text -> Props a
list              = textProp "list"

-- | <-US/docs/Mozilla/Tech/XUL/Props/maxlength>
maxlength ::  T.Text -> Props a
maxlength         = textProp "maxlength"

-- | <-US/docs/Mozilla/Tech/XUL/Props/minlength>
minlength ::  T.Text -> Props a
minlength         = textProp "minlength"

-- | <-US/docs/Mozilla/Tech/XUL/Props/method>
method ::  T.Text -> Props a
method            = textProp "method"

-- | <-US/docs/Mozilla/Tech/XUL/Props/multiple>
multiple ::  Bool -> Props a
multiple          = boolProp "multiple"

-- | <-US/docs/Mozilla/Tech/XUL/Props/novalidate>
novalidate ::  Bool -> Props a
novalidate        = boolProp "noValidate"

-- | <-US/docs/Mozilla/Tech/XUL/Props/pattern>
pattern ::  T.Text -> Props a
pattern           = textProp "pattern"

-- | <-US/docs/Mozilla/Tech/XUL/Props/readonly>
readonly ::  Bool -> Props a
readonly          = boolProp "readOnly"

-- | <-US/docs/Mozilla/Tech/XUL/Props/required>
required ::  Bool -> Props a
required          = boolProp "required"

-- | <-US/docs/Mozilla/Tech/XUL/Props/size>
size ::  T.Text -> Props a
size              = textProp "size"

-- | <-US/docs/Mozilla/Tech/XUL/Props/for>
for ::  T.Text -> Props a
for               = textProp "for"

-- | <-US/docs/Mozilla/Tech/XUL/Props/form>
form_ ::  T.Text -> Props a
form_               = textProp "form"

-- | <-US/docs/Mozilla/Tech/XUL/Props/max>
max ::  T.Text -> Props a
max               = textProp "max"

-- | <-US/docs/Mozilla/Tech/XUL/Props/min>
min ::  T.Text -> Props a
min               = textProp "min"

-- | <-US/docs/Mozilla/Tech/XUL/Props/step>
step ::  T.Text -> Props a
step              = textProp "step"

-- | <-US/docs/Mozilla/Tech/XUL/Props/cols>
cols ::  T.Text -> Props a
cols              = textProp "cols"

-- | <-US/docs/Mozilla/Tech/XUL/Props/rows>
rows ::  T.Text -> Props a
rows              = textProp "rows"

-- | <-US/docs/Mozilla/Tech/XUL/Props/wrap>
wrap ::  T.Text -> Props a
wrap              = textProp "wrap"

-- | <-US/docs/Mozilla/Tech/XUL/Props/target>
target_ ::  T.Text -> Props a
target_            = textProp "target"

-- | <-US/docs/Mozilla/Tech/XUL/Props/download>
download ::  T.Text -> Props a
download          = textProp "download"

-- | <-US/docs/Mozilla/Tech/XUL/Props/downloadAs>
downloadAs ::  T.Text -> Props a
downloadAs        = textProp "downloadAs"

-- | <-US/docs/Mozilla/Tech/XUL/Props/hreflang>
hreflang ::  T.Text -> Props a
hreflang          = textProp "hreflang"

-- | <-US/docs/Mozilla/Tech/XUL/Props/media>
media ::  T.Text -> Props a
media             = textProp "media"

-- | <-US/docs/Mozilla/Tech/XUL/Props/ping>
ping ::  T.Text -> Props a
ping              = textProp "ping"

-- | <-US/docs/Mozilla/Tech/XUL/Props/rel>
rel ::  T.Text -> Props a
rel               = textProp "rel"

-- | <-US/docs/Mozilla/Tech/XUL/Props/ismap>
ismap ::  T.Text -> Props a
ismap             = textProp "ismap"

-- | <-US/docs/Mozilla/Tech/XUL/Props/usemap>
usemap ::  T.Text -> Props a
usemap            = textProp "usemap"

  | < -US/docs/Mozilla/Tech/XUL/Props/shape >
shape ::  T.Text -> Props a
shape             = textProp "shape"

-- | <-US/docs/Mozilla/Tech/XUL/Props/coords>
coords ::  T.Text -> Props a
coords            = textProp "coords"

-- | <-US/docs/Mozilla/Tech/XUL/Props/src>
src ::  T.Text -> Props a
src               = textProp "src"

-- | <-US/docs/Mozilla/Tech/XUL/Props/height>
height ::  T.Text -> Props a
height            = textProp "height"

  | < -US/docs/Mozilla/Tech/XUL/Props/width >
width ::  T.Text -> Props a
width             = textProp "width"

-- | <-US/docs/Mozilla/Tech/XUL/Props/alt>
alt ::  T.Text -> Props a
alt               = textProp "alt"

-- | <-US/docs/Mozilla/Tech/XUL/Props/autoplay>
autoplay ::  Bool -> Props a
autoplay          = boolProp "autoplay"

-- | <-US/docs/Mozilla/Tech/XUL/Props/controls>
controls ::  Bool -> Props a
controls          = boolProp "controls"

-- | <-US/docs/Mozilla/Tech/XUL/Props/loop>
loop ::  Bool -> Props a
loop              = boolProp "loop"

-- | <-US/docs/Mozilla/Tech/XUL/Props/preload>
preload ::  T.Text -> Props a
preload           = textProp "preload"

-- | <-US/docs/Mozilla/Tech/XUL/Props/poster>
poster ::  T.Text -> Props a
poster            = textProp "poster"

-- | <-US/docs/Mozilla/Tech/XUL/Props/default>
default_ ::  Bool -> Props a
default_           = boolProp "default"

-- | <-US/docs/Mozilla/Tech/XUL/Props/kind>
kind ::  T.Text -> Props a
kind              = textProp "kind"

-- | <-US/docs/Mozilla/Tech/XUL/Props/srclang>
srclang ::  T.Text -> Props a
srclang           = textProp "srclang"

-- | <-US/docs/Mozilla/Tech/XUL/Props/sandbox>
sandbox ::  T.Text -> Props a
sandbox           = textProp "sandbox"

-- | <-US/docs/Mozilla/Tech/XUL/Props/seamless>
seamless ::  T.Text -> Props a
seamless          = textProp "seamless"

-- | <-US/docs/Mozilla/Tech/XUL/Props/srcdoc>
srcdoc ::  T.Text -> Props a
srcdoc            = textProp "srcdoc"

-- | <-US/docs/Mozilla/Tech/XUL/Props/reversed>
reversed ::  T.Text -> Props a
reversed          = textProp "reversed"

-- | <-US/docs/Mozilla/Tech/XUL/Props/start>
start ::  T.Text -> Props a
start             = textProp "start"

-- | <-US/docs/Mozilla/Tech/XUL/Props/align>
align ::  T.Text -> Props a
align             = textProp "align"

-- | <-US/docs/Mozilla/Tech/XUL/Props/colspan>
colspan ::  T.Text -> Props a
colspan           = textProp "colspan"

-- | <-US/docs/Mozilla/Tech/XUL/Props/rowspan>
rowspan ::  T.Text -> Props a
rowspan           = textProp "rowspan"

-- | <-US/docs/Mozilla/Tech/XUL/Props/headers>
headers ::  T.Text -> Props a
headers           = textProp "headers"

-- | <-US/docs/Mozilla/Tech/XUL/Props/scope>
scope ::  T.Text -> Props a
scope             = textProp "scope"

-- | <-US/docs/Mozilla/Tech/XUL/Props/async>
async ::  T.Text -> Props a
async             = textProp "async"

-- | <-US/docs/Mozilla/Tech/XUL/Props/charset>
charset ::  T.Text -> Props a
charset           = textProp "charset"

-- | <-US/docs/Mozilla/Tech/XUL/Props/content>
content ::  T.Text -> Props a
content           = textProp "content"

-- | <-US/docs/Mozilla/Tech/XUL/Props/defer>
defer ::  T.Text -> Props a
defer             = textProp "defer"

-- | <-US/docs/Mozilla/Tech/XUL/Props/httpEquiv>
httpEquiv ::  T.Text -> Props a
httpEquiv         = textProp "httpEquiv"

-- | <-US/docs/Mozilla/Tech/XUL/Props/language>
language ::  T.Text -> Props a
language          = textProp "language"

-- | <-US/docs/Mozilla/Tech/XUL/Props/scoped>
scoped ::  T.Text -> Props a
scoped            = textProp "scoped"

-- | <-US/docs/Mozilla/Tech/XUL/Props/type>
type_ ::  T.Text -> Props a
type_ = textProp "type"

-- | <-US/docs/Mozilla/Tech/XUL/Props/name>
name ::  T.Text -> Props a
name = textProp "name"

-- | <-US/docs/Mozilla/Tech/XUL/Props/href>
href ::  T.Text -> Props a
href = textProp "href"

-- | <-US/docs/Mozilla/Tech/XUL/Props/id>
id ::  T.Text -> Props a
id = textProp "id"

-- | <-US/docs/Mozilla/Tech/XUL/Props/placeholder>
placeholder ::  T.Text -> Props a
placeholder = textProp "placeholder"

-- | <-US/docs/Mozilla/Tech/XUL/Props/checked>
checked ::  Bool -> Props a
checked = boolProp "checked"

-- | Set "autofocus" property
-- <-US/docs/Mozilla/Tech/XUL/Props/autofocus>
autofocus ::  Bool -> Props a
autofocus = boolProp "autofocus"

-- | Set "className" property
-- <-US/docs/Web/API/Element/className>
className ::  T.Text -> Props a
className = textProp "class"

# LANGUAGE DeriveFunctor       #
# LANGUAGE OverloadedStrings #
 | Define multiple classes conditionally


 | <-US/docs/Mozilla/Tech/XUL/Props/title>
 | <-US/docs/Mozilla/Tech/XUL/Props/selected>
 | <-US/docs/Mozilla/Tech/XUL/Props/hidden>
 | <-US/docs/Mozilla/Tech/XUL/Props/value>
 | <-US/docs/Mozilla/Tech/XUL/Props/defaultValue>
 | <-US/docs/Mozilla/Tech/XUL/Props/accept>
 | <-US/docs/Mozilla/Tech/XUL/Props/acceptCharset>
 | <-US/docs/Mozilla/Tech/XUL/Props/a>
 | <-US/docs/Mozilla/Tech/XUL/Props/autocomplete>
 | <-US/docs/Mozilla/Tech/XUL/Props/autosave>
 | <-US/docs/Mozilla/Tech/XUL/Props/disabled>
 | <-US/docs/Mozilla/Tech/XUL/Props/enctype>
 | <-US/docs/Mozilla/Tech/XUL/Props/formation>
 | <-US/docs/Mozilla/Tech/XUL/Props/list>
 | <-US/docs/Mozilla/Tech/XUL/Props/maxlength>
 | <-US/docs/Mozilla/Tech/XUL/Props/minlength>
 | <-US/docs/Mozilla/Tech/XUL/Props/method>
 | <-US/docs/Mozilla/Tech/XUL/Props/multiple>
 | <-US/docs/Mozilla/Tech/XUL/Props/novalidate>
 | <-US/docs/Mozilla/Tech/XUL/Props/pattern>
 | <-US/docs/Mozilla/Tech/XUL/Props/readonly>
 | <-US/docs/Mozilla/Tech/XUL/Props/required>
 | <-US/docs/Mozilla/Tech/XUL/Props/size>
 | <-US/docs/Mozilla/Tech/XUL/Props/for>
 | <-US/docs/Mozilla/Tech/XUL/Props/form>
 | <-US/docs/Mozilla/Tech/XUL/Props/max>
 | <-US/docs/Mozilla/Tech/XUL/Props/min>
 | <-US/docs/Mozilla/Tech/XUL/Props/step>
 | <-US/docs/Mozilla/Tech/XUL/Props/cols>
 | <-US/docs/Mozilla/Tech/XUL/Props/rows>
 | <-US/docs/Mozilla/Tech/XUL/Props/wrap>
 | <-US/docs/Mozilla/Tech/XUL/Props/target>
 | <-US/docs/Mozilla/Tech/XUL/Props/download>
 | <-US/docs/Mozilla/Tech/XUL/Props/downloadAs>
 | <-US/docs/Mozilla/Tech/XUL/Props/hreflang>
 | <-US/docs/Mozilla/Tech/XUL/Props/media>
 | <-US/docs/Mozilla/Tech/XUL/Props/ping>
 | <-US/docs/Mozilla/Tech/XUL/Props/rel>
 | <-US/docs/Mozilla/Tech/XUL/Props/ismap>
 | <-US/docs/Mozilla/Tech/XUL/Props/usemap>
 | <-US/docs/Mozilla/Tech/XUL/Props/coords>
 | <-US/docs/Mozilla/Tech/XUL/Props/src>
 | <-US/docs/Mozilla/Tech/XUL/Props/height>
 | <-US/docs/Mozilla/Tech/XUL/Props/alt>
 | <-US/docs/Mozilla/Tech/XUL/Props/autoplay>
 | <-US/docs/Mozilla/Tech/XUL/Props/controls>
 | <-US/docs/Mozilla/Tech/XUL/Props/loop>
 | <-US/docs/Mozilla/Tech/XUL/Props/preload>
 | <-US/docs/Mozilla/Tech/XUL/Props/poster>
 | <-US/docs/Mozilla/Tech/XUL/Props/default>
 | <-US/docs/Mozilla/Tech/XUL/Props/kind>
 | <-US/docs/Mozilla/Tech/XUL/Props/srclang>
 | <-US/docs/Mozilla/Tech/XUL/Props/sandbox>
 | <-US/docs/Mozilla/Tech/XUL/Props/seamless>
 | <-US/docs/Mozilla/Tech/XUL/Props/srcdoc>
 | <-US/docs/Mozilla/Tech/XUL/Props/reversed>
 | <-US/docs/Mozilla/Tech/XUL/Props/start>
 | <-US/docs/Mozilla/Tech/XUL/Props/align>
 | <-US/docs/Mozilla/Tech/XUL/Props/colspan>
 | <-US/docs/Mozilla/Tech/XUL/Props/rowspan>
 | <-US/docs/Mozilla/Tech/XUL/Props/headers>
 | <-US/docs/Mozilla/Tech/XUL/Props/scope>
 | <-US/docs/Mozilla/Tech/XUL/Props/async>
 | <-US/docs/Mozilla/Tech/XUL/Props/charset>
 | <-US/docs/Mozilla/Tech/XUL/Props/content>
 | <-US/docs/Mozilla/Tech/XUL/Props/defer>
 | <-US/docs/Mozilla/Tech/XUL/Props/httpEquiv>
 | <-US/docs/Mozilla/Tech/XUL/Props/language>
 | <-US/docs/Mozilla/Tech/XUL/Props/scoped>
 | <-US/docs/Mozilla/Tech/XUL/Props/type>
 | <-US/docs/Mozilla/Tech/XUL/Props/name>
 | <-US/docs/Mozilla/Tech/XUL/Props/href>
 | <-US/docs/Mozilla/Tech/XUL/Props/id>
 | <-US/docs/Mozilla/Tech/XUL/Props/placeholder>
 | <-US/docs/Mozilla/Tech/XUL/Props/checked>
 | Set "autofocus" property
 <-US/docs/Mozilla/Tech/XUL/Props/autofocus>
 | Set "className" property
 <-US/docs/Web/API/Element/className>

module Concur.Replica.DOM.Props where

import qualified Data.Text                as T

import           Replica.VDOM             (DOMEvent)

data Prop a
  = PropText T.Text
  | PropBool Bool
  | PropEvent (DOMEvent -> a)
  | PropMap [Props a]
  deriving Functor

data Props a = Props T.Text (Prop a)
  deriving Functor

boolProp :: T.Text -> Bool -> Props a
boolProp k v = Props k (PropBool v)

textProp :: T.Text -> T.Text -> Props a
textProp k v = Props k (PropText v)

key :: T.Text -> Props a
key v = textProp "key" v

style :: [(T.Text, T.Text)] -> Props a
style m = Props "style" (PropMap [ Props k (PropText v) | (k, v) <- m ])

  > div [ classList [ ( " empty " , null items ) ] [ ]
classList ::  [(T.Text, Bool)] -> Props a
classList xs = textProp "class" $ T.intercalate " " [ t | (t, True) <- xs ]

title ::  T.Text -> Props a
title = textProp "title"

selected ::  Bool -> Props a
selected = boolProp "selected"

hidden ::  Bool -> Props a
hidden             = boolProp "hidden"

value ::  T.Text -> Props a
value             = textProp "value"

defaultValue ::  T.Text -> Props a
defaultValue      = textProp "defaultValue"

accept ::  T.Text -> Props a
accept            = textProp "accept"

acceptCharset ::  T.Text -> Props a
acceptCharset     = textProp "acceptCharset"

a_ ::  T.Text -> Props a
a_            = textProp "a"

autocomplete ::  Bool -> Props a
autocomplete b = textProp "autocomplete" (if b then "on" else "off")

autosave ::  T.Text -> Props a
autosave          = textProp "autosave"

disabled ::  Bool -> Props a
disabled          = boolProp "disabled"

enctype ::  T.Text -> Props a
enctype           = textProp "enctype"

formation ::  T.Text -> Props a
formation         = textProp "formation"

list ::  T.Text -> Props a
list              = textProp "list"

maxlength ::  T.Text -> Props a
maxlength         = textProp "maxlength"

minlength ::  T.Text -> Props a
minlength         = textProp "minlength"

method ::  T.Text -> Props a
method            = textProp "method"

multiple ::  Bool -> Props a
multiple          = boolProp "multiple"

novalidate ::  Bool -> Props a
novalidate        = boolProp "noValidate"

pattern ::  T.Text -> Props a
pattern           = textProp "pattern"

readonly ::  Bool -> Props a
readonly          = boolProp "readOnly"

required ::  Bool -> Props a
required          = boolProp "required"

size ::  T.Text -> Props a
size              = textProp "size"

for ::  T.Text -> Props a
for               = textProp "for"

form_ ::  T.Text -> Props a
form_               = textProp "form"

max ::  T.Text -> Props a
max               = textProp "max"

min ::  T.Text -> Props a
min               = textProp "min"

step ::  T.Text -> Props a
step              = textProp "step"

cols ::  T.Text -> Props a
cols              = textProp "cols"

rows ::  T.Text -> Props a
rows              = textProp "rows"

wrap ::  T.Text -> Props a
wrap              = textProp "wrap"

target_ ::  T.Text -> Props a
target_            = textProp "target"

download ::  T.Text -> Props a
download          = textProp "download"

downloadAs ::  T.Text -> Props a
downloadAs        = textProp "downloadAs"

hreflang ::  T.Text -> Props a
hreflang          = textProp "hreflang"

media ::  T.Text -> Props a
media             = textProp "media"

ping ::  T.Text -> Props a
ping              = textProp "ping"

rel ::  T.Text -> Props a
rel               = textProp "rel"

ismap ::  T.Text -> Props a
ismap             = textProp "ismap"

usemap ::  T.Text -> Props a
usemap            = textProp "usemap"

  | < -US/docs/Mozilla/Tech/XUL/Props/shape >
shape ::  T.Text -> Props a
shape             = textProp "shape"

coords ::  T.Text -> Props a
coords            = textProp "coords"

src ::  T.Text -> Props a
src               = textProp "src"

height ::  T.Text -> Props a
height            = textProp "height"

  | < -US/docs/Mozilla/Tech/XUL/Props/width >
width ::  T.Text -> Props a
width             = textProp "width"

alt ::  T.Text -> Props a
alt               = textProp "alt"

autoplay ::  Bool -> Props a
autoplay          = boolProp "autoplay"

controls ::  Bool -> Props a
controls          = boolProp "controls"

loop ::  Bool -> Props a
loop              = boolProp "loop"

preload ::  T.Text -> Props a
preload           = textProp "preload"

poster ::  T.Text -> Props a
poster            = textProp "poster"

default_ ::  Bool -> Props a
default_           = boolProp "default"

kind ::  T.Text -> Props a
kind              = textProp "kind"

srclang ::  T.Text -> Props a
srclang           = textProp "srclang"

sandbox ::  T.Text -> Props a
sandbox           = textProp "sandbox"

seamless ::  T.Text -> Props a
seamless          = textProp "seamless"

srcdoc ::  T.Text -> Props a
srcdoc            = textProp "srcdoc"

reversed ::  T.Text -> Props a
reversed          = textProp "reversed"

start ::  T.Text -> Props a
start             = textProp "start"

align ::  T.Text -> Props a
align             = textProp "align"

colspan ::  T.Text -> Props a
colspan           = textProp "colspan"

rowspan ::  T.Text -> Props a
rowspan           = textProp "rowspan"

headers ::  T.Text -> Props a
headers           = textProp "headers"

scope ::  T.Text -> Props a
scope             = textProp "scope"

async ::  T.Text -> Props a
async             = textProp "async"

charset ::  T.Text -> Props a
charset           = textProp "charset"

content ::  T.Text -> Props a
content           = textProp "content"

defer ::  T.Text -> Props a
defer             = textProp "defer"

httpEquiv ::  T.Text -> Props a
httpEquiv         = textProp "httpEquiv"

language ::  T.Text -> Props a
language          = textProp "language"

scoped ::  T.Text -> Props a
scoped            = textProp "scoped"

type_ ::  T.Text -> Props a
type_ = textProp "type"

name ::  T.Text -> Props a
name = textProp "name"

href ::  T.Text -> Props a
href = textProp "href"

id ::  T.Text -> Props a
id = textProp "id"

placeholder ::  T.Text -> Props a
placeholder = textProp "placeholder"

checked ::  Bool -> Props a
checked = boolProp "checked"

autofocus ::  Bool -> Props a
autofocus = boolProp "autofocus"

className ::  T.Text -> Props a
className = textProp "class"
