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

export const metadata: Metadata = {
  title: "Privacy Policy | IIH Notetaker",
  description: "Privacy practices for IIH Notetaker meeting transcription, recording, and AI summary features.",
};

const sections = [
  {
    title: "Information We Collect",
    items: [
      "Account information from Google sign-in, such as your name, email address, and profile details provided during authentication.",
      "Meeting information you submit or sync, including meeting titles, meeting links, platform details, scheduled times, participants, and meeting status.",
      "Meeting content generated through the service, including recordings, transcripts, summaries, decisions, action items, speaker labels, and related metadata.",
      "Usage and technical data, such as browser type, device details, IP address, authentication tokens, error logs, and service activity needed to operate and secure the application.",
      "Settings and preferences, including notification choices, transcription language, calendar automation, and AI summary configuration.",
    ],
  },
  {
    title: "How We Use Information",
    items: [
      "To authenticate users and provide access to meeting notes, transcripts, recordings, and summaries.",
      "To allow the meeting bot to join supported calls, record meeting audio or video where enabled, generate transcripts, and create AI-powered summaries.",
      "To organize meeting history, search results, speaker labels, action items, notifications, and user preferences.",
      "To troubleshoot, secure, maintain, and improve the service and prevent unauthorized access or misuse.",
      "To comply with legal obligations, enforce applicable terms, and respond to valid requests from users or administrators.",
    ],
  },
  {
    title: "Google API Data and Limited Use",
    items: [
      "IIH Notetaker's use and transfer of information received from Google APIs follows the Google API Services User Data Policy, including the Limited Use requirements.",
      "Google account information is used to authenticate users and connect them to the correct IIH Notetaker account.",
      "Calendar event information, when enabled, is used only to identify meetings selected for recording, transcription, summaries, and related meeting automation.",
      "Calendar data accessed via calendar.readonly is used exclusively to identify meetings the user has selected for recording. It is never used for advertising, profiling, or any secondary purpose.",
      "We do not sell Google user data, use it for advertising, or use it to train general-purpose AI models.",
    ],
  },
  {
    title: "Meeting Recording and Consent",
    items: [
      "The service may record meeting audio or video when a bot is admitted to a meeting and recording is started.",
      "You are responsible for notifying participants and obtaining any consent required by your organization, meeting platform, or applicable law before recording or transcribing a meeting.",
      "The bot appears as a participant when it joins a call. If a host denies entry or recording is stopped, transcription may not be generated.",
    ],
  },
  {
    title: "Sharing and Third-Party Services",
    items: [
      "We do not sell your meeting content.",
      "We may process information through trusted providers that support authentication, calendar access, meeting platforms, recording, transcription, AI summaries, hosting, storage, and analytics.",
      "Supported meeting and identity services may include Google, Microsoft Teams, Zoom, Jitsi, third-party meeting transcription bots, and configured AI providers such as OpenAI.",
      "Administrators or authorized users in your organization may be able to access meeting records depending on how the application is configured.",
    ],
  },
  {
    title: "Data Retention and Deletion",
    items: [
      "Meeting records, recordings, transcripts, summaries, and settings are kept for as long as needed to provide the service or as configured by your organization.",
      "Users may delete meeting data through available product controls. Some records may remain temporarily in backups, logs, or audit systems where required for security or legal reasons.",
      "If you need deletion or export beyond in-product controls, contact your organization administrator or support contact.",
    ],
  },
  {
    title: "Security",
    items: [
      "We use authentication, access controls, transport security, and operational safeguards designed to protect account and meeting data.",
      "No internet service can guarantee complete security. Keep your account credentials private and report suspected unauthorized access promptly.",
    ],
  },
  {
    title: "Your Choices",
    items: [
      "You can control notification, transcription, summary, and calendar automation settings from the Settings page.",
      "You can stop active recordings where the product provides that control.",
      "You can sign out to clear local authentication state from the browser.",
      "You can revoke IIH Notetaker's access to your Google account at any time by visiting https://myaccount.google.com/permissions and removing the app.",
    ],
  },
  {
    title: "Changes to This Policy",
    items: [
      "We may update this Privacy Policy when the product, providers, or legal requirements change.",
      "The latest version will be posted on this page with the updated effective date.",
    ],
  },
  {
    title: "Contact",
    items: [
      "For privacy, data deletion, or access requests, contact us at purchase@iihglobal.com.",
    ],
  },
];

export default async function PrivacyPolicyPage({
  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">
              <ShieldCheck 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">Privacy Policy</h1>
              <p className="mt-3 text-sm leading-6 text-gray-600 dark:text-gray-400">
                This policy explains how IIH Notetaker handles information when you use the app to join meetings,
                record calls, generate transcripts, and create AI meeting summaries.
              </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">
            This Privacy Policy is publicly available before sign-in and should match the Privacy Policy URL configured
            on the Google OAuth consent screen.
          </div>
        </section>
      </div>
    </main>
  );
}
