import * as React from 'npm:react@18.3.1'
import { Body, Button, Container, Head, Heading, Html, Preview, Section, Text } from 'npm:@react-email/components@0.0.22'
import type { TemplateEntry } from './registry.ts'

interface VendorInsuranceRequestProps {
  vendorName?: string
  requesterName?: string
  link?: string
  expiresAt?: string
}

const SITE_NAME = 'Avria Community Management'

const VendorInsuranceRequestEmail = ({ vendorName, requesterName, link, expiresAt }: VendorInsuranceRequestProps) => (
  <Html lang="en" dir="ltr">
    <Head />
    <Preview>Insurance information requested for {vendorName || 'your account'}</Preview>
    <Body style={main}>
      <Container style={container}>
        <Section style={brandBar} />
        <Heading style={h1}>Insurance information requested</Heading>
        <Text style={text}>
          Hello {vendorName || 'Vendor'},
        </Text>
        <Text style={text}>
          {requesterName || SITE_NAME} is requesting your current certificate of insurance information.
          Please use the secure link below to submit your insurance carrier, policy number, and expiration date.
          You can also upload a copy of your certificate.
        </Text>
        {link && <Button href={link} style={button}>Submit insurance information</Button>}
        {expiresAt && (
          <Text style={meta}>This link expires on {expiresAt}.</Text>
        )}
        <Text style={footer}>This request was sent by {SITE_NAME}. If you weren't expecting it, you can ignore this email.</Text>
      </Container>
    </Body>
  </Html>
)

export const template = {
  component: VendorInsuranceRequestEmail,
  subject: (data: Record<string, any>) =>
    `Action needed: Submit insurance information for ${data.vendorName || 'your account'}`,
  displayName: 'Vendor insurance request',
  previewData: {
    vendorName: 'Acme Plumbing',
    requesterName: 'Avria Community Management',
    link: 'https://avria.cloud/vendor-insurance/sample-token',
    expiresAt: 'June 1, 2026',
  },
} satisfies TemplateEntry

const main = { backgroundColor: '#ffffff', fontFamily: 'Inter, Arial, sans-serif' }
const container = { maxWidth: '600px', margin: '0 auto', padding: '28px 24px' }
const brandBar = { height: '5px', backgroundColor: '#2563eb', borderRadius: '6px', marginBottom: '24px' }
const h1 = { color: '#111827', fontSize: '24px', lineHeight: '32px', margin: '0 0 14px', fontWeight: '700' }
const text = { color: '#374151', fontSize: '15px', lineHeight: '24px', margin: '0 0 18px' }
const meta = { color: '#6b7280', fontSize: '13px', lineHeight: '20px', margin: '14px 0 0' }
const button = { backgroundColor: '#2563eb', color: '#ffffff', borderRadius: '6px', fontSize: '14px', fontWeight: '600', textDecoration: 'none', padding: '12px 18px' }
const footer = { color: '#6b7280', fontSize: '12px', lineHeight: '18px', margin: '28px 0 0' }
