{-# Language OverloadedStrings #-}
{-|
Module      : Client.View.IgnoreList
Description : Line renderers for ignore mask list view
Copyright   : (c) Eric Mertens, 2016
License     : ISC
Maintainer  : emertens@gmail.com

This module renders the lines used to list the ignore masks.
-}
module Client.View.IgnoreList
  ( ignoreListLines
  ) where

import           Client.Image.PackedImage
import           Client.Image.Palette
import           Client.Image.Message
import           Graphics.Vty.Attributes
import           Irc.Identifier
import           Data.HashSet (HashSet)
import           Data.Foldable
import           Control.Lens

-- | Render the lines used in a channel mask list.
ignoreListLines ::
  HashSet Identifier {- ^ ignore masks -} ->
  Palette            {- ^ palette      -} ->
  [Image']
ignoreListLines :: HashSet Identifier -> Palette -> [Image']
ignoreListLines HashSet Identifier
ignores Palette
pal =
  HashSet Identifier -> Palette -> Image'
summaryLine HashSet Identifier
ignores Palette
pal Image' -> [Image'] -> [Image']
forall a. a -> [a] -> [a]
:
  [ Attr -> Text -> Image'
text' Attr
defAttr (Text -> Text
cleanText (Identifier -> Text
idText Identifier
mask)) | Identifier
mask <- HashSet Identifier -> [Identifier]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList HashSet Identifier
ignores ]


-- | Render a summary describing the number of ignore masks.
summaryLine ::
  HashSet Identifier {- ^ ignore masks -} ->
  Palette            {- ^ palette      -} ->
  Image'
summaryLine :: HashSet Identifier -> Palette -> Image'
summaryLine HashSet Identifier
ignores Palette
pal
  | HashSet Identifier -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null HashSet Identifier
ignores = Attr -> Text -> Image'
text' (Getting Attr Palette Attr -> Palette -> Attr
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Attr Palette Attr
Lens' Palette Attr
palError Palette
pal) Text
"Ignore list empty"
  | Bool
otherwise    = Attr -> Text -> Image'
text' (Getting Attr Palette Attr -> Palette -> Attr
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Attr Palette Attr
Lens' Palette Attr
palLabel Palette
pal) Text
"Ignore entries: "
                Image' -> Image' -> Image'
forall a. Semigroup a => a -> a -> a
<> Attr -> String -> Image'
string Attr
defAttr (Int -> String
forall a. Show a => a -> String
show (HashSet Identifier -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length HashSet Identifier
ignores))