const { useState, useRef } = React;

/* ── Conexão com o Supabase ──
   A chave pública (anon/publishable) é segura para ficar no front-end:
   ela só permite chamar a Edge Function, que faz toda validação e
   processamento sensível no servidor. */
const SUPABASE_URL = "https://fvpxilfblhjsofjyuztw.supabase.co";
const SUPABASE_ANON_KEY = "sb_publishable_KESzOS6oI0DHNqMG85_mlw_K9oUT-eP";

/* ── Identidade visual do Verofy ── */
const C = {
  bg: "#0B1120", card: "#141E32", inputBg: "#1A2540",
  border: "#1E2D4A", text: "#F0F4FF", muted: "#8896B3",
  accent: "#10E6A0", accentDim: "#0A9966", blue: "#4FACFE",
  fy: "#6ADAB2", negative: "#FF5A7E", warning: "#FFB84D",
};

const PLANO = { nome: "Plano Premium", precoDe: 67.0, preco: 19.9 };

/* ── Helpers de máscara e validação ── */
function maskCpfCnpj(value) {
  const digits = value.replace(/\D/g, "").slice(0, 14);
  if (digits.length <= 11) {
    return digits
      .replace(/(\d{3})(\d)/, "$1.$2")
      .replace(/(\d{3})(\d)/, "$1.$2")
      .replace(/(\d{3})(\d{1,2})$/, "$1-$2");
  }
  return digits
    .replace(/(\d{2})(\d)/, "$1.$2")
    .replace(/(\d{3})(\d)/, "$1.$2")
    .replace(/(\d{3})(\d)/, "$1/$2")
    .replace(/(\d{4})(\d{1,2})$/, "$1-$2");
}

function maskPhone(value) {
  const digits = value.replace(/\D/g, "").slice(0, 11);
  if (digits.length <= 10) {
    return digits
      .replace(/(\d{2})(\d)/, "($1) $2")
      .replace(/(\d{4})(\d{1,4})$/, "$1-$2");
  }
  return digits
    .replace(/(\d{2})(\d)/, "($1) $2")
    .replace(/(\d{5})(\d{1,4})$/, "$1-$2");
}

function maskCep(value) {
  const digits = value.replace(/\D/g, "").slice(0, 8);
  return digits.replace(/(\d{5})(\d{1,3})$/, "$1-$2");
}

function maskCardNumber(value) {
  return value.replace(/\D/g, "").slice(0, 16).replace(/(\d{4})(?=\d)/g, "$1 ");
}

function maskExpiry(value) {
  const digits = value.replace(/\D/g, "").slice(0, 4);
  return digits.replace(/(\d{2})(\d{1,2})$/, "$1/$2");
}

function maskCvv(value) {
  return value.replace(/\D/g, "").slice(0, 4);
}

function detectarBandeira(numero) {
  const n = numero.replace(/\D/g, "");
  if (/^4/.test(n)) return "Visa";
  if (/^5[1-5]/.test(n)) return "Mastercard";
  if (/^3[47]/.test(n)) return "Amex";
  if (/^(636368|438935|504175|451416|509|636297|5067)/.test(n)) return "Elo";
  return null;
}

function validarCpf(cpf) {
  const n = cpf.replace(/\D/g, "");
  if (n.length !== 11) return false;
  if (/^(\d)\1{10}$/.test(n)) return false;
  let soma = 0, resto;
  for (let i = 1; i <= 9; i++) soma += parseInt(n.substring(i - 1, i)) * (11 - i);
  resto = (soma * 10) % 11;
  if (resto === 10 || resto === 11) resto = 0;
  if (resto !== parseInt(n.substring(9, 10))) return false;
  soma = 0;
  for (let i = 1; i <= 10; i++) soma += parseInt(n.substring(i - 1, i)) * (12 - i);
  resto = (soma * 10) % 11;
  if (resto === 10 || resto === 11) resto = 0;
  return resto === parseInt(n.substring(10, 11));
}

