'use strict';

import _createClass from "@babel/runtime/helpers/createClass";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { translate } from '../../utils';
var MODE_ALL = 'MODE_ALL';
var MODE_SELECTED = 'MODE_SELECTED';
export var SelectedRecordsSwitcher =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(SelectedRecordsSwitcher, _React$Component);

  function SelectedRecordsSwitcher() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = SelectedRecordsSwitcher.prototype;

  _proto.getShowSelectedCounter = function getShowSelectedCounter() {
    var _this$props = this.props,
        selectedCount = _this$props.selectedCount,
        maxCount = _this$props.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), ")");
  };

  _proto.getShowElement = function getShowElement(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 onClick(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);
  };

  _proto.render = function render() {
    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));
  };

  _createClass(SelectedRecordsSwitcher, null, [{
    key: "MODE_ALL",
    get: function get() {
      return MODE_ALL;
    }
  }, {
    key: "MODE_SELECTED",
    get: function get() {
      return MODE_SELECTED;
    }
  }]);

  return SelectedRecordsSwitcher;
}(React.Component);

_defineProperty(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
});

_defineProperty(SelectedRecordsSwitcher, "defaultProps", {
  className: null,
  testAutomationId: null,
  maxCount: null,
  showAllText: 'TRANSLATE:SHOW_ALL',
  showSelectedText: 'TRANSLATE:SHOW_SELECTED'
});