-- SPDX-FileCopyrightText: 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

module Handler.Utils.Table
  ( module Handler.Utils.Table
  ) where

import Import hiding (link)

import Handler.Utils.Table.Pagination as Handler.Utils.Table
import Handler.Utils.Table.Columns as Handler.Utils.Table
import Handler.Utils.Table.Cells as Handler.Utils.Table


-- | Given a header message, a bool and widget; display widget and header only if the boolean is true
maybeTable :: (RenderMessage UniWorX a)
           => a -> (Bool, Widget) -> Widget
maybeTable m = maybeTable' m Nothing Nothing

maybeTable' :: (RenderMessage UniWorX a)
           => a -> Maybe a -> Maybe Widget -> (Bool, Widget) -> Widget
maybeTable' _   Nothing       _ (False, _ ) = mempty
maybeTable' _   (Just nodata) _ (False, _ ) =
  [whamlet|
    <div .container>
      _{nodata}
  |]
maybeTable' hdr _ mbRemark      (True ,tbl) =
  [whamlet|
    <div .container>
      <h2> _{hdr}
      <div .container>
        ^{tbl}
        $maybe remark <- mbRemark
          <em>_{MsgProfileRemark}
          \ ^{remark}
  |]