\RequirePackage{standalone} %Nötig, da dieses Paket erst nach hyperref kommen muss

% allgemeine Voreinstellungen
% ****************************************************************
\pagestyle{scrheadings}

% Layoutfestlegungen
% ****************************************************************
\definecolor{chapter}{rgb}{0,0.25,0.56}
\definecolor{section}{rgb}{0.27,0.33,0.90}
\definecolor{subsection}{rgb}{0.54,0.66,0.90}
\definecolor{subsubsection}{rgb}{0.14,0.17,0.95}
\definecolor{paragraph}{cmyk}{0.5,0,.1,.39}

\addtokomafont{chapter}{\color{chapter}}
\addtokomafont{section}{\color{section}}
\addtokomafont{subsection}{\color{subsection}}
\addtokomafont{subsubsection}{\color{subsubsection}}
\addtokomafont{paragraph}{\color{paragraph}}

\hypersetup{
    hidelinks
}

% Kopfzeile festlegen
% ****************************************************************
% Kopf, Innenseite
\ihead{\leftmark}

% Kopf, Mitte
\chead{}

% Kopf, Außenseite
\ohead{\Titel}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Aufgabeneinstellungen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\DeclareExerciseProperty*{pcAufgabe}
\DeclareExerciseEnvironmentTemplate{schule-leitprogramm}
{%
\tcolorbox[
    colback = grey9,
    colframe = grey9,
    sharp corners,
    coltitle = black,
    flushleft title,
    bottomtitle=0mm,
    boxsep=0.5mm,
    top=0.5mm,
    bottom=1mm,
    breakable,
    title = \IfExerciseBooleanPropertyTF{pcAufgabe}{\uebungPCBild}{\uebungBild} \GetExerciseName~\GetExerciseProperty{counter}%
        \hfill%
        \ifthenelse{\boolean{schule@hinweislink}}{%
            \GetExercisePropertyT{bearbeitungshinweis}{\hyperref[hinweis:\ExerciseID]{\colorbox{black!30}{\color{blue!90}H}}}%
        }{}%
        \ifthenelse{\boolean{schule@loesunglink}}{%
            \IfExistSolutionT{~\hyperref[loesung:\ExerciseID]{\colorbox{black!30}{\color{blue!90}L}}}%
        }{}%
    ]%
    \label{aufgabe:\ExerciseID}
}
{\endtcolorbox}

\DeclareExerciseEnvironmentTemplate{schule-leitprogramm-loesung} {%
    \addpenalty{-9000}\smallskip\noindent\textbf{%
        % Falls Zusatzaufgabe:
        %   \llap{\GetExerciseProperty{symbol}}
        \ifthenelse{\equal{\ExerciseType}{zusatzaufgabe}}{\llap{\GetExerciseProperty{symbol}$\bigstar$}~}{\llap{\GetExerciseProperty{symbol}~}}%
        \XSIMmixedcase{\GetExerciseName}\nobreakspace
        \GetExerciseProperty{counter}\label{loesung:\ExerciseID}%
        \ifthenelse{\boolean{schule@loesunglink}}{\hfill\hyperref[aufgabe:\ExerciseID]{\colorbox{black!30}{\color{blue!90}$\leftarrow$}}}{}%
    }\par\nopagebreak[0]
}
{\par}%

\xsimsetup{
    aufgabe/template=schule-leitprogramm,
    aufgabe/within=chapter,
    loesung/template=schule-leitprogramm-loesung,
    print-solutions/headings=false,
}

\DeclareExerciseEnvironmentTemplate{schule-leitprogramm-kontrollaufgabe} {%
    \addpenalty{-3000}\smallskip\noindent\textbf{\color{paragraph}%
    \XSIMmixedcase{\GetExerciseName}\nobreakspace\GetExerciseProperty{counter}}:~~
}
{\par}%

\DeclareExerciseType{kontrollaufgabe}{
    exercise-env = kontrollaufgabe,
    solution-env = kontrollloesung,
    exercise-name = \XSIMtranslate{question},
    exercises-name = \XSIMtranslate{questions},
    solution-name = \XSIMtranslate{solution},
    exercise-template = schule-leitprogramm-kontrollaufgabe,
    solution-template = schule-leitprogramm-kontrollaufgabe,
}

\makeatletter% siehe FAQ (aber wirklich nachsehen!)
\newcommand*{\headingpar}{\par\nobreak\@afterheading}
\makeatother% siehe FAQ

\tcbset{
  leitprogrammBox/.style={
    colback = grey9,
    colframe = grey9,
    sharp corners,
    coltitle = black,
    flushleft title,
    bottomtitle=0mm,
    boxsep=0.5mm,
    top=0.5mm,
    bottom=1mm,
    fonttitle=\large,
    breakable,
  }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Boxen für das Leitprogramm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newtcolorbox{hinweisBox}{leitprogrammBox, title=\hinweisBild{} Hinweis}
\newtcolorbox{uebersichtBox}{leitprogrammBox, title = \wegweiserBild{} Übersicht}
\newtcolorbox{lernzieleBox}{leitprogrammBox, title = \zielBild{} Lernziele}
\newtcolorbox{theorieBox}{leitprogrammBox, title = \buchBild{} Theorie}
\newtcolorbox{nothelferBox}{leitprogrammBox, title = \krankenwagenBild{} Nothelfer}
\newtcolorbox{loesungenBox}{leitprogrammBox, title = \gluehlampeBild{} Lösungen}
\newtcolorbox{lernkontrolleBox}{leitprogrammBox, title= \lernkontrolleBild{} Lernkontrolle}

%Monatsname für z.B. Titelblatt
\newcommand{\monatWort}[1]{%
    \IfInteger{#1}{%
        \ifcase #1
            Monat 0 \or Januar \or Februar \or März  \or April \or Mai \or Juni \or Juli %
            \or August \or September \or Oktober \or November \or Dezember \fi%
    }{Unbekannter Monat}%
}

\ExplSyntaxOn

\int_new:N \g_feldnummer_int

%TextFeld in das Ergebnisse eingetragen werden können
\newcommand{\TextFeld}[1]{%
    \par\smallskip
    \begin{Form}
    \TextField[width=\linewidth,%
    height=#1,multiline=true,borderwidth=0,name={feld\int_use:N \g_feldnummer_int}]{}%
    \end{Form}
    \int_gincr:N \g_feldnummer_int
}%

\ExplSyntaxOff

% Ausgabe von Hinweisen
% modifiziert für das Leitprogramm
% ********************************************************************

% Vollständige Liste
\renewcommand{\bearbeitungshinweisliste}{
    \ForEachUsedExerciseByType{%
        \def\ExerciseType{##1}%
        \def\ExerciseID{##2}%
        \GetExercisePropertyT{bearbeitungshinweis}{%
            \addpenalty{-3000}\smallskip\noindent\textbf{%
                Hinweis zu \XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{chapter}.##3\label{hinweis:##2}\hfill\hyperref[aufgabe:\ExerciseID]{\colorbox{black!30}{\color{blue!90}$\leftarrow$}}%
            }\par\smallskip
            ####1 \par%
        }%
    }%
}
