"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ZoomControlsBase = exports.ZoomControls = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _mediaUi = require("@atlaskit/media-ui");
var _zoomOutMediaServicesZoomOut = _interopRequireDefault(require("@atlaskit/icon/core/migration/zoom-out--media-services-zoom-out"));
var _zoomInMediaServicesZoomIn = _interopRequireDefault(require("@atlaskit/icon/core/migration/zoom-in--media-services-zoom-in"));
var _styleWrappers = require("./styleWrappers");
var _analyticsNext = require("@atlaskit/analytics-next");
var _analytics = require("./analytics/");
var _zoomInButtonClicked = require("./analytics/events/ui/zoomInButtonClicked");
var _zoomOutButtonClicked = require("./analytics/events/ui/zoomOutButtonClicked");
var _reactIntlNext = require("react-intl-next");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var ZoomControlsBase = exports.ZoomControlsBase = /*#__PURE__*/function (_Component) {
  function ZoomControlsBase() {
    var _this;
    (0, _classCallCheck2.default)(this, ZoomControlsBase);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, ZoomControlsBase, [].concat(args));
    (0, _defineProperty2.default)(_this, "zoomIn", function () {
      var _this$props = _this.props,
        onChange = _this$props.onChange,
        zoomLevel = _this$props.zoomLevel,
        createAnalyticsEvent = _this$props.createAnalyticsEvent;
      if (zoomLevel.canZoomIn) {
        var zoom = zoomLevel.zoomIn();
        (0, _analytics.fireAnalytics)((0, _zoomInButtonClicked.createZoomInButtonClickEvent)(zoom.value), createAnalyticsEvent);
        onChange(zoom);
      }
    });
    (0, _defineProperty2.default)(_this, "zoomOut", function () {
      var _this$props2 = _this.props,
        onChange = _this$props2.onChange,
        zoomLevel = _this$props2.zoomLevel,
        createAnalyticsEvent = _this$props2.createAnalyticsEvent;
      if (zoomLevel.canZoomOut) {
        var zoom = zoomLevel.zoomOut();
        (0, _analytics.fireAnalytics)((0, _zoomOutButtonClicked.createZoomOutButtonClickedEvent)(zoom.value), createAnalyticsEvent);
        onChange(zoom);
      }
    });
    return _this;
  }
  (0, _inherits2.default)(ZoomControlsBase, _Component);
  return (0, _createClass2.default)(ZoomControlsBase, [{
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
        zoomLevel = _this$props3.zoomLevel,
        formatMessage = _this$props3.intl.formatMessage,
        children = _this$props3.children;
      return (
        /*#__PURE__*/
        // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
        _react.default.createElement(_styleWrappers.ZoomWrapper, {
          className: _mediaUi.hideControlsClassName
        }, /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomCenterControls, null, /*#__PURE__*/_react.default.createElement(_mediaUi.MediaButton, {
          isDisabled: !zoomLevel.canZoomOut,
          onClick: this.zoomOut,
          iconBefore: /*#__PURE__*/_react.default.createElement(_zoomOutMediaServicesZoomOut.default, {
            color: "currentColor",
            spacing: "spacious",
            label: formatMessage(_mediaUi.messages.zoom_out)
          })
        }), /*#__PURE__*/_react.default.createElement(_mediaUi.MediaButton, {
          isDisabled: !zoomLevel.canZoomIn,
          onClick: this.zoomIn,
          iconBefore: /*#__PURE__*/_react.default.createElement(_zoomInMediaServicesZoomIn.default, {
            color: "currentColor",
            spacing: "spacious",
            label: formatMessage(_mediaUi.messages.zoom_in)
          })
        })), /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomRightControls, null, children, /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomLevelIndicator, null, zoomLevel.asPercentage)))
      );
    }
  }]);
}(_react.Component); // @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
var ZoomControls = exports.ZoomControls = (0, _analyticsNext.withAnalyticsEvents)({})((0, _reactIntlNext.injectIntl)(ZoomControlsBase));