import * as React from "react"
import { Button, Heading, Hr, Section, Text } from "@react-email/components"

import { RavenEmailLayout } from "./_components/layout"
import { TicketCard, type TicketCardProps } from "./_components/ticket-card"
import { EMAIL_COLORS } from "./_components/tokens"

export type TicketAssignedEmailProps = TicketCardProps & {
  ticketUrl: string
  assigneeName: string
}

export default function TicketAssignedEmail(props: TicketAssignedEmailProps) {
  const { ticketUrl, assigneeName, ...ticketProps } = props

  return (
    <RavenEmailLayout title="Chamado atribuido" preview={`Chamado #${ticketProps.ticketNumber} foi atribuido a ${assigneeName}`}>
      <Section style={{ textAlign: "center", margin: "24px 0" }}>
        <div
          style={{
            display: "inline-block",
            width: "64px",
            height: "64px",
            backgroundColor: "#e0f2fe",
            borderRadius: "50%",
            lineHeight: "64px",
            fontSize: "28px",
            border: "1px solid #0ea5e9",
          }}
        >
          &#128100;
        </div>
      </Section>

      <Heading style={{ margin: "0 0 12px 0", fontSize: "26px", fontWeight: 700, color: EMAIL_COLORS.textPrimary, textAlign: "center" }}>
        Chamado atribuido
      </Heading>

      <Text style={{ margin: "0 0 24px 0", fontSize: "15px", lineHeight: "1.7", color: EMAIL_COLORS.textSecondary, textAlign: "center" }}>
        O chamado foi atribuido a <strong>{assigneeName}</strong>.
      </Text>

      <TicketCard {...ticketProps} />

      <Section style={{ textAlign: "center", margin: "32px 0" }}>
        <Button
          href={ticketUrl}
          style={{
            display: "inline-block",
            backgroundColor: EMAIL_COLORS.primary,
            color: EMAIL_COLORS.primaryForeground,
            textDecoration: "none",
            borderRadius: "12px",
            padding: "14px 24px",
            fontWeight: 800,
            fontSize: "14px",
            border: `1px solid ${EMAIL_COLORS.primaryDark}`,
          }}
        >
          Ver chamado
        </Button>
      </Section>

      <Hr style={{ borderColor: EMAIL_COLORS.border, margin: "24px 0" }} />

      <Text style={{ margin: 0, fontSize: "12px", color: EMAIL_COLORS.textMuted, textAlign: "center" }}>
        Voce recebera atualizacoes por e-mail quando houver novidades.
      </Text>
    </RavenEmailLayout>
  )
}

TicketAssignedEmail.PreviewProps = {
  ticketNumber: "41025",
  ticketTitle: "Computador nao liga apos atualizacao",
  status: "AWAITING_ATTENDANCE",
  priority: "HIGH",
  category: "Hardware",
  subcategory: "Desktop",
  ticketUrl: "https://raven.rever.com.br/tickets/abc123",
  assigneeName: "Weslei Magalhaes",
} satisfies TicketAssignedEmailProps
