import { defineComponent as ge, useSlots as he, ref as g, computed as p, watch as U, onMounted as Ne, openBlock as b, createElementBlock as w, normalizeStyle as Ie, normalizeClass as E, createElementVNode as C, renderSlot as $, createCommentVNode as x, withDirectives as be, vModelDynamic as we, withModifiers as Ce, nextTick as M } from "vue";
import { C as o } from "./base-PQGakkrl.js";
import { C as O } from "./index-BnerInzC.js";
const Ve = {
  key: 0,
  class: "input-group-prepend"
}, Ee = { class: "input-group-text" }, xe = ["type", "name", "placeholder", "disabled", "readonly"], _e = {
  key: 1,
  class: "input-group-append"
}, Te = { class: "input-group-text" }, Ke = /* @__PURE__ */ ge({
  name: "ClInput",
  __name: "Index",
  props: {
    theme: {
      type: String,
      default: "default",
      validator: (f) => ["default", "icon", "bottomLine"].indexOf(f) !== -1
    },
    value: {
      type: [String, Number],
      default: ""
    },
    inputType: {
      type: String,
      default: ""
    },
    className: {
      type: String,
      default: ""
    },
    width: {
      type: String,
      default: ""
    },
    name: {
      type: String,
      default: ""
    },
    placeholder: {
      type: String,
      default: ""
    },
    disabled: {
      type: Boolean,
      default: !1
    },
    isReadonly: {
      type: Boolean,
      default: !1
    },
    isClean: {
      type: Boolean,
      default: !0
    },
    isNumber: {
      type: Boolean,
      default: !1
    },
    decimal: {
      type: Number,
      default: 0
    },
    isThousand: {
      type: Boolean,
      default: !0
    },
    isImmediateThousand: {
      type: Boolean,
      default: !0
    },
    isPassword: {
      type: Boolean,
      default: !1
    },
    changDelayTime: {
      type: Number,
      default: 200
    }
  },
  emits: ["update:value", "onChange", "onFocus", "onBlur", "onChangeBlur", "onKeyupEnter", "onClear", "onInit", "onKeydown", "onKeyup", "onChangeDelay"],
  setup(f, { expose: G, emit: j }) {
    const n = f, c = j, S = he(), D = g(null), _ = g(!1), h = g(!1), u = g(n.value), d = g(n.value), T = g(n.value), m = {
      prevDelayValue: n.value,
      valueDelayRun: !1
    }, z = p(() => {
      let e = "text";
      const { inputType: t, isNumber: s, isPassword: l } = n;
      return t ? e = t : s || l && (e = h.value ? "text" : "password"), e;
    }), Z = p(() => {
      let e = n.name;
      return o.isEmpty(e) && (e = `input_${o.getRandom(8)}`), e;
    }), B = p(() => !o.isUndefined(S.prepend)), k = p(() => !o.isUndefined(S.append)), A = p(() => n.isClean && !n.disabled && !o.isEmpty(u.value)), q = p(() => {
      const e = {
        "panel-input": !0,
        "box-width": !0,
        "input-disabled": n.disabled,
        "input-readonly": n.isReadonly
      };
      return n.className && !o.isEmpty(n.className) && n.className.split(" ").forEach((t) => {
        o.isEmpty(t) || (e[t] = !0);
      }), o.isEmpty(n.theme, "default") || (e[`input-${n.theme}`] = !0), e;
    }), H = p(() => {
      const e = {};
      return o.isEmpty(n.width) || (e.width = n.width), e;
    }), J = p(() => ({
      "input-container": !0,
      "input-clean": n.isClean,
      "input-password": n.isPassword
    })), Q = p(() => {
      const e = {};
      return (B.value || k.value) && (e["input-group"] = !0, e["input-group-focus"] = _.value), e["input-valueEntry"] = !o.isEmpty(u.value), e;
    }), W = p(() => ({
      "input-password-icon": !0,
      clIconFont: !0,
      "clIcon-eye-no": !h.value,
      "clIcon-eye": h.value
    }));
    let V;
    const X = (e) => {
      V && (clearTimeout(V), V = null), m.valueDelayRun = !0, V = setTimeout(() => {
        m.valueDelayRun = !1, m.prevDelayValue !== e && (m.prevDelayValue = e, c("onChangeDelay", e));
      }, n.changDelayTime);
    }, F = (e) => {
      if (e !== d.value) {
        d.value = e;
        const t = I(e);
        c("update:value", t), c("onChange", t), X(t);
      }
    }, Y = (e) => {
      _.value = !0, T.value = e, c("onFocus", e);
    }, ee = (e) => {
      _.value = !1, c("onBlur", e), e !== T.value && (T.value = e, c("onChangeBlur", e));
    }, te = (e) => {
      c("onKeyupEnter", e);
    }, ne = (e) => {
      c("onKeydown", e);
    }, se = (e) => {
      c("onKeyup", e);
    }, le = () => {
      c("onClear");
    }, oe = () => {
      M(() => {
        c("onInit");
      });
    }, R = (e) => {
      let t = o.isNumber(e);
      if (!t)
        if ((+e).toString() !== "NaN") {
          const s = e.split(".");
          s.length === 2 && (t = o.isNumber(s[0]) && (o.isEmpty(s[1]) || o.isNumber(s[1])));
        } else e === "-" && (t = !0);
      return t;
    }, N = (e, t, s = !0, l = !0) => {
      let i = e;
      if (n.isNumber) {
        let a = o.removeReplace(e);
        if (a.length > 0)
          if (R(a)) {
            if (l && a !== "-") {
              const { decimal: r } = n;
              s && r !== 0 && (a = r === -1 ? parseFloat(a).toString() : parseFloat(a).toFixed(r));
              const v = a.split(".");
              if (v.length > 0 && (a = n.isThousand ? o.getFormatThousands(v[0]) : v[0]), v.length === 2 && r !== 0) {
                const ve = r === -1 ? v[1] : v[1].substr(0, r);
                a += `.${ve}`;
              }
            }
          } else
            a = t;
        else
          a = "";
        i = a;
      }
      return i;
    }, ae = (e, t) => {
      const s = t.split(""), l = new RegExp(`^${s.join(".*?")}`), i = e.match(l);
      let a;
      return o.isUndefined(i) || (a = i[0].length), a;
    }, ue = (e, t, s) => {
      const l = O.getFocusSelection(e);
      let i = t.substring(0, l.start);
      i = o.removeReplace(i);
      const a = t.substring(l.start);
      let y = R(i);
      i.indexOf(".") > -1 && a.indexOf(".") > -1 && (y = !1);
      let r = l.start;
      y ? r = ae(s, i) : r = s.lastIndexOf(a), (o.isUndefined(r) || r > s.length) && (r = s.length), M(() => {
        O.setFocusSelection(e, r, r);
      });
    }, K = () => {
      const e = u.value;
      if (e && !o.isEmpty(e)) {
        let t = e.toString();
        if (n.isNumber) {
          const { decimal: s } = n;
          t = o.removeReplace(t), s !== 0 && (t = s === -1 ? parseFloat(t).toString() : parseFloat(t).toFixed(s));
          const l = t.split(".");
          l.length > 0 && (l[0] = n.isThousand ? o.getFormatThousands(l[0]) : l[0]), s === 0 ? t = l[0] : l.length === 2 ? (l[1] = s === -1 ? l[1] : o.getFillZero(l[1], s, "r"), t = l.join(".")) : t = l[0];
        }
        return t;
      } else
        return e;
    }, I = (e) => {
      let t = "";
      if (!o.isEmpty(e) && (t = e.toString(), n.isNumber && t !== "-")) {
        const { decimal: s } = n, l = t.split(".");
        let i = "";
        if (l.length > 0 && (i = o.removeReplace(l[0])), l.length === 2 && s !== 0) {
          let a = "";
          s === -1 ? a = l[1] : (a = l.length === 2 ? l[1] : "", a = o.getFillZero(a, s, "r")), i += `.${a}`;
        }
        t = i;
      }
      return t;
    }, P = () => {
      D.value?.focus();
    };
    U(
      () => n.value,
      (e, t) => {
        if (e !== t && e !== u.value) {
          let s = !0;
          if (n.isNumber) {
            const l = o.removeReplace(e), i = o.removeReplace(u.value), a = o.isEmpty(l), y = o.isEmpty(i);
            a && y ? s = !1 : !a && !y && (s = Number(l) !== Number(i));
          }
          if (s) {
            const l = N(e, t);
            u.value = l, d.value = l, m.valueDelayRun || (m.prevDelayValue = e);
          }
        }
      }
    ), U([() => n.isNumber, () => n.decimal, () => n.isThousand], () => {
      const e = N(u.value, "");
      u.value = e, F(e);
    });
    const ie = () => {
      if (!o.isEmpty(n.value)) {
        const e = N(n.value, n.value);
        u.value = e, d.value = e;
      }
      oe();
    };
    Ne(() => {
      ie();
    });
    const re = (e) => {
      const t = e.target.value, s = N(t, d.value, !1, n.isImmediateThousand);
      n.isNumber && (u.value = s, ue(e.target, t, s)), F(s);
    }, ce = (e) => {
      ne(e);
    }, pe = (e) => {
      e.preventDefault(), e.stopPropagation();
      const t = e.keyCode;
      if (!o.isUndefined(t) && t.toString() === "13") {
        const s = I(e.target.value);
        te(s);
      } else
        se(e);
    }, de = () => {
      const e = K();
      u.value = e, d.value = e;
      const t = I(e);
      Y(t);
    }, fe = () => {
      const e = K();
      u.value = e, d.value = e;
      const t = I(e);
      ee(t);
    }, me = () => {
      u.value = "", F(""), le(), P();
    }, ye = () => {
      h.value = !h.value;
    }, L = () => I(u.value);
    return G({
      getValue: L,
      getValueData: () => ({ value: L(), show: u.value }),
      setValue: (e) => {
        const t = o.isEmpty(e) ? "" : N(e, "");
        u.value = t, d.value = t;
      },
      focus: () => {
        P();
      }
    }), (e, t) => (b(), w("div", {
      class: E(q.value),
      style: Ie(H.value)
    }, [
      C("div", {
        class: E(Q.value)
      }, [
        B.value ? (b(), w("div", Ve, [
          C("span", Ee, [
            $(e.$slots, "prepend")
          ])
        ])) : x("", !0),
        C("div", {
          class: E(J.value)
        }, [
          be(C("input", {
            ref_key: "refElInput",
            ref: D,
            type: z.value,
            name: Z.value,
            class: "form-control container-border",
            autocomplete: "off",
            "onUpdate:modelValue": t[0] || (t[0] = (s) => u.value = s),
            placeholder: f.placeholder,
            disabled: f.disabled,
            readonly: f.isReadonly,
            onInput: re,
            onKeydown: ce,
            onKeyup: pe,
            onFocus: de,
            onBlur: fe
          }, null, 40, xe), [
            [we, u.value]
          ]),
          A.value ? (b(), w("i", {
            key: 0,
            class: "input-clear-icon clIconFont clIcon-close-circle-fill",
            onClick: Ce(me, ["stop"])
          })) : x("", !0),
          f.isPassword ? (b(), w("i", {
            key: 1,
            class: E(W.value),
            onClick: ye
          }, null, 2)) : x("", !0)
        ], 2),
        k.value ? (b(), w("div", _e, [
          C("span", Te, [
            $(e.$slots, "append")
          ])
        ])) : x("", !0)
      ], 2)
    ], 6));
  }
});
export {
  Ke as _
};
//# sourceMappingURL=Index.vue_vue_type_script_setup_true_lang-DWw1B8Z2.js.map
