"use strict";

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

exports.__esModule = true;
exports.TimeAmPmEditor = 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 _Button = require("../../Button");

var _Block = require("../../Block");

var instanceCounter = 0;

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

  function TimeAmPmEditor(props, ctx) {
    var _this;

    _this = _React$PureComponent.call(this, props, ctx) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleToggleAmPM", function () {
      var _this$props = _this.props,
          isAm = _this$props.isAm,
          onAmPmChange = _this$props.onAmPmChange;
      onAmPmChange(!isAm);
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getTitle", function () {
      var _this$props2 = _this.props,
          isAm = _this$props2.isAm,
          enableAMTitle = _this$props2.enableAMTitle,
          enablePMTitle = _this$props2.enablePMTitle;
      return isAm ? enablePMTitle : enableAMTitle;
    });
    _this.instanceId = instanceCounter++;
    return _this;
  }

  var _proto = TimeAmPmEditor.prototype;

  _proto.render = function render() {
    var _this$props3 = this.props,
        isAm = _this$props3.isAm,
        amPmSwitcherLabel = _this$props3.amPmSwitcherLabel,
        amLabel = _this$props3.amLabel,
        pmLabel = _this$props3.pmLabel;
    var descriptionId = "amPmSwitcherDescription-" + this.instanceId;
    return _react.default.createElement(_Block.Block, {
      className: "rc-datepicker-am-pm-button",
      testAutomationId: "amPmSwitcher"
    }, _react.default.createElement("p", {
      className: "sr-only",
      id: descriptionId
    }, this.getTitle()), _react.default.createElement("div", {
      className: "text-center time-text"
    }, _react.default.createElement(_Button.Button, {
      testAutomationId: "amPmSwitchButton",
      onClick: this.handleToggleAmPM,
      bsStyle: "primary",
      "aria-label": amPmSwitcherLabel,
      title: this.getTitle(),
      "aria-describedby": descriptionId
    }, isAm ? amLabel : pmLabel)));
  };

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

exports.TimeAmPmEditor = TimeAmPmEditor;
(0, _defineProperty2.default)(TimeAmPmEditor, "propTypes", {
  isAm: _propTypes.default.bool.isRequired,
  onAmPmChange: _propTypes.default.func.isRequired,
  amLabel: _propTypes.default.string.isRequired,
  pmLabel: _propTypes.default.string.isRequired,
  amPmSwitcherLabel: _propTypes.default.string.isRequired,
  enablePMTitle: _propTypes.default.string.isRequired,
  enableAMTitle: _propTypes.default.string.isRequired
});