import { defineComponent as h, ref as a, onMounted as E, onUnmounted as S, createVNode as t, Fragment as I, resolveComponent as i, isVNode as U, nextTick as _ } from "vue";
import { ElSelect as x, ElOption as A, ElInput as O, ElEmpty as k, ElMessage as f } from "element-plus";
import "@klweb/compose-app-engine";
import "@klweb/utils";
import { af as y, T as g } from "./main-DXvReGBc.js";
import { request as C } from "@/utils";
import { e as R } from "./index-ClGUov3E.js";
import { C as b } from "./index-_2MwRCvv.js";
const {
  IconSearch: V
} = R;
function B(l) {
  return typeof l == "function" || Object.prototype.toString.call(l) === "[object Object]" && !U(l);
}
const K = /* @__PURE__ */ h({
  name: "KlBusinessCompList",
  components: {
    ElSelect: x,
    ElOption: A,
    ElInput: O,
    ElEmpty: k
  },
  setup() {
    let l;
    const n = a("1000"), m = a([{
      label: "全部",
      value: "1000"
    }]), L = () => {
      C.get(API_URL.getCompCategoryTree, {
        params: {
          page: -1,
          pageSize: -1
        }
      }).then((e) => {
        if (e.code == 0) {
          const v = (e.data[0] ?? []).children.map((p) => ({
            label: p.label,
            value: p.id
          }));
          m.value = [...m.value, ...v], s();
        } else
          f.error(e.msg);
      });
    }, u = a(""), d = a(), r = a([]), s = () => {
      C.get(API_URL.getCompListByTreeId, {
        params: {
          publishStatus: 1,
          // 已发布
          name: u.value,
          mcId: n.value,
          page: 1,
          pageSize: 1e3
        }
      }).then((e) => {
        var o;
        if (e.code == 0) {
          const p = (((o = e.data) == null ? void 0 : o.records) ?? []).map((c) => ({
            component: c.key,
            version: "1.0.0",
            type: "component",
            name: c.modelName,
            id: c.id,
            imgUrl: c.imageUrl
          }));
          r.value = p, _(() => {
            l = y(d.value);
          });
        } else
          f.error(e.msg);
      });
    }, T = (e) => {
      n.value = e, s();
    };
    return L(), E(() => {
      l = r.value.length ? y(d.value) : null;
    }), S(() => {
      l && l.destroy();
    }), () => t(I, null, [t("section", {
      class: b["filter-text"]
    }, [t(i("el-input"), {
      modelValue: u.value,
      "onUpdate:modelValue": (e) => u.value = e,
      "prefix-icon": V,
      placeholder: g.COMP_SEARCH_PLACEHOLDER,
      onKeydown: (e) => {
        e.key === "Enter" && s();
      },
      onClear: s,
      clearable: !0
    }, {
      prepend: () => {
        let e;
        return t(i("el-select"), {
          modelValue: n.value,
          "onUpdate:modelValue": (o) => n.value = o,
          style: "width: 90px",
          onChange: T
        }, B(e = m.value.map((o) => t(i("el-option"), {
          label: o.label,
          value: o.value,
          key: o.value
        }, null))) ? e : {
          default: () => [e]
        });
      }
    })]), r.value.length ? t("ul", {
      class: b["comp-grid-container"],
      ref: d
    }, [r.value.map((e) => t("li", {
      class: "kl-drag-item",
      title: g.DRAG_LAYOUT_TIP_TEXT,
      "data-node": JSON.stringify(e),
      key: e.name
    }, [t("img", {
      src: e.imgUrl,
      style: "object-fit: cover"
    }, null), t("span", {
      class: "label"
    }, [e.name])]))]) : t(i("el-empty"), {
      "image-size": 90,
      description: g.DATA_NULL,
      style: "--el-empty-padding: 100px 0; --el-font-size-base: 12px"
    }, null)]);
  }
});
export {
  K as default
};
