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 TableActions from './TableActions'; interface FaturaListProps { faturas: Models.Document[]; loading: boolean; error: string | null; totalFaturas: number; currentPage: number; pageSize: number; onEdit: (fatura: Models.Document) => void; onDelete: (id: string) => Promise; onRefresh: () => void; onPrevPage: () => void; onNextPage: () => void; onSearch: (nome: string) => void; } const FaturaList: React.FC = ({ faturas, loading, error, totalFaturas, currentPage, pageSize, onEdit, onDelete, onRefresh, onPrevPage, onNextPage, onSearch }) => { const totalPages = Math.ceil(totalFaturas / pageSize); const startItem = (currentPage - 1) * pageSize + 1; const endItem = Math.min(currentPage * pageSize, totalFaturas); const [search, setSearch] = React.useState(''); const handleSearch = () => { onSearch(search); }; const handleDelete = async (id: string) => { if (confirm('Tem certeza que deseja deletar esta fatura?')) { await onDelete(id); } }; const columns: Column[] = [ { key: 'nome', header: 'Nome' }, { key: '$id', header: 'ID' }, { key: '$createdAt', header: 'Data de Criação', render: row => new Date(row.$createdAt).toLocaleDateString('pt-BR') }, ]; return (
{error && (
{error}
)} {loading ? (
Carregando faturas...
) : ( <> ( onEdit(fatura)} onDelete={() => handleDelete(fatura.$id)} /> )} />
{totalFaturas > 0 ? ( <>Mostrando {startItem} - {endItem} de {totalFaturas} faturas ) : ( 'Total de faturas: 0' )}
)}
); }; export default FaturaList;