module Handler.Utils.Templates where

import Data.Either (isLeft)

import Import.NoFoundation

modal :: WidgetT site IO () -> Either (SomeRoute site) (WidgetT site IO ()) -> WidgetT site IO ()
modal modalTrigger modalContent = do
  let modalDynamic = isLeft modalContent
  modalId <- newIdent
  triggerId <- newIdent
  $(widgetFile "widgets/modal")
  case modalContent of
    Left  route -> do
      route' <- toTextUrl route
      [whamlet|
        $newline never
        <a .modal__trigger href=#{route'} ##{triggerId}>
          <span .modal__trigger-label>^{modalTrigger}
      |]
    Right _     -> -- do
      [whamlet|
        $newline never
        <div .modal__trigger ##{triggerId}>
          <span .modal__trigger-label>^{modalTrigger}
      |]
