interface OrderConfirmationParams {
  customerEmail: string;
  orderNumber: string;
  voucherCodes: string[];
}

import { Attachment } from './mail';

interface EmailTemplate {
  to: string;
  subject: string;
  html: string;
  text: string;
  attachments?: Attachment[];
}

export function orderConfirmationTemplate(
  params: OrderConfirmationParams
): EmailTemplate {
  const { customerEmail, orderNumber, voucherCodes } = params;

  const voucherListHtml = voucherCodes
    .map((code) => `<li style="padding: 8px 0;"><strong>${code}</strong></li>`)
    .join('');

  const voucherListText = voucherCodes
    .map((code) => `  • ${code}`)
    .join('\n');

  const html = `
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
    .container { max-width: 600px; margin: 0 auto; padding: 20px; }
    .header { background-color: #f8f9fa; padding: 20px; border-radius: 5px; margin-bottom: 20px; }
    .content { margin: 20px 0; }
    .vouchers { background-color: #f0f0f0; padding: 15px; border-radius: 5px; margin: 20px 0; }
    .footer { color: #666; font-size: 12px; margin-top: 30px; border-top: 1px solid #ddd; padding-top: 20px; }
    h2 { color: #333; }
    h3 { color: #555; }
    ul { list-style-position: inside; }
  </style>
</head>
<body>
  <div class="container">
    <div class="header">
      <h2>Děkujeme za objednávku!</h2>
    </div>

    <div class="content">
      <p>Vaše objednávka <strong>#${orderNumber}</strong> byla zaplacena a nyní ji zpracovávame.</p>
      
      <div class="vouchers">
        <h3>Vaše poukazy:</h3>
        <ul>
          ${voucherListHtml}
        </ul>
      </div>

      <p>Poukazy můžete použít na našich službách. Každý poukazový kód je jedinečný.</p>
    </div>

    <div class="footer">
      <p>S pozdravem,<br><strong>VYSTŘÍKEJ TO</strong></p>
      <p>Objednávka: #${orderNumber}</p>
    </div>
  </div>
</body>
</html>
  `;

  const text = `
Děkujeme za objednávku!

Vaše objednávka #${orderNumber} byla zaplacena a nyní ji zpracovávame.

Vaše poukazy:
${voucherListText}

Poukazy můžete použít na našich službách. Každý poukazový kód je jedinečný.

S pozdravem,
VYSTŘÍKEJ TO

Objednávka: #${orderNumber}
  `;

  return {
    to: customerEmail,
    subject: `Potvrzení objednávky #${orderNumber} - VYSTŘÍKEJ TO`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Ověření emailu
 */
interface VerificationEmailParams {
  customerEmail: string;
  firstName: string;
  lastName: string;
  verificationUrl: string;
}

export function emailVerificationTemplate(
  params: VerificationEmailParams
): EmailTemplate {
  const { customerEmail, firstName, lastName, verificationUrl } = params;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Ověření emailu - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">
              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>
              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>
              <div style="font-size:22px; font-weight:bold; margin:0 0 20px;">Ověření emailové adresy</div>
              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p>Dobrý den, <strong>${firstName} ${lastName}</strong>,</p>
                <p>Děkujeme za registraci na <strong>VYSTŘÍKEJ TO</strong>!
                Pro dokončení registrace je potřeba ověřit Vaši emailovou adresu.</p>
              </div>

              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:20px auto;">
                <tr>
                  <td bgcolor="#f4c542" style="border-radius:6px;">
                    <a href="${verificationUrl}"
                       style="display:inline-block; padding:14px 28px; font-size:16px; font-weight:bold;
                              color:#000000; text-decoration:none;">
                      ✓ Ověřit emailovou adresu
                    </a>
                  </td>
                </tr>
              </table>
              <div style="background:#3a2f00; border:1px solid #f4c542; padding:12px 15px; border-radius:6px; margin:20px 0; color:#f4c542; font-size:14px; max-width:500px; margin-left:auto; margin-right:auto;">
                Tento odkaz je platný 24 hodin z bezpečnostních důvodů.
              </div>
              <div style="font-size:14px; line-height:1.5; text-align:left; max-width:500px; margin:20px auto; color:#dddddd;">
                <p><strong>Pokud nefunguje tlačítko</strong>, zkopírujte a vložte následující odkaz do vašeho prohlížeče:</p>
                <div style="background:#2a2a2a; padding:12px; border-radius:5px; font-family:monospace; font-size:13px; word-break:break-all; color:#f4c542;">
                  ${verificationUrl}
                </div>

                <p style="font-size:13px; color:#999; margin-top:20px;">
                  Pokud jste se na VYSTŘÍKEJ TO neregistrovali, můžete tento email ignorovat.
                </p>
              </div>

            </td>
          </tr>
        </table>
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

Ověření emailové adresy

Dobrý den, ${firstName} ${lastName},

Děkujeme za registraci na VYSTŘÍKEJ TO!
Pro dokončení registrace je potřeba ověřit Vaši emailovou adresu.

OVĚŘIT EMAILOVOU ADRESU:
${verificationUrl}

Tento odkaz je platný 24 hodin z bezpečnostních důvodů.

Pokud nefunguje tlačítko, zkopírujte a vložte následující odkaz do vašeho prohlížeče:
${verificationUrl}

Pokud jste se na VYSTŘÍKEJ TO neregistrovali, můžete tento email ignorovat.

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: 'Ověření emailu - VYSTŘÍKEJ TO',
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Potvrzení registrace
 */
export function registrationEmailTemplate(
  customerEmail: string,
  firstName: string,
  lastName: string
): EmailTemplate {
  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600" style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">

              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>

              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>

              <div style="font-size:20px; font-weight:bold; margin:0 0 10px;">Vítejte, ${firstName} ${lastName}!</div>
              <div style="font-size:18px; line-height:1.4; margin:0 0 25px;">
                S námi už <span style="color:#f4c542; font-weight:bold;">TO</span> stačí jen
                <span style="color:#f4c542; font-weight:bold;">VYSTŘÍKAT</span>!
              </div>

              <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="max-width:500px; margin:0 auto; text-align:left;">
                <tr><td style="font-size:16px; padding:8px 0;">✅ Exkluzivní slevy pouze pro registrované zákazníky.</td></tr>
                <tr><td style="font-size:16px; padding:8px 0;">✅ Rychlejší objednávání a sledování zásilek.</td></tr>
                <tr><td style="font-size:16px; padding:8px 0;">✅ Přístup k novinkám jako první.</td></tr>
                <tr><td style="font-size:16px; padding:8px 0;">✅ Všechny objednávky pohromadě.</td></tr>
              </table>

              <div style="margin:30px 0 10px; font-weight:bold; font-size:16px;">Děkujeme.
              </div>

              <div style="font-size:18px; margin:0 0 25px;">
                Pojďte <span style="color:#f4c542; font-weight:bold;">TO</span> s námi
                <span style="color:#f4c542; font-weight:bold;">VYSTŘÍKAT</span>!
              </div>
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:0 auto;">
                <tr>
                  <td bgcolor="#f4c542" style="border-radius:6px;">
                    <a href="${process.env.NEXT_PUBLIC_BASE_URL || 'https://vystrikejto.cz'}"
                       style="display:inline-block; padding:12px 24px; font-size:16px; font-weight:bold;
                              color:#000000; text-decoration:none;">
                      ZAČÍT NAKUPOVAT
                    </a>
                  </td>
                </tr>
              </table>

            </td>
          </tr>
        </table>
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600" style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

Vítejte, ${firstName} ${lastName}!

S námi už TO stačí jen VYSTŘÍKAT!

Výhody vašeho účtu:
✅ Exkluzivní slevy pouze pro registrované zákazníky.
✅ Rychlejší objednávání a sledování zásilek.
✅ Přístup k novinkám jako první.
✅ Všechny objednávky pohromadě.

Děkujeme.

Pojďte TO s námi VYSTŘÍKAT!

ZAČÍT NAKUPOVAT: ${process.env.NEXT_PUBLIC_BASE_URL || 'https://vystrikejto.cz'}

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: 'Vítejte u VYSTŘÍKEJ TO! 🎉',
    html: html.trim(),
    text: text.trim(),
  };
}
interface OrderRecapItem {
  name: string;
  quantity: number;
  unitPrice: number;
  lineTotal: number;
  image?: string;
  productType?: string;
}

interface InvoiceItem {
  name: string;
  quantity: number;
  unitPrice: number;
  lineTotal: number;
  productType?: string;
}

interface InvoiceData {
  orderNumber: string;
  createdAt: Date;
  items: InvoiceItem[];
  shippingPrice: number;
  total: number;
  currency: string;
  shippingMethod: string;
  customerName: string;
  customerEmail?: string;
  customerPhone?: string;
  billingAddress?: {
    street: string;
    city: string;
    zip: string;
  };
  shippingAddress?: {
    street: string;
    city: string;
    zip: string;
  };
  voucherCode?: string;
  discountAmount?: number;
}

interface VoucherData {
  code: string;
  value: number;
  currency: string;
  issueDate: Date;
  expiryDate: Date;
}

interface OrderRecapDetails {
  orderNumber: string;
  createdAt: Date;
  items: OrderRecapItem[];
  shippingPrice: number;
  total: number;
  currency: string;
  shippingMethod: string;
  billingName: string;
  isGiftWrapped?: boolean;
  voucherCode?: string;
  discountAmount?: number;
  orderNote?: string;
  customerEmail?: string;
  customerPhone?: string;
  trackingUrl?: string;
  billingAddress?: {
    street: string;
    city: string;
    zip: string;
  };
  shippingAddress?: {
    street: string;
    city: string;
    zip: string;
  };
}

export function orderRecapEmailTemplate(
  customerEmail: string,
  details: OrderRecapDetails
): EmailTemplate {
  const itemsHtml = details.items
    .map(
      (item) =>
        `<tr>
          <td style="padding: 12px; border-bottom: 1px solid #3a3a3a; vertical-align: middle;">
            ${item.image ? `<img src="${item.image}" alt="${item.name}" style="max-width: 60px; height: auto; border-radius: 6px; display: block;">` : ''}
          </td>
          <td style="padding: 12px; border-bottom: 1px solid #3a3a3a; color: #dddddd;">${item.name}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a3a3a; text-align: center; color: #dddddd;">${item.quantity}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a3a3a; text-align: right; color: #dddddd; white-space: nowrap;">${item.unitPrice.toFixed(2)} ${details.currency}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a3a3a; text-align: right; color: #f4c542; font-weight: bold; white-space: nowrap;">${item.lineTotal.toFixed(2)} ${details.currency}</td>
        </tr>`
    )
    .join('');

  const itemsText = details.items
    .map((item) => `${item.name} (${item.quantity}x) - ${item.lineTotal.toFixed(2)} ${details.currency}`)
    .join('\n');

  const hasOnlyVouchers = details.items.every(item => item.productType === 'voucher');
  const showShipping = !hasOnlyVouchers || details.shippingPrice > 0;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Rekapitulace objednávky - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">
              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>
              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>
              <div style="font-size:22px; font-weight:bold; margin:0 0 10px;">Rekapitulace objednávky</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 8px;">Číslo objednávky: <strong style="color:#f4c542;">#${details.orderNumber}</strong></div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">Datum objednávky: <strong style="color:#f4c542;">${details.createdAt.toLocaleTimeString('cs-CZ', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', year: 'numeric' })}</strong></div>
              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p>Dobrý den, <strong>${details.billingName}</strong>,</p>

                <p>Děkujeme za Vaši objednávku. Níže naleznete podrobný přehled:</p>
              </div>
              <div style="max-width:500px; margin:25px auto;">
                <table role="presentation" width="100%" cellpadding="0" cellspacing="0"
                       style="background:#2a2a2a; border-radius:8px; overflow:hidden;">
                  <thead>
                    <tr style="background:#1a1a1a;">
                      <th style="padding: 12px; text-align: center; color: #f4c542; font-weight: bold; border-bottom: 2px solid #f4c542; width: 60px;">Náhled</th>
                      <th style="padding: 12px; text-align: left; color: #f4c542; font-weight: bold; border-bottom: 2px solid #f4c542;">Položka</th>
                      <th style="padding: 12px; text-align: center; color: #f4c542; font-weight: bold; border-bottom: 2px solid #f4c542;">Počet</th>
                      <th style="padding: 12px; text-align: right; color: #f4c542; font-weight: bold; border-bottom: 2px solid #f4c542;">Cena</th>
                      <th style="padding: 12px; text-align: right; color: #f4c542; font-weight: bold; border-bottom: 2px solid #f4c542;">Celkem</th>
                    </tr>
                  </thead>
                  <tbody>
                    ${itemsHtml}
                  </tbody>
                </table>
              </div>
              <div style="max-width:500px; margin:25px auto; background:#2a2a2a; padding:20px; border-radius:8px;">
                <table role="presentation" width="100%" style="color:#dddddd; font-size:14px;">
                  <tr>
                    <td style="padding:8px 0;">Mezisoučet položek:</td>
                    <td style="padding:8px 0; text-align:right; white-space: nowrap;">${(details.total - details.shippingPrice + (details.discountAmount || 0)).toFixed(2)} ${details.currency}</td>
                  </tr>
                  ${details.discountAmount && details.discountAmount > 0 ? `
                  <tr>
                    <td style="padding:8px 0;">Sleva (${details.voucherCode || 'poukaz'}):</td>
                    <td style="padding:8px 0; text-align:right; color:#4CAF50; white-space: nowrap;">-${details.discountAmount.toFixed(2)} ${details.currency}</td>
                  </tr>
                  ` : ''}
                  ${showShipping ? `
                  <tr>
                    <td style="padding:8px 0;">Doprava (${details.shippingMethod}):</td>
                    <td style="padding:8px 0; text-align:right; white-space: nowrap;">${details.shippingPrice === 0 ? 'Zdarma' : details.shippingPrice.toFixed(2) + ' ' + details.currency}</td>
                  </tr>
                  ` : ''}
                  <tr style="border-top:2px solid #f4c542;">
                    <td style="padding:12px 0; font-size:16px; font-weight:bold;">CELKEM K ÚHRADĚ:</td>
                    <td style="padding:12px 0; text-align:right; font-size:16px; font-weight:bold; color:#f4c542; white-space: nowrap;">${details.total.toFixed(2)} ${details.currency}</td>
                  </tr>
                </table>
              </div>

              <div style="max-width:500px; margin:25px auto;">
                ${details.orderNote ? `
                <div style="background:#2a2a2a; border:1px solid #f4c542; padding:20px; border-radius:8px; margin-bottom:15px;">
                  <div style="font-size:14px; color:#f4c542; font-weight:bold; margin-bottom:12px; border-bottom:1px solid #3a3a3a; padding-bottom:10px;">📝 POZNÁMKA K OBJEDNÁVCE</div>
                  <div style="font-size:13px; color:#dddddd; line-height:1.8;">
                    ${details.orderNote.replace(/\n/g, '<br>')}
                  </div>
                </div>
                ` : ''}
                <div style="background:#2a2a2a; border:1px solid #f4c542; padding:20px; border-radius:8px; margin-bottom:15px;">
                  <div style="font-size:14px; color:#f4c542; font-weight:bold; margin-bottom:12px; border-bottom:1px solid #3a3a3a; padding-bottom:10px;">👤 ZÁKAZNÍK</div>
                  <div style="font-size:13px; color:#dddddd; line-height:1.8;">
                    <div><strong>${details.billingName}</strong></div>
                    ${details.billingAddress ? `
                    <div style="font-size:12px; color:#cccccc;">
                      ${details.billingAddress.street}<br>
                      ${details.billingAddress.zip} ${details.billingAddress.city}
                    </div>
                    ` : ''}
                    ${details.customerEmail ? `<div style="color:#f4c542; text-decoration:none;">${details.customerEmail}</div>` : ''}
                    ${details.customerPhone ? `<div style="color:#f4c542;">${details.customerPhone}</div>` : ''}

                  </div>
                </div>

                  ${showShipping && details.shippingAddress ? `
                <div style="background:#2a2a2a; border:1px solid #f4c542; padding:20px; border-radius:8px;">
                  <div style="font-size:14px; color:#f4c542; font-weight:bold; margin-bottom:12px; border-bottom:1px solid #3a3a3a; padding-bottom:10px;">📦 ZVOLENÁ DOPRAVA</div>
                  <div style="font-size:13px; color:#dddddd; line-height:1.8;">
                    <div><strong>${details.shippingMethod}</strong></div>
                    <div style="font-size:12px; color:#cccccc;">
                      ${details.shippingAddress.street}<br>
                      ${details.shippingAddress.zip} ${details.shippingAddress.city}
                    </div>
                  </div>
                </div>
                ` : showShipping ? `
                <div style="background:#2a2a2a; border:1px solid #f4c542; padding:20px; border-radius:8px;">
                  <div style="font-size:14px; color:#f4c542; font-weight:bold; margin-bottom:12px; border-bottom:1px solid #3a3a3a; padding-bottom:10px;">📦 ZVOLENÁ DOPRAVA</div>
                  <div style="font-size:13px; color:#dddddd; line-height:1.8;">
                    <div><strong>${details.shippingMethod}</strong></div>
                  </div>
                </div>
                ` : ''}
              </div>
              ${details.trackingUrl ? `
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:25px auto 5px;">
                <tr>
                  <td bgcolor="#f4c542" style="border-radius:6px;">
                    <a href="${details.trackingUrl}" style="display:inline-block; padding:14px 28px; font-size:16px; font-weight:bold; color:#000000; text-decoration:none;">
                      Sledovat stav objednávky
                    </a>
                  </td>
                </tr>
              </table>
              ` : ''}
            </td>
          </tr>
        </table>

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

Rekapitulace objednávky
Číslo objednávky: #${details.orderNumber}
Datum objednávky: ${details.createdAt.toLocaleDateString('cs-CZ')}

Dobrý den, ${details.billingName},

Děkujeme za Vaši objednávku. Níže naleznete podrobný přehled:

POLOŽKY:
${itemsText}

SHRNUTÍ CENY:
Mezisouček (bez dopravy): ${(details.total - details.shippingPrice + (details.discountAmount || 0)).toFixed(2)} ${details.currency}
${details.discountAmount && details.discountAmount > 0 ? `Sleva (${details.voucherCode || 'poukaz'}): -${details.discountAmount.toFixed(2)} ${details.currency}\n` : ''}${showShipping ? `Doprava (${details.shippingMethod}): ${details.shippingPrice === 0 ? 'Zdarma' : details.shippingPrice.toFixed(2) + ' ' + details.currency}\n` : ''}
---
CELKEM K ÚHRADĚ: ${details.total.toFixed(2)} ${details.currency}

${details.orderNote ? `
POZNÁMKA K OBJEDNÁVCE:
${details.orderNote}

` : ''}
ZÁKAZNÍK:
${details.billingName}
${details.customerEmail || ''}
${details.customerPhone || ''}

${showShipping ? `DOPRAVA:
${details.shippingMethod}
${details.shippingAddress ? `${details.shippingAddress.street}
${details.shippingAddress.zip} ${details.shippingAddress.city}` : ''}` : ''}

${details.trackingUrl ? `SLEDOVAT STAV OBJEDNÁVKY:
${details.trackingUrl}
` : ''}

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: `Rekapitulace objednávky #${details.orderNumber} - VYSTŘÍKEJ TO`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Inicializace platby
 */
interface PaymentInitializationParams {
  customerEmail: string;
  firstName: string;
  lastName: string;
  orderNumber: string;
  amount: number;
  currency: string;
  paymentUrl: string;
  trackingUrl?: string;
}

export function paymentInitializationTemplate(
  params: PaymentInitializationParams
): EmailTemplate {
  const { customerEmail, firstName, lastName, orderNumber, amount, currency, paymentUrl, trackingUrl } = params;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Inicializace platby - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">

              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>

              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>

              <div style="font-size:22px; font-weight:bold; margin:0 0 20px;">Čekáme na Vaši platbu</div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p>Dobrý den, <strong>${firstName} ${lastName}</strong>,</p>

                <p>Vaše objednávka <strong>#${orderNumber}</strong> je připravena k zaplacení.</p>

                <p>Celková částka k úhradě: <strong style="color:#f4c542; font-size:18px;">${amount.toFixed(2)} ${currency}</strong></p>
              </div>
              <div style="text-align:center; margin:25px 0; max-width:500px; margin-left:auto; margin-right:auto;">
        
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:20px auto;">
                <tr>
                  <td bgcolor="#f4c542" style="border-radius:6px;">
                    <a href="${paymentUrl}"
                       style="display:inline-block; padding:14px 28px; font-size:16px; font-weight:bold;
                              color:#000000; text-decoration:none;">
                      💰 Zaplatit nyní
                    </a>
                  </td>
                </tr>
              </table>
              </div>
              <div style="font-size:14px; line-height:1.5; text-align:left; max-width:500px; margin:20px auto; color:#dddddd;">
                <p><strong>Pokud nefunguje tlačítko</strong>, zkopírujte a vložte následující odkaz do Vašeho prohlížeče:</p>
                <div style="background:#2a2a2a; padding:12px; border-radius:5px; font-family:monospace; font-size:13px; word-break:break-all; color:#f4c542;">
                  ${paymentUrl}
                </div>
              </div>
              ${trackingUrl ? `
              <p style="font-size:14px; color:#cccccc; margin:22px 0 8px;">Aktuální stav objednávky můžete kdykoliv zobrazit zde:</p>
              <a href="${trackingUrl}" style="color:#f4c542; font-weight:bold; text-decoration:underline;">Sledovat objednávku</a>
              ` : ''}

            </td>
          </tr>
        </table>
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

Čekáme na Vaši platbu

Dobrý den, ${firstName},

Vaše objednávka #${orderNumber} je připravena k zaplacení.

Celková částka k úhradě: ${amount.toFixed(2)} ${currency}

ZAPLATIT NYNÍ:
${paymentUrl}

${trackingUrl ? `SLEDOVAT STAV OBJEDNÁVKY:
${trackingUrl}
` : ''}


Pokud nefunguje tlačítko, zkopírujte a vložte následující odkaz do Vašeho prohlížeče:
${paymentUrl}

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: `Inicializace platby #${orderNumber} - VYSTŘÍKEJ TO`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Potvrzení úspěšné platby
 */
interface PaymentSuccessParams {
  customerEmail: string;
  firstName: string;
  lastName: string;
  orderNumber: string;
  amount: number;
  currency: string;
  paymentDate: Date;
  trackingUrl?: string;
}

export function paymentSuccessTemplate(
  params: PaymentSuccessParams
): EmailTemplate {
  const { customerEmail, firstName, lastName, orderNumber, amount, currency, paymentDate, trackingUrl } = params;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Platba potvrzena - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">

              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>

              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>

              <div style="font-size:24px; font-weight:bold; margin:0 0 10px; color:#4CAF50;">Platba potvrzena!</div>
              <div style="font-size:16px; margin:0 0 20px; color:#cccccc;">Děkujeme.</div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p>Dobrý den, <strong>${firstName} ${lastName}</strong>,</p>

                <p>Vaše platba byla úspěšně přijata a zpracována.</p>
              </div>

              <div style="background:#2a2a2a; border:1px solid #4CAF50; padding:20px; border-radius:8px; margin:25px 0; max-width:500px; margin-left:auto; margin-right:auto;">
                <table role="presentation" width="100%" style="color:#dddddd; font-size:14px;">
                  <tr>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a;">Číslo objednávky:</td>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a; text-align:right; font-weight:bold; color:#f4c542;">#${orderNumber}</td>
                  </tr>
                  <tr>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a;">Zaplacená částka:</td>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a; text-align:right; font-weight:bold; color:#f4c542;">${amount.toFixed(2)} ${currency}</td>
                  </tr>
                  <tr>
                    <td style="padding:8px 0;">Datum platby:</td>
                    <td style="padding:8px 0; text-align:right;">${paymentDate.toLocaleTimeString('cs-CZ', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', year: 'numeric' })}</td>
                  </tr>
                </table>
              </div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p style="text-align:center;">Objednávku aktuálně připravujeme k odeslání.</p>
              </div>
              ${trackingUrl ? `
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center" style="margin:20px auto 0;">
                <tr>
                  <td bgcolor="#f4c542" style="border-radius:6px;">
                    <a href="${trackingUrl}" style="display:inline-block; padding:14px 28px; font-size:16px; font-weight:bold; color:#000000; text-decoration:none;">
                      Sledovat stav objednávky
                    </a>
                  </td>
                </tr>
              </table>
              ` : ''}

            </td>
          </tr>
        </table>

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

✅ Platba potvrzena!
Děkujeme.

Dobrý den, ${firstName} ${lastName},

Vaše platba byla úspěšně přijata a zpracována!

DETAILY PLATBY:
Číslo objednávky: #${orderNumber}
Zaplacená částka: ${amount.toFixed(2)} ${currency}
Datum platby: ${paymentDate.toLocaleDateString('cs-CZ')} ${paymentDate.toLocaleTimeString('cs-CZ', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', year: 'numeric' })}

CO BUDE DÁL?
Vaše objednávka je nyní potvrzena a bude brzy zpracována.

ZOBRAZIT OBJEDNÁVKU:
${trackingUrl || `${process.env.NEXT_PUBLIC_BASE_URL || 'https://vystrikejto.cz'}/orders`}

---


Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: `Platba potvrzena #${orderNumber} - VYSTŘÍKEJ TO`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Zrušení platby
 */
interface PaymentCancellationParams {
  customerEmail: string;
  firstName: string;
  lastName: string,
  orderNumber: string;
  amount: number;
  currency: string;
  trackingUrl?: string;
}

export function paymentCancellationTemplate(
  params: PaymentCancellationParams
): EmailTemplate {
  const { customerEmail, firstName, lastName, orderNumber, amount, currency, trackingUrl } = params;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Platba zrušena - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">

              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>

              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>

              <div style="font-size:24px; font-weight:bold; margin:0 0 10px; color:#eb1515;">Platba zrušena!</div>
              <div style="font-size:16px; margin:0 0 20px; color:#cccccc;">Vaše objednávka nebyla zaplacena.</div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p>Dobrý den, <strong>${firstName} ${lastName}</strong>,</p>

                <p>Vaše platba pro objednávku <strong>#${orderNumber}</strong> byla zrušena nebo neproběhla úspěšně.</p>
              </div>

              <div style="background:#2a2a2a; border:1px solid #ffc107; padding:20px; border-radius:8px; margin:25px 0; max-width:500px; margin-left:auto; margin-right:auto;">
                <table role="presentation" width="100%" style="color:#dddddd; font-size:14px;">
                  <tr>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a;">Číslo objednávky:</td>
                    <td style="padding:8px 0; border-bottom:1px solid #3a3a3a; text-align:right; font-weight:bold; color:#f4c542;">#${orderNumber}</td>
                  </tr>
                  <tr>
                    <td style="padding:8px 0;">Částka:</td>
                    <td style="padding:8px 0; text-align:right; font-weight:bold;">${amount.toFixed(2)} ${currency}</td>
                  </tr>
                </table>
              </div>

              <div style="font-size:14px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p><strong>Možné důvody:</strong></p>
                <ul style="margin:10px 0; padding-left:20px;">
                  <li>Vypršel čas pro dokončení platby.</li>
                  <li>Platba byla zamítnuta Vaší bankou.</li>
                  <li>Platbu jste zrušili sami.</li>
                </ul>
              </div>
              <div style="background:#2a2a2a; padding:15px; border-radius:6px; margin:20px 0; max-width:500px; margin-left:auto; margin-right:auto;">
                <p style="margin:0 0 10px; color:#f4c542; font-weight:bold;">Potřebujete pomoc?</p>
                <p style="margin:0; color:#dddddd; font-size:14px;">Pokud máte jakékoliv otázky, kontaktujte nás. Jsme tu pro vás!</p>
              </div>
              ${trackingUrl ? `
              <a href="${trackingUrl}" style="color:#f4c542; font-weight:bold; text-decoration:underline;">Zobrazit stav objednávky</a>
              ` : ''}

            </td>
          </tr>
        </table>
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>

      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

Platba zrušena!
Vaše objednávka nebyla zaplacena

Dobrý den, ${firstName},

Vaše platba pro objednávku #${orderNumber} byla zrušena nebo neproběhla úspěšně.

DETAILY OBJEDNÁVKY:
Číslo objednávky: #${orderNumber}
Částka: ${amount.toFixed(2)} ${currency}

MOŽNÉ DŮVODY:
• Vypršel čas pro dokončení platby
• Platba byla zamítnuta vaší bankou
• Jste si přáli platbu zrušit

POTŘEBUJETE POMOC?
Pokud máte jakékoliv otázky nebo problémy, kontaktujte nás. Jsme tu pro vás!

${trackingUrl ? `STAV OBJEDNÁVKY:
${trackingUrl}
` : ''}

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: `Platba zrušena #${orderNumber} - VYSTŘÍKEJ TO`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * EMAIL TEMPLATE: Zaslání dárkového poukazu
 */
interface VoucherDeliveryParams {
  customerEmail: string;
  firstName: string;
  lastName: string;
  orderNumber: string;
}

export function voucherDeliveryEmailTemplate(
  params: VoucherDeliveryParams
): EmailTemplate {
  const { customerEmail, firstName, lastName, orderNumber } = params;

  const html = `
<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="UTF-8">
  <title>Váš dárkový poukaz - VYSTŘÍKEJ TO</title>
</head>
<body style="margin:0; padding:0; background:#f0f0f0; font-family:Arial, sans-serif;">
  <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#f0f0f0">
    <tr>
      <td align="center" style="padding:30px 15px;">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="background:#1c1c1c; border-radius:20px; overflow:hidden;">
          <tr>
            <td style="padding:40px 30px 30px 30px; text-align:center; color:#ffffff;">
              <div style="font-size:28px; font-weight:bold; color:#f4c542; margin:0; line-height:1.2;">VYSTŘÍKEJ TO</div>
              <div style="font-size:14px; color:#cccccc; margin:0 0 20px;">CELÉ PARFÉMY</div>
              <div style="height:1px; background:#f4c542; width:100%; margin:20px 0;"></div>
              <div style="font-size:24px; font-weight:bold; margin:0 0 10px; color:#f4c542;">Váš dárkový poukaz je tady! 🎁</div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:20px auto; color:#dddddd;">
                <p>Dobrý den, <strong>${firstName} ${lastName}</strong>,</p>
                <p>Děkujeme za nákup na <strong>VYSTŘÍKEJ TO</strong>. V příloze tohoto emailu naleznete Váš dárkový poukaz v PDF formátu, který si můžete vytisknout nebo přeposlat jako dárek.</p>
                <p>Poukaz můžete uplatnit na celý náš sortiment zadáním kódu v nákupním košíku.</p>
              </div>

              <div style="background:#2a2a2a; border:1px solid #f4c542; padding:20px; border-radius:8px; margin:25px 0; max-width:500px; margin-left:auto; margin-right:auto;">
                <p style="margin:0; color:#dddddd; font-size:14px;">Číslo Vaší objednávky: <strong style="color:#f4c542;">#${orderNumber}</strong></p>
              </div>

              <div style="font-size:15px; line-height:1.6; text-align:left; max-width:500px; margin:0 auto; color:#dddddd;">
                <p style="text-align:center;">Věříme, že poukaz udělá radost!</p>
              </div>
            </td>
          </tr>
        </table>
        <table role="presentation" cellpadding="0" cellspacing="0" border="0" width="600"
               style="margin-top:20px; font-size:12px; color:#999999;">
          <tr>
            <td align="center" style="padding:10px;">
              Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na
              <a href="mailto:${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}" style="color:#f4c542; text-decoration:none;">${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}</a><br>
              © 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>
  `;

  const text = `
VYSTŘÍKEJ TO
CELÉ PARFÉMY

🎁 Váš dárkový poukaz je tady!

Dobrý den, ${firstName} ${lastName},

Děkujeme za nákup na VYSTŘÍKEJ TO. V příloze tohoto emailu naleznete Váš dárkový poukaz v PDF formátu, který si můžete vytisknout nebo přeposlat jako dárek.

Číslo objednávky: #${orderNumber}

Poukaz můžete uplatnit na celý náš sortiment zadáním kódu v nákupním košíku.

Věříme, že poukaz udělá radost!

---

Pokud máte jakékoliv otázky, neváhejte nás kontaktovat na: ${process.env.CONTACT_EMAIL || 'info@vystrikejto.cz'}

© 2026 VYSTŘÍKEJ TO – Všechna práva vyhrazena
  `;

  return {
    to: customerEmail,
    subject: `Váš dárkový poukaz k objednávce #${orderNumber} 🎁`,
    html: html.trim(),
    text: text.trim(),
  };
}

/**
 * INVOICE HTML TEMPLATE - Pro PDF generování
 */
export function generateInvoiceHtml(data: InvoiceData): string {
  const companyInfo = {
    name: 'Rozalie Vicherková',
    street: process.env.COMPANY_STREET,
    city: process.env.COMPANY_CITY,
    ic: process.env.COMPANY_IC,
    email: process.env.CONTACT_EMAIL,
  };

  const itemsHtml = data.items
    .map(
      (item) =>
        `<tr>
          <td style="padding: 12px; border-bottom: 1px solid #3a2f14;">${item.name}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a2f14; text-align: center;">${item.quantity}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a2f14; text-align: right;">${item.unitPrice.toFixed(2)} ${data.currency}</td>
          <td style="padding: 12px; border-bottom: 1px solid #3a2f14; text-align: right;">${item.lineTotal.toFixed(2)} ${data.currency}</td>
        </tr>`
    )
    .join('');

  const subtotal = data.total - data.shippingPrice + (data.discountAmount || 0);
  const hasOnlyVouchers = data.items.every(item => item.productType === 'voucher');
  const showShipping = !hasOnlyVouchers || data.shippingPrice > 0;

  return `<!DOCTYPE html>
<html lang="cs">
<head>
    <meta charset="UTF-8">
    <title>Faktura - ${data.orderNumber}</title>
    <style>
        body {
            margin: 0;
            padding: 40px;
            font-family: "Segoe UI", Arial, sans-serif;
            background: #0b0b0b;
            color: #e6c87a;
        }

        .invoice {
            position: relative;
            max-width: 900px;
            margin: auto;
            background: #111;
            padding: 50px;
            border: 1px solid #3a2f14;
            box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
            overflow: hidden;
        }

        /* Watermark */
        .watermark {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) rotate(-30deg);
            font-size: 120px;
            font-weight: 800;
            color: rgba(230, 200, 122, 0.06);
            white-space: nowrap;
            pointer-events: none;
            user-select: none;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 40px;
        }

        .logo img {
            max-height: 200px;
        }

        .invoice-title {
            text-align: right;
        }

        .invoice-title h1 {
            margin: 0;
            font-size: 32px;
            letter-spacing: 2px;
        }

        .section {
            margin-bottom: 30px;
        }

        .section h2 {
            font-size: 14px;
            letter-spacing: 1px;
            border-bottom: 1px solid #3a2f14;
            padding-bottom: 6px;
            margin-bottom: 10px;
            color: #d4b15f;
        }

        .addresses {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
        }

        .address p {
            margin: 4px 0;
            font-size: 14px;
            color: #e0e0e0;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        table th,
        table td {
            padding: 12px;
            font-size: 14px;
        }

        table th {
            text-align: left;
            border-bottom: 1px solid #3a2f14;
            color: #d4b15f;
        }

        table td {
            border-bottom: 1px solid rgba(255, 255, 255, 0.05);
            color: #e0e0e0;
        }

        .total {
            margin-top: 30px;
            text-align: right;
            font-size: 18px;
            color: #e6c87a;
        }


        @media print {
            body {
                background: #ffffff;
                color: #000000;
                padding: 0;
            }

            .invoice {
                background: #ffffff;
                color: #000000;
                box-shadow: none;
                border: 1px solid #000;
            }
            .address p {
            margin: 4px 0;
            font-size: 14px;
            color: #000000;
            }
            .section h2 {
                color: #000;
                border-bottom: 1px solid #000;
            }

            table th {
                color: #000;
                border-bottom: 1px solid #000;
            }

            table td {
                color: #000;
            }

            .total {
                color: #000;
            }


            .watermark {
                color: rgba(0, 0, 0, 0.08);
            }
        }
    </style>
</head>
<body>
    <div class="invoice">
        <div class="watermark">NEPLAŤTE</div>
        <div class="header">
            <div class="logo"><img src="https://vystrikejto.cz/images/logo.png" alt="Logo"> </div>
            <div class="invoice-title">
                <h1>FAKTURA – ${data.orderNumber}</h1>
                <p>Objednávka č.: <strong>${data.orderNumber}</strong></p>
                <p>Datum vystavení: <strong>${data.createdAt.toLocaleDateString('cs-CZ')}</strong></p>
                <p>Datum uskut. zdan. plnění: <strong>${data.createdAt.toLocaleDateString('cs-CZ')}</strong></p>
            </div>
        </div>

        <div class="section addresses">
            <div class="address">
                <h2>DODAVATEL</h2>
                <p>${companyInfo.name}</p>
                <p>${companyInfo.street}</p>
                <p>${companyInfo.city}</p>
                <p>${companyInfo.ic}</p>
                <p>Nejsme plátci DPH</p>
            </div>
            <div class="address">
                <h2>ODBĚRATEL (FAKTURAČNÍ ADRESA)</h2>
                <p>${data.customerName}</p>
                ${data.billingAddress ? `
                <p>${data.billingAddress.street}</p>
                <p>${data.billingAddress.zip} ${data.billingAddress.city}</p>
                ` : ''}
                ${data.customerEmail ? `<p>${data.customerEmail}</p>` : ''}
                ${data.customerPhone ? `<p>${data.customerPhone}</p>` : ''}
            </div>
        </div>
        <div class="section">
            <h2>POLOŽKY</h2>
            <table>
                <thead>
                    <tr>
                        <th>Popis</th>
                        <th>Množství</th>
                        <th>Cena / ks</th>
                        <th>Celkem</th>
                    </tr>
                </thead>
                <tbody>
                    ${itemsHtml}
                </tbody>
            </table>
        </div>

        <div class="summary">
            <div class="summary-row">
                <span class="label">Mezisoučet:</span>
                <span class="value">${subtotal.toFixed(2)} ${data.currency}</span>
            </div>
            ${data.discountAmount && data.discountAmount > 0 ? `
            <div class="summary-row">
                <span class="label">Sleva${data.voucherCode ? ` (${data.voucherCode})` : ''}:</span>
                <span class="value">-${data.discountAmount.toFixed(2)} ${data.currency}</span>
            </div>
            ` : ''}
            ${showShipping ? `
            <div class="summary-row">
                <span class="label">Doprava (${data.shippingMethod}):</span>
                <span class="value">${data.shippingPrice === 0 ? 'Zdarma' : data.shippingPrice.toFixed(2) + ' ' + data.currency}</span>
            </div>
            ` : ''}
            <div class="summary-row total">
                <span class="label">CELKEM K ÚHRADĚ:</span>
                <span class="value">${data.total.toFixed(2)} ${data.currency}</span>
            </div>
        </div>
    </div>
</body>
</html>`;
}

/**
 * VOUCHER HTML TEMPLATE - Pro PDF generování
 */
export function generateVoucherHtml(data: VoucherData): string {

  return `<!DOCTYPE html>
<html lang="cs">
<head>
    <meta charset="UTF-8">
    <title>Luxury Voucher</title>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;800&display=swap');

        body {
            margin: 0;
            padding: 40px;
            font-family: "Inter", "Segoe UI", Arial, sans-serif;
            background: #0b0b0b;
            color: #e6c87a;
        }

        .voucher {
            position: relative;
            max-width: 820px;
            margin: auto;
            background: linear-gradient(180deg, #121212, #0e0e0e);
            padding: 70px;
            border: 1px solid #3a2f14;
            overflow: hidden;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
            z-index: 2;
        }

        .logo img {
            max-height: 180px;
        }

        .voucher-title {
            text-align: right;
        }

        .voucher-title h1 {
            margin: 0;
            font-size: 38px;
            letter-spacing: 4px;
            font-weight: 700;
        }

        .voucher-title p {
            margin: 6px 0;
            font-size: 13px;
            color: #cfcfcf;
        }

        .content {
            position: relative;
            z-index: 2;
            text-align: center;
            margin: 70px 0 60px;
        }

        .content h2 {
            font-size: 50px;
            letter-spacing: 4px;
            font-weight: 800;
            color: #d4b15f;
        }

        .value {
            font-size: 56px;
            font-weight: 700;
            letter-spacing: 2px;
            margin-bottom: 15px;
        }

        .content p {
            font-size: 15px;
            color: #cfcfcf;
        }

        .code {
            margin: 50px auto 0;
            padding: 18px 40px;
            border: 1px dashed #3a2f14;
            display: inline-block;
            font-size: 20px;
            letter-spacing: 6px;
            color: #e6c87a;
            background: rgba(255, 255, 255, 0.02);
            text-transform: uppercase;
        }

        .details {
            margin-top: 60px;
            padding-top: 30px;
            border-top: 1px solid rgba(230, 200, 122, 0.2);
            font-size: 13px;
            color: #bdbdbd;
            line-height: 1.7;
            position: relative;
            z-index: 2;
            text-align: center;
        }

        /* PRINT / PDF */
        @media print {
            body {
                background: #fff;
                color: #000;
                padding: 0;
            }

            .voucher {
                background: #fff;
                border: 1px solid #000;
            }

            .voucher-title p,
            .details,
            .content p {
                color: #000;
            }

            .code {
                border-color: #000;
                color: #000;
            }
        }
    </style>
</head>
<body>
    <div class="voucher">
        <div class="header">
            <div class="logo">
                <img src="https://vystrikejto.cz/images/logo.png" alt="Logo">
            </div>
            <div class="voucher-title">
                <h1>DÁRKOVÝ POUKAZ</h1>
                <p>Datum vystavení: <strong>${data.issueDate.toLocaleDateString('cs-CZ')}</strong></p>
            </div>
        </div>

        <div class="content">
            <h2>V hodnotě</h2>
            <div class="value">${data.value.toLocaleString('cs-CZ')} ${data.currency}</div>
            <p>Lze uplatnit na celý sortiment</p>

            <div class="code">
                ${data.code}
            </div>
        </div>

        <div class="details">
            Voucher je nepřenosný a nelze jej směnit za hotovost.<br>
            Platnost voucheru je do <strong>${data.expiryDate.toLocaleDateString('cs-CZ')}</strong>.<br>
            Voucher lze uplatnit pouze jednorázově.
        </div>
    </div>
</body>
</html>`;
}
