import Link from "next/link";
import type { ReactNode } from "react";
import type { Metadata } from "next";
import { prisma } from "@/lib/prisma";
import { SITE, whatsappLink } from "@/lib/site";

export async function generateMetadata(): Promise<Metadata> {
  const page = await prisma.pageSeo.findUnique({ where: { path: "/faq" } });
  return {
    title: page?.title || "FAQ — Iniyaval Return Gifts",
    description:
      page?.description ||
      "Answers to common questions about ordering, personalization, shipping, payment, and returns at Iniyaval Return Gifts.",
  };
}

const FAQS: { q: string; a: ReactNode }[] = [
  {
    q: "Do you deliver across India and internationally?",
    a: "Yes — we ship across India and internationally from Tiruchirappalli, Tamil Nadu. International delivery times vary by destination and we'll share an estimate when you place that order.",
  },
  {
    q: "Is there a minimum order quantity?",
    a: "It depends on the product — many personalized and return-gift items have a minimum order quantity shown on the product page, since personalization is usually done per batch. You can't check out below that quantity.",
  },
  {
    q: "Can I personalize my order?",
    a: (
      <>
        Many products have a personalization field for a name, initials, or a short message right on the product page.
        For a custom photo print, logo, or your own design idea,{" "}
        <a href={whatsappLink("Hi! I'd like to ask about a custom design.")} target="_blank" rel="noopener noreferrer" className="text-rose-700 hover:underline">
          WhatsApp us
        </a>{" "}
        and we&apos;ll work it out with you directly.
      </>
    ),
  },
  {
    q: "How is shipping calculated?",
    a: "Shipping is calculated by the weight of your order and shown before you pay — no surprises at the end. Orders above a certain value ship free; the exact threshold is shown on the checkout page.",
  },
  {
    q: "How long does delivery take?",
    a: (
      <>
        Standard items are usually packed and handed to our courier within 2–3 business days, with delivery taking a
        further 4–8 business days within India. Personalized or bulk/corporate orders can take longer depending on
        quantity and design complexity — see our{" "}
        <Link href="/shipping-policy" className="text-rose-700 hover:underline">
          Shipping Policy
        </Link>{" "}
        for details.
      </>
    ),
  },
  {
    q: "What payment methods do you accept?",
    a: "We use Razorpay for secure checkout, which supports UPI, credit/debit cards, netbanking, and wallets.",
  },
  {
    q: "Can I track my order?",
    a: (
      <>
        Yes — use{" "}
        <Link href="/track-order" className="text-rose-700 hover:underline">
          Track Order
        </Link>{" "}
        with your order number and email, or check your order history if you&apos;re signed in under{" "}
        <Link href="/account" className="text-rose-700 hover:underline">
          My Account
        </Link>
        .
      </>
    ),
  },
  {
    q: "What if an item arrives damaged or wrong, or I want to return something?",
    a: (
      <>
        Contact us within 48 hours of delivery with your order number and photos if something arrived damaged,
        defective, or incorrect, and we&apos;ll arrange a replacement or refund. Unused standard (non-personalized)
        items can be returned within 7 days. Because personalized items are made specifically for you, they can only
        be returned for a genuine printing error or defect on our part. Full details are in our{" "}
        <Link href="/return-refund-policy" className="text-rose-700 hover:underline">
          Return &amp; Refund Policy
        </Link>
        .
      </>
    ),
  },
  {
    q: "Do you handle bulk or corporate gifting orders?",
    a: (
      <>
        Yes — browse{" "}
        <Link href="/shop?category=corporate-bulk-gifts" className="text-rose-700 hover:underline">
          Corporate &amp; Bulk Gifting
        </Link>
        , or{" "}
        <a href={whatsappLink("Hi! I'd like a quote for a bulk/corporate order.")} target="_blank" rel="noopener noreferrer" className="text-rose-700 hover:underline">
          WhatsApp us
        </a>{" "}
        for a quote — larger quantities are often eligible for a bulk discount.
      </>
    ),
  },
  {
    q: "How can I reach you with a question that's not covered here?",
    a: (
      <>
        WhatsApp us at {SITE.whatsappDisplay}, email {SITE.email}, or visit our{" "}
        <Link href="/contact" className="text-rose-700 hover:underline">
          Contact
        </Link>{" "}
        page.
      </>
    ),
  },
];

export default function FaqPage() {
  return (
    <div className="mx-auto max-w-2xl px-4 py-14 sm:px-6">
      <h1 className="font-[family-name:var(--font-heading)] text-2xl font-bold text-stone-800">Frequently Asked Questions</h1>
      <p className="mt-1 text-sm text-stone-500">Common questions about ordering, personalization, shipping, payment, and returns.</p>

      <div className="mt-6 divide-y divide-rose-100 rounded-lg border border-rose-100 bg-white">
        {FAQS.map((item) => (
          <details key={item.q} className="group p-4 open:bg-rose-50/30">
            <summary className="flex cursor-pointer list-none items-center justify-between gap-3 text-sm font-medium text-stone-800">
              {item.q}
              <span className="shrink-0 text-rose-700 transition-transform group-open:rotate-45">+</span>
            </summary>
            <div className="mt-2 text-sm leading-relaxed text-stone-600">{item.a}</div>
          </details>
        ))}
      </div>
    </div>
  );
}
