{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Matterhorn.Draw.ThemeListWindow
  ( drawThemeListWindow
  )
where

import           Prelude ()
import           Matterhorn.Prelude

import           Brick
import           Brick.Keybindings
import qualified Brick.Widgets.List as L
import           Brick.Widgets.Border ( hBorder )
import           Brick.Widgets.Center ( hCenter )

import           Network.Mattermost.Types ( TeamId )

import           Matterhorn.Draw.ListWindow ( drawListWindow, WindowPosition(..) )
import           Matterhorn.Themes
import           Matterhorn.Types


drawThemeListWindow :: ChatState -> TeamId -> Widget Name
drawThemeListWindow :: ChatState -> TeamId -> Widget Name
drawThemeListWindow ChatState
st TeamId
tId =
    let window :: Widget Name
window = ListWindowState InternalTheme ()
-> (() -> Widget Name)
-> (() -> Widget Name)
-> (() -> Widget Name)
-> (Bool -> InternalTheme -> Widget Name)
-> Maybe (Widget Name)
-> WindowPosition
-> Int
-> Widget Name
forall a b.
ListWindowState a b
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (Bool -> a -> Widget Name)
-> Maybe (Widget Name)
-> WindowPosition
-> Int
-> Widget Name
drawListWindow (ChatState
stChatState
-> Getting
     (ListWindowState InternalTheme ())
     ChatState
     (ListWindowState InternalTheme ())
-> ListWindowState InternalTheme ()
forall s a. s -> Getting a s a -> a
^.TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const (ListWindowState InternalTheme ()) TeamState)
 -> ChatState -> Const (ListWindowState InternalTheme ()) ChatState)
-> ((ListWindowState InternalTheme ()
     -> Const
          (ListWindowState InternalTheme ())
          (ListWindowState InternalTheme ()))
    -> TeamState -> Const (ListWindowState InternalTheme ()) TeamState)
-> Getting
     (ListWindowState InternalTheme ())
     ChatState
     (ListWindowState InternalTheme ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ListWindowState InternalTheme ()
 -> Const
      (ListWindowState InternalTheme ())
      (ListWindowState InternalTheme ()))
-> TeamState -> Const (ListWindowState InternalTheme ()) TeamState
Lens' TeamState (ListWindowState InternalTheme ())
tsThemeListWindow)
                                  (Widget Name -> () -> Widget Name
forall a b. a -> b -> a
const (Widget Name -> () -> Widget Name)
-> Widget Name -> () -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt Text
"Themes")
                                  (Widget Name -> () -> Widget Name
forall a b. a -> b -> a
const (Widget Name -> () -> Widget Name)
-> Widget Name -> () -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt Text
"No matching themes found.")
                                  (Widget Name -> () -> Widget Name
forall a b. a -> b -> a
const (Widget Name -> () -> Widget Name)
-> Widget Name -> () -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt Text
"Search built-in themes:")
                                  Bool -> InternalTheme -> Widget Name
renderInternalTheme
                                  (Widget Name -> Maybe (Widget Name)
forall a. a -> Maybe a
Just Widget Name
forall {n}. Widget n
footer)
                                  WindowPosition
WindowUpperRight
                                  Int
50
        footer :: Widget n
