-- | Document language for lesson plan notebooks.
module Drasil.DocumentLanguage.Notebook.DocumentLanguage(mkNb) where

import Drasil.DocumentLanguage.Notebook.NBDecl (NBDecl, mkNBDesc)
import Drasil.DocumentLanguage.Notebook.Core (ApndxSec(..), NBDesc, DocSection(..), 
  IntrodSec(..), IntrodSub(..), BodySec(..), BodySub(..), SmmrySec(..))

import Language.Drasil

import SysInfo.Drasil (SystemInformation(SI), _authors, _kind, _sys, citeDB)

import qualified Drasil.DocLang.Notebook as NB (appendix, body, reference, summary)
import qualified Drasil.NBSections.Introduction as Intro (introductionSection, purposeOfDoc)
import qualified Drasil.NBSections.Body as Body (reviewSec, mainIdeaSec, mthdAndanls, exampleSec)

-- | Creates a notebook from a document description and system information.
mkNb :: NBDecl -> (IdeaDict -> IdeaDict -> Sentence) -> SystemInformation -> Document
mkNb :: NBDecl
-> (IdeaDict -> IdeaDict -> Sentence)
-> SystemInformation
-> Document
mkNb dd :: NBDecl
dd comb :: IdeaDict -> IdeaDict -> Sentence
comb si :: SystemInformation
si@SI {_sys :: ()
_sys = a
sys, _kind :: ()
_kind = b
kind, _authors :: ()
_authors = [c]
authors} =
  Sentence -> Sentence -> [Section] -> Document
Notebook (b -> IdeaDict
forall c. Idea c => c -> IdeaDict
nw b
kind IdeaDict -> IdeaDict -> Sentence
`comb` a -> IdeaDict
forall c. Idea c => c -> IdeaDict
nw a
sys) (SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List ([Sentence] -> Sentence) -> [Sentence] -> Sentence
forall a b. (a -> b) -> a -> b
$ (c -> Sentence) -> [c] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S (String -> Sentence) -> (c -> String) -> c -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> String
forall n. HasName n => n -> String
name) [c]
authors) ([Section] -> Document) -> [Section] -> Document
forall a b. (a -> b) -> a -> b
$
  SystemInformation -> NBDesc -> [Section]
mkSections SystemInformation
si NBDesc
l where
    l :: NBDesc
l = SystemInformation -> NBDecl -> NBDesc
mkNBDesc SystemInformation
si NBDecl
dd

-- | Helper for creating the notebook sections.
-- Add NBDesc for references.
mkSections :: SystemInformation -> NBDesc -> [Section]
mkSections :: SystemInformation -> NBDesc -> [Section]
mkSections si :: SystemInformation
si = (DocSection -> Section) -> NBDesc -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map DocSection -> Section
doit  
  where
    doit :: DocSection -> Section
    doit :: DocSection -> Section
doit (IntrodSec is :: IntrodSec
is)      = SystemInformation -> IntrodSec -> Section
mkIntroSec SystemInformation
si IntrodSec
is
    doit (BodySec bs :: BodySec
bs)        = BodySec -> Section
mkBodySec BodySec
bs
    doit (SmmrySec ss :: SmmrySec
ss)       = SmmrySec -> Section
mkSmmrySec SmmrySec
ss
    doit BibSec              = BibRef -> Section
mkBib (SystemInformation -> BibRef
citeDB SystemInformation
si)
    doit (ApndxSec a :: ApndxSec
a)        = ApndxSec -> Section
mkAppndxSec ApndxSec
a

-- Add more intro subsections
-- | Helper for making the 'Introduction' section.
mkIntroSec :: SystemInformation -> IntrodSec -> Section
mkIntroSec :: SystemInformation -> IntrodSec -> Section
mkIntroSec si :: SystemInformation
si (IntrodProg probIntro :: [Contents]
probIntro l :: [IntrodSub]
l) =
  [Contents] -> [Section] -> Section
Intro.introductionSection [Contents]
probIntro ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (IntrodSub -> Section) -> [IntrodSub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map (SystemInformation -> IntrodSub -> Section
mkSubIntro SystemInformation
si) [IntrodSub]
l
  where
    mkSubIntro :: SystemInformation -> IntrodSub -> Section
    mkSubIntro :: SystemInformation -> IntrodSub -> Section
mkSubIntro _ (InPurpose intro :: [Sentence]
intro) = [Sentence] -> Section
Intro.purposeOfDoc [Sentence]
intro

-- | Helper for making the 'Body' section.
mkBodySec :: BodySec -> Section
mkBodySec :: BodySec -> Section
mkBodySec (BodyProg l :: [BodySub]
l) = [Contents] -> [Section] -> Section
NB.body [] ([Section] -> Section) -> [Section] -> Section
forall a b. (a -> b) -> a -> b
$ (BodySub -> Section) -> [BodySub] -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map BodySub -> Section
mkSubs [BodySub]
l
  where
    mkSubs :: BodySub -> Section
    mkSubs :: BodySub -> Section
mkSubs (Review cs :: [Contents]
cs )                 = [Contents] -> Section
Body.reviewSec [Contents]
cs 
    mkSubs (MainIdea cntnts :: [Contents]
cntnts subsec :: [Section]
subsec)     = [Contents] -> [Section] -> Section
Body.mainIdeaSec [Contents]
cntnts [Section]
subsec
    mkSubs (MethsAndAnls cntnts :: [Contents]
cntnts subsec :: [Section]
subsec) = [Contents] -> [Section] -> Section
Body.mthdAndanls [Contents]
cntnts [Section]
subsec
    mkSubs (Example cntnts :: [Contents]
cntnts subsec :: [Section]
subsec)      = [Contents] -> [Section] -> Section
Body.exampleSec [Contents]
cntnts [Section]
subsec

-- | Helper for making the 'Summary' section.
mkSmmrySec :: SmmrySec -> Section
mkSmmrySec :: SmmrySec -> Section
mkSmmrySec (SmmryProg cs :: [Contents]
cs) = [Contents] -> [Section] -> Section
NB.summary [Contents]
cs []

-- | Helper for making the 'Bibliography' section.
mkBib :: BibRef -> Section
mkBib :: BibRef -> Section
mkBib bib :: BibRef
bib = [Contents] -> [Section] -> Section
NB.reference [UnlabelledContent -> Contents
UlC (UnlabelledContent -> Contents) -> UnlabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc (BibRef -> RawContent
Bib BibRef
bib)] []

-- | Helper for making the 'Appendix' section.
mkAppndxSec :: ApndxSec -> Section
mkAppndxSec :: ApndxSec -> Section
mkAppndxSec (ApndxProg cs :: [Contents]
cs) = [Contents] -> [Section] -> Section
NB.appendix [Contents]
cs []