import { ALIASES_LABEL, CATEGORY_LABEL, CONTRACT_LABEL, KIND_LABEL, LAYER_LABEL, PRINCIPLE_LABEL, REFERENCED_BY_LABEL, } from "#configuration/strings/ontology.strings"; import { DEFINITION_LABEL, LEXICON_INTRO } from "#configuration/strings/lexicon.strings"; import { LEX_ANCHOR, LEX_CATEGORY_ANCHOR } from "#core/ids/ontology.ids"; import type { Section, Subsection } from "#types/document.types"; import type { TermCategoryView, TermView } from "#types/ontology.types"; import { chips, glossary, linkRow, linked, plainList, row } from "#domain/converters/ontology.converter"; import { ONTOLOGY_LEXICON_ICON } from "#configuration/icons/ontology.icons"; export const termSubsection = function termSubsection(term: TermView): Subsection { return { blocks: [ chips([ linked(KIND_LABEL, term.kind), linked(CATEGORY_LABEL, term.category), linked(LAYER_LABEL, term.layer), ]), glossary([ row(DEFINITION_LABEL, term.definition), ...(term.aliases.length === 0 ? [] : [row(ALIASES_LABEL, plainList(term.aliases))]), ...linkRow(PRINCIPLE_LABEL, term.principle === null ? [] : [term.principle]), ...linkRow(CONTRACT_LABEL, term.contract === null ? [] : [term.contract]), ...linkRow(REFERENCED_BY_LABEL, term.referencedBy), ]), ], id: LEX_ANCHOR + term.id, title: term.name, }; }; const categorySection = function categorySection(group: TermCategoryView): Section { return { icon: ONTOLOGY_LEXICON_ICON, id: LEX_CATEGORY_ANCHOR + group.id, intro: LEXICON_INTRO, subsections: [...group.terms].sort((a, b) => a.name.localeCompare(b.name)).map(termSubsection), title: group.category, }; }; export const lexiconSections = function lexiconSections(groups: readonly TermCategoryView[]): readonly Section[] { return [...groups].sort((a, b) => a.category.localeCompare(b.category)).map(categorySection); };