import { defineAsyncComponent as _, defineComponent as y, ref as g, onActivated as C, watch as T, createVNode as o, resolveComponent as l, withModifiers as h, isVNode as V } from "vue";
import { ElCollapse as N, ElCollapseItem as I, ElEmpty as x, ElMessageBox as A } from "element-plus";
import { useResolveVnode as c, useGetCompNode as b, useGetCompRefProps as S } from "@klweb/compose-app-engine";
import { k, ad as M, l as R, ab as j, A as d, ae as w, T as p } from "./main-Blxobku2.js";
import { e as L } from "./index-BbdVezoQ.js";
const O = _({
  loader: () => import("./AddEvent-B_IF8mXG.js"),
  loadingComponent: k
}), i = {
  "event-setter-container": "_event-setter-container_r1fen_1",
  "event-setter__head": "_event-setter__head_r1fen_7",
  "event-setter__main": "_event-setter__main_r1fen_15"
}, {
  IconRemoveCircle: P
} = L;
function U(s) {
  return typeof s == "function" || Object.prototype.toString.call(s) === "[object Object]" && !V(s);
}
const B = /* @__PURE__ */ y({
  name: "KlEventSetter",
  components: {
    ElCollapse: N,
    ElCollapseItem: I,
    ElEmpty: x,
    CommonCodeEditor: M
  },
  props: {
    compId: {
      type: String,
      default: ""
    }
  },
  setup(s) {
    const n = g([]), r = async () => {
      const e = b(s.compId);
      if (!e) return;
      const t = e.events ? null : await S(s.compId), a = (t == null ? void 0 : t.events) || [];
      e.events = e.events ?? a, n.value = e.events;
    };
    r();
    const m = (e) => {
      n.value.push(e);
    }, u = (e) => {
      A.confirm(p.DELETE_EVENT_TEXT, "提示", {
        type: "warning",
        draggable: !0,
        autofocus: !1
      }).then(() => {
        n.value.some((t, a) => {
          if (t.type === e)
            return n.value.splice(a, 1), !0;
        });
      }).catch(() => {
        console.log("取消");
      });
    }, v = () => n.value.map((t) => t.type), f = () => [...Array(n.value.length).keys()];
    return C(() => r()), T([R, j], () => {
      r();
    }), () => {
      let e;
      return o("div", {
        class: i["event-setter-container"]
      }, [o("div", {
        class: i["event-setter__head"]
      }, [c(O, {
        disabled: v(),
        onHandleAddEvent: m
      })]), o("div", {
        class: i["event-setter__main"]
      }, [n.value.length ? o(l("el-collapse"), {
        class: "kl-editor-setter__collapse",
        modelValue: f()
      }, U(e = n.value.map((t, a) => o(l("el-collapse-item"), {
        name: a
      }, {
        default: () => [o(l("common-code-editor"), {
          title: d.EDIT_EVENT_SCRIPT,
          height: "110px",
          modelValue: t.value,
          "onUpdate:modelValue": (E) => t.value = E,
          language: "javascript",
          options: {
            noSemanticValidation: !1,
            lineNumbers: "off",
            folding: !1
          }
        }, null)],
        title: () => o("span", null, [t.type, c(w, {
          content: d.REMOVE_EVENT,
          icon: P,
          iconStyle: {
            color: "var(--editor-color-error)",
            opacity: "0.9",
            transform: "translateY(2px)"
          },
          onClick: h(() => {
            u(t.type);
          }, ["stop"])
        })])
      }))) ? e : {
        default: () => [e]
      }) : o(l("el-empty"), {
        "image-size": 90,
        description: p.COMP_EVENT_NULL,
        style: "--el-empty-padding: 100px 0; --el-font-size-base: 12px"
      }, null)])]);
    };
  }
});
export {
  B as default
};
