import { getCurrentInstance as v, ref as k, inject as h, defineComponent as S, openBlock as g, createBlock as E, unref as P, withCtx as C, createTextVNode as M, toDisplayString as D } from "vue";
import { ElButton as I } from "element-plus";
const _ = Symbol("ModalStateToken"), O = () => h(_, {});
function R(n, t) {
  var r, o;
  const a = v(), s = a.provides[_];
  let e = O();
  s && (e = s);
  const l = (r = e.action) == null ? void 0 : r.getModalId(n), u = k(!0), w = (o = e.store) == null ? void 0 : o[l];
  return {
    show: (i) => {
      var p, d;
      if ((u.value || !w) && ((p = e.action) == null || p.register(
        l,
        n,
        t,
        //@ts-ignore
        a == null ? void 0 : a.provides
      ), u.value = !1), !e.modalPromise[l]) {
        let m, f;
        const T = new Promise((b, y) => {
          m = b, f = y;
        });
        e.modalPromise[l] = {
          promise: T,
          reject: f,
          resolve: m
        };
      }
      return (d = e.action) == null || d.show(l, i), e.modalPromise[l].promise;
    },
    hide: () => {
      var i;
      return (i = e.action) == null ? void 0 : i.hide(l);
    }
  };
}
const c = /* @__PURE__ */ new WeakMap(), j = (...n) => {
  var t;
  const r = n[0], o = (t = v()) == null ? void 0 : t.proxy;
  if (o == null)
    throw new Error("injectLocal must be called in setup");
  return c.has(o) && r in c.get(o) ? c.get(o)[r] : h(...n);
};
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const A = Symbol("FORM_PROVIDER_CONTEXT"), B = () => j(A), F = /* @__PURE__ */ S({
  __name: "Action",
  props: {
    component: {},
    params: {},
    label: {},
    row: {},
    buttonType: {}
  },
  setup(n) {
    const t = n, r = R(t.component), o = B(), a = () => {
      r.show({ ...t.params, row: t.row }).then(() => {
        o == null || o.reload();
      });
    };
    return (s, e) => (g(), E(P(I), {
      size: "small",
      plain: "",
      type: s.buttonType,
      onClick: a
    }, {
      default: C(() => [
        M(D(s.label), 1)
      ]),
      _: 1
    }, 8, ["type"]));
  }
});
export {
  F as default
};
//# sourceMappingURL=Action.mjs.map
