%%%%
% Commandes d'affichage
%%%%%%%%%%%%%%%%%%%%%%%%%%% \ref{exercice:\thechapter.22} ---> pour faire référence à un exercice (ici, le num 22)

\newcommand{\putnbexosintoc}
{%
	\addtocontents{toc}{\hspace*{8mm}\textit{\lefthand~~\arabic{nbexosTotal} exercices entièrement corrigés}}
}

\newcommand{\exercices}{%
	\clearpage
	\pagestyle{enonces}
	\phantomsection
	\addcontentsline{toc}{section}{Enoncés}
	\begin{flushright}
		\begin{tikzpicture}
			\foreach\x/\i in {1/25,2/50,3/100} { \fill[numpageenonce!\i] (\x,0) rectangle +(0.5,0.5) ;}
			\node[text = numpageenonce,right] at (4,0.25) {\Huge\duttfamily EXERCICES};
		\end{tikzpicture}
	\end{flushright}
	\tcbstartrecording
	\itemclass{numpageenonce}
	\arrayrulecolor{numpageenonce}
	
}

\newcommand{\corriges}{%
	\tcbstoprecording
	\clearpage
	\pagestyle{corriges}
	\phantomsection
	\addcontentsline{toc}{section}{Corrigés des exercices}
	\begin{flushright}
		\begin{tikzpicture}
			\foreach\x/\i in {1/25,2/50,3/100} { \fill[numpagecorrige!\i] (\x,0) rectangle +(0.5,0.5) ;}
			\node[text = numpagecorrige,right] at (4,0.25) {\Huge\duttfamily CORRECTIONS};
		\end{tikzpicture}
	\end{flushright}
	\itemclass{numpagecorrige}
	\arrayrulecolor{numpagecorrige}
	\tcbinputrecords
}

\fancypagestyle{enonces}{% 
	\pagecolor{pageenonce}
	\fancyhf{}%
  	\fancyfoot[RO]{% pages impaires
		\ClearShipoutPicture
		\vskip0.1pt  	
		\begin{tikzpicture}
		\node[rounded corners=3pt,fill=numpageenonce,inner ysep=5pt, inner xsep=2ex,text=pageenonce] (numpage) {\ECFWebster\thepage};
		\end{tikzpicture}
  	}
  	\fancyfoot[LE]{% pages paires	
  		\ClearShipoutPicture
  		\vskip0.1pt
  		\begin{tikzpicture}
  		\node[rounded corners=3pt,fill=numpageenonce,inner ysep=5pt, inner xsep=2ex,text=pagecorrige] (numpage) {\ECFWebster\thepage};
  		\end{tikzpicture}
  	}
}

\fancypagestyle{corriges}{% 
	\pagecolor{pagecorrige}
	\fancyhf{}%
  	\fancyfoot[RO]{% pages impaires
		\ClearShipoutPicture
		\vskip0.1pt  	
		\begin{tikzpicture}
		\node[rounded corners=3pt,fill=numpagecorrige,inner ysep=5pt, inner xsep=2ex,text=pageenonce] (numpage) {\ECFWebster\thepage};
		\end{tikzpicture}
  	}
  	\fancyfoot[LE]{% pages paires	
  		\ClearShipoutPicture
  		\vskip0.1pt
  		\begin{tikzpicture}
  		\node[rounded corners=3pt,fill=numpagecorrige,inner ysep=5pt, inner xsep=2ex,text=pagecorrige] (numpage) {\ECFWebster\thepage};
  		\end{tikzpicture}
  	}
}

\newcounter{nbexos}[chapter]
\newcounter{nbexosTotal}
\AtBeginEnvironment{exocor}{\stepcounter{nbexos}\stepcounter{nbexosTotal}}

