%%%
%%%        Project: AraCom - LaTeX Template
%%%    Description: This is the basic LaTeX Template for all AraCom related presentations
%%%        Version: 1.0
%%%         Author: Robert Jeutter <robert.jeutter@aracom.de>
%%%     Maintainer: Robert Jeutter <robert.jeutter@aracom.de>
%%%  Creation-Date: 07.06.2023
%%%      Copyright: (c) 2023 Robert Jeutter
%%%      Images by AraCom IT Service
%%%

\usepackage{multirow}
\usepackage{subfigure}
\usepackage{etoolbox}
\usepackage{tikz}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{amsfonts, amsmath, oldgerm, lmodern, animate}
\usepackage{verbatim}
\usepackage{bm}
\usepackage[T1]{fontenc}
\usepackage[defaultsans,scale=0.9]{opensans} % replaces default sans-serif font
\usepackage{opensans} % replaces default serif font

\definecolor{aracomblue}{RGB}{96, 167, 192}
\definecolor{aracomgrey}{rgb}{0.9, 0.9, 0.9}

\setbeamercolor{block title}{fg=white,bg=aracomblue}
\setbeamercolor{block body}{fg=white,bg=aracomblue}

\newcommand{\themecolor}[1]{
  \setbeamercolor{normal text}{fg=white,bg=darkgray}
  \setbeamercolor{structure}{fg=aracomblue}
  \setbeamercolor{block title}{fg=aracomblue,bg=aracomgrey}
  \setbeamercolor{block body}{fg=darkgray,bg=aracomgrey}
}

\themecolor{white}
\setbeamercolor{title}{fg=aracomblue}
\setbeamercolor{author}{fg=white}
\setbeamercolor{date}{fg=white}

\setbeamerfont{author}{size=\scriptsize}
\setbeamerfont{date}{size=\tiny}
\setbeamerfont{title}{series=\bfseries, size=\fontsize{36}{40}}
\setbeamerfont{subtitle}{series=\mdseries,size=\footnotesize}
\setbeamerfont{frametitle}{family=\sffamily,series=\bfseries,size=\large}
\setbeamerfont{framesubtitle}{series=\mdseries}
\setbeamerfont{block title}{series=\centering, size=\small}
\setbeamerfont{block body}{size=\scriptsize}

% Code to get prettier boxes
\setbeamertemplate{blocks}[rounded, shadow=true]

% Bullets in several levels
\setbeamertemplate{itemize item}{\textbullet}
\setbeamertemplate{itemize subitem}{\textemdash}
\setbeamertemplate{itemize subsubitem}{\ensuremath{\circ}}

