"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.SwitcherItem = void 0;

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var SwitcherItem =
/*#__PURE__*/
function (_React$PureComponent) {
  (0, _inheritsLoose2.default)(SwitcherItem, _React$PureComponent);

  function SwitcherItem() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function () {
      _this.context.onItemClick(_this.props.id);
    });
    return _this;
  }

  var _proto = SwitcherItem.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        children = _this$props.children,
        id = _this$props.id,
        label = _this$props.label,
        testAutomationId = _this$props.testAutomationId;
    var className = (0, _classnames.default)('rc-switcher__item', {
      'rc-switcher__item_selected': this.context.selectedId === id
    });
    return _react.default.createElement("button", {
      "data-test-automation-id": testAutomationId,
      className: className,
      onClick: this.onClick,
      "aria-label": label
    }, children);
  };

  return SwitcherItem;
}(_react.default.PureComponent);

exports.SwitcherItem = SwitcherItem;
(0, _defineProperty2.default)(SwitcherItem, "contextTypes", {
  selectedId: _propTypes.default.string.isRequired,
  onItemClick: _propTypes.default.func.isRequired
});
(0, _defineProperty2.default)(SwitcherItem, "propTypes", {
  id: _propTypes.default.string.isRequired,
  testAutomationId: _propTypes.default.string,
  label: _propTypes.default.string.isRequired
});
(0, _defineProperty2.default)(SwitcherItem, "defaultProps", {
  testAutomationId: null
});