"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const utils_1 = require("../utils");
const types_1 = require("../../types");
const Checkbox_1 = require("../../Checkbox");
const solid_1 = require("@heroicons/react/24/solid");
const TruncatedTooltip_1 = tslib_1.__importDefault(require("./TruncatedTooltip"));
function Row({ keyIdx, dataIdx, data, bodyKey, thBodyComponent, className, readonly, isHighlight, highlightReadonly, selectedAllPeople, tableKey, brSetSelectedPeople, selectedPeople, border, expandable, }) {
    const cellValue = (0, utils_1.renderCell)(data, bodyKey, thBodyComponent).value;
    const renderInclude = (person) => {
        return !!selectedPeople.find((select) => JSON.stringify(select) === JSON.stringify(person));
    };
    const [checked, setChecked] = (0, react_1.useState)(renderInclude(data));
    (0, react_1.useEffect)(() => {
        setChecked(renderInclude(data));
    }, [renderInclude(data)]);
    const handleChange = (e) => {
        const checked = e.target.checked;
        setChecked(checked);
        const valueSelected = checked
            ? [...selectedPeople, data]
            : selectedPeople.filter((p) => JSON.stringify(p) !== JSON.stringify(data));
        brSetSelectedPeople(valueSelected);
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        keyIdx === 0 && selectedAllPeople && selectedAllPeople.enable && (react_1.default.createElement("td", { key: keyIdx, className: (0, types_1.classNames)(border && 'border-r', dataIdx !== 0 && 'border-t', !isHighlight ? (readonly ? '' : 'group-hover:bg-gray-50 group-hover:cursor-pointer') : '', isHighlight && !highlightReadonly ? 'group-hover:bg-gray-50 group-hover:cursor-pointer' : '') },
            react_1.default.createElement("div", { className: 'flex justify-center items-center pl-3', onClick: (event) => event.stopPropagation() },
                react_1.default.createElement(Checkbox_1.PHXCheckbox, { id: `${tableKey}-${dataIdx}`, checked: checked, onChange: (event) => handleChange(event) })))),
        react_1.default.createElement("td", { key: keyIdx, className: (0, types_1.classNames)(className, !isHighlight ? (readonly ? '' : 'group-hover:bg-gray-50 group-hover:cursor-pointer') : '', isHighlight && !highlightReadonly ? 'group-hover:bg-gray-50 group-hover:cursor-pointer' : '') }, (expandable === null || expandable === void 0 ? void 0 : expandable.enable) ? (react_1.default.createElement("div", { className: 'relative min-w-0' },
            react_1.default.createElement("button", { "aria-label": expandable.isExpanded ? 'Collapse row' : 'Expand row', className: 'absolute -left-8 top-1/2 flex h-4 w-4 -translate-y-1/2 items-center justify-center rounded text-gray-700 hover:bg-gray-100', onClick: (event) => {
                    event.stopPropagation();
                    expandable.onToggle();
                }, type: 'button' }, expandable.isExpanded ? react_1.default.createElement(solid_1.ChevronUpIcon, { className: 'h-3 w-3' }) : react_1.default.createElement(solid_1.ChevronDownIcon, { className: 'h-3 w-3' })),
            react_1.default.createElement(TruncatedTooltip_1.default, null, cellValue))) : (cellValue))));
}
exports.default = Row;
//# sourceMappingURL=Row.js.map