\mode<presentation>

% Requirement
\RequirePackage{tikz}
\RequirePackage{etoolbox}

\useinnertheme{rectangles}

\setbeamertemplate{background canvas}{\includegraphics[width=\paperwidth,height=\paperheight]{../common/bg.pdf}}

\setbeamertemplate{navigation symbols}{}

\setbeamertemplate{itemize item}[triangle]
%\setbeamertemplate{itemize subitem}[circle]
\setbeamertemplate{itemize subitem}{$\rhd$}
\setbeamertemplate{itemize subsubitem}[circle]


%colortheme
\definecolor{iut}{RGB}{149,193,31}
\definecolor{gris}{RGB}{89,89,89}
\definecolor{ficelle}{RGB}{205,200,191}
\definecolor{attention}{RGB}{214,141,123}
\definecolor{code highlight}{RGB}{239,233,228}%

\setbeamercolor*{palette primary}{fg=iut,bg=gris}

\setbeamercolor*{title}{fg=iut, bg=white}
\setbeamercolor*{subtitle}{fg=gris, bg=white}

\setbeamercolor*{title page header}{fg=iut, bg=white}
\setbeamercolor*{subtitle page header}{fg=gris, bg=white}
\setbeamercolor*{foot}{fg=white, bg=iut}
\setbeamercolor*{foot number}{fg=gris, bg=white}

\setbeamercolor{part title}{fg=iut}

\setbeamercolor{structure}{fg=iut}

%\setbeamercolor{itemize item}{fg=iut}
%\setbeamercolor{itemize subitem}{fg=iut}
%\setbeamercolor{itemize subsubitem}{fg=iut}

%\setbeamercolor{enumerate item}{fg=iut}
%\setbeamercolor{enumerate subitem}{fg=iut}
%\setbeamercolor{enumerate subsubitem}{fg=iut}

%\setbeamercolor{item projected}{fg=white, bg=iut}
%\setbeamercolor{subitem projected}{fg=white, bg=iut}
%\setbeamercolor{subsubitem projected}{fg=white, bg=iut}

\setbeamercolor{alerted text}{fg=iut}
\setbeamercolor{example text}{fg=ficelle}

\setbeamercolor{block title}{use=palette primary, fg=white, bg=palette primary.fg}
\setbeamercolor{block body}{use=palette primary, bg=palette primary.fg!7}
\setbeamercolor{block title example}{fg=white, bg=ficelle}
\setbeamercolor{block body example}{parent=normal text, bg=ficelle!10!white}
\setbeamercolor{block title alerted}{fg=white,bg=attention}
\setbeamercolor{block body alerted}{parent=normal text, bg=attention!10!white}
\AtBeginEnvironment{alertblock}{\setbeamercolor{alerted text}{fg=attention}}

%fonttheme
\setbeamerfont{title}{size=\LARGE,series=\bfseries}
\setbeamerfont{subtitle}{size=\large,shape=\scshape,series=\bfseries}
\setbeamerfont{date}{size=\footnotesize}

\setbeamerfont{frame title}{size=\Large,series=\bfseries}
\setbeamerfont{frame subtitle}{size=\normalsize,shape=\scshape,series=\bfseries}


%%innertheme
\defbeamertemplate*{title page}{IUT}[1][]{ 
  \vfill
  \begin{beamercolorbox}[wd=.9\paperwidth, sep=5pt, center, #1]{title page header}
    \usebeamerfont{title}\inserttitle\par%
      \ifx\insertsubtitle\@empty%
      \else%
        \vskip.3em%
              {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
      \fi%     
  \end{beamercolorbox}

  \vskip1.5em\par

  \begin{beamercolorbox}[sep=8pt,center,#1]{author}
    \usebeamerfont{author}\mdseries\large\insertauthor
  \end{beamercolorbox}
  \vfill
  \begin{beamercolorbox}[sep=8pt,center,#1]{institute}
    \insertinstitute
  \end{beamercolorbox}
  \begin{beamercolorbox}[sep=8pt,center,#1]{date}
    \usebeamerfont{date}\insertdate
  \end{beamercolorbox}
  \vfill
}

%outertheme
\defbeamertemplate*{frametitle}{IUT}[1][]{
  \begin{beamercolorbox}[wd=\paperwidth, sep=10pt, #1, ignorebg]{title page header}
    \usebeamerfont{frame title}\insertframetitle\par%
  \end{beamercolorbox}% 
  \ifx\insertframesubtitle\@empty%
  \else%
  \nointerlineskip%
  \begin{beamercolorbox}[wd=\paperwidth, sep=2pt, #1, leftskip=25pt, ignorebg]{subtitle page header}
    \usebeamerfont{frame subtitle}\usebeamercolor[fg]{subtitle page header}\insertframesubtitle\par%
  \end{beamercolorbox}%
  \fi%

  \vspace{-1em}
}

\defbeamertemplate*{footline}{IUT}{
  \leavevmode
  \begin{tikzpicture}[overlay, every node/.style={scale=.8, transform shape}]
  \usebeamercolor[bg]{foot}
  \draw[fill] (8ex,3ex) circle (4.8ex);
  \usebeamercolor[fg]{foot}
  \draw[fill] (8ex,3ex) circle (4ex);
  \usebeamercolor[fg]{foot number}
  \node[scale=1.5] at (8ex,3ex) {$^\text{\insertframenumber}/_\text{\insertmainframenumber}$};
  \end{tikzpicture}
  \raisebox{3ex}{\hspace*{15ex}\insertsection}
}



\let\oldtt\texttt
\renewcommand{\texttt}[1]{\colorbox{code highlight}{\oldtt{#1}}}


\AtBeginSection[]{
  \begin{frame}
    \vfill 
    \begin{center}
      \begin{tikzpicture}
        \fill[iut, rounded corners] (-4,-1.5) rectangle (4,1.5);
        \node[white, font=\huge, text width=7cm, align=center] at (0,0) {\insertsectionhead};
      \end{tikzpicture}
    \end{center}
    \vfill 
  \end{frame}
}



\mode<all>


\newcommand{\colorExtract}[3]{
  \usebeamercolor{#1}
  \definecolor{#2}{named}{fg}
  \definecolor{#3}{named}{bg}
}

\colorExtract{palette primary}{iut}{gris}
