"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

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

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

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

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

var _core = require("@math.gl/core");

var _controller = _interopRequireDefault(require("./controller"));

var _orbitController = require("./orbit-controller");

var _linearInterpolator = _interopRequireDefault(require("../transitions/linear-interpolator"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var OrthographicState = function (_OrbitState) {
  (0, _inherits2.default)(OrthographicState, _OrbitState);

  var _super = _createSuper(OrthographicState);

  function OrthographicState(props) {
    var _this;

    (0, _classCallCheck2.default)(this, OrthographicState);
    _this = _super.call(this, props);
    _this.zoomAxis = void 0;
    _this.zoomAxis = props.zoomAxis || 'all';
    return _this;
  }

  var _proto = OrthographicState.prototype;

  _proto._calculateNewZoom = function _calculateNewZoom(_ref) {
    var scale = _ref.scale,
        startZoom = _ref.startZoom;

    var _this$getViewportProp = this.getViewportProps(),
        maxZoom = _this$getViewportProp.maxZoom,
        minZoom = _this$getViewportProp.minZoom;

    if (startZoom === undefined) {
      startZoom = this.getViewportProps().zoom;
    }

    var deltaZoom = Math.log2(scale);

    if (Array.isArray(startZoom)) {
      var _startZoom = startZoom,
          _startZoom2 = (0, _slicedToArray2.default)(_startZoom, 2),
          newZoomX = _startZoom2[0],
          newZoomY = _startZoom2[1];

      switch (this.zoomAxis) {
        case 'X':
          newZoomX = (0, _core.clamp)(newZoomX + deltaZoom, minZoom, maxZoom);
          break;

        case 'Y':
          newZoomY = (0, _core.clamp)(newZoomY + deltaZoom, minZoom, maxZoom);
          break;

        default:
          var z = Math.min(newZoomX + deltaZoom, newZoomY + deltaZoom);

          if (z < minZoom) {
            deltaZoom += minZoom - z;
          }

          z = Math.max(newZoomX + deltaZoom, newZoomY + deltaZoom);

          if (z > maxZoom) {
            deltaZoom += maxZoom - z;
          }

          newZoomX += deltaZoom;
          newZoomY += deltaZoom;
      }

      return [newZoomX, newZoomY];
    }

    return (0, _core.clamp)(startZoom + deltaZoom, minZoom, maxZoom);
  };

  return OrthographicState;
}(_orbitController.OrbitState);

var OrthographicController = function (_Controller) {
  (0, _inherits2.default)(OrthographicController, _Controller);

  var _super2 = _createSuper(OrthographicController);

  function OrthographicController() {
    var _this2;

    (0, _classCallCheck2.default)(this, OrthographicController);

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

    _this2 = _super2.call.apply(_super2, [this].concat(args));
    _this2.ControllerState = OrthographicState;
    _this2.transition = {
      transitionDuration: 300,
      transitionInterpolator: new _linearInterpolator.default(['target', 'zoom'])
    };
    _this2.dragMode = 'pan';
    return _this2;
  }

  var _proto2 = OrthographicController.prototype;

  _proto2._onPanRotate = function _onPanRotate() {
    return false;
  };

  return OrthographicController;
}(_controller.default);

exports.default = OrthographicController;
//# sourceMappingURL=orthographic-controller.js.map