import { EMAIL_LOGO_URL } from '../assets/logo-studio-m-white';

type BaseTemplateConfig = {
  title: string;
  preheader?: string;
  content: string;
};

const BODY_STYLE =
  "margin:0; padding:0; background-color:#f6f5f1; color:#3c2f2b; font-family:'Archivo','Helvetica Neue',Arial,sans-serif;";
const ROOT_TABLE_STYLE =
  'width:100%; border-collapse:collapse; border-spacing:0; background-color:#f6f5f1;';
const ROOT_CELL_STYLE = 'padding:32px 0;';
const CONTAINER_TABLE_STYLE =
  'width:100%; max-width:640px; background-color:#ffffff; border-radius:24px; overflow:hidden; box-shadow:0 16px 40px rgba(105,72,63,0.15); border:1px solid #f0ece8; border-collapse:collapse; border-spacing:0;';
const HEADER_CELL_STYLE =
  'padding:36px 32px; background:linear-gradient(140deg,#69483f 0%,#352420 100%); color:#f6f5f1; text-align:center;';
const HEADER_LOGO_STYLE =
  'display:block; width:100%; max-width:280px; height:auto; margin:0 auto;';
const PREHEADER_STYLE =
  'display:none!important; visibility:hidden; opacity:0; color:transparent; height:0; width:0; overflow:hidden; mso-hide:all;';

export const renderBaseTemplate = ({
  title,
  preheader = '',
  content,
}: BaseTemplateConfig) => `<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>${title}</title>
  </head>
  <body style="${BODY_STYLE}">
    <span style="${PREHEADER_STYLE}">${preheader}</span>
    <table role="presentation" width="100%" style="${ROOT_TABLE_STYLE}">
      <tr>
        <td align="center" style="${ROOT_CELL_STYLE}">
          <table
            role="presentation"
            width="100%"
            style="${CONTAINER_TABLE_STYLE}"
          >
            <tr>
              <td style="${HEADER_CELL_STYLE}">
                <img
                  src="${EMAIL_LOGO_URL}"
                  alt="Studio M"
                  style="${HEADER_LOGO_STYLE}"
                />
              </td>
            </tr>
            ${content}
          </table>
        </td>
      </tr>
    </table>
  </body>
</html>`;
