\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jouheadings}[2026/03/08 Shared heading system for JOU thesis]

\newlength{\jouHeadingChapterNumberWidth}
\setlength{\jouHeadingChapterNumberWidth}{1.5em}
\newlength{\jouHeadingSectionNumberWidth}
\setlength{\jouHeadingSectionNumberWidth}{2.75em}
\newlength{\jouHeadingSubsectionNumberWidth}
\setlength{\jouHeadingSubsectionNumberWidth}{4.15em}

\newcommand{\JOUHeadingHeaderYearToken}{二{\songti 〇}二六}
\newcommand{\JOUHeadingBodyHeaderLeftInline}{江苏海洋大学\JOUHeadingHeaderYearToken{}届本科毕业设计（论文）}
\newcommand{\JOUHeadingBodyHeaderRightPlaceholder}{第\hspace{1.6em}页\hspace{1.2em}共\hspace{1.6em}页}

\newcommand{\JOUHeadingChapterLabel}[1]{%
    \makebox[\jouHeadingChapterNumberWidth][l]{#1}%
}
\newcommand{\JOUHeadingSectionLabel}[1]{%
    \makebox[\jouHeadingSectionNumberWidth][l]{#1}%
}
\newcommand{\JOUHeadingSubsectionLabel}[1]{%
    \makebox[\jouHeadingSubsectionNumberWidth][l]{#1}%
}

\newcommand{\JOUChapterHeadingLine}[2]{%
    {\heiti\zihao{-3}\noindent\JOUHeadingChapterLabel{#1}#2\par}%
}
\newcommand{\JOUSectionHeadingLine}[2]{%
    {\heiti\zihao{-4}\noindent\JOUHeadingSectionLabel{#1}#2\par}%
}
\newcommand{\JOUSubsectionHeadingLine}[2]{%
    {\heiti\zihao{-4}\noindent\JOUHeadingSubsectionLabel{#1}#2\par}%
}

\newcommand{\JOUApplyBodySectioning}{%
    \renewcommand{\thechapter}{\arabic{chapter}}%
    \renewcommand{\thesection}{\thechapter.\arabic{section}}%
    \renewcommand{\thesubsection}{\thesection.\arabic{subsection}}%
    \ctexset{%
        chapter={%
            format={\heiti\zihao{-3}\raggedright},%
            name={,},%
            number={\arabic{chapter}},%
            aftername=\hspace{1em},%
            beforeskip=0.5\baselineskip,%
            afterskip=0.5\baselineskip%
        },%
        section={%
            format={\heiti\zihao{-4}},%
            beforeskip=0.5\baselineskip,%
            afterskip=0.5\baselineskip,%
            indent=0pt%
        },%
        subsection={%
            format={\heiti\zihao{-4}},%
            beforeskip=0pt,%
            afterskip=0pt,%
            indent=0pt%
        }%
    }%
}

\newcommand{\JOUApplyBodyTextLayout}{%
    \ctexset{%
        punct=quanjiao,%
        space=auto,%
        autoindent=true%
    }%
    \setlength{\parindent}{2em}%
}

\newcommand{\JOUApplyBodyReferenceNames}{%
    \crefname{figure}{图}{图}%
    \Crefname{figure}{图}{图}%
    \crefname{table}{表}{表}%
    \Crefname{table}{表}{表}%
    \crefname{equation}{式}{式}%
    \Crefname{equation}{式}{式}%
    \crefname{algorithm}{算法}{算法}%
    \Crefname{algorithm}{算法}{算法}%
    \crefname{theorem}{定理}{定理}%
    \Crefname{theorem}{定理}{定理}%
    \crefname{lemma}{引理}{引理}%
    \Crefname{lemma}{引理}{引理}%
    \crefname{proposition}{命题}{命题}%
    \Crefname{proposition}{命题}{命题}%
    \crefname{corollary}{推论}{推论}%
    \Crefname{corollary}{推论}{推论}%
    \crefname{definition}{定义}{定义}%
    \Crefname{definition}{定义}{定义}%
    \crefname{example}{例}{例}%
    \Crefname{example}{例}{例}%
    \crefname{remark}{注}{注}%
    \Crefname{remark}{注}{注}%
    \crefname{chapter}{第}{第}%
    \Crefname{chapter}{第}{第}%
    \crefname{section}{节}{节}%
    \Crefname{section}{节}{节}%
    \crefname{subsection}{小节}{小节}%
    \Crefname{subsection}{小节}{小节}%
    \crefname{lstlisting}{代码}{代码}%
    \Crefname{lstlisting}{代码}{代码}%
    \crefname{listing}{代码}{代码}%
    \Crefname{listing}{代码}{代码}%
    \crefformat{chapter}{第##2##1##3章}%
    \Crefformat{chapter}{第##2##1##3章}%
    \crefformat{section}{##2##1##3节}%
    \Crefformat{section}{##2##1##3节}%
    \crefformat{subsection}{##2##1##3小节}%
    \Crefformat{subsection}{##2##1##3小节}%
}

\newcommand{\JOUApplyBodyTocLayout}{%
    \renewcommand{\contentsname}{目\hspace{2em}录}%
    \setcounter{tocdepth}{1}%
    \titlecontents{chapter}[0pt]{\songti\zihao{-4}}%
        {\thecontentslabel\hspace{1em}}{}%
        {\titlerule*[0.5pc]{.}\contentspage}%
    \titlecontents{section}[2em]{\songti\zihao{-4}}%
        {\thecontentslabel\hspace{1em}}{}%
        {\titlerule*[0.5pc]{.}\contentspage}%
}
