'use strict';
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var classnames_1 = __importDefault(require("classnames"));
var utils_1 = require("../../utils");
var index_en_US_1 = __importDefault(require("../../lang/common/index-en_US"));
var MODE_ALL = 'MODE_ALL';
var MODE_SELECTED = 'MODE_SELECTED';
var SelectedRecordsSwitcher = /** @class */ (function (_super) {
    __extends(SelectedRecordsSwitcher, _super);
    function SelectedRecordsSwitcher() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Object.defineProperty(SelectedRecordsSwitcher, "MODE_ALL", {
        get: function () {
            return MODE_ALL;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(SelectedRecordsSwitcher, "MODE_SELECTED", {
        get: function () {
            return MODE_SELECTED;
        },
        enumerable: true,
        configurable: true
    });
    SelectedRecordsSwitcher.prototype.getShowSelectedCounter = function () {
        var _a = this.props, selectedCount = _a.selectedCount, maxCount = _a.maxCount;
        var className = classnames_1.default({
            limitExceeded: maxCount && selectedCount > maxCount
        });
        return (react_1.default.createElement("span", { className: className },
            "(",
            react_1.default.createElement("span", { "data-test-automation-id": "count" },
                selectedCount,
                maxCount ? '/' + maxCount : null),
            ")"));
    };
    SelectedRecordsSwitcher.prototype.getShowElement = function (mode) {
        var _this = this;
        var clickable = this.props.mode !== mode;
        var isModeAll = mode === MODE_ALL;
        var testAutomationId = isModeAll ? 'showAllButton' : 'showSelectedButton';
        var text = isModeAll ? (utils_1.translate(this.props.showAllText)) : (react_1.default.createElement("span", null,
            utils_1.translate(this.props.showSelectedText),
            " ",
            this.getShowSelectedCounter()));
        if (clickable) {
            return (react_1.default.createElement("a", { href: "#", onClick: function (e) {
                    e.preventDefault();
                    _this.props.onChange(mode);
                    return false;
                }, "data-test-automation-id": testAutomationId }, text));
        }
        return (react_1.default.createElement("strong", { className: "text-primary", "data-test-automation-id": testAutomationId }, text));
    };
    SelectedRecordsSwitcher.prototype.render = function () {
        return (react_1.default.createElement("div", { "data-test-automation-id": this.props.testAutomationId, className: classnames_1.default('store-selected-records-switcher', this.props.className) },
            this.getShowElement(MODE_ALL),
            react_1.default.createElement("span", { "aria-hidden": "true" }, "|"),
            this.getShowElement(MODE_SELECTED)));
    };
    SelectedRecordsSwitcher.propTypes = {
        className: prop_types_1.default.string,
        testAutomationId: prop_types_1.default.string,
        showAllText: prop_types_1.default.string,
        showSelectedText: prop_types_1.default.string,
        selectedCount: prop_types_1.default.number.isRequired,
        maxCount: prop_types_1.default.number,
        mode: prop_types_1.default.oneOf([MODE_ALL, MODE_SELECTED]).isRequired,
        onChange: prop_types_1.default.func.isRequired
    };
    SelectedRecordsSwitcher.defaultProps = {
        className: null,
        testAutomationId: null,
        maxCount: null,
        get showAllText() {
            return index_en_US_1.default.SHOW_ALL;
        },
        get showSelectedText() {
            return index_en_US_1.default.SHOW_SELECTED;
        }
    };
    return SelectedRecordsSwitcher;
}(react_1.default.Component));
exports.SelectedRecordsSwitcher = SelectedRecordsSwitcher;
//# sourceMappingURL=SelectedRecordsSwitcher.js.map