\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{dane_cv}[2025/10/10 Dane's CV Class]

% Base class
\LoadClass[10pt, letterpaper]{article}

% Packages
\RequirePackage[
    ignoreheadfoot,
    top=2cm,
    bottom=2cm,
    left=2cm,
    right=2cm,
    footskip=1.0cm,
]{geometry}
\RequirePackage[explicit]{titlesec}
\RequirePackage{tabularx}
\RequirePackage{array}
\RequirePackage[dvipsnames]{xcolor}
\RequirePackage{enumitem}
\RequirePackage{fontawesome5}
\RequirePackage{amsmath}
\RequirePackage[
    pdftitle={Dane Sabo's CV},
    pdfauthor={Dane Sabo},
    pdfcreator={LaTeX},
    colorlinks=true,
    urlcolor=primaryColor
]{hyperref}
\RequirePackage[pscoord]{eso-pic}
\RequirePackage{calc}
\RequirePackage{bookmark}
\RequirePackage{lastpage}
\RequirePackage{changepage}
\RequirePackage{paracol}
\RequirePackage{ifthen}
\RequirePackage{needspace}
\RequirePackage{iftex}

% Ensure PDF is machine readable/ATS parsable
\ifPDFTeX
    \input{glyphtounicode}
    \pdfgentounicode=1
    \RequirePackage[T1]{fontenc}
    \RequirePackage[utf8]{inputenc}
    \RequirePackage{lmodern}
\fi

\RequirePackage[default, type1]{sourcesanspro}

% Color definitions
\definecolor{primaryColor}{RGB}{0, 79, 144}

% Settings
\AtBeginEnvironment{adjustwidth}{\partopsep0pt}
\pagestyle{empty}
\setcounter{secnumdepth}{0}
\setlength{\parindent}{0pt}
\setlength{\topskip}{0pt}
\setlength{\columnsep}{0.15cm}

% Footer style
\makeatletter
\let\ps@customFooterStyle\ps@plain
\patchcmd{\ps@customFooterStyle}{\thepage}{
    \color{gray}\textit{\small Dane Sabo - Page \thepage{} of \pageref*{LastPage}}
}{}{}
\makeatother
\pagestyle{customFooterStyle}

% Section formatting
\titleformat{\section}{
    \needspace{4\baselineskip}
    \Large\color{primaryColor}
}{
}{
}{
    \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]\hspace{-0.1cm}
}[]

\titlespacing{\section}{
    -1pt
}{
    0.3cm
}{
    0.2cm
}

% Subsection formatting
\titleformat{\subsection}{
    \large\color{primaryColor}
}{
}{
}{
    \textbf{#1}
}[]

\titlespacing{\subsection}{
    0pt
}{
    0.2cm
}{
    0.1cm
}

% Environments
\newenvironment{highlights}{
    \begin{itemize}[
        topsep=0.10cm,
        parsep=0.10cm,
        partopsep=0pt,
        itemsep=0pt,
        leftmargin=0.4cm + 10pt
    ]
}{
    \end{itemize}
}

\newenvironment{highlightsforbulletentries}{
    \begin{itemize}[
        topsep=0.10cm,
        parsep=0.10cm,
        partopsep=0pt,
        itemsep=0pt,
        leftmargin=10pt
    ]
}{
    \end{itemize}
}

\newenvironment{onecolentry}{
    \begin{adjustwidth}{
        0.2cm + 0.00001cm
    }{
        0.2cm + 0.00001cm
    }
}{
    \end{adjustwidth}
}

\newenvironment{twocolentry}[2][]{
    \onecolentry
    \def\secondColumn{#2}
    \setcolumnwidth{\fill, 4.5cm}
    \begin{paracol}{2}
}{
    \switchcolumn \raggedleft \secondColumn
    \end{paracol}
    \endonecolentry
}

\newenvironment{threecolentry}[3][]{
    \onecolentry
    \def\thirdColumn{#3}
    \setcolumnwidth{1cm, \fill, 4.5cm}
    \begin{paracol}{3}
    {\raggedright #2} \switchcolumn
}{
    \switchcolumn \raggedleft \thirdColumn
    \end{paracol}
    \endonecolentry
}

\newenvironment{header}{
    \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5}
}{
    \par\kern\topsep
}

% Commands
\newcommand{\placelastupdatedtext}{%
  \AddToShipoutPictureFG*{%
    \put(
        \LenToUnit{\paperwidth-2cm-0.2cm+0.05cm},
        \LenToUnit{\paperheight-1.0cm}
    ){\vtop{{\null}\makebox[0pt][c]{
        \small\color{gray}\textit{Last Updated in October 2025}\hspace{\widthof{Last updated in October 2025}}
    }}}%
  }%
}

% Save original href
\let\hrefWithoutArrow\href

% Custom href with external link icon
\renewcommand{\href}[2]{\hrefWithoutArrow{#1}{\ifthenelse{\equal{#2}{}}{ }{#2 }\raisebox{.15ex}{\footnotesize \faExternalLink*}}}

% AND command for header
\newcommand{\AND}{\unskip
    \cleaders\copy\ANDbox\hskip\wd\ANDbox
    \ignorespaces
}
\newsavebox\ANDbox
\sbox\ANDbox{}
