'use client';

import React, { useState } from 'react';
import Link from 'next/link';
import Navbar from '@/components/layout/Navbar';
import Footer from '@/components/layout/Footer';
import {
  ShieldCheck,
  CheckCircle2,
  ArrowRight,
  Code2,
  Lock,
  Layers,
  Sparkles,
  Zap,
  Globe,
  FileCheck2,
  Terminal,
  Activity,
  Coins,
  Send,
  Users,
} from 'lucide-react';

export default function LandingPage() {
  const [testNin, setTestNin] = useState('12345678901');
  const [testResult, setTestResult] = useState<any>(null);
  const [testing, setTesting] = useState(false);

  const handleTestLookup = () => {
    setTesting(true);
    setTestResult(null);

    setTimeout(() => {
      setTesting(false);
      setTestResult({
        status: 'SUCCESS',
        code: 'IDENTITY_VERIFIED',
        mode: 'SANDBOX',
        data: {
          nin: '1234****901',
          fullName: 'MUSA IBRAHIM YAKUBU',
          gender: 'M',
          dateOfBirth: '1988-11-04',
          stateOfOrigin: 'Kano State',
          matchConfidence: '99.4%',
        },
        unitsDeducted: 10,
      });
    }, 600);
  };

  return (
    <div className="min-h-screen bg-[#f8fafc] text-slate-900 font-sans flex flex-col selection:bg-emerald-500/20">
      <Navbar />

      <main className="flex-1">
        {/* HERO SECTION */}
        <section className="relative overflow-hidden pt-12 pb-20 sm:pt-16 sm:pb-24 border-b border-slate-200/80 bg-gradient-to-b from-emerald-50/40 via-white to-[#f8fafc]">
          <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
            <div className="text-center space-y-5 max-w-3xl mx-auto">
              <div className="inline-flex items-center gap-2 px-3.5 py-1.5 rounded-full bg-emerald-50 border border-emerald-200 text-emerald-800 text-xs font-bold shadow-sm">
                <Sparkles className="w-3.5 h-3.5 text-emerald-600" />
                <span>Modern Identity Verification Platform</span>
                <span className="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>
                <span className="font-mono text-[11px]">1,000 Free Units on Signup</span>
              </div>

              <h1 className="text-4xl sm:text-5xl lg:text-6xl font-extrabold text-slate-900 tracking-tight leading-[1.15]">
                Instant Identity Verification &{' '}
                <span className="text-transparent bg-clip-text bg-gradient-to-r from-emerald-700 via-emerald-600 to-teal-600">
                  Developer REST APIs
                </span>
              </h1>

              <p className="text-base sm:text-lg text-slate-600 leading-relaxed">
                SmartAuth empowers Nigerian enterprises, fintechs, and developers to verify National Identification Numbers (NIN) and phone linkages in real time with high availability.
              </p>

              <div className="flex flex-col sm:flex-row items-center justify-center gap-3 pt-2">
                <Link
                  href="/register"
                  className="w-full sm:w-auto px-8 py-3.5 rounded-xl bg-[#00875a] hover:bg-[#00693e] text-white text-sm font-bold shadow-lg shadow-emerald-700/20 hover:shadow-xl transition-all flex items-center justify-center gap-2"
                >
                  <span>Register Now</span>
                  <ArrowRight className="w-4 h-4" />
                </Link>

                <Link
                  href="/docs"
                  className="w-full sm:w-auto px-7 py-3.5 rounded-xl bg-white hover:bg-slate-50 border border-slate-200 text-slate-800 text-sm font-bold shadow-sm transition-all flex items-center justify-center gap-2"
                >
                  <Code2 className="w-4 h-4 text-emerald-700" />
                  <span>API Documentation</span>
                </Link>
              </div>

              {/* Trust Indicators */}
              <div className="pt-8 flex flex-wrap items-center justify-center gap-6 text-xs text-slate-500">
                <div className="flex items-center gap-1.5">
                  <CheckCircle2 className="w-4 h-4 text-emerald-600" />
                  <span>Zero Setup Fees</span>
                </div>
                <div className="flex items-center gap-1.5">
                  <CheckCircle2 className="w-4 h-4 text-emerald-600" />
                  <span>Sub-second Latency</span>
                </div>
                <div className="flex items-center gap-1.5">
                  <CheckCircle2 className="w-4 h-4 text-emerald-600" />
                  <span>NDPR & ISO-27001 Ready</span>
                </div>
              </div>
            </div>
          </div>
        </section>

        {/* INTERACTIVE SANDBOX DEMO */}
        <section className="py-16 bg-white border-b border-slate-200/80">
          <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div className="text-center max-w-2xl mx-auto mb-10 space-y-2">
              <span className="text-xs font-bold text-emerald-700 uppercase tracking-widest font-mono">
                Interactive Preview
              </span>
              <h2 className="text-2xl sm:text-3xl font-extrabold text-slate-900">
                Test Sandbox Identity Lookup
              </h2>
              <p className="text-xs sm:text-sm text-slate-500">
                Experience how instant NIN lookups work in the SmartAuth Sandbox environment.
              </p>
            </div>

            <div className="max-w-2xl mx-auto bg-slate-50 border border-slate-200 rounded-2xl p-6 sm:p-8 shadow-sm space-y-5">
              <div className="space-y-2">
                <label className="block text-xs font-bold text-slate-700">
                  Enter Test 11-Digit NIN
                </label>
                <div className="flex flex-col sm:flex-row gap-2">
                  <input
                    type="text"
                    value={testNin}
                    onChange={(e) => setTestNin(e.target.value)}
                    placeholder="12345678901"
                    maxLength={11}
                    className="flex-1 bg-white border border-slate-200 rounded-xl px-4 py-2.5 text-xs font-mono font-bold text-slate-900 focus:outline-none focus:border-emerald-600 shadow-sm"
                  />
                  <button
                    onClick={handleTestLookup}
                    disabled={testing}
                    className="px-6 py-2.5 bg-[#00875a] hover:bg-[#00693e] text-white text-xs font-bold rounded-xl transition-all flex items-center justify-center gap-2 shadow-sm disabled:opacity-50"
                  >
                    {testing ? (
                      <span className="animate-pulse">Verifying...</span>
                    ) : (
                      <>
                        <Terminal className="w-3.5 h-3.5" />
                        <span>Run Test Match</span>
                      </>
                    )}
                  </button>
                </div>
              </div>

              {testResult && (
                <div className="p-4 bg-white border border-emerald-200 rounded-xl space-y-3 animate-in fade-in duration-200">
                  <div className="flex items-center justify-between border-b border-slate-100 pb-2">
                    <span className="text-xs font-bold text-emerald-800 flex items-center gap-1.5">
                      <CheckCircle2 className="w-4 h-4 text-emerald-600" />
                      Verification Result (Mock Sandbox)
                    </span>
                    <span className="text-[10px] font-mono px-2 py-0.5 rounded bg-emerald-50 text-emerald-800 font-bold">
                      -10 UNITS
                    </span>
                  </div>

                  <div className="grid grid-cols-2 sm:grid-cols-3 gap-3 text-xs">
                    <div>
                      <span className="text-slate-400 text-[10px] uppercase font-semibold">NIN (Masked)</span>
                      <p className="font-mono font-bold text-slate-800">{testResult.data.nin}</p>
                    </div>
                    <div>
                      <span className="text-slate-400 text-[10px] uppercase font-semibold">Full Name</span>
                      <p className="font-bold text-slate-800">{testResult.data.fullName}</p>
                    </div>
                    <div>
                      <span className="text-slate-400 text-[10px] uppercase font-semibold">Origin</span>
                      <p className="font-bold text-slate-800">{testResult.data.stateOfOrigin}</p>
                    </div>
                    <div>
                      <span className="text-slate-400 text-[10px] uppercase font-semibold">Match Score</span>
                      <p className="font-bold text-emerald-700">{testResult.data.matchConfidence}</p>
                    </div>
                    <div className="col-span-2">
                      <span className="text-slate-400 text-[10px] uppercase font-semibold">Mode</span>
                      <p className="font-mono text-emerald-800 font-bold">SANDBOX / SIMULATED</p>
                    </div>
                  </div>
                </div>
              )}
            </div>
          </div>
        </section>

        {/* IDENTITY & API FEATURES SECTION */}
        <section id="services" className="py-20 bg-[#f8fafc]">
          <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 space-y-12">
            <div className="text-center max-w-2xl mx-auto space-y-2">
              <span className="text-xs font-bold text-emerald-700 uppercase tracking-widest font-mono">
                Platform Capabilities
              </span>
              <h2 className="text-3xl font-extrabold text-slate-900">
                Built for High-Growth Verification
              </h2>
              <p className="text-xs sm:text-sm text-slate-500">
                Designed to support both interactive manual desk operations and automated programmatic integrations.
              </p>
            </div>

            <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
              {/* Feature 1 */}
              <div className="bg-white rounded-2xl p-7 border border-slate-200/90 shadow-sm space-y-4 hover:border-emerald-200 transition-all">
                <div className="w-11 h-11 rounded-xl bg-emerald-50 border border-emerald-100 flex items-center justify-center text-emerald-700">
                  <FileCheck2 className="w-6 h-6" />
                </div>
                <h3 className="text-base font-bold text-slate-900">
                  Verification Desk
                </h3>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Interactive web desk for compliance officers and agents to perform real-time NIN and Phone-NIN checks without code.
                </p>
              </div>

              {/* Feature 2 */}
              <div className="bg-white rounded-2xl p-7 border border-slate-200/90 shadow-sm space-y-4 hover:border-emerald-200 transition-all">
                <div className="w-11 h-11 rounded-xl bg-emerald-50 border border-emerald-100 flex items-center justify-center text-emerald-700">
                  <Code2 className="w-6 h-6" />
                </div>
                <h3 className="text-base font-bold text-slate-900">
                  REST API Engine
                </h3>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Cryptographic API keys (`sk_test_` & `sk_live_`), idempotency support, HMAC webhook signatures, and SDKs in cURL, JS, Python, and PHP.
                </p>
              </div>

              {/* Feature 3 */}
              <div className="bg-white rounded-2xl p-7 border border-slate-200/90 shadow-sm space-y-4 hover:border-emerald-200 transition-all">
                <div className="w-11 h-11 rounded-xl bg-emerald-50 border border-emerald-100 flex items-center justify-center text-emerald-700">
                  <Coins className="w-6 h-6" />
                </div>
                <h3 className="text-base font-bold text-slate-900">
                  Units Accounting
                </h3>
                <p className="text-xs text-slate-500 leading-relaxed">
                  Transparent pay-per-verification units architecture with automatic shared wallet pooling for team members and organizations.
                </p>
              </div>
            </div>
          </div>
        </section>

        {/* CTA BANNER */}
        <section className="py-16 bg-white border-t border-slate-200/80">
          <div className="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 text-center space-y-5">
            <h2 className="text-3xl font-extrabold text-slate-900">
              Ready to verify identities with SmartAuth?
            </h2>
            <p className="text-sm text-slate-500 max-w-xl mx-auto">
              Create an account now and instantly receive 1,000 complimentary Sandbox Units.
            </p>
            <div>
              <Link
                href="/register"
                className="inline-flex items-center gap-2 px-8 py-3.5 rounded-xl bg-[#00875a] hover:bg-[#00693e] text-white text-sm font-bold shadow-lg shadow-emerald-700/20 hover:shadow-xl transition-all"
              >
                <span>Register Now</span>
                <ArrowRight className="w-4 h-4" />
              </Link>
            </div>
          </div>
        </section>
      </main>

      <Footer />
    </div>
  );
}
