import { makeAutoObservable } from "mobx";
import { EventBus } from "@dage/utils";

export class VideoSceneModel {
  event = new EventBus();

  /**
   * 播放中
   * @default true
   */
  playing = true;

  constructor() {
    makeAutoObservable(this);
  }

  /** 播放 */
  play() {
    window.ReactKrpanoActionProxy?.call("plugin[video].play()");
  }
  /** 暂停 */
  pause() {
    window.ReactKrpanoActionProxy?.call("plugin[video].pause()");
  }
}

export const videoSceneModel = new VideoSceneModel();

window.onVideoSceneReady = () => {
  videoSceneModel.event.emit("Event.videoScene.ready", undefined);
};
window.onVideoScenePlay = () => {
  videoSceneModel.playing = true;
  videoSceneModel.event.emit("Event.videoScene.play", undefined);
};
window.onVideoScenePaused = () => {
  videoSceneModel.playing = false;
  videoSceneModel.event.emit("Event.videoScene.pause", undefined);
};
window.onVideoSceneComplete = () => {
  videoSceneModel.event.emit("Event.videoScene.complete", undefined);
};
window.onVideoSceneError = (error: string) => {
  videoSceneModel.event.emit("Event.videoScene.error", error);
};
