%% This is file `bfh-projectproposal.cfg' version 2.2.1 (2024-03-11),
%% it is part of
%% BFH-CI -- Corporate Design for Bern University of Applied Sciences
%% ----------------------------------------------------------------------------
%%
%%  Copyright (C) 2021–2024 by
%%      Marei Peischl <marei@peitex.de>
%%      Andreas Habegger <andreas.habegger@bfh.ch>
%%
%% ============================================================================
%% 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 <bfh-ci@peitex.de>
%%   Andreas Habegger <andreas.habegger@bfh.ch>
%%
%% The development respository can be found at
%% https://gitlab.ti.bfh.ch/bfh-latex/bfh-ci/
%% Please use the issue tracker for feedback!
%%
%% ============================================================================
%%
\ProvidesFile{bfh-projectproposal.cfg}[2024-03-11 v2.2.1 projectproposal configuration for bfhlayout]
\KOMAoptions{headsepline=false}
\clearpairofpagestyles

\savegeometry{BFH-base}

\geometry{top=\g_ptxcd_topLogoMargin_dim,headheight=\box_ht:N \g__ptxcd_logo_box}

\DeclareNewLayer[
	clone=title.BFH.logo,
	contents={\putLL{\box_use:N \g__ptxcd_logo_box}}
]{BFH.headlinelogo}

\DeclareNewLayer[
	clone=title.BFH.partnerlogo
]{BFH.headlinepartnerlogo}

\DeclarePageStyleByLayers{bfh-projectproposal}{scrheadings.foot.oneside,scrheadings.foot.odd,scrheadings.foot.even,BFH.headlinelogo,BFH.headlinepartnerlogo}
\pagestyle{bfh-projectproposal}
\renewcommand*{\titlepagestyle}{bfh-projectproposal}

\setkomafont{pageheadfoot}{\usekomafont{titlefooter}}
\addtokomafont{subject}{\itshape}

\ifoot{\@titlefooterleft}
\ofoot{\@titlefooterright}

\setcounter{secnumdepth}{-1}

%compact lists
\renewcommand*{\labelitemi}{–}
\edef\@list@extra{\@list@extra\topsep\z@\parsep\z@\itemsep\z@}
\setlength{\leftmarginiv}{\leftmarginiii}
\setlength{\leftmarginiii}{\leftmarginii}
\setlength{\leftmarginii}{\leftmargini}
\setlength{\leftmargini}{\dimexpr.5em+1ex}

%titlepage

\date{}

\renewcommand*{\@maketitle}{%
	\begingroup
	\setparsizes{\z@}{\z@}{\z@\@plus 1fil}\par@updaterelative
		\__ptxcd_print_title:
		\tl_if_empty:NF \g__ptxcd_PP_ProjectDescription_tl {\par\g__ptxcd_PP_ProjectDescription_tl\par}
	\skip_vertical:n {\g_ptxcd_rule_height_dim+.5\box_ht:N \g__ptxcd_logo_box}
	\endgroup
	\@thanks\let\@thanks\@empty
}

\bool_new:N \l__ptxcd_title_dates_bool

\providecommand*{\coadvisorname}{\GetTranslation{Co-advisor}}
\providecommand*{\advisorname}{\GetTranslation{Advisor}}
\providecommand*{\projectpartnername}{\GetTranslation{Project~partner}}
\providecommand*{\expertname}{\GetTranslation{Expert}}

\providecommand*{\projectstartdatename}{\GetTranslation{Project~start}}
\providecommand*{\studysubmissiondatename}{\GetTranslation{Pre-study~submission}}
\providecommand*{\reportsubmissiondatename}{\GetTranslation{Report~submission}}
\providecommand*{\presentationdatename}{\GetTranslation{Presentation}}

\cs_new:Nn \ptxcd_title_data_field:n {
	\tl_if_empty:cF {@#1} {
	\raggedright \use:c {#1name} &\raggedright \use:c {@#1}\tabularnewline
	}
}

\cs_set:Nn 	\__ptxcd_print_title: {
	\begingroup
	\usekomafont{disposition}
	{\usekomafont{title}\@title\par}
	\ifx\@subtitle\@empty\else{\medskip\usekomafont{subtitle}\@subtitle\par}\fi
	\smallskip
		\ifx\@subject\@empty\else{\usekomafont{subject}\@subject\par\smallskip}\fi
		\ifx\@author\@empty\else{\usekomafont{author}\@author\par\smallskip}\fi
	\endgroup
	\tl_if_blank:eTF {
		\@projectstartdate
		\@studysubmissiondate
		\@reportsubmissiondate
		\@presentationdate
	} 
		{\bool_set_false:N \l__ptxcd_title_dates_bool}
		{\bool_set_true:N \l__ptxcd_title_dates_bool}
		
	\begin{tabular}{@{}p{0.2\linewidth}>{\raggedright\arraybackslash}p{\dimexpr.3\linewidth-2\tabcolsep-.5\columnsep}@{}}%
		\ptxcd_title_data_field:n {advisor}
		\ptxcd_title_data_field:n {coadvisor}
		\bool_if:NT \l__ptxcd_title_dates_bool
			{
			\ptxcd_title_data_field:n {projectpartner}
			\ptxcd_title_data_field:n {expert}	
			}
	\end{tabular}\hfill
	\begin{tabular}{@{}p{0.2\linewidth}p{\dimexpr.33\linewidth-2\tabcolsep-.5\columnsep}@{}}%
		\bool_if:NF \l__ptxcd_title_dates_bool
			{
				\ptxcd_title_data_field:n {projectpartner}
				\ptxcd_title_data_field:n {expert}		
			}
		\ptxcd_title_data_field:n {projectstartdate}
		\ptxcd_title_data_field:n {studysubmissiondate}
		\ptxcd_title_data_field:n {reportsubmissiondate}
		\ptxcd_title_data_field:n {presentationdate}
	\end{tabular}
	\par\medskip
	\tl_if_blank:eF {\@date\@version}{
		\usekomafont{date}
		\ifx\@version\@empty
		\@date
		\else\GetTranslation{version-of-date}
		\fi
		\par\smallskip
	}
	\ifx\@publishers\@empty\else{\usekomafont{publishers}\@publishers\par}\fi
}

\clist_map_inline:nn {advisor, coadvisor, projectpartner, expert, projectstartdate, studysubmissiondate, reportsubmissiondate, presentationdate} {
	\cs_if_exist:cF {#1}	{
		\cs_new_nopar:cpn {#1}  ##1 {\exp_args:Nc \def {@#1} {##1}}
		\use:c {#1} {}
	}
}

\tl_new:N \g__ptxcd_PP_ProjectDescription_tl
\NewDocumentEnvironment{ProjectDescription}{+b}{}{\tl_gset:Nn \g__ptxcd_PP_ProjectDescription_tl {#1}}


% RatingChart

\colorlet{competenceRating-color}{BFH-DarkRed}


\keys_define:nn {ptxcd/CompetenceChart} {
	radius .dim_set:N = \l__ptxcd_CompetenceChart_radius_dim,
	radius .initial:n = .35\linewidth,
	max-weight .int_set:N = \l__ptxcd_Competencechart_maxweight_int,
	max-weight .initial:n = {6},
	color .code:n = \colorlet{BFH-competenceRating}{#1},
	color .initial:n = BFH-DarkRed,
}

\seq_new:N \l__ptxcd_projectProposal_competence_rating_seq
\tl_new:N \l__ptxcd_Competence_tl
\tl_new:N \l__ptxcd_Competence_path_tl

\cs_new:Npn  \__ptxcd_Competence_get_weight:w #1 = #2 \q_stop {#2}
\cs_new:Npn  \__ptxcd_Competence_get_label:w #1 = #2 \q_stop {#1}

\cs_new:Nn \__ptxcd_Competence_weight:n  {
	\__ptxcd_Competence_get_weight:w #1 \q_stop
}

\cs_generate_variant:Nn \__ptxcd_Competence_weight:n {e}

\cs_new:Nn \__ptxcd_Competence_label:n  {
	\__ptxcd_Competence_get_label:w #1 \q_stop
}
\cs_generate_variant:Nn \__ptxcd_Competence_label:n {e}

\int_new:N \l__ptxcd_projectProposal_competence_angle_int
\dim_new:N \l__ptxcd_CompetenceChart_radius_step_dim

\NewDocumentCommand{\DisplayCompetenceRatingChart}{om}
{
	\begingroup
	\IfNoValueF{#1}{\keys_set:nn {ptxcd/CompetenceChart} {#1}}
	\seq_set_from_clist:Nn \l__ptxcd_projectProposal_competence_rating_seq	{#2}
	\int_set:Nn \l__ptxcd_projectProposal_competence_angle_int {360/\seq_count:N \l__ptxcd_projectProposal_competence_rating_seq}
	\dim_set:Nn \l__ptxcd_CompetenceChart_radius_step_dim {\l__ptxcd_CompetenceChart_radius_dim/(\seq_count:N \l__ptxcd_projectProposal_competence_rating_seq+1)}
	\begin{tikzpicture}[rotate=\int_eval:n {90-\l__ptxcd_projectProposal_competence_angle_int},x=\l__ptxcd_CompetenceChart_radius_step_dim,y=\l__ptxcd_CompetenceChart_radius_step_dim]
		% draw the background
		\int_step_inline:nnnn {\l__ptxcd_projectProposal_competence_angle_int} {\l__ptxcd_projectProposal_competence_angle_int} {360} {
			\draw(0,0) -- (\int_eval:n {##1}\c_colon_str\l__ptxcd_CompetenceChart_radius_dim);
		}
		\int_step_inline:nn {\l__ptxcd_Competencechart_maxweight_int} {
			\draw [black!40] (0\c_colon_str##1) \foreach \a in {0,\int_use:N \l__ptxcd_projectProposal_competence_angle_int,...,360}{
				-- (\a\c_colon_str##1)
			} -- cycle;
			\int_step_inline:nnnn {\l__ptxcd_projectProposal_competence_angle_int} {\l__ptxcd_projectProposal_competence_angle_int} {360} {
				\fill (####1\c_colon_str##1) circle (1pt);
			}
		}
		\tl_clear:N \l__ptxcd_Competence_path_tl
		%expand path before used in path to avoid expansion bugs
		\int_step_inline:nn {\seq_count:N \l__ptxcd_projectProposal_competence_rating_seq} {
			\tl_put_right:Nx \l__ptxcd_Competence_path_tl {(\int_eval:n {##1*\l__ptxcd_projectProposal_competence_angle_int}\c_colon_str\__ptxcd_Competence_weight:e {\seq_item:Nn \l__ptxcd_projectProposal_competence_rating_seq {##1}})--}
			\node[anchor=\int_eval:n {(##1-1)*\l__ptxcd_projectProposal_competence_angle_int-90}] at (\int_eval:n {##1*\l__ptxcd_projectProposal_competence_angle_int}\c_colon_str\l__ptxcd_CompetenceChart_radius_dim) {\__ptxcd_Competence_label:e {\seq_item:Nn \l__ptxcd_projectProposal_competence_rating_seq {##1}}};
		}
		\exp_last_unbraced:Nno \use:n {\draw[color=BFH-competenceRating,fill=BFH-competenceRating!50,line~width=1.5pt,opacity=0.5]}
		\l__ptxcd_Competence_path_tl cycle;
	\end{tikzpicture}
	\endgroup
}
\endinput