% !TEX root = ../HSRTReport.cls
% ==============================================================================
% Page Setup Configuration Module
% ==============================================================================
% Description: Page layout configuration including headers, footers, and styling
% Author: Frederik Beimgraben
% License: Creative Commons CC BY 4.0
% ==============================================================================

% ==============================================================================
% Required Packages
% ==============================================================================
\usepackage{lastpage}  % For "Page X of Y" functionality
\usepackage{fancyhdr}  % Already loaded, but ensure it's available

% ==============================================================================
% Page Style Configuration
% ==============================================================================
% Use fancy page style for headers and footers
\pagestyle{fancy}

% Remove default header rule
\renewcommand{\headrulewidth}{0pt}

% Override KOMA-Script chapter page style to use fancy instead of plain
\renewcommand{\chapterpagestyle}{fancy}

% ==============================================================================
% Page Number Configuration
% ==============================================================================
% Set page number font style
\setkomafont{pagenumber}{\color{gray}\blenderfont\selectfont}

% Adjust footer position - move up by reducing footskip
\setlength{\footskip}{25pt}  % Reduced from default to move footer up

% ==============================================================================
% Header and Footer Setup
% ==============================================================================
% Clear all header and footer fields
\fancyhf{}

% ------------------------------------------------------------------------------
% Header Configuration
% ------------------------------------------------------------------------------
% Left header: Chapter number and title
% Right header: Document title
\fancyhead[R]{%
	\color{gray}\blenderfont

	% show if chapter > 0
	\ifthenelse{\value{chapter} > 0}{\thechapter~–~\leftmark}{}
}
\fancyhead[L]{\color{gray}\blenderfont\@title} % Document title on right

% Update chapter marks to show only chapter name without "Chapter" prefix
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{}  % Don't show sections in header

\newcommand{\footerhorizspacing}{\qquad}

% ------------------------------------------------------------------------------
% Footer Configuration
% ------------------------------------------------------------------------------
% Footer format: Author Name | Module Name | Page X of Y
% The footer is centered
\fancyfoot[C]{%
	\color{gray}\blenderfont%
	\@author%
	\footerhorizspacing%
	\ifdef{\modulename}{\modulename}{Modul-Name}%
	\footerhorizspacing%
	Seite~\thepage~von~\pageref{LastPage}%
}

% ==============================================================================
% Plain Page Style (for chapter pages)
% ==============================================================================
% Define the plain page style (used on chapter start pages)
\fancypagestyle{plain}{
	\fancyhf{}
	% Show headers also on chapter start pages
	\fancyhead[R]{%
		\color{gray}\blenderfont

		% show if chapter > 0
		\ifthenelse{\value{chapter} > 0}{\thechapter~–~\leftmark}{}
	}
	\fancyhead[L]{\color{gray}\blenderfont\@title}
	% Same footer as regular pages
	\fancyfoot[C]{%
		\color{gray}\blenderfont%
		\@author%
		\footerhorizspacing%
		\ifdef{\modulename}{\modulename}{Modul-Name}%
		\footerhorizspacing%
		Seite~\thepage~von~\pageref{LastPage}%
	}
	\renewcommand{\headrulewidth}{0pt}
}

% ==============================================================================
% Fancy Page Style Definition
% ==============================================================================
% Explicitly define the fancy page style
\fancypagestyle{fancy}{
	\fancyhf{}
	\fancyhead[R]{%
		\color{gray}\blenderfont

		% show if chapter > 0
		\ifthenelse{\value{chapter} > 0}{\thechapter~–~\leftmark}{}
	}
	\fancyhead[L]{\color{gray}\blenderfont\@title}
	\fancyfoot[C]{%
		\color{gray}\blenderfont%
		\@author%
		\footerhorizspacing%
		\ifdef{\modulename}{\modulename}{Modul-Name}%
		\footerhorizspacing%
		Seite~\thepage~von~\pageref{LastPage}%
	}
}

% ==============================================================================
% Override Default Page Styles
% ==============================================================================
% Ensure all special pages use fancy style
\AtBeginDocument{%
	\pagestyle{fancy}%
	\renewcommand{\chapterpagestyle}{fancy}%
}

% ==============================================================================
% End of Page Setup Module
% ==============================================================================
