import {
  Body,
  Container,
  Head,
  Heading,
  Hr,
  Html,
  Preview,
  Section,
  Text,
} from "@react-email/components";
import * as React from "react";

const BG = "#0f1418";
const FG = "#e8eef2";
const MUTED = "#9aa6b0";
const PRIMARY = "#1ECBB8";
const ACCENT = "#FBA13B";
const BORDER = "#1f2a32";

const main: React.CSSProperties = {
  backgroundColor: BG,
  fontFamily:
    "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, sans-serif",
  margin: 0,
  padding: "32px 0",
};

const container: React.CSSProperties = {
  margin: "0 auto",
  width: "100%",
  maxWidth: 560,
  backgroundColor: "#141a20",
  border: `1px solid ${BORDER}`,
  borderRadius: 12,
  padding: 32,
};

const brand: React.CSSProperties = {
  fontSize: 22,
  fontWeight: 700,
  letterSpacing: "-0.5px",
  background: `linear-gradient(90deg, ${PRIMARY}, ${ACCENT})`,
  WebkitBackgroundClip: "text",
  WebkitTextFillColor: "transparent",
  margin: "0 0 4px 0",
};

const tagline: React.CSSProperties = {
  fontSize: 11,
  letterSpacing: "0.2em",
  textTransform: "uppercase",
  color: MUTED,
  margin: "0 0 28px 0",
};

const heading: React.CSSProperties = {
  fontSize: 24,
  color: FG,
  margin: "0 0 16px 0",
  lineHeight: "1.3",
};

const paragraph: React.CSSProperties = {
  fontSize: 15,
  color: FG,
  lineHeight: "1.6",
  margin: "0 0 16px 0",
};

const buttonStyle: React.CSSProperties = {
  display: "inline-block",
  backgroundColor: PRIMARY,
  color: "#001a16",
  fontWeight: 600,
  fontSize: 15,
  padding: "12px 24px",
  borderRadius: 8,
  textDecoration: "none",
  margin: "8px 0 24px 0",
};

const linkFallback: React.CSSProperties = {
  fontSize: 13,
  color: MUTED,
  wordBreak: "break-all",
  margin: "8px 0",
};

const footer: React.CSSProperties = {
  fontSize: 12,
  color: MUTED,
  textAlign: "center" as const,
  margin: "24px 0 0 0",
};

const divider: React.CSSProperties = {
  borderColor: BORDER,
  margin: "24px 0",
};

interface EmailLayoutProps {
  preview: string;
  children: React.ReactNode;
}

export function EmailLayout({ preview, children }: EmailLayoutProps) {
  return (
    <Html>
      <Head />
      <Preview>{preview}</Preview>
      <Body style={main}>
        <Container style={container}>
          <Heading style={brand} as="h1">
            Trovo
          </Heading>
          <Text style={tagline}>Discover. Plan. Go.</Text>
          {children}
          <Hr style={divider} />
          <Text style={footer}>
            Trovo · AI-powered travel planning &amp; booking
            <br />
            <span style={{ color: "#5a6671" }}>
              You received this email because you signed up at trovo.app.
            </span>
          </Text>
        </Container>
      </Body>
    </Html>
  );
}

export { paragraph, heading, buttonStyle, linkFallback, divider };
export const Section_ = Section;
