% !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{}

\newcommand{\fancyfootL}{
	\color{gray}\blenderfont
	\raisebox{0em}{
		\hspace{-37.5pt}\@author
	}
	\newline
	\raisebox{0em}{
		\hspace{-37.5pt}\ifdef{\modulename}{\modulename}{Modul-Name}
	}
}

\newcommand{\fancyfootC}{
	\color{gray}\blenderfont\newline
	\raisebox{0em}{
		Seite~\thepage~von~\pageref{LastPage}
	}
}

% ------------------------------------------------------------------------------
% 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[L]{
	\fancyfootL
}
\fancyfoot[C]{
	\fancyfootC
}

% ==============================================================================
% 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]{
		\fancyfootC
	}
	\fancyfoot[L]{
		\fancyfootL
	}
	\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]{
		\fancyfootC
	}
	\fancyfoot[L]{
		\fancyfootL
	}
}

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

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