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

import Drasil.DocumentLanguage.Notebook.LsnDecl (LsnDecl, mkLsnDesc)
import Drasil.DocumentLanguage.Notebook.Core (LsnDesc, LsnChapter(..), 
  Intro(..), LearnObj(..), Review(..), CaseProb(..), Example(..), Smmry(..), Apndx(..))

import Language.Drasil hiding (kind)

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

import qualified Drasil.DocLang.Notebook as Lsn (intro, learnObj, caseProb, example, 
  appendix, review, reference, summary)

-- | Creates a notebook from a lesson description and system information.
mkNb :: LsnDecl -> (IdeaDict -> IdeaDict -> Sentence) -> SystemInformation -> Document
mkNb :: LsnDecl
-> (IdeaDict -> IdeaDict -> Sentence)
-> SystemInformation
-> Document
mkNb LsnDecl
dd 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 (forall c. Idea c => c -> IdeaDict
nw b
kind IdeaDict -> IdeaDict -> Sentence
`comb` forall c. Idea c => c -> IdeaDict
nw a
sys) (SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. HasName n => n -> String
name) [c]
authors) forall a b. (a -> b) -> a -> b
$
  SystemInformation -> LsnDesc -> [Section]
mkSections SystemInformation
si LsnDesc
l where
    l :: LsnDesc
l = SystemInformation -> LsnDecl -> LsnDesc
mkLsnDesc SystemInformation
si LsnDecl
dd

-- | Helper for creating the notebook sections.
mkSections :: SystemInformation -> LsnDesc -> [Section]
mkSections :: SystemInformation -> LsnDesc -> [Section]
mkSections SystemInformation
si = forall a b. (a -> b) -> [a] -> [b]
map LsnChapter -> Section
doit  
  where
    doit :: LsnChapter -> Section
    doit :: LsnChapter -> Section
doit (Intro Intro
i)     = Intro -> Section
mkIntro Intro
i
    doit (LearnObj LearnObj
lo) = LearnObj -> Section
mkLearnObj LearnObj
lo
    doit (Review Review
r)    = Review -> Section
mkReview Review
r
    doit (CaseProb CaseProb
cp) = CaseProb -> Section
mkCaseProb CaseProb
cp
    doit (Example Example
e)   = Example -> Section
mkExample Example
e
    doit (Smmry Smmry
s)     = Smmry -> Section
mkSmmry Smmry
s
    doit LsnChapter
BibSec        = BibRef -> Section
mkBib (SystemInformation -> BibRef
citeDB SystemInformation
si)
    doit (Apndx Apndx
a)     = Apndx -> Section
mkAppndx Apndx
a

-- | Helper for making the 'Introduction' section.
mkIntro :: Intro -> Section
mkIntro :: Intro -> Section
mkIntro (IntrodProg [Contents]
i) = [Contents] -> [Section] -> Section
Lsn.intro [Contents]
i []
  
-- | Helper for making the 'Learning Objectives' section.
mkLearnObj :: LearnObj -> Section
mkLearnObj :: LearnObj -> Section
mkLearnObj (LrnObjProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.learnObj [Contents]
cs []

-- | Helper for making the 'Review' section.
mkReview :: Review -> Section
mkReview :: Review -> Section
mkReview (ReviewProg [Contents]
r) = [Contents] -> [Section] -> Section
Lsn.review [Contents]
r [] 

-- | Helper for making the 'Case Problem' section.
mkCaseProb :: CaseProb -> Section
mkCaseProb :: CaseProb -> Section
mkCaseProb (CaseProbProg [Contents]
cp) = [Contents] -> [Section] -> Section
Lsn.caseProb [Contents]
cp [] 

-- | Helper for making the 'Example' section.
mkExample:: Example -> Section
mkExample :: Example -> Section
mkExample (ExampleProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.example [Contents]
cs []

-- | Helper for making the 'Summary' section.
mkSmmry :: Smmry -> Section
mkSmmry :: Smmry -> Section
mkSmmry (SmmryProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.summary [Contents]
cs []

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

-- | Helper for making the 'Appendix' section.
mkAppndx :: Apndx -> Section
mkAppndx :: Apndx -> Section
mkAppndx (ApndxProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.appendix [Contents]
cs []