import { defineComponent as j, renderSlot as I, getCurrentInstance as W, inject as G, unref as f, watch as V, isRef as H, shallowRef as L, ref as A, openBlock as J, createBlock as Q, withCtx as m, createVNode as v, createTextVNode as F, toDisplayString as S, createElementVNode as M } from "vue";
import { ElTableColumn as Y, ElButton as k, ElPopover as Z } from "element-plus";
import { useRouter as x } from "vue-router";
const D = /* @__PURE__ */ j({
  name: "If",
  __name: "If",
  props: {
    when: {}
  },
  setup(e) {
    const o = (n) => n;
    return (n, l) => n.when ? I(n.$slots, "default", {
      key: 0,
      value: o(n.when)
    }) : I(n.$slots, "fallback", { key: 1 });
  }
}), B = /* @__PURE__ */ new WeakMap(), N = (...e) => {
  var o;
  const n = e[0], l = (o = W()) == null ? void 0 : o.proxy;
  if (l == null)
    throw new Error("injectLocal must be called in setup");
  return B.has(l) && n in B.get(l) ? B.get(l)[n] : G(...e);
};
function O(e) {
  return typeof e == "function" ? e() : f(e);
}
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
const K = () => {
};
function z(e, o = !1, n = "Timeout") {
  return new Promise((l, d) => {
    setTimeout(o ? () => d(n) : l, e);
  });
}
function X(e, o = !1) {
  function n(r, { flush: t = "sync", deep: i = !1, timeout: u, throwOnTimeout: h } = {}) {
    let a = null;
    const C = [new Promise((_) => {
      a = V(
        e,
        (y) => {
          r(y) !== o && (a == null || a(), _(y));
        },
        {
          flush: t,
          deep: i,
          immediate: !0
        }
      );
    })];
    return u != null && C.push(
      z(u, h).then(() => O(e)).finally(() => a == null ? void 0 : a())
    ), Promise.race(C);
  }
  function l(r, t) {
    if (!H(r))
      return n((y) => y === r, t);
    const { flush: i = "sync", deep: u = !1, timeout: h, throwOnTimeout: a } = t ?? {};
    let s = null;
    const _ = [new Promise((y) => {
      s = V(
        [e, r],
        ([c, R]) => {
          o !== (c === R) && (s == null || s(), y(c));
        },
        {
          flush: i,
          deep: u,
          immediate: !0
        }
      );
    })];
    return h != null && _.push(
      z(h, a).then(() => O(e)).finally(() => (s == null || s(), O(e)))
    ), Promise.race(_);
  }
  function d(r) {
    return n((t) => !!t, r);
  }
  function T(r) {
    return l(null, r);
  }
  function b(r) {
    return l(void 0, r);
  }
  function E(r) {
    return n(Number.isNaN, r);
  }
  function P(r, t) {
    return n((i) => {
      const u = Array.from(i);
      return u.includes(r) || u.includes(O(r));
    }, t);
  }
  function w(r) {
    return p(1, r);
  }
  function p(r = 1, t) {
    let i = -1;
    return n(() => (i += 1, i >= r), t);
  }
  return Array.isArray(O(e)) ? {
    toMatch: n,
    toContains: P,
    changed: w,
    changedTimes: p,
    get not() {
      return X(e, !o);
    }
  } : {
    toMatch: n,
    toBe: l,
    toBeTruthy: d,
    toBeNull: T,
    toBeNaN: E,
    toBeUndefined: b,
    changed: w,
    changedTimes: p,
    get not() {
      return X(e, !o);
    }
  };
}
function ee(e) {
  return X(e);
}
const te = {
  rowKey: "id",
  title: "Fast Start",
  routerMode: "hash",
  basename: "/"
}, ne = Symbol("FAST_START_CONTEXT"), le = () => N(ne, te), oe = () => {
  const { basename: e } = le();
  return ({ resource: o, id: n, type: l }) => {
    switch (l) {
      case "list":
        return g(`${e}/${o}`);
      case "create":
        return g(`${e}/${o}/create`);
      case "edit":
        return n == null ? g(`${e}/${o}/edit`) : g(`${e}/${o}/edit/${encodeURIComponent(n)}`);
      case "detail":
        return n == null ? g(`${e}/${o}/detail`) : g(
          `${e}/${o}/detail/${encodeURIComponent(n)}`
        );
      default:
        return l;
    }
  };
}, g = (e) => e.replace("//", "/"), re = Symbol("RESOURCE_CONTEXT"), ae = () => N(re, { name: "" }), se = Symbol("FORM_PROVIDER_CONTEXT"), ie = () => N(se), ue = {
  create: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  deleteOne: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  getList: () => Promise.resolve({
    data: Array.from({ length: 30 }).map((e, o) => ({
      name: o,
      id: o
    })),
    total: 20
  }),
  // avoids adding a context in tests
  getMany: () => Promise.resolve({ data: [] }),
  // avoids adding a context in tests
  getManyReference: () => Promise.resolve({ data: [], total: 0 }),
  // avoids adding a context in tests
  getOne: () => Promise.resolve({ data: null }),
  // avoids adding a context in tests
  update: () => Promise.resolve({ data: null })
  // avoids adding a context in tests
}, ce = Symbol("DATA_PROVIDER_CONTEXT"), q = () => N(ce, ue);
function de(e) {
  const {
    initialData: o,
    shallow: n,
    onSuccess: l = K,
    onError: d = K,
    immediate: T,
    resetOnExecute: b = !1,
    queryFn: E,
    queryKey: P
  } = e, w = (n ? L : A)(o), p = A(!1), r = A(!1), t = A(!1), i = L(), u = (c) => {
    r.value = c, p.value = !c;
  }, h = () => {
    b && (w.value = o);
  }, a = () => new Promise((c, R) => {
    ee(p).toBe(!0).then(() => i.value ? R(i.value) : c(y));
  }), s = {
    then: (...c) => a().then(...c),
    catch: (...c) => a().catch(...c)
  };
  let C = 0;
  const _ = (c) => {
    if (i.value = void 0, r.value)
      return s;
    if (E === void 0)
      return p.value = !0, s;
    h(), u(!0), C += 1;
    const R = C;
    return E(c).then(($) => {
      const U = $;
      w.value = U, l(U);
    }).catch(($) => {
      i.value = $, d($);
    }).finally(() => {
      var $;
      ($ = e.onFinish) == null || $.call(e), R === C && u(!1);
    }), s;
  };
  T && _();
  const y = {
    data: w,
    error: i,
    isFinished: p,
    isLoading: r,
    isAborted: t,
    isCanceled: t,
    execute: _
  };
  return {
    ...y,
    ...s
  };
}
const fe = (e, o = !1) => {
  const { deleteOne: n } = q(), l = de({
    immediate: o,
    queryFn: (T) => n(e, T)
  }), d = l.execute;
  return { ...l, sendDelete: d };
}, pe = { class: "fast-start-table-delete-button" }, Te = /* @__PURE__ */ j({
  name: "FsTableActionColumn",
  __name: "FsTableActionColumn",
  props: {
    label: { default: "操作" },
    fixed: { type: [String, Boolean], default: "right" },
    width: { default: "150px" },
    edit: { default: () => ({
      label: "编辑",
      show: !0,
      buttonType: "default",
      type: "view"
    }) },
    detail: { default: () => ({
      label: "详情",
      show: !1,
      type: "view"
    }) },
    delete: { default: () => ({
      label: "删除",
      show: !0,
      buttonType: "danger",
      title: "确认删除该条数据吗?"
    }) }
  },
  emits: ["edit", "delete", "detail"],
  setup(e, { emit: o }) {
    const n = e, l = ie();
    q();
    const d = o, T = oe(), { name: b } = ae(), E = x(), P = fe(b), w = (t) => {
      if (n.edit.type === "view") {
        const i = T({
          resource: b,
          type: "edit",
          id: t[(l == null ? void 0 : l.rowKey) || "id"]
        });
        E.push(i);
      } else
        d("edit", t);
    }, p = (t) => {
      if (n.detail.type === "view") {
        const i = T({
          resource: b,
          type: "detail",
          id: t[(l == null ? void 0 : l.rowKey) || "id"]
        });
        E.push(i);
      } else
        d("detail", t);
    }, r = (t) => {
      n.delete.custom ? d("delete", t) : P.sendDelete({ ...t, id: t[(l == null ? void 0 : l.rowKey) || "id"] }).then(() => {
        l == null || l.reload();
      });
    };
    return (t, i) => (J(), Q(f(Y), {
      label: t.label,
      fixed: t.fixed,
      width: t.width
    }, {
      default: m(({ row: u }) => {
        var h;
        return [
          v(f(D), {
            when: t.edit.show
          }, {
            default: m(() => {
              var a;
              return [
                v(f(k), {
                  size: "small",
                  onClick: (s) => w(u),
                  plain: "",
                  type: (a = t.edit) == null ? void 0 : a.buttonType
                }, {
                  default: m(() => [
                    F(S(t.edit.label), 1)
                  ]),
                  _: 2
                }, 1032, ["onClick", "type"])
              ];
            }),
            _: 2
          }, 1032, ["when"]),
          v(f(D), {
            when: t.detail.show
          }, {
            default: m(() => {
              var a;
              return [
                v(f(k), {
                  size: "small",
                  onClick: (s) => p(u),
                  plain: "",
                  type: (a = t.edit) == null ? void 0 : a.buttonType
                }, {
                  default: m(() => [
                    F(S(t.detail.label), 1)
                  ]),
                  _: 2
                }, 1032, ["onClick", "type"])
              ];
            }),
            _: 2
          }, 1032, ["when"]),
          v(f(D), {
            when: (h = t.$props.delete) == null ? void 0 : h.show
          }, {
            default: m(() => [
              v(f(Z), { placement: "top" }, {
                reference: m(() => {
                  var a;
                  return [
                    v(f(k), {
                      size: "small",
                      plain: "",
                      type: (a = t.$props.delete) == null ? void 0 : a.buttonType
                    }, {
                      default: m(() => {
                        var s;
                        return [
                          F(S((s = t.$props.delete) == null ? void 0 : s.label), 1)
                        ];
                      }),
                      _: 1
                    }, 8, ["type"])
                  ];
                }),
                default: m(() => {
                  var a;
                  return [
                    M("div", null, S((a = t.$props.delete) == null ? void 0 : a.title), 1),
                    M("div", pe, [
                      v(f(k), {
                        onClick: (s) => r(u),
                        plain: "",
                        type: "danger",
                        size: "small",
                        loading: f(P).isLoading.value
                      }, {
                        default: m(() => {
                          var s;
                          return [
                            F(S((s = t.$props.delete) == null ? void 0 : s.label), 1)
                          ];
                        }),
                        _: 2
                      }, 1032, ["onClick", "loading"])
                    ])
                  ];
                }),
                _: 2
              }, 1024)
            ]),
            _: 2
          }, 1032, ["when"]),
          I(t.$slots, "default", { row: u })
        ];
      }),
      _: 3
    }, 8, ["label", "fixed", "width"]));
  }
});
export {
  Te as default
};
//# sourceMappingURL=FsTableActionColumn.mjs.map
