import React from 'react'; import { Models } from 'appwrite'; import SearchBar from './SearchBar'; import RefreshButton from './RefreshButton'; import ListHeader from './ListHeader'; import DataTable, { Column } from './DataTable'; import Pagination from './Pagination'; import ActionButton from './ActionButton'; import TableActions from './TableActions'; // Adicionar esta importação interface Props { carrinhos: Models.Document[]; loading: boolean; isChangingPage?: boolean; error: string | null; totalCarrinhos: number; currentPage: number; pageSize: number; onEdit: (doc: Models.Document) => void; onDelete: (id: string) => Promise; onRefresh: () => void; onPrevPage: () => void; onNextPage: () => void; onSearch: (usuario: string) => void; } const columns: Column[] = [ { key: 'usuarios', header: 'Usuário', render: row => { const usuario = (row as any).usuarios; if (usuario && typeof usuario === 'object') { return ( usuario['nome-civil'] || usuario['nome-social'] || usuario.$id || '' ); } return usuario; } }, { key: 'itens', header: 'Itens', render: row => ((row as any).itens || []).join(', ') }, { key: 'quantidades', header: 'Quantidades', className: 'text-center', render: row => { const quantidades = (row as any).quantidades; const valor = Array.isArray(quantidades) ? quantidades.join(', ') : typeof quantidades === 'number' ? quantidades.toString() : '1'; return
{valor}
; } } ]; const CarrinhoList: React.FC = ({ carrinhos, loading, isChangingPage = false, error, totalCarrinhos, currentPage, pageSize, onEdit, onDelete, onRefresh, onPrevPage, onNextPage, onSearch }) => { const totalPages = Math.ceil(totalCarrinhos / pageSize); const startItem = (currentPage - 1) * pageSize + 1; const endItem = Math.min(currentPage * pageSize, totalCarrinhos); const [search, setSearch] = React.useState(''); const handleSearch = () => onSearch(search); const handleDelete = async (id: string) => { if (confirm('Tem certeza que deseja deletar este carrinho?')) { await onDelete(id); } }; return (
{error && (
{error}
)} {isChangingPage && (
Carregando página...
)} {loading ? (
Carregando carrinhos...
) : ( <> ( onEdit(row)} onDelete={() => handleDelete(row.$id)} /> )} />
{totalCarrinhos > 0 ? ( <>Mostrando {startItem} - {endItem} de {totalCarrinhos} carrinhos ) : ( 'Total de carrinhos: 0' )}
)}
); }; export default CarrinhoList;