{-# Language BangPatterns #-}
{-|
Module      : Client.View
Description : View selection module
Copyright   : (c) Eric Mertens, 2016
License     : ISC
Maintainer  : emertens@gmail.com

This module selects the correct view based on the current state.

-}
module Client.View
  ( viewLines
  ) where

import           Client.Image.PackedImage
import           Client.State
import           Client.State.Focus
import           Client.View.Cert
import           Client.View.ChannelInfo
import           Client.View.Digraphs
import           Client.View.Help
import           Client.View.IgnoreList
import           Client.View.KeyMap
import           Client.View.MaskList
import           Client.View.Mentions
import           Client.View.Messages
import           Client.View.Palette
import           Client.View.RtsStats
import           Client.View.UrlSelection
import           Client.View.UserList
import           Client.View.Windows
import           Control.Lens

viewLines :: Focus -> Subfocus -> Int -> ClientState -> [Image']
viewLines :: Focus -> Subfocus -> Int -> ClientState -> [Image']
viewLines Focus
focus Subfocus
subfocus Int
w !ClientState
st =
  case (Focus
focus, Subfocus
subfocus) of
    (Focus, Subfocus)
_ | Just (String
"url",String
arg) <- ClientState -> Maybe (String, String)
clientActiveCommand ClientState
st ->
      Int -> Focus -> String -> ClientState -> [Image']
urlSelectionView Int
w Focus
focus String
arg ClientState
st
    (ChannelFocus Text
network Identifier
channel, Subfocus
FocusInfo) ->
      Text -> Identifier -> ClientState -> [Image']
channelInfoImages Text
network Identifier
channel ClientState
st
    (ChannelFocus Text
network Identifier
channel, Subfocus
FocusUsers)
      | Getting Bool ClientState Bool -> ClientState -> Bool
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Bool ClientState Bool
Lens' ClientState Bool
clientDetailView ClientState
st -> Text -> Identifier -> ClientState -> [Image']
userInfoImages Text
network Identifier
channel ClientState
st
      | Bool
otherwise                -> Text -> Identifier -> Int -> ClientState -> [Image']
userListImages Text
network Identifier
channel Int
w ClientState
st
    (ChannelFocus Text
network Identifier
channel, FocusMasks Char
mode) ->
      Char -> Text -> Identifier -> Int -> ClientState -> [Image']
maskListImages Char
mode Text
network Identifier
channel Int
w ClientState
st
    (Focus
_, FocusWindows WindowsFilter
filt) -> WindowsFilter -> ClientState -> [Image']
windowsImages WindowsFilter
filt ClientState
st
    (Focus
_, Subfocus
FocusMentions)     -> Int -> ClientState -> [Image']
mentionsViewLines Int
w ClientState
st
    (Focus
_, Subfocus
FocusPalette)      -> Palette -> [Image']
paletteViewLines Palette
pal
    (Focus
_, Subfocus
FocusDigraphs)     -> Int -> ClientState -> [Image']
digraphLines Int
w ClientState
st
    (Focus
_, Subfocus
FocusKeyMap)       -> ClientState -> [Image']
keyMapLines ClientState
st
    (Focus
_, FocusHelp Maybe Text
mb)      -> ClientState -> Maybe Text -> Palette -> [Image']
helpImageLines ClientState
st Maybe Text
mb Palette
pal
    (Focus
_, Subfocus
FocusRtsStats)     -> Maybe Stats -> Palette -> [Image']
rtsStatsLines (Getting (Maybe Stats) ClientState (Maybe Stats)
-> ClientState -> Maybe Stats
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Maybe Stats) ClientState (Maybe Stats)
Lens' ClientState (Maybe Stats)
clientRtsStats ClientState
st) Palette
pal
    (Focus
_, Subfocus
FocusIgnoreList)   -> HashSet Identifier -> Palette -> [Image']
ignoreListLines (Getting (HashSet Identifier) ClientState (HashSet Identifier)
-> ClientState -> HashSet Identifier
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (HashSet Identifier) ClientState (HashSet Identifier)
Lens' ClientState (HashSet Identifier)
clientIgnores ClientState
st) Palette
pal
    (Focus
_, Subfocus
FocusCert)         -> ClientState -> [Image']
certViewLines ClientState
st
    (Focus, Subfocus)
_ -> Focus -> Int -> ClientState -> [Image']
chatMessageImages Focus
focus Int
w ClientState
st
  where
    pal :: Palette
pal = ClientState -> Palette
clientPalette ClientState
st