"use strict";

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

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

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

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

var _assert = _interopRequireDefault(require("../utils/assert"));

function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var TransitionInterpolator = function () {
  function TransitionInterpolator(opts) {
    (0, _classCallCheck2.default)(this, TransitionInterpolator);
    this._propsToCompare = void 0;
    this._propsToExtract = void 0;
    this._requiredProps = void 0;
    var compare = opts.compare,
        extract = opts.extract,
        required = opts.required;
    this._propsToCompare = compare;
    this._propsToExtract = extract || compare;
    this._requiredProps = required;
  }

  var _proto = TransitionInterpolator.prototype;

  _proto.arePropsEqual = function arePropsEqual(currentProps, nextProps) {
    var _iterator = _createForOfIteratorHelper(this._propsToCompare),
        _step;

    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var key = _step.value;

        if (!(key in currentProps) || !(key in nextProps) || !(0, _core.equals)(currentProps[key], nextProps[key])) {
          return false;
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }

    return true;
  };

  _proto.initializeProps = function initializeProps(startProps, endProps) {
    var startViewStateProps = {};
    var endViewStateProps = {};

    var _iterator2 = _createForOfIteratorHelper(this._propsToExtract),
        _step2;

    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var key = _step2.value;

        if (key in startProps || key in endProps) {
          startViewStateProps[key] = startProps[key];
          endViewStateProps[key] = endProps[key];
        }
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }

    this._checkRequiredProps(startViewStateProps);

    this._checkRequiredProps(endViewStateProps);

    return {
      start: startViewStateProps,
      end: endViewStateProps
    };
  };

  _proto.getDuration = function getDuration(startProps, endProps) {
    return endProps.transitionDuration;
  };

  _proto._checkRequiredProps = function _checkRequiredProps(props) {
    if (!this._requiredProps) {
      return;
    }

    this._requiredProps.forEach(function (propName) {
      var value = props[propName];
      (0, _assert.default)(Number.isFinite(value) || Array.isArray(value), "".concat(propName, " is required for transition"));
    });
  };

  return TransitionInterpolator;
}();

exports.default = TransitionInterpolator;
//# sourceMappingURL=transition-interpolator.js.map