-- | Document language for lesson plan notebooks.
module Drasil.DocumentLanguage.Notebook
  (mkNb, LsnDesc, LsnChapter(..), LearnObj(..), Review(..), CaseProb(..), Example(..)
  ) where

import Control.Lens ((^.))

import Language.Drasil (IdeaDict, Sentence(S), Section, CI, Document(Notebook), BibRef,
  foldlList, SepType(Comma), FoldType(List), fullName, Contents(UlC), ulcc, RawContent(Bib))
import Drasil.System (System, whatsTheBigIdea, sysName, authors)

import Drasil.DocumentLanguage.Notebook.Core (LsnDesc, LsnChapter(..),
  Intro(..), LearnObj(..), Review(..), CaseProb(..), Example(..), Smmry(..), Apndx(..))
import qualified Drasil.DocLang.Notebook as Lsn (intro, learnObj, caseProb, example,
  appendix, review, reference, summary)
import Drasil.ExtractLsnDesc (extractLsnPlanBib)

-- | Creates a notebook from a lesson description and system information.
mkNb :: LsnDesc -> (IdeaDict -> CI -> Sentence) -> System -> Document
mkNb :: LsnDesc -> (IdeaDict -> CI -> Sentence) -> System -> Document
mkNb LsnDesc
dd IdeaDict -> CI -> Sentence
comb System
si = Sentence -> Sentence -> [Section] -> Document
Notebook Sentence
nm Sentence
as ([Section] -> Document) -> [Section] -> Document
forall a b. (a -> b) -> a -> b
$ System -> LsnDesc -> [Section]
mkSections System
si LsnDesc
dd
  where
    nm :: Sentence
nm = System -> IdeaDict
whatsTheBigIdea System
si IdeaDict -> CI -> Sentence
`comb` (System
si System -> Getting CI System CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI System CI
forall c. HasSystemMeta c => Lens' c CI
Lens' System CI
sysName)
    as :: Sentence
as = SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List ([Sentence] -> Sentence) -> [Sentence] -> Sentence
forall a b. (a -> b) -> a -> b
$ (Person -> Sentence) -> [Person] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S (String -> Sentence) -> (Person -> String) -> Person -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Person -> String
forall n. HasName n => n -> String
fullName) ([Person] -> [Sentence]) -> [Person] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ System
si System -> Getting [Person] System [Person] -> [Person]
forall s a. s -> Getting a s a -> a
^. Getting [Person] System [Person]
forall c. HasSystemMeta c => Lens' c [Person]
Lens' System [Person]
authors

-- | Helper for creating the notebook sections.
mkSections :: System -> LsnDesc -> [Section]
mkSections :: System -> LsnDesc -> [Section]
mkSections System
si LsnDesc
dd = (LsnChapter -> Section) -> LsnDesc -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map LsnChapter -> Section
doit LsnDesc
dd
  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 (System -> LsnDesc -> BibRef
extractLsnPlanBib System
si LsnDesc
dd)
    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 [Section]
ss) = [Contents] -> [Section] -> Section
Lsn.review [Contents]
r [Section]
ss

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

-- | 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 (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.
mkAppndx :: Apndx -> Section
mkAppndx :: Apndx -> Section
mkAppndx (ApndxProg [Contents]
cs) = [Contents] -> [Section] -> Section
Lsn.appendix [Contents]
cs []