\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{argumentation}[2023/12/03 Argumentation]
% Author:   Lars Bengel
% E-Mail:   lars.bengel@fernuni-hagen.de
% Version:  1.1
% Date:     2023/12/03
% License:  LaTeX Project Public License 1.3c

%%%%%%%%%%% Package Requirements %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{pgfopts}                        % For managing package options
\RequirePackage{tikz}                           % For drawing the argumentation frameworks
\usetikzlibrary{positioning}                    % For relative node positioning
\usetikzlibrary{arrows.meta}                    % For directed edges / attack arrows
\usetikzlibrary{arrows}                         % For directed edges / attack arrows
\usetikzlibrary{decorations.markings}           % For creating the support edge markings

\newcommand{\argstyle}[1]{#1}                   % Defines the font style in which argument names are displayed

%%%%%%%%%% Package Options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{/argumentation/argumentstyle/.is choice,
    /argumentation/argumentstyle/standard/.code={\tikzset{argument/.style={circle,draw=black,inner sep=0,outer sep=0}}},
    /argumentation/argumentstyle/custom/.code={},
    /argumentation/argumentstyle=standard,
}

\pgfkeys{/argumentation/attackstyle/.is choice,
    /argumentation/attackstyle/standard/.code={\tikzset{attack/.style={-{stealth'}}}},
    /argumentation/attackstyle/large/.code={\tikzset{attack/.style={-{Stealth[scale=1.25]}}}},
    /argumentation/attackstyle=standard,
}

\pgfkeys{/argumentation/supportstyle/.is choice,
    /argumentation/supportstyle/standard/.code={\tikzset{support/.style = {attack,postaction = {decorate,decoration={markings,mark=at position 0.36 with {\draw[-] (0,-0.1) -- (0.1,0.1);}}}}}},
    /argumentation/supportstyle/dashed/.code={\tikzset{support/.style = {attack,densely dashed}}},
    /argumentation/supportstyle/double/.code={\tikzstyle{support}=[-{Classical TikZ Rightarrow},double]},
    /argumentation/supportstyle=standard,
}

\pgfkeys{/argumentation/namestyle/.is choice,
    /argumentation/namestyle/normal/.code={\relax},
    /argumentation/namestyle/italics/.code={\renewcommand{\argstyle}[1]{\emph{#1}}},
    /argumentation/namestyle/bold/.code={\renewcommand{\argstyle}[1]{\textbf{#1}}},
    /argumentation/namestyle/bolditalics/.code={\renewcommand{\argstyle}[1]{\emph{\textbf{#1}}}},
    /argumentation/namestyle/monospace/.code={\renewcommand{\argstyle}[1]{\texttt{#1}}},
    /argumentation/namestyle=normal,
}

\ProcessPgfPackageOptions{/argumentation}
%%%%%%%%%% Package Content %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\tikzset{ % global predefined tikz-styles
    argument size/.style={minimum size=0.7cm},                              % Standard size of argument nodes
    selfattack/.style={loop,min distance=2mm,in=0,out=60,looseness=5},      % Standard style for self-attacks
    inactive/.style={draw=black!30, text=black!40},                         % Make a node or edge inactive, i.e., greyed out
    incomplete/.style={densely dashed},                                     % Style for displaying incomplete nodes or attacks
    argin/.style={fill=green},                                              % Color an argument that is labelled in
    argout/.style={fill=red},                                               % Color an argument that is labelled out
    argundec/.style={fill=cyan},                                            % Color an argument that is labelled undecided
    caption/.style={draw=none},                                             % Style for displaying AF name in Figure
    invisible/.style={draw=none,text=black!0},                              % Make a node or edge invisible
    annotation/.style={above,font=\small},
}

% Commands for setting custom tikz-style parameters (experimental)
\newcommand{\setargumentstyle}[1]{\tikzset{argument/.style={#1}}}
\newcommand{\setattackstyle}[1]{\tikzset{attack/.style={#1}}}
\newcommand{\setsupportstyle}[1]{\tikzset{support/.style={#1}}}

%\newcommand{\setloopstyle}[1]{\tikzset{selfattack/.style={#1}}}
%\newcommand{\adjustargumentstyle}[1]{\tikzset{argument/.append style={#1}}}
%\newcommand{\adjustattackstyle}[1]{\tikzset{attack/.append style={#1}}}


%%%%%%%%%%%%%%% Environment %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{
    /tikz/small/.style = {node distance=0.55cm,argument size/.style={minimum size=0.55cm},caption/.append style={font=\small}},
    /tikz/tiny/.style = {node distance=0.35cm,argument size/.style={font=\small, minimum size=0.4cm},caption/.append style={font=\small}},
}

\newenvironment{af}[1][]{
    \tikzpicture[#1]
}{%
    \endtikzpicture
}

%%%%%%%%%%%%%%%% Commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Creates a node displaying the name of the AF
\newcommand{\afname}[3][]{\node[caption,#1](#2){#3};}

\newcommand{\annotation}[3][]{\node[annotation,above of=#2,#1](an_#2){#3};}

% Creates an argument node
\newcommand{\argument}[3][]{\node[argument,argument size,#1](#2){\argstyle{#3}};}

% Creates an attack edge
\newcommand{\attack}[3][]{\path(#2) edge [attack,#1] (#3);}

% Creates a self-attack
\newcommand{\selfattack}[2][]{\path(#2) edge [attack,selfattack,#1] (#2);}

% Creates two symmetric attack edges between two arguments
\newcommand{\dualattack}[3][]{\path(#2) edge [attack, bend right,#1] (#3);\path(#3) edge [attack, bend right,#1] (#2);}

% Creates a weighted attack
\newcommand{\annotatedattack}[4][]{\path(#2) edge [attack,#1] node[annotation](p_#2_#3){#4} (#3);}

% Creates a support edge between two arguments
\newcommand{\support}[3][]{\path(#2) edge [support=0.35,#1] (#3);}
