import { defineComponent as Q, ref as w, reactive as y, watch as R, openBlock as n, createElementBlock as m, createVNode as W, withCtx as X, createElementVNode as g, normalizeClass as Y, createCommentVNode as b, toDisplayString as O, createBlock as F, nextTick as Z, createApp as ee } from "vue";
import { C as c } from "../../Shared/base-PQGakkrl.js";
import { _ as oe } from "../../Shared/BaseTransition.vue_vue_type_script_setup_true_lang-DLAYzSgX.js";
import H from "../../Element/ClButton.js";
const ce = { class: "alert-body" }, le = {
  key: 0,
  class: "alert-icon"
}, te = {
  key: 1,
  class: "alert-title"
}, ne = {
  key: 2,
  class: "alert-text"
}, se = ["innerHTML"], ie = { key: 1 }, ae = {
  key: 3,
  class: "alert-operate"
}, re = /* @__PURE__ */ Q({
  name: "ClAlert",
  __name: "Alert",
  props: {
    isBackClick: { type: Boolean },
    submitLabel: {},
    submitColor: {},
    cancelLabel: {},
    cancelColor: {}
  },
  setup(h, { expose: C }) {
    const i = h, s = w(null), l = w(null), a = w(null), r = y({
      isLoadBackClick: !0
    }), o = y({
      isBackClick: !1,
      clsIcon: "",
      isShowIcon: !1,
      title: "",
      isShowTitle: !1,
      text: "",
      html: "",
      isShowTextHtml: !1,
      isShowText: !1,
      submitLabel: "",
      submitIcon: "",
      submitColor: "default",
      cancelLabel: "",
      cancelIcon: "",
      cancelColor: "grayLight",
      isShowSubmit: !1,
      isShowSubmitLoad: !1,
      isShowCancel: !1,
      isShowOperate: !1,
      isShow: !1
    }), t = y({
      submit: null,
      cancel: null
    });
    let S = null;
    const _ = {
      icon: {
        info: "clIconFont clIcon-info-circle color-default",
        success: "clIconFont clIcon-check-circle color-green",
        error: "clIconFont clIcon-exclamation-circle color-red",
        warn: "clIconFont clIcon-warn-fill color-yellow",
        doubt: "clIconFont clIcon-question-circle color-cyan"
      }
    }, L = () => document.querySelector("body"), I = () => document.querySelector("body>.panel-alert"), B = () => {
      const e = I();
      return !c.isUndefined(e);
    }, N = () => {
      B() ? (clearTimeout(S), S = null) : L()?.appendChild(s.value);
    }, A = () => {
      Z(() => {
        B() && (S = setTimeout(() => {
          const e = I();
          L()?.removeChild(e);
        }, 2 * 1e3));
      });
    }, M = (e) => {
      const d = c.isBoolean(e.isBackClick) ? e.isBackClick : i.isBackClick ?? !0;
      let u = "";
      c.isEmpty(e.iconType) || (u = c.isExistJsonKey(_.icon, e.iconType) ? _.icon[e.iconType] : ""), c.isEmpty(u) && !c.isEmpty(e.icon) && (u = e.icon);
      const k = !c.isEmpty(u), p = !c.isEmpty(e.title), T = !c.isEmpty(e.html), E = !c.isEmpty(e.text) || T, J = c.isEmpty(e.submitLabel) ? i.submitLabel || "确定" : e.submitLabel, z = c.isEmpty(e.submitColor) ? i.submitColor || "default" : e.submitColor, j = c.isEmpty(e.cancelLabel) ? i.cancelLabel || "取消" : e.cancelLabel, K = c.isEmpty(e.cancelColor) ? i.cancelColor || "grayLight" : e.cancelColor, x = c.isBoolean(e.isSubmit) ? e.isSubmit : !1, U = c.isBoolean(e.isLoad) ? e.isLoad : !1, v = c.isBoolean(e.isCancel) ? e.isCancel : !1, $ = x || v, G = p || E;
      return {
        isBackClick: d,
        clsIcon: u,
        isShowIcon: k,
        title: e.title,
        isShowTitle: p,
        text: e.text,
        html: e.html,
        isShowTextHtml: T,
        isShowText: E,
        submitLabel: J,
        submitIcon: e.submitIcon,
        submitColor: z,
        isShowSubmit: x,
        isShowSubmitLoad: U,
        cancelLabel: j,
        cancelIcon: e.cancelIcon,
        cancelColor: K,
        isShowCancel: v,
        isShowOperate: $,
        isShow: G
      };
    }, P = (e) => {
      const d = M(e);
      if (N(), d.isShow) {
        for (const [u, k] of Object.entries(d))
          o[u] = k;
        t.submit = e.submitCallback, t.cancel = e.cancelCallback, l.value.show();
      } else
        t.submit = null, t.cancel = null, l.value.hide(), o.isShow = !1;
    }, f = () => {
      l.value.hide(), r.isLoadBackClick = !0, o.isShow = !1;
    };
    R(
      () => o.isShow,
      (e) => {
        e || A();
      }
    );
    const V = () => {
      o.isShowSubmitLoad && (r.isLoadBackClick = !1), c.isFunction(t.submit) ? t.submit() : f();
    }, q = () => {
      f(), c.isFunction(t.cancel) && t.cancel();
    }, D = () => {
      f(), c.isFunction(t.cancel) && t.cancel();
    };
    return C({
      open: (e) => {
        P(e);
      },
      hide: () => {
        o.isShowSubmitLoad && a.value?.loadStop(), f();
      },
      reset: () => {
        o.isShowSubmitLoad && a.value?.loadStop();
      }
    }), (e, d) => (n(), m("div", {
      class: "panel-alert",
      ref_key: "refElTopParent",
      ref: s
    }, [
      W(oe, {
        isBackClick: o.isBackClick && r.isLoadBackClick,
        classTransitionEnter: "animated zoomIn",
        width: "500px",
        onOnClickBack: D,
        ref_key: "refElTransition",
        ref: l
      }, {
        default: X(() => [
          g("div", ce, [
            o.isShowIcon ? (n(), m("div", le, [
              g("i", {
                class: Y(o.clsIcon)
              }, null, 2)
            ])) : b("", !0),
            o.isShowTitle ? (n(), m("div", te, O(o.title), 1)) : b("", !0),
            o.isShowText ? (n(), m("div", ne, [
              o.isShowTextHtml ? (n(), m("div", {
                key: 0,
                innerHTML: o.html
              }, null, 8, se)) : (n(), m("div", ie, O(o.text), 1))
            ])) : b("", !0),
            o.isShowOperate ? (n(), m("div", ae, [
              o.isShowSubmit ? (n(), F(H, {
                key: 0,
                ref_key: "refElBtnSubmit",
                ref: a,
                className: "alert-submit",
                isShowLoad: o.isShowSubmitLoad,
                isShowBackDrop: !0,
                label: o.submitLabel,
                icon: o.submitIcon,
                color: o.submitColor,
                onOnClick: V
              }, null, 8, ["isShowLoad", "label", "icon", "color"])) : b("", !0),
              o.isShowCancel ? (n(), F(H, {
                key: 1,
                className: "alert-cancel",
                label: o.cancelLabel,
                icon: o.cancelIcon,
                color: o.cancelColor,
                onOnClick: q
              }, null, 8, ["label", "icon", "color"])) : b("", !0)
            ])) : b("", !0)
          ])
        ]),
        _: 1
      }, 8, ["isBackClick"])
    ], 512));
  }
}), Se = (h = {}) => {
  const C = ee(re, h), i = document.createElement("div"), s = C.mount(i);
  return {
    alert: (l, a = {}) => {
      const r = c.getJsonMerge(
        {
          isSubmit: !0
        },
        a,
        {
          title: l,
          isCancel: !1,
          cancelCallback: null
        }
      );
      s.open(r);
    },
    confirm: (l, a) => {
      const r = c.getJsonMerge(
        {
          isSubmit: !0,
          isCancel: !0
        },
        a,
        {
          title: l
        }
      );
      s.open(r);
    },
    custom: (l) => {
      s.open(l);
    },
    close: () => {
      s.hide();
    },
    reset: () => {
      s.reset();
    }
  };
};
export {
  Se as default
};
//# sourceMappingURL=Alert.js.map
