import type { LeadStatus } from "@/lib/useLeadForm";

/** Hidden field that only bots fill in. */
export function Honeypot() {
  return (
    <div aria-hidden className="absolute -left-[9999px] h-px w-px overflow-hidden">
      <label>
        Website
        <input type="text" name="website" tabIndex={-1} autoComplete="off" />
      </label>
    </div>
  );
}

export type FormMessages = { sending: string; sent: string; error: string; consent: string; privacyLink: string; privacyHref: string };

/** Consent checkbox (Ley 1581 de 2012 / GDPR) with a link to the privacy policy. */
export function Consent({ messages, dark = false }: { messages: FormMessages; dark?: boolean }) {
  const [before, after] = messages.consent.split("{link}");
  return (
    <label className={`flex items-start gap-3 text-xs leading-relaxed ${dark ? "text-cream/65" : "text-stone"}`}>
      <input type="checkbox" name="consent" required className="mt-0.5 accent-[var(--color-gold)]" />
      <span>
        {before}
        <a href={messages.privacyHref} className="underline underline-offset-2 hover:text-gold-ink" target="_blank" rel="noopener">
          {messages.privacyLink}
        </a>
        {after}
      </span>
    </label>
  );
}

export function StatusLine({ status, messages, dark = false }: { status: LeadStatus; messages: FormMessages; dark?: boolean }) {
  const text = status === "sending" ? messages.sending : status === "sent" ? messages.sent : status === "error" ? messages.error : "";
  const tone = status === "error" ? "text-red-700" : dark ? "text-gold-light" : "text-forest";
  return (
    <p className={`min-h-5 text-sm ${status === "error" && dark ? "text-red-300" : tone}`} role="status" aria-live="polite">
      {text}
    </p>
  );
}
