module Potato.Flow.OwlHelpers where


import Relude

import Potato.Flow.SElts
import Potato.Flow.Owl
import Potato.Flow.OwlItem
import Potato.Flow.Llama
import Potato.Flow.SEltMethods

superOwl_mustGetSLine :: SuperOwl -> SAutoLine
superOwl_mustGetSLine :: SuperOwl -> SAutoLine
superOwl_mustGetSLine SuperOwl
sowl = case OwlItem -> OwlSubItem
_owlItem_subItemforall a b. (a -> b) -> a -> b
$ SuperOwl -> OwlItem
_superOwl_elt SuperOwl
sowl of
  OwlSubItemLine SAutoLine
sline -> SAutoLine
sline
  OwlSubItem
x -> forall a t. (HasCallStack, IsText t) => t -> a
error forall a b. (a -> b) -> a -> b
$ Text
"expected SAutoLine, got " forall a. Semigroup a => a -> a -> a
<> forall b a. (Show a, IsString b) => a -> b
show OwlSubItem
x forall a. Semigroup a => a -> a -> a
<> Text
" instead"

data SetLineStyleEnd = SetLineStyleEnd_Start | SetLineStyleEnd_End | SetLineStyleEnd_Both

setLineStyleEnd_setStart :: SetLineStyleEnd -> Bool
setLineStyleEnd_setStart :: SetLineStyleEnd -> Bool
setLineStyleEnd_setStart SetLineStyleEnd
SetLineStyleEnd_End = Bool
False
setLineStyleEnd_setStart SetLineStyleEnd
_ = Bool
True

setLineStyleEnd_setEnd :: SetLineStyleEnd -> Bool
setLineStyleEnd_setEnd :: SetLineStyleEnd -> Bool
setLineStyleEnd_setEnd SetLineStyleEnd
SetLineStyleEnd_Start = Bool
False
setLineStyleEnd_setEnd SetLineStyleEnd
_ = Bool
True


-- TODO move into Llama/Helpers.hs or something
makeLlamaForLineStyle :: SuperOwl -> SetLineStyleEnd -> LineStyle -> Llama
makeLlamaForLineStyle :: SuperOwl -> SetLineStyleEnd -> LineStyle -> Llama
makeLlamaForLineStyle SuperOwl
sowl SetLineStyleEnd
end LineStyle
newstyle = Llama
r where
  rid :: REltId
rid = SuperOwl -> REltId
_superOwl_id SuperOwl
sowl
  sline :: SAutoLine
sline = SuperOwl -> SAutoLine
superOwl_mustGetSLine SuperOwl
sowl
  newsline :: SAutoLine
newsline = SAutoLine
sline {
      _sAutoLine_lineStyle :: LineStyle
_sAutoLine_lineStyle = if SetLineStyleEnd -> Bool
setLineStyleEnd_setStart SetLineStyleEnd
end then LineStyle
newstyle else SAutoLine -> LineStyle
_sAutoLine_lineStyle SAutoLine
sline
      , _sAutoLine_lineStyleEnd :: LineStyle
_sAutoLine_lineStyleEnd = if SetLineStyleEnd -> Bool
setLineStyleEnd_setEnd SetLineStyleEnd
end then LineStyle
newstyle else SAutoLine -> LineStyle
_sAutoLine_lineStyleEnd SAutoLine
sline
    }
  r :: Llama
r = (REltId, SElt) -> Llama
makeSetLlama (REltId
rid, SAutoLine -> SElt
SEltLine SAutoLine
newsline)

makeLlamaForFlipLineStyle :: SuperOwl -> Maybe Llama
makeLlamaForFlipLineStyle :: SuperOwl -> Maybe Llama
makeLlamaForFlipLineStyle SuperOwl
sowl = Maybe Llama
r where
  seltl :: SEltLabel
seltl = SuperOwl -> SEltLabel
superOwl_toSEltLabel_hack SuperOwl
sowl
  startStyle :: Maybe LineStyle
startStyle = SEltLabel -> Maybe LineStyle
getSEltLabelLineStyle SEltLabel
seltl
  endStyle :: Maybe LineStyle
endStyle = SEltLabel -> Maybe LineStyle
getSEltLabelLineStyleEnd SEltLabel
seltl
  rid :: REltId
rid = SuperOwl -> REltId
_superOwl_id SuperOwl
sowl
  sline :: SAutoLine
sline = SuperOwl -> SAutoLine
superOwl_mustGetSLine SuperOwl
sowl
  newsline :: SAutoLine
newsline = SAutoLine
sline {
      _sAutoLine_lineStyle :: LineStyle
_sAutoLine_lineStyle = SAutoLine -> LineStyle
_sAutoLine_lineStyleEnd SAutoLine
sline
      , _sAutoLine_lineStyleEnd :: LineStyle
_sAutoLine_lineStyleEnd = SAutoLine -> LineStyle
_sAutoLine_lineStyle SAutoLine
sline
    }
  r :: Maybe Llama
r = if Maybe LineStyle
startStyle forall a. Eq a => a -> a -> Bool
== Maybe LineStyle
endStyle
    then forall a. Maybe a
Nothing
    else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ (REltId, SElt) -> Llama
makeSetLlama (REltId
rid, SAutoLine -> SElt
SEltLine SAutoLine
newsline)