import { defineComponent, useAttrs, ref, onMounted, watch, createElementBlock, openBlock, mergeProps, unref, createElementVNode, createTextVNode } from 'vue';
import '../../../utils/index.mjs';
import { videoPlayerProps } from './video-player.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
const _hoisted_1 = ["src", "poster", "autoplay", "loop", "preload", "muted", "controls", "width", "height"];
const _hoisted_2 = ["src", "type"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlVideoPlayer" },
  __name: "video-player",
  props: videoPlayerProps,
  setup(__props) {
    const attrs = useAttrs();
    const bem = createNamespace("video-player");
    const props = __props;
    const videoElement = ref();
    const videoTypeMap = {
      MP4: "video/mp4",
      WebM: "video/webm",
      OGG: "video/ogg",
      MOV: "video/quicktime",
      AVI: "video/x-msvideo",
      WMV: "video/x-ms-wmv",
      FLV: "video/x-flv",
      MKV: "video/x-matroska"
    };
    const getType = (format) => {
      return videoTypeMap[format.toUpperCase()] || "video/mp4";
    };
    const tryAutoplay = () => {
      const video = videoElement.value;
      if (!video || !props.autoplay) return;
      video.play().catch(() => {
        video.muted = true;
        video.play().catch(() => {
        });
      });
    };
    onMounted(() => {
      tryAutoplay();
    });
    watch(
      () => props.src,
      () => {
        const video = videoElement.value;
        if (!video) return;
        video.load();
        tryAutoplay();
      }
    );
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("video", mergeProps({
        ref_key: "videoElement",
        ref: videoElement
      }, unref(attrs), {
        class: [unref(bem).b()],
        src: _ctx.src,
        poster: _ctx.poster,
        autoplay: _ctx.autoplay,
        loop: _ctx.loop,
        preload: _ctx.preload,
        muted: _ctx.muted,
        controls: _ctx.controls,
        width: _ctx.width,
        height: _ctx.height
      }), [
        createElementVNode("source", {
          src: _ctx.src,
          type: getType(_ctx.format)
        }, null, 8, _hoisted_2),
        _cache[0] || (_cache[0] = createTextVNode(
          " \u60A8\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u89C6\u9891\u64AD\u653E\u3002 ",
          -1
          /* CACHED */
        ))
      ], 16, _hoisted_1);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=video-player.vue2.mjs.map
