% !TEX root = ../HSRTReport.cls
% ==============================================================================
% Bibliography Configuration Module
% ==============================================================================
% Description: Configure BibLaTeX citation formatting and hyperlink behavior
% Author: Frederik Beimgraben
% License: Creative Commons CC BY 4.0
% ==============================================================================

% ==============================================================================
% BibLaTeX Hyperlink Configuration
% ==============================================================================
% Make entire citation content clickable, not just parts of it

% Load hyperref support for biblatex
\ExecuteBibliographyOptions{
	hyperref=true,
	backref=false,
	url=true,
	doi=true,
	isbn=false
}

% ------------------------------------------------------------------------------
% Make entire citation clickable (not just author or year)
% ------------------------------------------------------------------------------
% This works with APA style to make the complete "Author, Year" clickable

% Redefine how hyperlinks are created in citations
\DeclareFieldFormat{citehyperref}{%
	\bibhyperref{#1}%
}

% Make cite command create single hyperlink
\DeclareCiteCommand{\cite}
{\usebibmacro{prenote}}
{\bibhyperref{\usebibmacro{citeindex}\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}

% Make parencite create single hyperlink for entire content
\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{prenote}}
{\bibhyperref{\usebibmacro{citeindex}\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}

% Make textcite create unified hyperlink
\DeclareCiteCommand{\textcite}
{\usebibmacro{prenote}}
{\bibhyperref{%
		\usebibmacro{citeindex}%
		\printnames{labelname}%
		\setunit{\nameyeardelim}%
		\printfield{year}%
	}}
{\multicitedelim}
{\usebibmacro{postnote}}

% Alternative simple command for fully linked citations
\newcommand{\fcite}[1]{%
	\hyperlink{cite.#1}{\citeauthor{#1}, \citeyear{#1}}%
}

% Make footcite also use single hyperlink
\DeclareCiteCommand{\footcite}[\mkbibfootnote]
{\usebibmacro{prenote}}
{\bibhyperref{\usebibmacro{citeindex}\usebibmacro{cite}}}
{\multicitedelim}
{\usebibmacro{postnote}}

% ==============================================================================
% Additional Citation Formatting
% ==============================================================================

% ------------------------------------------------------------------------------
% Citation punctuation
% ------------------------------------------------------------------------------
\renewcommand{\nameyeardelim}{\addcomma\space}  % Comma between author and year
\renewcommand{\multicitedelim}{\addsemicolon\space}  % Semicolon between multiple citations

% ------------------------------------------------------------------------------
% Author name formatting in citations
% ------------------------------------------------------------------------------
\DeclareNameAlias{sortname}{family-given}  % Last name first in bibliography
\DeclareNameAlias{default}{given-family}   % Normal order in citations

% ------------------------------------------------------------------------------
% URL and DOI formatting
% ------------------------------------------------------------------------------
\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{doi}{%
	\ifhyperref
	{\href{https://doi.org/#1}{\nolinkurl{doi:#1}}}
	{\nolinkurl{doi:#1}}%
}

% ------------------------------------------------------------------------------
% Bibliography spacing
% ------------------------------------------------------------------------------
\setlength{\bibitemsep}{0.5\baselineskip}  % Space between bibliography entries
\setlength{\bibhang}{2em}                  % Hanging indent for bibliography

% ==============================================================================
% End of Bibliography Configuration Module
% ==============================================================================
