"use client";
import { getMergedEmbedOption as x, isString as E, getSwatchAspectRatio as A, camelCaseToKebabCase as b, isValidEmbedOption as B, wistiaPlayerStyleBlock as C, isFunction as I } from "./chunk-FSLSW5KG.es.js";
import { forwardRef as F, useRef as K, useState as g, useEffect as y, Fragment as M } from "react";
import { jsxs as R, jsx as S } from "react/jsx-runtime";
var T = (a) => {
  const e = {};
  return Object.entries(a).forEach(([c, r]) => {
    typeof r == "boolean" ? e[c] = String(r) : e[c] = r;
  }), e;
}, V = F(
  (a, e) => {
    const { aspect: c, children: r, className: v, embedHost: d, id: o, mediaId: n, roundedPlayer: P, swatch: m, style: O } = a, p = x(n, "embedHost", d != null ? d : void 0), l = E(p) ? p : "fast.wistia.com", h = K(null), [f, j] = g(c), [W, D] = g(!1);
    y(() => {
      m !== !1 && f === void 0 && E(l) && A(n, l).then((t) => {
        j(t);
      }), import("./wistia-player-PKAEVX5L.es.js"), customElements.whenDefined("wistia-player").then(() => {
        D(!0);
      });
    }, []);
    const u = {}, w = {};
    Object.entries(a).forEach(([t, s]) => {
      if (t.startsWith("on") && t[2] === t[2].toUpperCase()) {
        const i = b(t).slice(3);
        I(s) && (u[i] = s);
      } else B(s) && (w[b(t)] = s);
    }), Object.entries(u).forEach(([t, s]) => {
      y(() => {
        const i = h.current;
        return i == null || i.addEventListener(t, s), () => {
          i == null || i.removeEventListener(t, s);
        };
      }, [s, W]);
    });
    const H = f !== void 0, L = C({
      mediaId: n,
      embedHost: l,
      aspect: f,
      shouldLoadSwatch: m,
      roundedPlayer: P
    });
    return /* @__PURE__ */ R(M, { children: [
      H && /* @__PURE__ */ S("style", { dangerouslySetInnerHTML: { __html: L } }),
      /* @__PURE__ */ S(
        "wistia-player",
        {
          ref: ((t) => {
            h.current = t, typeof e == "function" ? e(t) : e !== null && (e.current = t);
          }),
          id: o != null ? o : void 0,
          "media-id": n,
          class: v,
          style: O,
          react: String(!0),
          ...T(w),
          children: r
        },
        o != null ? o : n
      )
    ] });
  }
);
export {
  V as WistiaPlayerWrapper
};
