"use client";

import { motion } from "framer-motion";
import { ArrowRight, Mail, MapPin, MessageCircle, Phone } from "lucide-react";
import { Button } from "@/components/ui/button";
import SectionHeading from "@/components/ppdb/SectionHeading";
import { navigate } from "@/lib/router";
import { waLink } from "@/lib/usePublic";
import type { PublicData } from "@/lib/types";

export default function Contact({ data }: { data: PublicData | null }) {
  const wa = waLink(
    data?.waAdmin || "6281234567890",
    "Halo panitia PPDB SMK Al Aitaam, saya ingin bertanya tentang pendaftaran siswa baru."
  );

  return (
    <section id="kontak" className="bg-background py-20 sm:py-24">
      <div className="mx-auto max-w-7xl px-4 sm:px-6">
        <motion.div
          initial={{ opacity: 0, y: 32 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true, margin: "-60px" }}
          transition={{ duration: 0.6 }}
          className="relative overflow-hidden rounded-[2.5rem] bg-gradient-to-br from-[#7B1E28] via-[#5d1420] to-[#3a0e15] p-8 text-center shadow-2xl shadow-[#7B1E28]/30 sm:p-14"
        >
          <div className="pointer-events-none absolute inset-0 bg-dots opacity-30" />
          <div className="animate-blob pointer-events-none absolute -top-20 -right-20 size-72 bg-[#D4A017]/20 blur-2xl" />
          <div className="relative">
            <h2 className="text-3xl font-extrabold text-white sm:text-4xl">
              Siap Bergabung dengan Keluarga Besar
              <span
                className="bg-clip-text text-transparent"
                style={{
                  backgroundImage: "linear-gradient(100deg,#D4A017 15%,#F5D77A 40%,#C18E12 60%,#D4A017 80%)",
                  backgroundSize: "200% auto",
                  animation: "ppdb-shine 5s linear infinite",
                }}
              >
                {" "}SMK Al Aitaam?
              </span>
            </h2>
            <p className="mx-auto mt-4 max-w-xl text-white/75">
              Jangan tunda masa depanmu. Daftar sekarang atau konsultasikan pilihan jurusanmu
              dengan panitia PPDB melalui WhatsApp.
            </p>
            <div className="mt-8 flex flex-wrap items-center justify-center gap-3">
              <Button
                size="lg"
                onClick={() => navigate("daftar")}
                className="group h-12 rounded-full bg-gradient-to-r from-[#D4A017] to-[#F0B429] px-7 text-base font-bold text-[#4a121c] shadow-xl transition-all hover:-translate-y-0.5"
              >
                Daftar Sekarang
                <ArrowRight className="size-5 transition-transform group-hover:translate-x-1" />
              </Button>
              <a href={wa} target="_blank" rel="noopener noreferrer">
                <Button
                  size="lg"
                  variant="outline"
                  className="h-12 rounded-full border-white/25 bg-white/5 px-7 text-base font-semibold text-white hover:bg-white/15 hover:text-white"
                >
                  <MessageCircle className="size-5" />
                  Tanya Panitia
                </Button>
              </a>
            </div>
          </div>
        </motion.div>

        <div className="mt-10 grid gap-4 sm:grid-cols-3">
          {[
            { Icon: MapPin, title: "Alamat Sekolah", value: data?.alamat || "-" },
            { Icon: Phone, title: "Telepon", value: data?.telepon || "-" },
            { Icon: Mail, title: "Email", value: data?.email || "-" },
          ].map((c, i) => (
            <motion.div
              key={c.title}
              initial={{ opacity: 0, y: 20 }}
              whileInView={{ opacity: 1, y: 0 }}
              viewport={{ once: true, margin: "-40px" }}
              transition={{ duration: 0.45, delay: i * 0.1 }}
              className="flex items-start gap-3.5 rounded-2xl border bg-card p-5 shadow-sm"
            >
              <span className="grid size-11 shrink-0 place-items-center rounded-xl bg-[#7B1E28]/10 text-[#7B1E28]">
                <c.Icon className="size-5" />
              </span>
              <div className="min-w-0">
                <p className="text-sm font-bold text-[#4a1520]">{c.title}</p>
                <p className="mt-1 break-words text-sm leading-relaxed text-muted-foreground">{c.value}</p>
              </div>
            </motion.div>
          ))}
        </div>
      </div>
    </section>
  );
}