footer = Widget n
forall {n}. Widget n
hBorder Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=>
                 (Widget n -> Widget n
forall n. Widget n -> Widget n
hCenter (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ [Widget n] -> Widget n
forall n. [Widget n] -> Widget n
hBox [ Widget n
forall {n}. Widget n
enter
                                 , Text -> Widget n
forall n. Text -> Widget n
txt (Text -> Widget n) -> Text -> Widget n
forall a b. (a -> b) -> a -> b
$ Text
":choose theme  "
                                 , Widget n
forall {n}. Widget n
close
                                 , Text -> Widget n
forall n. Text -> Widget n
txt Text
":close"
                                 ])
        enter :: Widget n
enter = Widget n -> Widget n
forall n. Widget n -> Widget n
emph (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Text -> Widget n
forall n. Text -> Widget n
txt (Text -> Widget n) -> Text -> Widget n
forall a b. (a -> b) -> a -> b
$ Maybe Binding -> Text
ppMaybeBinding (KeyConfig KeyEvent -> KeyEvent -> Maybe Binding
forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
ActivateListItemEvent)
        close :: Widget n
close = Widget n -> Widget n
forall n. Widget n -> Widget n
emph (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Text -> Widget n
forall n. Text -> Widget n
txt (Text -> Widget n) -> Text -> Widget n
forall a b. (a -> b) -> a -> b
$ Maybe Binding -> Text
ppMaybeBinding (KeyConfig KeyEvent -> KeyEvent -> Maybe Binding
forall k. (Show k, Ord k) => KeyConfig k -> k -> Maybe Binding
firstActiveBinding KeyConfig KeyEvent
kc KeyEvent
CancelEvent)
        kc :: KeyConfig KeyEvent
kc = ChatState
stChatState
-> Getting (KeyConfig KeyEvent) ChatState (KeyConfig KeyEvent)
-> KeyConfig KeyEvent
forall s a. s -> Getting a s a -> a
^.(ChatResources -> Const (KeyConfig KeyEvent) ChatResources)
-> ChatState -> Const (KeyConfig KeyEvent) ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const (KeyConfig KeyEvent) ChatResources)
 -> ChatState -> Const (KeyConfig KeyEvent) ChatState)
-> ((KeyConfig KeyEvent
     -> Const (KeyConfig KeyEvent) (KeyConfig KeyEvent))
    -> ChatResources -> Const (KeyConfig KeyEvent) ChatResources)
-> Getting (KeyConfig KeyEvent) ChatState (KeyConfig KeyEvent)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const (KeyConfig KeyEvent) Config)
-> ChatResources -> Const (KeyConfig KeyEvent) ChatResources
Lens' ChatResources Config
crConfiguration((Config -> Const (KeyConfig KeyEvent) Config)
 -> ChatResources -> Const (KeyConfig KeyEvent) ChatResources)
-> ((KeyConfig KeyEvent
     -> Const (KeyConfig KeyEvent) (KeyConfig KeyEvent))
    -> Config -> Const (KeyConfig KeyEvent) Config)
-> (KeyConfig KeyEvent
    -> Const (KeyConfig KeyEvent) (KeyConfig KeyEvent))
-> ChatResources
-> Const (KeyConfig KeyEvent) ChatResources
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(KeyConfig KeyEvent
 -> Const (KeyConfig KeyEvent) (KeyConfig KeyEvent))
-> Config -> Const (KeyConfig KeyEvent) Config
Lens' Config (KeyConfig KeyEvent)
configUserKeysL
        emph :: Widget n -> Widget n
emph = AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr
    in Widget Name -> Widget Name
forall n. Widget n -> Widget n
joinBorders Widget Name
window

renderInternalTheme :: Bool -> InternalTheme -> Widget Name
renderInternalTheme :: Bool -> InternalTheme -> Widget Name
renderInternalTheme Bool
foc InternalTheme
it =
    (if Bool
foc then AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
forceAttr AttrName
L.listSelectedFocusedAttr else Widget Name -> Widget Name
forall a. a -> a
id) (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
    (Padding -> Widget Name -> Widget Name
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
     AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
clientEmphAttr (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
     Text -> Widget Name
forall n. Text -> Widget n
txt (Text -> Widget Name) -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ InternalTheme -> Text
internalThemeName InternalTheme
it) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=>
    (Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
2 (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$
     (Padding -> Widget Name -> Widget Name
forall n. Padding -> Widget n -> Widget n
padLeft (Int -> Padding
Pad Int
2) (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txtWrap (Text -> Widget Name) -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ InternalTheme -> Text
internalThemeDesc InternalTheme
it) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=> Char -> Widget Name
forall n. Char -> Widget n
fill Char
' ')