-- | Defines helper functions for making the Table of Auxiliary Constants section.
module Drasil.Sections.AuxiliaryConstants 
  (valsOfAuxConstantsF, tableOfConstants, tableOfConstantsRef) where

import Language.Drasil
import qualified Drasil.DocLang.SRS as SRS (valsOfAuxCons)
import Drasil.DocumentLanguage.Units (toSentence)
import Data.Drasil.Concepts.Documentation (value, description, symbol_, tAuxConsts)
import qualified Data.Drasil.Concepts.Math as CM (unit_)
import Control.Lens ((^.))
import Drasil.Sections.ReferenceMaterial (emptySectSentPlu)

-- | Gets the auxiliary constant values given an introductory 'Idea' and a 'QDefinition'.
valsOfAuxConstantsF :: Idea a => a -> [ConstQDef] -> Section
valsOfAuxConstantsF :: forall a. Idea a => a -> [QDefinition Literal] -> Section
valsOfAuxConstantsF a
kWord [QDefinition Literal]
listOfConstants = [Contents] -> [Section] -> Section
SRS.valsOfAuxCons (a -> [QDefinition Literal] -> [Contents]
forall a. Idea a => a -> [QDefinition Literal] -> [Contents]
contentGenerator a
kWord [QDefinition Literal]
listOfConstants)  []

-- | Gets a table of constants from a 'QDefinition'. Also uses an 'Idea' as the introduction.
contentGenerator :: Idea a => a -> [ConstQDef] -> [Contents]
contentGenerator :: forall a. Idea a => a -> [QDefinition Literal] -> [Contents]
contentGenerator a
_ [] = [Sentence -> Contents
mkParagraph (Sentence -> Contents) -> Sentence -> Contents
forall a b. (a -> b) -> a -> b
$ [IdeaDict] -> Sentence
forall n. NamedIdea n => [n] -> Sentence
emptySectSentPlu [IdeaDict
tAuxConsts]]
contentGenerator a
a [QDefinition Literal]
b  = [a -> Contents
forall a. Idea a => a -> Contents
intro a
a, LabelledContent -> Contents
LlC (LabelledContent -> Contents) -> LabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ [QDefinition Literal] -> LabelledContent
tableOfConstants [QDefinition Literal]
b]

--FIXME: general introduction?
-- | Helper that creates a general introduction using an 'Idea'.
intro :: (Idea a) => a -> Contents
intro :: forall a. Idea a => a -> Contents
intro a
kWord = [Sentence] -> Contents
foldlSP [String -> Sentence
S String
"This section contains the standard values that are used for calculations in" Sentence -> Sentence -> Sentence
+:+ a -> Sentence
forall c. Idea c => c -> Sentence
short a
kWord]

-- | Helper that gets a table of constants from a 'QDefinition'.
tableOfConstants :: [ConstQDef] -> LabelledContent
tableOfConstants :: [QDefinition Literal] -> LabelledContent
tableOfConstants [QDefinition Literal]
f = Reference -> RawContent -> LabelledContent
llcc Reference
tableOfConstantsRef (RawContent -> LabelledContent) -> RawContent -> LabelledContent
forall a b. (a -> b) -> a -> b
$ [Sentence] -> [[Sentence]] -> Sentence -> Bool -> RawContent
Table
  [IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize IdeaDict
symbol_, IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize IdeaDict
description, IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize IdeaDict
value, ConceptChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize ConceptChunk
CM.unit_]
  ([QDefinition Literal -> Sentence]
-> [QDefinition Literal] -> [[Sentence]]
forall a b. [a -> b] -> [a] -> [[b]]
mkTable [QDefinition Literal -> Sentence
forall c. (HasUID c, HasSymbol c) => c -> Sentence
ch, QDefinition Literal -> Sentence
forall n. NamedIdea n => n -> Sentence
phrase, \QDefinition Literal
c -> ModelExpr -> Sentence
eS (ModelExpr -> Sentence) -> ModelExpr -> Sentence
forall a b. (a -> b) -> a -> b
$ Literal -> ModelExpr
forall c. Express c => c -> ModelExpr
express (Literal -> ModelExpr) -> Literal -> ModelExpr
forall a b. (a -> b) -> a -> b
$ QDefinition Literal
c QDefinition Literal
-> Getting Literal (QDefinition Literal) Literal -> Literal
forall s a. s -> Getting a s a -> a
^. Getting Literal (QDefinition Literal) Literal
forall e. Lens' (QDefinition e) e
forall (c :: * -> *) e. DefiningExpr c => Lens' (c e) e
defnExpr, QDefinition Literal -> Sentence
forall u. MayHaveUnit u => u -> Sentence
toSentence] [QDefinition Literal]
f)
  (IdeaDict -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize' IdeaDict
tAuxConsts)
  Bool
True

-- | Table of constants reference label.
tableOfConstantsRef :: Reference
tableOfConstantsRef :: Reference
tableOfConstantsRef = UID -> Reference
makeTabRef' (IdeaDict
tAuxConsts IdeaDict -> Getting UID IdeaDict UID -> UID
forall s a. s -> Getting a s a -> a
^. Getting UID IdeaDict UID
forall c. HasUID c => Getter c UID
Getter IdeaDict UID
uid)