import { defineComponent as N, ref as a, createVNode as l, Fragment as P, resolveComponent as t, isVNode as U, toValue as y } from "vue";
import { ElSelect as z, ElOption as R, ElButton as V, ElInput as _, ElEmpty as O, ElIcon as B, ElMessage as h } from "element-plus";
import { T as b, A as j } from "./main-Blxobku2.js";
import { u as M } from "./use.pager-DA_wrMsj.js";
import { request as E } from "@/utils";
import { e as H } from "./index-BbdVezoQ.js";
import { C as S } from "./index-6txV8xZU.js";
const {
  IconSearch: w,
  IconSelected: D
} = H;
function K(n) {
  return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !U(n);
}
const Y = /* @__PURE__ */ N({
  name: "KlBusinessCompRep",
  components: {
    ElSelect: z,
    ElOption: R,
    ElButton: V,
    ElInput: _,
    ElEmpty: O,
    ElIcon: B,
    IconSelected: D
  },
  emits: ["handleNodeClick"],
  setup(n, {
    emit: C
  }) {
    const r = a("1000"), i = a([{
      label: "全部",
      value: "1000"
    }]), x = () => {
      E.get(API_URL.getCompCategoryTree, {
        params: {
          page: -1,
          pageSize: -1
        }
      }).then((e) => {
        if (e.code == 0) {
          const p = (e.data[0] ?? []).children.map((v) => ({
            label: v.label,
            value: v.id
          }));
          i.value = [...i.value, ...p], s();
        } else
          h.error(e.msg);
      });
    }, m = a(""), d = a([]), c = a(""), s = () => {
      E.get(API_URL.getCompListByTreeId, {
        params: {
          publishStatus: 1,
          // 已发布
          name: m.value,
          mcId: r.value,
          page: y(f),
          pageSize: y(I)
        }
      }).then((e) => {
        var o, p;
        if (e.code == 0) {
          k.value = (o = e.data) == null ? void 0 : o.total;
          const T = (((p = e.data) == null ? void 0 : p.records) ?? []).map((u) => ({
            component: u.key,
            version: "1.0.0",
            type: "component",
            name: u.modelName,
            id: u.id,
            imgUrl: u.imageUrl
          }));
          d.value = T;
        } else
          h.error(e.msg);
      });
    }, {
      currentPage: f,
      pageSize: I,
      total: k
    } = M({
      el: "#compPager",
      pageSize: 10,
      pageSizes: [10, 20, 50, 100],
      extMethod: s
    }), A = (e) => {
      r.value = e, s();
    }, g = () => {
      f.value = 1, s();
    }, L = (e) => {
      if (c.value === e.component) {
        c.value = "", C("handleNodeClick", null);
        return;
      }
      c.value = e.component, C("handleNodeClick", e);
    };
    return x(), () => l(P, null, [l("section", {
      class: S["filter-text"]
    }, [l(t("el-input"), {
      modelValue: m.value,
      "onUpdate:modelValue": (e) => m.value = e,
      "prefix-icon": w,
      placeholder: b.COMP_SEARCH_PLACEHOLDER,
      onKeydown: (e) => {
        e.key === "Enter" && g();
      },
      onClear: g,
      clearable: !0
    }, {
      prepend: () => {
        let e;
        return l(t("el-select"), {
          modelValue: r.value,
          "onUpdate:modelValue": (o) => r.value = o,
          style: "width: 150px",
          onChange: A
        }, K(e = i.value.map((o) => l(t("el-option"), {
          label: o.label,
          value: o.value,
          key: o.value
        }, null))) ? e : {
          default: () => [e]
        });
      }
    }), l(t("el-button"), {
      type: "primary",
      style: "margin-left: 10px",
      onClick: g
    }, {
      default: () => [j.SEARCH]
    })]), d.value.length ? l("ul", {
      class: S["comp-grid-container"]
    }, [d.value.map((e) => l("li", {
      class: c.value === e.component && "active",
      key: e.name,
      onClick: () => L(e)
    }, [l("img", {
      src: e.imgUrl,
      style: "object-fit: cover"
    }, null), l("span", {
      class: "label"
    }, [e.name]), l(t("el-icon"), null, {
      default: () => [l(t("icon-selected"), null, null)]
    })]))]) : l(t("el-empty"), {
      "image-size": 90,
      description: b.DATA_NULL,
      style: "--el-empty-padding: 35.5px 0; --el-font-size-base: 12px"
    }, null), l("section", {
      class: "el-pagination-container",
      id: "compPager",
      style: "margin-bottom: 10px"
    }, null)]);
  }
});
export {
  Y as default
};
