%% Copyright (C) 2017 Achim D. Brucker, https://www.brucker.ch
%%
%% License:
%%   This program can be redistributed and/or modified under the terms
%%   of the LaTeX Project Public License Distributed from CTAN
%%   archives in directory macros/latex/base/lppl.txt; either
%%   version 1.3c of the License, or (at your opinion) any later version.
%%   OR
%%   The 2-clause BSD-style license.
%%
%%   SPDX-License-Identifier: LPPL-1.3c+ OR BSD-2-Clause
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\RequirePackage{etoolbox}
\RequirePackage{graphicx}
\RequirePackage{keycommand}

\ProvidesPackage{lh-lecture-presentation}
     [2017/02/08 v0.0  LaTeX style for lectures (add-on to lh-presentation)]


  \newcommand{\lecturedate}[1]{\date{#1}}

  \def\lh@lecture@length{}
  \newcommand{\lecturelength}[1]{\gdef\lh@lecture@length{#1}}

  \def\lh@lecture@description{}
  \newcommand{\lecturedescription}[1]{\gdef\lh@lecture@description{#1}}

  \newboolean{lh@lecture@bib}
  \setboolean{lh@lecture@bib}{false}
  \newboolean{lh@lecture@cloze}
  \setboolean{lh@lecture@cloze}{false}


%%%% OLD Definition:   
\newenvironment{lecturedesc}[7]{
  \lecturedate{#3}%
  \lecture{#1}{#2}%
  \lecturelength{#4}%
  \part{#1}
  \subtitle{#1}%
  \ifx#5\@empty%
  \else%
  \titlevisual{#5}%
  \fi
  \setboolean{lh@lecture@bib}{#6}
  \setboolean{lh@lecture@cloze}{#7}
  \begin{frame}[plain]\maketitle\end{frame}
  \begin{bibunit}[alpha]
  }{
    \section{Appendix}
    \ThanksFrame
    \ifthenelse{\boolean{lh@lecture@bib}}{%
    \begin{frame}[allowframebreaks]
      \frametitle{Bibliography}
      \footnotesize
      \putbib[adb-long,brucker,fmde]
    \end{frame}}{}
    \ifthenelse{\boolean{lh@lecture@cloze}}{%
      \begin{frame}
      \frametitle{Cloze Solutions}
      \printendnotes
    \end{frame}}{}
\end{bibunit}
}

\newcounter{lh@lecture@part@cnt}
\stepcounter{lh@lecture@part@cnt}

\newcommand{\lh@lecture}[2]{%
  \@expandtwoargs\lecture{#1}{\expanded{#2}}%
}%

\newcommand{\centry}[2]{\item[ \usebeamercolor*{normal
    text} #1] #2}
\newkeyenvironment*{lecturepart}[%
  part=%
  ,label=%
  ,date=%
  ,lastmodify=%
  ,duration=%
  ,visual={lh-title-visual-lock-16x9}%
  ,bool bibliography=false%
  ,bool cloze=false%
  ,takeaways=%
  ,changelog=%
  ]{%

  \lh@lecture{Part \thelh@lecture@part@cnt: \commandkey{part}}{\commandkey{label}}
  \ifthenelse{\equal{\commandkey{lastmodify}}{}}{%
    \lecturedate{\commandkey{date}}%
  }{%
    \lecturedate{\commandkey{date} (Last modification: \commandkey{lastmodify})}%
  }
  \lecturelength{\commandkey{duration}}%
  \part{Part \thelh@lecture@part@cnt: \commandkey{part}}
  \subtitle{Part \thelh@lecture@part@cnt: \commandkey{part}}%

  \titlevisual{\commandkey{visual}}%
  \ifthenelse{\equal{\commandkey{bibliography}}{1}}{%
    \setboolean{lh@lecture@bib}{true}
  }{%
    \setboolean{lh@lecture@bib}{false}
  }
  \ifthenelse{\equal{\commandkey{cloze}}{1}}{%
    \setboolean{lh@lecture@cloze}{true}
  }{%
    \setboolean{lh@lecture@cloze}{false}
  }
  \begin{frame}[plain]\maketitle\end{frame}%
\begin{frame}
  \frametitle{Outline}
  \tableofcontents[sectionstyle=show/show,subsectionstyle=hide/hide]
  \begin{tikzpicture}[remember picture,overlay]
    \node[above, xshift=-2.5cm,yshift=0.4cm] at (current page.south east){%
      \scalebox{0.6}{\begin{minipage}{7.42cm}
        \begin{block}{Changelog}
          \begin{description}
            \commandkey{changelog}
          \centry{\commandkey{date}}{Initial release} 
          \end{description}
        \end{block}
      \end{minipage}}
    };
\end{tikzpicture}
\end{frame}



  
  \begin{bibunit}[alpha]
}{
     \ifcommandkey{takeaways}{%
       \KeyTakeAwayFrame{
         \commandkey{takeaways}
       }
     }{%
       \ThanksFrame
     }  
     \section{Appendix}
     \ifthenelse{\boolean{lh@lecture@bib}}{%
     \begin{frame}[allowframebreaks]
       \frametitle{Bibliography}
       \footnotesize
       \putbib[adb-long,brucker,fmde]
     \end{frame}}{}
     \ifthenelse{\boolean{lh@lecture@cloze}}{%
       \begin{frame}
       \frametitle{Cloze Solutions}
       \printendnotes
     \end{frame}}{}
 \end{bibunit}
\stepcounter{lh@lecture@part@cnt}
}



  

\newcommand\appendtographicspath[1]{%
  \gappto\Ginput@path{{#1}}%
}
\newcommand\prependtographicspath[1]{%
  \gpreto\Ginput@path{{#1}}%
}

\newcommand{\includelecture}[2]{
  \prependtographicspath{#1-#2/figures/}
  \include{#1-#2/#2}
}


\endinput

