import { createElement as _createElement } from "react";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import React, { useState } from "react";
import "./style.scss";
import { useTable } from "react-table";
import CheckboxComponent from "../CheckboxComponent";
import RectangularIcon from "../RectangularIcon";
import PersonCompanyNameClickable from "../PersonCompanyNameClickable";
import ExternalSearchDropdown from "../ExternalSearchDropdown";
import { SecondaryButton } from "..";
import BadgeWithCount from "../BadgeWithCount";
const SearchPersonTable = ({ onCheckClick = (publicIdentifier) => {
    console.log("Showing the publicIdentifier :: ", publicIdentifier);
}, onNameClick = (publicIdentifier) => {
    console.log("Showing the publicIdentifier :: ", publicIdentifier);
}, onCompanyClick = (universalName, urn) => {
    console.log("universalName: string, urn: string ", universalName, "............................", urn);
}, personsData, showExternalSearch, searchTime, onCompleteSearch = () => { }, onCreateExternalSearch = () => { }, profileTableColums = [], }) => {
    // useEffect(() => {
    //   console.log("It search Table", { personsData });
    // }, []);
    const [externalSearch, setExternalSearch] = useState(false);
    const data = personsData;
    const columns = React.useMemo(() => 
    // [
    //   { Header: "Name", accessor: "fullName" },
    //   { Header: "Title", accessor: "currentTitle" },
    //   { Header: "Company", accessor: "currentCompany" },
    //   { Header: "Location", accessor: "location" },
    //   { Header: "Industry", accessor: "industry" },
    //   { Header: "Skills", accessor: "skills" },
    //   { Header: "Last Updated", accessor: "lastUpdated" },
    // ]
    profileTableColums, []);
    const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data });
    return (_jsxs("table", { className: "searchPersonTable--Generic", ...getTableProps(), children: [_jsx("thead", { children: headerGroups.map((headerGroup) => (_jsx("tr", { ...headerGroup.getHeaderGroupProps(), children: headerGroup.headers.map((column) => (_jsx("th", { ...column.getHeaderProps(), children: column.render("Header") }))) }))) }), _jsxs("tbody", { ...getTableBodyProps(), children: [rows.map((row) => {
                        prepareRow(row);
                        return (_createElement("tr", { ...row.getRowProps(), key: row.original.publicIdentifier }, row.cells.map((cell) => {
                            if (cell.column.Header === "Name") {
                                return (_jsx("td", { ...cell.getCellProps(), children: _jsxs("span", { className: "searchPersonTable--NameCell", children: [_jsx("p", { children: cell.row.original.index }), _jsx(CheckboxComponent, { sizeVariant: "xs", checked: cell.row.original.isSelected, onClick: (_checked) => {
                                                    onCheckClick(cell.row.original.publicIdentifier);
                                                } }), _jsx(RectangularIcon, { iconPath: cell?.row?.original?.profilePicture, iconSize: "40", borderRadius: "6" }, `${cell.row.original.publicIdentifier}-${cell.row.original.lastUpdated}`), _jsxs("span", { className: "nameAndAssignmentCell", children: [_jsx(PersonCompanyNameClickable, { text: cell?.value, onClick: () => onNameClick(cell.row.original.publicIdentifier) }), _jsx(BadgeWithCount, { count: cell.row.original.assignmentCount, toolTipPosition: "top", toolTipContent: `Added to ${cell.row.original.assignmentCount} assignments`, iconSize: "16", iconType: "briefcase" })] })] }) }));
                            }
                            else if (cell.column.Header === "Company") {
                                return (_jsx("td", { ...cell.getCellProps(), children: _jsx("span", { className: "searchPersonTable--NameCell", children: _jsx(PersonCompanyNameClickable, { text: cell?.value, onClick: () => onCompanyClick(cell.row.original.experience?.[0]
                                                ?.universalName || "", cell.row.original.experience?.[0]?.urn || "") }) }) }));
                            }
                            else {
                                return (_jsx("td", { ...cell.getCellProps(), className: cell?.value === "Not Available"
                                        ? "searchPersonTable--NotAvailable"
                                        : "", children: cell.render("Cell") || "N/A" }));
                            }
                        })));
                    }), showExternalSearch && (_jsx("div", { className: "externalSearchOptionContainer", children: externalSearch ? (_jsx("div", { className: "externalSearch", children: _jsx(ExternalSearchDropdown, { searchTime: searchTime, onCompleteSearch: () => {
                                    onCompleteSearch();
                                    setExternalSearch(true);
                                } }) })) : (_jsxs(_Fragment, { children: [_jsx("p", { className: "externalSearchMessage", children: "Still can\u2019t find the profile you\u2019re looking for? We can search the internet for this name." }), _jsx(SecondaryButton, { onClick: () => {
                                        // setExternalSearch(true);
                                        onCreateExternalSearch();
                                    }, text: "Search by name", colorVariant: "orange" })] })) }))] })] }));
};
export default SearchPersonTable;
