import { defineComponent as le, inject as ce, ref as w, computed as K, watch as P, onMounted as re, openBlock as D, createElementBlock as I, createVNode as R, createCommentVNode as J, unref as H, createBlock as ne, normalizeStyle as ue, withCtx as Y, createElementVNode as C, normalizeClass as de, toDisplayString as Z, nextTick as M, reactive as ge, provide as me } from "vue";
import { C as s } from "./base-PQGakkrl.js";
import { _ as ve } from "./Index.vue_vue_type_script_setup_true_lang-CejRfZxl.js";
import { _ as ye } from "./List.vue_vue_type_script_setup_true_lang-DzmylhZ6.js";
import { RecycleScroller as we } from "vue-virtual-scroller";
/* empty css                              */
import { C as X } from "./index-BnerInzC.js";
import { _ as De } from "./Index.vue_vue_type_script_setup_true_lang-B_jfFc6B.js";
import { _ as ie } from "./One.vue_vue_type_script_setup_true_lang-BuNRS-9u.js";
import { u as fe } from "./language-DxTlvFs2.js";
import { _ as xe } from "./Index.vue_vue_type_script_setup_true_lang-C4rRquU-.js";
const Se = { class: "select-inDropdown-container" }, Ce = {
  key: 0,
  class: "select-inDropdown-search"
}, Te = {
  key: 1,
  class: "select-inDropdown-checkboxAll"
}, Ie = ["onClick"], ke = { class: "select-inDropdown-item-inner" }, be = {
  key: 0,
  class: "select-inDropdown-checkbox"
}, _e = ["innerHTML"], Ee = {
  key: 3,
  class: "select-inDropdown-body"
}, Oe = { class: "select-inDropdown-empty" }, Le = /* @__PURE__ */ le({
  name: "ClSelectInDropdown",
  __name: "Dropdown",
  props: {
    isSearch: {
      type: Boolean,
      default: !1
    },
    searchPlaceholder: String,
    searchKey: {
      type: Array,
      default: () => ["name"]
    },
    searchKeyType: {
      type: String,
      default: "||"
    },
    isMultiple: {
      type: Boolean,
      default: !1
    },
    isCheckBoxAll: {
      type: Boolean,
      default: !1
    },
    showDropDownTextFormat: String,
    originalData: {
      type: Array,
      default: () => []
    },
    keyIndex: String,
    isOpen: {
      type: Boolean,
      default: !1
    },
    selectId: {
      type: Array,
      default: () => []
    },
    serverCallback: Function
  },
  emits: ["onChange", "onInitComplete"],
  setup(a, { expose: j, emit: k }) {
    const t = a, g = k, { optPageLanguage: y, getPageLanguage: b } = fe();
    b("common");
    const x = ce("$SelectTop"), S = w(null), c = w(null);
    let p = !0;
    const d = { isScrollLoadIng: !1 }, m = `select-inList-${t.keyIndex}`, r = w(""), u = w([]), _ = w([]);
    let U = {};
    const ee = K(() => {
      let o = !1;
      return _.value.length > 0 && t.selectId.length >= _.value.length && (o = s.isContainArr(t.selectId, _.value)), o;
    }), te = (o) => s.isEmpty(t.showDropDownTextFormat) ? o.name : s.convertStringFormat(t.showDropDownTextFormat, o), E = (o) => {
      const n = U[o] || {};
      return s.isBoolean(n._isTypeRadio) ? n._isTypeRadio : !1;
    }, A = () => {
      const o = [];
      U = s.getJsonByList(u.value), u.value.forEach((n) => {
        if (s.isObject(n)) {
          const l = n.id.toString();
          E(l) || (n.isDisabled ? s.isExistValue(t.selectId, l) && o.push(l) : o.push(l));
        } else
          o.push(n);
      }), _.value = o;
    }, W = () => {
      p && (p = !1, u.value = s.getListClone(t.originalData), A(), oe(), M(() => {
        S.value && S.value.setValue("");
      }));
    }, oe = () => {
      M(() => {
        if (c.value && t.selectId.length > 0) {
          const o = u.value.findIndex(
            (n) => s.isExistValue(t.selectId, n.id.toString())
          );
          o > -1 && c.value.scrollToItem(o);
        }
      });
    }, N = (o) => {
      const n = [];
      return t.isMultiple ? E(o) ? s.isExistValue(t.selectId, o) || n.push(o) : (t.selectId.forEach((l) => {
        l !== o && !E(l) && n.push(l);
      }), s.isExistValue(t.selectId, o) || n.push(o)) : n.push(o), n;
    }, O = (o) => {
      const n = u.value;
      let l = -1;
      if (n.length > 0) {
        const h = r.value;
        h.length > 0 ? (n.forEach((T, f) => {
          T.id.toString() === h && (l = f);
        }), l += o, l < 0 ? l = 0 : l >= n.length && (l = n.length - 1)) : l = 0;
      }
      r.value = n[l].id.toString(), c.value && c.value.scrollToItem(l);
    }, L = (o) => {
      let n = o.keyCode;
      if (!s.isUndefined(n))
        switch (n = n.toString(), n) {
          case "13":
            o.preventDefault(), o.stopPropagation();
            break;
          case "38":
            o.preventDefault(), o.stopPropagation(), O(-1);
            break;
          case "40":
            o.preventDefault(), o.stopPropagation(), O(1);
            break;
        }
    }, B = (o) => {
      let n = o.keyCode;
      if (!s.isUndefined(n))
        switch (n = n.toString(), n) {
          case "27":
            break;
          case "13":
            const l = r.value, h = N(l);
            g("onChange", h);
            break;
        }
    }, $ = async () => {
      if (!d.isScrollLoadIng) {
        if (d.isScrollLoadIng = !0, t.serverCallback) {
          const o = { offset: u.value.length };
          if (t.isSearch && S.value) {
            const l = S.value.getValue();
            s.isEmpty(l) || (o.search = l);
          }
          const n = await t.serverCallback(o);
          u.value.push(...n), A(), x.convertListToJson(n);
        }
        d.isScrollLoadIng = !1;
      }
    }, V = () => {
      W(), g("onInitComplete");
    };
    P(
      () => t.isOpen,
      (o) => {
        o && W();
      }
    ), P(
      () => t.originalData,
      (o) => {
        p = !0, u.value = s.getListClone(o), A();
      }
    ), re(() => {
      V();
    });
    const q = async (o) => {
      let n = [];
      if (t.serverCallback)
        n = await t.serverCallback({ search: o, offset: 0 }), x.convertListToJson(n);
      else if (s.isEmpty(o))
        n = t.originalData;
      else {
        const l = o.toLowerCase(), h = t.searchKey.length, T = t.searchKey;
        t.originalData.forEach((f) => {
          const F = [];
          for (let Q = 0; Q < h; Q++)
            f[T[Q]].toLowerCase().indexOf(l) > -1 && F.push(!0);
          if (F.length > 0)
            switch (t.searchKeyType) {
              case "||":
                n.push(f);
                break;
              case "&&":
                F.length === h && n.push(f);
                break;
            }
        });
      }
      u.value = n, A(), r.value = "", x.calculationDropdownPosition();
    }, z = (o) => {
      if (t.isMultiple) {
        const n = [], l = [];
        _.value.forEach((f) => {
          o.value ? s.isExistValue(t.selectId, f) || n.push(f) : s.isExistValue(t.selectId, f) && l.push(f);
        });
        const h = s.getArrClone(t.selectId);
        l.length > 0 && l.forEach((f) => {
          h.splice(h.indexOf(f), 1);
        }), n.length > 0 && h.push(...n);
        const T = [];
        h.forEach((f) => {
          E(f) || T.push(f);
        }), g("onChange", T);
      }
    }, G = (o) => {
      if (!o.isDisabled) {
        const n = o.id.toString(), l = N(n);
        g("onChange", l);
      }
    };
    return j({
      initOpenShow: (o) => {
        o ? (X.onListener(window, "keydown", L), X.onListener(window, "keyup", B)) : (X.offListener(window, "keydown", L), X.offListener(window, "keyup", B));
      }
    }), (o, n) => (D(), I("div", Se, [
      a.isSearch ? (D(), I("div", Ce, [
        R(De, {
          ref_key: "refElSearch",
          ref: S,
          onOnChange: q
        }, null, 512)
      ])) : J("", !0),
      a.isMultiple && a.isCheckBoxAll && u.value.length > 0 ? (D(), I("div", Te, [
        R(ie, {
          forId: `${m}-cb-all`,
          label: H(y).checkboxAll,
          value: ee.value,
          onOnChange: z
        }, null, 8, ["forId", "label", "value"])
      ])) : J("", !0),
      u.value.length > 0 ? (D(), ne(H(we), {
        key: 2,
        class: "select-inDropdown-body select-inDropdown-scroller",
        style: ue({ height: Math.min(u.value.length * 35, 210) + "px" }),
        items: u.value,
        "item-size": 35,
        "key-field": "id",
        ref_key: "refElScroller",
        ref: c,
        onScrollEnd: $
      }, {
        default: Y(({ item: l }) => [
          C("div", {
            class: de({
              "option-selected": a.selectId.indexOf(l.id.toString()) > -1,
              "option-disabled": l.isDisabled,
              "option-hoverKeydown": r.value === l.id.toString()
            }),
            style: { height: "35px" },
            onClick: (h) => G(l)
          }, [
            C("div", ke, [
              a.isMultiple ? (D(), I("div", be, [
                R(ie, {
                  name: `${m}-cb`,
                  forId: `${m}-cb-${l.id}`,
                  value: a.selectId.indexOf(l.id.toString()) > -1,
                  isDisabled: l.isDisabled
                }, null, 8, ["name", "forId", "value", "isDisabled"])
              ])) : J("", !0),
              C("div", {
                class: "select-inDropdown-title",
                innerHTML: te(l)
              }, null, 8, _e)
            ])
          ], 10, Ie)
        ]),
        _: 1
      }, 8, ["style", "items"])) : (D(), I("div", Ee, [
        C("div", Oe, Z(H(y).noResultsText), 1)
      ]))
    ]));
  }
}), Ae = { class: "select-inTag-container" }, Be = { class: "select-inTag-title" }, $e = { class: "select-inTag-operate" }, Ve = ["title"], Fe = { class: "select-inTag-body" }, Ke = /* @__PURE__ */ le({
  name: "ClSelectInTags",
  __name: "Tags",
  props: {
    showTextFormat: String,
    selectId: {
      type: Array,
      default: () => []
    }
  },
  emits: ["onRemove"],
  setup(a, { emit: j }) {
    const k = a, t = j, { optPageLanguage: g, getPageLanguage: y } = fe();
    y("common");
    const b = ce("$SelectTop"), x = K(() => b.getSelectData(k.selectId)), S = () => {
      const p = [];
      x.value.forEach((d) => {
        d.isDisabled && p.push(d.id.toString());
      }), t("onRemove", p);
    }, c = (p) => {
      const d = s.getArrClone(k.selectId);
      d.splice(k.selectId.indexOf(p), 1), t("onRemove", d);
    };
    return (p, d) => (D(), I("div", Ae, [
      C("div", Be, [
        C("span", null, Z(H(g).selected) + " " + Z(a.selectId.length) + " " + Z(H(g).count), 1),
        C("span", $e, [
          C("i", {
            class: "clIconFont clIcon-remove select-inTag-deleteAll",
            title: H(g).deleteAll,
            onClick: S
          }, null, 8, Ve)
        ])
      ]),
      C("div", Fe, [
        R(xe, {
          showTextFormat: a.showTextFormat,
          list: x.value,
          onOnRemove: c
        }, null, 8, ["showTextFormat", "list"])
      ])
    ]));
  }
}), Pe = {
  key: 0,
  class: "select-inText-num"
}, Ye = /* @__PURE__ */ le({
  name: "ClSelect",
  __name: "Index",
  props: {
    value: [String, Number],
    list: {
      type: Array,
      default: () => []
    },
    className: String,
    placeholder: String,
    classDropDown: String,
    theme: {
      type: String,
      default: "default"
      // default | noBorder
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    multiple: {
      type: Boolean,
      default: !1
    },
    isClear: {
      type: Boolean,
      default: !1
    },
    isSearch: {
      type: Boolean,
      default: !1
    },
    isCheckBoxAll: {
      type: Boolean,
      default: !0
    },
    isShowTag: {
      type: Boolean,
      default: !0
    },
    arrowDirection: {
      type: String,
      default: "right"
      // left|right
    },
    searchPlaceholder: String,
    searchKey: {
      type: Array,
      default: () => ["name"]
    },
    searchKeyType: {
      type: String,
      default: "||"
    },
    showTextFormat: String,
    showDropDownTextFormat: String,
    multipleRealTimeChange: {
      type: Boolean,
      default: !1
    },
    onOpenBefore: Function,
    serverCallback: Function
  },
  emits: ["update:value", "onChange", "onInit", "onOpen"],
  setup(a, { expose: j, emit: k }) {
    const t = a, g = k, y = w(null), b = w(null), x = w(null), S = `ddl-${s.getRandom(8)}`, c = ge({
      isOpen: !1,
      isInitFirstOpen: !1,
      dropDownPos: "down",
      dropDownTop: "",
      tagHeight: "",
      tagLeft: "",
      tagDirection: "right"
    });
    let p = [], d = {};
    const m = w(!1), r = w([]), u = w([]), _ = K(() => {
      let e = t.arrowDirection;
      return t.theme === "noBorder" && (e = e.length === 0 ? "left" : e), e;
    }), U = K(() => {
      const e = ["panel-select", "box-width"];
      t.theme === "noBorder" && e.push("select-theme-noBorder");
      let i = e.join(" ");
      return s.isEmpty(t.className) || (i += " " + t.className), i;
    }), ee = K(() => {
      const e = ["select-inDropdown"];
      return c.isOpen && t.multiple && t.isShowTag && (e.push("select-inTag-ext"), e.push(`select-inTag-${c.tagDirection}`)), t.classDropDown && !s.isEmpty(t.classDropDown) && e.push(t.classDropDown), e.join(" ");
    }), te = K(() => {
      const e = {
        "select-inTag": !0,
        "select-inTag-open": c.isOpen
      };
      return e[`select-inTag-${c.dropDownPos}`] = !0, e[`select-inTag-${c.tagDirection}`] = !0, e;
    }), E = (e) => {
      g("update:value", e);
    }, A = (e, i) => {
      E(e), g("onChange", e, i);
    }, W = () => {
      M(() => {
        g("onInit");
      });
    }, oe = (e) => {
      M(() => {
        g("onOpen", e);
      });
    }, N = () => {
      const e = [];
      return r.value.forEach((i) => {
        s.isExistJsonKey(d, i) && e.push(i);
      }), e;
    }, O = (e) => {
      const i = s.isEmpty(e) ? {} : s.getJsonByList(e);
      d = s.getJsonMerge(d, i);
    }, L = () => {
      if (m.value && !s.isEmpty(r.value)) {
        const e = N();
        s.isEqualArr(r.value, e) || (r.value = e, E(e.join(",")));
      }
    }, B = (e) => {
      const i = s.isEmpty(e) ? [] : e.toString().split(",");
      let v = s.isEqualArr(r.value, i);
      v && (v = e === r.value.join(",")), v || (p = i, r.value = i);
    }, $ = (e) => s.isExistJsonKey(d, e) ? s.getJsonClone(d[e]) : {}, V = () => {
      const e = [];
      return r.value.forEach((i) => {
        const v = $(i);
        s.isEmpty(v) || e.push(v);
      }), e;
    }, q = () => {
      p = r.value;
      const e = r.value.join(","), i = t.multiple ? V() : $(e);
      A(e, i);
    }, z = () => {
      c.isOpen || !s.isEqualArr(r.value, p) && q();
    }, G = () => {
      m.value || (m.value = !0, O(t.list), B(t.value), L(), W());
    }, se = () => {
      !m.value && t.list.length > 0 && G();
    };
    P(m, (e) => {
      e && W();
    }), P(
      () => t.list,
      (e) => {
        m.value || (m.value = !0, e.length === 0 && L());
      }
    ), P(
      [() => t.value, () => t.list],
      ([e, i]) => {
        const v = i;
        !m.value && v.length > 0 && (m.value = !0), O(v), s.isUndefined(e) || B(e), L();
      }
    ), P(
      [r, () => t.list],
      ([e, i]) => {
        i.length > 0 && s.isEmpty(d) && O(i);
        const pe = V().map((ae) => s.isEmpty(t.showTextFormat) ? ae.name : s.convertStringFormat(t.showTextFormat, ae));
        u.value = pe;
      }
    ), re(() => {
      M(() => {
        se();
      });
    }), me("$SelectTop", {
      getSelectData: V,
      getSelectValueInfo: $,
      calculationDropdownPosition: () => {
        y.value.calculationPosition();
      },
      convertListToJson: O
    });
    const o = (e) => {
      t.disabled || (c.isOpen = e, e ? p = r.value : z(), M(() => {
        b.value && b.value.initOpenShow(e);
      }), oe(e));
    }, n = () => {
      t.disabled || (r.value = [], z());
    }, l = (e) => {
      if (c.dropDownPos = e.use.dropDownPos, c.dropDownTop = `${e.use.dropDownTop}px`, t.multiple && t.isShowTag) {
        const i = x.value.offsetWidth;
        c.tagHeight = t.theme === "default" ? `${e.original.dropDownHeight + 1}px` : `${e.original.dropDownHeight}px`;
        const v = e.original.winWidth - (e.original.controlOffset.left + e.original.dropDownWidth) >= i ? "right" : "left";
        c.tagDirection = v, v === "right" ? c.tagLeft = `${e.original.dropDownWidth - 1}px` : c.tagLeft = `${(e.original.dropDownWidth - e.original.textWidth + i + 1) * -1}px`;
      }
    }, h = (e) => {
      r.value = e, t.multiple ? t.multipleRealTimeChange && q() : (y.value.setOpen(!1), o(!1));
    }, T = (e) => {
      r.value = e;
    }, f = () => {
      y.value && (y.value.checkCurrentIsOpen() || y.value.initCompleteOpen());
    }, F = () => N().join(",");
    return j({
      getValue: F,
      getValueData: () => {
        const e = F();
        return t.multiple ? V() : $(e);
      },
      setValue: (e) => {
        B(e), L();
      },
      runInitComplete: () => {
        G();
      }
    }), (e, i) => (D(), ne(ye, {
      ref_key: "refElDropdownLayer",
      ref: y,
      classParent: U.value,
      classText: "select-inText",
      classDropDown: ee.value,
      placeholder: a.placeholder,
      isDisabled: a.disabled,
      isClear: a.isClear,
      textLabel: u.value.join(","),
      textArrowDirection: _.value,
      onOpenBeforeCallback: a.onOpenBefore,
      onOnChangeOpen: o,
      onOnClear: n,
      onOnChangePosition: l
    }, {
      textExtend: Y(() => [
        a.multiple ? (D(), I("span", Pe, [
          a.multiple && u.value.length > 1 ? (D(), ne(ve, {
            key: 0,
            num: u.value.length
          }, null, 8, ["num"])) : J("", !0)
        ])) : J("", !0)
      ]),
      dropdown: Y(() => [
        R(Le, {
          ref_key: "refElList",
          ref: b,
          isSearch: a.isSearch,
          searchPlaceholder: a.searchPlaceholder,
          searchKey: a.searchKey,
          searchKeyType: a.searchKeyType,
          isMultiple: a.multiple,
          isCheckBoxAll: a.isCheckBoxAll,
          showDropDownTextFormat: a.showDropDownTextFormat,
          originalData: a.list,
          keyIndex: S,
          selectId: r.value,
          isOpen: c.isOpen,
          serverCallback: a.serverCallback,
          onOnChange: h,
          onOnInitComplete: f
        }, null, 8, ["isSearch", "searchPlaceholder", "searchKey", "searchKeyType", "isMultiple", "isCheckBoxAll", "showDropDownTextFormat", "originalData", "selectId", "isOpen", "serverCallback"])
      ]),
      dropdownExtend: Y(() => [
        a.multiple && a.isShowTag ? (D(), I("div", {
          key: 0,
          class: de(te.value),
          style: ue({ height: c.tagHeight, left: c.tagLeft }),
          ref_key: "refElTags",
          ref: x
        }, [
          R(Ke, {
            showTextFormat: a.showTextFormat,
            selectId: r.value,
            onOnRemove: T
          }, null, 8, ["showTextFormat", "selectId"])
        ], 6)) : J("", !0)
      ]),
      _: 1
    }, 8, ["classParent", "classDropDown", "placeholder", "isDisabled", "isClear", "textLabel", "textArrowDirection", "onOpenBeforeCallback"]));
  }
});
export {
  Ye as _
};
//# sourceMappingURL=Index.vue_vue_type_script_setup_true_lang-_Zu2nb2q.js.map
