import type { Metadata } from "next";
import Link from "next/link";
import { ArrowLeft, FileText } from "lucide-react";
import { LogoIcon } from "@/components/ui/logo";

export const metadata: Metadata = {
  title: "Terms of Service | IIH Notetaker",
  description: "Terms for using IIH Notetaker meeting transcription and summary features.",
};

const sections = [
  {
    title: "Use of the Service",
    items: [
      "You may use IIH Notetaker to create meeting records, recordings, transcripts, summaries, and action items for lawful business purposes.",
      "You must keep your account secure and use the service only with meeting links, calendar events, and content you are authorized to process.",
      "You may not misuse the service, attempt unauthorized access, interfere with the platform, or upload unlawful, harmful, or infringing content.",
    ],
  },
  {
    title: "Recording Responsibilities",
    items: [
      "You are responsible for telling meeting participants when a meeting is being recorded or transcribed.",
      "You must obtain consent where required by applicable law, company policy, or the meeting platform's rules.",
      "You should not use the service for sensitive meetings unless your organization has approved that use.",
    ],
  },
  {
    title: "Meeting Content",
    items: [
      "You retain responsibility for the meeting links, recordings, transcripts, summaries, action items, and other content created through your account.",
      "AI-generated summaries may contain mistakes or omissions and should be reviewed before relying on them for important decisions.",
      "Do not treat transcripts or summaries as legal, medical, financial, or professional advice.",
    ],
  },
  {
    title: "Third-Party Platforms",
    items: [
      "The service may connect with meeting, identity, transcription, storage, hosting, and AI providers.",
      "Your use of third-party platforms such as Google Meet, Microsoft Teams, Zoom, Jitsi, third-party transcription services, or OpenAI may also be governed by their own terms.",
      "We are not responsible for third-party outages, policy changes, or platform limitations that affect recording or transcription.",
    ],
  },
  {
    title: "Availability and Changes",
    items: [
      "The service may change over time as features, providers, or security requirements evolve.",
      "We may suspend or restrict access if needed to protect the service, comply with law, or address misuse.",
    ],
  },
  {
    title: "Limitation of Liability",
    items: [
      "The service is provided as available, and meeting transcripts or summaries may not always be complete, accurate, or timely.",
      "To the maximum extent permitted by law, liability is limited for indirect, incidental, consequential, special, or business interruption damages.",
    ],
  },
  {
    title: "Governing Law",
    items: [
      "These Terms are governed by applicable law. Disputes will be resolved in the jurisdiction where the service operator is established.",
    ],
  },
];

export default async function TermsOfServicePage({
  searchParams,
}: {
  searchParams: Promise<{ from?: string }>;
}) {
  const resolvedSearchParams = await searchParams;
  const from = resolvedSearchParams.from || "/";
  const isBack = !!resolvedSearchParams.from;

  return (
    <main className="min-h-screen bg-gray-50 px-4 py-8 text-gray-900 dark:bg-gray-950 dark:text-gray-100 sm:px-6 lg:px-8">
      <div className="mx-auto max-w-3xl space-y-6">
        <div className="flex items-center justify-between gap-4">
          <Link
            href={from}
            className="inline-flex items-center gap-2 text-sm font-medium text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100"
          >
            <ArrowLeft className="h-4 w-4" />
            {isBack ? "Back" : "Back to homepage"}
          </Link>
          <div className="flex items-center gap-2">
            <LogoIcon size={28} />
            <span className="text-sm font-semibold">IIH Notetaker</span>
          </div>
        </div>

        <section className="rounded-xl border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-800 dark:bg-gray-900 sm:p-8">
          <div className="mb-8 flex items-start gap-3">
            <div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-blue-50 dark:bg-blue-950">
              <FileText className="h-5 w-5 text-blue-600 dark:text-blue-400" />
            </div>
            <div>
              <p className="text-sm font-medium text-blue-600 dark:text-blue-400">Last updated: June 1, 2026</p>
              <h1 className="mt-1 text-2xl font-bold tracking-tight sm:text-3xl">Terms of Service</h1>
              <p className="mt-3 text-sm leading-6 text-gray-600 dark:text-gray-400">
                These terms describe the basic rules for using IIH Notetaker for meeting recording,
                transcription, summaries, and action item tracking.
              </p>
            </div>
          </div>

          <div className="space-y-7">
            {sections.map((section) => (
              <section key={section.title} className="space-y-3">
                <h2 className="text-base font-semibold">{section.title}</h2>
                <ul className="list-disc space-y-2 pl-5 text-sm leading-6 text-gray-600 dark:text-gray-400">
                  {section.items.map((item) => (
                    <li key={item}>{item}</li>
                  ))}
                </ul>
              </section>
            ))}
          </div>

          <div className="mt-8 rounded-lg border border-gray-200 bg-gray-50 p-4 text-sm leading-6 text-gray-600 dark:border-gray-800 dark:bg-gray-950 dark:text-gray-400">
            These Terms are publicly available before sign-in and should match the Terms of Service URL configured on
            the Google OAuth consent screen.
          </div>
        </section>
      </div>
    </main>
  );
}
