import { defineComponent as L, useSlots as q, useCssModule as P, useAttrs as U, ref as y, computed as c, watchEffect as Z, onMounted as G, openBlock as f, createBlock as V, mergeProps as E, unref as l, createSlots as J, withCtx as k, createElementVNode as N, withDirectives as K, vModelDynamic as W, createElementBlock as x, normalizeClass as v, renderSlot as b, createCommentVNode as C } from "vue";
import { isNil as D } from "es-toolkit";
import { convertDecimal as I, sanitizeDecimal as X, decimalSeparator as h } from "./utils/i18n.js";
import { _ as j } from "./Field.vue_vue_type_script_setup_true_lang-CJUQxQdh.js";
import H from "./Icon.js";
import { _ as Q } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Y = { class: "relative" }, ee = ["id", "aria-errormessage", "aria-invalid", "autocomplete", "placeholder", "type", "disabled", "readonly"], te = /* @__PURE__ */ L({
  name: "ll-input",
  inheritAttrs: !1,
  __name: "Input",
  props: {
    autocomplete: { default: "off" },
    modelValue: { default: "" },
    value: { default: null },
    type: { default: "text" },
    placeholder: { default: void 0 },
    addBottomSpace: { type: Boolean },
    errorText: {},
    hintText: {},
    id: {},
    errorId: {},
    isReadOnly: { type: Boolean },
    isRequired: { type: Boolean },
    label: {},
    showOptionalInLabel: { type: Boolean },
    isLabelSrOnly: { type: Boolean },
    fieldset: { type: Boolean },
    isDisabled: { type: Boolean },
    disabled: { type: Boolean }
  },
  emits: ["update:model-value", "change", "focus", "blur"],
  setup(_, { expose: S, emit: $ }) {
    const e = _, m = $, r = q(), s = P(), i = U(), w = y();
    S({ inputEl: w });
    const n = y(e.modelValue);
    e.type === "number" && (e.modelValue || e.modelValue === 0) && (n.value = I(e.modelValue, h));
    const p = y(!1), M = c(() => e.isReadOnly || "readonly" in i && i.readonly !== !1), d = c(() => e.type === "number"), O = c(() => {
      const o = { ...i };
      return delete o.class, o;
    }), R = c(() => d.value || e.type === "password" && p.value ? "text" : e.type);
    Z(() => {
      n.value = B(e.modelValue);
    });
    function g(o = "", a = !1) {
      if (!d.value)
        return o;
      let t = o;
      if (D(t) || `${t}`.length === 0) return "";
      if (h !== "." && (t = I(t, ".")), a && (t === "." && (t = "0."), t.toString().startsWith("0.")))
        return t;
      if (!D(t) && `${t}`.length)
        t = Intl.NumberFormat("en-US", {
          style: "decimal",
          maximumFractionDigits: 7,
          useGrouping: !1
        }).format(Number(t));
      else
        return "";
      return isNaN(Number(t)) ? "" : parseFloat(t);
    }
    function B(o) {
      return d.value ? X(o, h) : o;
    }
    function A() {
      const o = d.value ? g(n.value) : n.value;
      m("change", o);
    }
    function T(o) {
      const a = o.target.value;
      n.value = B(a);
      const t = d.value ? g(n.value, !0) : a;
      m("update:model-value", t);
    }
    return G(() => {
      if (e.value !== null)
        throw new Error("ll-input: use :model-value or v-model instead of :value.");
      if (i.onInput)
        throw new Error("ll-input: use the @update:model-value event instead of @input");
    }), (o, a) => (f(), V(j, E(e, {
      class: ["stash-input", [l(s).root, l(i).class]],
      "data-test": "ll-input"
    }), J({
      default: k(({ fieldId: t, fieldErrorId: F, hasError: z }) => [
        N("div", Y, [
          K(N("input", E(O.value, {
            id: t,
            ref_key: "inputEl",
            ref: w,
            "onUpdate:modelValue": a[0] || (a[0] = (u) => n.value = u),
            "aria-errormessage": F,
            "aria-invalid": z,
            autocomplete: _.autocomplete,
            placeholder: e.placeholder,
            class: [
              { [l(s)["input-prepended"]]: !!l(r).prepend },
              { [l(s)["input-appended"]]: !!l(r).append || e.type === "password" },
              { [l(s)["has-error"]]: !!e.errorText }
            ],
            type: R.value,
            disabled: e.isDisabled || e.disabled,
            readonly: M.value,
            onChange: A,
            onInput: T,
            onBlur: a[1] || (a[1] = (u) => m("blur", u)),
            onFocus: a[2] || (a[2] = (u) => m("focus", u))
          }), null, 16, ee), [
            [W, n.value]
          ]),
          l(r).prepend ? (f(), x("div", {
            key: 0,
            class: v(["stash-input-prepend font-semibold", [l(s).symbol, l(s)["symbol--prepend"]]])
          }, [
            b(o.$slots, "prepend")
          ], 2)) : C("", !0),
          l(r).append || e.type === "password" ? (f(), x("div", {
            key: 1,
            class: v(["stash-input-append font-semibold", [l(s).symbol, l(s)["symbol--append"]]])
          }, [
            l(r).append ? b(o.$slots, "append", { key: 0 }) : (f(), V(H, {
              key: 1,
              name: p.value ? "hide" : "show",
              class: v(["cursor-pointer", { "text-ice-500": e.isDisabled || e.disabled }]),
              "data-test": p.value ? "hide-password-icon" : "show-password-icon",
              onClick: a[3] || (a[3] = (u) => p.value = !p.value)
            }, null, 8, ["name", "class", "data-test"]))
          ], 2)) : C("", !0)
        ])
      ]),
      _: 2
    }, [
      l(r).hint ? {
        name: "hint",
        fn: k(() => [
          b(o.$slots, "hint")
        ]),
        key: "0"
      } : void 0
    ]), 1040, ["class"]));
  }
}), oe = "_root_E0RfE", le = "_symbol_22ZCT", ae = {
  root: oe,
  "has-error": "_has-error_EANnk",
  "input-prepended": "_input-prepended_ZJ3ts",
  "input-appended": "_input-appended_L3MrE",
  symbol: le,
  "symbol--prepend": "_symbol--prepend_MqO-E",
  "symbol--append": "_symbol--append_RXDKz"
}, se = {
  $style: ae
}, me = /* @__PURE__ */ Q(te, [["__cssModules", se]]);
export {
  me as default
};
//# sourceMappingURL=Input.js.map
