import { Head, useForm } from "@inertiajs/react";
import { motion } from "framer-motion";
import { Nav } from "@/components/sections/Nav";
import { Footer } from "@/components/sections/Footer";
import { fadeUp, staggerContainer, staggerItem, viewportOptions } from "@/lib/animations";

const socials = [
  { label: "Facebook", href: "https://www.facebook.com/YouthAdvocatesZimbabwe/", icon: "f" },
  { label: "X / Twitter", href: "https://x.com/yadvocates_hub", icon: "𝕏" },
  { label: "LinkedIn", href: "https://www.linkedin.com/company/youthadvocates/?originalSubdomain=zw", icon: "in" },
  { label: "YouTube", href: "https://www.youtube.com/@YouthAdvocatesZ", icon: "▶" },
  { label: "Instagram", href: "https://www.instagram.com/youthadvocates/?hl=en", icon: "◎" },
];

const details = [
  {
    label: "Visit Us",
    value: "926 New Zengeza 4\nChitungwiza, Zimbabwe",
    icon: (
      <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.8}>
        <path strokeLinecap="round" strokeLinejoin="round" d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z" />
        <path strokeLinecap="round" strokeLinejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z" />
      </svg>
    ),
  },
  {
    label: "Call Us",
    value: "+263 77 746 9107",
    href: "tel:+263777469107",
    icon: (
      <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.8}>
        <path strokeLinecap="round" strokeLinejoin="round" d="M2.25 6.75c0 8.284 6.716 15 15 15h2.25a2.25 2.25 0 002.25-2.25v-1.372c0-.516-.351-.966-.852-1.091l-4.423-1.106c-.44-.11-.902.055-1.173.417l-.97 1.293c-.282.376-.769.542-1.21.38a12.035 12.035 0 01-7.143-7.143c-.162-.441.004-.928.38-1.21l1.293-.97c.363-.271.527-.734.417-1.173L6.963 3.102a1.125 1.125 0 00-1.091-.852H4.5A2.25 2.25 0 002.25 4.5v2.25z" />
      </svg>
    ),
  },
  {
    label: "Email Us",
    value: "advocates@yadvocates.org",
    href: "mailto:advocates@yadvocates.org",
    icon: (
      <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.8}>
        <path strokeLinecap="round" strokeLinejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75" />
      </svg>
    ),
  },
  {
    label: "Crisis Helpline",
    value: "Call 393: 24 hours, 7 days",
    href: "tel:393",
    icon: (
      <svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.8}>
        <path strokeLinecap="round" strokeLinejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" />
      </svg>
    ),
  },
];

