\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{craftofficial}[CraftLaw for the CraftFuze Legal Project, Council Proposal]

\LoadClass[a4paper,8pt,oneside]{article}
\RequirePackage[left=2cm, right=2cm, top=2cm]{geometry}
\RequirePackage[utf8]{inputenc}
\RequirePackage[english]{babel}
\RequirePackage{blindtext}
\RequirePackage{titling}
\RequirePackage{fancyhdr}
\RequirePackage{tikz}
\RequirePackage[shortlabels]{enumitem}
\RequirePackage{needspace}
\RequirePackage[document]{ragged2e}
\RequirePackage{scrextend}

% Indent
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt}
\setlist[enumerate,1]{leftmargin=1.5em,topsep=-1ex,itemsep=-1ex,partopsep=1ex,parsep=1ex,style=sameline}
\setlist[enumerate,2]{leftmargin=1.5em,topsep=-1ex,itemsep=-1ex,partopsep=1ex,parsep=1ex,style=sameline}
\setenumerate[0]{label=\textbf{\arabic*.}}

% Header and footer
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[LE,RO]{\thepage}

% New title layout
\newcommand{\settitle}[1]{\def\@lawtitle{#1}}
\newcommand{\setdate}[1]{\def\@date{#1}}

\newcommand{\generateHeader}{
	% Header
	\fancyhead[LE,LO]{\@date}
	\fancyhead[CE,CO]{Official Journal of the Crafty Table}
	\fancyhead[RE,RO]{\@lawtitle}
	
	% Title
	\noindent%
	\begin{figure}
		\centering
		\includegraphics[width=30mm]{smooth}
	\end{figure}
	\centering%
	\textbf{\large\fontfamily{phv}\fontseries{b}%
        \selectfont \@lawtitle}%
    \medskip%
}


% Introduction
\newcommand{\introduction}[1]{%
	\bigskip%
	\vbox{%
		PREAMBLE\medskip%
		\begin{flushleft}
			\noindent{#1}%
		\end{flushleft}
	}%
}

% About proposal content
\newcounter{TopArticle}
\newcommand{\toparticle}[2]{%
	% Count 1 up
	\stepcounter{TopArticle}%
	
	% Demand space and take space
	\needspace{5\baselineskip}%
	
	% Center the title and print it
	\begin{flushleft}
	\textbf{ARTICLE \Roman{TopArticle} \uppercase{#1}}\newline%
	
	\medskip%
	\par{#2}
	\end{flushleft}
}

\newcommand{\signature}[1]{
	\bigskip%
	\begin{flushleft}
		Hereby ordering and burdening the Judiciary to publish this Act in the Official Journal of the Crafty Table; and that all shall be bound to its provisions and shall act faithfully in accordance with it.
		
		\medskip%
		
		Ordered as such here on this day, the \@date.
		
		\bigskip%
		
		\textit{Signed,}\medskip%
		\par{#1}
	\end{flushleft}
}

% About legal content
\newcounter{TitleCounter}
\newcounter{TitleSubCounter}[TitleCounter]
\newcounter{ChapterCounter}[TitleCounter]
\newcounter{ChapterSubCounter}[ChapterCounter]
\newcounter{SectionCounter}[ChapterCounter]
\newcounter{SectionSubCounter}[SectionCounter]
\newcounter{ParagraphCounter}[SectionCounter]
\newcounter{SubParagraphCounter}[ParagraphCounter]
\newcounter{ArticleCounter}[TitleSubCounter]
\newcounter{ArticleSubCounter}[ArticleCounter]
\renewcommand{\title}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{TitleCounter}%
		\needspace{25\baselineskip}%
		
		\begin{flushleft}
			\textbf{Title \Roman{TitleCounter}}%
			: \textbf{#1}
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\newcommand{\subtitle}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{TitleSubCounter}%
		\needspace{25\baselineskip}%
		
		\begin{flushleft}
			\textbf{Title \Roman{TitleCounter} \Alph{TitleSubCounter}}%
			: \textbf{#1}
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\newcommand{\chapter}[1]{
	\begin{addmargin}[1em]{2em}
		\stepcounter{ChapterCounter}%
		\needspace{20\baselineskip}%
		
		\begin{flushleft}
			\textbf{Chapter \Roman{ChapterCounter}}%
			: \textbf{#1}%
		\end{flushleft}	
	\end{addmargin}
	\bigskip%
}
\newcommand{\subchapter}[1]{
	\begin{addmargin}[1em]{2em}
		\stepcounter{ChapterSubCounter}%
		\needspace{20\baselineskip}%
		
		\begin{flushleft}
			\textbf{Chapter \Roman{ChapterCounter} \Alph{ChapterSubCounter}}%
			: \textbf{#1}%
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\renewcommand{\section}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{SectionCounter}%
		\needspace{15\baselineskip}%
		
		\begin{flushleft}
			\textbf{Section \Roman{SectionCounter}}%
			: \textbf{#1}%
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\renewcommand{\subsection}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{SectionSubCounter}%
		\needspace{15\baselineskip}%
		
		\begin{flushleft}
			\textbf{Section \Roman{SectionCounter} \Alph{SectionSubCounter}}%
			: \textbf{#1}%
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\renewcommand{\paragraph}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{ParagraphCounter}%
		\needspace{10\baselineskip}%
		
		\begin{flushleft}
			\textbf{Paragraph §\arabic{ParagraphCounter}.\arabic{SubParagraphCounter}}%
			: \textbf{#1}%
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\renewcommand{\subparagraph}[1]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{SubParagraphCounter}%
		\needspace{10\baselineskip}%
		
		\begin{flushleft}
			\textbf{Paragraph §\arabic{ParagraphCounter}.\arabic{SubParagraphCounter}}%
			: \textbf{#1}%
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\newcommand{\article}[2]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{ArticleCounter}%
		\needspace{5\baselineskip}%
		
		\begin{flushleft}
			\textbf{Article \arabic{ArticleCounter}}%
			\def\param{#1}%
			\ifx\param\empty
				%
			\else
				: \textbf{#1}%
			\fi
			
			\par{#2}
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}
\newcommand{\subarticle}[2]{%
	\begin{addmargin}[1em]{2em}
		\stepcounter{ArticleSubCounter}%
		\needspace{5\baselineskip}%
		
		\begin{flushleft}
			\textbf{Article \arabic{ArticleCounter}\alph{ArticleSubCounter}}%
			\def\param{#1}%
			\ifx\param\empty
				%
			\else
			: \textbf{#1}%
			\fi
			
			\par{#2}
		\end{flushleft}
	\end{addmargin}
	\bigskip%
}