import React, { useState } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog'; import { Plus, TrendingUp, Trash2, Package } from 'lucide-react'; import { useMovimentacoesEstoque, useExcluirMovimentacao } from '@/hooks/useEstoqueMovimentacoes'; import { MovimentacaoModal } from './MovimentacaoModal'; import { MovimentacaoTableHeader } from './MovimentacaoTableHeader'; import { Skeleton } from '@/components/ui/skeleton'; export const MovimentacaoEstoqueSimplificada = () => { const [isModalOpen, setIsModalOpen] = useState(false); const [sortConfig, setSortConfig] = useState<{ key: string; direction: 'asc' | 'desc'; }>({ key: 'created_at', direction: 'desc' }); const { data: movimentacoes = [], isLoading } = useMovimentacoesEstoque(); const excluirMovimentacao = useExcluirMovimentacao(); const handleSort = (key: string) => { let direction: 'asc' | 'desc' = 'asc'; if (sortConfig.key === key && sortConfig.direction === 'asc') { direction = 'desc'; } setSortConfig({ key, direction }); }; const sortedMovimentacoes = React.useMemo(() => { if (!movimentacoes) return []; return [...movimentacoes].sort((a, b) => { let aValue: any; let bValue: any; switch (sortConfig.key) { case 'material': aValue = a.estoque_materiais?.codigo || ''; bValue = b.estoque_materiais?.codigo || ''; break; case 'data_movimentacao': aValue = new Date(a.data_movimentacao); bValue = new Date(b.data_movimentacao); break; case 'created_at': aValue = new Date(a.created_at); bValue = new Date(b.created_at); break; default: aValue = a[sortConfig.key as keyof typeof a]; bValue = b[sortConfig.key as keyof typeof b]; } if (aValue < bValue) return sortConfig.direction === 'asc' ? -1 : 1; if (aValue > bValue) return sortConfig.direction === 'asc' ? 1 : -1; return 0; }); }, [movimentacoes, sortConfig]); const getStatusColor = (tipo: string) => { switch (tipo) { case 'entrada': return 'bg-green-500'; case 'saida': return 'bg-red-500'; case 'empenho': return 'bg-yellow-500'; case 'desempenho': return 'bg-blue-500'; case 'ajuste': return 'bg-purple-500'; case 'transferencia': return 'bg-orange-500'; default: return 'bg-gray-500'; } }; if (isLoading) { return (
Nenhuma movimentação registrada