"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableBatchActions = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const Box_1 = require("../Box");
const Flex_1 = require("../Flex");
const Text_1 = require("../Text");
const Icon_1 = require("../Icon");
const Button_1 = require("../Button");
const TableBatchActions = ({ batchActions, showBatchActions, totalSelectedRows, selectedData, selectedRowIndices, refresh, lastUpdate, isLoading, }) => {
    const label = (str = '') => str
        .replace('{0}', `${totalSelectedRows}`)
        .replace('{s}', totalSelectedRows === 1 ? '' : 's');
    return ((0, jsx_runtime_1.jsx)(Flex_1.Flex, Object.assign({ variant: "raw" }, { children: batchActions.map((action, index) => {
            if (!(action.condition === true ||
                (action.condition === undefined &&
                    (!action.needsSelection ||
                        (action.needsSelection &&
                            showBatchActions &&
                            totalSelectedRows > 0)))) ||
                (!action.showWhenLoading && isLoading)) {
                return null;
            }
            return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [action.isRefresh && lastUpdate && ((0, jsx_runtime_1.jsx)(Box_1.Box, Object.assign({ variant: "raw", margin: "0 0 0 4px" }, { children: (0, jsx_runtime_1.jsx)(Text_1.Text, Object.assign({ variant: "span", format: "b3", color: "gray.1" }, { children: lastUpdate }), void 0) }), `batchAction${index + 1}LastUpdate`)), (0, jsx_runtime_1.jsx)(Box_1.Box, Object.assign({ variant: "raw", margin: "0 0 0 s" }, { children: (0, jsx_runtime_1.jsxs)(Button_1.Button, Object.assign({ variant: "primary", onClick: () => {
                                if (refresh && action.isRefresh)
                                    refresh();
                                else if (action.click)
                                    action.click(selectedData, selectedRowIndices);
                            } }, action.buttonProps, { children: [action.icon && ((0, jsx_runtime_1.jsx)(Icon_1.Icon, { variant: "basic", icon: action.icon, size: "15px", color: "brandMain", margin: "-2px s 0 0" }, void 0)), action.buttonProps &&
                                    action.buttonProps.variant === 'tertiary' ? ((0, jsx_runtime_1.jsx)(Text_1.Text, Object.assign({ variant: "span", format: "b2", color: "brandMain" }, { children: label(action.label) }), void 0)) : (label(action.label))] }), void 0) }), `batchAction${index + 1}`)] }, `batchAction${index + 1}Fragment`));
        }) }), void 0));
};
exports.TableBatchActions = TableBatchActions;
//# sourceMappingURL=TableBatchActions.js.map