import '@das-fed/ui/packages/components/input/style.css';
import { withInstall as K } from "@das-fed/utils/with-install/index";
import { getVarValue as Q, setThemeRule as X } from "@das-fed/web/packages/theme/index";
import { defineComponent as Y, computed as d, ref as r, watch as h, nextTick as C, createElementBlock as b, openBlock as c, normalizeClass as R, normalizeStyle as _, createCommentVNode as i, createVNode as V, unref as S, withCtx as y, mergeProps as ee, createSlots as te, renderSlot as x, toDisplayString as D, Fragment as oe, createBlock as le } from "vue";
import "element-plus/es/components/input/style/css";
import { ElInput as ae } from "element-plus";
import { t as re, setI18nRule as se } from "@das-fed/web/packages/i18n/index";
import { DasTooltip as ie } from "@das-fed/ui/packages/components/tooltip/index";
import { DasErrorOverlayModel as ne } from "@das-fed/ui/packages/components/error-overlay-model/index";
import { calcTextWidth as ue } from "@das-fed/utils/common-tools";
const de = ["auto", "fit-content", "inherit", "initial", "max-content", "min-content", "revert", "unset", "-webkit-fill-available"], fe = (l) => /^[+-]?\d+(\.\d+)?(px|em|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|%)$/.test(l), pe = (l) => {
  if (l)
    return typeof l == "string" && fe(l) || typeof l == "string" && de.includes(l) ? l : l + "px";
}, ce = {
  key: 0,
  class: "das-input-label-content"
}, ve = {
  key: 0,
  class: "das-input-success-label"
}, me = {
  key: 0,
  class: "das-input-label-content"
}, be = ["title"], he = {
  inheritAttrs: !1
}, ye = /* @__PURE__ */ Y({
  ...he,
  __name: "index",
  props: {
    modelValue: { default: "" },
    type: { default: "text" },
    width: { default: "" },
    borderType: { default: "bottom" },
    placeholder: { default: "" },
    size: { default: "default" },
    disabled: { type: Boolean, default: !1 },
    isView: { type: Boolean, default: !1 },
    success: { type: Boolean, default: !1 },
    successLabel: { default: "" },
    error: { type: Boolean, default: !1 },
    errorLabel: { default: "" },
    isErrorTitle: { type: Boolean, default: !1 },
    isTitle: { type: Boolean, default: !0 },
    errorMode: { default: "default" },
    errorModelZIndex: { default: 2e3 },
    noSetDefaultVal: { type: Boolean, default: !1 },
    autosize: { type: [Boolean, Object], default: !0 },
    showWordLimit: { type: Boolean, default: !0 },
    showTextWordLimit: { type: Boolean, default: !1 },
    maxlength: { default: 0 },
    maxLength: { default: 0 },
    filterSpace: { type: Boolean, default: !0 }
  },
  emits: ["update:modelValue", "change"],
  setup(l, { expose: g, emit: T }) {
    const o = l, v = d(() => o.placeholder || re("请输入")), N = d(() => `width:${pe(o.width)}`), F = d(() => {
      const e = Number(o.maxLength) ? Number(o.maxLength) : !1, t = Number(o.maxlength) ? Number(o.maxlength) : !1;
      return e || t && t || !1;
    }), w = T, n = d({
      get: () => o.modelValue,
      set: (e) => w("update:modelValue", e)
    }), O = r(o.isTitle), u = r(!1), P = d(() => n.value ? n.value : v.value), B = r(), s = r(), L = r(!1), Z = d(() => o.type === "textarea" ? o.showWordLimit : o.showTextWordLimit), U = d(() => o.isView || o.disabled), A = d(() => U.value ? o.noSetDefaultVal ? "" : "-" : v.value ?? ""), k = r(!1), f = r(0);
    r({
      display: "block",
      color: Q("--das-ui-input-error-color").value,
      "white-space": "break-spaces"
    }), h(
      () => {
        var e;
        return (e = s.value) == null ? void 0 : e.textarea;
      },
      (e) => {
        C(() => {
          var t;
          e && (e != null && e.nextSibling) && ((t = e.nextSibling) != null && t.style) && (e.nextSibling.style.display = "none");
        });
      }
    );
    const j = (e) => {
      let t = e + "";
      o.type !== "textarea" && o.filterSpace && (t = t.trim()), n.value = t, w("change", t);
    }, q = () => {
      var t;
      o.borderType === "bottom" && (k.value = !0);
      const e = (t = s.value) == null ? void 0 : t.textarea;
      e && e.nextSibling && e.nextSibling.style && (e.nextSibling.style.display = "block", console.log("textareaRef", e.nextSibling));
    }, G = () => {
      var t;
      o.borderType === "bottom" && (k.value = !1);
      const e = (t = s.value) == null ? void 0 : t.textarea;
      e && e.nextSibling && e.nextSibling.style && (e.nextSibling.style.display = "none");
    }, W = () => {
      const e = o.size === "table" ? 12 : 14;
      return ue(v.value, e);
    };
    h(
      () => s.value,
      (e) => {
        setTimeout(() => {
          var a, $;
          const t = e;
          t && (f.value = ((a = t == null ? void 0 : t.ref) == null ? void 0 : a.offsetWidth) ?? 0, p.value = n.value ? ($ = t == null ? void 0 : t.ref) == null ? void 0 : $.scrollWidth : W());
        }, 200);
      }
    );
    const p = r(0), z = () => {
      C(() => {
        var e, t, a;
        (e = s.value) != null && e.ref && (f.value = (t = s.value) == null ? void 0 : t.ref.offsetWidth, p.value = n.value ? (a = s.value) == null ? void 0 : a.ref.scrollWidth : W(), console.log("inputWidth==", f.value), console.log("textWidth==", p.value), (f.value === p.value || p.value - f.value < 1) && (u.value = !1));
      });
    };
    h(() => [n.value, v.value], z);
    const E = r(), m = r(), H = () => {
      z(), f.value === p.value || p.value - f.value < 1 ? u.value = !1 : (u.value = !0, m && clearTimeout(m.value), E && clearTimeout(E.value)), o.errorMode === "overlay" && (L.value = !0);
    }, J = () => {
      m.value = setTimeout(() => {
        u.value = !1;
      }, 200), E.value = setTimeout(() => {
        L.value = !1;
      }, 200);
    }, I = () => {
      console.log("进入tooltip"), u.value = !0, m.value && clearTimeout(m.value);
    }, M = () => {
      console.log("离开toolTip"), m.value = setTimeout(() => {
        u.value = !1;
      }, 200);
    };
    return h(
      () => {
        var e;
        return (e = B.value) == null ? void 0 : e.$tooltipRef.popperRef.contentRef;
      },
      (e) => {
        e && (e.addEventListener("mouseenter", I), e.addEventListener("mouseleave", M));
      }
    ), h(
      () => u.value,
      (e) => {
        var t;
        if (!e) {
          const a = (t = B.value) == null ? void 0 : t.$tooltipRef.popperRef.contentRef;
          a && (a.removeEventListener("mouseenter", I), a.removeEventListener("mouseleave", M));
        }
      }
    ), g({
      $refInput: s
    }), (e, t) => (c(), b(
      "div",
      {
        style: _(N.value),
        class: R([
          "das-ui-input",
          { "only-border-bottom": e.borderType === "bottom" },
          { "das-input-normal-size": e.size === "default" },
          { "das-input-table-size": e.size === "table" }
        ])
      },
      [
        i(" 这里tooltip不能使用v-model:visible 有响应问题 "),
        V(S(ie), {
          ref_key: "inputTooltipRef",
          ref: B,
          effect: "light",
          placement: "top",
          manual: !0,
          visible: u.value,
          disabled: !O.value,
          content: P.value
        }, {
          default: y(() => [
            V(S(ae), ee({
              ref_key: "$refInput",
              ref: s
            }, e.$attrs, {
              modelValue: n.value,
              "onUpdate:modelValue": t[0] || (t[0] = (a) => n.value = a),
              placeholder: A.value,
              disabled: e.disabled,
              readonly: e.isView,
              type: o.type,
              class: [
                { "is-view": e.isView },
                { "das-input-success": e.success },
                { "das-input-error": e.error },
                { "input-focus-color": k.value }
              ],
              autosize: o.autosize,
              showWordLimit: Z.value,
              maxlength: F.value,
              onChange: j,
              onFocus: q,
              onBlur: G,
              onMouseenter: H,
              onMouseleave: J
            }), te({
              _: 2
              /* DYNAMIC */
            }, [
              e.$slots.prepend ? {
                name: "prepend",
                fn: y(() => [
                  i(" 输入框前置内容 "),
                  x(e.$slots, "prepend", {}, void 0, !0)
                ]),
                key: "0"
              } : void 0,
              e.$slots.append ? {
                name: "append",
                fn: y(() => [
                  i(" 输入框后置内容 "),
                  x(e.$slots, "append", {}, void 0, !0)
                ]),
                key: "1"
              } : void 0,
              e.$slots.suffix ? {
                name: "suffix",
                fn: y(() => [
                  x(e.$slots, "suffix", {}, void 0, !0)
                ]),
                key: "2"
              } : void 0,
              e.$slots.prefix ? {
                name: "prefix",
                fn: y(() => [
                  x(e.$slots, "prefix", {}, void 0, !0)
                ]),
                key: "3"
              } : void 0
            ]), 1040, ["modelValue", "placeholder", "disabled", "readonly", "type", "class", "autosize", "showWordLimit", "maxlength"])
          ]),
          _: 3
          /* FORWARDED */
        }, 8, ["visible", "disabled", "content"]),
        e.success && e.successLabel ? (c(), b("div", ce, [
          e.success ? (c(), b(
            "span",
            ve,
            D(e.successLabel),
            1
            /* TEXT */
          )) : i("v-if", !0)
        ])) : i("v-if", !0),
        e.error && e.errorLabel ? (c(), b(
          oe,
          { key: 1 },
          [
            e.errorMode === "default" ? (c(), b("div", me, [
              e.error ? (c(), b("span", {
                key: 0,
                class: R(["das-input-error-label", { "error-label-overflow": e.isErrorTitle }]),
                title: e.isErrorTitle ? e.errorLabel : ""
              }, D(e.errorLabel), 11, be)) : i("v-if", !0)
            ])) : i("v-if", !0),
            L.value && e.errorMode === "overlay" ? (c(), le(S(ne), {
              key: 1,
              errorLabel: e.errorLabel,
              getEl: () => s.value.$el,
              errorModelZIndex: e.errorModelZIndex
            }, null, 8, ["errorLabel", "getEl", "errorModelZIndex"])) : i("v-if", !0)
          ],
          64
          /* STABLE_FRAGMENT */
        )) : i("v-if", !0)
      ],
      6
      /* CLASS, STYLE */
    ));
  }
}), ge = (l, g) => {
  const T = l.__vccOpts || l;
  for (const [o, v] of g)
    T[o] = v;
  return T;
}, Te = /* @__PURE__ */ ge(ye, [["__scopeId", "data-v-d9b9d4c5"]]), xe = {
  "--das-ui-input-default-text-color": "#212121",
  "--das-ui-input-default-placeholder-text-color": "#B2B2B2",
  "--das-ui-input-full-border-color": "#D9D9D9",
  "--das-ui-input-active-full-border-color": "#5582F3",
  "--das-ui-input-disabled-full-border-color": "#d9d9d9",
  "--das-ui-input-disabled-full-border-text-color": "#B2B2B2",
  "--das-ui-input-view-full-border-color": "#E5E5E5",
  "--das-ui-input-textarea-count-color": "#ccc",
  "--das-ui-input-ground-bg-color": "#fafafa",
  "--das-ui-input-only-bottom-color": "#999",
  "--das-ui-input-only-bottom-active-border-color": "#5582F3",
  "--das-ui-input-only-bottom-disabled-border-color": "#E5E5E5",
  "--das-ui-input-only-bottom-disabled-border-text-color": "#B2B2B2",
  "--das-ui-input-only-bottom-view-border-color": "#E5E5E5",
  "--das-ui-input-success-color": "#1BA854",
  "--das-ui-input-error-color": "#FB2323"
}, Be = {
  共: { "zh-CN": "共", en: "Total", _appCode: "framework" },
  项: { "zh-CN": "项", en: "Item", _appCode: "framework" },
  请输入: { "zh-CN": "请输入", en: "Please enter", _appCode: "framework" }
};
se(Be);
X(xe);
const $e = K(Te);
export {
  $e as DasInput,
  $e as default
};
