import { jsxs as N, Fragment as w, jsx as o } from "react/jsx-runtime";
import { t as j } from "../../classix-DG18itHa.js";
import { useState as S, useEffect as I } from "react";
import { i as B } from "../../icons-06oXnjRF.js";
import { u as E } from "../../utils--n2yqjCy.js";
import { i as a } from "../../styles.module-BUYR37kC.js";
function A({
  className: L,
  defaultCountryCode: c = "+47",
  disabled: u = !1,
  icon: i,
  label: m,
  placeholder: h,
  ref: v,
  required: l,
  type: t = "text",
  ...e
}) {
  const [s, d] = S(""), [r, g] = S(""), {
    onChange: P,
    value: f,
    ...T
  } = e, {
    touched: p,
    onBlur: x
  } = E(f === ""), C = i && t !== "radio" && t !== "datetime-local" ? {
    "--icon-svg": B(i, !0)
  } : void 0;
  I(() => {
    if (typeof e.onChange == "function" && t === "tel") {
      const n = {
        name: e.name,
        value: r ? (s || c).split(" ").join("") + r.split(" ").join("") : void 0
      };
      e.onChange({
        target: n,
        currentTarget: n
      });
    }
  }, [s, r]), I(() => {
    t === "tel" && !e.value && (g(""), d(""));
  }, [e.value, t]);
  const V = /* @__PURE__ */ N(w, { children: [
    /* @__PURE__ */ o("input", { disabled: u, hidden: !0, onChange: P, pattern: void 0, placeholder: h, ref: v, type: t, value: f }),
    /* @__PURE__ */ o("input", { type: "text", className: a.input, disabled: u, maxLength: 5, onChange: (n) => d(n.target.value), placeholder: c, value: s }),
    /* @__PURE__ */ o("input", { type: "tel", className: j(a.input, p && a.touched), "data-icon": i ? "true" : void 0, disabled: u, maxLength: 14, name: void 0, onChange: (n) => g(n.target.value), onBlur: x, pattern: e.pattern, required: l, style: C, value: r, ...T })
  ] });
  return /* @__PURE__ */ N("label", { className: a.label, "data-component": "input", children: [
    m && /* @__PURE__ */ o("span", { "data-required": l || void 0, children: m }),
    t === "tel" ? V : /* @__PURE__ */ o("input", { ref: v, className: j(a.input, L, p && a.touched), "data-icon": i ? "true" : void 0, disabled: u, onBlur: x, placeholder: h, required: l, style: C, type: t, ...e })
  ] });
}
export {
  A as Input
};
//# sourceMappingURL=index.js.map
