import { r as U, s as B, H as E, v as h, V as L, j as b, w as x } from "./index-CsBCemCF.js";
import { memo as Y, useRef as J, useMemo as V, useEffect as n } from "react";
const X = /* @__PURE__ */ U("iframe", process.env.NODE_ENV === "production" ? {
  target: "evvcert0"
} : {
  target: "evvcert0",
  label: "StyledVideoIframe"
})(({
  theme: r
}) => ({
  colorScheme: "normal",
  border: "none",
  padding: r.spacing.none,
  margin: r.spacing.none,
  width: "100%",
  aspectRatio: "16 / 9"
}), process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3J1bm5lci93b3JrL3N0bGl0ZS9zdGxpdGUvc3RyZWFtbGl0L2Zyb250ZW5kL2xpYi9zcmMvY29tcG9uZW50cy9lbGVtZW50cy9WaWRlby9zdHlsZWQtY29tcG9uZW50cy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFrQmlDIiwiZmlsZSI6Ii9ob21lL3J1bm5lci93b3JrL3N0bGl0ZS9zdGxpdGUvc3RyZWFtbGl0L2Zyb250ZW5kL2xpYi9zcmMvY29tcG9uZW50cy9lbGVtZW50cy9WaWRlby9zdHlsZWQtY29tcG9uZW50cy50cyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogQ29weXJpZ2h0IChjKSBTdHJlYW1saXQgSW5jLiAoMjAxOC0yMDIyKSBTbm93Zmxha2UgSW5jLiAoMjAyMi0yMDI1KVxuICpcbiAqIExpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSBcIkxpY2Vuc2VcIik7XG4gKiB5b3UgbWF5IG5vdCB1c2UgdGhpcyBmaWxlIGV4Y2VwdCBpbiBjb21wbGlhbmNlIHdpdGggdGhlIExpY2Vuc2UuXG4gKiBZb3UgbWF5IG9idGFpbiBhIGNvcHkgb2YgdGhlIExpY2Vuc2UgYXRcbiAqXG4gKiAgICAgaHR0cDovL3d3dy5hcGFjaGUub3JnL2xpY2Vuc2VzL0xJQ0VOU0UtMi4wXG4gKlxuICogVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZVxuICogZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gXCJBUyBJU1wiIEJBU0lTLFxuICogV0lUSE9VVCBXQVJSQU5USUVTIE9SIENPTkRJVElPTlMgT0YgQU5ZIEtJTkQsIGVpdGhlciBleHByZXNzIG9yIGltcGxpZWQuXG4gKiBTZWUgdGhlIExpY2Vuc2UgZm9yIHRoZSBzcGVjaWZpYyBsYW5ndWFnZSBnb3Zlcm5pbmcgcGVybWlzc2lvbnMgYW5kXG4gKiBsaW1pdGF0aW9ucyB1bmRlciB0aGUgTGljZW5zZS5cbiAqL1xuXG5pbXBvcnQgc3R5bGVkIGZyb20gXCJAZW1vdGlvbi9zdHlsZWRcIlxuXG5leHBvcnQgY29uc3QgU3R5bGVkVmlkZW9JZnJhbWUgPSBzdHlsZWQuaWZyYW1lKCh7IHRoZW1lIH0pID0+ICh7XG4gIGNvbG9yU2NoZW1lOiBcIm5vcm1hbFwiLFxuICBib3JkZXI6IFwibm9uZVwiLFxuICBwYWRkaW5nOiB0aGVtZS5zcGFjaW5nLm5vbmUsXG4gIG1hcmdpbjogdGhlbWUuc3BhY2luZy5ub25lLFxuICB3aWR0aDogXCIxMDAlXCIsXG4gIGFzcGVjdFJhdGlvOiBcIjE2IC8gOVwiLFxufSkpXG4iXX0= */"), j = x.getLogger("Video"), N = {
  width: "100%"
};
function C({
  element: r,
  endpoints: c,
  elementMgr: p
}) {
  const o = J(null), {
    type: y,
    url: Z,
    startTime: i,
    subtitles: W,
    endTime: a,
    loop: l,
    autoplay: G,
    muted: g
  } = r, u = B(Z), s = E(W);
  let I = h(u);
  const v = V(() => {
    if (!r.id)
      return !0;
    const e = p.getElementState(r.id, "preventAutoplay");
    return e || p.setElementState(r.id, "preventAutoplay", !0), e ?? !1;
  }, [r.id, p]), m = V(() => JSON.stringify(s ? s.map((e) => c.buildMediaURL(`${e.url}`)) : []), [s, c]);
  n(() => {
    const e = JSON.parse(m);
    e.length !== 0 && e.forEach((t) => {
      c.checkSourceUrlResponse(t, "Video Subtitle");
    });
  }, [m, c]), n(() => {
    o.current && (o.current.currentTime = i);
  }, [i]), n(() => {
    const e = o.current, t = () => {
      e && (e.currentTime = r.startTime);
    };
    return e && e.addEventListener("loadedmetadata", t), () => {
      e && e.removeEventListener("loadedmetadata", t);
    };
  }, [r]), n(() => {
    const e = o.current;
    if (!e)
      return;
    let t = !1;
    const d = () => {
      a > 0 && e.currentTime >= a && (l ? (e.currentTime = i || 0, e.play()) : t || (t = !0, e.pause()));
    };
    return a > 0 && e.addEventListener("timeupdate", d), () => {
      e && a > 0 && e.removeEventListener("timeupdate", d);
    };
  }, [a, l, i]), n(() => {
    const e = o.current;
    if (!e)
      return;
    const t = () => {
      l && (e.currentTime = i || 0, e.play());
    };
    return e.addEventListener("ended", t), () => {
      e && e.removeEventListener("ended", t);
    };
  }, [l, i]);
  const f = (e) => {
    const t = new URL(e);
    if (i && !isNaN(i) && t.searchParams.append("start", i.toString()), a && !isNaN(a) && t.searchParams.append("end", a.toString()), l) {
      t.searchParams.append("loop", "1");
      const d = t.pathname.split("/").pop();
      d && t.searchParams.append("playlist", d);
    }
    return G && t.searchParams.append("autoplay", "1"), g && t.searchParams.append("mute", "1"), t.toString();
  };
  if (y === L.Type.YOUTUBE_IFRAME)
    return /* @__PURE__ */ b.jsx(X, { className: "stVideo", "data-testid": "stVideo", title: u, src: f(u), allow: "autoplay; encrypted-media", allowFullScreen: !0 });
  const S = (e) => {
    const t = e.currentTarget.src;
    j.error(`Client Error: Video source error - ${t}`), c.sendClientErrorToHost("Video", "Video source failed to load", "onerror triggered", t);
  };
  return process.env.NODE_ENV === "development" && s.length > 0 && (I = "anonymous"), // eslint-disable-next-line jsx-a11y/media-has-caption
  /* @__PURE__ */ b.jsx("video", { className: "stVideo", "data-testid": "stVideo", ref: o, controls: !0, muted: g, autoPlay: G && !v, src: c.buildMediaURL(u), style: N, crossOrigin: I, onError: S, children: s?.map((e, t) => /* @__PURE__ */ b.jsx(
    "track",
    {
      kind: "captions",
      src: c.buildMediaURL(`${e.url}`),
      label: `${e.label}`,
      default: t === 0,
      "data-testid": "stVideoSubtitle"
    },
    t
  )) });
}
const T = Y(C);
export {
  T as default
};
//# sourceMappingURL=index-Dj7MXPcv.js.map
