/**
 * VendorWelcome.tsx — sent after vendor account creation / onboarding.
 */

import {
  Html,
  Head,
  Body,
  Container,
  Section,
  Text,
  Link,
  Hr,
  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 VendorWelcomeProps {
  vendorName?: string;
  dashboardUrl: string;
  unsubscribeUrl: string;
  locale?: Locale;
}

const copy = {
  he: {
    preview: 'ברוכ.ה הבא.ה כעסק שותף במולטידיל!',
    heading: (n?: string) => (n ? `ברוכ.ה הבא.ה, ${n}!` : 'ברוכ.ה הבא.ה!'),
    body: 'שמחים שהצטרפת! הלקוחות כבר מחפשים עסקאות בסביבתך. צור את הדיל הראשון שלך עכשיו ותתחיל להרוויח.',
    cta: 'לדשבורד שלי',
    unsub: 'הסרה מרשימת התפוצה',
  },
  en: {
    preview: "Welcome to Multideal — let's launch your first deal!",
    heading: (n?: string) => (n ? `Welcome, ${n}!` : 'Welcome!'),
    body: 'Great to have you on board! Customers are already searching for deals near you. Create your first deal and start earning.',
    cta: 'Go to my dashboard',
    unsub: 'Unsubscribe',
  },
} as const;

export function VendorWelcome({
  vendorName,
  dashboardUrl,
  unsubscribeUrl,
  locale = 'he',
}: VendorWelcomeProps) {
  const c = copy[locale] ?? copy.he;
  const dir = dirForLocale(locale);
  const fontFamily = locale === 'he' ? fonts.he : fonts.en;

  return (
    <Html lang={locale} dir={dir}>
      <Head />
      <Preview>{c.preview}</Preview>
      <Body
        style={{
          backgroundColor: tokens.neutral50,
          fontFamily: fontFamily,
          margin: 0,
          padding: spacing.marginBlock32,
        }}
      >
        <Container
          style={{
            maxWidth: spacing.cardMaxWide,
            backgroundColor: tokens.neutral0,
            borderRadius: '8px',
            padding: spacing.padSectionLg,
          }}
        >
          <Section>
            <Text
              style={{
                fontSize: spacing.px24,
                fontWeight: 700,
                color: tokens.textPrimary,
                marginBottom: '8px',
                fontFamily,
              }}
            >
              {c.heading(vendorName)}
            </Text>
            <Text
              style={{
                fontSize: spacing.px16,
                color: tokens.textSecondary,
                lineHeight: '1.6',
                fontFamily,
              }}
            >
              {c.body}
            </Text>
          </Section>
          <Section style={{ textAlign: 'center', marginTop: spacing.px24 }}>
            <Link
              href={dashboardUrl}
              style={{
                display: 'inline-block',
                backgroundColor: tokens.brandPrimary600,
                color: tokens.brandOnPrimary,
                padding: spacing.padButtonSm,
                borderRadius: '6px',
                textDecoration: 'none',
                fontWeight: 600,
                fontFamily,
                fontSize: spacing.px15,
              }}
            >
              {c.cta}
            </Link>
          </Section>
          <Hr style={{ borderColor: tokens.borderDefault, margin: spacing.marginSection }} />
          <Text
            style={{
              fontSize: spacing.px12,
              color: tokens.textMuted,
              textAlign: 'center',
              fontFamily,
            }}
          >
            <Link href={unsubscribeUrl} style={{ color: tokens.textMuted }}>
              {c.unsub}
            </Link>
          </Text>
        </Container>
      </Body>
    </Html>
  );
}

export default VendorWelcome;