export default function Contact() {
  const { data, setData, post, processing, errors, reset, wasSuccessful } = useForm({
    name: "",
    email: "",
    message: "",
  });

  function handleSubmit(e: React.FormEvent) {
    e.preventDefault();
    post("/contact", { onSuccess: () => reset() });
  }

  return (
    <>
      <Head title="Contact Us" />
      <Nav />

      <main className="pt-18">
        {/* Page header */}
        <div className="bg-navy px-16 py-20 max-md:px-8">
          <motion.div
            variants={fadeUp}
            initial="hidden"
            animate="visible"
            className="mx-auto max-w-[1140px]"
          >
            <p className="mb-3 font-mono text-[11px] font-bold tracking-[0.18em] text-amber uppercase">
              Get In Touch
            </p>
            <h1 className="mb-4 text-[clamp(32px,4.5vw,58px)] font-bold leading-[1.05] tracking-tight text-white">
              Contact Us
            </h1>
            <p className="max-w-xl text-[17px] leading-[1.7] text-white/70">
              Whether you need support, want to partner with us, or just want to learn more,
              we're here. We respond within 24 hours.
            </p>
          </motion.div>
        </div>

        {/* Main content */}
        <div className="mx-auto max-w-[1140px] px-16 py-20 max-md:px-8">
          <div className="grid gap-16 lg:grid-cols-[1fr_1.4fr]">

            {/* Left — contact details */}
            <motion.div
              variants={staggerContainer}
              initial="hidden"
              whileInView="visible"
              viewport={viewportOptions}
            >
              <motion.div variants={fadeUp} className="mb-10">
                <h2 className="mb-2 text-2xl font-bold text-navy">Reach us directly</h2>
                <p className="text-[15px] leading-relaxed text-secondary">
                  Our team is based in Chitungwiza, Zimbabwe, with programme staff across Southern and East Africa.
                </p>
              </motion.div>

              <div className="mb-10 flex flex-col gap-5">
                {details.map(({ label, value, href, icon }) => (
                  <motion.div
                    key={label}
                    variants={staggerItem}
                    className="flex items-start gap-4 rounded-2xl border border-border bg-surface p-5"
                  >
                    <span className="mt-0.5 flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-amber-tint text-amber">
                      {icon}
                    </span>
                    <div>
                      <p className="mb-0.5 text-xs font-bold tracking-wider text-secondary uppercase">
                        {label}
                      </p>
                      {href ? (
                        <a href={href} className="font-semibold text-navy hover:text-amber transition-colors whitespace-pre-line">
                          {value}
                        </a>
                      ) : (
                        <p className="font-semibold text-navy whitespace-pre-line">{value}</p>
                      )}
                    </div>
                  </motion.div>
                ))}
              </div>

              {/* Social media */}
              <motion.div variants={fadeUp}>
                <p className="mb-4 font-mono text-[11px] font-bold tracking-[0.18em] text-secondary uppercase">
                  Follow Us
                </p>
                <div className="flex flex-wrap gap-3">
                  {socials.map(({ label, href, icon }) => (
                    <a
                      key={label}
                      href={href}
                      target="_blank"
                      rel="noopener noreferrer"
                      className="flex items-center gap-2 rounded-full border border-border bg-white px-4 py-2 text-sm font-semibold text-navy transition-colors hover:border-amber hover:text-amber"
                    >
                      <span className="text-base leading-none">{icon}</span>
                      {label}
                    </a>
                  ))}
                </div>
              </motion.div>
            </motion.div>

            {/* Right — contact form */}
            <motion.div
              variants={fadeUp}
              initial="hidden"
              whileInView="visible"
              viewport={viewportOptions}
            >
              <div className="rounded-2xl border border-border bg-white p-10 shadow-sm max-md:p-6">
                <h2 className="mb-1 text-2xl font-bold text-navy">Send us a message</h2>
                <p className="mb-8 text-sm text-secondary">We respond within 24 hours.</p>

                {wasSuccessful && (
                  <div className="mb-6 rounded-xl bg-green-tint px-5 py-4 text-sm font-semibold text-green">
                    Message sent! We'll get back to you within 24 hours.
                  </div>
                )}

                <form onSubmit={handleSubmit} className="flex flex-col gap-5">
                  <div>
                    <label htmlFor="name" className="mb-1.5 block text-sm font-semibold text-navy">
                      Your Name <span className="text-amber">*</span>
                    </label>
                    <input
                      id="name"
                      type="text"
                      required
                      value={data.name}
                      onChange={(e) => setData("name", e.target.value)}
                      placeholder="e.g. Tatenda Moyo"
                      className="w-full rounded-xl border border-border bg-surface px-4 py-3 text-sm text-body placeholder:text-muted focus:border-amber focus:outline-none focus:ring-2 focus:ring-amber/20"
                    />
                    {errors.name && <p className="mt-1 text-xs text-red-600">{errors.name}</p>}
                  </div>

                  <div>
                    <label htmlFor="email" className="mb-1.5 block text-sm font-semibold text-navy">
                      Your Email <span className="text-amber">*</span>
                    </label>
                    <input
                      id="email"
                      type="email"
                      required
                      value={data.email}
                      onChange={(e) => setData("email", e.target.value)}
                      placeholder="you@example.com"
                      className="w-full rounded-xl border border-border bg-surface px-4 py-3 text-sm text-body placeholder:text-muted focus:border-amber focus:outline-none focus:ring-2 focus:ring-amber/20"
                    />
                    {errors.email && <p className="mt-1 text-xs text-red-600">{errors.email}</p>}
                  </div>

                  <div>
                    <label htmlFor="message" className="mb-1.5 block text-sm font-semibold text-navy">
                      Message <span className="text-amber">*</span>
                    </label>
                    <textarea
                      id="message"
                      required
                      rows={6}
                      value={data.message}
                      onChange={(e) => setData("message", e.target.value)}
                      placeholder="How can we help you?"
                      className="w-full resize-none rounded-xl border border-border bg-surface px-4 py-3 text-sm text-body placeholder:text-muted focus:border-amber focus:outline-none focus:ring-2 focus:ring-amber/20"
                    />
                    {errors.message && <p className="mt-1 text-xs text-red-600">{errors.message}</p>}
                  </div>

                  <button
                    type="submit"
                    disabled={processing}
                    className="rounded-xl bg-amber px-8 py-3.5 text-sm font-bold text-white transition-opacity hover:opacity-90 disabled:opacity-60"
                  >
                    {processing ? "Sending…" : "Send Message →"}
                  </button>
                </form>
              </div>
            </motion.div>
          </div>

          {/* Full-width map */}
          <motion.div
            variants={fadeUp}
            initial="hidden"
            whileInView="visible"
            viewport={viewportOptions}
            className="mt-16 overflow-hidden rounded-2xl border border-border shadow-sm"
          >
            <iframe
              title="Youth Advocates location"
              src="https://maps.google.com/maps?q=-17.992336,31.073946&z=17&hl=en&gl=ZW&output=embed"
              width="100%"
              height="480"
              style={{ border: 0, display: "block" }}
              allowFullScreen
              loading="lazy"
              referrerPolicy="no-referrer-when-downgrade"
            />
          </motion.div>
        </div>
      </main>

      <Footer />
    </>
  );
}
