import type { Metadata } from "next";
import { getPublicPageSeo } from "@/lib/public-page-seo";
import { resolveOgImageUrl } from "@/lib/site-og-image";

const SITE_URL = (process.env.NEXT_PUBLIC_SITE_URL || "https://nizamify.com").replace(/\/$/, "");

export async function generateMetadata(): Promise<Metadata> {
  const seo = await getPublicPageSeo("terms");
  const title = seo?.metaTitle?.trim() || seo?.title?.trim() || "Terms & Conditions";
  const description =
    seo?.metaDescription?.trim() ||
    "Read the terms and conditions for using Nizamify products, services, and website.";
  const canonical = "/terms";
  const keywords =
    Array.isArray(seo?.metaKeywords) && seo.metaKeywords.length > 0
      ? seo.metaKeywords
      : ["Nizamify terms and conditions"];
  const image = resolveOgImageUrl(seo?.image);

  return {
    title,
    description,
    keywords,
    alternates: { canonical },
    openGraph: {
      title,
      description,
      url: `${SITE_URL}${canonical}`,
      type: "website",
      images: [{ url: image }],
    },
    twitter: {
      card: "summary_large_image",
      title,
      description,
      images: [image],
    },
  };
}

export default function TermsPage() {
  return (
    <section className="bg-slate-50 pb-10 pt-3">
      <div className="container">
        <div className="mx-auto max-w-4xl rounded-xl border bg-white p-6 shadow-sm md:p-10">
          <h1 className="text-3xl font-bold text-slate-900 md:text-4xl">Terms &amp; Conditions</h1>
          <p className="mt-2 text-sm text-slate-600">
            Last updated: May 7, 2026
          </p>

          <div className="prose prose-slate mt-5 max-w-none">
            <p>
              These Terms &amp; Conditions (&quot;Terms&quot;) govern your access to and use of the
              Nizamify website and services (&quot;Service&quot;). By using the Service, you agree to
              these Terms.
            </p>

            <h2>1. Use of the Service</h2>
            <ul>
              <li>You must provide accurate information when contacting us or placing an order.</li>
              <li>You agree not to misuse the Service, attempt unauthorized access, or disrupt operations.</li>
            </ul>

            <h2>2. Products &amp; Pricing</h2>
            <p>
              Product availability, specifications, pricing, promotions, and delivery fees may change
              without notice. We may correct errors in pricing or product information.
            </p>

            <h2>3. Orders, Payments, and Delivery</h2>
            <p>
              Order acceptance is subject to confirmation. Delivery timelines are estimates and may
              vary based on location and courier performance.
            </p>

            <h2>4. Returns &amp; Warranty</h2>
            <p>
              Return and warranty eligibility depends on the product category and condition. For help,
              contact us and include your order details.
            </p>

            <h2>5. Intellectual Property</h2>
            <p>
              All content on this website (including text, images, and logos) is owned by Nizamify or
              its licensors and may not be used without permission.
            </p>

            <h2>6. Limitation of Liability</h2>
            <p>
              To the maximum extent permitted by law, Nizamify is not liable for indirect or consequential
              damages arising from use of the Service.
            </p>

            <h2>7. Changes to These Terms</h2>
            <p>
              We may update these Terms from time to time. Continued use of the Service means you accept
              the updated Terms.
            </p>

            <h2>8. Contact</h2>
            <p>
              If you have questions about these Terms, please reach us via the{" "}
              <a href="/contact-us">Contact Us</a> page.
            </p>
          </div>
        </div>
      </div>
    </section>
  );
}