import '@das-fed/ui/packages/components/input-dialog-select/style.css';
import { withInstall as R } from "@das-fed/utils/with-install/index";
import { defineComponent as W, ref as s, computed as B, watch as j, nextTick as P, createElementBlock as c, openBlock as d, mergeProps as H, createElementVNode as D, createCommentVNode as g, createBlock as q, normalizeClass as G, unref as t, withDirectives as T, toDisplayString as M, Fragment as J, createVNode as Q, withModifiers as U } from "vue";
import { DasAutoRegisterIcon as X, DasIcon as Y } from "@das-fed/ui/packages/components/icon/index";
import { vDasTooltip as $ } from "@das-fed/ui/packages/components/text-tooltip/index";
import { DasErrorOverlayModel as x } from "@das-fed/ui/packages/components/error-overlay-model/index";
import { getVarValue as ee, setThemeRule as le } from "@das-fed/web/packages/theme/index";
import { t as F, currentLang as te, setI18nRule as oe } from "@das-fed/web/packages/i18n/index";
import { isEmpty as i } from "@das-fed/utils/common-tools";
const ae = {
  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" }, de = ["title"], ne = /* @__PURE__ */ W({
  __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: "bottom" },
    optionsLabelKey: { default: "name" },
    optionsValueKey: { default: "id" },
    placeholder: {},
    errorMode: { default: "default" },
    errorModelZIndex: { default: 2e3 },
    noSetDefaultVal: { type: Boolean }
  },
  emits: ["update:modelValue", "open-dialog", "clear-dialog", "update:selectedOptions", "change"],
  setup(k, { emit: C }) {
    X({
      search: import("@das-fed/ui/packages/icons/search")
    });
    const l = k, a = C, h = s(!1), p = B(() => l.isView), E = B(() => l.placeholder ? l.placeholder : F("请选择")), N = B(() => `width:${l.width === "auto" ? "100%" : l.width}`);
    let r = s("");
    r.value = l.modelValue;
    const n = s(null), u = s(null);
    let f = s(""), z = s([]);
    j(
      () => l.selectedOptions,
      (e, m) => {
        let b = "", I = [], y = [];
        if (i(e) && i(m) && l.modelValue instanceof Array && !l.modelValue.length) {
          r.value = "", f.value = "";
          return;
        }
        if (i(e) && i(m)) return;
        if (typeof e == "string")
          b = e;
        else if (e instanceof Array) {
          if (!(e != null && e.length) && !(m != null && m.length)) {
            r.value = p.value || l.disabled ? "-" : "";
            return;
          }
          y = e.map((v) => {
            const o = v[l.optionsLabelKey];
            if (!(o === null || typeof o > "u" || o === ""))
              return o;
          }), I = e.map((v) => {
            const o = v[l.optionsValueKey];
            if (!(o === null || typeof o > "u" || o === ""))
              return o;
          }), b = te.value === "zh-CN" ? y.join("、") : y.join(",");
        }
        const A = l.noSetDefaultVal ? "" : "-";
        r.value = (p.value || l.disabled) && i(b) ? A : b, z.value = I, I.length || (f.value = ""), a("update:modelValue", z.value), a("change", z.value, l.selectedOptions), P(() => {
          var v, o, w, S;
          ((v = n == null ? void 0 : n.value) == null ? void 0 : v.offsetWidth) > 0 && ((o = u == null ? void 0 : u.value) == null ? void 0 : o.offsetWidth) > 0 && ((w = u == null ? void 0 : u.value) == null ? void 0 : w.offsetWidth) > ((S = n == null ? void 0 : n.value) == null ? void 0 : S.offsetWidth) - 20 && y.length > 1 ? f.value = I.length > 0 ? `${F("das-framework-input-dialog-select-total-items", y.length)}` : "" : f.value = "";
        });
      },
      {
        deep: !0,
        immediate: !0
      }
    );
    const O = s();
    s({
      display: "block",
      color: ee("--das-ui-input-error-color").value,
      "white-space": "break-spaces"
      // 'word-break': 'break-all',
    });
    const V = () => {
      a("open-dialog");
    }, K = () => {
      f.value = "", r.value = "", a("update:selectedOptions", []), a("update:modelValue", []), a("clear-dialog"), a("change", [], []);
    }, L = s(!1), Z = () => {
      h.value = !0, l.errorMode === "overlay" && (L.value = !0);
    }, _ = () => {
      h.value = !1, l.errorMode === "overlay" && (L.value = !1);
    };
    return (e, m) => (d(), c(
      "div",
      H({
        class: "das-ui-input-dialog-select",
        tabindex: "0",
        style: N.value
      }, e.$attrs, {
        ref_key: "$refInputDialogSelect",
        ref: O,
        onMouseenter: Z,
        onMouseleave: _,
        class: [
          { "normal-size": e.size === "default" },
          { "auto-size": e.size === "auto" },
          { "small-size": e.size === "small" },
          { "table-size": e.size === "table" },
          { isview: p.value },
          { disabled: e.disabled }
        ]
      }),
      [
        D(
          "div",
          {
            ref_key: "dialogTextWrap",
            ref: n,
            class: G([
              "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": !t(i)(t(r)) && e.isClear }
            ])
          },
          [
            t(i)(t(r)) && !t(i)(E.value) && !p.value && !e.disabled ? T((d(), c("div", ae, [
              D(
                "span",
                null,
                M(E.value),
                1
                /* TEXT */
              )
            ])), [
              [t($)]
            ]) : T((d(), c("div", re, [
              D(
                "span",
                {
                  ref_key: "dialogText",
                  ref: u
                },
                M(t(r)),
                513
                /* TEXT, NEED_PATCH */
              )
            ])), [
              [t($)]
            ]),
            p.value ? g("v-if", !0) : (d(), c(
              "span",
              se,
              M(t(f)),
              1
              /* TEXT */
            )),
            !p.value && !e.disabled ? (d(), c(
              J,
              { key: 3 },
              [
                !t(i)(t(r)) && e.isClear ? (d(), c("span", {
                  key: 0,
                  class: "das-ui-input-dialog-select-clear",
                  onClick: U(K, ["stop"])
                })) : g("v-if", !0),
                Q(t(Y), {
                  class: "das-ui-input-dialog-select-search",
                  icon: e.suffixIcon,
                  onClick: V
                }, null, 8, ["icon"])
              ],
              64
              /* STABLE_FRAGMENT */
            )) : g("v-if", !0)
          ],
          2
          /* CLASS */
        ),
        D("div", ie, [
          e.error && e.errorLabel && e.errorMode === "default" ? (d(), c("span", {
            key: 0,
            class: "das-input-dialog-select-error-label",
            title: e.errorLabel
          }, M(e.errorLabel), 9, de)) : g("v-if", !0)
        ]),
        g(" 错误状态 "),
        e.error && e.errorLabel && h.value && e.errorMode === "overlay" && L.value ? (d(), q(t(x), {
          key: 0,
          errorLabel: e.errorLabel,
          getEl: () => O.value,
          errorModelZIndex: e.errorModelZIndex
        }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : g("v-if", !0)
      ],
      16
      /* FULL_PROPS */
    ));
  }
}), ue = (k, C) => {
  const l = k.__vccOpts || k;
  for (const [a, h] of C)
    l[a] = h;
  return l;
}, ce = /* @__PURE__ */ ue(ne, [["__scopeId", "data-v-f6defb6e"]]), pe = {
  请选择: { "zh-CN": "请选择", en: "Please select", _appCode: "framework" },
  "das-framework-input-dialog-select-total-items": { "zh-CN": "共$0项", en: "Total $0 Items", _appCode: "framework" }
}, fe = {
  "--demo-alert-bg": {
    light: "#fff",
    dark: "rgba(255,255,255,.2)"
  },
  "--das-ui-input-dialog-select-border": "#999",
  "--das-ui-input-dialog-select-border-all": "#d9d9d9",
  "--das-ui-input-dialog-select-view-border": "#e5e5e5",
  "--das-ui-input-dialog-select-icon": "#666",
  "--das-ui-input-dialog-select-text": "#212121",
  "--das-ui-input-dialog-select-disabled-text": "#b2b2b2",
  "--das-ui-input-dialog-select-border-active": "#5582F3",
  "--das-ui-input-dialog-select-error-color": "#FB2323",
  "--das-ui-color-overlay-error": "#FFDBE0",
  "--das-ui-input-error-color": "#FB2323"
};
oe(pe);
le(fe);
const De = R(ce);
export {
  De as DasInputDialogSelect,
  De as default
};
