import Link from "next/link";
import PageHeader from "@/components/ui/PageHeader";
import { getSiteConfig } from "@/lib/api/site";

export const metadata = {
  title: "Return & Cancellation Policy | Biznie",
  description: "Biznie's return, cancellation and refund policy for B2B raw material orders.",
};

type Section = { title: string; body: string | string[] };

/*
  Used only until Admin -> Website Setup -> Returns Policy has content. The
  cancellation rule is the same setting the Terms and checkout show (4.1);
  the "free within 24 hours" and "2% restocking fee" lines contradicted the
  published Terms and are gone.
*/
const sections = (bookingPolicy: string): Section[] => [
  {
    title: "Order Cancellation",
    body: [
      bookingPolicy,
      "Custom-cut, custom-blended or made-to-order materials are non-cancellable once processing begins.",
    ],
  },
  {
    title: "Material Returns",
    body: [
      "Material that does not match agreed specifications (grade, quantity, dimension) is eligible for return within 7 days of delivery.",
      "Damaged-in-transit material must be reported within 48 hours with photo evidence and Proof of Delivery (POD).",
      "Returns for change of mind, market price changes, or buyer's project changes are not accepted.",
    ],
  },
  {
    title: "Steel-Specific Terms",
    body: [
      "Weight: the loading-point weighbridge slip is the billing weight. A difference at destination beyond the tolerance agreed on the order is settled by re-weighment at an approved weighbridge.",
      "Mill Test Certificate: material whose grade or heat number does not match its MTC is treated as non-conforming and is eligible for return or replacement.",
      "Rust: light surface rust and mill scale are normal for hot-rolled steel and are not a defect. Pitting or rust that reduces section or weight must be reported within 48 hours of delivery with photos.",
    ],
  },
  {
    title: "Quality Disputes",
    body: "Quality disputes are resolved through joint inspection or third-party laboratory testing. The party at fault bears the testing cost. Replacement or refund is issued within 7 working days of dispute resolution.",
  },
  {
    title: "Refund Process",
    body: [
      "Refunds for cancelled or returned orders are processed within 7 working days to the original payment source.",
      "Wallet refunds are instant.",
      "Bank refunds may take 3–5 additional working days based on your bank.",
    ],
  },
  {
    title: "Non-Returnable Items",
    body: [
      "Items used, consumed or processed after delivery.",
      "Custom-blended chemicals or pre-cut steel/sheets.",
      "Bulk perishable agri commodities after acceptance.",
      "Items returned without original invoice or packaging.",
    ],
  },
  {
    title: "How to Request a Return",
    body: "Log in to your dashboard → Orders → select the order → click 'Raise Return / Dispute'. Our team will respond within 24 hours.",
  },
];

export default async function ReturnPolicyPage() {
  const site = await getSiteConfig({ next: { revalidate: 300 } });

  return (
    <div className="min-h-screen bg-gray-50">
      <PageHeader title="Return & Cancellation Policy" subtitle="Fair, transparent terms for every order." />

      <div className="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8 py-12 space-y-6">
        {site.returnsPolicy ? (
          // The admin-managed policy, with {{booking_policy}} and other tokens filled in.
          <div
            className="prose prose-sm max-w-none rounded-2xl border border-gray-100 bg-white p-7 shadow-sm"
            dangerouslySetInnerHTML={{ __html: site.returnsPolicy }}
          />
        ) : sections(site.legal.bookingPolicy).map((section) => (
          <div key={section.title} className="bg-white rounded-2xl border border-gray-100 shadow-sm p-7">
            <h2 className="text-lg font-black text-gray-900 mb-3">{section.title}</h2>
            {Array.isArray(section.body) ? (
              <ul className="list-disc pl-5 space-y-1.5 text-gray-600 text-sm leading-relaxed">
                {section.body.map((item, i) => (
                  <li key={i}>{item}</li>
                ))}
              </ul>
            ) : (
              <p className="text-gray-600 leading-relaxed text-sm">{section.body}</p>
            )}
          </div>
        ))}

        <div className="bg-gradient-to-r from-[#CC1414] to-[#8B0000] text-white rounded-2xl p-6 text-center">
          <h3 className="font-bold mb-1">Need help with a return?</h3>
          <p className="text-red-100 text-sm mb-4">Our support team is available Mon–Sat, 9 AM – 7 PM.</p>
          <Link
            href="/contact"
            className="inline-block bg-white text-[#CC1414] font-semibold px-6 py-2.5 rounded-lg hover:bg-gray-100 transition-colors text-sm"
          >
            Contact Support
          </Link>
        </div>
      </div>
    </div>
  );
}
