import { defineComponent as v, watch as S, ref as r, openBlock as k, createElementBlock as b, unref as u, onMounted as O, nextTick as _ } from "vue";
import { nanoid as D } from "nanoid";
import { cloneDeep as T, isEqual as z } from "lodash";
const B = ["poster", "autoplay", "controls", "loop", "muted", "src"], L = v({ name: "zv-media-video-dynamic" }), M = /* @__PURE__ */ v({
  ...L,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  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(c, { expose: p, emit: l }) {
    const e = c, m = () => {
      const o = r(""), t = r(D()), a = () => {
        window.SHJDatasourceV2({
          tId: e.uuid,
          sources: e.sources,
          callback: ({ data: d }) => {
            try {
              window.SHJParseEvent(e.useEvents, "dataListener", d), o.value = d[0].data[0].src;
            } catch {
              window.SHJParseEvent(e.useEvents, "dataListener", null);
            }
          }
        });
      };
      return O(() => _(() => a())), { init: a, src: o, key: t };
    }, { init: i, src: E, key: w } = m();
    S(() => T(e.sources), (o, t) => {
      z(o, t) || i();
    }, { deep: !0 });
    const s = r(), n = l, y = () => {
      n("on-video-progress"), window.SHJParseEvent(e.useEvents, "on-video-progress");
    }, f = () => {
      n("on-video-play"), window.SHJParseEvent(e.useEvents, "on-video-play");
    }, P = () => {
      n("on-video-pause"), window.SHJParseEvent(e.useEvents, "on-video-pause");
    }, g = () => {
      n("on-video-ended"), window.SHJParseEvent(e.useEvents, "on-video-ended");
    }, V = () => {
      n("on-video-playing"), window.SHJParseEvent(e.useEvents, "on-video-playing");
    }, h = () => {
      n("on-video-timeupdate"), window.SHJParseEvent(e.useEvents, "on-video-timeupdate");
    }, H = () => {
      n("on-video-error"), window.SHJParseEvent(e.useEvents, "on-video-error");
    }, J = () => {
      n("on-video-volumechange"), window.SHJParseEvent(e.useEvents, "on-video-volumechange");
    };
    return p({
      /** 开始播放 */
      play: () => {
        s.value && s.value.play();
      },
      /** 暂停播放 */
      pause: () => {
        s.value && s.value.pause();
      },
      refresh: () => i(),
      refreshView: () => i(),
      refreshData: () => i()
    }), (o, t) => (k(), b("video", {
      ref_key: "videoRef",
      ref: s,
      key: u(w),
      poster: o.basicOption.poster,
      autoplay: o.basicOption.autoplay,
      controls: o.basicOption.controls,
      loop: o.basicOption.loop,
      muted: o.basicOption.muted,
      class: "zerov-widget-video",
      src: u(E),
      onProgress: y,
      onPlay: f,
      onEnded: g,
      onPlaying: V,
      onPause: P,
      onTimeupdate: h,
      onError: H,
      onVolumechange: J
    }, null, 40, B));
  }
});
export {
  M as default
};
