/**
 * DealApproved.tsx - FDS §9.4 Deal Approved Email
 *
 * Sent to vendor when admin approves a deal.
 */

import {
  Html,
  Head,
  Body,
  Container,
  Section,
  Text,
  Link,
  Preview,
} from '@/server/email/primitives.js';
import { dirForLocale, type Locale } from '@/lib/i18n/index.js';
import { fonts, spacing, tokens } from '@/server/email/tokens/index.js';

export interface DealApprovedProps {
  dealTitle: string;
  dealUrl: string;
  /** Vendor's display name - used for personalisation in future template revisions. */
  vendorName: string;
  locale?: Locale;
}

const copy = {
  he: {
    preview: (title: string) => `העסקה "${title}" אושרה ועלייה לאוויר`,
    heading: 'העסקה אושרה! 🎉',
    body: (title: string) => `העסקה "${title}" עלתה לאוויר ומוצגת כעת ללקוחות.`,
    cta: 'צפה בעסקה',
  },
  en: {
    preview: (title: string) => `Your deal "${title}" is now live`,
    heading: 'Your deal is live! 🎉',
    body: (title: string) => `"${title}" is now live and visible to customers.`,
    cta: 'View deal',
  },
} as const;

export default function DealApproved({
  dealTitle,
  dealUrl,
  vendorName: _vendorName,
  locale = 'he',
}: DealApprovedProps) {
  const t = copy[locale];
  const dir = dirForLocale(locale);
  const fontFamily = locale === 'he' ? fonts.he : fonts.en;

  return (
    <Html lang={locale} dir={dir}>
      <Head />
      <Preview>{t.preview(dealTitle)}</Preview>
      <Body style={{ backgroundColor: tokens.neutral100, fontFamily }}>
        <Container style={{ padding: spacing.padPage }}>
          <div
            style={{
              maxWidth: spacing.cardMaxNarrow,
              margin: '0 auto',
              backgroundColor: tokens.surfaceBase,
              borderRadius: '8px',
              border: `1px solid ${tokens.borderDefault}`,
              overflow: 'hidden',
            }}
          >
            <Section
              style={{
                backgroundColor: tokens.success700,
                padding: spacing.padHeaderLg,
                textAlign: locale === 'he' ? 'right' : 'left',
              }}
            >
              <Text
                style={{
                  fontSize: spacing.px20,
                  fontWeight: 700,
                  color: tokens.brandOnPrimary,
                  fontFamily,
                  margin: '0',
                }}
              >
                {t.heading}
              </Text>
            </Section>

            <Section
              style={{
                padding: spacing.padSectionLg,
                direction: dir,
                textAlign: locale === 'he' ? 'right' : 'left',
              }}
            >
              <Text
                style={{
                  fontSize: spacing.px16,
                  color: tokens.textSecondary,
                  fontFamily,
                  margin: spacing.marginBottom24,
                  lineHeight: '1.6',
                }}
              >
                {t.body(dealTitle)}
              </Text>

              <Link
                href={dealUrl}
                style={{
                  backgroundColor: tokens.brandPrimary700,
                  color: tokens.brandOnPrimary,
                  padding: spacing.padButton,
                  borderRadius: '6px',
                  fontFamily,
                  fontSize: spacing.px15,
                  fontWeight: 600,
                  textDecoration: 'none',
                  display: 'inline-block',
                }}
              >
                {t.cta}
              </Link>
            </Section>
          </div>
        </Container>
      </Body>
    </Html>
  );
}
