import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { SearchCompanyTableData } from "../../utils";
import TablePagination from "../TablePagination";
import "./style.scss";
import { useEffect, useState } from "react";
import SearchCompanyTable from "../SearchCompanyTable";
function generateSequence(start, end) {
    const array = [];
    let current = start;
    while (current <= end) {
        array.push(current);
        current += 1;
    }
    return array;
}
const SearchCompanyTableContainer = () => {
    const [currentPage, setCurrentPage] = useState(1);
    const [selectedCompanies, setSelectedCompanies] = useState([]);
    const [data, setData] = useState([]);
    const totalCount = SearchCompanyTableData.length;
    const pageSize = 10;
    let upperCap = currentPage * pageSize;
    let lowerCap = currentPage * pageSize - pageSize;
    useEffect(() => {
        lowerCap = currentPage * pageSize - pageSize;
        upperCap = currentPage * pageSize;
        setData(SearchCompanyTableData.slice(lowerCap, upperCap).map((row) => ({
            ...row,
            isSelected: selectedCompanies.includes(row.universalName),
        })));
    }, [currentPage]);
    const pageButtons = generateSequence(1, Math.ceil(totalCount / pageSize));
    return (_jsxs("div", { className: "searchCompanyTableContainer", children: [_jsx("div", { className: "searchPersonTableContainer-Table", children: _jsx(SearchCompanyTable, { onCheckClick: (publicIdentifier) => {
                        if (!selectedCompanies.includes(publicIdentifier)) {
                            setSelectedCompanies([...selectedCompanies, publicIdentifier]);
                        }
                        else {
                            setSelectedCompanies(selectedCompanies.filter((id) => id !== publicIdentifier));
                        }
                        // console.log("hello g wassup:::::::::::id ", publicIdentifier);
                    }, onNameClick: (publicIdentifier) => {
                        console.log("hello g wassup:::::::::::id ", publicIdentifier);
                    }, companyData: data }) }), _jsx(TablePagination, { totalPages: 10, totalCount: totalCount, lowerCap: lowerCap, upperCap: upperCap, pageButtons: pageButtons, onPrevClick: () => { }, onNextClick: () => { }, onPageNumberClick: (pageNumber) => setCurrentPage(pageNumber) })] }));
};
export default SearchCompanyTableContainer;
