"use client";

import React from "react";
import Link from "next/link";
import Image from "next/image";
import {
  ArrowLeft,
  Shield,
  Lock,
  HardDrive,
  Cpu,
  CreditCard,
  Server,
  UserCheck,
  FileCheck2,
  CheckCircle2,
  ExternalLink,
} from "lucide-react";
import { useI18n } from "@/lib/i18n/context";
import { LanguageSwitch } from "@/components/common/LanguageSwitch";
import { Footer } from "@/components/landing/Footer";

export default function PrivacyPage() {
  const { language } = useI18n();
  const isDe = language === "de";

  return (
    <div className="min-h-screen bg-[#F6F9FF] flex flex-col justify-between font-sans text-[#161C22]">
      {/* Top Sticky Header */}
      <header className="sticky top-0 z-40 w-full bg-[#F6F9FF]/95 backdrop-blur-md border-b border-[#E2E8F0]">
        <div className="max-w-[1440px] mx-auto px-4 sm:px-8 h-20 flex items-center justify-between">
          <Link href="/" className="flex items-center gap-3 group">
            <div className="w-10 h-10 bg-white border-2 border-black p-1 shadow-xs overflow-hidden flex items-center justify-center shrink-0 transition-transform group-hover:scale-95">
              <Image
                src="/app-icon-original.png"
                alt="ScanReceipts logo"
                width={40}
                height={40}
                className="w-full h-full object-contain"
                priority
              />
            </div>
            <div className="flex flex-col">
              <span className="font-display font-black text-lg tracking-tight text-black leading-none">
                SCANRECEIPTS
              </span>
              <span className="font-mono text-[10px] uppercase tracking-caps text-[#475569] font-medium mt-0.5">
                Privacy & Data Governance
              </span>
            </div>
          </Link>

          <div className="flex items-center gap-4">
            <LanguageSwitch />
            <Link
              href="/"
              className="hidden sm:inline-flex items-center gap-1.5 font-mono text-xs uppercase tracking-caps px-3 py-2 border border-[#E2E8F0] bg-white text-black hover:border-black transition-colors"
            >
              <ArrowLeft className="w-3.5 h-3.5" />
              <span>{isDe ? "Zur Startseite" : "Back to Home"}</span>
            </Link>
          </div>
        </div>
      </header>

      {/* Main Content */}
      <main className="max-w-5xl w-full mx-auto px-4 sm:px-8 py-10 sm:py-16 flex-1">
        {/* Breadcrumb & Meta */}
        <div className="flex flex-wrap items-center justify-between gap-4 mb-8">
          <div className="flex items-center gap-2 font-mono text-xs text-[#64748B] uppercase tracking-caps">
            <Link href="/" className="hover:text-black transition-colors">
              HOME
            </Link>
            <span>/</span>
            <span className="text-black font-bold">PRIVACY POLICY</span>
          </div>

          <div className="flex items-center gap-2 font-mono text-[11px] bg-white border border-[#E2E8F0] px-3 py-1 text-[#475569]">
            <span className="w-2 h-2 rounded-full bg-emerald-500 animate-pulse"></span>
            <span>LAST UPDATED: AUGUST 2026 (UNITED STATES)</span>
          </div>
        </div>

        {/* Hero Title Section */}
        <div className="bg-white border border-[#CBD5E1] p-6 sm:p-10 mb-10 shadow-xs relative overflow-hidden">
          <div
            className="absolute inset-0 opacity-[0.25] pointer-events-none"
            style={{
              backgroundImage: `radial-gradient(#94A3B8 1px, transparent 1px)`,
              backgroundSize: "16px 16px",
            }}
          />

          <div className="relative z-10 space-y-3">
            <div className="inline-flex items-center gap-2 px-2.5 py-1 bg-[#F8FAFC] border border-[#E2E8F0] font-mono text-[11px] uppercase tracking-caps font-semibold text-black">
              <Shield className="w-3.5 h-3.5 text-black" />
              <span>US Privacy Governance & Secure Data Custody</span>
            </div>

            <h1 className="font-display text-3xl sm:text-4xl lg:text-5xl font-black tracking-tight text-black">
              Privacy Policy
            </h1>

            <p className="text-sm sm:text-base text-[#475569] max-w-3xl leading-relaxed">
              This Privacy Policy explains how ScanReceipts handles information when you use our AI-powered optical character recognition (OCR) and receipt processing software. We do not sell your personal data.
            </p>
          </div>
        </div>

        {/* Quick Overview Badges */}
        <div className="grid grid-cols-1 sm:grid-cols-3 gap-4 mb-10 font-mono text-xs">
          <div className="bg-white border border-[#E2E8F0] p-4 flex items-start gap-3">
            <HardDrive className="w-5 h-5 text-emerald-600 shrink-0 mt-0.5" />
            <div>
              <div className="font-bold text-black uppercase tracking-caps">
                Secure Account Storage
              </div>
              <div className="text-[11px] text-[#64748B] mt-1">
                Receipts and financial ledgers are stored securely and scoped to your account.
              </div>
            </div>
          </div>

          <div className="bg-white border border-[#E2E8F0] p-4 flex items-start gap-3">
            <Cpu className="w-5 h-5 text-black shrink-0 mt-0.5" />
            <div>
              <div className="font-bold text-black uppercase tracking-caps">
                Zero AI Model Training
              </div>
              <div className="text-[11px] text-[#64748B] mt-1">
                Receipt images are processed transiently and never used to train public AI models.
              </div>
            </div>
          </div>

          <div className="bg-white border border-[#E2E8F0] p-4 flex items-start gap-3">
            <Lock className="w-5 h-5 text-black shrink-0 mt-0.5" />
            <div>
              <div className="font-bold text-black uppercase tracking-caps">
                TLS 1.3 Encryption
              </div>
              <div className="text-[11px] text-[#64748B] mt-1">
                End-to-end encrypted API pipelines for all processing requests.
              </div>
            </div>
          </div>
        </div>

        {/* Content Sections */}
        <div className="space-y-8">
          {/* Section 1: Data Controller / Entity */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <UserCheck className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                1. Service Operator &amp; Contact
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-2">
              <p>
                The Service is operated by ScanReceipts Systems (&quot;ScanReceipts,&quot; &quot;we,&quot; &quot;us,&quot; or &quot;our&quot;). If you have questions regarding this Privacy Policy or your data, please contact:
              </p>
              <div className="p-4 bg-[#F8FAFC] border border-[#E2E8F0] font-mono text-xs space-y-1">
                <div className="font-bold text-black text-sm">ScanReceipts Privacy Operations</div>
                <div>Email: <a href="mailto:privacy@scan-receipts.app" className="text-black font-semibold underline">privacy@scan-receipts.app</a></div>
                <div>Support: <a href="mailto:support@scan-receipts.app" className="text-black font-semibold underline">support@scan-receipts.app</a></div>
              </div>
            </div>
          </section>

          {/* Section 2: Account-Based Data Storage */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <HardDrive className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                2. Account-Based Data Storage
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                Extracted receipt information, line items, mathematical calculations, and generated spreadsheets are stored securely in our database, scoped to your individual account. This keeps your receipt history available whenever you sign in, from any device or browser.
              </p>
              <p>
                If you use ScanReceipts as a guest without creating an account, your receipts are still stored under a temporary, browser-specific identifier rather than a shared or public bucket. You may delete your records at any time through the application dashboard.
              </p>
            </div>
          </section>

          {/* Section 3: AI Processing & Third-Party APIs */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <Cpu className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                3. Transient AI Vision Processing
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                When you initiate a scan by uploading or photographing a receipt (JPEG, PNG, WebP, or PDF), the file payload is transmitted over an encrypted TLS 1.3 HTTPS connection to our processing backend to execute optical character recognition via commercial enterprise AI Vision APIs (such as OpenRouter, OpenAI, DeepSeek, Google Cloud Vertex, or Anthropic).
              </p>
              <ul className="list-disc pl-5 space-y-1.5 text-xs text-[#475569]">
                <li>
                  <strong className="text-black">No Training on User Data:</strong> Processing is performed strictly under commercial API terms prohibiting the retention or use of customer inputs to train public artificial intelligence models.
                </li>
                <li>
                  <strong className="text-black">Transient Processing:</strong> Document images are held in volatile server memory solely for the duration required to extract structured JSON data, and are immediately discarded upon delivery of extraction results back to your browser.
                </li>
              </ul>
            </div>
          </section>

          {/* Section 4: Stripe Payment Processing */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <CreditCard className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                4. Payment Processing (Stripe)
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                Payment processing for paid license purchases is provided by Stripe, Inc. (510 Townsend Street, San Francisco, CA 94103, USA).
              </p>
              <p>
                When you purchase a license, your payment details (credit card number, expiration date, CVV, billing address) are collected directly by Stripe via their PCI-DSS Level 1 compliant secure checkout frame. ScanReceipts never receives, processes, or stores your raw payment credentials on our servers.
              </p>
              <p>
                For more details, review Stripe&apos;s Privacy Policy at:{" "}
                <a
                  href="https://stripe.com/privacy"
                  target="_blank"
                  rel="noopener noreferrer"
                  className="text-black font-semibold underline inline-flex items-center gap-1"
                >
                  <span>https://stripe.com/privacy</span>
                  <ExternalLink className="w-3 h-3" />
                </a>
              </p>
            </div>
          </section>

          {/* Section 5: California & US State Privacy Disclosures (CCPA / CPRA) */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <FileCheck2 className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                5. State Privacy Rights (California CCPA / CPRA &amp; US States)
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                Under the California Consumer Privacy Act (CCPA), California Privacy Rights Act (CPRA), and similar state laws in Virginia, Colorado, Connecticut, and Utah:
              </p>
              <ul className="list-disc pl-5 space-y-1.5 text-xs text-[#475569]">
                <li>
                  <strong className="text-black">No Sale or Sharing of Personal Data:</strong> We do NOT sell your personal information or share it for cross-context behavioral advertising.
                </li>
                <li>
                  <strong className="text-black">Right to Know / Access:</strong> You have the right to request information regarding categories of personal information collected.
                </li>
                <li>
                  <strong className="text-black">Right to Delete:</strong> You can delete your receipt records directly from your account dashboard at any time, or request deletion of any billing metadata held by Stripe.
                </li>
                <li>
                  <strong className="text-black">Non-Discrimination:</strong> We will not deny goods, charge different prices, or provide a different level of quality if you exercise your statutory privacy rights.
                </li>
              </ul>
            </div>
          </section>

          {/* Section 6: Security & Logs */}
          <section className="bg-white border border-[#E2E8F0] p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-[#E2E8F0]">
              <Server className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                6. Security Measures &amp; Technical Logs
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                We implement industry-standard administrative, physical, and technical safeguards (including TLS 1.3 in-transit encryption) to protect data transmitted to and from the Service. Standard web server logs collect minimal connection metadata (IP address, user agent, timestamps) solely for operational diagnostics and security monitoring.
              </p>
            </div>
          </section>
        </div>
      </main>

      {/* Standard Landing Footer */}
      <Footer />
    </div>
  );
}
