%MIT License

%Copyright (c) 2020 Aditya Dev

%Permission is hereby granted, free of charge, to any person obtaining a copy
%of this software and associated documentation files (the "Software"), to deal
%in the Software without restriction, including without limitation the rights
%to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%copies of the Software, and to permit persons to whom the Software is
%furnished to do so, subject to the following conditions:

%The above copyright notice and this permission notice shall be included in all
%copies or substantial portions of the Software.

%THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
%SOFTWARE.

\ProvidesPackage{color-env}[2020/10/31 color-env]

%%%%%%%%%%%%%%%%
% Requirements %
%%%%%%%%%%%%%%%%

\RequirePackage{xcolor}
\RequirePackage{graphicx}
\RequirePackage[framemethod=TikZ]{mdframed}  %% for colored framed boxes
\RequirePackage{framed}  %% for problem 
\RequirePackage{amsthm}  %% for theorem environment 

%%%%%%%%%%%%%%%%%%
%  Environments  %
%%%%%%%%%%%%%%%%%%

%%%%%%%% Problem %%%%%%%%%%%%%
\colorlet{shadecolor}{orange!12}
\newtheorem{prob}{Problem}
\newenvironment{problem}
{\begin{shaded}\begin{prob}}
		{\end{prob}\end{shaded}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%% THEOREM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{theo}[section] \setcounter{theo}{0} %% counter
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{section}.\arabic{theo}}
\newenvironment{theorem}[2][]{%
	\refstepcounter{theo}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=blue!20]
				{\strut Theorem~\thetheo};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=blue!20]
				{\strut Theorem~\thetheo:~#1};}}%
	}%
	\mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
		linewidth=2pt,topline=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax
	}
	\begin{mdframed}[]\relax%
		\label{#2}}{\end{mdframed}}
%%%%%%%%%%%%%%% LEMMA %%%%%%%%%%%%%%%
\newcounter{lem}[section]\setcounter{lem}{0}
\renewcommand{\thelem}{\arabic{chapter}.\arabic{section}.\arabic{lem}}
\newenvironment{lemma}[2][]{%
	\refstepcounter{lem}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=orange!20]
				{\strut Lemma~\thelem};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=orange!20]
				{\strut Lemma~\thelem:~#1};}}%
	}%
	\mdfsetup{innertopmargin=10pt,linecolor=orange!20,%
		linewidth=2pt,topline=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax
	}
	\begin{mdframed}[]\relax%
		\label{#2}}{\end{mdframed}}

%%%%%%%%%%%%% DEFINITION %%%%%%%%%%%%%%%
\newcounter{def}[section]\setcounter{def}{0}
\renewcommand{\thedef}{\arabic{chapter}.\arabic{section}.\arabic{def}}
\newenvironment{definition}[2][]{%
	\refstepcounter{def}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=red!25]
				{\strut Definition~\thedef};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=red!25]
				{\strut Definition~\thedef:~#1};}}%
	}%
	\mdfsetup{innertopmargin=10pt,linecolor=red!25,%
		linewidth=2pt,topline=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax
	}
	\begin{mdframed}[]\relax%
		\label{#2}}{\end{mdframed}}
%%%%%%%%%%%%%% COROLLARY %%%%%%%%%%%%%%%%%%
\newcounter{cor}[section]\setcounter{cor}{0}
\renewcommand{\thecor}{\arabic{chapter}.\arabic{section}.\arabic{cor}}
\newenvironment{corollary}[2][]{%
	\refstepcounter{cor}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=yellow!20]
				{\strut Corollary~\thecor};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=yellow!20]
				{\strut Corollary~\thecor:~#1};}}%
	}%
	\mdfsetup{innertopmargin=10pt,linecolor=yellow!20,%
		linewidth=2pt,topline=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax
	}
	\begin{mdframed}[]\relax%
		\label{#2}}{\end{mdframed}}

%%%%%%%%%%%%% PROPOSITIONS %%%%%%%%%%%%%%%%%%%
\newcounter{prop}[section]\setcounter{prop}{0}
\renewcommand{\theprop}{\arabic{chapter}.\arabic{section}.\arabic{prop}}
\newenvironment{proposition}[2][]{%
	\refstepcounter{prop}%
	\ifstrempty{#1}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=green!25]
				{\strut Proposition~\theprop};}}
	}%
	{\mdfsetup{%
			frametitle={%
				\tikz[baseline=(current bounding box.east),outer sep=0pt]
				\node[anchor=east,rectangle,fill=green!25]
				{\strut Proposition~\theprop:~#1};}}%
	}%
	\mdfsetup{innertopmargin=10pt,linecolor=green!25,%
		linewidth=2pt,topline=true,%
		frametitleaboveskip=\dimexpr-\ht\strutbox\relax
	}
	\begin{mdframed}[]\relax%
        \label{#2}}{\end{mdframed}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\expandafter\let\expandafter\oldproof\csname\string\proof\endcsname
\let\oldendproof\endproof
\renewenvironment{proof}[1][\proofname]{%
	\oldproof[\bf \scshape \large #1]%
}{\oldendproof}
\renewcommand\qedsymbol{$\blacksquare$}  %% optional if you like it.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%
%\expandafter\let\expandafter\oldproof\csname\string\proof\endcsname
%\let\oldendproof\endproof
%\renewenvironment{proof}[1][\proofname]{%
%	\oldproof[\bf \scshape \large #1]%
%}{\oldendproof}
%%%%%%%%%%%%%%%%



