export default class Transition {
  constructor(timeline) {
    this._inProgress = false;
    this._handle = null;
    this._timeline = void 0;
    this.time = 0;
    this.settings = {
      duration: 0
    };
    this._timeline = timeline;
  }

  get inProgress() {
    return this._inProgress;
  }

  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);
  }

  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);
    }
  }

  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;
    }
  }

  update() {
    var _this$settings$onUpda, _this$settings4;

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

    if (this._handle === null) {
      const {
        _timeline: timeline,
        settings
      } = this;
      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;
  }

  _onUpdate() {}

}
//# sourceMappingURL=transition.js.map