\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{PrimeTeX/packages/DocProperties}[2025-07-09]

\RequirePackage[en-US]{datetime2}

\DTMnewdatestyle{longdate}{%
	\renewcommand{\DTMdisplaydate}[4]{\number##3\ \DTMenglishmonthname{##2}\ \number##1}%
	\renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}

\NewDocumentCommand{\FormatDate}{m m}{%
	\DTMsavedate{saveDate}{#1}%
	\DTMsetdatestyle{#2}%
	\DTMusedate{saveDate}
}

\RequirePackage{readarray}
\readarraysepchar{,}

\NewDocumentCommand{\GetRevision}{m}{%
	\readdef{#1}\@RevHistory%
	\readarray*\@RevHistory\@RevHistoryArray[-,\ncols]%
	\Version[\@RevHistoryArray[2,1]]%
	\edef\eDate{\@RevHistoryArray[2,2]}%
	\DTMsavedate{tempDate}{\eDate}%
	\DTMsetdatestyle{default}%
	\Date[\DTMusedate{tempDate}]%
	\DTMsetdatestyle{longdate}%
	\LongDate[\DTMusedate{tempDate}]%
	\Author[\@RevHistoryArray[2,3]]%
}

\NewDocumentCommand{\SetPDFInfo}{}{
	\hypersetup{
		pdfauthor	= {\@AuthorCompany},
		pdfsubject	= {\ProjectTitle},
		pdftitle	= {\@Title},
		pdfkeywords	= {
			Customer:~\@CustomerFull~(\@Customer),
			Last~Modified~By:~\@Author,
			Modification~Date:~\@Date,
			Revision~Number:~\@Version,
			\@AuthorCompany{}~Project~Number:~\@InternalProjectNumber,
		},
	}
}

\NewExpandableDocumentCommand{\ProjectTitle}{}{%
	Project \@CustomerProjectNumber{}: \@ProjectDescription%
}

% Custom document properties.
\edef\@Author{}
\NewDocumentCommand{\Author}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@Author%
	}{%
		\xdef\@Author{#1}%
	}%
}

\edef\@AuthorCompany{}
\NewDocumentCommand{\AuthorCompany}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@AuthorCompany%
	}{%
		\xdef\@AuthorCompany{#1}%
	}%
}

\edef\@Customer{}
\NewDocumentCommand{\Customer}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@Customer%
	}{%
		\xdef\@Customer{#1}%
	}%
}

\edef\@CustomerFull{}
\NewDocumentCommand{\CustomerFull}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@CustomerFull%
	}{%
		\xdef\@CustomerFull{#1}%
	}%
}

\edef\@CustomerProjectNumber{}
\NewDocumentCommand{\CustomerProjectNumber}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@CustomerProjectNumber%
	}{%
		\xdef\@CustomerProjectNumber{#1}%
	}%
}

\edef\@Date{}
\NewDocumentCommand{\Date}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@Date%
	}{%
		\xdef\@Date{#1}%
	}%
}

\edef\@LongDate{}
\NewDocumentCommand{\LongDate}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@LongDate%
	}{%
		\xdef\@LongDate{#1}%
	}%
}

\edef\@InternalProjectNumber{}
\NewDocumentCommand{\InternalProjectNumber}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@InternalProjectNumber%
	}{%
		\xdef\@InternalProjectNumber{#1}%
	}%
}

\edef\@ProjectDescription{}
\NewDocumentCommand{\ProjectDescription}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@ProjectDescription%
	}{%
		\xdef\@ProjectDescription{#1}%
	}%
}

\edef\@Title{}
\NewDocumentCommand{\Title}{>{\TrimSpaces}o}{%
	\IfNoValueTF{#1}{%
		\@Title%
	}{%
		\xdef\@Title{#1}%
	}%
}

\edef\@Version{}
\NewDocumentCommand{\Version}{>{\TrimSpaces}o O{Revision: }}{%
	\IfNoValueTF{#1}{%
		\@Version%
	}{%
		\xdef\@Version{#1}%
	}%
}