% bacco.sty - Custom style file for Professor Lisa C. Bacco's SOC class
% APA 7th Edition formatting

% Version variable
\def\baccoversion{v1.0}

\RequirePackage{snhu}
\ProvidesPackage{bacco}[\baccoversion Custom package for Professor Lisa C. Bacco, M.A., CMS]

% Required packages for APA formatting
\RequirePackage{times}  % Times New Roman font
\RequirePackage{setspace}  % For double spacing
\RequirePackage[margin=1in]{geometry}  % 1-inch margins
\RequirePackage{indentfirst}  % Indent first paragraph

% Fix headheight warning for fancyhdr
\setlength{\headheight}{14.5pt}

% Set double spacing
\doublespacing

% Set font size to 12pt (already set in documentclass)
% Times New Roman is set via \usepackage{times}

% APA formatting: indent paragraphs by 0.5 inches
\setlength{\parindent}{0.5in}

% Remove extra spacing between paragraphs
\setlength{\parskip}{0pt}

% APA title page formatting
\renewcommand{\maketitle}{%
    % Title page - no running head, just page number
    \thispagestyle{plain}
    \begin{titlepage}
        % Page number handled by \thispagestyle{plain} above
        \vspace{1in}
        
        % Title (centered, bold, title case)
        \begin{center}
            \textbf{\@reporttitle}
        \end{center}
        
        \vspace{1in}
        
        % Author information (centered)
        \begin{center}
            \@studentname\par
            Southern New Hampshire University\par
            \@class\par
            \@instructor\par
            \@submissiondate
        \end{center}
        
        \vfill
    \end{titlepage}
    
    % Start new page for content with running head
    \newpage
    \setcounter{page}{2}
    % Set APA page style for content pages (running head LEFT, page number RIGHT)
    \thispagestyle{apa}
    \pagestyle{apa}
}

% Custom commands for APA document
% Default values first
\def\@runninghead{Running Head}
\def\@instructor{}

% Then allow overriding
\newcommand{\runninghead}[1]{\def\@runninghead{#1}}
\newcommand{\instructor}[1]{\def\@instructor{#1}}

% APA-style page headers (for pages after title page)
% Running head on LEFT, page number on RIGHT (APA format)
\fancypagestyle{apa}{
    \fancyhf{}  % Clear all headers and footers
    \fancyhead[L]{\uppercase{\@runninghead}}  % LEFT: Running head
    \fancyhead[R]{\thepage}  % RIGHT: Page number
    \fancyfoot{}  % Clear footer
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}

% Plain style for title page (just page number on right)
\fancypagestyle{plain}{
    \fancyhf{}  % Clear all headers and footers
    \fancyhead{}  % Clear header
    \fancyhead[R]{\thepage}  % RIGHT: Page number only
    \fancyfoot{}  % Clear footer
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}

% Use APA page style (override SNHU default)
% Execute after SNHU's AtBeginDocument to ensure our style takes precedence
\AtBeginDocument{
    \pagestyle{apa}
}

% References section formatting
\newenvironment{references}{%
    \newpage
    \section*{References}
    \addcontentsline{toc}{section}{References}
    \noindent
}{}