\newenvironment{colorblock}[3][white]{%
  \begingroup
  \setbeamercolor{block title}{fg=#1,bg=#2}
  \setbeamercolor{block body} {fg=#1,bg=#2}
  \begin{block}{#3}
    }{%
  \end{block}
  \endgroup
}

% Put the logo in each slide's down right area
\pgfdeclareimage[width=0.4\paperwidth]{araLogo}{../images/aracom_Logo-2023-white}
\renewcommand{\logo}{araLogo}
\setbeamertemplate{footline}{\hspace{0.72\paperwidth} \LARGE{www.aracom.de}}

% Define frame title and subtitle layout
\setbeamertemplate{frametitle}{
  \begin{beamercolorbox}[leftskip=-.5cm]{frametitle}%
    \vspace*{.1cm}\\    
    \usebeamerfont{frametitle}\insertframetitle\\
    \noindent\textcolor{aracomblue}{\rule{1cm}{1mm}}
  \end{beamercolorbox}
}

% Define the title page
\setbeamertemplate{title page}{
  \vskip0pt plus 1filll
  \hspace{-12mm}% Pull back the box in an inelegant way - but it works!
  \begin{beamercolorbox}[wd=0.9\textwidth,sep=10pt,leftskip=8mm]{title}
    {\usebeamerfont{title}\inserttitle}
    \arabar%

    {\usebeamerfont{author}\usebeamercolor[fg]{author}\insertauthor}

    {\usebeamerfont{date}\usebeamercolor[fg]{date}\insertdate}
  \end{beamercolorbox}
  \setbeamertemplate{footline}{}
  \vspace{-.6ex}\hspace{0.56\paperwidth}\pgfuseimage{\logo}
}

\newcommand{\arabar}[1]{%
  \newline
  \noindent\textcolor{aracomblue}{\rule{2cm}{2mm}}
  \newline\noindent
}

\newcommand{\TikzSplitSlide}[1]{%
  \rule{0.4\paperwidth}{0pt}%
  \begin{tikzpicture}
    \clip (-0.1\paperwidth,-0.5\paperheight) --
    ( 0.5\paperwidth,-0.5\paperheight) --
    ( 0.5\paperwidth, 0.5\paperheight) --
    ( 0.1\paperwidth, 0.5\paperheight) -- cycle;
    \node at (0.2\paperwidth,0) {%
      \includegraphics[height=\paperheight]{#1}%
    };
  \end{tikzpicture}
}

\renewcommand{\maketitle}{
  \begingroup
  \setbeamertemplate{background}{
    \includegraphics[height=\paperheight]{../images/background.png}
  }
  \vspace{-5ex}\hspace{-5ex}\begin{frame}
    \Large\titlepage%
  \end{frame}
  \endgroup
}

\newenvironment{chapter}[3][]{% Args: image (optional), color, frame title
  \begingroup
  \themecolor{blue}
  \ifstrequal{#2}{aracomblue}{ % Use blue text, else white
    \setbeamercolor{frametitle}{fg=white}
    \setbeamercolor{normal text}{fg=white,bg=#2}
  }{
    \setbeamercolor{frametitle}{fg=aracomblue}
    \setbeamercolor{normal text}{fg=aracomblue,bg=#2}
  }
  \ifstrempty{#1}{}{\setbeamertemplate{background}{\TikzSplitSlide{#1}}}
  \setbeamertemplate{frametitle}{%
    \vspace*{2cm}
    \vfill
    \centering
    \begin{beamercolorbox}[wd=0.55\textwidth,center,shadow=true,rounded=true]{frametitle}
      \usebeamerfont{title}\insertframetitle\\
      \usebeamerfont{framesubtitle}\insertframesubtitle%
    \end{beamercolorbox}
    \vfill
  }
  \begin{frame}{#3}
    \hspace*{0.05\textwidth}%
    \minipage{0.35\textwidth}%
    \usebeamercolor[fg]{normal text}%
    }{%
    \endminipage%
  \end{frame}
  \endgroup
}

\newenvironment{sidepic}[2]{% Args: image, frame title
  \begingroup
  \setbeamertemplate{background}{%
    \hspace*{0.6\paperwidth}%
    \includegraphics[height=\paperheight]{#1}%
  }
  \setbeamertemplate{frametitle}{% Same as normal, but with right skip
    \vspace*{-3.5ex}
    \begin{beamercolorbox}[leftskip=2cm,rightskip=0.4\textwidth]{frametitle}%
      \usebeamerfont{frametitle}\insertframetitle\\
      \usebeamerfont{framesubtitle}\insertframesubtitle%
    \end{beamercolorbox}
  }
  \begin{frame}{#2}
    \minipage{0.6\textwidth}%
    }{%
    \endminipage%
  \end{frame}
  \endgroup
}

\newcommand{\strtoc}{Table of Contents}
\newcommand{\strsubsec}{Section \thesection.\thesubsection}

% TYPESETTING ELEMENTS

% style of section presented in the table of contents
\setbeamertemplate{section in toc}{$\blacktriangleright$~\inserttocsection}

% style of subsection presented in the table of contents
\setbeamertemplate{subsection in toc}{}
\setbeamertemplate{subsection in toc}{\textcolor{white}\footnotesize\hspace{1.2 em}$\blacktriangleright$~\inserttocsubsection}

% automate subtitle of each frame
\makeatletter
%\pretocmd\beamer@checkframetitle{\framesubtitle{\thesection\, \secname}}
\makeatother

% avoid numbering of frames that are breaked into multiply slides
\setbeamertemplate{frametitle continuation}{}

% at the begining of section, add table of contents with the current section highlighted
\AtBeginSection[]{
  \begingroup
  \themecolor{blue}
  \begin{chapter}[../images/titleimage.png]{black!90}{\insertsectionhead}
   %\tableofcontents[currentsection]
  \end{chapter}
  \endgroup
}

% at the beginning of subsection, add subsection title page
\AtBeginSubsection[]
{
  \begin{frame}{\,}{\thesection\, \secname}
    \fontfamily{ptm}\selectfont
    \centering\textsl{\textbf{\textcolor{aracomblue}{
          \large Section \thesection.\thesubsection%
          \vskip15pt
          \LARGE \subsecname%
        }}}
  \end{frame}
}

% code block setting
\definecolor{codegreen}{RGB}{101,218,120}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
  % backgroundcolor=\color{backcolour},
  commentstyle=\color{aracomblue},
  keywordstyle=\color{magenta},
  numberstyle=\tiny\color{codegray},
  stringstyle=\color{codepurple},
  basicstyle=\ttfamily\scriptsize,
  breakatwhitespace=false,
  breaklines=true,
  captionpos=b,
  keepspaces=true,
  numbers=left,
  numbersep=5pt,
  showspaces=false,
  showstringspaces=false,
  showtabs=false,
  tabsize=4,
  xleftmargin=10pt,
  xrightmargin=10pt,
}

\lstset{style=mystyle}

% NEW COMMANDS

% set colored hyperlinks command
\newcommand{\hrefcol}[2]{\textcolor{aracomgrey}{\href{#1}{#2}}}
\newcommand{\hlinkcol}[1]{\hrefcol{#1}{#1}}


% centering paragraph statement
\newcommand{\centerstate}[1]{
  \centering
  \begin{columns}
    \begin{column}{0.8\textwidth}
      #1
    \end{column}
  \end{columns}
}

% colored textbf
\newcommand{\atextbf}[1]{\textbf{\textcolor{aracomblue}{#1}}}
\newcommand{\atextsl}[1]{\textsl{\textcolor{aracomblue}{#1}}}
\newcommand{\aemph}[1]{\emph{\textcolor{aracomblue}{#1}}}

% about page
\newcommand{\aboutpage}[2]{
  \begingroup
  \themecolor{blue}
  \begin{frame}[c]{#1}{\,}
    \centering
    \begin{minipage}{\textwidth}
      \usebeamercolor[fg]{normal text}
      \centering
      \Large \textsl{\normalsize #2}
    \end{minipage}
  \end{frame}
  \endgroup
}

% bibliography page
\newcommand{\bibliographpage}{
  \section{References}

  \begingroup
  \themecolor{blue}
  \begin{frame}[allowframebreaks]{References}{\,}
    \tiny
    \printbibliography[heading=none]
  \end{frame}
  \endgroup
}