'use client';

import React, { useState, useEffect } from 'react';
import NINAuthSidebar from '@/components/dashboard/NINAuthSidebar';
import NINAuthHeader from '@/components/dashboard/NINAuthHeader';
import VerificationServiceModule from '@/components/modules/VerificationServiceModule';
import { Terminal, ShieldCheck, Coins, Sparkles } from 'lucide-react';

export default function VerificationServicePage() {
  const [user, setUser] = useState<any>(null);
  const [wallet, setWallet] = useState<any>(null);
  const [sidebarCollapsed, setSidebarCollapsed] = useState(false);

  const loadData = async () => {
    try {
      const res = await fetch('/api/v1/account');
      const data = await res.json();
      if (data.success) {
        setUser(data.data.user);
        setWallet(data.data.wallet);
      }
    } catch {}
  };

  useEffect(() => {
    loadData();
  }, []);

  return (
    <div className="flex min-h-screen bg-[#f8fafc] text-slate-900 font-sans selection:bg-emerald-500/20">
      <NINAuthSidebar
        collapsed={sidebarCollapsed}
        onToggleCollapse={() => setSidebarCollapsed(!sidebarCollapsed)}
        userRole={user?.role}
      />

      <div className="flex-1 flex flex-col min-w-0">
        <NINAuthHeader
          user={user}
          wallet={wallet}
          onToggleSidebar={() => setSidebarCollapsed(!sidebarCollapsed)}
        />

        <main className="flex-1 p-6 sm:p-8 space-y-6 overflow-y-auto max-w-7xl">
          {/* Header & Balance Notice */}
          <div className="flex flex-wrap items-center justify-between gap-4">
            <div>
              <div className="flex items-center gap-2">
                <Terminal className="w-5 h-5 text-[#00875a]" />
                <h1 className="text-xl font-bold text-slate-900">
                  Verification Service
                </h1>
              </div>
              <p className="text-xs text-slate-500 mt-1">
                Execute identity verification queries and inspect structured citizen records.
              </p>
            </div>

            <div className="flex items-center gap-3">
              <div className="px-4 py-2 rounded-xl bg-amber-50 border border-amber-200 text-xs font-mono font-bold text-amber-900 flex items-center gap-2">
                <Coins className="w-4 h-4 text-amber-600" />
                <span>Available Units: {Number(wallet?.unitsBalance ?? 1000).toLocaleString()}</span>
              </div>
            </div>
          </div>

          {/* Modular Verification Service Component */}
          <VerificationServiceModule onVerificationComplete={loadData} />
        </main>
      </div>
    </div>
  );
}
