{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RecursiveDo     #-}

module Potato.Flow.Vty.Info (
  InfoWidgetConfig(..)
  , InfoWidget(..)
  , holdInfoWidget
) where

import           Relude

import           Potato.Flow
import           Potato.Reflex.Vty.Helpers

import           Reflex
import           Reflex.Network
import           Reflex.Vty



data InfoWidgetConfig t = InfoWidgetConfig {
  forall t. InfoWidgetConfig t -> Dynamic t Selection
_infoWidgetConfig_selection :: Dynamic t Selection
}

data InfoWidget t = InfoWidget {
}

holdInfoWidget :: forall t m. (MonadWidget t m)
  => InfoWidgetConfig t
  -> m (InfoWidget t)
holdInfoWidget :: forall t (m :: * -> *).
MonadWidget t m =>
InfoWidgetConfig t -> m (InfoWidget t)
holdInfoWidget InfoWidgetConfig {Dynamic t Selection
_infoWidgetConfig_selection :: Dynamic t Selection
_infoWidgetConfig_selection :: forall t. InfoWidgetConfig t -> Dynamic t Selection
..} = do
  let
    -- TODO read canvasSelection and figure out what the preset is
    infoDyn :: Dynamic t (m ())
infoDyn = forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
ffor Dynamic t Selection
_infoWidgetConfig_selection forall a b. (a -> b) -> a -> b
$ \selection :: Selection
selection@(SuperOwlParliament Seq SuperOwl
sowls) -> case () of
      ()
_ | forall a. IsParliament a => a -> Int
isParliament_length Selection
selection forall a. Eq a => a -> a -> Bool
== Int
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
      ()
_ | forall a. IsParliament a => a -> Int
isParliament_length Selection
selection forall a. Ord a => a -> a -> Bool
> Int
1 -> forall {k} (t :: k) (m :: * -> *).
(Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m,
 HasTheme t m) =>
Behavior t Text -> m ()
text Behavior t Text
"many"
      ()
_ -> do
        let
          sowl :: SuperOwl
sowl = HasCallStack => CanvasSelection -> SuperOwl
selectionToSuperOwl (Seq SuperOwl -> CanvasSelection
CanvasSelection Seq SuperOwl
sowls)
          rid :: Int
rid = SuperOwl -> Int
_superOwl_id SuperOwl
sowl
          label :: Text
label = forall o. HasOwlItem o => o -> Text
hasOwlItem_name SuperOwl
sowl
          selt :: SElt
selt = SuperOwl -> SElt
superOwl_toSElt_hack SuperOwl
sowl
        forall t (m :: * -> *) a.
(HasDisplayRegion t m, MonadFix m) =>
Layout t m a -> m a
initLayout forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k) (m :: * -> *) a.
(Reflex t, MonadFix m, HasLayout t m) =>
m a -> m a
col forall a b. (a -> b) -> a -> b
$ do
          (forall {k} (m :: * -> *) (t :: k) a.
(MonadFix m, MonadHold t m, HasLayout t m, HasInput t m,
 HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m) =>
Dynamic t Constraint -> m a -> m a
grout forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: k).
Reflex t =>
Dynamic t Int -> Dynamic t Constraint
fixed) Dynamic t Int
1 forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k) (m :: * -> *).
(Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m,
 HasTheme t m) =>
Behavior t Text -> m ()
text (forall {k} (t :: k) a. Reflex t => a -> Behavior t a
constant (Text
"rid: " forall a. Semigroup a => a -> a -> a
<> forall b a. (Show a, IsString b) => a -> b
show Int
rid forall a. Semigroup a => a -> a -> a
<> Text
" name: " forall a. Semigroup a => a -> a -> a
<> Text
label))
          case SElt
selt of
            SEltBox SBox {SuperStyle
SBoxTitle
SBoxText
SBoxType
LBox
_sBox_box :: SBox -> LBox
_sBox_superStyle :: SBox -> SuperStyle
_sBox_title :: SBox -> SBoxTitle
_sBox_text :: SBox -> SBoxText
_sBox_boxType :: SBox -> SBoxType
_sBox_boxType :: SBoxType
_sBox_text :: SBoxText
_sBox_title :: SBoxTitle
_sBox_superStyle :: SuperStyle
_sBox_box :: LBox
..} -> (forall {k} (m :: * -> *) (t :: k) a.
(MonadFix m, MonadHold t m, HasLayout t m, HasInput t m,
 HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m) =>
Dynamic t Constraint -> m a -> m a
grout forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: k).
Reflex t =>
Dynamic t Int -> Dynamic t Constraint
fixed) Dynamic t Int
1 forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k) (m :: * -> *).
(Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m,
 HasTheme t m) =>
Behavior t Text -> m ()
text (forall {k} (t :: k) a. Reflex t => a -> Behavior t a
constant (SBoxText -> Text
_sBoxText_text SBoxText
_sBox_text))
            SElt
_                 -> (forall {k} (m :: * -> *) (t :: k) a.
(MonadFix m, MonadHold t m, HasLayout t m, HasInput t m,
 HasImageWriter t m, HasDisplayRegion t m, HasFocusReader t m) =>
Dynamic t Constraint -> m a -> m a
grout forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (t :: k).
Reflex t =>
Dynamic t Int -> Dynamic t Constraint
fixed) Dynamic t Int
1 forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k) (m :: * -> *).
(Reflex t, Monad m, HasDisplayRegion t m, HasImageWriter t m,
 HasTheme t m) =>
Behavior t Text -> m ()
text (forall {k} (t :: k) a. Reflex t => a -> Behavior t a
constant Text
"something else")

  forall t (m :: * -> *) a.
(NotReady t m, Adjustable t m, PostBuild t m) =>
Dynamic t (m a) -> m (Event t a)
networkView Dynamic t (m ())
infoDyn

  return InfoWidget {}