import { defineComponent as K, ref as n, onMounted as W, watch as G, createVNode as o, resolveComponent as a, createTextVNode as J, withModifiers as Q, isVNode as X, toValue as k, nextTick as Y } from "vue";
import { ElTree as Z, ElForm as $, ElFormItem as ee, ElTable as te, ElTableColumn as oe, ElTag as le, ElButton as ae, ElInput as re, ElMessage as T } from "element-plus";
import { C as h, D as ne } from "./index-Dne96l6h.js";
import { Loader as se, request as S } from "@/utils";
import { o as ie, T as m, A as d } from "./main-DXvReGBc.js";
import { u as ce } from "./use.pager-c2-RbMcd.js";
import "@klweb/compose-app-engine";
import "@klweb/utils";
import { u as ue } from "./script.code.block-DyZxbH0e.js";
import { e as de } from "./index-ClGUov3E.js";
const {
  IconSearch: D
} = de;
function pe(p) {
  return typeof p == "function" || Object.prototype.toString.call(p) === "[object Object]" && !X(p);
}
const Se = /* @__PURE__ */ K({
  name: "KlDataSourceList",
  components: {
    ElTree: Z,
    ElForm: $,
    ElFormItem: ee,
    ElTable: te,
    ElTableColumn: oe,
    ElTag: le,
    ElButton: ae,
    ElInput: re
  },
  emits: ["close"],
  props: {
    id: {
      type: String,
      default: ""
    }
  },
  setup(p, {
    emit: b
  }) {
    let i;
    const E = new ie(), c = n(), C = n(""), g = n(""), v = n([]), _ = {
      label: "label",
      children: "children"
    }, f = n(""), r = n(), x = n([{
      type: "selection",
      width: 55,
      reserveSelection: !0
    }, {
      name: "服务名称",
      key: "serveName",
      showOverflowTooltip: !0
    }, {
      name: "服务 ID",
      key: "id",
      showOverflowTooltip: !0
    }, {
      name: "服务主机",
      key: "shostPort",
      showOverflowTooltip: !0
    }, {
      name: "接口地址",
      key: "iurl",
      showOverflowTooltip: !0
    }, {
      name: "请求方式",
      key: "irequest",
      showOverflowTooltip: !0
    }, {
      name: "描述",
      key: "describe",
      showOverflowTooltip: !0
    }, {
      name: "操作",
      type: "action",
      fixed: "right",
      width: 120
    }]), w = n([]), s = n([]), u = () => {
      i && i.start(), S.get(API_URL.getDsListByTreeId, {
        params: {
          publishStatus: 1,
          // 已发布
          keyword: f.value,
          mcId: C.value,
          page: k(A),
          pageSize: k(R)
        }
      }).then((t) => {
        var e, l;
        i && i.done(), t.code == 0 ? (L.value = (e = t.data) == null ? void 0 : e.total, w.value = ((l = t.data) == null ? void 0 : l.records) ?? [], r.value.scrollTo(0, 0)) : T.error(t.msg);
      });
    }, {
      currentPage: A,
      pageSize: R,
      total: L
    } = ce({
      el: "#dsPager",
      extMethod: u
    }), I = (t, e) => t ? e.label.includes(t) : !0;
    (() => {
      S.get(API_URL.getDsCategoryTree, {
        params: {
          page: -1,
          pageSize: -1
        }
      }).then((t) => {
        if (t.code == 0) {
          const e = t.data ?? [];
          v.value = e, y(e[0]);
        } else
          T.error(t.msg);
      });
    })();
    const y = (t, e) => {
      const {
        id: l
      } = t;
      C.value = l, f.value = e ?? "", Y(() => {
        u(), c.value && c.value.setCurrentKey(l);
      });
    }, P = () => {
      const t = v.value[0], {
        id: e
      } = s.value[0];
      y(t, e);
    }, N = () => {
      r.value.clearSelection();
    }, O = (t) => {
      r.value && (t.length > 1 && (r.value.clearSelection(), r.value.toggleRowSelection(t.pop(), !0)), s.value = r.value.getSelectionRows());
    }, V = (t) => {
      r.value && (r.value.clearSelection(), r.value.toggleRowSelection(t, !0), s.value = [t]);
    }, F = (t) => t.id, M = ({
      row: t
    }) => {
      var l;
      const e = (l = s.value[0]) == null ? void 0 : l.id;
      return t.id === e ? "current-checked-row" : "";
    }, U = (t) => {
      E.service({
        width: "800",
        targetFlag: "ds-details",
        title: d.VIEW_DS_DETAILS,
        isResize: !0,
        top: "8vh",
        contentModule: ne,
        contentAttrs: {
          id: t
        }
      });
    }, z = () => {
      const {
        id: t,
        shostPort: e,
        iurl: l,
        irequest: j,
        inputParam: q,
        headerParam: B
      } = s.value[0], H = {
        id: t,
        protocol: "http",
        hostPort: e,
        url: l,
        abUrl: !1,
        method: j,
        params: q,
        headers: B,
        contentType: "application/json",
        timeout: 1e4,
        serializeParams: !1,
        dataFilter: {
          enabled: !1,
          value: ue("dataFilter")
        },
        responseType: "json"
      };
      b("close", H);
    };
    return W(() => {
      i = new se({
        type: "overlay",
        option: {
          target: document.querySelector(".dialog-component"),
          text: "",
          customClass: ""
        }
      });
    }), G(g, (t) => {
      c.value && c.value.filter(t);
    }), () => {
      let t;
      return o("div", {
        class: "dialog-component"
      }, [o("section", {
        class: "dialog-component__body"
      }, [o("section", {
        class: h["ds-list-container"]
      }, [o("aside", null, [o(a("el-input"), {
        modelValue: g.value,
        "onUpdate:modelValue": (e) => g.value = e,
        "prefix-icon": D,
        placeholder: m.TREE_NODE_SEARCH_PLACEHOLDER,
        clearable: !0
      }, null), o(a("el-tree"), {
        data: v.value,
        "filter-node-method": I,
        ref: c,
        props: _,
        "node-key": "id",
        "expand-on-click-node": !1,
        "default-expand-all": !0,
        "empty-text": m.DATA_NULL,
        indent: 12,
        onNodeClick: (e) => y(e)
      }, null)]), o("main", null, [o("div", {
        class: "filter-toolbar"
      }, [o("section", null, [J("已绑定："), s.value.length > 0 ? o(a("el-tag"), {
        class: h["custom-el-tag"],
        type: "primary",
        size: "large",
        "disable-transitions": !0,
        closable: !0,
        onClick: P,
        onClose: N
      }, {
        default: () => [s.value[0].serveName]
      }) : "--"]), o("section", null, [o(a("el-input"), {
        modelValue: f.value,
        "onUpdate:modelValue": (e) => f.value = e,
        "prefix-icon": D,
        placeholder: m.SEARCH_PLACEHOLDER,
        clearable: !0,
        style: "width: 250px",
        onClear: u,
        onKeydown: (e) => {
          e.key === "Enter" && u();
        }
      }, null), o(a("el-button"), {
        type: "primary",
        onClick: u
      }, {
        default: () => [d.SEARCH]
      })])]), o(a("el-table"), {
        ref: r,
        height: "100%",
        class: ["el-table__header--bg", h["header-checkbox--disabled"]],
        border: !0,
        stripe: !0,
        "empty-text": m.DATA_NULL,
        data: w.value,
        "row-key": F,
        "row-class-name": M,
        onRowClick: V,
        onSelectionChange: O
      }, pe(t = x.value.map((e) => o(a("el-table-column"), {
        align: "center",
        type: e.type,
        width: e.width,
        label: e.name,
        fixed: e.fixed,
        prop: e.key,
        "reserve-selection": !!e.reserveSelection,
        "show-overflow-tooltip": !!e.showOverflowTooltip
      }, {
        default: ({
          row: l
        }) => {
          if (e.type !== "selection")
            return e.key === "irequest" ? o(a("el-tag"), {
              "disable-transitions": !0,
              type: l[e.key] === "get" ? "success" : "warning"
            }, {
              default: () => [l[e.key]]
            }) : e.type === "action" ? o(a("el-button"), {
              type: "primary",
              link: !0,
              onClick: Q(() => U(l.id), ["stop"])
            }, {
              default: () => [d.VIEW_DETAILS]
            }) : e.key && l[e.key];
        }
      }))) ? t : {
        default: () => [t]
      }), o("section", {
        class: "el-pagination-container",
        id: "dsPager"
      }, null)])])]), o("section", {
        class: "dialog-component__footer"
      }, [o(a("el-button"), {
        onClick: () => b("close")
      }, {
        default: () => [d.CANCEL]
      }), o(a("el-button"), {
        type: "primary",
        disabled: !s.value.length,
        onClick: z
      }, {
        default: () => [d.COMFIRM]
      })])]);
    };
  }
});
export {
  Se as default
};
