import '@das-fed/upf-ui/packages/components/input-dialog-select/style.css';
import { withInstall as R } from "@das-fed/upf-utils/with-install/index";
import { defineComponent as F, ref as n, computed as I, watch as H, nextTick as q, openBlock as u, createElementBlock as f, mergeProps as G, createElementVNode as M, normalizeClass as J, unref as l, withDirectives as N, toDisplayString as x, createCommentVNode as g, Fragment as Q, withModifiers as U, createVNode as X, createBlock as Y } from "vue";
import { DasAutoRegisterIcon as _, DasIcon as ee } from "@das-fed/upf-ui/packages/components/icon/index";
import { vDasTooltip as T } from "@das-fed/upf-ui/packages/components/text-tooltip/index";
import { DasErrorOverlayModel as te } from "@das-fed/upf-ui/packages/components/error-overlay-model/index";
import { t as w, currentLang as le, setI18nRule as ae } from "@das-fed/upf-web/packages/i18n/index";
import { isEmpty as i } from "@das-fed/upf-utils/common-tools";
const oe = {
  key: 0,
  class: "placeholder-text"
}, re = {
  key: 1,
  class: "dialog-text"
}, se = {
  key: 2,
  class: "reset-plus"
}, ie = { class: "das-input-dialog-select-label-content" }, ne = ["title"], ue = /* @__PURE__ */ F({
  __name: "Index",
  props: {
    modelValue: {},
    selectedOptions: { default: [] },
    disabled: { type: Boolean, default: !1 },
    isView: { type: Boolean, default: !1 },
    isClear: { type: Boolean, default: !1 },
    error: { type: Boolean, default: !1 },
    errorLabel: { default: "" },
    suffixIcon: { default: "search" },
    width: {},
    size: { default: "default" },
    borderType: { default: "bordered" },
    optionsLabelKey: { default: "name" },
    optionsValueKey: { default: "id" },
    placeholder: { default: w("请选择") },
    errorMode: { default: "default" },
    errorModelZIndex: { default: 2e3 },
    noSetDefaultVal: { type: Boolean },
    formSize: {}
  },
  emits: ["update:modelValue", "open-dialog", "clear-dialog", "update:selectedOptions", "change"],
  setup(e, { emit: C }) {
    _({
      search: import("@das-fed/upf-ui/packages/icons/search")
    });
    const t = e, r = C, y = n(!1), m = I(() => t.isView), S = I(() => t.placeholder), K = I(() => `${t.width === "auto" ? "100%" : t.width}`);
    let s = n("");
    s.value = t.modelValue;
    const d = n(null), c = n(null);
    let v = n(""), D = n([]);
    H(
      () => t.selectedOptions,
      (a, p) => {
        let b = "", z = [], k = [];
        if (i(a) && i(p) && t.modelValue instanceof Array && !t.modelValue.length) {
          s.value = "", v.value = "";
          return;
        }
        if (i(a) && i(p)) return;
        if (typeof a == "string")
          b = a;
        else if (a instanceof Array) {
          if (!(a != null && a.length) && !(p != null && p.length)) {
            s.value = m.value || t.disabled ? "-" : "";
            return;
          }
          k = a.map((h) => {
            const o = h[t.optionsLabelKey];
            if (!(o === null || typeof o > "u" || o === ""))
              return o;
          }), z = a.map((h) => {
            const o = h[t.optionsValueKey];
            if (!(o === null || typeof o > "u" || o === ""))
              return o;
          }), b = le.value === "zh-CN" ? k.join("、") : k.join(",");
        }
        const P = t.noSetDefaultVal ? "" : "-";
        s.value = (m.value || t.disabled) && i(b) ? P : b, D.value = z, z.length || (v.value = ""), r("update:modelValue", D.value), r("change", D.value, t.selectedOptions), q(() => {
          var h, o, $, E;
          ((h = d == null ? void 0 : d.value) == null ? void 0 : h.offsetWidth) > 0 && ((o = c == null ? void 0 : c.value) == null ? void 0 : o.offsetWidth) > 0 && (($ = c == null ? void 0 : c.value) == null ? void 0 : $.offsetWidth) > ((E = d == null ? void 0 : d.value) == null ? void 0 : E.offsetWidth) - 20 && k.length > 1 ? v.value = z.length > 0 ? `${w("das-framework-input-dialog-select-total-items", k.length)}` : "" : v.value = "";
        });
      },
      {
        deep: !0,
        immediate: !0
      }
    );
    const O = n(), V = () => {
      r("open-dialog");
    }, Z = () => {
      v.value = "", s.value = "", r("update:selectedOptions", []), r("update:modelValue", []), r("clear-dialog"), r("change", [], []);
    }, L = n(!1), A = () => {
      y.value = !0, t.errorMode === "overlay" && (L.value = !0);
    }, W = () => {
      y.value = !1, t.errorMode === "overlay" && (L.value = !1);
    }, B = I(() => t.formSize), j = I(() => ({
      width: K.value,
      "--input-dialog-select-height": B.value && {
        small: "24px",
        default: "32px",
        large: "40px"
      }[B.value]
    }));
    return (a, p) => (u(), f(
      "div",
      G({
        class: "das-ui-input-dialog-select",
        tabindex: "0",
        style: j.value
      }, a.$attrs, {
        ref_key: "$refInputDialogSelect",
        ref: O,
        onMouseenter: A,
        onMouseleave: W,
        class: [
          { "normal-size": e.size === "default" },
          { "auto-size": e.size === "auto" },
          { "small-size": e.size === "small" },
          { "table-size": e.size === "table" },
          { isview: m.value },
          { disabled: e.disabled }
        ]
      }),
      [
        M(
          "div",
          {
            ref_key: "dialogTextWrap",
            ref: d,
            class: J([
              "das-ui-input-dialog-select-content",
              { "only-border-bottom": e.borderType === "bottom" },
              { "das-input-dialog-select-error": e.error },
              { "das-input-dialog-select-clear-mode": !l(i)(l(s)) && e.isClear }
            ])
          },
          [
            l(i)(l(s)) && !l(i)(S.value) && !m.value && !e.disabled ? N((u(), f("div", oe, [
              M(
                "span",
                null,
                x(S.value),
                1
                /* TEXT */
              )
            ])), [
              [l(T)]
            ]) : N((u(), f("div", re, [
              M(
                "span",
                {
                  ref_key: "dialogText",
                  ref: c
                },
                x(l(s)),
                513
                /* TEXT, NEED_PATCH */
              )
            ])), [
              [l(T)]
            ]),
            m.value ? g("v-if", !0) : (u(), f(
              "span",
              se,
              x(l(v)),
              1
              /* TEXT */
            )),
            !m.value && !e.disabled ? (u(), f(
              Q,
              { key: 3 },
              [
                !l(i)(l(s)) && e.isClear ? (u(), f("span", {
                  key: 0,
                  class: "das-ui-input-dialog-select-clear",
                  onClick: U(Z, ["stop"])
                })) : g("v-if", !0),
                X(l(ee), {
                  class: "das-ui-input-dialog-select-search",
                  icon: e.suffixIcon,
                  onClick: V
                }, null, 8, ["icon"])
              ],
              64
              /* STABLE_FRAGMENT */
            )) : g("v-if", !0)
          ],
          2
          /* CLASS */
        ),
        M("div", ie, [
          e.error && e.errorLabel && e.errorMode === "default" ? (u(), f("span", {
            key: 0,
            class: "das-input-dialog-select-error-label",
            title: e.errorLabel
          }, x(e.errorLabel), 9, ne)) : g("v-if", !0)
        ]),
        g(" 错误状态 "),
        e.error && e.errorLabel && y.value && e.errorMode === "overlay" && L.value ? (u(), Y(l(te), {
          key: 0,
          errorLabel: e.errorLabel,
          getEl: () => O.value,
          errorModelZIndex: e.errorModelZIndex
        }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : g("v-if", !0)
      ],
      16
      /* FULL_PROPS */
    ));
  }
}), de = (e, C) => {
  const t = e.__vccOpts || e;
  for (const [r, y] of C)
    t[r] = y;
  return t;
}, ce = /* @__PURE__ */ de(ue, [["__scopeId", "data-v-da364233"]]), fe = {
  请选择: { "zh-CN": "请选择", en: "Please select", "zh-MO": "請選擇", _appCode: "framework" },
  "das-framework-input-dialog-select-total-items": { "zh-CN": "共$0项", en: "Total $0 Items", "zh-MO": "共$0項", _appCode: "framework" }
};
ae(fe);
const ke = R(ce);
export {
  ke as DasInputDialogSelect,
  ke as default
};
