\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{../easyLetter}[2023/04/04 Small class based on 'lettre' to quickly write a letter (FR)]

\LoadClass[12pt]{lettre}

% Fix hauteur
\renewcommand{\paperheight}{11in}

\AtEndPreamble{
    % Encoding
    \RequirePackage[utf8]{inputenc}
    \RequirePackage[T1]{fontenc}
    \RequirePackage{lmodern}

    % Language
    \RequirePackage[french]{babel}

    % Font
    \RequirePackage{fontspec}
    \setmainfont[Numbers={Monospaced}]{Fira Sans}
    \setmonofont{Fira Code}

    % Remove the extra line
    \makeatletter
    \newcommand*{\NoRule}{\renewcommand*{\rule@length}{0}}
    \makeatother
    \NoRule

    % Clickable links + metadata
    \RequirePackage[pdfauthor={\@author},
        pdftitle={\@title},
        pdfsubject={\@subject},
        pdfkeywords={\@author, lettre\@keywords},
        pdfcreator={LaTeX with 'easyLetter' preset},
        % Hide links
        hidelinks
    ]{hyperref}
}

% Title
\newcommand*{\titre}[1]{\def\@title{#1}}

% Author
\newcommand*{\auteur}[1]{\def\@author{#1}}

% Opening
\newcommand{\ouverture}[1]{\def\@opening{#1}}

% Closing
\newcommand{\cloture}[1]{\def\@closing{#1}}

% Subject
\def\@subject{\,}
\newcommand*{\sujet}[1]{\def\@subject{#1}}

% Keywords
\def\@keywords{\,}
\newcommand*{\motscles}[1]{\def\@keywords{\if#1\empty\else, #1\fi}}

% Receiver
\newcommand{\destinataire}[3]{\def\@receivername{#1}\def\@receiverAddress{#2}\def\@receiverCity{#3}}

% Letter content
\newenvironment{easyLetter}{
    \begin{letter}{
            % Destinataire
            \@receivername \\
            \@receiverAddress \\
            \textsc{\@receiverCity}
        }
        \conc{\@title}
        \opening{\@opening}}{
        \closing{\@closing}
    \end{letter}
}
