import '@das-fed/upf-ui/packages/components/cascader/style.css';
import { defineComponent as ae, useCssVars as le, useAttrs as te, ref as s, computed as i, watch as B, watchEffect as re, openBlock as m, createElementBlock as x, normalizeClass as oe, normalizeStyle as N, createVNode as I, unref as u, withCtx as b, withDirectives as _, mergeProps as se, isRef as ue, renderSlot as $, normalizeProps as ne, guardReactiveProps as ie, createTextVNode as O, toDisplayString as E, Fragment as ce, createElementVNode as de, createCommentVNode as L, createBlock as pe, nextTick as Z } from "vue";
import { withInstall as fe } from "@das-fed/upf-utils/with-install/index";
import { ElCascader as ve } from "element-plus";
import "element-plus/es/components/cascader/style/css";
import { vHoverInside as me } from "@das-fed/upf-utils/directive/hoverInside/index";
import { t as he, setI18nRule as ye } from "@das-fed/upf-web/packages/i18n/index";
import { vScrollbar as xe } from "@das-fed/upf-ui/packages/components/scrollbar/index";
import { DasTooltip as F } from "@das-fed/upf-ui/packages/components/tooltip/index";
import { DasErrorOverlayModel as be } from "@das-fed/upf-ui/packages/components/error-overlay-model/index";
import { calcTextWidth as ge } from "@das-fed/upf-utils/common-tools";
import { useModelValue as Ve } from "@das-fed/upf-utils/vue";
const Te = { style: { "max-height": "200px" } }, ze = {
  key: 0,
  class: "das-cascader-error-label-content"
}, Ce = {
  name: "DasCascader"
}, we = /* @__PURE__ */ ae({
  ...Ce,
  props: {
    modelValue: { default: void 0 },
    props: {},
    size: {},
    width: { default: "230px" },
    height: {},
    bordered: { type: Boolean, default: !0 },
    placeholder: { default: he("请选择") },
    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 },
    formSize: {}
  },
  emits: ["update:model-value", "change"],
  setup(r, { expose: w, emit: g }) {
    le((e) => ({
      v57c01640: K.value,
      f3189026: Q.value,
      v8dc8a508: S.value
    }));
    const a = r, t = Ve(a, "modelValue"), P = g, q = te(), c = s(null), V = s(null), D = s(null), T = s(), k = s(!1), z = i(() => a.isView ? a.noSetDefaultVal ? " " : "-" : a.placeholder ?? " "), d = s(0), p = s(0), n = s(!1), H = i(() => (Array.isArray(t.value) ? t.value.length : t.value) ? T.value : z.value), C = i(() => {
      var e;
      return V.value ? (e = V.value) == null ? void 0 : e.querySelector(".el-input__inner") : null;
    }), R = () => {
      const e = a.size === "table" ? 12 : 14;
      return ge(z.value, e);
    }, W = () => {
      Z(() => {
        var e, l;
        if (C.value) {
          d.value = ((e = C.value) == null ? void 0 : e.offsetWidth) ?? 0;
          const o = Array.isArray(t.value) ? t.value.length : t.value;
          p.value = o ? (l = C.value) == null ? void 0 : l.scrollWidth : R(), (d.value === p.value || p.value - d.value < 1) && (n.value = !1);
        }
      });
    };
    B(
      () => C.value,
      (e) => {
        setTimeout(() => {
          const l = e;
          if (l) {
            d.value = (l == null ? void 0 : l.offsetWidth) ?? 0;
            const o = Array.isArray(t.value) ? t.value.length : t.value;
            p.value = o ? l == null ? void 0 : l.scrollWidth : R();
          }
        }, 200);
      }
    ), B(() => [z.value, t.value], W);
    const f = s();
    B(
      () => {
        var e;
        return (e = D.value) == null ? void 0 : e.$tooltipRef.popperRef.contentRef;
      },
      (e) => {
        e && (e.addEventListener("mouseenter", function() {
          n.value = !0, f.value && clearTimeout(f.value);
        }), e.addEventListener("mouseleave", function() {
          f.value = setTimeout(() => {
            n.value = !1;
          }, 200);
        }));
      }
    );
    const U = s({
      display: "block",
      color: "var(--upf-color-error)",
      "white-space": "break-spaces"
    }), j = () => {
      W(), d.value === p.value || p.value - d.value < 1 ? n.value = !1 : (n.value = !0, f.value && clearTimeout(f.value)), k.value = !0;
    }, G = () => {
      f.value = setTimeout(() => {
        n.value = !1;
      }, 200), k.value = !1;
    }, J = (e, l) => {
      e ? j() : G();
    }, K = i(() => a.width ? a.width : "230px"), h = i(() => a.formSize), Q = i(() => a.height ? a.height : h.value ? h.value && {
      small: "24px",
      default: "32px",
      large: "40px"
    }[h.value] : "32px"), A = i(() => ({
      width: typeof a.width == "number" ? a.width + "px" : a.width,
      "--cascader-font-size": h.value && {
        small: "12px",
        default: "14px",
        large: "14px"
      }[h.value]
    })), S = s("-10px");
    re(() => {
      t.value ? setTimeout(() => {
        X();
      }, 1e3) : T.value = "";
    });
    const X = () => {
      var l;
      let e = (l = c == null ? void 0 : c.value) == null ? void 0 : l.getCheckedNodes();
      e && e[0] && e[0].text ? T.value = e[0].text : T.value = "";
    }, Y = (e) => {
      P("update:model-value", e), P("change", e);
    }, ee = (e) => {
      Z(() => {
        var o, v;
        const l = (v = (o = c.value) == null ? void 0 : o.popperPaneRef) == null ? void 0 : v.attributes["data-popper-placement"].value;
        l && l.indexOf("top") > -1 ? S.value = "10px" : S.value = "-10px";
      });
    };
    return w({
      $cascader: c
    }), (e, l) => (m(), x(
      "div",
      {
        class: oe(["das-ui-cascader", [
          r.bordered ? "bordered" : "underline",
          a.isView ? "readonly" : "",
          a.error ? "is-error" : "",
          a.size
        ]]),
        style: N(A.value)
      },
      [
        I(u(F), {
          ref_key: "inputTooltipRef",
          ref: D,
          placement: "top",
          trigger: "hover",
          visible: n.value,
          disabled: !r.isTooltip,
          content: H.value
        }, {
          default: b(() => {
            var o;
            return [
              _((m(), x("div", {
                ref_key: "$cascaderBox",
                ref: V
              }, [
                I(u(ve), se({
                  ref_key: "$cascader",
                  ref: c,
                  modelValue: u(t),
                  "onUpdate:modelValue": l[0] || (l[0] = (v) => ue(t) ? t.value = v : null)
                }, u(q), {
                  props: a.props,
                  size: a.size === "table" || a.size === "medium" || a.size === "mini" ? "default" : a.size,
                  disabled: a.disabled || a.isView,
                  placeholder: z.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: A.value,
                  onVisibleChange: ee,
                  onChange: Y
                }), {
                  default: b(({ node: v, data: M }) => [
                    $(e.$slots, "default", ne(ie({ node: v, data: M })), () => [
                      I(
                        u(F),
                        { placement: "top" },
                        {
                          content: b(() => {
                            var y;
                            return [
                              _((m(), x("div", Te, [
                                O(
                                  E(M[((y = a.props) == null ? void 0 : y.label) || "label"]),
                                  1
                                  /* TEXT */
                                )
                              ])), [
                                [u(xe)]
                              ])
                            ];
                          }),
                          default: b(() => {
                            var y;
                            return [
                              O(
                                " " + E(M[((y = a.props) == null ? void 0 : y.label) || "label"]),
                                1
                                /* TEXT */
                              )
                            ];
                          }),
                          _: 2
                          /* DYNAMIC */
                        },
                        1024
                        /* DYNAMIC_SLOTS */
                      )
                    ], !0)
                  ]),
                  empty: b(() => [
                    $(e.$slots, "empty", {}, void 0, !0)
                  ]),
                  _: 3
                  /* FORWARDED */
                }, 16, ["modelValue", "props", "size", "disabled", "placeholder", "collapseTags", "separator", "popper-class", "style"])
              ])), [
                [u(me), J]
              ])
            ];
          }),
          _: 3
          /* FORWARDED */
        }, 8, ["visible", "disabled", "content"]),
        r.error && r.errorLabel ? (m(), x(
          ce,
          { key: 0 },
          [
            r.errorMode === "default" ? (m(), x("div", ze, [
              de(
                "span",
                {
                  style: N(U.value)
                },
                E(r.errorLabel),
                5
                /* TEXT, STYLE */
              )
            ])) : L("v-if", !0),
            r.errorMode === "overlay" && k.value ? (m(), pe(u(be), {
              key: 1,
              errorLabel: r.errorLabel,
              getEl: () => {
                var o;
                return (o = V.value) == null ? void 0 : o.querySelector(".el-cascader");
              },
              errorModelZIndex: r.errorModelZIndex
            }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : L("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : L("v-if", !0)
      ],
      6
      /* CLASS, STYLE */
    ));
  }
}), ke = (r, w) => {
  const g = r.__vccOpts || r;
  for (const [a, t] of w)
    g[a] = t;
  return g;
}, Se = /* @__PURE__ */ ke(we, [["__scopeId", "data-v-f085c194"]]), Me = { 请选择: { "zh-CN": "请选择", en: "Please select", "zh-MO": "請選擇", _appCode: "framework" } };
ye(Me);
const $e = fe(Se), Oe = () => s(null), Ze = { name: "cascader 级联" };
export {
  $e as DasCascader,
  Oe as DasCascaderRef,
  Ze as default
};
