\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{PrimeTeX/packages/Boxout}[2025-08-20]

\RequirePackage{PrimeTeX/packages/Layout}
\RequirePackage{PrimeTeX/packages/Color}
\RequirePackage{PrimeTeX/packages/Tables}
\RequirePackage{calc}

\providelength{\boxoutpadding}[1em]
\providelength{\boxoutrule}[1pt]

\colorlet{boxoutbgcolor}{PrimePaleBlue}
\colorlet{boxoutfgcolor}{PrimeBlue}

\NewTblrEnviron{tblrBoxout}
\SetTblrInner[tblrBoxout]{
	%colspec		= {X[1,l,h]},
	cells		= {boxoutbgcolor},
	hlines		= {0pt},
	hline{1,Z}	= {\boxoutrule,boxoutfgcolor},
	row{1}		= {font={\bfseries\sbfamily}},
	vborder{1}	= {rightspace=\boxoutpadding},
	vborder{Z}	= {leftspace=\boxoutpadding},
	vlines		= {0pt},
	vline{1,Z}	= {\boxoutrule,boxoutfgcolor},
}

\NewDocumentEnvironment{Boxout}{
	O{colspec={X[l,h]}}
	>{\TrimSpaces}m
	+m
	+b
}{%
	\label{box:#2}%
	\captionlistentry[figure]{#3}%
	\begin{tblrBoxout}{#1}%
		{\Centering{}#3}\\%
		#4\\%
	\end{tblrBoxout}%
}{}

\NewDocumentEnvironment{BigBoxout}{
	O{\bigfloatoverhang}
	O{htpb}
	O{\bigfloatoffsetratio}
	O{X[l,h]}
	>{\TrimSpaces}m
	+m
	+b
}{
	\begin{figure}[#2]%
		\begin{adjustwidth}{-#1 * \real{#3}}{-#1 / \real{#3}}%
			\begin{Boxout}[#4]{#5}{#6}%
				#7%
			\end{Boxout}%
		\end{adjustwidth}%
	\end{figure}%
}{}

\NewDocumentEnvironment{WrapBoxout}{
	% position [l,r,i,o]
	O{O}
	% offset
	O{\marparwidth}
	% width
	O{3in}
	O{X[l,h]}
	>{\TrimSpaces}m
	+m
	+b
}{%
	\begin{wrapfigure}{#1}[#2]%
		\begin{minipage}{#3}%
			\begin{Boxout}[#4]{#5}{#6}%
				#7%
			\end{Boxout}%
		\end{minipage}%
	\end{wrapfigure}%
}{}