import { jsx as r, jsxs as t, Fragment as y } from "react/jsx-runtime";
import { useState as c, useEffect as w, useMemo as k } from "react";
import { u as j, b as T, x as n, h as _ } from "./index-Bk6WqXgW.mjs";
const $ = {
  srt: "srt",
  vtt: "vtt",
  lrc: "lrc",
  elrc: "elrc",
  ass: "ass",
  ssa: "ssa",
  ttml: "ttml",
  dfxp: "ttml"
}, E = (s) => {
  var p;
  const a = ((p = s.split(".").pop()) == null ? void 0 : p.toLowerCase()) || "";
  return $[a];
}, R = ({ url: s, fileName: a }) => {
  const p = j(), [o, b] = c(""), [h, m] = c(!0), [x, u] = c(null);
  w(() => {
    (async () => {
      try {
        m(!0), u(null), b(await _(s));
      } catch (l) {
        console.error(l), u(p("subtitle.load_failed"));
      } finally {
        m(!1);
      }
    })();
  }, [s]);
  const f = k(() => {
    if (!o) return null;
    try {
      return T(o, E(a));
    } catch (e) {
      return console.error(e), null;
    }
  }, [o, a]);
  if (h)
    return /* @__PURE__ */ r("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full rfp-bg-[#0f0f12]", children: /* @__PURE__ */ r("div", { className: "rfp-w-12 rfp-h-12 rfp-border-4 rfp-border-line-strong rfp-border-t-spinner-head rfp-rounded-full rfp-animate-spin" }) });
  if (x || !f)
    return /* @__PURE__ */ r("div", { className: "rfp-flex rfp-items-center rfp-justify-center rfp-w-full rfp-h-full rfp-bg-[#0f0f12]", children: /* @__PURE__ */ r("div", { className: "rfp-text-fg-secondary rfp-text-center", children: /* @__PURE__ */ r("p", { className: "rfp-text-lg", children: x || p("subtitle.parse_failed") }) }) });
  const i = f.format === "lrc" || f.format === "elrc", g = f.metadata ?? {}, v = i ? "group-hover:rfp-bg-violet-400" : "group-hover:rfp-bg-sky-400";
  return /* @__PURE__ */ t("div", { className: "rfp-relative rfp-w-full rfp-h-full rfp-bg-[#0f0f12]", children: [
    /* @__PURE__ */ r("div", { className: "rfp-w-full rfp-h-full rfp-overflow-auto rfp-px-6 md:rfp-px-10 rfp-pt-6 rfp-pb-16 md:rfp-pb-20", children: /* @__PURE__ */ t("div", { className: "rfp-relative rfp-max-w-5xl rfp-mx-auto", children: [
      /* @__PURE__ */ r("div", { className: "rfp-absolute rfp-left-[5px] md:rfp-left-[7px] rfp-top-2 rfp-bottom-2 rfp-w-px rfp-bg-surface-1" }),
      /* @__PURE__ */ r("ol", { className: "rfp-space-y-5 md:rfp-space-y-6", children: f.cues.map((e, l) => /* @__PURE__ */ t("li", { className: "rfp-relative rfp-pl-6 md:rfp-pl-8 rfp-group", children: [
        /* @__PURE__ */ r(
          "div",
          {
            className: `rfp-absolute rfp-left-0 rfp-top-2 rfp-w-3 rfp-h-3 rfp-rounded-full rfp-bg-surface-3 rfp-border-2 rfp-border-[#0f0f12] rfp-transition-colors ${v}`
          }
        ),
        /* @__PURE__ */ t("div", { className: "rfp-flex rfp-flex-wrap rfp-items-baseline rfp-gap-x-3 rfp-gap-y-1 rfp-mb-1.5", children: [
          /* @__PURE__ */ r("span", { className: "rfp-text-[11px] rfp-font-mono rfp-text-fg-muted rfp-tabular-nums", children: n(e.start) }),
          /* @__PURE__ */ r("span", { className: "rfp-text-[11px] rfp-text-fg-disabled", children: "→" }),
          /* @__PURE__ */ r("span", { className: "rfp-text-[11px] rfp-font-mono rfp-text-fg-muted rfp-tabular-nums", children: n(e.end) }),
          /* @__PURE__ */ t("span", { className: "rfp-text-[10px] rfp-font-mono rfp-text-fg-disabled rfp-tabular-nums", children: [
            "#",
            e.id ?? l + 1
          ] }),
          e.style && /* @__PURE__ */ r("span", { className: "rfp-text-[9px] rfp-uppercase rfp-tracking-widest rfp-text-fg-tertiary rfp-px-1.5 rfp-py-0.5 rfp-rounded rfp-bg-surface-1 rfp-border rfp-border-line-weak", children: e.style })
        ] }),
        e.words && e.words.length > 0 ? /* @__PURE__ */ r("div", { className: "rfp-flex rfp-flex-wrap rfp-gap-x-1.5 rfp-gap-y-1 rfp-text-base md:rfp-text-lg rfp-text-fg-primary rfp-leading-relaxed group-hover:rfp-text-fg-primary rfp-transition-colors", children: e.words.map((d, N) => /* @__PURE__ */ t(
          "span",
          {
            className: "rfp-inline-flex rfp-flex-col rfp-items-start",
            title: n(d.start),
            children: [
              /* @__PURE__ */ r("span", { className: "rfp-text-[9px] rfp-text-fg-disabled rfp-font-mono rfp-leading-none rfp-tabular-nums", children: n(d.start).slice(3, 8) }),
              /* @__PURE__ */ r("span", { className: "rfp-leading-snug", children: d.text })
            ]
          },
          `w-${N}`
        )) }) : /* @__PURE__ */ r(
          "p",
          {
            className: `rfp-whitespace-pre-wrap rfp-break-words rfp-leading-relaxed group-hover:rfp-text-fg-primary rfp-transition-colors rfp-text-fg-primary ${i ? "rfp-text-base md:rfp-text-xl rfp-font-medium" : "rfp-text-sm md:rfp-text-base"}`,
            children: e.text
          }
        )
      ] }, `cue-${l}`)) })
    ] }) }),
    /* @__PURE__ */ t("div", { className: "rfp-pointer-events-none rfp-absolute rfp-bottom-3 rfp-right-3 md:rfp-bottom-4 md:rfp-right-4 rfp-flex rfp-items-center rfp-gap-2 rfp-px-2.5 rfp-py-1 rfp-rounded-full rfp-bg-surface-nav rfp-backdrop-blur rfp-border rfp-border-line-weak rfp-text-[10px] rfp-text-fg-tertiary rfp-font-mono rfp-tabular-nums", children: [
      /* @__PURE__ */ t("span", { children: [
        f.cues.length,
        " ",
        p(i ? "subtitle.lines" : "subtitle.cues")
      ] }),
      g.length && /* @__PURE__ */ t(y, { children: [
        /* @__PURE__ */ r("span", { className: "rfp-text-fg-disabled", children: "·" }),
        /* @__PURE__ */ r("span", { children: g.length })
      ] })
    ] })
  ] });
};
export {
  R as SubtitleRenderer
};
//# sourceMappingURL=index-j3RDh5hd.mjs.map
