export interface InquiryClientConfirmationData {
  firstName: string;
  mooringNumber: string | null;
  contactEmail: string;
}

export function inquiryClientConfirmation(data: InquiryClientConfirmationData) {
  const { firstName, mooringNumber, contactEmail } = data;

  const berthText = mooringNumber ? `Berth ${mooringNumber}` : 'a Port Nimara Berth';

  const subject = mooringNumber
    ? `Thank You for Your Interest in Berth ${mooringNumber}`
    : 'Thank You for Your Interest in a Port Nimara Berth';

  const html = `<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>${subject}</title>
  <style type="text/css">
    table, td { mso-table-lspace: 0pt; mso-table-rspace: 0pt; }
    img { border: 0; display: block; }
    p { margin: 0; padding: 0; }
  </style>
</head>
<body style="margin:0; padding:0; background-color:#f2f2f2;">
  <table role="presentation" width="100%" border="0" cellspacing="0" cellpadding="0" style="background-image: url('https://s3.portnimara.com/images/Overhead_1_blur.png'); background-size: cover; background-position: center; background-color:#f2f2f2;">
    <tr>
      <td align="center" style="padding:30px;">
        <table role="presentation" width="600" border="0" cellspacing="0" cellpadding="0" style="background-color:#ffffff; border-radius:8px; overflow:hidden; box-shadow:0 2px 4px rgba(0,0,0,0.1);">
          <tr>
            <td style="padding:20px; font-family: Arial, sans-serif; color:#333333;">
              <center>
                <img src="https://s3.portnimara.com/images/Port%20Nimara%20New%20Logo-Circular%20Frame_250px.png" alt="Port Nimara Logo" width="100" style="margin-bottom:20px;" />
              </center>
              <p style="margin-bottom:10px; font-size:16px;">Dear ${escapeHtml(firstName)},</p>
              <p style="margin-bottom:10px; font-size:16px;">
                Thank you for expressing interest in ${escapeHtml(berthText)}.
                Our team has registered your interest, and we will reach out to you very shortly
                by your preferred method of contact with more information.
              </p>
              <p style="margin-bottom:10px; font-size:16px;">
                If you have any questions, please feel free to reach out to us at
                <a href="mailto:${escapeHtml(contactEmail)}" style="color:#007bff; text-decoration:underline;">${escapeHtml(contactEmail)}</a>.
              </p>
              <p style="font-size:16px;">
                Best regards,<br />
                The Port Nimara Sales Team
              </p>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>`;

  const text = [
    `Dear ${firstName},`,
    '',
    `Thank you for expressing interest in ${berthText}. Our team has registered your interest, and we will reach out to you very shortly by your preferred method of contact with more information.`,
    '',
    `If you have any questions, please feel free to reach out to us at ${contactEmail}.`,
    '',
    'Best regards,',
    'The Port Nimara Sales Team',
  ].join('\n');

  return { subject, html, text };
}

function escapeHtml(str: string): string {
  return str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#39;');
}
