import { defineComponent as h, computed as C, ref as r, onMounted as N, watch as y, onUnmounted as P, openBlock as E, createElementBlock as _, mergeProps as x } from "vue";
import { i as B } from "../intl-tel-input-KyxsDd7Z.mjs";
const w = /* @__PURE__ */ h({
  inheritAttrs: !1,
  __name: "IntlTelInput",
  props: {
    options: { default: () => ({}) },
    usePreciseValidation: { type: Boolean, default: !1 },
    disabled: { type: Boolean, default: !1 },
    inputProps: { default: () => ({}) },
    value: {},
    modelValue: {}
  },
  emits: [
    "changeNumber",
    "changeCountry",
    "changeValidity",
    "changeErrorCode",
    "update:modelValue"
  ],
  setup(d, { expose: V, emit: b }) {
    const l = d, u = b, i = C(() => l.value ?? l.modelValue ?? ""), n = r(null), t = r(null), s = r(!1), c = () => t.value ? l.usePreciseValidation ? t.value.isValidNumberPrecise() : t.value.isValidNumber() : null, p = () => {
      var a, o;
      let e = c();
      s.value !== e && (s.value = e, u("changeValidity", !!e), u(
        "changeErrorCode",
        e ? null : ((o = (a = t.value) == null ? void 0 : a.getValidationError) == null ? void 0 : o.call(a)) ?? null
      ));
    }, m = () => {
      var a;
      const e = ((a = t.value) == null ? void 0 : a.getNumber()) ?? "";
      u("changeNumber", e), u("update:modelValue", e), p();
    }, g = () => {
      var e;
      u("changeCountry", ((e = t.value) == null ? void 0 : e.getSelectedCountryData().iso2) ?? ""), m();
    };
    return N(() => {
      n.value && (t.value = B(n.value, l.options), i.value && t.value.setNumber(i.value), l.disabled && t.value.setDisabled(l.disabled), s.value = c());
    }), y(
      () => l.disabled,
      (e) => {
        var a;
        return (a = t.value) == null ? void 0 : a.setDisabled(e);
      }
    ), y(
      () => i.value,
      (e) => {
        var v, f;
        if (!t.value) return;
        const a = e ?? "", o = ((f = (v = t.value).getNumber) == null ? void 0 : f.call(v)) ?? "";
        document.activeElement === n.value || o === a || (t.value.setNumber(a), p());
      },
      { flush: "post" }
    ), P(() => {
      var e;
      return (e = t.value) == null ? void 0 : e.destroy();
    }), V({ instance: t, input: n }), (e, a) => (E(), _("input", x({
      ref_key: "input",
      ref: n,
      type: "tel",
      onCountrychange: g,
      onInput: m
    }, d.inputProps), null, 16));
  }
});
export {
  w as default
};
