'use client';

import { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import { Download } from 'lucide-react';
import DataTable from '@/components/ui/DataTable';
import Badge from '@/components/ui/Badge';
import ActionButton from '@/components/ui/ActionButton';
import { verifaydaApi } from '@/lib/api';
import { formatDateTime, formatCurrency } from '@/lib/utils';

export default function VerifaydaPage() {
  const [filters, setFilters] = useState({ search: '', verified: '' });

  const { data, isLoading } = useQuery({
    queryKey: ['verifayda', filters],
    queryFn: () => verifaydaApi.getVerifications(filters),
  });

  const columns = [
      { key: 'nationalId', label: 'National ID', render: (ver: any) => <span className="font-mono">{ver.nationalId}</span> },
      { key: 'fullName', label: 'Name', render: (ver: any) => ver.fullName || 'N/A' },
      { key: 'verified', label: 'Status', render: (ver: any) => <Badge variant="status" status={ver.verified ? 'CONFIRMED' : 'CANCELLED'}>{ver.verified ? 'Verified' : 'Failed'}</Badge> },
      { key: 'createdAt', label: 'Verified At', render: (ver: any) => formatDateTime(ver.createdAt) },
    ];

  return (
    <div className="space-y-6">
      <div className="flex items-center justify-between">
        <div>
          <h1 className="text-2xl font-bold text-foreground">Verifayda Integration</h1>
          <p className="text-muted-foreground">Ethiopian national ID verification logs</p>
        </div>
        <ActionButton icon={Download} variant="secondary">Export</ActionButton>
      </div>

      <div className="card">
        <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
          
      <div>
        <label className="label">Search</label>
        <input type="text" placeholder="Search by National ID..." className="input" value={filters.search} onChange={(e) => setFilters({ ...filters, search: e.target.value })} />
      </div>
      <div>
        <label className="label">Status</label>
        <select className="input" value={filters.verified} onChange={(e) => setFilters({ ...filters, verified: e.target.value })}>
          <option value="">All</option>
          <option value="true">Verified</option>
          <option value="false">Failed</option>
        </select>
      </div>
    
        </div>
      </div>

      <DataTable
        data={data?.items || data || []}
        columns={columns}
        loading={isLoading}
        emptyMessage="No verifayda integration found"
      />
    </div>
  );
}
