import { jsx as e, jsxs as a } from "react/jsx-runtime";
import { useState as u, useRef as v, useEffect as g } from "react";
import x from "video.js";
import { u as y } from "./index-Bk6WqXgW.mjs";
const b = (r) => {
  var s;
  const o = ((s = r.split(".").pop()) == null ? void 0 : s.toLowerCase().split("?")[0]) || "";
  return {
    mp4: "video/mp4",
    webm: "video/webm",
    ogg: "video/ogg",
    ogv: "video/ogg",
    mov: "video/quicktime",
    // MOV 使用 QuickTime MIME 类型
    avi: "video/x-msvideo",
    mkv: "video/x-matroska",
    m4v: "video/mp4",
    "3gp": "video/3gpp",
    flv: "video/x-flv"
  }[o] || "video/mp4";
}, L = ({ url: r }) => {
  const o = y(), [f, s] = u(null), [h, d] = u(!0), n = v(null), l = v(null);
  return g(() => {
    if (!l.current && n.current) {
      const t = document.createElement("video-js");
      t.classList.add("vjs-big-play-centered", "vjs-theme-apple"), n.current.appendChild(t);
      const c = b(r), i = x(t, {
        controls: !0,
        fill: !0,
        preload: "auto",
        controlBar: {
          children: [
            "playToggle",
            "volumePanel",
            "currentTimeDisplay",
            "timeDivider",
            "durationDisplay",
            "progressControl",
            "remainingTimeDisplay",
            "fullscreenToggle"
          ],
          volumePanel: {
            inline: !1
          }
        },
        html5: {
          vhs: {
            overrideNative: !0
          },
          nativeVideoTracks: !1,
          nativeAudioTracks: !1,
          nativeTextTracks: !1
        },
        sources: c === "video/quicktime" ? [
          { src: r, type: "video/quicktime" },
          { src: r, type: "video/mp4" }
          // 备用方案
        ] : [{ src: r, type: c }]
      }), m = i.el().querySelector("video");
      m && (m.style.objectFit = "contain"), i.on("loadeddata", () => {
        d(!1);
      }), i.on("error", () => {
        const p = i.error();
        console.error("Video.js error:", p), s(o("video.load_failed_with_error", { error: (p == null ? void 0 : p.message) || o("common.unknown_error") })), d(!1);
      }), l.current = i;
    }
  }, [r]), g(() => {
    const t = l.current;
    return () => {
      t && !t.isDisposed() && (t.dispose(), l.current = null);
    };
  }, []), f ? /* @__PURE__ */ e("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ a("div", { className: "rfp-text-center", children: [
    /* @__PURE__ */ e("div", { className: "rfp-w-16 rfp-h-16 rfp-mx-auto rfp-mb-4 rfp-rounded-full rfp-bg-red-500/10 rfp-flex rfp-items-center rfp-justify-center", children: /* @__PURE__ */ e("svg", { className: "rfp-w-8 rfp-h-8 rfp-text-red-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ e("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" }) }) }),
    /* @__PURE__ */ e("p", { className: "rfp-text-lg rfp-font-medium rfp-text-fg-primary rfp-mb-2", children: o("video.load_failed") }),
    /* @__PURE__ */ e("p", { className: "rfp-text-sm rfp-text-fg-tertiary", children: f })
  ] }) }) : /* @__PURE__ */ e("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full", children: /* @__PURE__ */ a("div", { className: "rfp-w-full rfp-h-full rfp-relative", children: [
    h && /* @__PURE__ */ e("div", { className: "rfp-absolute rfp-inset-0 rfp-flex rfp-items-center rfp-justify-center rfp-bg-surface-3 rfp-backdrop-blur-sm rfp-z-10", children: /* @__PURE__ */ a("div", { className: "rfp-text-center", children: [
      /* @__PURE__ */ e("div", { className: "rfp-w-12 rfp-h-12 rfp-mx-auto rfp-mb-3 rfp-border-3 rfp-border-line-strong rfp-border-t-spinner-head rfp-rounded-full rfp-animate-spin" }),
      /* @__PURE__ */ e("p", { className: "rfp-text-sm rfp-text-fg-secondary rfp-font-medium", children: o("video.loading") })
    ] }) }),
    /* @__PURE__ */ e(
      "div",
      {
        ref: n,
        className: "rfp-overflow-hidden rfp-w-full rfp-h-full [&_video]:rfp-object-contain",
        style: {
          boxShadow: "0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.05)"
        }
      }
    )
  ] }) });
};
export {
  L as VideoRenderer
};
//# sourceMappingURL=index-CuNzcYw0.mjs.map
