import '@das-fed/ui/packages/components/cascader/style.css';
import { defineComponent as ae, useCssVars as re, ref as t, computed as v, useAttrs as le, watch as F, watchEffect as oe, createElementBlock as h, openBlock as f, normalizeStyle as R, normalizeClass as te, createVNode as _, createCommentVNode as D, unref as s, withCtx as b, withDirectives as W, mergeProps as se, isRef as ue, renderSlot as A, normalizeProps as ce, guardReactiveProps as de, createTextVNode as N, toDisplayString as E, Fragment as ie, createBlock as ne, createElementVNode as pe, nextTick as $ } from "vue";
import { withInstall as ve } from "@das-fed/utils/with-install/index";
import { ElCascader as fe } from "element-plus";
import "element-plus/es/components/cascader/style/css";
import { vHoverInside as me } from "@das-fed/utils/directive/hoverInside/index";
import { getVarValue as he, getVar as Z, setThemeRule as be } from "@das-fed/web/packages/theme/index";
import { t as ye, setI18nRule as ge } from "@das-fed/web/packages/i18n/index";
import { vScrollbar as xe } from "@das-fed/ui/packages/components/scrollbar/index";
import { DasTooltip as O } from "@das-fed/ui/packages/components/tooltip/index";
import { DasErrorOverlayModel as Ve } from "@das-fed/ui/packages/components/error-overlay-model/index";
import { calcTextWidth as Te } from "@das-fed/utils/common-tools";
import { useModelValue as we } from "@das-fed/utils/vue";
const Ce = { style: { maxheight: "200px" } }, ke = {
  key: 0,
  class: "das-cascader-error-label-content"
}, ze = {
  name: "DasCascader"
}, Be = /* @__PURE__ */ ae({
  ...ze,
  props: {
    modelValue: { default: void 0 },
    props: {},
    size: {},
    width: { default: "230px" },
    height: {},
    bordered: { type: Boolean, default: !1 },
    placeholder: { default: ye("请选择") },
    collapseTags: { type: Boolean, default: !0 },
    disabled: { type: Boolean, default: !1 },
    isView: { type: Boolean, default: !1 },
    isTooltip: { type: Boolean, default: !0 },
    error: { type: Boolean, default: !1 },
    errorLabel: {},
    errorMode: { default: "default" },
    separator: { default: "/" },
    errorModelZIndex: { default: 2e3 },
    noSetDefaultVal: { type: Boolean }
  },
  emits: ["update:model-value", "change"],
  setup(y, { expose: C, emit: g }) {
    re((e) => ({
      "7ebd2f0c": K.value,
      "39bcacf3": Q.value,
      "37a6a536": z.value
    }));
    const a = y, l = we(a, "modelValue"), I = g, q = le(), c = t(null), x = t(null), M = t(null), V = t(), k = t(!1), T = v(() => a.isView ? a.noSetDefaultVal ? " " : "-" : a.placeholder ?? " "), d = t(0), i = t(0), u = t(!1), H = v(() => (Array.isArray(l.value) ? l.value.length : l.value) ? V.value : T.value), w = v(() => {
      var e;
      return x.value ? (e = x.value) == null ? void 0 : e.querySelector(".el-input__inner") : null;
    }), S = () => {
      const e = a.size === "table" ? 12 : 14;
      return Te(T.value, e);
    }, L = () => {
      $(() => {
        var e, r;
        if (w.value) {
          d.value = ((e = w.value) == null ? void 0 : e.offsetWidth) ?? 0;
          const o = Array.isArray(l.value) ? l.value.length : l.value;
          i.value = o ? (r = w.value) == null ? void 0 : r.scrollWidth : S(), (d.value === i.value || i.value - d.value < 1) && (u.value = !1);
        }
      });
    };
    F(
      () => w.value,
      (e) => {
        setTimeout(() => {
          const r = e;
          if (r) {
            d.value = (r == null ? void 0 : r.offsetWidth) ?? 0;
            const o = Array.isArray(l.value) ? l.value.length : l.value;
            i.value = o ? r == null ? void 0 : r.scrollWidth : S();
          }
        }, 200);
      }
    ), F(() => [T.value, l.value], L);
    const n = t();
    F(
      () => {
        var e;
        return (e = M.value) == null ? void 0 : e.$tooltipRef.popperRef.contentRef;
      },
      (e) => {
        e && (e.addEventListener("mouseenter", function() {
          u.value = !0, n.value && clearTimeout(n.value);
        }), e.addEventListener("mouseleave", function() {
          n.value = setTimeout(() => {
            u.value = !1;
          }, 200);
        }));
      }
    );
    const U = t({
      display: "block",
      color: he("--das-ui-cascader-overlay-error-color").value,
      "white-space": "break-spaces"
    }), j = () => {
      L(), d.value === i.value || i.value - d.value < 1 ? u.value = !1 : (u.value = !0, n.value && clearTimeout(n.value)), k.value = !0;
    }, G = () => {
      n.value = setTimeout(() => {
        u.value = !1;
      }, 200), k.value = !1;
    }, J = (e, r) => {
      e ? j() : G();
    }, K = v(() => a.width ? a.width : "230px"), Q = v(() => a.height ? a.height : "auto"), P = v(() => ({
      width: typeof a.width == "number" ? a.width + "px" : a.width
    })), z = t("-10px");
    oe(() => {
      l.value ? setTimeout(() => {
        X();
      }, 1e3) : V.value = "";
    });
    const X = () => {
      var r;
      let e = (r = c == null ? void 0 : c.value) == null ? void 0 : r.getCheckedNodes();
      e && e[0] && e[0].text ? V.value = e[0].text : V.value = "";
    }, Y = (e, r) => {
      I("update:model-value", e), I("change", e);
    }, ee = (e) => {
      $(() => {
        var o, p;
        const r = (p = (o = c.value) == null ? void 0 : o.popperPaneRef) == null ? void 0 : p.attributes["data-popper-placement"].value;
        r && r.indexOf("top") > -1 ? z.value = "10px" : z.value = "-10px";
      });
    };
    return C({
      $cascader: c
    }), (e, r) => (f(), h(
      "div",
      {
        class: te(["das-ui-cascader", [
          e.bordered ? "bordered" : "underline",
          a.isView ? "readonly" : "",
          a.error ? "is-error" : "",
          a.size
        ]]),
        style: R(P.value)
      },
      [
        _(s(O), {
          ref_key: "inputTooltipRef",
          ref: M,
          placement: "top",
          trigger: "hover",
          visible: u.value,
          disabled: !e.isTooltip,
          content: H.value
        }, {
          default: b(() => {
            var o;
            return [
              W((f(), h("div", {
                ref_key: "$cascaderBox",
                ref: x
              }, [
                _(s(fe), se({
                  ref_key: "$cascader",
                  ref: c,
                  modelValue: s(l),
                  "onUpdate:modelValue": r[0] || (r[0] = (p) => ue(l) ? l.value = p : null)
                }, s(q), {
                  props: a.props,
                  size: a.size === "table" || a.size === "medium" ? "default" : a.size,
                  disabled: a.disabled || a.isView,
                  placeholder: T.value,
                  collapseTags: a.collapseTags,
                  separator: a.separator,
                  "popper-class": (o = a.props) != null && o.multiple ? "das-ui-cascader-popper-box das-popper-multiple" : "das-ui-cascader-popper-box das-popper-simple",
                  style: P.value,
                  onVisibleChange: ee,
                  onChange: Y
                }), {
                  default: b(({ node: p, data: B }) => [
                    A(e.$slots, "default", ce(de({ node: p, data: B })), () => [
                      _(
                        s(O),
                        { placement: "top" },
                        {
                          content: b(() => {
                            var m;
                            return [
                              W((f(), h("div", Ce, [
                                N(
                                  E(B[((m = a.props) == null ? void 0 : m.label) || "label"]),
                                  1
                                  /* TEXT */
                                )
                              ])), [
                                [s(xe)]
                              ])
                            ];
                          }),
                          default: b(() => {
                            var m;
                            return [
                              N(
                                " " + E(B[((m = a.props) == null ? void 0 : m.label) || "label"]),
                                1
                                /* TEXT */
                              )
                            ];
                          }),
                          _: 2
                          /* DYNAMIC */
                        },
                        1024
                        /* DYNAMIC_SLOTS */
                      )
                    ], !0)
                  ]),
                  empty: b(() => [
                    A(e.$slots, "empty", {}, void 0, !0)
                  ]),
                  _: 3
                  /* FORWARDED */
                }, 16, ["modelValue", "props", "size", "disabled", "placeholder", "collapseTags", "separator", "popper-class", "style"])
              ])), [
                [s(me), J]
              ])
            ];
          }),
          _: 3
          /* FORWARDED */
        }, 8, ["visible", "disabled", "content"]),
        e.error && e.errorLabel ? (f(), h(
          ie,
          { key: 0 },
          [
            e.errorMode === "default" ? (f(), h("div", ke, [
              pe(
                "span",
                {
                  style: R(U.value)
                },
                E(e.errorLabel),
                5
                /* TEXT, STYLE */
              )
            ])) : D("v-if", !0),
            e.errorMode === "overlay" && k.value ? (f(), ne(s(Ve), {
              key: 1,
              errorLabel: e.errorLabel,
              getEl: () => {
                var o;
                return (o = x.value) == null ? void 0 : o.querySelector(".el-cascader");
              },
              errorModelZIndex: e.errorModelZIndex
            }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : D("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : D("v-if", !0)
      ],
      6
      /* CLASS, STYLE */
    ));
  }
}), Fe = (y, C) => {
  const g = y.__vccOpts || y;
  for (const [a, l] of C)
    g[a] = l;
  return g;
}, _e = /* @__PURE__ */ Fe(Be, [["__scopeId", "data-v-0157385c"]]), De = { 请选择: { "zh-CN": "请选择", en: "Please select", _appCode: "framework" } }, Ee = {
  "--das-ui-cascader-color-primary": "#5582F3",
  // 主题色
  "--das-ui-cascader-color-text": Z("--das-ui-color-normal"),
  // 常规字体色
  "--das-ui-cascader-color-border": "#d9d9d9",
  // 边框基础色
  "--das-ui-cascader-color-underline": Z("--das-ui-color-help"),
  // 下划线基础色
  "--das-ui-cascader-color-error": "#FB2323",
  // 错误边框色
  "--das-ui-cascader-color-disabled": "#e5e5e5",
  // 禁用边框色
  "--das-ui-cascader-font-size-small": "14px",
  // 字体大小-small
  "--das-ui-cascader-font-size-middle": "14px",
  // 字体大小-middle
  "--das-ui-cascader-font-size-table": "12px",
  // 字体大小-table
  "--das-ui-cascader-menu-min-width": "160px",
  // 选项最小宽度
  "--das-ui-cascader-menu-node-height": "32px",
  // 选项的高度
  "--das-ui-cascader-menu-checkbox-border-color": "#D9D9D9",
  // 选项多选框边框色
  "--das-ui-cascader-menu-color-active-bg": "#F2F6FF",
  // 选项active背景色
  "--das-ui-cascader-menu-color-hover-bg": "#F5F5F5",
  // 选项hover背景色
  "--das-ui-cascader-overlay-error-color": "#FB2323",
  "--das-ui-cascader-overlay-error-bg-color": "#FFDBE0"
};
ge(De);
be(Ee);
const qe = ve(_e), He = () => t(null), Ue = { name: "cascader 级联" };
export {
  qe as DasCascader,
  He as DasCascaderRef,
  Ue as default
};
