\NeedsTeXFormat{LaTeX2e}
\ProvidesExplClass{PrimeTeX/Manual}{2025-09-12}{1.0}{
	A class creating for user manuals and other book-like documents to be
	published by Prime Controls.
}

% Option 'electronic': single side printing, among other things.
\bool_new:N \g_electronic_bool
\bool_gset_false:N \g_electronic_bool

\DeclareOption{electronic}{
	\bool_gset_true:N \g_electronic_bool
}
\NewExpandableDocumentCommand{\IsElectronic}{}{\g_electronic_bool}

% Option 'admin': turn on admin manual sections.
\bool_new:N \g_admin_bool
\bool_gset_false:N \g_admin_bool

\DeclareOption{admin}{
	\bool_gset_true:N \g_admin_bool
}
\NewExpandableDocumentCommand{\IsAdminManual}{}{\g_admin_bool}

% Option 'darkmode': render as light text on dark background. Only applies if
% electronic mode is also on.
\bool_new:N \g_dark_mode_bool
\bool_gset_false:N \g_dark_mode_bool

\DeclareOption{darkmode}{
	\bool_gset:Nn \g_dark_mode_bool {\g_electronic_bool}
}
\NewExpandableDocumentCommand{\IsDarkMode}{}{\g_dark_mode_bool}

% Option 'draft': same as base book class, but with bigger overfull boxes.
\bool_new:N \g_draft_bool
\bool_gset_false:N \g_draft_bool

\DeclareOption{draft}{
	\bool_gset_true:N \g_draft_bool
	\overfullrule = 1in
}
\NewExpandableDocumentCommand{\IsDraft}{}{\g_draft_bool}

% Option 'roman': render Part numbers and print-format front matter page numbers
% as Roman numerals.
\bool_new:N \g_roman_bool
\bool_gset_false:N \g_roman_bool

\DeclareOption{roman}{
	\bool_gset_true:N \g_roman_bool
}
\NewExpandableDocumentCommand{\DoRomanNumerals}{}{\g_roman_bool}

% Option 'numberword': render Part numbers as number words (e.g. One, Two, Three).
% Only kind of working.
\bool_new:N \g_number_word_bool
\bool_gset_false:N \g_number_word_bool

\DeclareOption{numberword}{
	\bool_gset_true:N \g_number_word_bool
}
\NewExpandableDocumentCommand{\DoNumberWords}{}{\g_number_word_bool}

% Option 'labels': show Part and Chapter labels in the header.
\bool_new:N \g_label_bool
\bool_gset_false:N \g_label_bool

\DeclareOption{labels}{
	\bool_gset_true:N \g_label_bool
}
\NewExpandableDocumentCommand{\ShowLabels}{}{\g_label_bool}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}

\ProcessOptions\relax

\bool_if:NTF \g_electronic_bool {
	\bool_if:NTF \g_draft_bool {
		\LoadClass[draft,oneside]{book}
	} {
		\LoadClass[oneside]{book}
	}
} {
	\bool_if:NTF \g_draft_bool {
		\LoadClass[draft]{book}
	} {
		\LoadClass{book}
	}
}

\input{PrimeTeX/commonincludes.def}

\NewDocumentCommand{\rem}{+m}{}

\str_new:N \l_IncludeOnly_chapters_str

% Wrapper for \includeonly.
% If argument is empty, all chapters are included.
% If the argument is not empty, only chapters that are listed are included.
\NewDocumentCommand{\IncludeOnlyChapters}{m}{
	\str_set:Nn \l_IncludeOnly_chapters_str {#1}
	\str_remove_all:Nn \l_IncludeOnly_chapters_str {~}
	\str_if_empty:NF \l_IncludeOnly_chapters_str {
		\expanded{\noexpand\includeonly{\l_IncludeOnly_chapters_str}}
	}
}