"use client";

import { motion } from "framer-motion";
import { Plus } from "lucide-react";

type FAQItem = {
  question: string;
  answer: string;
};

type FAQAccordionProps = {
  items: FAQItem[];
};

export function FAQAccordion({ items }: FAQAccordionProps) {
  return (
    <motion.div
      className="divide-y divide-slate-200/75 overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-[0_18px_55px_rgb(15_23_42_/_0.055)]"
      initial={{ opacity: 0, y: 12 }}
      whileInView={{ opacity: 1, y: 0 }}
      viewport={{ once: true, margin: "-80px" }}
      transition={{ duration: 0.4, ease: [0.22, 1, 0.36, 1] }}
    >
      {items.map((item) => (
        <details key={item.question} className="group p-5 open:bg-slate-50/60 sm:p-6">
          <summary className="flex cursor-pointer list-none items-start justify-between gap-4 text-base font-semibold leading-6 text-slate-950">
            {item.question}
            <Plus aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-primary transition group-open:rotate-45" strokeWidth={1.8} />
          </summary>
          <p className="mt-3 text-sm leading-6 text-slate-600">{item.answer}</p>
        </details>
      ))}
    </motion.div>
  );
}
