"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableRowActions = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Flex_1 = require("../Flex");
const Box_1 = require("../Box");
const TableCheckbox_1 = require("./TableCheckbox");
const Icon_1 = require("../Icon");
const icons_1 = require("../../theme/icons");
const Tooltip_1 = require("../Tooltip");
const TableRowActions = ({ hooks, selectable, setShowBatchActions, rowActions, subRow, setSkipTableReset, rowsIndexesCheckboxesDisabled, rowsIndexesCheckboxesHidden, }) => {
    hooks.visibleColumns.push((cols) => [
        ...(selectable
            ? [
                {
                    id: 'selection',
                    width: 30,
                    Header: ({ getToggleAllRowsSelectedProps, }) => ((0, jsx_runtime_1.jsx)(TableCheckbox_1.TableCheckbox, Object.assign({}, getToggleAllRowsSelectedProps(), { setShowBatchActions: setShowBatchActions }), void 0)),
                    Cell: ({ row }) => (rowsIndexesCheckboxesHidden === null || rowsIndexesCheckboxesHidden === void 0 ? void 0 : rowsIndexesCheckboxesHidden.includes(row.index)) ? null : ((0, jsx_runtime_1.jsx)(TableCheckbox_1.TableCheckbox, Object.assign({}, row.getToggleRowSelectedProps(), ((rowsIndexesCheckboxesDisabled === null || rowsIndexesCheckboxesDisabled === void 0 ? void 0 : rowsIndexesCheckboxesDisabled.includes(row.index)) && {
                        disabled: true,
                        checked: false,
                    })), void 0)),
                },
            ]
            : []),
        ...cols,
        ...(rowActions
            ? [
                {
                    id: 'action',
                    width: 30,
                    Cell: ({ row }) => ((0, jsx_runtime_1.jsx)(Flex_1.Flex, Object.assign({ variant: "raw", justify: "end" }, { children: rowActions.map((rowAction) => {
                            const showTooltip = rowAction.showTooltip
                                ? rowAction === null || rowAction === void 0 ? void 0 : rowAction.showTooltip(row.original)
                                : true;
                            const isDisabled = rowAction.disabled
                                ? rowAction.disabled(row.original, row.index)
                                : false;
                            const RowActionWrapper = (props) => isDisabled && rowAction.disabledTooltip && showTooltip ? ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, Object.assign({}, props), void 0)) : ((0, jsx_runtime_1.jsx)(Box_1.Box, Object.assign({}, props), void 0));
                            return ((0, jsx_runtime_1.jsx)(Box_1.Box, Object.assign({ variant: "raw", margin: "0 0 0 s" }, { children: (0, jsx_runtime_1.jsx)(RowActionWrapper, Object.assign({}, (rowAction.disabledTooltip
                                    ? {
                                        content: rowAction.disabledTooltip(row.original, row.index),
                                    }
                                    : {}), { children: (0, jsx_runtime_1.jsx)(rowAction.Content, Object.assign({}, rowAction.ContentProps, { className: rowAction.onlyShowOnHover ? 'showOnHover' : null, onClick: () => {
                                            if (!rowAction.disabled ||
                                                (rowAction.disabled &&
                                                    !rowAction.disabled(row.original, row.index))) {
                                                setSkipTableReset(true);
                                                rowAction.action(row.original, row.index);
                                                setTimeout(() => {
                                                    setSkipTableReset(false);
                                                }, 300);
                                            }
                                        }, disabled: isDisabled }, { children: rowAction.ContentChildren &&
                                            (rowAction.ContentChildren instanceof Function
                                                ? rowAction.ContentChildren(row.original)
                                                : rowAction.ContentChildren) }), void 0) }), void 0) }), rowAction.id));
                        }) }), void 0)),
                },
            ]
            : []),
        ...(subRow
            ? [
                {
                    id: 'expansion',
                    width: 30,
                    Cell: ({ row }) => ((0, jsx_runtime_1.jsx)("span", Object.assign({}, row.getToggleRowExpandedProps(), { children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { variant: "basic", icon: row.isExpanded
                                ? icons_1.polyIcons.ChevronDown
                                : icons_1.polyIcons.ChevronLeft, size: "24px", color: "gray3" }, void 0) }), void 0)),
                },
            ]
            : []),
    ]);
};
exports.TableRowActions = TableRowActions;
//# sourceMappingURL=TableRowActions.js.map