import React from "react";
import Table from "./Table";
import SortOrder from "../../../Types/BaseDatabase/SortOrder";
const LocalTable = (props) => {
    const [currentPage, setCurrentPage] = React.useState(1);
    const [itemsPerPage, setItemsPerPage] = React.useState(10);
    const [sortOrder, setSortOrder] = React.useState(SortOrder.Ascending);
    const [sortBy, setSortBy] = React.useState(null);
    const [dataSlice, setDataSlice] = React.useState(props.data.slice(0, itemsPerPage));
    React.useEffect(() => {
        const startIndex = (currentPage - 1) * itemsPerPage;
        const endIndex = startIndex + itemsPerPage;
        setDataSlice(props.data.slice(startIndex, endIndex));
    }, [currentPage, itemsPerPage, props.data]);
    return (React.createElement(Table, { data: dataSlice, columns: props.columns, totalItemsCount: props.data.length, currentPageNumber: currentPage, error: "", isLoading: false, itemsOnPage: itemsPerPage, onNavigateToPage: (pageNumber, itemsPerPage) => {
            setCurrentPage(pageNumber);
            setItemsPerPage(itemsPerPage);
        }, id: props.id, disablePagination: false, singularLabel: props.singularLabel, pluralLabel: props.pluralLabel, sortOrder: sortOrder, sortBy: sortBy, onSortChanged: (sortBy, sortOrder) => {
            setSortOrder(sortOrder);
            setSortBy(sortBy);
            const sortedData = [...props.data].sort((a, b) => {
                if (sortOrder === SortOrder.Ascending) {
                    return a[sortBy] > b[sortBy] ? 1 : -1;
                }
                return a[sortBy] < b[sortBy] ? 1 : -1;
            });
            setDataSlice(sortedData.slice(0, itemsPerPage));
            setCurrentPage(1);
        } }));
};
export default LocalTable;
//# sourceMappingURL=LocalTable.js.map