'use client';

import React, { useState, useEffect } from 'react';
import AdminSidebar from '@/components/admin/AdminSidebar';
import {
  Server,
  ShieldCheck,
  Zap,
  CheckCircle2,
  Clock,
  Layers,
  Lock,
  RefreshCw,
  AlertTriangle,
} from 'lucide-react';

export default function AdminProvidersPage() {
  const [providers, setProviders] = useState<any[]>([
    {
      name: 'MockVerificationProvider',
      type: 'SANDBOX',
      status: 'ACTIVE_DEFAULT',
      description: 'Built-in deterministic Nigerian identity simulation with realistic latency and PII masking.',
      latency: '200ms - 500ms',
      supports: ['NIN Verification', 'Phone-NIN Linkage', 'BVN Mock Lookup'],
    },
    {
      name: 'ProductionVerificationProvider',
      type: 'PRODUCTION',
      status: 'AWAITING_OFFICIAL_SPECS',
      description: 'Pluggable production adapter shell. Ready to connect official government verification API upon documentation delivery.',
      latency: 'Configurable',
      supports: ['Pending Official Specs'],
    },
  ]);

  return (
    <div className="flex min-h-screen bg-[#070b14] text-slate-100">
      <AdminSidebar />

      <div className="flex-1 flex flex-col min-w-0">
        <header className="h-16 border-b border-slate-800 bg-[#070b14]/80 backdrop-blur-md px-6 flex items-center justify-between sticky top-0 z-30">
          <div className="flex items-center gap-2">
            <span className="w-2 h-2 rounded-full bg-amber-400"></span>
            <span className="text-xs font-bold text-amber-300 font-mono">Verification Provider Architecture</span>
          </div>
        </header>

        <main className="flex-1 p-6 space-y-6 overflow-y-auto max-w-7xl">
          <div>
            <h1 className="text-xl font-bold text-white flex items-center gap-2">
              <Server className="w-5 h-5 text-amber-400" />
              API Provider Adapters & Gateway Configuration
            </h1>
            <p className="text-xs text-slate-400 mt-0.5">
              Decoupled verification providers adhering to the IVerificationProvider interface.
            </p>
          </div>

          <div className="p-4 rounded-2xl bg-slate-900/80 border border-slate-800 flex items-start gap-3 text-xs text-slate-300">
            <ShieldCheck className="w-5 h-5 text-emerald-400 shrink-0 mt-0.5" />
            <div className="space-y-1">
              <span className="font-bold text-white">Modular Architecture Rule (Strict)</span>
              <p className="text-slate-400 leading-relaxed">
                As required, no undocumented endpoints or fictitious URLs are created. The application routes depend solely on the <code className="text-emerald-400">VerificationService</code> abstraction, ensuring zero-downtime hot swapping when official live credentials arrive.
              </p>
            </div>
          </div>

          {/* Provider Cards */}
          <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
            {providers.map((p) => (
              <div key={p.name} className="glass-panel rounded-2xl p-6 border border-slate-800 space-y-4 relative">
                <div className="flex items-center justify-between border-b border-slate-800 pb-3">
                  <div className="space-y-0.5">
                    <h3 className="text-sm font-bold text-white font-mono">{p.name}</h3>
                    <span className="text-[10px] text-slate-400 uppercase font-semibold">{p.type}</span>
                  </div>
                  <span
                    className={`px-2.5 py-1 rounded-full text-[10px] font-bold ${
                      p.status.includes('ACTIVE')
                        ? 'bg-emerald-500/20 text-emerald-300 border border-emerald-500/30'
                        : 'bg-amber-500/20 text-amber-300 border border-amber-500/30'
                    }`}
                  >
                    {p.status}
                  </span>
                </div>

                <p className="text-xs text-slate-300 leading-relaxed">{p.description}</p>

                <div className="space-y-2 pt-2 border-t border-slate-800/80 text-xs">
                  <div className="flex justify-between">
                    <span className="text-slate-400">Response Latency:</span>
                    <span className="text-white font-mono font-bold">{p.latency}</span>
                  </div>
                  <div className="space-y-1">
                    <span className="text-slate-400 block">Supported Schemes:</span>
                    <div className="flex flex-wrap gap-1.5">
                      {p.supports.map((s: string) => (
                        <span
                          key={s}
                          className="px-2 py-0.5 rounded bg-slate-900 text-[10px] font-mono text-emerald-400 border border-slate-800"
                        >
                          {s}
                        </span>
                      ))}
                    </div>
                  </div>
                </div>
              </div>
            ))}
          </div>
        </main>
      </div>
    </div>
  );
}
