%%
%% chemidentifier.sty
%%
%% Numerotation logique et hyperliens pour les composes chimiques.
%% Logical numbering and hyperlinking of chemical compounds.
%%
%% Copyright (C) 2026 Aliocha SKRZYPCZAK <aliochask.pro@gmail.com>
%%
%% This work may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License, either version 1.3c of this license
%% or (at your option) any later version.
%%
%% This work has the LPPL maintenance status `maintained'.
%% The Current Maintainer of this work is Aliocha SKRZYPCZAK.
%%
%% ------------------------------------------------------------------
%% This file is only the loader: it picks which implementation of the
%% package to read, and reads it.
%%
%%   \usepackage{chemidentifier}              -> chemidentifier-v2.sty
%%   \usepackage[version=2]{chemidentifier}   -> chemidentifier-v2.sty
%%   \usepackage[version=1]{chemidentifier}   -> chemidentifier-v1.sty
%%
%% Version 1 is frozen: a document written against it keeps compiling
%% to the same output for good, whatever version 2 grows into.  Version
%% 2 changes three behaviours on purpose (see its own header), so the
%% escape hatch is a single option rather than a rewrite.
%%
%% 'version' is the *only* option handled here.  Everything else is
%% left strictly alone and processed by the implementation file itself,
%% with \ProcessKeyOptions, so that class-wide options keep reaching
%% the package the way they always did.
%% ------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\RequirePackage{expl3}
\ProvidesExplPackage {chemidentifier} {2026-08-19} {2.0.0}
  {Logical numbering and hyperlinking of chemical compounds}

\tl_new:N \l__chemid_load_version_tl
\tl_new:N \l__chemid_load_options_tl
\tl_set:Nn \l__chemid_load_version_tl { 2 }

\msg_new:nnnn { chemidentifier } { unknown-version }
  { Unknown~package~version~'#1'. }
  {
    'version'~selects~the~implementation~to~load:~1~for~the~frozen~
    first~version,~2~(the~default)~for~the~current~one.~Version~2~is~
    loaded~instead.
  }

\keys_define:nn { chemidentifier / load }
  {
    version .tl_set:N = \l__chemid_load_version_tl ,
    % Every other option belongs to the implementation, which will read
    % the very same list again through \ProcessKeyOptions: seen and
    % skipped here, never reported, never consumed.
    unknown .code:n   = { } ,
  }

% The package option list, taken verbatim from LaTeX's own record of it
% ('v' expansion, so that a value such as 'format=\textbf' reaches
% \keys_set unexpanded).
\cs_if_exist:cT { opt@chemidentifier.sty }
  { \tl_set:Nv \l__chemid_load_options_tl { opt@chemidentifier.sty } }
\keys_set:nV { chemidentifier / load } \l__chemid_load_options_tl

\str_case:VnF \l__chemid_load_version_tl
  {
    { 1 } { \file_input:n { chemidentifier-v1.sty } }
    { 2 } { \file_input:n { chemidentifier-v2.sty } }
  }
  {
    \msg_error:nnV { chemidentifier } { unknown-version }
      \l__chemid_load_version_tl
    \file_input:n { chemidentifier-v2.sty }
  }
