import { defineComponent as r, watch as h, openBlock as b, createElementBlock as O, ref as S, onMounted as H } from "vue";
import { cloneDeep as J, isEqual as _ } from "lodash";
import d from "flv.js";
const F = ["poster", "autoplay", "controls", "loop", "muted"], R = r({ name: "zv-media-flv" }), M = /* @__PURE__ */ r({
  ...R,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {}
  },
  emits: [
    "on-video-progress",
    "on-video-play",
    "on-video-pause",
    "on-video-ended",
    "on-video-playing",
    "on-video-timeupdate",
    "on-video-error",
    "on-video-volumechange"
  ],
  setup(v, { expose: p, emit: l }) {
    const e = v, u = () => {
      const o = S(), s = (a) => {
        if (a && d.isSupported())
          try {
            const t = d.createPlayer({
              type: "flv",
              url: a
            });
            t.attachMediaElement(o.value), t.load(), e.basicOption.autoplay && t.play();
          } catch {
          }
      };
      return H(() => s(e.basicOption.src)), { videoRef: o, initFlvVideo: s };
    }, { videoRef: i, initFlvVideo: c } = u();
    h(() => J(e.basicOption), (o, s) => {
      _(o, s) || c(o.src);
    }, { deep: !0 });
    const n = l, m = () => {
      n("on-video-progress"), window.SHJParseEvent(e.useEvents, "on-video-progress");
    }, f = () => {
      n("on-video-play"), window.SHJParseEvent(e.useEvents, "on-video-play");
    }, E = () => {
      n("on-video-pause"), window.SHJParseEvent(e.useEvents, "on-video-pause");
    }, y = () => {
      n("on-video-ended"), window.SHJParseEvent(e.useEvents, "on-video-ended");
    }, P = () => {
      n("on-video-playing"), window.SHJParseEvent(e.useEvents, "on-video-playing");
    }, w = () => {
      n("on-video-timeupdate"), window.SHJParseEvent(e.useEvents, "on-video-timeupdate");
    }, g = () => {
      n("on-video-error"), window.SHJParseEvent(e.useEvents, "on-video-error");
    }, V = () => {
      n("on-video-volumechange"), window.SHJParseEvent(e.useEvents, "on-video-volumechange");
    };
    return p({
      /** 开始播放 */
      play: () => {
        i.value && i.value.play();
      },
      /** 暂停播放 */
      pause: () => {
        i.value && i.value.pause();
      }
    }), (o, s) => (b(), O("video", {
      ref_key: "videoRef",
      ref: i,
      class: "zerov-widget",
      poster: o.basicOption.poster,
      autoplay: o.basicOption.autoplay,
      controls: o.basicOption.controls,
      loop: o.basicOption.loop,
      muted: o.basicOption.muted,
      onProgress: m,
      onPlay: f,
      onEnded: y,
      onPlaying: P,
      onPause: E,
      onTimeupdate: w,
      onError: g,
      onVolumechange: V
    }, null, 40, F));
  }
});
export {
  M as default
};
