{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes       #-}

module PrettyPrint where

import           Data.Function    ((&))
import           Data.Monoid      ((<>))
import           Data.String.Here
import           Data.Text        (Text)
import qualified Data.Text        as T
import           Hexon
import           Hexon.Types

format_id :: Either String RID -> Text
format_id (Left _) = "meh."
format_id (Right result) = [i|
${top}
${banner_top}
${banner_name}
${banner_bottom}

• By ${username}
• ${date}
${display_comments}
|]
    where
        msg      = result |> rid_message
        name     = result |> rid_info |> info_name
        username = result |> rid_info |> info_username
        date     = result |> rid_info |> info_date
        comments = result |> rid_info |> info_comments

        pre :: Text
        pre      = case msg of
                    "error" ->
                        "Item not available :("
                    "success" ->
                        "*Item available!*"
                    _ -> ""

        nlength          = T.length name + 2
        top              = "\ESC[1m" <> pre <> "\STX"
        banner_top       = "┌" <> (T.replicate nlength "─") <> "┐"
        banner_name      = "│ " <> name <> " │"
        banner_bottom    = "└" <> (T.replicate nlength "─") <> "┘"
        display_comments = fmap ("• " <>) (T.splitOn "\n" comments)


-- format_add :: Either String RItem -> Text
-- format_add (Left _)       = "meh."
-- format_add (Right result) = undefined

-- format_del :: Either String RID -> Text
-- format_del (Left _)       = "meh."
-- format_del (Right result) = undefined

-- format_auth :: Either String RAuth -> Text
-- format_auth (Left _)       = "meh."
-- format_auth (Right result) = undefined

-- format_comment :: Either String RComment -> Text
-- format_comment (Left _)       = "meh"
-- format_comment (Right result) = undefined
