\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{awesomebox}[2019/04/04 v0.5]

% Awesome Box has been written by Étienne Deparis and is released under
% the WTFPL (http://www.wtfpl.net/txt/copying/).
% A copy of this license is distributed in this package.
%
% Contributors:
% v0.2: Vincent Goulet https://github.com/vigou3
% v0.3: Gilbert Fuerer https://github.com/foreachthing
% * Remove xelatex/luatex requirement and add pdflatex compatibility
% v0.4: Marcel Krüger https://github.com/zauguin
% * Fontawesome5 compatibility
% Gilbert Fuerer
% * Custom vertical rule color
% v0.5: Georger Araújo https://github.com/georgerbr
% * Horizontal rules at top and bottom, title

% https://ctan.org/pkg/fontawesome5
\RequirePackage{fontawesome5}

% Compatibility with old version of this package
\def\abIconCheck{\faCheck}
\def\abIconInfoCircle{\faInfoCircle}
\def\abIconFire{\faFire}
\def\abIconExclamationCircle{\faExclamationCircle}
\def\abIconExclamationTriangle{\faExclamationTriangle}
\def\abIconCogs{\faCogs}
\def\abIconThumbsUp{\faThumbsUp}
\def\abIconThumbsDown{\faThumbsDown}
\def\abIconCertificate{\faCertificate}
\def\abIconLightBulb{\faLightbulb[regular]}
\def\abIconTwitter{\faTwitter}
\def\abIconGithub{\faGithub}

% https://ctan.org/pkg/xcolor
\RequirePackage{xcolor}
% Some basic colors
\definecolor{abnote}{RGB}{25,64,122}
\definecolor{abcaution}{RGB}{188,50,0}
\definecolor{abwarning}{RGB}{188,103,0}
\definecolor{abimportant}{RGB}{188,0,0}
\definecolor{abvrulecolor}{RGB}{221,221,216}

\newlength{\aweboxleftmargin}
\setlength{\aweboxleftmargin}{0.08\linewidth}
\newlength{\aweboxcontentwidth}
\setlength{\aweboxcontentwidth}{0.92\linewidth}
\newlength{\aweboxvskip}
\setlength{\aweboxvskip}{5mm}
\newlength{\aweboxsignraise}
\setlength{\aweboxsignraise}{-5mm}
\newlength{\aweboxrulewidth}
\setlength{\aweboxrulewidth}{2pt}

\RequirePackage{array}

% To allow for more than one optional argument
\RequirePackage{xparse}

% Horizontal rule definitions used with second optional argument [hrule]
\def\abShortLine{\cline{2-2}}
\def\abLongLine{\hline}

% Commands API
% \awesomebox[vrulecolor][hrule][title]{vrulewidth}{icon}{iconcolor}{content}
\NewDocumentCommand \awesomebox { O{abvrulecolor} O{} o m m m +m }{%
  \vspace{\aweboxvskip}\noindent
  \begin{tabular}%
    {p{\aweboxleftmargin}!{\color{#1}\vrule width #4}p{\aweboxcontentwidth}}
    \IfValueTF {#3}
      { & #3 \\ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} & #7 \\ #2}
      {         #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} & #7 \\ #2}
  \end{tabular}
  \vspace{\aweboxvskip}}

\newcommand{\notebox}[1]{%
  \awesomebox[abnote]{\aweboxrulewidth}{\abIconInfoCircle}{abnote}{#1}}

\newcommand{\tipbox}[1]{%
  \awesomebox{\aweboxrulewidth}{\abIconLightBulb}{black}{#1}}

\newcommand{\warningbox}[1]{%
  \awesomebox[abwarning]{\aweboxrulewidth}{\abIconExclamationTriangle}{abwarning}{#1}}

\newcommand{\cautionbox}[1]{%
  \awesomebox[abcaution]{\aweboxrulewidth}{\abIconFire}{abcaution}{#1}}

\newcommand{\importantbox}[1]{%
  \awesomebox[abimportant]{\aweboxrulewidth}{\abIconExclamationCircle}{abimportant}{#1}}

% Environments API
% \begin{awesomeblock}[vrulecolor][hrule][title]{vrulewidth}{icon}{iconcolor}
%   content
% \end{awesomeblock}
\NewDocumentEnvironment{awesomeblock}{ O{abvrulecolor} O{} o m m m }
{\vspace{\aweboxvskip}\noindent
  \begin{tabular}%
    {p{\aweboxleftmargin}!{\color{#1}\vrule width #4}p{\aweboxcontentwidth}}
    \IfValueTF {#3}
      { & #3 \\ #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} &}
      {         #2 \raisebox{\aweboxsignraise}{\textcolor{#6}{\Huge#5}} &}}
{\\ #2 \end{tabular}\vspace{\aweboxvskip}}

\newenvironment{noteblock}%
{\begin{awesomeblock}[abnote]{\aweboxrulewidth}{\abIconInfoCircle}{abnote}}
  {\end{awesomeblock}}

\newenvironment{tipblock}%
{\begin{awesomeblock}{\aweboxrulewidth}{\abIconLightBulb}{black}}
  {\end{awesomeblock}}

\newenvironment{warningblock}%
{\begin{awesomeblock}[abwarning]{\aweboxrulewidth}{\abIconExclamationTriangle}{abwarning}}
  {\end{awesomeblock}}

\newenvironment{cautionblock}%
{\begin{awesomeblock}[abcaution]{\aweboxrulewidth}{\abIconFire}{abcaution}}
  {\end{awesomeblock}}

\newenvironment{importantblock}%
{\begin{awesomeblock}[abimportant]{\aweboxrulewidth}{\abIconExclamationCircle}{abimportant}}
  {\end{awesomeblock}}

\endinput