function validarCnpj(cnpj) {
  const n = cnpj.replace(/\D/g, "");
  if (n.length !== 14) return false;
  if (/^(\d)\1{13}$/.test(n)) return false;
  let tamanho = n.length - 2;
  let numeros = n.substring(0, tamanho);
  const digitos = n.substring(tamanho);
  let soma = 0, pos = tamanho - 7;
  for (let i = tamanho; i >= 1; i--) {
    soma += numeros.charAt(tamanho - i) * pos--;
    if (pos < 2) pos = 9;
  }
  let resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11);
  if (resultado !== parseInt(digitos.charAt(0))) return false;
  tamanho += 1;
  numeros = n.substring(0, tamanho);
  soma = 0; pos = tamanho - 7;
  for (let i = tamanho; i >= 1; i--) {
    soma += numeros.charAt(tamanho - i) * pos--;
    if (pos < 2) pos = 9;
  }
  resultado = soma % 11 < 2 ? 0 : 11 - (soma % 11);
  return resultado === parseInt(digitos.charAt(1));
}

function validarEmail(email) {
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}

function validarValidadeCartao(mmYY) {
  const match = mmYY.match(/^(\d{2})\/(\d{2})$/);
  if (!match) return false;
  const mes = parseInt(match[1], 10);
  const ano = 2000 + parseInt(match[2], 10);
  if (mes < 1 || mes > 12) return false;
  const agora = new Date();
  const expira = new Date(ano, mes, 0);
  return expira >= new Date(agora.getFullYear(), agora.getMonth(), 1);
}

/* ── Ícone de bandeira ── */
function BandeiraIcon({ bandeira }) {
  if (!bandeira) return null;
  const cores = { Visa: "#1A1F71", Mastercard: "#EB001B", Amex: "#2E77BC", Elo: "#000000" };
  return (
    <span style={{
      fontSize: 11, fontWeight: 700, color: "#fff",
      background: cores[bandeira] || C.muted,
      padding: "3px 8px", borderRadius: 5, letterSpacing: 0.3,
    }}>
      {bandeira}
    </span>
  );
}

/* ── Campo de formulário reutilizável ── */
function Field({ label, error, children, hint }) {
  return (
    <div style={{ marginBottom: 16 }}>
      <label style={{ display: "block", fontSize: 12.5, color: C.muted, marginBottom: 6, fontWeight: 500 }}>
        {label}
      </label>
      {children}
      {hint && !error && <div style={{ fontSize: 11.5, color: C.muted, marginTop: 5 }}>{hint}</div>}
      {error && <div style={{ fontSize: 11.5, color: C.negative, marginTop: 5 }}>{error}</div>}
    </div>
  );
}

const inputStyle = (hasError) => ({
  width: "100%",
  background: C.inputBg,
  border: `1px solid ${hasError ? C.negative : C.border}`,
  borderRadius: 10,
  padding: "12px 14px",
  color: C.text,
  fontSize: 14,
  outline: "none",
  boxSizing: "border-box",
  fontFamily: "inherit",
});

/* ── Logo ── */
const LOGO_ICON_BASE64 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAABA5ElEQVR42pW9WZCsWXEm6O7nRORyM+9a+8pWVIEoqiiWRhRCCzuSGgRiEKholu7qlrW1TT/IbBabh3kYG7OxWR7GbJ6mW0jNMrSQuqXGRAsMBKIkARItiU0SCApqUy331t1yuZkR/3H/5sHP9kdEXrWysqryZkbGjTiLL59//jn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/iStOSqNQREAyw6sk7KYJRSF7/b90vt7LQakUrPvoe8EKXJEaR8vIGct/Xt0rHGP3acp/DLQzU4IVAGRX1aHhzZwuudiJWnrTF1OwfsnMLGicgWr55JRzi1t+y+DRYep89Ja6C/t2rjFxTqGZLu5pA5wH77x+hpwjqYBteMRio+Y+FbL1zjHxU/NAjDDXq4MX3XoMdvsplxkjAmTs/TSu+6O1Nj49gWXBvNLCQjzAkfWjx/wOD8nmYFRns0QAAAABJRU5ErkJggg==";

function Logo() {
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 10, justifyContent: "center" }}>
      <img
        src={LOGO_ICON_BASE64}
        alt="Verofy"
        style={{ width: 34, height: 34, borderRadius: 10, flexShrink: 0, objectFit: "cover" }}
      />
      <span style={{ fontWeight: 700, fontSize: 19, letterSpacing: -0.5 }}>
        <span style={{ color: C.text }}>Vero</span><span style={{ color: C.fy }}>fy</span>
      </span>
    </div>
  );
}

