\NeedsTeXFormat{LaTeX2e}
\ProvidesExplPackage{PrimeTeX/packages/Header}{2025-08-16}{1.0}{
	Customize header and footer layout and contents.
}

\ProvideLength{\HeaderInsideOffset}[\BigFloatOverhang]
\ProvideLength{\HeaderOutsideOffset}[\fp_to_dim:n{\BigFloatOverhang * \BigFloatOffset}]

\pagestyle{fancy}

% Clear all header & footer formatting.
\fancyhf{}

\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\NewDocumentCommand{\chapappname}{}{Chapter~\thechapter{}:~}
\NewDocumentCommand{\partlabel}{}{\bool_if:NT \g_label_bool {\partname{}~\thepart{}:~}\parttitle}

\NewDocumentCommand{\FrontMatter}{}{
	\pagestyle{plain}
	\bool_if:nTF {\g_electronic_bool || !\g_roman_bool} {
		\pagenumbering{arabic}
	}{
		\pagenumbering{roman}
	}
}

\NewDocumentCommand{\MainMatter}{}{
	\pagestyle{fancy}
	\bool_if:NF \g_electronic_bool {
		\pagenumbering{arabic}
	}
}

\NewDocumentCommand{\Appendix}{}{
	\appendix
	\RenewDocumentCommand{\chapappname}{}{Appendix~\thechapter{}:~}
	\RenewDocumentCommand{\partlabel}{}{}
	\RenewDocumentCommand{\chapterautorefname}{}{Appendix}
}

\NewDocumentCommand{\BackMatter}{}{
	\RenewDocumentCommand{\chapappname}{}{}
	\RenewDocumentCommand{\partlabel}{}{}
}

\NewDocumentCommand{\parttitle}{}{}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}

\fancypagestyle{fancy}{
	\bool_if:NTF \g_electronic_bool {
		\fancyhfoffset[L]{\HeaderInsideOffset}
		\fancyhfoffset[R]{\HeaderOutsideOffset}
		\fancyhead[L]{\partlabel}
		\fancyhead[R]{\bool_if:NT \g_label_bool {\chapappname} \leftmark}

		\fancyfoot[R]{\thepage}
	}{
		\fancyhfoffset[LE,RO]{\HeaderOutsideOffset}
		\fancyhead[LE]{\partlabel}
		\fancyhead[RO]{\bool_if:NT \g_label_bool {\chapappname} \leftmark}

		\fancyfoot[LE,RO]{\thepage}
	}
}

\fancypagestyle{plain}{ %
	\fancyhf{} % remove everything
	\renewcommand{\headrulewidth}{0pt} % remove lines as well
	\renewcommand{\footrulewidth}{0pt}

	\bool_if:NTF \g_electronic_bool {
		\fancyhfoffset[L]{\HeaderInsideOffset}
		\fancyhfoffset[R]{\HeaderOutsideOffset}
		\fancyfoot[R]{\thepage}
	}{
		\fancyhfoffset[LE,RO]{\HeaderOutsideOffset}
		\fancyfoot[LE,RO]{\thepage}
	}
}
