import React, { useState } from 'react';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Card, CardContent } from '@/components/ui/card';
import { 
  ArrowRightLeft, 
  Settings2, 
  ShieldCheck, 
  AlertCircle,
  Plus,
  ArrowUpCircle,
  ArrowDownCircle,
  Search
} from 'lucide-react';
import { DashboardKPICard } from '@/components/shared/DashboardKPICard/DashboardKPICard';
import ExcelTable from '@/features/prafrot/components/ExcelTable';
import { MOCK_PENDING_TRANSACTIONS } from '../mockData';

export const ReconciliationView = () => {
  const [activeTab, setActiveTab] = useState('pendencias');

  const kpis = [
    { label: 'Saldo Bancário', value: 'R$ 152.430,12', color: 'green', icon: ArrowUpCircle },
    { label: 'A Conciliar hoje', value: 'R$ 12.850,00', color: 'orange', icon: AlertCircle },
    { label: 'Pendências Críticas', value: '03', color: 'red', icon: ShieldCheck },
    { label: 'Regras Ativas', value: '24', color: 'blue', icon: Settings2 },
  ];

  return (
    <div className="workspace-theme space-y-6 p-6">
      <header className="flex justify-between items-center">
        <div>
          <h1 className="text-2xl font-black text-slate-800 dark:text-stone-100 uppercase tracking-tighter">Financeiro / Conciliação</h1>
          <p className="text-slate-500 text-sm">Cruzamento de extratos bancários com registros sistêmicos</p>
        </div>
        <div className="flex gap-3">
          <button className="flex items-center gap-2 bg-[var(--workspace-sec-3-light)] text-white px-4 py-2 rounded-xl font-bold text-sm shadow-lg hover:brightness-110 transition-all hover:scale-105 active:scale-95">
            <ArrowRightLeft size={18} />
            CONCILIAR AGORA
          </button>
        </div>
      </header>

      {/* KPI Section */}
      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
        {kpis.map((kpi, i) => (
          <DashboardKPICard 
            key={i}
            label={kpi.label}
            value={kpi.value}
            color={kpi.color}
            icon={kpi.icon}
          />
        ))}
      </div>

      <Card className="border-none shadow-sm bg-white dark:bg-[#1b1b1b] rounded-2xl overflow-hidden border border-slate-100 dark:border-white/5">
        <Tabs defaultValue="pendencias" className="w-full" onValueChange={setActiveTab}>
          <div className="px-6 pt-4 border-b border-slate-100 dark:border-[#2a2a2a] flex justify-between items-center bg-slate-50/50 dark:bg-[#1e1e1e]/50">
            <TabsList className="bg-transparent gap-8 h-12">
              <TabsTrigger 
                value="pendencias" 
                className="data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-[var(--workspace-sec-3-light)] rounded-none px-0 font-bold text-xs uppercase tracking-[0.2em] text-slate-400 data-[state=active]:text-[var(--workspace-sec-3-light)] transition-all"
              >
                <div className="flex items-center gap-2">
                  <AlertCircle size={16} />
                  Pendências
                </div>
              </TabsTrigger>
              <TabsTrigger 
                value="cruzamento" 
                className="data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-[var(--workspace-sec-3-light)] rounded-none px-0 font-bold text-xs uppercase tracking-[0.2em] text-slate-400 data-[state=active]:text-[var(--workspace-sec-3-light)] transition-all"
              >
                <div className="flex items-center gap-2">
                  <ArrowRightLeft size={16} />
                  Cruzamento
                </div>
              </TabsTrigger>
              <TabsTrigger 
                value="config" 
                className="data-[state=active]:bg-transparent data-[state=active]:shadow-none data-[state=active]:border-b-2 data-[state=active]:border-[var(--workspace-sec-3-light)] rounded-none px-0 font-bold text-xs uppercase tracking-[0.2em] text-slate-400 data-[state=active]:text-[var(--workspace-sec-3-light)] transition-all"
              >
                <div className="flex items-center gap-2">
                  <Settings2 size={16} />
                  Configurações
                </div>
              </TabsTrigger>
            </TabsList>

            <div className="flex items-center gap-2 bg-white dark:bg-[#252525] px-3 py-1.5 rounded-xl border border-slate-200 dark:border-white/10 shadow-sm">
               <Search size={14} className="text-slate-400" />
               <input 
                 type="text" 
                 placeholder="Buscar transação..." 
                 className="bg-transparent border-none text-xs focus:ring-0 w-48 text-slate-600 dark:text-stone-300"
               />
            </div>
          </div>

          <CardContent className="p-0">
            <TabsContent value="pendencias" className="m-0 min-h-[400px]">
               <div className="p-4">
                  <ExcelTable 
                    columns={[
                      { field: 'id', header: 'ID', width: '80px' },
                      { field: 'data', header: 'Data', width: '120px' },
                      { field: 'descricao', header: 'Descrição da Transação', width: '350px' },
                      { field: 'valor', header: 'Valor', width: '150px', type: 'currency' },
                      { field: 'tipo', header: 'Tipo', width: '120px' },
                    ]}
                    data={MOCK_PENDING_TRANSACTIONS}
                  />
               </div>
            </TabsContent>
            
            <TabsContent value="cruzamento" className="m-0 min-h-[400px]">
               <div className="p-12 text-center">
                  <div className="w-16 h-16 bg-slate-50 dark:bg-white/5 rounded-full flex items-center justify-center mx-auto mb-4 border border-slate-100 dark:border-white/5">
                    <ArrowRightLeft size={32} className="text-[var(--workspace-sec-3-light)]" />
                  </div>
                  <h3 className="text-lg font-black uppercase tracking-tight text-slate-700 dark:text-stone-200">Cruzamento Digital</h3>
                  <p className="text-slate-400 text-sm max-w-md mx-auto mt-2">
                    Algoritmo de IA para cruzamento automático de extratos bancários com contas a pagar e receber.
                  </p>
               </div>
            </TabsContent>

            <TabsContent value="config" className="m-0 min-h-[400px]">
               <div className="grid grid-cols-1 md:grid-cols-3 gap-4 p-6">
                  {['Categorias', 'Regras de Importação', 'Mapeamento de Caixas'].map(item => (
                    <Card key={item} className="p-6 bg-slate-50 dark:bg-white/5 border-none hover:bg-white dark:hover:bg-white/10 transition-all cursor-pointer group rounded-2xl border border-transparent hover:border-slate-200 dark:hover:border-white/10">
                       <h4 className="font-bold text-slate-700 dark:text-stone-200 mb-2">{item}</h4>
                       <p className="text-[10px] text-slate-400 uppercase tracking-widest">Gerenciar Parâmetros</p>
                    </Card>
                  ))}
               </div>
            </TabsContent>
          </CardContent>
        </Tabs>
      </Card>
    </div>
  );
};
