{-# LANGUAGE
    OverloadedStrings
  , ExtendedDefaultRules
  , FlexibleContexts
  #-}

module Pages.Home where

import Imports
import Templates.Master

import Data.Url
import Data.Markup
import Web.Page.Lucid
import Path.Extended
import Lucid
import qualified Data.Text as T
import qualified Text.Blaze.Html.Renderer.Text as H
import qualified Text.Pandoc as P

import Control.Monad.Trans
import Control.Monad.Morph
import Control.Monad.Reader


homePage :: ( MonadApp m
            ) => WebPage (HtmlT m ()) T.Text
homePage =
  masterPage { afterStylesScripts = do
                 afterStylesScripts masterPage
                 afterStylesScripts'
             }
  where
    afterStylesScripts' =
      localStylesScripts

    localStylesScripts = do
      hostname <-envAuthority <$> lift ask
      hoist (`runAbsoluteUrlT` hostname) $ do
        elm      <- lift $ toLocation JsElm
     --   deploy JavaScript Remote elm
        return ()


homeContent :: ( MonadApp m
               ) => HtmlT m ()
homeContent =
  div_ [class_ "row"] $
    div_ [class_ "column sixteen wide"] mainPanel
  where
    mainPanel =
      div_ [ id_ "mainPanel"
           , class_ "ui inverted segment"
           ] $
        div_ [class_ "ui two column very relaxed grid stackable"] $ do
          -- Body text
          div_ [class_ "column"] $ do
            h1_ [class_ "ui inverted header"] $ do
              logo <- T.pack <$> lift (locUrl . addFileExt "png" =<< toLocation ImgLogoLight)
              img_ [ src_ logo, class_ "ui circular image"]
              div_ [class_ "content"] $ do
                "Nested-Routes"
                div_ [class_ "sub header"] "WAI Routing Library"
            div_ [id_ "cta", class_ "left aligned"] $ do
              gettingStartedLink <- T.pack <$> lift (locUrl =<< toLocation (AppDocs $ Just AppGettingStarted))
              docsIntroLink      <- T.pack <$> lift (locUrl =<< toLocation (AppDocs Nothing))
              a_ [ class_ "ui huge button orange"
                 , href_ gettingStartedLink
                 ] "Get Started"
              a_ [ class_ "ui huge button"
                 , href_ docsIntroLink
                 ] "See Documentation"
            div_ [class_ "ui divider"] ""
            mainPanelText <- envMainPanel <$> lift ask
            let opts = P.def
            renderPandoc opts mainPanelText

          div_ [class_ "ui vertical divider"] $ toHtmlRaw "&#8680;"

          -- Code sample
          div_ [class_ "column"] $ do
            codeSample <- envCodeSample <$> lift ask
            let opts = P.def { P.writerHighlight = True
                             }
            renderPandoc opts codeSample
