import { defineComponent as C, getCurrentInstance as E, ref as p, onActivated as I, watch as y, createVNode as l, resolveComponent as a, isVNode as V, defineAsyncComponent as b } from "vue";
import { ElCollapse as h, ElCollapseItem as F, ElForm as S, ElFormItem as _, ElButton as P, ElInput as w, ElSwitch as g, ElTooltip as k, ElMessage as x } from "element-plus";
import { copyText as A } from "@klweb/utils";
import { useResolveVnode as N, useGetCompNode as U, useGetCompRefProps as R, useResolveAsyncCompLoader as j } from "@klweb/compose-app-engine";
import { k as B, a8 as D, A as O } from "./main-DXvReGBc.js";
import { e as T } from "./index-ClGUov3E.js";
const G = {
  "copy-comp-id-icon": "_copy-comp-id-icon_1ptyb_1"
}, {
  IconCopy: K
} = T;
function L(n) {
  return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !V(n);
}
const Q = /* @__PURE__ */ C({
  name: "KlPropSetter",
  components: {
    ElCollapse: h,
    ElCollapseItem: F,
    ElForm: S,
    ElFormItem: _,
    ElButton: P,
    ElInput: w,
    ElSwitch: g,
    ElTooltip: k
  },
  props: {
    compId: {
      type: String,
      default: ""
    }
  },
  setup(n) {
    const {
      appContext: d
    } = E(), {
      app: s
    } = d, e = p(null), c = p(!1), u = p(""), m = p({}), r = async () => {
      if (e.value = U(n.compId), !e.value) return;
      const t = e.value.properties ? null : await R(n.compId), o = (t == null ? void 0 : t.properties) || {};
      e.value.properties = e.value.properties ?? o, m.value = e.value.properties, f();
    }, f = () => {
      var o;
      u.value = ((o = e.value) == null ? void 0 : o.component) + "PropSetter";
      const t = j(u.value);
      c.value = !!t, t && !s.component(u.value) && s.component(u.value, b({
        loader: t
      }));
    };
    r();
    const i = p(["1", "2"]), v = (t) => {
      A(t, () => {
        x.success("已复制到剪切板");
      });
    };
    return I(() => r()), y([B, D], () => {
      r();
    }), () => {
      let t;
      return e.value && l(a("el-collapse"), {
        class: "kl-editor-setter__collapse",
        modelValue: i.value,
        "onUpdate:modelValue": (o) => i.value = o
      }, {
        default: () => [l(a("el-collapse-item"), {
          title: "基础信息",
          name: "1"
        }, {
          default: () => [l(a("el-form"), {
            class: "kl-editor-setter__form",
            model: e.value,
            "label-width": "80px",
            "label-position": "left"
          }, {
            default: () => [l(a("el-form-item"), {
              label: "组件 ID"
            }, {
              default: () => [l(a("el-input"), {
                readonly: !0,
                class: "width--full",
                modelValue: e.value.compId,
                "onUpdate:modelValue": (o) => e.value.compId = o
              }, {
                append: () => l(a("el-tooltip"), {
                  effect: "dark",
                  "hide-after": 0,
                  placement: "top",
                  content: O.COPY
                }, {
                  default: () => [l(a("el-button"), {
                    class: G["copy-comp-id-icon"],
                    icon: K,
                    onClick: () => {
                      var o;
                      return v(((o = e.value) == null ? void 0 : o.compId) ?? "");
                    }
                  }, null)]
                })
              })]
            }), l(a("el-form-item"), {
              label: "组件名称"
            }, {
              default: () => [l(a("el-input"), {
                class: "width--full",
                modelValue: e.value.name,
                "onUpdate:modelValue": (o) => e.value.name = o
              }, null)]
            }), l(a("el-form-item"), {
              label: "是否渲染",
              class: "content-position--right"
            }, {
              default: () => [l(a("el-switch"), {
                modelValue: e.value.isRender,
                "onUpdate:modelValue": (o) => e.value.isRender = o
              }, null)]
            })]
          })]
        }), c.value && l(a("el-collapse-item"), {
          title: "属性设置",
          name: "2"
        }, L(t = N(u.value, {
          compId: n.compId,
          properties: m.value
        })) ? t : {
          default: () => [t]
        })]
      });
    };
  }
});
export {
  Q as default
};
