\NeedsTeXFormat{LaTeX2e}[1994/12/01]

\ProvidesClass{UiO_profile/UiO_profile_fp}[2023/01/01 UiO profile frontpage]

\DeclareOption{american}{\def \uiopfp@lang {eng}}
\DeclareOption{english}{\def \uiopfp@lang {eng}}
\DeclareOption{UKenglish}{\def \uiopfp@lang {eng}}
\DeclareOption{USenglish}{\def \uiopfp@lang {eng}}
\DeclareOption{norsk}{\def \uiopfp@lang {bm}}
\DeclareOption{nynorsk}{\def \uiopfp@lang {nn}}

\newcommand{\uiopfp@fac@eng}{Faculty of Mathematics and Natural Sciences}
\newcommand{\uiopfp@fac@bm}{Det matematisk-naturvitenskapelige fakultet}
\newcommand{\uiopfp@fac@nn}{Det matematisk-naturvitenskaplege fakultet}

\newcommand{\uiopfp@dept@eng}{Department of Informatics}
\newcommand{\uiopfp@dept@bm}{Institutt for informatikk}
\newcommand{\uiopfp@dept@nn}{Institutt for informatikk}

\newcommand{\uiopfp@thesis@eng}{Master's thesis}
\newcommand{\uiopfp@thesis@bm}{Masteroppgave}
\newcommand{\uiopfp@thesis@nn}{Masteroppg\aa ve}

\newcommand{\uiopfp@bachelor@eng}{Bachelor's thesis}
\newcommand{\uiopfp@bachelor@bm}{Bacheloroppgave}
\newcommand{\uiopfp@bachelor@nn}{Bacheloroppg\aa ve}

\newcommand{\uiopfp@spname@eng}{ECTS study points}
\newcommand{\uiopfp@spname@bm}{studiepoeng}
\newcommand{\uiopfp@spname@nn}{studiepoeng}

\newcommand{\uiopfp@supervisor@eng}{Supervisor}
\newcommand{\uiopfp@supervisors@eng}{Supervisors}
\newcommand{\uiopfp@supervisor@bm}{Veileder}
\newcommand{\uiopfp@supervisors@bm}{Veiledere}
\newcommand{\uiopfp@supervisor@nn}{Rettleiar}
\newcommand{\uiopfp@supervisors@nn}{Rettleiarar}

\newcommand{\uiopfp@std@size}{14}
\newcommand{\uiopfp@big@size}{20}
\newcommand{\uiopfp@head@size}{32}

\ExecuteOptions{norsk}
\ProcessOptions \relax

\definecolor{uiopfp@blue}{RGB}{124, 155, 206}
\definecolor{uiopfp@light@blue}{RGB}{223, 231, 243}
\definecolor{uiopfp@pink}{RGB}{251, 102, 102}
\definecolor{uiopfp@light@pink}{RGB}{253, 224, 225}
\definecolor{uiopfp@green}{RGB}{116, 198, 165}
\definecolor{uiopfp@light@green}{RGB}{197, 228, 207}
\definecolor{uiopfp@gray}{RGB}{220, 221, 223}
\definecolor{uiopfp@grey}{RGB}{220, 221, 223}
\definecolor{uiopfp@light@gray}{RGB}{255, 255, 255}
\definecolor{uiopfp@light@grey}{RGB}{255, 255, 255}

\RequirePackage{tikz}
\RequirePackage[export]{adjustbox}
\RequirePackage{color, eso-pic, graphicx, xifthen, keyval}
\usetikzlibrary{fit,calc}

%% The options:

\newboolean{uiopfp@compact}

\define@key{uiopfp@keys}{author}{\def \uiopfp@author {#1}}
\define@key{uiopfp@keys}{binding}[24]{\def \uiopfp@bind {#1}}
\define@key{uiopfp@keys}{color}{\def \uiopfp@color {#1}}
\define@key{uiopfp@keys}{colour}{\def \uiopfp@color {#1}}
\define@key{uiopfp@keys}{date}{\def \uiopfp@date {#1}}
\define@key{uiopfp@keys}{dept}{\def \uiopfp@dept {#1}}
\define@key{uiopfp@keys}{fac}{\def \uiopfp@fac {#1}}
\define@key{uiopfp@keys}{font}{\def \uiopfp@font {#1}}
\define@key{uiopfp@keys}{image}{\def \uiopfp@image {#1}}
\define@key{uiopfp@keys}{image-trim}{\edef\uiopfp@imagetrim{trim={#1}}}
\define@key{uiopfp@keys}{info}{\def \uiopfp@info {#1}}
\define@key{uiopfp@keys}{kind}{\def \uiopfp@firstchip {#1}}
\define@key{uiopfp@keys}{program}{\def \uiopfp@programname{#1}}
\define@key{uiopfp@keys}{sp}{\def \uiopfp@sp{#1}}
\define@key{uiopfp@keys}{subtitle}{\def \uiopfp@subtitle {#1}}
\define@key{uiopfp@keys}{supervisor}{\def \uiopfp@supervisor {#1}}
\define@key{uiopfp@keys}{supervisors}{\def \uiopfp@supervisors {#1}}
\define@key{uiopfp@keys}{title}{\def \uiopfp@title {#1}}

% Default values:
\def \uiopfp@author {\@author}
\def \uiopfp@bind {0}
\def \uiopfp@color {gray}
\providecommand{\uiopfp@date}{\uiopfp@term~\uiopfp@year}
\def \uiopfp@dept {\csname uiopfp@dept@\uiopfp@lang \endcsname}
\def \uiopfp@fac {\csname uiopfp@fac@\uiopfp@lang \endcsname}
\def \uiopfp@font {helvetica}
\def \uiopfp@info {}
\edef \uiopfp@imagetrim {trim={0 0 0 0}}
\providecommand{\uiopfp@program}{}
\def \uiopfp@supervisor {}
\def \uiopfp@supervisors {}
\def \uiopfp@title {\@title}

\AtEndOfPackage{\ifthenelse{\equal{\uiopfp@font}{helvetica}}
  {\RequirePackage[scaled]{helvet}}
  {}}


%% Determine the term (as in "Spring 2022"):
\newcounter{uiopfp@cur@year}   \setcounter{uiopfp@cur@year}{\the\year}
\newcounter{uiopfp@cur@month}  \setcounter{uiopfp@cur@month}{\the\month}

\ifthenelse{\theuiopfp@cur@month<7}
  {\newcommand{\uiopfp@term@eng}{Spring}%
   \newcommand{\uiopfp@term@bm}{V\aa ren}%
   \newcommand{\uiopfp@term@nn}{V\aa ren}}
  {\newcommand{\uiopfp@term@eng}{Autumn}%
   \newcommand{\uiopfp@term@bm}{H\o sten}%
   \newcommand{\uiopfp@term@nn}{Hausten}}
\newcommand{\uiopfp@term}{\csname uiopfp@term@\uiopfp@lang\endcsname}
\newcommand{\uiopfp@year}{\arabic{uiopfp@cur@year}}

\newcounter{uiopfp@bind@w}
\newcommand{\uiofp}[1][]{{%
  \parindent = 0pt   \parskip = 0pt   \relax
  \@ifundefined{hypersetup}{}{\hypersetup{pageanchor=false}}
  \setkeys{uiopfp@keys}{#1}
  \setcounter{uiopfp@bind@w}{28}  \addtocounter{uiopfp@bind@w}{\uiopfp@bind}
  \fontfamily{phv}
  \ifthenelse{\equal{\uiopfp@font}{arial}}{\fontfamily{ua1}}{}
  \ifthenelse{\equal{\uiopfp@font}{verdana}}{\fontfamily{jvn}}{}
  \fontencoding{T1}\fontsize{\uiopfp@std@size}{18pt}%
  \fontseries{m}\fontshape{n}\selectfont

  \uiopfp@page
  %\if@twoside \uiopfp@blankpage \fi
  \setcounter{page}{1}
  \@ifundefined{hypersetup}{}{\hypersetup{pageanchor=true}}
}}


\newcommand{\uiopfp@page}{
  \thispagestyle{empty}
  \begin{titlepage}
    \begin{tikzpicture}[remember picture,overlay]
      % Bakgrunn
      \node (back names) [shape=rectangle, fill={uiopfp@light@\uiopfp@color}, minimum height=\paperheight, minimum width=\paperwidth, anchor=south west] at (current page.south west) {};

      % Segl
      \node[inner sep=0pt, anchor=south east] (uioname) at ([shift={(-10mm,10mm)}]back names.south east) {
        \includegraphics[width=23.7mm,right]{UiO_profile/profiles/03_uio_segl_pos.png}
      };

      % Dato
      \node[anchor=south west] (uioname) at ([shift={(10mm,10mm)}]back names.south west) {
        \ifdefined\uiopfp@date
          \uiopfp@date
        \else
        \fi
      };

      % "Ribbon" bakgrunn
      \node (names) [shape=rectangle, fill={uiopfp@\uiopfp@color}, minimum height=.25\paperheight, minimum width=\paperwidth, anchor=north west,inner sep=0pt] at (current page.north west) {
        \ifdefined\uiopfp@image
            \begingroup\edef\x{\endgroup\noexpand\includegraphics[width=\paperwidth,height=.25\paperheight,\uiopfp@imagetrim,clip]{\uiopfp@image}}\x
        \fi
      };

      % Navnetrekk
      \node[inner sep=0pt, anchor=north west] (uioname) at ([shift={(10mm,-10mm)}]names.north west) {
        \includegraphics[width=63mm]{UiO_profile/profiles/03_uio_navnetrekk_\uiopfp@lang.png}
      };

      % Chip 1
      \ifdefined\uiopfp@firstchip
        \node[anchor=north west, fill=black, text=white, inner sep=5pt] (chip1) at ([shift={(10mm,15mm)}]names.south west) {
          \uiopfp@firstchip
        };
      \fi

      % Tittel
      \node[anchor=north west] (title) at ([shift={(10mm,-10mm)}]names.south west) {
        \ifdefined\uiopfp@title
          {\sf\Huge\uiopfp@title}
        \else
        \fi
      };

      % Undertittel
      \node[anchor=north west] (subtitle) at ([shift={(0,\ifdefined\uiopfp@title -5mm\else 0\fi)}]title.south west) {
        \ifdefined\uiopfp@subtitle
          \uiopfp@subtitle
        \else
        \fi
      };

      % Forfatter
      \node[anchor=north west] (author) at ([shift={(0,-5mm)}]\ifdefined\uiopfp@subtitle subtitle\else title\fi.south west) {
        {\uiopfp@author}
      };

      % Studieprogram
      \node[anchor=north west] (program) at ([shift={(0,-5mm)}]\ifdefined\uiopfp@author author\else subtitle\fi.south west) {
        \ifdefined\uiopfp@programname
          \uiopfp@programname
        \else
        \fi
      };

      % Studiepoeng
      \node[anchor=north west] (points) at ([shift={(0,0)}]program.south west) {
        \ifdefined\uiopfp@sp
          {\uiopfp@sp~\csname uiopfp@spname@\uiopfp@lang\endcsname\par}
        \else
        \fi
      };

      % Institutt
      \node[anchor=north west] (institute) at ([shift={(0,-5mm)}]\ifdefined\uiopfp@sp points\else program\fi.south west) {
        \ifdefined\uiopfp@dept
         \uiopfp@dept
        \else
        \fi
      };

      % Fakultet
      \node[anchor=north west] (faculty) at ([shift={(0,0)}]institute.south west) {
        \ifdefined\uiopfp@fac
          \uiopfp@fac
        \else
        \fi
      };

    \end{tikzpicture}
    \newpage
  \end{titlepage}
}

\newcommand{\subtitle}[1]{\def \uiopfp@subtitle{#1}}

\endinput
