% !TEX root = ../Main.tex
% ========================================================
% Vereinfachung zur Darstellung von Tagesordnungspunkten
% (TOP) in einem Sitzungsprotokoll.
% ========================================================

\NewEnviron{TOP}[1]{
    \goodbreak
    \section{#1}
    \BODY
    \vspace{1.5em}
}

% tok for the committee members
\newtoks\committeeMembers

% counters for: STUPA, AStA, Präsent, Online
\newcounter{stupaCounter}
\newcounter{astaCounter}
\newcounter{presentCounter}
\newcounter{onlineCounter}

% Command to count based on flags: STUPA, AStA, Präsent, Online
\DeclareRobustCommand{\CountPresence}[4]{
    \ifthenelse{#1=1}{\stepcounter{stupaCounter}}{}
    \ifthenelse{#2=1}{\stepcounter{astaCounter}}{}
    \ifthenelse{#3=1}{\stepcounter{presentCounter}}{}
    \ifthenelse{#4=1}{\stepcounter{onlineCounter}}{}
}

% Command to add a line to the presence table
%                       Online ┑
%                   Präsent ┑  │
%                   ASTA ┑  │  │                                 ┍ Bis*
%               STUPA ┑  │  │  │  ┍ Name      ┍ Rolle(n)   ┍ Ab* │
% \AddCommitteeMember{1}{1}{1}{0}{Max Muster}{Musterrolle}{4:20}{6:09}
\DeclareRobustCommand{\AddCommitteeMember}[8]{
    \CountPresence{#1}{#2}{#3}{#4}
    \committeeMembers=\expandafter{\the\committeeMembers
        \PresenceTableLine{#5}{#6}{#7}{#8}{#1}{#2}{#3}{#4}
    }
}

\DeclareRobustCommand{\AddPresenceSeparator}[0]{
    \committeeMembers=\expandafter{\the\committeeMembers
        \hdashline\addlinespace[1ex]
    }
}

% Command to make the final table
\DeclareRobustCommand{\MakePresenceTable}{
    \begin{CustomBox}{\faIcon{user}}{eggplant}
        \chapter{Anwesenheitsliste}
        \PresenceTable{
            \the\committeeMembers
            \specialrule{.2em}{.05em}{.05em}\addlinespace[1ex]
            \PresenceTableSums{\thestupaCounter}{\theastaCounter}{\thepresentCounter}{\theonlineCounter}
            \specialrule{.2em}{.05em}{.05em}
        }
    \end{CustomBox}
}