import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import SearchPersonTable from "../SearchPersonTable";
import { SearchPersonTableData } from "../../utils";
import TablePagination from "../TablePagination";
import "./style.scss";
import { useEffect, useState } from "react";
import { ChatDropDown } from "..";
function generateSequence(start, end) {
    const array = [];
    let current = start;
    while (current <= end) {
        array.push(current);
        current += 1;
    }
    return array;
}
const SearchPersonTableContainer = ({ showExternalSearch, searchTime, }) => {
    const [value, setValue] = useState("");
    const [currentPage, setCurrentPage] = useState(1);
    const [selectedProfiles, setSelectedProfiles] = useState([]);
    const [data, setData] = useState([]);
    const totalCount = SearchPersonTableData.length;
    const pageSize = 10;
    let upperCap = currentPage * pageSize;
    let lowerCap = currentPage * pageSize - pageSize;
    useEffect(() => {
        lowerCap = currentPage * pageSize - pageSize;
        upperCap = currentPage * pageSize;
        setData(SearchPersonTableData.slice(lowerCap, upperCap).map((row) => ({
            ...row,
            isSelected: selectedProfiles.includes(row.publicIdentifier),
        })));
    }, [currentPage]);
    const pageButtons = generateSequence(1, Math.ceil(totalCount / pageSize));
    return (_jsxs("div", { className: "searchPersonTableContainer", children: [_jsx(ChatDropDown, { value: value, isCreateShown: false, showSearchIcon: false, filteredOptions: [{ label: "India" }, { label: "Pakistan" }], handleOptionClick: (prop) => {
                    setValue(prop.label);
                }, handleCreateClick: (text) => {
                    console.log({ text });
                }, handleInputChange: (e) => {
                    setValue(e.target.value);
                } }), _jsx("div", { className: "searchPersonTableContainer-Table", children: _jsx(SearchPersonTable, { searchTime: searchTime, onCompleteSearch: () => false, onCreateExternalSearch: () => false, onCheckClick: (publicIdentifier) => {
                        if (!selectedProfiles.includes(publicIdentifier)) {
                            setSelectedProfiles([...selectedProfiles, publicIdentifier]);
                        }
                        else {
                            setSelectedProfiles(selectedProfiles.filter((id) => id !== publicIdentifier));
                        }
                        // console.log("hello g wassup:::::::::::id ", publicIdentifier);
                    }, onCompanyClick: (publicIdentifier) => {
                        console.log("hello g wassup:::::::::::id ", publicIdentifier);
                    }, onNameClick: (publicIdentifier) => {
                        console.log("hello g wassup:::::::::::id ", publicIdentifier);
                    }, personsData: data, showExternalSearch: showExternalSearch }) }), _jsx(TablePagination, { totalPages: 10, totalCount: totalCount, lowerCap: lowerCap, upperCap: upperCap, pageButtons: pageButtons, onPrevClick: () => { }, onNextClick: () => { }, onPageNumberClick: (pageNumber) => setCurrentPage(pageNumber) })] }));
};
export default SearchPersonTableContainer;
