
%  ▄▄·       ▄• ▄▌ ▐ ▄ ▄▄▄▄▄▄▄▄ .▄▄▄  
% ▐█ ▌▪ ▄█▀▄ █▪██▌•█▌▐█•██  ▀▄.▀·▀▄ █·
% ██ ▄▄▐█▌.▐▌█▌▐█▌▐█▐▐▌ ▐█.▪▐▀▀▪▄▐▀▀▄ 
% ▐███▌▐█▌.▐▌▐█▄█▌██▐█▌ ▐█▌·▐█▄▄▌▐█•█▌
% ·▀▀▀  ▀█▄▀▪ ▀▀▀ ▀▀ █▪ ▀▀▀  ▀▀▀ .▀  ▀

\usepackage{xstring}
% tcolorbox and other stylistic elements (i.e. inline versions of them) that have counters
\newcounter{lemmas}
\newcounter{definitions}
\newcounter{corollaries}
\newcounter{theorems}
\newcounter{axioms}
\newcounter{examples}
\newcounter{facts}
\newcounter{propositions}
\newcounter{formulas}
\newcounter{remarks}
\newcounter{all}


% ┌                                                ┐
% │             Numbering of sections              │
% └                                                ┘
\newcommand{\subsectionRendering}[1]{
    \ifnum\value{numberSubsections}=1
        \ifthenelse{\equal{#1}{dot}}{%
            \arabic{section}.\arabic{subsection}%
        }{%
            \arabic{section}-\arabic{subsection}%
        }%
    \else
        \ifnum\value{numberSubsections}=2
            \ifthenelse{\equal{#1}{dot}}{%
                \arabic{section}.\arabic{subsection}.\arabic{subsubsection}%
            }{%
                \arabic{section}.\arabic{subsection}.\arabic{subsubsection}%
            }%
        \else
            \arabic{section}%
        \fi
    \fi}

\newcommand{\usenumberArabic}[1]{%
    % \generateLabel{#1}{\subsectionRendering{dash}}
    \ifnum\value{numberingConfig}=1
        \subsectionRendering{dot}.\arabic{#1}\stepcounter{#1}%
    \else
        \ifnum\value{numberingConfig}=2
            \ifthenelse{\equal{#1}{definitions}}{%
                \subsectionRendering{dot}.\arabic{definitions}\stepcounter{definitions}%
            }{%
                \subsectionRendering{dot}.\arabic{all}\stepcounter{all}%
            }%
        \else
            \ifnum\value{numberingConfig}=3
                \subsectionRendering{dot}.\arabic{all}\stepcounter{all}%
            \else
                \relax%
            \fi
        \fi
    \fi}

\newcommand{\generateLabel}[2]{\label{#1:#2}}
%
% \newcommand{\labelIt}[1]{\label{#1:}}

% ────────────────────────────────────────────────────────────────────

\newcounter{numberingConfigStore}
\setcounter{numberingConfigStore}{\value{numberingConfig}}

\newcommand{\setNumberingStyle}[1]{
    \setcounter{numberingConfig}{#1}
    \ifthenelse{\equals{#1}{0}}{
        \setcounter{numberingConfigStore}{#1}
    }{}
}
\newcommand{\numberingOff}{
    \setcounter{numberingConfig}{0}
}
\newcommand{\numberingOn}{
    \setcounter{numberingConfig}{\value{numberingConfigStore}}
}

% Reset definition, lemma, etc counters, add a new page
\newcommand{\newsection}{
    \newpage
    \newsectionNoPB
}

% Reset definitions, lemma, etc counters, do not add new page
\newcommand{\newsectionNoPB}{
    \setcounter{lemmas}{1}
    \setcounter{definitions}{1}
    \setcounter{corollaries}{1}
    \setcounter{theorems}{1}
    \setcounter{axioms}{1}
    \setcounter{examples}{1}
    \setcounter{facts}{1}
    \setcounter{propositions}{1}
    \setcounter{formulas}{1}
    \setcounter{remarks}{1}
    \setcounter{all}{1}
}
\newsectionNoPB


% ────────────────────────────────────────────────────────────────────
%          ╭────────────────────────────────────────────────╮
%          │                  Tcolorboxes                   │
%          ╰────────────────────────────────────────────────╯
% ────────────────────────────────────────────────────────────────────

% Definitions
\newtcolorbox{definition}[2][]{mainboxstyle,colback=blue!5!white,colframe=blue!75!black,colbacktitle=blue!75!black,title={\large #2},overlay={\node[overlaystyle,draw=blue!75!black,fill=blue!75!black] at (frame.north east) {\large Definition\usenumberArabic{definitions}};},#1}

% Theorems
\newtcolorbox{theorem}[2][]{mainboxstyle,colback=ForestGreen!5!white,colframe=ForestGreen!75!black,colbacktitle=ForestGreen!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=ForestGreen!75!black,fill=ForestGreen!75!black] at (frame.north east) {\large \translate{Theorem}{\theoremde}\usenumberArabic{theorems}};},#1}

% Lemmas
\newtcolorbox{lemma}[2][]{mainboxstyle,colback=Aquamarine!5!white,colframe=Aquamarine!75!black,colbacktitle=Aquamarine!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=Aquamarine!75!black,fill=Aquamarine!75!black] at (frame.north east) {\large Lemma\usenumberArabic{lemmas}};},#1}

% Corollaries
\newtcolorbox{corollary}[2][]{mainboxstyle,colback=teal!5!white,colframe=teal!75!black,colbacktitle=teal!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=teal!75!black,fill=teal!75!black] at (frame.north east) {\large \translate{Corollary}{Korollar}\usenumberArabic{corollaries}};},#1}

% Axioms
\newtcolorbox{axiom}[2][]{mainboxstyle,colback=JungleGreen!5!white,colframe=JungleGreen!75!black,colbacktitle=JungleGreen!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=JungleGreen!75!black,fill=JungleGreen!75!black] at (frame.north east) {\large Axiom\usenumberArabic{axioms}};},#1}

% Facts
\newtcolorbox{fact}[2][]{mainboxstyle,colback=SeaGreen!5!white,colframe=SeaGreen!75!black,colbacktitle=SeaGreen!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=SeaGreen!75!black,fill=SeaGreen!75!black] at (frame.north east) {\large \translate{Fact}{Fakt}\usenumberArabic{facts}};},#1}

% Propositions
\newtcolorbox{proposition}[2][]{mainboxstyle,colback=Cyan!5!white,colframe=Cyan!75!black,colbacktitle=Cyan!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=Cyan!75!black,fill=Cyan!75!black] at (frame.north east) {\large Proposition\usenumberArabic{propositions}};},#1}

% Examples
\newtcolorbox{example}[2][]{mainboxstyle,colback=gray!5!white,colframe=gray!75!black,colbacktitle=gray!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=gray!75!black,fill=gray!75!black] at (frame.north east) {\large \translate{Example}{Beispiel}\usenumberArabic{examples}};},#1}

% Formula
\newtcolorbox{formula}[2][]{mainboxstyle,colback=red!5!white,colframe=red!75!black,colbacktitle=red!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=red!75!black,fill=red!75!black] at (frame.north east) {\large \translate{Formula}{Formel}\usenumberArabic{formulas}};},#1}

% Remark
\newtcolorbox{remark}[2][]{mainboxstyle,colback=green!5!white,colframe=green!75!black,colbacktitle=green!75!black,title={\large #2},
    overlay={\node[overlaystyle,draw=green!75!black,fill=green!75!black] at (frame.north east) {\large \translate{Remark}{Bemerkung} \usenumberArabic{remarks}};},#1}


% ────────────────────────────────────────────────────────────────────
%          ╭────────────────────────────────────────────────╮
%          │              Inline environments               │
%          ╰────────────────────────────────────────────────╯
% ────────────────────────────────────────────────────────────────────


% Inline environments (inline)
\newcommand{\inlineex}{\bg{gray}{\translate{Example}{Beispiel}\usenumberArabic{examples}:}}
\newcommand{\inlinedef}{\bg{blue}{Definition\usenumberArabic{definitions}:}}
\newcommand{\inlineformula}{\bg{red}{\translate{Formula}{Formel}\usenumberArabic{formulas}:}}
\newcommand{\inlinelemma}{\bg{Aquamarine}{Lemma\usenumberArabic{lemmas}:}}
\newcommand{\inlinetheorem}{\bg{ForestGreen}{\translate{Theorem}{\theoremde}\usenumberArabic{theorems}:}}
\newcommand{\inlineaxiom}{\bg{JungleGreen}{Axiom\usenumberArabic{axioms}:}}
\newcommand{\inlinecorollary}{\bg{teal}{\translate{Corollary}{Korollar}\usenumberArabic{corollaries}:}}
\newcommand{\inlinefact}{\bg{SeaGreen}{\translate{Fact}{Fakt}\usenumberArabic{facts}:}}
\newcommand{\inlineproposition}{\bg{Cyan}{Proposition\usenumberArabic{propositions}:}}
\newcommand{\inlineremark}{\bg{green}{\translate{Remark}{Bemerkung}\usenumberArabic{remarks}:}}
\newcommand{\inlineproof}{\bg{magenta}{\translate{Proof}{Beweis}:}}

% Enhanced inline environments
\newcommand{\fancyex}[1]{\bg{gray}{\translate{Example}{Beispiel}\usenumberArabic{examples}:} \textit{(#1)}}
\newcommand{\fancydef}[1]{\bg{blue}{Definition\usenumberArabic{definitions}:} \textit{(#1)}}
\newcommand{\fancyformula}[1]{\bg{red}{\translate{Formula}{Formel}\usenumberArabic{formulas}:} \textit{(#1)}}
\newcommand{\fancylemma}[1]{\bg{Aquamarine}{Lemma\usenumberArabic{lemmas}:} \textit{(#1)}}
\newcommand{\fancytheorem}[1]{\bg{ForestGreen}{\translate{Theorem}{\theoremde}\usenumberArabic{theorems}:} \textit{(#1)}}
\newcommand{\fancyaxiom}[1]{\bg{JungleGreen}{Axiom\usenumberArabic{axioms}:} \textit{(#1)}}
\newcommand{\fancycorollary}[1]{\bg{teal}{\translate{Corollary}{Korollar}\usenumberArabic{corollaries}:} \textit{(#1)}}
\newcommand{\fancyfact}[1]{\bg{SeaGreen}{\translate{Fact}{Fakt}\usenumberArabic{facts}:} \textit{(#1)}}
\newcommand{\fancyproposition}[1]{\bg{Cyan}{Proposition\usenumberArabic{propositions}:} \textit{(#1)}}
\newcommand{\fancyremark}[1]{\bg{green}{\translate{Remark}{Bemerkung}\usenumberArabic{remarks}:} \textit{(#1)}}
\newcommand{\fancyproof}[1]{\bg{magenta}{\translate{Proof}{Beweis}: \textit{(#1)}}}

% short environments (abbreviated)
\newcommand{\shortex}{\bg{gray}{\translate{Ex}{Bsp}\usenumberArabic{examples}:}}
\newcommand{\shortdef}{\bg{blue}{D\usenumberArabic{definitions}:}}
\newcommand{\short}{\bg{red}{F\usenumberArabic{formulas}:}}
\newcommand{\shortlemma}{\bg{Aquamarine}{L\usenumberArabic{lemmas}:}}
\newcommand{\shorttheorem}{\bg{ForestGreen}{\translate{T}{\StrMid{\theoremde}{1}{1}}\usenumberArabic{theorems}:}}
\newcommand{\shortaxiom}{\bg{JungleGreen}{A\usenumberArabic{axioms}:}}
\newcommand{\shortcorollary}{\bg{teal}{\translate{C}{K}\usenumberArabic{corollaries}:}}
\newcommand{\shortfact}{\bg{SeaGreen}{F\usenumberArabic{facts}:}}
\newcommand{\shortproposition}{\bg{Cyan}{P\usenumberArabic{propositions}:}}
\newcommand{\shortremark}{\bg{green}{\tr{R}{B}\usenumberArabic{remarks}:}}
\newcommand{\shortproof}{\bg{magenta}{\translate{Proof}{Beweis}:}}

% Enhanced short environments (abbreviated)
\newcommand{\compactex}[1]{\bg{gray}{\translate{Ex}{Bsp} \usenumberArabic{examples}:} \textit{(#1)}}
\newcommand{\compactdef}[1]{\bg{blue}{D \usenumberArabic{definitions}:} \textit{(#1)}}
\newcommand{\compactformula}[1]{\bg{red}{F \usenumberArabic{formulas}:} \textit{(#1)}}
\newcommand{\compactlemma}[1]{\bg{Aquamarine}{L \usenumberArabic{lemmas}:} \textit{(#1)}}
\newcommand{\compacttheorem}[1]{\bg{ForestGreen}{\translate{T}{\StrMid{\theoremde}{1}{1}} \usenumberArabic{theorems}:} \textit{(#1)}}
\newcommand{\compactaxiom}[1]{\bg{JungleGreen}{A \usenumberArabic{axioms}:} \textit{(#1)}}
\newcommand{\compactcorollary}[1]{\bg{teal}{\translate{C}{K} \usenumberArabic{corollaries}:} \textit{(#1)}}
\newcommand{\compactfact}[1]{\bg{SeaGreen}{F \usenumberArabic{facts}:} \textit{(#1)}}
\newcommand{\compactproposition}[1]{\bg{Cyan}{P \usenumberArabic{propositions}:} \textit{(#1)}}
\newcommand{\compactremark}[1]{\bg{green}{\tr{R}{B} \usenumberArabic{remarks}:} \textit{(#1)}}
\newcommand{\compactproof}[1]{\bg{magenta}{\translate{Proof}{Beweis}: \textit{(#1)}}}
