% (The MIT License)
%
% Copyright (c) 2022 Yegor Bugayenko
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the 'Software'), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.

\RequirePackage{geometry}
  \geometry{paperwidth=16in, paperheight=9in, left=4in, right=2in, top=1.5in, bottom=1.5in}
\RequirePackage[absolute]{textpos}
  \TPGrid{16}{16}
\RequirePackage[tt=false,type1=true]{libertine} % the font we use
\RequirePackage{microtype} % just to make rendering smooth
\AddToHook{env/verbatim/begin}{\microtypesetup{protrusion=false}}
\RequirePackage{anyfontsize} % to support all sizes
\RequirePackage{multicol} % for pptWide environment
\RequirePackage[fontsize=24pt]{fontsize} % to make fonts larger
\RequirePackage{changepage} % to use 'adjustwidth' environment in pptWide
\RequirePackage{soul} % for underscores in crumbs
\RequirePackage{tikz} % for drawing circles
\RequirePackage{lastpage} % to count pages and show total

\RequirePackage{crumbs}
  \renewcommand\crumb[2]{%
    \ifnum\value{crumbi}=1\else\hspace{1em}\fi
    \ifnum\value{crumbi}=\value{section}%
      {\setulcolor{blue}\color{blue}\ul{#1}}%
    \else%
      #1%
    \fi%
  }
  \renewcommand\subcrumb[2]{%
    \ifnum\value{subcrumbi}=1\else\hspace{0.5em}\fi
    \ifnum\value{subcrumbi}=\value{subsection}%
      {\setulcolor{blue}\color{blue}\ul{#1}}%
    \else%
      #1%
    \fi%
  }

\RequirePackage{fancyhdr}
  \pagestyle{fancy}
  \renewcommand{\headrulewidth}{0pt}
  \fancyhf{}
  \fancyhead[L]{%
    \ifx\crumbs\empty\else
      \begin{textblock}{12}(1,1)%
        \ifnum\value{section}=0\else
          {\small\ttfamily\crumbs}
          \ifnum\value{subsection}=0\else
            \\[6pt]
            {\quad\scriptsize\ttfamily\color{grey}[ \subcrumbs{} ]}
          \fi
        \fi
      \end{textblock}%
    \fi
  }
  \fancyhead[R]{%
    \ifnum\value{page}=1\else%
      \begin{textblock}{4}[1,0](15,1)%
        {\ttfamily\normalsize {\thepage{}}{\footnotesize{\color{grey}/\pageref{LastPage}}}}
      \end{textblock}%
      \makeatletter\ifdefined\ppt@nominutes\else
        \ifcsname c@minutes\endcsname
          \ifnum\value{minutes}=0\else%
            \begin{textblock}{1}[1,0](15.8,0.2)%
              \tikz{\node[inner sep=2pt,circle,draw=grey]{\color{grey}\scriptsize\ttfamily\theminutes{}};}
            \end{textblock}%
          \fi
        \fi
      \fi\makeatother
    \fi
  }

\newcommand\pptLeft[1]{%
  \fancyfoot[L]{%
    \ifnum\value{page}=1\else%
      \begin{textblock}{8}[0,1](1,15)%
        {\color{grey}\scriptsize\ttfamily #1}
      \end{textblock}%
    \fi
  }
}

\newcommand\pptRight[1]{%
  \fancyfoot[R]{%
    \ifnum\value{page}=1\else%
      \begin{textblock}{8}[1,1](15,15)%
        {\color{grey}\scriptsize\ttfamily #1}
      \end{textblock}%
    \fi
  }
}

\AtBeginDocument{%
  \raggedbottom%
  \raggedright%
  \raggedcolumns%
  \setlength\topskip{0pt}%
  \setlength\headheight{32pt}%
  \setlength\footskip{32pt}%
  \setlength\parindent{0pt}%
  \setlength\parskip{18pt}%
  \setlength\columnsep{32pt}%
  \normalsize%
  \sffamily%
}
