import { defineComponent as d, ref as s, computed as m, onBeforeUpdate as g, onErrorCaptured as k, createElementBlock as v, openBlock as c, Fragment as _, renderSlot as y, createBlock as B, createCommentVNode as E, unref as x } from "vue";
import A from "../PlErrorAlert/PlErrorAlert.vue.js";
import { isErrorLike as C, tryDo as S } from "@milaboratories/helpers";
const D = /* @__PURE__ */ d({
  __name: "PlErrorBoundary",
  setup(h, { expose: f }) {
    const i = (e) => {
      if (e != null)
        return C(e) ? e.stack == null || e.stack.length === 0 ? e.message : e.stack.includes(e.message) ? e.stack : e.message + `
` + e.stack : S(() => JSON.stringify(e, null, 4), () => e.toString());
    }, t = s(null), o = m(() => {
      var e;
      return (e = t.value) == null ? void 0 : e.error;
    }), p = m(() => i(o.value));
    function a() {
      t.value = null;
    }
    const n = s(null);
    return g(() => {
      t.value !== null && n.value && a();
    }), k((e, r) => {
      var l, u;
      return t.value = {
        title: ((u = (l = r == null ? void 0 : r.$) == null ? void 0 : l.type) == null ? void 0 : u.name) ?? void 0,
        error: e
      }, !1;
    }), f({ error: o, reset: a }), (e, r) => {
      var l;
      return c(), v(_, null, [
        y(e.$slots, "default"),
        o.value ? (c(), B(x(A), {
          key: 0,
          ref_key: "errorAlert",
          ref: n,
          message: p.value,
          title: (l = t.value) == null ? void 0 : l.title
        }, null, 8, ["message", "title"])) : E("", !0)
      ], 64);
    };
  }
});
export {
  D as default
};
//# sourceMappingURL=PlErrorBoundary.vue.js.map
