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

const description = `General legal terms and conditions for using the ${site.name} website and related services.`;

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

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

const domain = site.domain.toLowerCase();

const sections: readonly LegalSection[] = [
  {
    id: "introduction",
    heading: "Introduction",
    intro: [
      "By accessing or using the website, you agree to abide by these Legal Policies and all other policies or notices that may be posted on the site.",
      `If you do not agree with the terms herein, you should refrain from using the website or other services by ${site.name}.`,
    ],
  },
  {
    id: "about-gptdefend",
    heading: `About ${site.name}`,
    intro: [
      `${site.name} is an antivirus concept that utilizes AI and emphasizes simplification of digital security. The information found on this website might provide you with ideas about the current product concepts, as well as the features that are still to come. The content found on this website should not be viewed as any guarantee regarding availability of a certain feature or functionality.`,
    ],
  },
  {
    id: "use-of-the-website",
    heading: "Use of the Website",
    intro: [
      `You consent to access the ${site.name} site solely for lawful purposes and in such a manner that it will neither affect nor endanger its proper functioning.`,
      "You shall not:",
    ],
    bullets: [
      "Seek to breach unauthorized access to the website and its systems",
      "Inject any malicious code, software, or other dangerous material",
      "Abuse forms, interactive tools, and other website features",
      "Distribute or alter site contents without authorization",
      "Violate any laws by using the website or other services",
    ],
    outro: ["Your access to the site can be blocked to protect it and its users or systems."],
  },
  {
    id: "website-content",
    heading: "Website Content",
    intro: [
      `${site.name} will strive to make the website content accurate and meaningful. Nevertheless, website information is subject to modification, deletion, and updating at any time.`,
      "The descriptions, features, images, screenshots, and other information contained herein represent conceptual functions and do not guarantee the availability of future products.",
    ],
  },
  {
    id: "intellectual-property",
    heading: "Intellectual Property",
    intro: [
      `Unless otherwise stated, the trademarks, brand names, contents of the website, images, designs, text, and other materials provided on the website are either owned or licensed to ${site.name} and are covered under applicable intellectual property laws.`,
      "You are allowed to view and use the website for its intended purposes. However, you are not permitted to copy, publish, alter, distribute, or commercialize the website materials without permission.",
    ],
  },
  {
    id: "third-party-content-and-services",
    heading: "Third-Party Content and Services",
    intro: [
      `The ${site.name} website can have references and links to other external third-party websites, services, or resources.`,
      `These third-party services function independently of ${site.name}. The availability, contents, privacy policies, and terms governing third parties are managed by the third parties themselves.`,
      `${site.name} is not liable for any third-party websites and services beyond its control.`,
    ],
  },
  {
    id: "no-guarantee-of-availability",
    heading: "No Guarantee of Availability",
    intro: [
      "We may change, update, suspend, or discontinue parts of the website at any time.",
      "We do not guarantee that the website or every feature will always be available, uninterrupted, or error-free. Maintenance, updates, technical issues, or circumstances outside our reasonable control may affect availability.",
    ],
  },
  {
    id: "security-information",
    heading: "Security Information",
    intro: [
      `The security information available on the ${site.name} website is meant to help users comprehend the product and the way it offers protection from various digital threats.`,
      "The security information cannot be viewed as an assurance that any device, file, account, network, or computer will be absolutely safe from any possible threats. No security solution can offer complete protection from all threats.",
    ],
  },
  {
    id: "limitation-of-liability",
    heading: "Limitation of Liability",
    intro: [
      `To the fullest extent allowed under applicable laws, ${site.name} shall not be liable for any losses and/or damages that result from your access to and/or use of the website and the information provided via it.`,
      "Nothing in this disclaimer shall be deemed to exclude or limit liability to the extent it is not allowed under applicable laws.",
    ],
  },
  {
    id: "changes-to-this-policy",
    heading: "Changes to This Policy",
    intro: [
      `We may update this Legal Policy from time to time to reflect changes to the website. This Legal Policy can be modified at times to accommodate any modifications to the website or our services.`,
      "Any modifications made would be reflected on the \u2018Last Updated\u2019 date on this page. Your continued use of the website after the revised Legal Policy comes into effect indicates your acceptance of the new terms, within the limits of the applicable law.",
    ],
  },
  {
    id: "other-policies",
    heading: "Other Policies",
    intro: [
      `Additional policies may apply to specific aspects of the ${site.name} website or services, including our:`,
    ],
    bullets: ["Privacy Policy", "Cookie Policy", "Terms of Service, where applicable"],
    outro: ["These policies should be read together where they apply."],
  },
  {
    id: "contact",
    heading: "Contact",
    intro: [
      `If you have questions about this Legal Policy or the information presented on the ${site.name} website, please contact us at:`,
    ],
    email: `legal@${domain}`,
  },
];

export default function LegalPage() {
  return (
    <>
      <PageHero
        title="Our Legal"
        accent="Policy"
        lead={
          <>
            Last updated: Sep 30, 2026
            <br className="d-none d-md-block" />
            This Legal Policy contains the general terms and conditions
            applicable to you when accessing or using the website and its
            associated online 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>
    </>
  );
}
