import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import { Button } from '../../Button';
import { Block } from '../../Block';
var instanceCounter = 0;
export var TimeAmPmEditor =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(TimeAmPmEditor, _React$PureComponent);

  function TimeAmPmEditor(props, ctx) {
    var _this;

    _this = _React$PureComponent.call(this, props, ctx) || this;

    _defineProperty(_assertThisInitialized(_this), "handleToggleAmPM", function () {
      var _this$props = _this.props,
          isAm = _this$props.isAm,
          onAmPmChange = _this$props.onAmPmChange;
      onAmPmChange(!isAm);
    });

    _defineProperty(_assertThisInitialized(_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.createElement(Block, {
      className: "rc-datepicker-am-pm-button",
      testAutomationId: "amPmSwitcher"
    }, React.createElement("p", {
      className: "sr-only",
      id: descriptionId
    }, this.getTitle()), React.createElement("div", {
      className: "text-center time-text"
    }, React.createElement(Button, {
      testAutomationId: "amPmSwitchButton",
      onClick: this.handleToggleAmPM,
      bsStyle: "primary",
      "aria-label": amPmSwitcherLabel,
      title: this.getTitle(),
      "aria-describedby": descriptionId
    }, isAm ? amLabel : pmLabel)));
  };

  return TimeAmPmEditor;
}(React.PureComponent);

_defineProperty(TimeAmPmEditor, "propTypes", {
  isAm: PropTypes.bool.isRequired,
  onAmPmChange: PropTypes.func.isRequired,
  amLabel: PropTypes.string.isRequired,
  pmLabel: PropTypes.string.isRequired,
  amPmSwitcherLabel: PropTypes.string.isRequired,
  enablePMTitle: PropTypes.string.isRequired,
  enableAMTitle: PropTypes.string.isRequired
});