% datemultical: Named dates with multi-calendar formatting for LaTeX.
%
% Copyright (C) 2026 Amer Amikhteh
%
% This package is free software: you may redistribute it and/or modify
% it under the terms of the LaTeX Project Public License as published
% by the LaTeX Project, either version 1.3c of the License, or
% (at your option) any later version.
%
% This package is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty
% of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%
% The full license text is available at:
% https://www.latex-project.org/lppl/
%
% This work is "maintained" by Amer Amikhteh.
%
% The current maintainer of this work is Amer Amikhteh.
%
% This package consists of the file datemultical.sty and the files
% distributed with it.

\NeedsTeXFormat{LaTeX2e}

\makeatletter

\def\dmc@year{2026}
\def\dmc@month{09}
\def\dmc@day{17}
\def\dmc@date{\dmc@year/\dmc@month/\dmc@day}
\def\dmc@version{0.1.0}

\ProvidesPackage{datemultical}
[\dmc@date\space v\dmc@version\space Named dates with multi-calendar formatting]

\RequirePackage{expl3}
\RequirePackage{xparse}

% =================================================
% Package options
% =================================================

\DeclareOption{native}
{
  \PassOptionsToPackage{native}{datemultical-engine}
}

\newif\ifdmc@persian
% \dmc@persianfalse

\DeclareOption{persian}
{
  \dmc@persiantrue
}

\ProcessOptions\relax

% =================================================
% Calendar engine
% =================================================

\RequirePackage{datemultical-engine}

% =================================================
% Public API files
% =================================================

\makeatletter

\ExplSyntaxOn

\input{datemultical-base.def}
\input{datemultical-captions.def}
\input{datemultical-facap.def}
\input{datemultical-format.def}

\ExplSyntaxOff

% -------------------------------------------------
% Persian auto-detection
% -------------------------------------------------

\makeatletter

\def\dmc@detect@language{%
  \@ifundefined{languagename}{%
    % No language information is available.
  }{%
    \edef\dmc@templang{\languagename}%
    \def\dmc@fa{farsi}%
    \def\dmc@per{persian}%

    \ifx\dmc@templang\dmc@fa
      \dmc@persiantrue
    \else
      \ifx\dmc@templang\dmc@per
        \dmc@persiantrue
      \fi\fi
  }%
}

\AtBeginDocument{%
  \ifdmc@persian
  \else
    \@ifpackageloaded{xepersian}{%
      \dmc@persiantrue
    }{%
      \dmc@detect@language
    }%
  \fi
}

\makeatother

\endinput