import type { Metadata } from "next";
import { PageHero } from "@/components/PageHero";
import { LegalContents } from "@/components/legal/LegalContents";
import { site } from "@/lib/site";

const description = `These terms explain the rules for using the ${site.name} website and services.`;

export const metadata: Metadata = {
  title: "Terms & Conditions",
  description,
  openGraph: { title: `Terms & Conditions | ${site.name}`, description },
  twitter: { title: `Terms & Conditions | ${site.name}`, description },
};

type TermsSection = {
  id: string;
  heading: string;
  intro: readonly string[];
  bullets?: readonly string[];
  outro?: readonly string[];
  email?: string;
};

const domain = site.domain.toLowerCase();

const sections: readonly TermsSection[] = [
  {
    id: "introduction",
    heading: "Introduction",
    intro: [
      `These Terms & Conditions apply to your use of the ${site.name} website and ${site.name} services available through the website. By using the site and services provided by ${site.name}, you agree to these terms.`,
      "Should you disagree with these terms, you are advised against using the website and related services.",
    ],
  },
  {
    id: "about-gptdefend",
    heading: `About ${site.name}`,
    intro: [
      "The platform uses AI-based technology for digital security and aims to provide users with information about security activities and protect the user from any threat.",
      `Terms applicable to ${site.name} products, features, capabilities, or services available through this website are as follows:`,
    ],
  },
  {
    id: "using-gptdefend",
    heading: `Using ${site.name}`,
    intro: [
      `You agree to use the ${site.name} service solely for lawful purposes in compliance with the Terms and Conditions.`,
      "You are prohibited from:",
    ],
    bullets: [
      `Attempting unauthorized access to the ${site.name} system and service`,
      "Disrupting the operation of the website or the products",
      "Uploading malicious code, harmful files, and other destructive contents",
      "Trying to circumvent security measures and restrictions",
      `Using ${site.name} for any unlawful purposes and violation of rights`,
      `Copying, modifying, distributing, or exploiting ${site.name} content without permission`,
    ],
    outro: [`${site.name} reserves the right to limit access to the system if required.`],
  },
  {
    id: "gptdefend-features",
    heading: `${site.name} Features`,
    intro: [
      `${site.name} may contain security capabilities like threat detection, security notifications, AI-powered analysis, handling of suspicious items, and related protection capabilities.`,
      "Features and capabilities may vary based on the product, plan, device, operating system, or any other applicable conditions.",
      `You are responsible for reviewing the information provided by the product or the plan you use from ${site.name}.`,
    ],
  },
  {
    id: "ai-powered-information",
    heading: "AI-Powered Information",
    intro: [
      `${site.name} may utilize AI-powered capabilities to help interpret security information and provide proper context.`,
      "Information generated or processed through AI should be understood as part of the security experience and is not intended as a guaranteed method of detecting and interpreting all threats, security incidents, and risks.",
      "Security decisions should be made responsibly and with consideration of the information at your disposal.",
    ],
  },
  {
    id: "security-and-protection",
    heading: "Security and Protection",
    intro: [
      `The ${site.name} technology is intended to assist you in protecting your supported devices, as well as providing information on security in understandable form. Nevertheless, there is no such technology, product, or antivirus that can provide you with protection from all types of potential threats.`,
      `The ${site.name} technology is not intended to act as a warranty for the absence of viruses, breaches, losses, or any other security-related issues.`,
      "It is your responsibility to ensure that your device is properly secured and protected at all times.",
    ],
  },
  {
    id: "accounts-and-information",
    heading: "Accounts and Information",
    intro: [
      `Some of the features or services provided by ${site.name} might require you to share certain information or create an account. You are responsible for sharing correct information wherever needed and for ensuring the safety of any account details you may have.`,
      `In case you think that your account details have been compromised, you should inform ${site.name} using the provided methods of contact.`,
    ],
  },
  {
    id: "plans-and-payments",
    heading: "Plans and Payments",
    intro: [
      `Whenever there is a paid plan or some paid service provided by ${site.name}, all the necessary pricing, features, billing terms, and conditions will be shown to you along with the plan or service.`,
      "Your usage of the paid service can be further governed by terms provided during the purchasing process.",
    ],
  },
  {
    id: "intellectual-property",
    heading: "Intellectual Property",
    intro: [
      `The ${site.name} trademark, logo, software, site structure, text, graphics, interfaces, and all other content related to ${site.name} are protected under relevant intellectual property laws.`,
      `Unless explicitly authorized, you may not copy, edit, distribute, sell, rent, decompile, or otherwise misuse the content or services provided by ${site.name}. The use of ${site.name} intellectual property is not transferred to you by these Terms and Conditions.`,
    ],
  },
  {
    id: "third-party-services",
    heading: "Third-Party Services",
    intro: [
      `${site.name} may link or refer to third-party websites, services, software, or technology. Third-party services may have their own rules and policies. ${site.name} has no control over third-party services.`,
    ],
  },
  {
    id: "privacy",
    heading: "Privacy",
    intro: [
      `The use of ${site.name} could include the collection and/or processing of information as provided in our Privacy Policy and Cookie Policy. These Policies are part of the information relating to your use of the ${site.name} website and services.`,
    ],
  },
  {
    id: "availability-and-changes",
    heading: "Availability and Changes",
    intro: [
      `${site.name} reserves the right to change, modify, suspend, or discontinue services or portions of the Website at any time.`,
      "We cannot guarantee that all features or services will be available at all times, without interruption or error.",
      "We can also amend these Terms & Conditions from time to time. You will be able to see this through the Last updated date of this page.",
    ],
  },
  {
    id: "contact-us",
    heading: "Contact Us",
    intro: [`If you have questions about these Terms & Conditions, please contact us at:`],
    email: `legal@${domain}`,
  },
];

