var j = Object.defineProperty;
var r = (e, o) => j(e, "name", { value: o, configurable: !0 });

// src/actions/decorator.ts
import { global as F } from "@storybook/global";
import { makeDecorator as M, useEffect as C } from "storybook/preview-api";

// src/actions/constants.ts
var h = "actions", y = "storybook/actions", L = `${y}/panel`, g = `${y}/action-event`, W = `${y}/action-clear`;

// src/actions/runtime/action.ts
import { ImplicitActionsDuringRendering as S } from "storybook/internal/preview-errors";
import { global as E } from "@storybook/global";
import { addons as I } from "storybook/preview-api";
import { v4 as P } from "uuid";

// src/actions/runtime/configureActions.ts
var a = {
  depth: 10,
  clearOnStoryChange: !0,
  limit: 50
};

// src/actions/runtime/action.ts
var A = /* @__PURE__ */ r((e, o) => {
  let t = Object.getPrototypeOf(e);
  return !t || o(t) ? t : A(t, o);
}, "findProto"), x = /* @__PURE__ */ r((e) => !!(typeof e == "object" && e && A(e, (o) => /^Synthetic(?:Base)?Event$/.test(o.constructor.name)) &&
typeof e.persist == "function"), "isReactSyntheticEvent"), k = /* @__PURE__ */ r((e) => {
  if (x(e)) {
    let o = Object.create(
      e.constructor.prototype,
      Object.getOwnPropertyDescriptors(e)
    );
    o.persist();
    let t = Object.getOwnPropertyDescriptor(o, "view"), n = t?.value;
    return typeof n == "object" && n?.constructor.name === "Window" && Object.defineProperty(o, "view", {
      ...t,
      value: Object.create(n.constructor.prototype)
    }), o;
  }
  return e;
}, "serializeArg"), T = /* @__PURE__ */ r(() => typeof crypto == "object" && typeof crypto.getRandomValues == "function" ? P() : (
  // pseudo random id, example response lo1e7zm4832bkr7yfl7
  Date.now().toString(36) + Math.random().toString(36).substring(2)
), "generateId");
function O(e, o = {}) {
  let t = {
    ...a,
    ...o
  }, n = /* @__PURE__ */ r(function(...i) {
    if (o.implicit) {
      let u = ("__STORYBOOK_PREVIEW__" in E ? (
        // eslint-disable-next-line no-underscore-dangle
        E.__STORYBOOK_PREVIEW__
      ) : void 0)?.storyRenders.find(
        (c) => c.phase === "playing" || c.phase === "rendering"
      );
      if (u) {
        let c = !globalThis?.FEATURES?.disallowImplicitActionsInRenderV8, d = new S({
          phase: u.phase,
          name: e,
          deprecated: c
        });
        if (c)
          console.warn(d);
        else
          throw d;
      }
    }
    let m = I.getChannel(), p = T(), l = 5, f = i.map(k), R = i.length > 1 ? f : f[0], D = {
      id: p,
      count: 0,
      data: { name: e, args: R },
      options: {
        ...t,
        maxDepth: l + (t.depth || 3)
      }
    };
    m.emit(g, D);
  }, "actionHandler");
  return n.isAction = !0, n.implicit = o.implicit, n;
}
r(O, "action");

// src/actions/runtime/actions.ts
var b = /* @__PURE__ */ r((...e) => {
  let o = a, t = e;
  t.length === 1 && Array.isArray(t[0]) && ([t] = t), t.length !== 1 && typeof t[t.length - 1] != "string" && (o = {
    ...a,
    ...t.pop()
  });
  let n = t[0];
  (t.length !== 1 || typeof n == "string") && (n = {}, t.forEach((i) => {
    n[i] = i;
  }));
  let s = {};
  return Object.keys(n).forEach((i) => {
    s[i] = O(n[i], o);
  }), s;
}, "actions");

// src/actions/decorator.ts
var { document: v, Element: w } = F, N = /^(\S+)\s*(.*)$/, V = w != null && !w.prototype.matches, Y = V ? "msMatchesSelector" : "matches", _ = /* @__PURE__ */ r(
(e, o) => {
  if (e[Y](o))
    return !0;
  let t = e.parentElement;
  return t ? _(t, o) : !1;
}, "hasMatchInAncestry"), $ = /* @__PURE__ */ r((e, ...o) => {
  let t = e(...o);
  return Object.entries(t).map(([n, s]) => {
    let [i, m, p] = n.match(N) || [];
    return {
      eventName: m,
      handler: /* @__PURE__ */ r((l) => {
        (!p || _(l.target, p)) && s(l);
      }, "handler")
    };
  });
}, "createHandlers"), B = /* @__PURE__ */ r((e, ...o) => {
  let t = v && v.getElementById("storybook-root");
  C(() => {
    if (t != null) {
      let n = $(e, ...o);
      return n.forEach(({ eventName: s, handler: i }) => t.addEventListener(s, i)), () => n.forEach(({ eventName: s, handler: i }) => t.removeEventListener(
      s, i));
    }
  }, [t, e, o]);
}, "applyEventHandlers"), mt = M({
  name: "withActions",
  parameterName: h,
  skipIfNoParametersOrOptions: !0,
  wrapper: /* @__PURE__ */ r((e, o, { parameters: t }) => (t?.handles && B(b, ...t.handles), e(o)), "wrapper")
});
export {
  mt as withActions
};
