/**
 * VendorLowRedemption.tsx — sent when a vendor's deal has low redemptions.
 */

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 VendorLowRedemptionProps {
  vendorName?: string;
  dealTitle: string;
  redemptionCount: number;
  tipUrl: string;
  unsubscribeUrl: string;
  locale?: Locale;
}

const copy = {
  he: {
    preview: (dealTitle: string) => `הדיל "${dealTitle}" — טיפים לשיפור הביצועים`,
    heading: (n?: string) => (n ? `שלום, ${n}!` : 'שלום!'),
    body: (dealTitle: string, redemptionCount: number) =>
      `הדיל "${dealTitle}" קיבל ${redemptionCount} מימושים בלבד. הנה כמה טיפים לשיפור הביצועים.`,
    cta: 'לטיפים לשיפור הדיל',
    unsub: 'הסרה מרשימת התפוצה',
  },
  en: {
    preview: (dealTitle: string) => `Your deal "${dealTitle}" — tips to improve performance`,
    heading: (n?: string) => (n ? `Hi ${n},` : 'Hi there,'),
    body: (dealTitle: string, redemptionCount: number) =>
      `Your deal "${dealTitle}" has only ${redemptionCount} redemptions. Here are some tips to improve performance.`,
    cta: 'See improvement tips',
    unsub: 'Unsubscribe',
  },
} as const;

export function VendorLowRedemption({
  vendorName,
  dealTitle,
  redemptionCount,
  tipUrl,
  unsubscribeUrl,
  locale = 'he',
}: VendorLowRedemptionProps) {
  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(dealTitle)}</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(dealTitle, redemptionCount)}
            </Text>
          </Section>
          <Section style={{ textAlign: 'center', marginTop: spacing.px24 }}>
            <Link
              href={tipUrl}
              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 VendorLowRedemption;