export default function TermsPage() {
  return (
    <>
      <PageHero
        title="Our Terms &"
        accent="Conditions"
        lead={
          <>
            Last updated: Sep 30, 2026
            <br className="d-none d-md-block" />
            These terms explain the rules for using the {site.name} website and
            services.
          </>
        }
      />

      <section className="webContent py-4 py-lg-5">
        <div className="container">
          <div className="row g-4 g-xl-5">
            <div className="d-none d-lg-block col-12 col-lg-4 col-xl-3">
              <LegalContents
                sections={sections.map(({ id, heading }) => ({
                  id,
                  heading,
                  body: [],
                }))}
              />
            </div>
            <div className="col-12 col-lg-8 col-xl-9">
              {sections.map((section) => (
                <article className="legal-section" id={section.id} key={section.id}>
                  {(() => {
                    const bullets = section.bullets;
                    return (
                      <>
                  <div className="legal-section-head">
                    <h2 className="text-xl fw-600 mb-0">{section.heading}</h2>
                  </div>
                  {section.intro.map((paragraph, index) => (
                    <p className="text-md fw-400 mb-0" key={`${section.id}-intro-${index}`}>
                      {paragraph}
                    </p>
                  ))}
                  {bullets ? (
                    <ul className="legal-list text-md fw-400">
                      {bullets.map((item, index) => (
                        <li key={`${section.id}-bullet-${index}`}>{item}</li>
                      ))}
                    </ul>
                  ) : null}
                  {section.outro?.map((paragraph, index) => (
                    <p className="text-md fw-400 mb-0" key={`${section.id}-outro-${index}`}>
                      {paragraph}
                    </p>
                  ))}
                  {section.email ? (
                    <p className="text-md fw-400 mb-0">
                      <a href={`mailto:${section.email}`}>{section.email}</a>
                    </p>
                  ) : null}
                      </>
                    );
                  })()}
                </article>
              ))}
            </div>
          </div>
        </div>
      </section>
    </>
  );
}
