"use strict";
/* eslint-disable react/display-name */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableRowActions = void 0;
const react_1 = __importDefault(require("react"));
const Flex_1 = require("../Flex");
const Box_1 = require("../Box");
const TableCheckbox_1 = require("./TableCheckbox");
const Icon_1 = require("../Icon");
const icons_1 = require("../../assets/images/icons");
const Tooltip_1 = require("../Tooltip");
exports.TableRowActions = ({ hooks, selectable, setShowBatchActions, rowActions, subRow, setSkipTableReset, rowsIndexesCheckboxesDisabled, rowsIndexesCheckboxesHidden, }) => {
    hooks.visibleColumns.push((cols) => [
        ...(selectable
            ? [
                {
                    id: 'selection',
                    width: 30,
                    Header: ({ getToggleAllRowsSelectedProps, }) => (react_1.default.createElement(TableCheckbox_1.TableCheckbox, Object.assign({}, getToggleAllRowsSelectedProps(), { setShowBatchActions: setShowBatchActions }))),
                    Cell: ({ row }) => (rowsIndexesCheckboxesHidden === null || rowsIndexesCheckboxesHidden === void 0 ? void 0 : rowsIndexesCheckboxesHidden.includes(row.index)) ? null : (react_1.default.createElement(TableCheckbox_1.TableCheckbox, Object.assign({}, row.getToggleRowSelectedProps(), ((rowsIndexesCheckboxesDisabled === null || rowsIndexesCheckboxesDisabled === void 0 ? void 0 : rowsIndexesCheckboxesDisabled.includes(row.index)) && {
                        disabled: true,
                        checked: false,
                    })))),
                },
            ]
            : []),
        ...cols,
        ...(rowActions
            ? [
                {
                    id: 'action',
                    width: 30,
                    Cell: ({ row }) => (react_1.default.createElement(Flex_1.Flex, { justifyContent: "flex-end" }, 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 ? (react_1.default.createElement(Tooltip_1.Tooltip, Object.assign({}, props))) : (react_1.default.createElement(Box_1.Box, Object.assign({}, props)));
                        return (react_1.default.createElement(Box_1.Box, { key: rowAction.id, ml: "s" },
                            react_1.default.createElement(RowActionWrapper, Object.assign({}, (rowAction.disabledTooltip
                                ? {
                                    content: rowAction.disabledTooltip(row.original, row.index),
                                }
                                : {})),
                                react_1.default.createElement(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 }), rowAction.ContentChildren &&
                                    (rowAction.ContentChildren instanceof Function
                                        ? rowAction.ContentChildren(row.original)
                                        : rowAction.ContentChildren)))));
                    }))),
                },
            ]
            : []),
        ...(subRow
            ? [
                {
                    id: 'expansion',
                    width: 30,
                    Cell: ({ row }) => (react_1.default.createElement("span", Object.assign({}, row.getToggleRowExpandedProps()),
                        react_1.default.createElement(Icon_1.Icon, { Asset: row.isExpanded ? icons_1.SvgChevronDown : icons_1.SvgChevronLeft, width: 24, height: 24, color: "gray.3" }))),
                },
            ]
            : []),
    ]);
};
//# sourceMappingURL=TableRowActions.js.map