"use client";

import React from "react";
import Link from "next/link";
import Image from "next/image";
import {
  ArrowLeft,
  FileSpreadsheet,
  AlertTriangle,
  Scale,
  ShieldCheck,
  HardDrive,
  CreditCard,
  Ban,
  CheckCircle2,
  Cpu,
  Calculator,
  Gavel,
} from "lucide-react";
import { useI18n } from "@/lib/i18n/context";
import { LanguageSwitch } from "@/components/common/LanguageSwitch";
import { Footer } from "@/components/landing/Footer";

export default function TermsPage() {
  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">
                Terms of Service & Legal Disclaimers
              </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">TERMS OF SERVICE</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">
              <Scale className="w-3.5 h-3.5 text-black" />
              <span>Binding Legal Agreement & Strict Limitation of Liability</span>
            </div>

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

            <p className="text-sm sm:text-base text-[#475569] max-w-3xl leading-relaxed">
              Please read these Terms of Service carefully before using ScanReceipts. This agreement contains strict disclaimers of warranty, total limitations of liability, mandatory binding arbitration, and class action waivers.
            </p>
          </div>
        </div>

        {/* High-Impact Disclaimer Callouts */}
        <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-10">
          <div className="p-5 bg-white border-2 border-black space-y-2">
            <div className="flex items-center gap-2 text-black font-mono text-xs uppercase tracking-caps font-bold">
              <AlertTriangle className="w-4 h-4 text-black" />
              <span>AI OCR Extraction Disclaimer</span>
            </div>
            <p className="text-xs text-[#475569] leading-relaxed">
              Optical Character Recognition (OCR) and Artificial Intelligence models operate probabilistically and may generate inaccurate, incomplete, or false data. You are solely responsible for inspecting and verifying all extracted figures prior to any use.
            </p>
          </div>

          <div className="p-5 bg-white border-2 border-black space-y-2">
            <div className="flex items-center gap-2 text-black font-mono text-xs uppercase tracking-caps font-bold">
              <Ban className="w-4 h-4 text-black" />
              <span>No Tax, Accounting, or Legal Advice</span>
            </div>
            <p className="text-xs text-[#475569] leading-relaxed">
              ScanReceipts is a standalone software utility and does not provide certified CPA accounting, tax preparation, audit defense, or legal counsel. We assume zero liability for IRS audits, tax penalties, or misreported deductions.
            </p>
          </div>
        </div>

        {/* Content Sections */}
        <div className="space-y-8">
          {/* Section 1: Agreement to Terms */}
          <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]">
              <FileSpreadsheet className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                1. Agreement to Terms & Eligibility
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                By accessing or using the ScanReceipts web application, software, APIs, and associated services (collectively, the &quot;Service&quot;), operated by ScanReceipts Systems (&quot;we,&quot; &quot;us,&quot; or &quot;our&quot;), you agree to be bound by these Terms of Service. If you do not agree to these terms, you must immediately cease all access and use of the Service.
              </p>
              <p>
                You must be at least 18 years of age (or the age of legal majority in your jurisdiction) to access or use the Service. By using the Service, you represent and warrant that you possess full legal capacity to enter into this binding agreement.
              </p>
            </div>
          </section>

          {/* Section 2: Description of Service & Quotas */}
          <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">
                2. Service Scope, Free Quotas & Paid Licenses
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                ScanReceipts provides a browser-based optical character recognition (OCR) and receipt parsing tool that transforms image/PDF documents into structured spreadsheets (.xlsx and .csv).
              </p>
              <ul className="list-disc pl-5 space-y-1.5 text-xs text-[#475569]">
                <li>
                  <strong className="text-black">Free Tier / Guest Mode:</strong> Users are provided with a complimentary quota of up to 5 receipt scans without requiring an account.
                </li>
                <li>
                  <strong className="text-black">Pro Licenses:</strong> Unlimited batch processing and extended features are available through paid license options (Weekly Pass $4.99/week, Annual Pro $39.99/year, Lifetime License $59.99 one-time).
                </li>
                <li>
                  <strong className="text-black">Payment Processing:</strong> All payments are processed securely via Stripe. Paid licenses are non-refundable once OCR processing capacity has been utilized, except where required by applicable mandatory consumer laws.
                </li>
              </ul>
            </div>
          </section>

          {/* Section 3: Absolute Disclaimer of Warranties ("AS IS") */}
          <section className="bg-white border-2 border-black p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-black">
              <Cpu className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-black text-black uppercase tracking-tight">
                3. Absolute Disclaimer of Warranties (&quot;AS IS&quot; &amp; &quot;AS AVAILABLE&quot;)
              </h2>
            </div>
            <div className="text-sm text-[#161C22] leading-relaxed space-y-3">
              <p className="font-bold text-black uppercase font-mono text-xs tracking-wider">
                TO THE MAXIMUM EXTENT PERMITTED UNDER APPLICABLE UNITED STATES FEDERAL AND STATE LAW:
              </p>
              <p className="p-4 bg-[#F8FAFC] border border-[#CBD5E1] font-mono text-xs text-[#334155] uppercase leading-relaxed">
                THE SERVICE, INCLUDING ALL SOFTWARE, ARTIFICIAL INTELLIGENCE MODELS, OCR PARSING, MATHEMATICAL VALIDATIONS, SPREADSHEET GENERATION, AND CONTENT, IS PROVIDED STRICTLY ON AN &quot;AS IS,&quot; &quot;AS AVAILABLE,&quot; AND &quot;WITH ALL FAULTS&quot; BASIS. SCANRECEIPTS SYSTEMS AND ITS AFFILIATES, OFFICERS, DIRECTORS, EMPLOYEES, AGENTS, SUPPLIERS, AND LICENSORS EXPRESSLY DISCLAIM ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, ACCURACY, NON-INFRINGEMENT, QUIET ENJOYMENT, AND FREEDOM FROM COMPUTER VIRUSES OR HARMFUL CODE.
              </p>
              <p>
                We do not warrant that the Service will meet your specific business or accounting requirements, that operation will be uninterrupted, secure, or error-free, that OCR output will be 100% accurate, or that any defects will be corrected.
              </p>
            </div>
          </section>

          {/* Section 4: Total Limitation of Liability */}
          <section className="bg-white border-2 border-black p-6 sm:p-8 shadow-xs">
            <div className="flex items-center gap-2 pb-4 mb-4 border-b border-black">
              <Gavel className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-black text-black uppercase tracking-tight">
                4. Total Limitation of Liability &amp; Exclusion of Damages
              </h2>
            </div>
            <div className="text-sm text-[#161C22] leading-relaxed space-y-3">
              <p className="p-4 bg-[#F8FAFC] border border-[#CBD5E1] font-mono text-xs text-[#334155] uppercase leading-relaxed">
                IN NO EVENT AND UNDER NO LEGAL THEORY (WHETHER IN CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY, STATUTE, OR OTHERWISE) SHALL SCANRECEIPTS SYSTEMS, ITS FOUNDERS, OWNERS, OPERATORS, AFFILIATES, AGENTS, CONTRACTORS, OR LICENSORS BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY INDIRECT, CONSEQUENTIAL, INCIDENTAL, SPECIAL, EXEMPLARY, OR PUNITIVE DAMAGES, INCLUDING BUT NOT LIMITED TO:
              </p>
              <ul className="list-disc pl-5 space-y-1.5 text-xs text-[#334155] font-mono uppercase">
                <li>LOSS OF PROFITS, REVENUE, DATA, GOODWILL, OR BUSINESS OPPORTUNITY;</li>
                <li>TAX PENALTIES, IRS FINES, AUDIT ADJUSTMENTS, ACCRUED INTEREST, OR ACCOUNTING CORRECTIONS;</li>
                <li>COST OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;</li>
                <li>CORRUPTION, DELETION, OR LOSS OF STORED RECEIPTS IN BROWSER INDEXEDDB OR LOCALSTORAGE;</li>
                <li>SERVICE OUTAGES, THIRD-PARTY AI API DOWNTIME, OR SYSTEM FAILURES.</li>
              </ul>
              <p className="font-mono text-xs text-black font-bold pt-2">
                IN ALL CASES, OUR MAXIMUM AGGREGATE LIABILITY ARISING OUT OF OR RELATING TO THESE TERMS OR YOUR USE OF THE SERVICE SHALL BE STRICTLY LIMITED TO THE GREATER OF: (A) THE TOTAL AMOUNT ACTUALLY PAID BY YOU TO SCANRECEIPTS IN THE TWELVE (12) MONTHS PRECEDING THE CLAIM, OR (B) TEN UNITED STATES DOLLARS ($10.00 USD).
              </p>
            </div>
          </section>

          {/* Section 5: Mandatory Indemnification */}
          <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]">
              <ShieldCheck className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                5. Mandatory Indemnification by User
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                You agree to defend, indemnify, and hold harmless ScanReceipts Systems, its operators, officers, employees, contractors, and licensors from and against any and all claims, liabilities, damages, losses, fines, penalties, costs, and expenses (including reasonable attorneys&apos; fees and court costs) arising out of or related to:
              </p>
              <ul className="list-disc pl-5 space-y-1 text-xs text-[#475569]">
                <li>Your access to or use of the Service;</li>
                <li>Your reliance on any extracted data, line items, totals, or exported Excel/CSV documents;</li>
                <li>Any tax filings, bookkeeping submissions, or financial disclosures prepared using outputs from the Service;</li>
                <li>Your violation of these Terms or any applicable federal, state, or international laws;</li>
                <li>Any third-party claim alleging that documents or receipts uploaded by you violate intellectual property or privacy rights.</li>
              </ul>
            </div>
          </section>

          {/* Section 6: Data Storage & User Backup Recommendations */}
          <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">
                6. Data Storage &amp; User Backup Recommendations
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                When you create and sign in to an account, your receipt records and generated tables are stored securely on our servers, scoped to your account, so they remain available across sessions and devices.
              </p>
              <p>
                If you use the Service as a guest without creating an account, your records are stored under a temporary identifier tied to your browser session rather than a persistent account. Clearing your browser data or cookies, or using private/incognito browsing, may result in the loss of access to guest records. We recommend regularly exporting and keeping your own backup copies of your financial records (Excel, CSV, or PDF), particularly when using guest mode.
              </p>
            </div>
          </section>

          {/* Section 7: Binding Dispute Resolution & Class Action Waiver */}
          <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]">
              <Scale className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                7. Dispute Resolution, Binding Arbitration &amp; Class Action Waiver
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-3">
              <p>
                <strong className="text-black">Governing Law:</strong> These Terms and any dispute arising hereunder shall be governed by and construed in accordance with the laws of the State of Delaware, United States, without giving effect to any conflict of law principles.
              </p>
              <p>
                <strong className="text-black">Binding Arbitration:</strong> Any dispute, controversy, or claim arising out of or relating to these Terms or the Service shall be resolved through final and binding individual arbitration administered by the American Arbitration Association (AAA), rather than in court.
              </p>
              <p>
                <strong className="text-black">Class Action Waiver:</strong> YOU AND SCANRECEIPTS AGREE THAT EACH MAY BRING CLAIMS AGAINST THE OTHER ONLY IN YOUR OR ITS INDIVIDUAL CAPACITY, AND NOT AS A PLAINTIFF OR CLASS MEMBER IN ANY PURPORTED CLASS, CONSOLIDATED, OR REPRESENTATIVE PROCEEDING.
              </p>
            </div>
          </section>

          {/* Section 8: Contact Information */}
          <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]">
              <CheckCircle2 className="w-5 h-5 text-black" />
              <h2 className="font-display text-xl sm:text-2xl font-bold text-black">
                8. Contact &amp; Legal Notices
              </h2>
            </div>
            <div className="text-sm text-[#334155] leading-relaxed space-y-2">
              <p>
                For questions regarding these Terms or legal notices, please contact us electronically at:
              </p>
              <div className="p-4 bg-[#F8FAFC] border border-[#E2E8F0] font-mono text-xs space-y-1">
                <div className="font-bold text-black">ScanReceipts Legal Operations</div>
                <div>Inquiries: <a href="mailto:legal@scan-receipts.app" className="text-black underline font-semibold">legal@scan-receipts.app</a></div>
                <div>Support: <a href="mailto:support@scan-receipts.app" className="text-black underline font-semibold">support@scan-receipts.app</a></div>
              </div>
            </div>
          </section>
        </div>
      </main>

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