% \NewTColorBox[auto counter,number within = chapter]{exocor}{m+O{}}{%
	% enhanced,
	% breakable,
	% separator sign none,
	% before skip = 2mm,
	% after skip = 2mm,
	% colback = pageenonce!30,
	% colframe = numpageenonce,
	% boxrule = 0.2mm,
	% drop fuzzy shadow,
	% watermark zoom=1,
	% watermark color=gray,
	% watermark opacity=.1,
	% clip watermark,
	% watermark text={\rotatebox{30}{mathweb.fr}},
	% title={Exercice \thetcbcounter\ifx\hfuzz#1\hfuzz\else~(#1)\fi\arrayrulecolor{numpageenonce}},
	% label={exercice:\thetcbcounter},
	% attach boxed title to top left = { xshift = 1cm , yshift*=1mm-\tcboxedtitleheight },
	% varwidth boxed title*=-3cm,
	% boxed title style = {
		% frame code = {
			% \path[fill = numpageenonce!30!black] ([yshift=-1mm,xshift=-1mm]frame.north west)
				% arc[start angle=0,end angle=180,radius=1mm] ([yshift=-1mm,xshift=1mm]frame.north east)
				% arc[start angle=180,end angle=0,radius=1mm];
			% \path[left color=numpageenonce!60!black,right color=numpageenonce!60!black,middle color=numpageenonce!80!black] ([xshift=-2mm]frame.north west) 
				% -- ([xshift=2mm]frame.north east)[rounded corners=1mm]
				% -- ([xshift=1mm,yshift=-1mm]frame.north east)
				% -- (frame.south east) -- (frame.south west)-- ([xshift=-1mm,yshift=-1mm]frame.north west)[sharp corners]-- cycle;
		% },
		% interior engine=empty
	% },
	% fonttitle = \fontfamily{lmss}\selectfont\bfseries,
	% after upper={\par\hfill\textcolor{numpageenonce}{\itshape Solution page~\pageref{solution:\thetcbcounter}}},
    % lowerbox=ignored,
    % savelowerto=corriges/exercice-\thetcbcounter.tex,
    % record={\string\solution{\thetcbcounter}{corriges/exercice-\thetcbcounter.tex}},
	% #2
% }

\NewTColorBox[auto counter,number within=chapter]{exocor}{mO{0}O{}}{%
    enhanced,
    breakable,
    separator sign none,
    before skip=2mm,
    after skip=2mm,
    colback=pageenonce!30,
    colframe=numpageenonce,
    boxrule=0.2mm,
    drop fuzzy shadow,
    watermark zoom=1,
    watermark color=gray,
    watermark opacity=.1,
    clip watermark,
    watermark text={\rotatebox{30}{mathweb.fr}},
    title={Exercice \thetcbcounter\ifx\hfuzz#1\hfuzz\else~(#1)\fi\arrayrulecolor{numpageenonce}},
    label={exercice:\thetcbcounter},
    attach boxed title to top left={xshift=1cm, yshift*=1mm-\tcboxedtitleheight},
    varwidth boxed title*=-3cm,
    boxed title style={
        frame code={
            \path[fill=numpageenonce!30!black] ([yshift=-1mm,xshift=-1mm]frame.north west)
                arc[start angle=0,end angle=180,radius=1mm] ([yshift=-1mm,xshift=1mm]frame.north east)
                arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=numpageenonce!60!black,right color=numpageenonce!60!black,middle color=numpageenonce!80!black] ([xshift=-2mm]frame.north west)
                -- ([xshift=2mm]frame.north east)[rounded corners=1mm]
                -- ([xshift=1mm,yshift=-1mm]frame.north east)
                -- (frame.south east) -- (frame.south west)-- ([xshift=-1mm,yshift=-1mm]frame.north west)[sharp corners]-- cycle;
			\node[anchor=north east, inner sep=2pt] at ([xshift=0.93\linewidth,yshift=-1mm]frame.north west) {
            \href{https://mathweb.fr/traitement_erreur.php?livre=\jobname&exercice=\thetcbcounter}{\includegraphics[width=16px,height=16px]{erreur.png}}
        };
			% Mettre ici le code pour insérer les étoiles
			\ifnum#2>0
				\node[anchor=north west, inner sep=2pt, outer sep=0pt, fill=numpageenonce!30, draw=numpageenonce, rounded corners=1mm] at ([xshift=-13mm,yshift=-4mm]frame.north west) {
					\parbox{4mm}{\raggedleft
						\foreach \i in {1,...,#2} {
							\textcolor{numpageenonce}{\faStar} \\
						}
					}
				};
			\fi			
        },
        interior engine=empty
    },
    fonttitle=\fontfamily{lmss}\selectfont\bfseries,
    after upper={\par\hfill\textcolor{numpageenonce}{\itshape Solution page~\pageref{solution:\thetcbcounter}}},
    lowerbox=ignored,
    savelowerto=corriges/exercice-\thetcbcounter.tex,
    record={\string\solution{\thetcbcounter}{corriges/exercice-\thetcbcounter.tex}},
    #3
}






\NewTotalTColorBox{\solution}{mm}{%
    enhanced,
	breakable,
    colframe = numpagecorrige,
    colback = pagecorrige!30,
    coltitle = numpagecorrige,
    fonttitle = \fontfamily{lmss}\selectfont\bfseries,
	rounded corners,arc is angular,arc=3mm,
	drop fuzzy shadow,
	watermark zoom=1,
	watermark color=gray,
	watermark opacity=.1,
	clip watermark,
	watermark text={\rotatebox{30}{mathweb.fr}},
    title={Corrigé de l'exercice~\ref{exercice:#1} page~\pageref{exercice:#1}\arrayrulecolor{numpagecorrige}},
    phantomlabel={solution:#1},
    attach title to upper=\par
}{\input{#2}}
