import { defineComponent as m, watch as p, ref as d, openBlock as b, createElementBlock as x, unref as u, withDirectives as O, createElementVNode as r, vShow as V, normalizeClass as F, onMounted as B, nextTick as T, createStaticVNode as z } from "vue";
import { nanoid as G } from "nanoid";
import { cloneDeep as v, isEqual as f } from "lodash";
const M = ["autoplay", "loop", "muted"], N = ["src"], R = /* @__PURE__ */ z('<svg width="100%" height="100%" viewBox="0 0 75 75" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-a3d928ad><circle cx="37.5" cy="37.5" r="37.5" fill="#3D9CFF" fill-opacity="0.1" data-v-a3d928ad></circle><path fill-rule="evenodd" clip-rule="evenodd" d="M51.3268 20.4054H33.1254C32.2255 20.4 31.3554 20.728 30.6832 21.3264C30.0109 21.9247 29.5841 22.7508 29.4852 23.6453L27.0161 44.2762C26.1001 43.746 25.053 43.4598 23.9763 43.4598C22.3672 43.4598 20.824 44.099 19.6862 45.2368C18.5484 46.3746 17.9092 47.9178 17.9092 49.5269C17.9092 51.136 18.5484 52.6792 19.6862 53.817C20.824 54.9548 22.3672 55.594 23.9763 55.594C25.5854 55.594 27.1286 54.9548 28.2664 53.817C29.3529 52.7305 29.9848 51.2743 30.0395 49.744L30.0555 49.746L32.361 31.3141H50.5623L48.8975 44.2994C47.9722 43.7543 46.9103 43.4598 45.818 43.4598C44.2089 43.4598 42.6657 44.099 41.5279 45.2368C40.3901 46.3746 39.7509 47.9178 39.7509 49.5269C39.7509 51.136 40.3901 52.6792 41.5279 53.817C42.6657 54.9548 44.2089 55.594 45.818 55.594C47.4271 55.594 48.9703 54.9548 50.1081 53.817C51.1946 52.7305 51.8265 51.2743 51.8812 49.744L51.8971 49.746L54.9792 24.434C55.034 23.9233 54.9801 23.4069 54.8211 22.9185C54.6621 22.4301 54.4015 21.981 54.0566 21.6005C53.7116 21.22 53.29 20.9168 52.8196 20.7108C52.3491 20.5049 51.8403 20.4008 51.3268 20.4054Z" fill="url(#paint0_linear_534:1941)" data-v-a3d928ad></path><defs data-v-a3d928ad><linearGradient id="paint0_linear_534:1941" x1="17.9092" y1="37.9996" x2="56.4836" y2="37.9996" gradientUnits="userSpaceOnUse" data-v-a3d928ad><stop stop-color="#3D9CFF" data-v-a3d928ad></stop><stop offset="1" stop-color="#43E8F3" data-v-a3d928ad></stop></linearGradient></defs></svg>', 1), U = [
  R
], q = m({ name: "zv-media-audio-dynamic" }), Q = /* @__PURE__ */ m({
  ...q,
  props: {
    basicOption: {},
    sources: {},
    useEvents: {},
    uuid: {}
  },
  emits: [
    "on-audio-progress",
    "on-audio-play",
    "on-audio-pause",
    "on-audio-ended",
    "on-audio-playing",
    "on-audio-timeupdate",
    "on-audio-error",
    "on-audio-volumechange"
  ],
  setup(w, { expose: y, emit: E }) {
    const e = w, C = () => {
      const o = d(""), s = d(G()), D = d(!1), l = () => {
        window.SHJDatasourceV2({
          tId: e.uuid,
          sources: e.sources,
          callback: ({ data: c }) => {
            try {
              window.SHJParseEvent(e.useEvents, "dataListener", c), o.value = c[0].data[0].src;
            } catch {
              window.SHJParseEvent(e.useEvents, "dataListener", null);
            }
          }
        });
      };
      return B(() => T(() => l())), { init: l, src: o, key: s, isAudioPlay: D };
    }, { init: i, src: h, key: g, isAudioPlay: n } = C();
    p(() => v(e.basicOption), (o, s) => {
      f(o, s) || i();
    }, {
      deep: !0
    }), p(() => v(e.sources), (o, s) => {
      f(o, s) || i();
    }, { deep: !0 });
    const t = d(), a = E, P = () => {
      a("on-audio-progress"), window.SHJParseEvent(e.useEvents, "on-audio-progress"), n.value = !0;
    }, _ = () => {
      a("on-audio-play"), window.SHJParseEvent(e.useEvents, "on-audio-play"), n.value = !0;
    }, S = () => {
      a("on-audio-pause"), window.SHJParseEvent(e.useEvents, "on-audio-pause"), n.value = !1;
    }, H = () => {
      a("on-audio-ended"), window.SHJParseEvent(e.useEvents, "on-audio-ended"), n.value = !1;
    }, A = () => {
      a("on-audio-playing"), window.SHJParseEvent(e.useEvents, "on-audio-playing");
    }, J = () => {
      a("on-audio-timeupdate"), window.SHJParseEvent(e.useEvents, "on-audio-timeupdate");
    }, k = () => {
      a("on-audio-error"), window.SHJParseEvent(e.useEvents, "on-audio-error"), n.value = !1;
    }, L = () => {
      a("on-audio-volumechange"), window.SHJParseEvent(e.useEvents, "on-audio-volumechange");
    };
    return y({
      /** 开始播放 */
      play: () => {
        t.value && t.value.play();
      },
      /** 暂停播放 */
      pause: () => {
        t.value && t.value.pause();
      },
      refresh: () => i(),
      refreshView: () => i(),
      refreshData: () => i()
    }), (o, s) => (b(), x("div", {
      key: u(g),
      class: "audio"
    }, [
      O(r("audio", {
        ref_key: "audioRef",
        ref: t,
        autoplay: o.basicOption.autoplay,
        loop: o.basicOption.loop,
        controls: !1,
        muted: o.basicOption.muted,
        onProgress: P,
        onPlay: _,
        onEnded: H,
        onPlaying: A,
        onPause: S,
        onTimeupdate: J,
        onError: k,
        onVolumechange: L
      }, [
        r("source", { src: u(h) }, null, 8, N)
      ], 40, M), [
        [V, !1]
      ]),
      r("div", {
        class: F(["audio-svg", {
          animation: u(n)
        }])
      }, U, 2)
    ]));
  }
});
export {
  Q as default
};
