\NeedsTeXFormat{LaTeX2e}
% extensions

\RequirePackage{colorscheme}
\RequirePackage{base}
\RequirePackage{myhdr}
\RequirePackage{notbeamer}

\RequirePackage{xsim}

\DeclareExerciseTagging{step}
\DeclareExerciseTagging{type}
\DeclareExerciseTagging{tribe}
\DeclareExerciseTagging{difficulty}
\DeclareExerciseTagging{origin}
\DeclareExerciseTagging{mode}

\DeclareExerciseTranslations{total}{
    French = total,
}

\DeclareExerciseEnvironmentTemplate{exo}{%
    \subsection*
    {%
        \color{exercise}{\XSIMmixedcase{\GetExerciseName}}\nobreakspace
        \GetExerciseProperty{counter}%
        \hspace{0.5cm} \GetExercisePropertyT{mode}
        {{\PropertyValue}}%
        \hspace{0.5cm} \color{line}\hrulefill \hspace{0.5cm}
        \color{exercise}
        \GetExercisePropertyT{subtitle}
        {{\PropertyValue}}%
        \GetExercisePropertyT{points}
        {{(/\PropertyValue})}%
        \noindent
    }
}{}

\xsimsetup{exercise/template=exo}

\DeclareExerciseEnvironmentTemplate{sol}{%
    \subsection*
    {%
        \color{exercise}\nobreakspace
        Exercice \GetExerciseProperty{counter}%
        \hspace{0.5cm} \color{line}\hrulefill \hspace{0.5cm}
        \color{exercise}{\XSIMmixedcase{\GetExerciseName}}
        \hspace{0.5cm} \color{line}\hrulefill \hspace{0.5cm}
        \color{exercise}
        \GetExercisePropertyT{subtitle}
        {{\PropertyValue}}%
        \noindent
    }
}{}
\xsimsetup{solution/template=sol}


\DeclareExerciseTableTemplate{DNB}{%
    \XSIMputright\ExerciseTableCode{%
        \hline
        \XSIMifblankTF{\ExerciseType}
        {}
        {\XSIMmixedcase{\GetExerciseParameter{exercise-name}}}
        &
        \XSIMmixedcase{\XSIMtranslate{points}} \\
        \hline
    }%
    \ForEachUsedExerciseByType{%
        \XSIMifeqTF{#1}{\ExerciseTableType{#1}}
        {%
            \XSIMifblankTF{\ExerciseType}
            {%
                \XSIMputright\ExerciseTableCode{%
                    \XSIMmixedcase{\ExerciseParameterGet{#1}{exercise-name} }%
                }%
            }
            {}%
            \XSIMputright\ExerciseTableCode
            {#3 & \XSIMifblankTF{#5}{\printgoal{0}}{\printgoal{#5}}\\ }%
        }
        {}%
    }
    \XSIMputright\ExerciseTableCode{%
        \hline
        \XSIMmixedcase{\XSIMtranslate{total}} &
        \XSIMifblankTF{\ExerciseType}
        {\TotalExerciseGoal{points}{}{}}
        {\TotalExerciseTypeGoal{\ExerciseType}{points}{}{}} \\
        \hline
    }%
    \XSIMexpandcode{%
        \noexpand\begin{tabular}{|\XSIMifblankTF{\ExerciseType}{l}{c}|c|}
            \noexpand\ExerciseTableCode
        \noexpand\end{tabular}%
    }%
}

\newcommand\printsectionexercises{%
        \ForEachUsedExerciseByType{%
            \ifnum\ExercisePropertyGet{##1}{##2}{step}=\value{section}
                    \printexercise{exercise}{##2}
                \fi
            }%
}

\newcommand\listsectionexercises{%

    \begin{itemize}[label={$\square$}]
        \ForEachUsedExerciseByType{%
            \ifnum\ExercisePropertyGet{##1}{##2}{step}=\value{section}%
                \item %
                    \GetExerciseProperty{mode}%
                    {{\PropertyValue}}\;%
                    \XSIMmixedcase{\GetExerciseName}\nobreakspace
                    \GetExerciseProperty{counter}%
                    {{\PropertyValue}}%
                    : %
                    \GetExerciseProperty{subtitle}%
                    {{\PropertyValue}}%
                    \dotfill
                    %Auto-évaluation
                    \begin{tikzpicture}
                        \foreach \k in {0,1,...,4}{
                            \draw (\k*0.5, 0) node[draw, star, star points=5, star point ratio=0.5]{};
                        }
                    \end{tikzpicture}
                \fi
            }%
    \end{itemize}
}

\xsimsetup{
    exercise/within = section,
    exercise/the-counter = \arabic{exercise},
}

\newcommand\searchMode{\faIcon{search}}
\newcommand\groupMode{\faIcon{users}}
\newcommand\trainMode{\faIcon{tools}}
\newcommand\projectMode{\faIcon{sitemap}}
\newcommand\infoMode{\faIcon{desktop}}

\newcommand\legendMode{%
    \textbf{Légende:} \hfill
    \searchMode: pour découvrir quelque chose
    \hfill
    \groupMode: à faire en groupe
    \hfill
    \trainMode: pour s'entrainer
}
