"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableBatchActions = void 0;
const react_1 = __importStar(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");
exports.TableBatchActions = ({ batchActions, showBatchActions, totalSelectedRows, selectedData, selectedRowIndices, refresh, lastUpdate, isLoading, }) => {
    const label = (str = '') => str
        .replace('{0}', `${totalSelectedRows}`)
        .replace('{s}', totalSelectedRows === 1 ? '' : 's');
    return (react_1.default.createElement(Flex_1.Flex, null, batchActions.map((action, index) => {
        if (!(action.condition === true ||
            (action.condition === undefined &&
                (!action.needsSelection ||
                    (action.needsSelection &&
                        showBatchActions &&
                        totalSelectedRows > 0)))) ||
            (!action.showWhenLoading && isLoading)) {
            return null;
        }
        return (react_1.default.createElement(react_1.Fragment, { key: `batchAction${index}Fragment` },
            action.isRefresh && lastUpdate && (react_1.default.createElement(Box_1.Box, { key: `batchAction${index}LastUpdate`, ml: "4px" },
                react_1.default.createElement(Text_1.Text, { variant: "b3", color: "gray.1" }, lastUpdate))),
            react_1.default.createElement(Box_1.Box, { key: `batchAction${index}`, ml: "s" },
                react_1.default.createElement(Button_1.Button, Object.assign({ onClick: () => {
                        if (refresh && action.isRefresh)
                            refresh();
                        else if (action.click)
                            action.click(selectedData, selectedRowIndices);
                    } }, action.buttonProps),
                    action.icon && (react_1.default.createElement(Icon_1.Icon, { Asset: action.icon, width: 15, height: 15, color: "brandMain", mt: "-2px", mr: "s" })),
                    action.buttonProps &&
                        action.buttonProps.variant === 'ghost' ? (react_1.default.createElement(Text_1.Text, { variant: "b2", color: "brandMain" }, label(action.label))) : (label(action.label))))));
    })));
};
//# sourceMappingURL=TableBatchActions.js.map