import {
  Heading,
  Section,
  Text,
} from '@react-email/components';
import { EmailLayout } from './components/EmailLayout';
import { Card } from './components/Card';
import { Button } from './components/Button';
import { theme } from './theme';

interface ReferralSignupEmailProps {
  userName?: string;
  referredUserName?: string;
  referralCode?: string;
}

export const ReferralSignupEmail = ({
  userName = 'Kirubel',
  referredUserName = 'Alex Martinez',
  referralCode = 'AMB-KIRU-2024',
}: ReferralSignupEmailProps) => {
  return (
    <EmailLayout
      preview={`Someone signed up using your referral code!`}
    >
      <Section>
        <Heading style={heading}>
          New Referral Signup! 👋
        </Heading>
        <Text style={text}>
          Hi {userName},
        </Text>
        <Text style={text}>
          Great news! <strong>{referredUserName}</strong> has signed up for AmbaPay using your referral code <strong>{referralCode}</strong>.
        </Text>
        <Card>
          <Section style={detailRow}>
            <Text style={detailLabel}>Referred User:</Text>
            <Text style={detailValue}>{referredUserName}</Text>
          </Section>
          <Section style={detailRow}>
            <Text style={detailLabel}>Referral Code Used:</Text>
            <Text style={detailValue}>{referralCode}</Text>
          </Section>
          <Section style={statusRow}>
            <Text style={statusLabel}>Status:</Text>
            <Text style={statusValue}>Account Created ✓</Text>
          </Section>
        </Card>
        <Section style={infoBox}>
          <Text style={infoTitle}>Next Steps</Text>
          <Text style={infoText}>
            You'll earn referral points once <strong>{referredUserName}</strong> completes their first transaction. Keep an eye out for your reward notification!
          </Text>
        </Section>
        <Text style={text}>
          Keep sharing your referral code to earn more points and help grow the AmbaPay community!
        </Text>
        <Section style={buttonSection}>
          <Button href="https://amba.app/referrals">
            View Referral Dashboard
          </Button>
        </Section>
        <Text style={text}>
          Best regards,<br />
          The AmbaPay Team
        </Text>
      </Section>
    </EmailLayout>
  );
};

const heading = {
  color: theme.colors.primary,
  fontSize: '28px',
  fontWeight: '700',
  margin: '0 0 24px',
};

const text = {
  color: theme.colors.textDark,
  fontSize: '16px',
  lineHeight: '24px',
  margin: '0 0 16px',
};

const detailRow = {
  display: 'flex',
  justifyContent: 'space-between',
  marginBottom: '12px',
  paddingBottom: '12px',
  borderBottom: `1px solid ${theme.colors.border}`,
};

const detailLabel = {
  color: theme.colors.text,
  fontSize: '14px',
  fontWeight: '600',
  margin: '0',
  flex: '1',
};

const detailValue = {
  color: theme.colors.textDark,
  fontSize: '14px',
  margin: '0',
  textAlign: 'right' as const,
  flex: '1',
};

const statusRow = {
  display: 'flex',
  justifyContent: 'space-between',
  marginTop: '12px',
  paddingTop: '12px',
  borderTop: `2px solid ${theme.colors.accent}`,
};

const statusLabel = {
  color: theme.colors.primary,
  fontSize: '14px',
  fontWeight: '600',
  margin: '0',
  flex: '1',
};

const statusValue = {
  color: theme.colors.primary,
  fontSize: '14px',
  fontWeight: '600',
  margin: '0',
  textAlign: 'right' as const,
  flex: '1',
};

const infoBox = {
  backgroundColor: theme.colors.accentLightest,
  borderRadius: '8px',
  padding: '16px',
  margin: '24px 0',
  borderLeft: `4px solid ${theme.colors.accent}`,
};

const infoTitle = {
  color: theme.colors.primary,
  fontSize: '16px',
  fontWeight: '600',
  margin: '0 0 8px',
};

const infoText = {
  color: theme.colors.textDark,
  fontSize: '14px',
  lineHeight: '22px',
  margin: '0',
};

const buttonSection = {
  textAlign: 'center' as const,
  margin: '32px 0',
};

ReferralSignupEmail.PreviewProps = {
  userName: 'Kirubel',
  referredUserName: 'Alex Martinez',
  referralCode: 'AMB-KIRU-2024',
} as ReferralSignupEmailProps;

export default ReferralSignupEmail;

