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

import { RavenEmailLayout } from "./_components/layout"
import { EMAIL_COLORS } from "./_components/tokens"

export type InviteEmailProps = {
  inviterName: string
  roleName: string
  companyName?: string | null
  inviteUrl: string
}

export default function InviteEmail(props: InviteEmailProps) {
  const { inviterName, roleName, companyName, inviteUrl } = props

  return (
    <RavenEmailLayout title="Convite para o Sistema de Chamados" preview={`${inviterName} convidou voce para acessar o Sistema de Chamados Raven`}>
      <Section style={{ textAlign: "center", margin: "24px 0" }}>
        <div
          style={{
            display: "inline-block",
            width: "64px",
            height: "64px",
            backgroundColor: EMAIL_COLORS.primary,
            borderRadius: "50%",
            lineHeight: "64px",
            fontSize: "28px",
          }}
        >
          &#127881;
        </div>
      </Section>

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

      <Text style={{ margin: "0 0 24px 0", fontSize: "15px", lineHeight: "1.7", color: EMAIL_COLORS.textSecondary, textAlign: "center" }}>
        <strong>{inviterName}</strong> convidou voce para acessar o Sistema de Chamados Raven.
      </Text>

      <Section
        style={{
          backgroundColor: "#f8fafc",
          borderRadius: "12px",
          border: `1px solid ${EMAIL_COLORS.border}`,
          margin: "24px 0",
        }}
      >
        <table cellPadding="0" cellSpacing="0" role="presentation" style={{ width: "100%" }}>
          <tbody>
            <tr>
              <td style={{ padding: "16px 20px", borderBottom: `1px solid #f1f5f9` }}>
                <table cellPadding="0" cellSpacing="0" role="presentation" style={{ width: "100%" }}>
                  <tbody>
                    <tr>
                      <td style={{ color: EMAIL_COLORS.textMuted, fontSize: "13px", fontWeight: 500, width: "100px" }}>
                        Funcao
                      </td>
                      <td style={{ color: EMAIL_COLORS.textPrimary, fontSize: "14px", fontWeight: 600 }}>
                        {roleName}
                      </td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
            {companyName ? (
              <tr>
                <td style={{ padding: "16px 20px" }}>
                  <table cellPadding="0" cellSpacing="0" role="presentation" style={{ width: "100%" }}>
                    <tbody>
                      <tr>
                        <td style={{ color: EMAIL_COLORS.textMuted, fontSize: "13px", fontWeight: 500, width: "100px" }}>
                          Empresa
                        </td>
                        <td style={{ color: EMAIL_COLORS.textPrimary, fontSize: "14px" }}>
                          {companyName}
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </td>
              </tr>
            ) : null}
          </tbody>
        </table>
      </Section>

      <Section style={{ textAlign: "center", margin: "32px 0" }}>
        <Button
          href={inviteUrl}
          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}`,
          }}
        >
          Aceitar convite
        </Button>
      </Section>

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

      <Text style={{ margin: 0, fontSize: "12px", color: EMAIL_COLORS.textMuted, textAlign: "center" }}>
        Se o botao nao funcionar, copie e cole esta URL no navegador:
        <br />
        <a href={inviteUrl} style={{ color: EMAIL_COLORS.primaryDark, textDecoration: "none" }}>
          {inviteUrl}
        </a>
      </Text>

      <Text style={{ margin: "24px 0 0 0", fontSize: "13px", color: EMAIL_COLORS.textMuted, textAlign: "center", lineHeight: "1.6" }}>
        Este convite expira em 7 dias. Se voce nao esperava este convite, pode ignora-lo com seguranca.
      </Text>
    </RavenEmailLayout>
  )
}

InviteEmail.PreviewProps = {
  inviterName: "Renan Oliveira",
  roleName: "Agente",
  companyName: "Paulicon",
  inviteUrl: "https://raven.rever.com.br/invite/abc123def456",
} satisfies InviteEmailProps
