\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{uebung}[Sem4 Componentware Exercise Sheet Class]

% Base class with options
\LoadClass[11pt,a4paper]{article}

% Required packages
\RequirePackage[german]{babel}
\RequirePackage{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{titlesec}
\RequirePackage{enumitem}
\RequirePackage{listings}
\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage{amsmath}
\RequirePackage{hyperref}
\RequirePackage{minted}

% Minted config
\usemintedstyle{default}

% Define chapter counter for exercise sheets
\newcounter{chapter}
\renewcommand{\thechapter}{\arabic{chapter}}

% Page geometry
\geometry{a4paper, left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm}

% Colors for code listings
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

% Code listing style
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2,
    frame=single,
    framesep=5pt
}

\lstset{style=mystyle}

% Header and footer setup
\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{\textbf{Übung Componentware}}
\fancyhead[R]{\textbf{Aufgabenblatt zu Kapitel \thechapter}}
\fancyfoot[C]{\thepage}

% Title format
\renewcommand{\maketitle}{
    \begin{center}
        \LARGE\textbf{Übung Componentware}\\
        \Large\textbf{Aufgabenblatt zu Kapitel \thechapter}
        \vspace{1cm}

        \large\textbf{Aufgaben – \@author}
    \end{center}
    \vspace{0.5cm}
}

% Section formatting
\titleformat{\section}
    {\large\bfseries}
    {}
    {0em}
    {}
    [\titlerule]

% Exercise item formatting
\newlist{exercises}{enumerate}{1}
\setlist[exercises]{
    label=\arabic*),
    leftmargin=*,
    itemsep=1em,
    before=\vspace{1.0cm}
}

% Java code environment
\lstnewenvironment{javaCode}[1][]
    {\lstset{style=mystyle, language=Java, #1}}
    {}

% JSP/HTML code environment
\lstnewenvironment{htmlCode}[1][]
    {\lstset{style=mystyle, language=HTML, #1}}
    {}

% XML code environment
\lstnewenvironment{xmlCode}[1][]
    {\lstset{style=mystyle, language=XML, #1}}
    {}

% Subsection for code examples
\newcommand{\codeexample}[1]{
    \vspace{0.5em}
    \noindent\textbf{Beispiel:}
    \vspace{0.3em}
    #1
}

% Environment for multi-page content
\newenvironment{multipagecontent}
    {\par\vspace{1em}}
    {\par\vspace{1em}}

% Command for page breaks with continuation marker
\newcommand{\continuepage}{
    \vfill
    \centerline{\textit{Fortsetzung auf nächster Seite...}}
    \newpage
    \centerline{\textit{Fortsetzung von vorheriger Seite...}}
    \vspace{1em}
}

% Hyperref setup
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
    pdftitle={Componentware Übungen},
    pdfauthor={Linus Nagel}
}

% Chapter command for exercise sheets
\newcommand{\chapter}[1]{\setcounter{chapter}{#1}}

\endinput
