'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 __());
    };
})();
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { translate } from '../../utils';
import lang from '../../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({
            limitExceeded: maxCount && selectedCount > maxCount
        });
        return (React.createElement("span", { className: className },
            "(",
            React.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 ? (translate(this.props.showAllText)) : (React.createElement("span", null,
            translate(this.props.showSelectedText),
            " ",
            this.getShowSelectedCounter()));
        if (clickable) {
            return (React.createElement("a", { href: "#", onClick: function (e) {
                    e.preventDefault();
                    _this.props.onChange(mode);
                    return false;
                }, "data-test-automation-id": testAutomationId }, text));
        }
        return (React.createElement("strong", { className: "text-primary", "data-test-automation-id": testAutomationId }, text));
    };
    SelectedRecordsSwitcher.prototype.render = function () {
        return (React.createElement("div", { "data-test-automation-id": this.props.testAutomationId, className: classnames('store-selected-records-switcher', this.props.className) },
            this.getShowElement(MODE_ALL),
            React.createElement("span", { "aria-hidden": "true" }, "|"),
            this.getShowElement(MODE_SELECTED)));
    };
    SelectedRecordsSwitcher.propTypes = {
        className: PropTypes.string,
        testAutomationId: PropTypes.string,
        showAllText: PropTypes.string,
        showSelectedText: PropTypes.string,
        selectedCount: PropTypes.number.isRequired,
        maxCount: PropTypes.number,
        mode: PropTypes.oneOf([MODE_ALL, MODE_SELECTED]).isRequired,
        onChange: PropTypes.func.isRequired
    };
    SelectedRecordsSwitcher.defaultProps = {
        className: null,
        testAutomationId: null,
        maxCount: null,
        get showAllText() {
            return lang.SHOW_ALL;
        },
        get showSelectedText() {
            return lang.SHOW_SELECTED;
        }
    };
    return SelectedRecordsSwitcher;
}(React.Component));
export { SelectedRecordsSwitcher };
//# sourceMappingURL=SelectedRecordsSwitcher.js.map