% Chapter designs, implemented with memoir's heading hooks.
% Copyright 2019, 2026 Adib Hasan. Part of BOOKbangla; LPPL 1.3c or later.

% Register a normal memoir style, so \chapterstyle{...} remains an override.
% Only the heading is decorated: \thechapter and reference values stay plain.
\makechapterstyle{classic}{%
  \renewcommand*\chapnamefont{\normalfont\bfseries\Large}%
  \renewcommand*\printchaptername{}%
  \renewcommand*\chapternamenum{}%
  \renewcommand*\printchapternum{%
    \hfill\begin{tikzpicture}[every node/.style={outer sep=0pt}]
      \node[outer sep=0pt,text width=2.4cm,minimum height=2.5cm,
        fill=bookbanglaaccent,font=\color{white}\bfseries\fontsize{75}{80}\selectfont,
        align=center] (bookbanglanumber) {\thechapter};
      \node[rotate=90,anchor=south,font=\color{black}\chapnamefont]
        at ([xshift=-5pt]bookbanglanumber.west) {\@chapapp};
    \end{tikzpicture}\par}
  \renewcommand*\afterchapternum{\par\nobreak\vskip-30pt}
  \renewcommand*\chaptitlefont{\bfseries\color{bookbanglaaccent}\fontsize{22}{24}\selectfont}
  \renewcommand*\afterchaptertitle{%
    \par\nobreak\vskip8pt
    {\color{bookbanglaaccent}\hrule height2.5pt\vskip3pt\hrule height.4pt}%
    \nobreak\vskip\afterchapskip}}
\chapterstyle{classic}

% Alternative compositions share memoir's numbered/unnumbered heading hooks.
% Keep the numbered/unnumbered distinction local to memoir's heading group.
\newif\ifbookbangla@numberedchapter
\newcommand*\bookbangla@structuredchapter{%
  \renewcommand*\chapnamefont{\normalfont\bfseries\Large}%
  \renewcommand*\printchaptername{}%
  \renewcommand*\chapternamenum{}%
  \renewcommand*\printchapternum{\bookbangla@numberedchaptertrue}%
  \renewcommand*\printchapternonum{\bookbangla@numberedchapterfalse}%
  \renewcommand*\afterchapternum{}%
  \renewcommand*\chapnumfont{\normalfont\bfseries\fontsize{52}{56}\selectfont}
  \renewcommand*\chaptitlefont{\normalfont\bfseries\fontsize{26}{34}\selectfont
    \hyphenpenalty=10000\exhyphenpenalty=10000}}

\makechapterstyle{modern}{%
  \bookbangla@structuredchapter
  \renewcommand*\chapnumfont{\normalfont\bfseries\fontsize{96}{96}\selectfont}%
  \renewcommand*\printchaptertitle[1]{%
    % Measure the right-hand number column, leaving a consistent gap to the
    % title for both single- and multiple-digit chapter numbers.
    \ifbookbangla@numberedchapter
      \setbox\@tempboxa=\vbox{%
        \hbox{\chapnamefont\@chapapp}\hbox{\chapnumfont\thechapter}}%
      \edef\bookbangla@modernnumbercenter{\the\dimexpr\linewidth-\wd\@tempboxa/2\relax}%
      \edef\bookbangla@moderntitlewidth{\the\dimexpr\linewidth-\wd\@tempboxa-20pt\relax}%
    \else
      \edef\bookbangla@moderntitlewidth{\the\linewidth}%
    \fi
    \begin{tikzpicture}[every node/.style={outer sep=0pt}]
      % The title may extend below this minimum height on smaller pages.
      \path (0,0) rectangle (\linewidth,-112pt);
      \ifbookbangla@numberedchapter
        \node[anchor=north,inner sep=0pt,
          text=bookbanglaaccent!45!white,font=\chapnumfont]
          (bookbanglanumber) at (\bookbangla@modernnumbercenter,-28pt) {\thechapter};
        \node[anchor=south,inner sep=0pt,font=\chapnamefont]
          at ([yshift=8pt]bookbanglanumber.north) {\@chapapp};
      \fi
      \node[anchor=north east,inner sep=0pt,
        text width=\bookbangla@moderntitlewidth,align=right,font=\chaptitlefont]
        at (\bookbangla@moderntitlewidth,-38pt) {##1};
    \end{tikzpicture}}}

\makechapterstyle{minimal}{%
  \bookbangla@structuredchapter
  \renewcommand*\printchaptertitle[1]{%
    \begin{tikzpicture}[every node/.style={outer sep=0pt}]
      \node[anchor=north west,inner sep=0pt,
        text width=\dimexpr\linewidth-82pt\relax,
        align=left,font=\chaptitlefont] (bookbanglatitle)
        at (82pt,0) {##1};
      \ifbookbangla@numberedchapter
        \node[anchor=north east,inner sep=0pt,font=\chapnamefont]
          at (54pt,0) {\@chapapp};
        \node[anchor=north east,inner sep=0pt,font=\chapnumfont]
          (bookbanglanumber) at (54pt,-28pt) {\thechapter};
      \else
        \coordinate (bookbanglanumber) at (54pt,-54pt);
      \fi
      % Extend the divider to whichever is taller: the title or the number.
      \coordinate (bookbanglaheadingbottom) at (current bounding box.south);
      \draw[bookbanglaaccent,line width=1.2pt]
        (66pt,2pt)--(66pt,0 |- bookbanglaheadingbottom);
      \path[use as bounding box] (0,0);
    \end{tikzpicture}}}

\makechapterstyle{ruled}{%
  \bookbangla@structuredchapter
  \renewcommand*\printchaptertitle[1]{%
    \begin{tikzpicture}[every node/.style={outer sep=0pt}]
      \ifbookbangla@numberedchapter
        % Stack the label above the number, framed by two fine horizontal rules.
        \node[anchor=north,inner sep=0pt,font=\chapnamefont]
          (bookbanglachaptername) at (.5\linewidth,0) {\scalebox{.9}{\@chapapp}};
        \node[anchor=north,inner xsep=12pt,inner ysep=0pt,
          font=\chapnumfont]
          (bookbanglachapter) at ([yshift=-8pt]bookbanglachaptername.south)
          {\thechapter};
        \draw[bookbanglaaccent,line width=.6pt]
          (.3pt,0 |- bookbanglachapter.center)--(bookbanglachapter.west)
          (bookbanglachapter.east)--(\dimexpr\linewidth-.3pt\relax,0 |- bookbanglachapter.center);
        \coordinate (bookbanglatitletop) at ([yshift=-18pt]bookbanglachapter.south);
      \else
        \coordinate (bookbanglatitletop) at (.5\linewidth,0);
      \fi
      \node[anchor=north,inner sep=0pt,text width=.9\linewidth,
        align=center,font=\chaptitlefont] (bookbanglatitle)
        at (bookbanglatitletop) {##1};
      \draw[bookbanglaaccent,line width=1.2pt]
        ([xshift=-18pt,yshift=-12pt]bookbanglatitle.south)--
        ([xshift=18pt,yshift=-12pt]bookbanglatitle.south);
      \path[use as bounding box] (0,0) (\linewidth,0);
    \end{tikzpicture}}}
\endinput
