import React from 'react'; import RefreshButton from './RefreshButton'; import ListHeader from './ListHeader'; import DataTable, { Column } from './DataTable'; import Pagination from './Pagination'; import TableActions from './TableActions'; import SearchBar from './SearchBar'; import { PagamentoDocument } from '@/types/legacyEntities'; interface PagamentoListProps { pagamentos: PagamentoDocument[]; loading: boolean; error: string | null; totalPagamentos: number; currentPage: number; pageSize: number; onEdit: (pagamento: PagamentoDocument) => void; onDelete: (id: string) => Promise; onRefresh: () => void; onPrevPage: () => void; onNextPage: () => void; onSearch: (term: string) => void; } const PagamentoList: React.FC = ({ pagamentos, loading, error, totalPagamentos, currentPage, pageSize, onEdit, onDelete, onRefresh, onPrevPage, onNextPage, onSearch, }) => { const totalPages = Math.ceil(totalPagamentos / pageSize); const startItem = (currentPage - 1) * pageSize + 1; const endItem = Math.min(currentPage * pageSize, totalPagamentos); const [search, setSearch] = React.useState(''); const columns: Column[] = [ { key: 'pedidos', header: 'Pedido', render: row => { const pedidos = row.pedidos; if (Array.isArray(pedidos)) { return pedidos.join(', '); } if (pedidos && typeof pedidos === 'object') { return pedidos.$id || 'N/A'; } return pedidos ?? 'N/A'; }, }, { key: 'status', header: 'Status' }, { key: 'metodo', header: 'Método' }, { key: 'valor', header: 'Valor', render: row => Number(row.valor || 0).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }), }, { key: '$id', header: 'ID' }, { key: '$createdAt', header: 'Data de Criação', render: row => new Date(row.$createdAt).toLocaleDateString('pt-BR'), }, ]; const handleDelete = async (id: string) => { if (confirm('Tem certeza que deseja deletar este pagamento?')) { await onDelete(id); } }; return (
onSearch(search)} placeholder="Buscar status" /> {error && (
{error}
)} {loading ? (
Carregando pagamentos...
) : ( <> ( onEdit(pagamento)} onDelete={() => handleDelete(pagamento.$id)} /> )} />
{totalPagamentos > 0 ? ( <>Mostrando {startItem} - {endItem} de {totalPagamentos} pagamentos ) : ( 'Total de pagamentos: 0' )}
)}
); }; export default PagamentoList;