%% This is file `tudacolors.sty' version 3.34 (2023/07/12),
%% it is part of
%% TUDa-CI -- Corporate Design for TU Darmstadt
%% ----------------------------------------------------------------------------
%%
%%  Copyright (C) 2018--2023 by Marei Peischl <marei@peitex.de>
%%
%% ============================================================================
%% 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.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainers of this work are
%%   Marei Peischl <tuda-ci@peitex.de>
%%   Markus Lazanowski <latex@ce.tu-darmstadt.de>
%%
%% The development respository can be found at
%% https://github.com/tudace/tuda_latex_templates
%% Please use the issue tracker for feedback!
%%
%% ============================================================================
%%
\def\fileversion{3.34}
\def\filedate{2023/07/12}
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}
\ProvidesExplPackage{tudacolors}{\filedate}{\fileversion}{Color definition for TU Darmstadt's tuda-ci bundle}

\RequirePackage{l3keys2e}

\str_if_exist:NF \g_ptxcd_department_str {
	\str_new:N \g_ptxcd_department_str
	\str_gset:Nn \g_ptxcd_department_str {default}
}

\keys_define:nn {ptxcd/colors} {
	accent .tl_gset:N = \g_ptxcd_color_accent_tl,
	accent .initial:n = 0b,
	textaccent .tl_gset:N = \g_ptxcd_color_textaccent_tl,
	textaccent .initial:n = \g_ptxcd_color_accent_tl,
	identbar .tl_gset:N = \g_ptxcd_color_identbar_tl,
	identbar .initial:n = \g_ptxcd_color_accent_tl,
	accentcolor .meta:n = {accent =#1},
	textaccentcolor .meta:n = {textaccent = #1},
	identbarcolor .meta:n = {identbar = #1},
	color .code:n = \keys_set:nn {ptxcd/colors} {accent=#1, textaccent=#1, identbar=#1}\PassOptionsToPackage{color=}{siunitx},
	text .choice:,
	text/preferblack .code:n = \bool_gset_false:N \g_ptxcd_color_whitetext_bool,
	text/preferwhite .code:n = \bool_gset_true:N  \g_ptxcd_color_whitetext_bool,
	text .initial:n = {preferwhite},
	text/black .meta:n = {text=preferblack},
	text/white .meta:n = {text=preferwhite},
	cmyk .code:n = \PassOptionsToPackage{cmyk}{xcolor},
	RGB .code:n = \PassOptionsToPackage{RGB}{xcolor},
	department .choice:,
	department / default .code:n = \str_gset:Nn \g_ptxcd_department_str {default},
	department / mecheng .code:n = \str_gset:Nn \g_ptxcd_department_str {mecheng}\keys_set:nn {ptxcd/colors}{accent=TUDa-2d,identbar=TUDa-6b},
	department / unknown .code:n = {
		\str_gset:Nx \g_ptxcd_department_str {\l_keys_value_tl}
	},
	departmentconfigprefix .tl_gset:N = \g__ptxcd_config_prefix_tl,
	mecheng .meta:n = {department=mecheng},
}

\ProcessKeysOptions{ptxcd/colors}

\RequirePackage{xcolor}

\input{tudacolors.def}

\str_if_eq:VnT \g_ptxcd_department_str {mecheng} {
	\colorlet{TUDa-Primary1}{TUDa-6b}
	\colorlet{TUDa-Primary2}{TUDa-2d}
	\colorlet{TUDa-Secondary1}{TUDa-9a}
	\colorlet{TUDa-Secondary2}{TUDa-8a}
	\colorlet{TUDa-Secondary3}{TUDa-6a}
	\colorlet{TUDa-Secondary4}{TUDa-3a}
	\colorlet{TUDa-Secondary5}{TUDa-4a}
	\colorlet{TUDa-Secondary6}{TUDa-5a}
	\colorlet{TUDa-Arrow}{TUDa-Primary2}
}

\clist_map_inline:nn {accent, textaccent, identbar} {
	\cs_if_exist:cF {\string\color@\tl_use:c {g_ptxcd_color_#1_tl}} {
		\cs_if_exist:cT {\string\color@TUDa-\tl_use:c {g_ptxcd_color_#1_tl}} {
			\tl_gset:cx {g_ptxcd_color_#1_tl} {TUDa-\tl_use:c {g_ptxcd_color_#1_tl}}
	}}
}

\clist_const:Nn \c_ptxcd_color_forbid_textaccent_clist {TUDa-0a,TUDa-5a,TUDa-6a,TUDa-6b,TUDa-7a}
\clist_const:Nn \c_ptxcd_color_allow_blacktext_clist {TUDa-0a,TUDa-0b,TUDa-0c,TUDa-1a,TUDa-2a,TUDa-3a,TUDa-4a,TUDa-4b,TUDa-4c,TUDa-5a,TUDa-5b,TUDa-5c,TUDa-6a,TUDa-6b,TUDa-6c,TUDa-7a,TUDa-7b,TUDa-7c,TUDa-8a,TUDa-8b,TUDa-8c,TUDa-9a,TUDa-9b,TUDa-10a}
\clist_const:Nn \c_ptxcd_color_allow_whitetext_clist {TUDa-0b,TUDa-0c,TUDa-0d,black,TUDa-1a,TUDa-1b,TUDa-1c,TUDa-1d,TUDa-2a,TUDa-2b,TUDa-2c,TUDa-2d,TUDa-3a,TUDa-3b,TUDa-3c,TUDa-3d,TUDa-4b,TUDa-4c,TUDa-4d,TUDa-5b,TUDa-5c,TUDa-5d,TUDa-6c,TUDa-6d,TUDa-7b,TUDa-7c,TUDa-7d,TUDa-8a,TUDa-8b,TUDa-8c,TUDa-8d,TUDa-9a,TUDa-9b,TUDa-9c,TUDa-9d,TUDa-10a,TUDa-10b,TUDa-10c,TUDa-10d,TUDa-11a,TUDa-11b,TUDa-11c,TUDa-11d}


%messages
\msg_new:nnnn{tudacolors} {undefined-color} {The~ color~ #1~ you~ selected~ is~ not~ defined.} {See~ the~ tuda-ci~ manual~ for~ a~ list~ of~ available~ colors.}
\msg_new:nnnn{tudacolors} {unselectable-color} {The~ color~ you~ selected~ (#1)~ must~ not~ be~ choosen~ for~ #2.} {See~ the~ Corporate~ Design~ Guidelines~ for~ further~ information.}

\hook_new:n {ptxcd/init-colors}
\hook_gput_code:nnn {ptxcd/init-colors} {tudacolors} {
	\exp_args:Nnx \colorlet{accentcolor}{\g_ptxcd_color_accent_tl}
	\bool_if:NTF \g_ptxcd_color_whitetext_bool {
		\clist_if_in:NVTF \c_ptxcd_color_allow_whitetext_clist \g_ptxcd_color_accent_tl {
			\colorlet{textonaccentcolor}{white}
		} {
			\colorlet{textonaccentcolor}{black}
			\tl_if_in:NnT \g_ptxcd_color_accent_tl {TUDa} {\msg_warning:nnxx{tudacolors} {unselectable-color} {white} {textonaccentcolor}}
		}
	} {
		\clist_if_in:NVTF \c_ptxcd_color_allow_blacktext_clist \g_ptxcd_color_accent_tl {
			\colorlet{textonaccentcolor}{black}
		} {
			\colorlet{textonaccentcolor}{white}
			\tl_if_in:NnT \g_ptxcd_color_accent_tl {TUDa} {msg_warning:nnxx{tudacolors} {unselectable-color} {black} {textonaccentcolor}}
		}
	}
	\colorlet{identbarcolor}{\g_ptxcd_color_identbar_tl}
	\exp_args:NNx \clist_if_in:NnTF \c_ptxcd_color_forbid_textaccent_clist {\g_ptxcd_color_textaccent_tl} {
		\msg_warning:nnxx{tudacolors} {unselectable-color} {\g_ptxcd_color_textaccent_tl} {textaccentcolor}
		\colorlet{textaccentcolor}{black}
	} {
		\colorlet{textaccentcolor}{\g_ptxcd_color_textaccent_tl}
	}
}

\file_if_exist_input:n {\g__ptxcd_config_prefix_tl\g_ptxcd_department_str-colors.def}

\hook_use:n {ptxcd/init-colors}

\colorlet{InfoBox}{white}

\endinput