import { defineComponent as r, watch as S, openBlock as h, createElementBlock as b, ref as H, onMounted as O } from "vue";
import d from "hls.js";
import { cloneDeep as J, isEqual as M } from "lodash";
const _ = ["poster", "autoplay", "controls", "loop", "muted"], R = r({ name: "zv-media-m3u8" }), A = /* @__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(p, { expose: v, emit: u }) {
    const o = p, l = () => {
      const e = H(), s = (t) => {
        if (t)
          if (d.isSupported()) {
            const a = new d();
            a.loadSource(t), a.attachMedia(e.value), a.on(d.Events.MANIFEST_PARSED, () => {
              o.basicOption.autoplay && e.value.play();
            });
          } else e.value.canPlayType("application/vnd.apple.mpegurl") && (e.value.src = t);
      };
      return O(() => s(o.basicOption.src)), { videoRef: e, initM3u8Video: s };
    }, { videoRef: i, initM3u8Video: c } = l();
    S(() => J(o.basicOption), (e, s) => {
      M(e, s) || c(e.src);
    }, { deep: !0 });
    const n = u, m = () => {
      n("on-video-progress"), window.SHJParseEvent(o.useEvents, "on-video-progress");
    }, E = () => {
      n("on-video-play"), window.SHJParseEvent(o.useEvents, "on-video-play");
    }, f = () => {
      n("on-video-pause"), window.SHJParseEvent(o.useEvents, "on-video-pause");
    }, y = () => {
      n("on-video-ended"), window.SHJParseEvent(o.useEvents, "on-video-ended");
    }, w = () => {
      n("on-video-playing"), window.SHJParseEvent(o.useEvents, "on-video-playing");
    }, P = () => {
      n("on-video-timeupdate"), window.SHJParseEvent(o.useEvents, "on-video-timeupdate");
    }, g = () => {
      n("on-video-error"), window.SHJParseEvent(o.useEvents, "on-video-error");
    }, V = () => {
      n("on-video-volumechange"), window.SHJParseEvent(o.useEvents, "on-video-volumechange");
    };
    return v({
      /** 开始播放 */
      play: () => {
        i.value && i.value.play();
      },
      /** 暂停播放 */
      pause: () => {
        i.value && i.value.pause();
      }
    }), (e, s) => (h(), b("video", {
      ref_key: "videoRef",
      ref: i,
      class: "zerov-widget",
      poster: e.basicOption.poster,
      autoplay: e.basicOption.autoplay,
      controls: e.basicOption.controls,
      loop: e.basicOption.loop,
      muted: e.basicOption.muted,
      onProgress: m,
      onPlay: E,
      onEnded: y,
      onPlaying: w,
      onPause: f,
      onTimeupdate: P,
      onError: g,
      onVolumechange: V
    }, null, 40, _));
  }
});
export {
  A as default
};