function CheckoutVerofy() {
  const [form, setForm] = useState({
    nome: "", email: "", cpfCnpj: "", telefone: "", cep: "", numeroEndereco: "",
    cardNumber: "", cardName: "", cardExpiry: "", cardCvv: "",
  });
  const [errors, setErrors] = useState({});
  const [loading, setLoading] = useState(false);
  const [success, setSuccess] = useState(false);
  const [generalError, setGeneralError] = useState("");
  const formTopRef = useRef(null);

  const bandeira = detectarBandeira(form.cardNumber);

  const setField = (key, maskFn) => (e) => {
    const raw = e.target.value;
    const masked = maskFn ? maskFn(raw) : raw;
    setForm((f) => ({ ...f, [key]: masked }));
    if (errors[key]) setErrors((er) => ({ ...er, [key]: null }));
  };

  const validar = () => {
    const novosErros = {};
    if (!form.nome.trim() || form.nome.trim().split(" ").length < 2) {
      novosErros.nome = "Informe seu nome completo.";
    }
    if (!validarEmail(form.email)) {
      novosErros.email = "Informe um e-mail válido.";
    }
    const digitsDoc = form.cpfCnpj.replace(/\D/g, "");
    const docValido = digitsDoc.length === 11 ? validarCpf(form.cpfCnpj) : digitsDoc.length === 14 ? validarCnpj(form.cpfCnpj) : false;
    if (!docValido) {
      novosErros.cpfCnpj = "Informe um CPF ou CNPJ válido.";
    }
    if (form.telefone.replace(/\D/g, "").length < 10) {
      novosErros.telefone = "Informe um telefone válido com DDD.";
    }
    if (form.cep.replace(/\D/g, "").length !== 8) {
      novosErros.cep = "Informe um CEP válido.";
    }
    if (!form.numeroEndereco.trim()) {
      novosErros.numeroEndereco = "Informe o número do endereço.";
    }
    const digitsCard = form.cardNumber.replace(/\D/g, "");
    if (digitsCard.length < 13 || digitsCard.length > 16) {
      novosErros.cardNumber = "Número de cartão inválido.";
    }
    if (!form.cardName.trim() || form.cardName.trim().length < 3) {
      novosErros.cardName = "Informe o nome impresso no cartão.";
    }
    if (!validarValidadeCartao(form.cardExpiry)) {
      novosErros.cardExpiry = "Validade inválida ou cartão expirado.";
    }
    if (form.cardCvv.length < 3) {
      novosErros.cardCvv = "CVV inválido.";
    }
    setErrors(novosErros);
    return Object.keys(novosErros).length === 0;
  };

  const handleSubmit = async (e) => {
    e.preventDefault();
    setGeneralError("");
    if (!validar()) {
      formTopRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
      return;
    }
    setLoading(true);

    try {
      const resposta = await fetch(
        `${SUPABASE_URL}/functions/v1/processar-pagamento`,
        {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${SUPABASE_ANON_KEY}`,
          },
          body: JSON.stringify(form),
        }
      );
      const dados = await resposta.json();

      if (!resposta.ok || dados.erro) {
        setGeneralError(dados.erro || "Não foi possível processar o pagamento. Tente novamente.");
        setLoading(false);
        formTopRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
        return;
      }

      setLoading(false);
      setSuccess(true);
    } catch (err) {
      setGeneralError("Erro de conexão. Verifique sua internet e tente novamente.");
      setLoading(false);
      formTopRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
    }
  };

  if (success) {
    return (
      <div style={{ minHeight: "100vh", background: C.bg, display: "flex", alignItems: "center", justifyContent: "center", padding: 20, fontFamily: "Inter, system-ui, sans-serif" }}>
        <div style={{ maxWidth: 420, width: "100%", textAlign: "center" }}>
          <Logo />
          <div style={{ marginTop: 36, background: C.card, border: `1px solid ${C.border}`, borderRadius: 18, padding: "40px 28px" }}>
            <div style={{
              width: 64, height: 64, borderRadius: "50%",
              background: `${C.accent}22`, display: "flex", alignItems: "center",
              justifyContent: "center", margin: "0 auto 20px",
            }}>
              <svg width="30" height="30" viewBox="0 0 24 24" fill="none">
                <path d="M5 13l4 4L19 7" stroke={C.accent} strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" />
              </svg>
            </div>
            <h2 style={{ color: C.text, fontSize: 20, fontWeight: 700, margin: "0 0 10px" }}>Pagamento confirmado!</h2>
            <p style={{ color: C.muted, fontSize: 14, lineHeight: 1.6, margin: 0 }}>
              Seu acesso ao Verofy será liberado em poucos minutos, fique atento ao seu e-mail.
            </p>
          </div>
        </div>
      </div>
    );
  }

  return (
    <div style={{ minHeight: "100vh", background: C.bg, padding: "40px 16px", fontFamily: "Inter, system-ui, sans-serif", color: C.text }}>
      <div ref={formTopRef} style={{ maxWidth: 460, margin: "0 auto" }}>
        <Logo />

        {/* Resumo do plano */}
        <div style={{
          marginTop: 28, background: C.card, border: `1px solid ${C.border}`,
          borderRadius: 16, padding: "22px 24px",
        }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start", flexWrap: "wrap", gap: 8 }}>
            <div>
              <div style={{ fontSize: 12, color: C.accent, fontWeight: 700, letterSpacing: 0.5, textTransform: "uppercase", marginBottom: 4 }}>
                {PLANO.nome}
              </div>
              <div style={{ fontSize: 13, color: C.negative }}>
                <span style={{ textDecoration: "none" }}>De R$ </span>
                <span style={{ textDecoration: "line-through" }}>{PLANO.precoDe.toFixed(2).replace(".", ",")}</span>
              </div>
            </div>
            <div style={{ textAlign: "right" }}>
              <span style={{ fontSize: 28, fontWeight: 800 }}>
                R$ {Math.floor(PLANO.preco)}
                <span style={{ fontSize: 16, color: C.muted, fontWeight: 600 }}>,{(PLANO.preco % 1).toFixed(2).slice(2)}</span>
              </span>
              <div style={{ fontSize: 12, color: C.muted }}>por mês</div>
            </div>
          </div>
          <div style={{ marginTop: 12, paddingTop: 12, borderTop: `1px solid ${C.border}`, fontSize: 12.5, color: C.muted }}>
            Cobrança recorrente mensal no cartão de crédito, cancele quando quiser.
          </div>
        </div>

        <form onSubmit={handleSubmit} style={{ marginTop: 24 }}>
          {generalError && (
            <div style={{
              background: `${C.negative}15`, border: `1px solid ${C.negative}55`,
              borderRadius: 10, padding: "12px 14px", marginBottom: 18,
              color: C.negative, fontSize: 13,
            }}>
              {generalError}
            </div>
          )}

          {/* Dados do cliente */}
          <div style={{ background: C.card, border: `1px solid ${C.border}`, borderRadius: 16, padding: 22, marginBottom: 16 }}>
            <h3 style={{ fontSize: 14, fontWeight: 700, margin: "0 0 16px", color: C.text }}>Seus dados</h3>

            <Field label="Nome completo" error={errors.nome}>
              <input
                style={inputStyle(errors.nome)}
                placeholder="Digite seu nome completo"
                value={form.nome}
                onChange={setField("nome")}
                autoComplete="name"
              />
            </Field>

            <Field label="E-mail" error={errors.email} hint="Seu acesso ao Verofy será enviado para este e-mail">
              <input
                type="email"
                style={inputStyle(errors.email)}
                placeholder="voce@email.com"
                value={form.email}
                onChange={setField("email")}
                autoComplete="email"
              />
            </Field>

            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
              <Field label="CPF ou CNPJ" error={errors.cpfCnpj}>
                <input
                  style={inputStyle(errors.cpfCnpj)}
                  placeholder="000.000.000-00"
                  value={form.cpfCnpj}
                  onChange={setField("cpfCnpj", maskCpfCnpj)}
                  inputMode="numeric"
                />
              </Field>
              <Field label="Telefone" error={errors.telefone}>
                <input
                  style={inputStyle(errors.telefone)}
                  placeholder="(00) 00000-0000"
                  value={form.telefone}
                  onChange={setField("telefone", maskPhone)}
                  inputMode="numeric"
                  autoComplete="tel"
                />
              </Field>
            </div>

            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
              <Field label="CEP" error={errors.cep} hint="Endereço de cobrança do cartão">
                <input
                  style={inputStyle(errors.cep)}
                  placeholder="00000-000"
                  value={form.cep}
                  onChange={setField("cep", maskCep)}
                  inputMode="numeric"
                  autoComplete="postal-code"
                />
              </Field>
              <Field label="Número" error={errors.numeroEndereco}>
                <input
                  style={inputStyle(errors.numeroEndereco)}
                  placeholder="123"
                  value={form.numeroEndereco}
                  onChange={setField("numeroEndereco")}
                  inputMode="numeric"
                  autoComplete="address-line2"
                />
              </Field>
            </div>
          </div>

          {/* Dados do cartão */}
          <div style={{ background: C.card, border: `1px solid ${C.border}`, borderRadius: 16, padding: 22, marginBottom: 22 }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }}>
              <h3 style={{ fontSize: 14, fontWeight: 700, margin: 0, color: C.text }}>Cartão de crédito</h3>
              {bandeira && <BandeiraIcon bandeira={bandeira} />}
            </div>

            <Field label="Número do cartão" error={errors.cardNumber}>
              <input
                style={inputStyle(errors.cardNumber)}
                placeholder="0000 0000 0000 0000"
                value={form.cardNumber}
                onChange={setField("cardNumber", maskCardNumber)}
                inputMode="numeric"
                autoComplete="cc-number"
              />
            </Field>

            <Field label="Nome impresso no cartão" error={errors.cardName}>
              <input
                style={inputStyle(errors.cardName)}
                placeholder="Como está no cartão"
                value={form.cardName}
                onChange={setField("cardName", (v) => v.toUpperCase())}
                autoComplete="cc-name"
              />
            </Field>

            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12 }}>
              <Field label="Validade" error={errors.cardExpiry}>
                <input
                  style={inputStyle(errors.cardExpiry)}
                  placeholder="MM/AA"
                  value={form.cardExpiry}
                  onChange={setField("cardExpiry", maskExpiry)}
                  inputMode="numeric"
                  autoComplete="cc-exp"
                />
              </Field>
              <Field label="CVV" error={errors.cardCvv}>
                <input
                  style={inputStyle(errors.cardCvv)}
                  placeholder="123"
                  value={form.cardCvv}
                  onChange={setField("cardCvv", maskCvv)}
                  inputMode="numeric"
                  autoComplete="cc-csc"
                />
              </Field>
            </div>
          </div>

          <button
            type="submit"
            disabled={loading}
            className={loading ? "" : "btn-pulse"}
            style={{
              width: "100%",
              background: loading ? C.border : `linear-gradient(135deg, ${C.accent}, ${C.blue})`,
              color: loading ? C.muted : "#06140F",
              border: "none",
              borderRadius: 12,
              padding: "15px 0",
              fontSize: 15,
              fontWeight: 700,
              cursor: loading ? "default" : "pointer",
              display: "flex",
              alignItems: "center",
              justifyContent: "center",
              gap: 10,
              fontFamily: "inherit",
            }}
          >
            {loading ? (
              <>
                <span style={{
                  width: 16, height: 16, borderRadius: "50%",
                  border: `2px solid ${C.muted}`, borderTopColor: "transparent",
                  display: "inline-block", animation: "spin 0.7s linear infinite",
                }} />
                Processando...
              </>
            ) : (
              "Assinar agora"
            )}
          </button>

          <div style={{
            marginTop: 18, display: "flex", alignItems: "center", justifyContent: "center",
            gap: 7, color: C.muted, fontSize: 12,
          }}>
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none">
              <rect x="5" y="11" width="14" height="9" rx="2" stroke={C.muted} strokeWidth="1.6" />
              <path d="M8 11V7a4 4 0 018 0v4" stroke={C.muted} strokeWidth="1.6" />
            </svg>
            Pagamento processado de forma segura pela Asaas, instituição de pagamento autorizada pelo Banco Central.
          </div>
        </form>
      </div>

      <style>{`
        @keyframes spin { to { transform: rotate(360deg); } }
        input::placeholder { color: ${C.muted}99; }
        input:focus { border-color: ${C.accent} !important; }
        @media (max-width: 380px) {
          input { font-size: 13px !important; padding: 12px 10px !important; }
        }
        .btn-pulse {
          animation: pulse-cta 2.2s ease-in-out infinite;
        }
        @keyframes pulse-cta {
          0%, 100% {
            transform: scale(1);
            box-shadow: 0 0 0 0 rgba(16,230,160,0.45);
          }
          50% {
            transform: scale(1.035);
            box-shadow: 0 0 0 10px rgba(16,230,160,0);
          }
        }
        @media (prefers-reduced-motion: reduce) {
          .btn-pulse { animation: none; }
        }
      `}</style>
    </div>
  );
}


/* ── Renderização ── */
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<CheckoutVerofy />);
