{-# LANGUAGE NamedFieldPuns #-}

module FortyTwo.Renderers.Select (renderOptions, renderOption) where

import Control.Monad.IO.Class

import FortyTwo.Types (Option(..), Options)
import System.Console.ANSI
import FortyTwo.Utils (addBreakingLinesSpacing)
import FortyTwo.Constants

-- | Render all the options collection
renderOptions :: MonadIO m => Options -> m ()
renderOptions :: forall (m :: * -> *). MonadIO m => Options -> m ()
renderOptions = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ forall (m :: * -> *). MonadIO m => Option -> m ()
renderOption

-- | Render a single option items
renderOption :: MonadIO m => Option -> m ()
renderOption :: forall (m :: * -> *). MonadIO m => Option -> m ()
renderOption Option { Bool
isFocused :: Option -> Bool
isFocused :: Bool
isFocused, String
value :: Option -> String
value :: String
value } = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
  if Bool
isFocused then do
    [SGR] -> IO ()
setSGR [ConsoleLayer -> ColorIntensity -> Color -> SGR
SetColor ConsoleLayer
Foreground ColorIntensity
Dull Color
Cyan]
    String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords [[Char
focusIcon], String
text]
    [SGR] -> IO ()
setSGR [SGR
Reset]
  else
    String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
separator forall a. [a] -> [a] -> [a]
++ String
text
  where
    separator :: String
separator = String
"  "
    text :: String
text = String -> String -> String
addBreakingLinesSpacing String
separator String
value