"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 _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var Transition = function () {
  function Transition(timeline) {
    (0, _classCallCheck2.default)(this, Transition);
    this._inProgress = false;
    this._handle = null;
    this._timeline = void 0;
    this.time = 0;
    this.settings = {
      duration: 0
    };
    this._timeline = timeline;
  }

  var _proto = Transition.prototype;

  _proto.start = function start(settings) {
    var _this$settings$onStar, _this$settings;

    this.cancel();
    this.settings = settings;
    this._inProgress = true;
    (_this$settings$onStar = (_this$settings = this.settings).onStart) === null || _this$settings$onStar === void 0 ? void 0 : _this$settings$onStar.call(_this$settings, this);
  };

  _proto.end = function end() {
    if (this._inProgress) {
      var _this$settings$onEnd, _this$settings2;

      this._timeline.removeChannel(this._handle);

      this._handle = null;
      this._inProgress = false;
      (_this$settings$onEnd = (_this$settings2 = this.settings).onEnd) === null || _this$settings$onEnd === void 0 ? void 0 : _this$settings$onEnd.call(_this$settings2, this);
    }
  };

  _proto.cancel = function cancel() {
    if (this._inProgress) {
      var _this$settings$onInte, _this$settings3;

      (_this$settings$onInte = (_this$settings3 = this.settings).onInterrupt) === null || _this$settings$onInte === void 0 ? void 0 : _this$settings$onInte.call(_this$settings3, this);

      this._timeline.removeChannel(this._handle);

      this._handle = null;
      this._inProgress = false;
    }
  };

  _proto.update = function update() {
    var _this$settings$onUpda, _this$settings4;

    if (!this._inProgress) {
      return false;
    }

    if (this._handle === null) {
      var timeline = this._timeline,
          settings = this.settings;
      this._handle = timeline.addChannel({
        delay: timeline.getTime(),
        duration: settings.duration
      });
    }

    this.time = this._timeline.getTime(this._handle);

    this._onUpdate();

    (_this$settings$onUpda = (_this$settings4 = this.settings).onUpdate) === null || _this$settings$onUpda === void 0 ? void 0 : _this$settings$onUpda.call(_this$settings4, this);

    if (this._timeline.isFinished(this._handle)) {
      this.end();
    }

    return true;
  };

  _proto._onUpdate = function _onUpdate() {};

  (0, _createClass2.default)(Transition, [{
    key: "inProgress",
    get: function get() {
      return this._inProgress;
    }
  }]);
  return Transition;
}();

exports.default = Transition;
//# sourceMappingURL=transition.js.map