{-# LANGUAGE OverloadedStrings #-}
module Eventlog.Rendering.Bootstrap where

import Eventlog.Rendering.Types

import Control.Monad
import Data.String
import qualified Data.Text as T
import Text.Blaze.Html5            as H
import Text.Blaze.Html5.Attributes as A
import Text.Blaze.Internal (attribute)

dataToggle :: AttributeValue -> Attribute
dataToggle :: AttributeValue -> Attribute
dataToggle = Tag -> Tag -> AttributeValue -> Attribute
attribute Tag
"data-toggle" Tag
" data-toggle=\""
{-# INLINE dataToggle #-}

dataTarget :: AttributeValue -> Attribute
dataTarget :: AttributeValue -> Attribute
dataTarget = Tag -> Tag -> AttributeValue -> Attribute
attribute Tag
"data-target" Tag
" data-target=\""
{-# INLINE dataTarget #-}

ariaControls :: AttributeValue -> Attribute
ariaControls :: AttributeValue -> Attribute
ariaControls = Tag -> Tag -> AttributeValue -> Attribute
attribute Tag
"aria-controls" Tag
" aria-controls=\""
{-# INLINE ariaControls #-}

ariaExpanded :: AttributeValue -> Attribute
ariaExpanded :: AttributeValue -> Attribute
ariaExpanded = Tag -> Tag -> AttributeValue -> Attribute
attribute Tag
"aria-expanded" Tag
" aria-expanded=\""
{-# INLINE ariaExpanded #-}

ariaLabel :: AttributeValue -> Attribute
ariaLabel :: AttributeValue -> Attribute
ariaLabel = Tag -> Tag -> AttributeValue -> Attribute
attribute Tag
"aria-label" Tag
" aria-label=\""
{-# INLINE ariaLabel #-}

navbar :: [TabGroup] -> Html
navbar :: [TabGroup] -> Html
navbar [TabGroup]
tab_groups = do
  Html -> Html
H.ul (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.id AttributeValue
"vizTabs" (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"nav nav-tabs" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
    [TabGroup] -> (TabGroup -> Html) -> Html
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [TabGroup]
tab_groups ((TabGroup -> Html) -> Html) -> (TabGroup -> Html) -> Html
forall a b. (a -> b) -> a -> b
$ \TabGroup
group -> do
      case TabGroup
group of
        SingleTab Tab
tab ->
          Html -> Html
H.li (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"nav-item" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$
            Html -> Html
H.a (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.id (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToNavItemID (Tab -> TabID
tabId Tab
tab)))
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ (Tab -> AttributeValue
tabClasses Tab
tab)
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
href (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToHref (Tab -> TabID
tabId Tab
tab)))
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
dataToggle AttributeValue
"tab"
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
dataTarget (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToHref (Tab -> TabID
tabId Tab
tab)))
                (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ String -> Html
forall a. IsString a => String -> a
fromString (Tab -> String
tabName Tab
tab)
        ManyTabs String
group_name [Tab]
tabs ->
          Html -> Html
H.li (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"nav-item dropdown" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ do
            Html -> Html
H.a (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"nav-link dropdown-toggle"
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
href AttributeValue
"#"
                (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
dataToggle AttributeValue
"dropdown"
                (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ String -> Html
forall a. IsString a => String -> a
fromString String
group_name
            Html -> Html
H.div (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"dropdown-menu" (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$
              [Tab] -> (Tab -> Html) -> Html
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Tab]
tabs ((Tab -> Html) -> Html) -> (Tab -> Html) -> Html
forall a b. (a -> b) -> a -> b
$ \Tab
tab ->
                Html -> Html
H.a (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
A.id (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToNavItemID (Tab -> TabID
tabId Tab
tab)))
                    (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
class_ AttributeValue
"dropdown-item"
                    (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
href (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToHref (Tab -> TabID
tabId Tab
tab)))
                    (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
dataToggle AttributeValue
"tab"
                    (Html -> Html) -> Attribute -> Html -> Html
forall h. Attributable h => h -> Attribute -> h
! AttributeValue -> Attribute
dataTarget (Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (TabID -> Text
tabIDToHref (Tab -> TabID
tabId Tab
tab)))
                    (Html -> Html) -> Html -> Html
forall a b. (a -> b) -> a -> b
$ String -> Html
forall a. IsString a => String -> a
fromString (Tab -> String
tabName Tab
tab)

tabClasses :: Tab -> AttributeValue
tabClasses :: Tab -> AttributeValue
tabClasses Tab
tab = Text -> AttributeValue
forall a. ToValue a => a -> AttributeValue
toValue (Text -> AttributeValue) -> Text -> AttributeValue
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
" " ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$
  Text
"nav-link" Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
:
  [ Text
"active" | Tab -> Bool
tabActive Tab
tab ] [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++
  [ Text
"not-available" | Tab -> Bool
tabDisabled Tab
tab ]