"use client";

import { useState } from "react";
import { ChevronDownIcon } from "./icons";

const FAQS = [
  {
    q: "What is VehCall?",
    a: "VehCall is a platform that lets anyone contact a vehicle owner through a QR code attached to the vehicle — without ever exposing the owner's personal phone number.",
  },
  {
    q: "How does the QR system work?",
    a: "Each vehicle gets a unique VehCall QR sticker. When someone scans it with their phone camera, VehCall securely loads the vehicle's communication options so they can call, message, or send an emergency alert.",
  },
  {
    q: "Is my phone number visible?",
    a: "Never. VehCall acts as a secure relay between both parties. Calls and messages are routed through the platform, so neither side ever sees the other's real number.",
  },
  {
    q: "Can I manage multiple vehicles?",
    a: "Yes. Premium plans support up to five vehicles, and our Enterprise plan offers fleet management with bulk registration and a business dashboard.",
  },
  {
    q: "What happens during emergencies?",
    a: "The emergency alert button immediately notifies the owner with a high-priority message. It's designed for urgent situations like accidents, hazards, or safety concerns.",
  },
  {
    q: "How secure is VehCall?",
    a: "All communication is encrypted, every vehicle is tied to a verified registration, and suspicious activity is actively monitored to keep the network safe and trustworthy.",
  },
];

export default function FAQ() {
  const [open, setOpen] = useState<number | null>(0);

  return (
    <section id="faq" className="relative py-24 sm:py-28">
      <div className="mx-auto max-w-3xl px-5 sm:px-8">
        <div className="flex flex-col items-center gap-4 text-center">
          <span className="eyebrow">FAQ</span>
          <h2 className="text-3xl font-bold sm:text-4xl">
            Frequently asked <span className="text-gradient">questions</span>
          </h2>
          <p className="text-white/60">
            Everything you need to know about VehCall. Still curious?{" "}
            <a href="#download" className="text-brand hover:underline">
              Reach out
            </a>
            .
          </p>
        </div>

        <div className="mt-12 space-y-3">
          {FAQS.map((item, i) => {
            const isOpen = open === i;
            return (
              <div
                key={item.q}
                className={`glass overflow-hidden rounded-2xl transition-colors ${
                  isOpen ? "border-brand/30" : ""
                }`}
              >
                <button
                  type="button"
                  aria-expanded={isOpen}
                  onClick={() => setOpen(isOpen ? null : i)}
                  className="flex w-full items-center justify-between gap-4 px-6 py-5 text-left"
                >
                  <span className="text-base font-semibold text-white">
                    {item.q}
                  </span>
                  <ChevronDownIcon
                    width={20}
                    height={20}
                    className={`shrink-0 text-brand transition-transform duration-300 ${
                      isOpen ? "rotate-180" : ""
                    }`}
                  />
                </button>
                <div
                  className={`grid transition-all duration-300 ease-out ${
                    isOpen
                      ? "grid-rows-[1fr] opacity-100"
                      : "grid-rows-[0fr] opacity-0"
                  }`}
                >
                  <div className="overflow-hidden">
                    <p className="px-6 pb-5 text-[15px] leading-relaxed text-white/65">
                      {item.a}
                    </p>
                  </div>
                </div>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}
