import {
  i as i2,
  t
} from "./chunk-VHRMAIPY.js";
import {
  d,
  o
} from "./chunk-WH2RCB7C.js";
import {
  c,
  f,
  i
} from "./chunk-2SJGEPY5.js";
import {
  d as d2,
  e,
  l,
  u
} from "./chunk-S7GHTZCP.js";
import "./chunk-EMI7KDEO.js";
import {
  __async
} from "./chunk-WDMUDEB6.js";

// node_modules/@ionic/core/components/p-Cwv-vmkN.js
var u2 = /* @__PURE__ */ new WeakMap();
var f2 = (o2, n, t2, i3 = 0, r = false) => {
  u2.has(o2) !== t2 && (t2 ? w(o2, n, i3, r) : p(o2, n));
};
var w = (o2, n, t2, i3 = false) => {
  const r = n.parentNode, a = n.cloneNode(false);
  a.classList.add("cloned-input"), a.tabIndex = -1, i3 && (a.disabled = true);
  const e2 = "rtl" === o2.ownerDocument.dir;
  a.style.insetInlineStart = e2 ? r.offsetWidth - n.offsetLeft - n.offsetWidth + "px" : `${n.offsetLeft}px`, r.appendChild(a), u2.set(o2, a);
  const s = e2 ? 9999 : -9999;
  o2.style.pointerEvents = "none", n.style.transform = `translate3d(${s}px,${t2}px,0) scale(0)`;
};
var p = (o2, n) => {
  const t2 = u2.get(o2);
  t2 && (u2.delete(o2), t2.remove()), o2.style.pointerEvents = "", n.style.transform = "";
};
var m = "input, textarea, [no-blur], [contenteditable]";
var b = "$ionPaddingTimer";
var y = (o2, n, t2) => {
  const i3 = o2[b];
  i3 && clearTimeout(i3), n > 0 ? o2.style.setProperty("--keyboard-offset", `${n}px`) : o2[b] = setTimeout((() => {
    o2.style.setProperty("--keyboard-offset", "0px"), t2 && t2();
  }), 120);
};
var S = (o2, n, t2) => {
  o2.addEventListener("focusout", (() => {
    n && y(n, 0, t2);
  }), { once: true });
};
var h = 0;
var D = "data-ionic-skip-scroll-assist";
var v = (o2) => {
  var n;
  if (document.activeElement === o2) return;
  const t2 = o2.getAttribute("id"), i3 = o2.closest(`label[for="${t2}"]`), r = null === (n = document.activeElement) || void 0 === n ? void 0 : n.closest(`label[for="${t2}"]`);
  null !== i3 && i3 === r || (o2.setAttribute(D, "true"), o2.focus());
};
var x = (o2, n, r, a, e2, d3, c2 = false, l2 = 0, u3 = true) => __async(null, null, function* () {
  if (!r && !a) return;
  const w2 = ((o3, n2, t2, i3) => {
    var r2;
    return ((o4, n3, t3, i4) => {
      const r3 = o4.top, a2 = o4.bottom, e3 = n3.top, s = e3 + 15, d4 = Math.min(n3.bottom, i4 - t3) - 50 - a2, c3 = s - r3, l3 = Math.round(d4 < 0 ? -d4 : c3 > 0 ? -c3 : 0), u4 = Math.min(l3, r3 - e3), f3 = Math.abs(u4);
      return { scrollAmount: u4, scrollDuration: Math.min(400, Math.max(150, f3 / 0.3)), scrollPadding: t3, inputSafeY: 4 - (r3 - s) };
    })((null !== (r2 = o3.closest("ion-item,[ion-item]")) && void 0 !== r2 ? r2 : o3).getBoundingClientRect(), n2.getBoundingClientRect(), t2, i3);
  })(o2, r || a, e2, l2);
  if (r && Math.abs(w2.scrollAmount) < 4) return v(n), void (d3 && null !== r && (y(r, h), S(n, r, (() => h = 0))));
  if (f2(o2, n, true, w2.inputSafeY, c2), v(n), d2((() => o2.click())), d3 && r && (h = w2.scrollPadding, y(r, h)), "undefined" != typeof window) {
    let a2;
    const e3 = () => __async(null, null, function* () {
      void 0 !== a2 && clearTimeout(a2), window.removeEventListener("ionKeyboardDidShow", s), window.removeEventListener("ionKeyboardDidShow", e3), r && (yield c(r, 0, w2.scrollAmount, w2.scrollDuration)), f2(o2, n, false, w2.inputSafeY), document.activeElement === n && v(n), d3 && S(n, r, (() => h = 0));
    }), s = () => {
      window.removeEventListener("ionKeyboardDidShow", s), window.addEventListener("ionKeyboardDidShow", e3);
    };
    if (r) {
      const o3 = yield i(r);
      if (u3 && w2.scrollAmount > o3.scrollHeight - o3.clientHeight - o3.scrollTop) return "password" === n.type ? (w2.scrollAmount += 50, window.addEventListener("ionKeyboardDidShow", s)) : window.addEventListener("ionKeyboardDidShow", e3), void (a2 = setTimeout(e3, 1e3));
    }
    e3();
  }
});
var M = (t2, i3) => __async(null, null, function* () {
  if (void 0 === o) return;
  const s = "ios" === i3, u3 = "android" === i3, w2 = t2.getNumber("keyboardHeight", 290), p2 = t2.getBoolean("scrollAssist", true), b2 = t2.getBoolean("hideCaretOnScroll", s), y2 = t2.getBoolean("inputBlurring", false), S2 = t2.getBoolean("scrollPadding", true), h2 = Array.from(o.querySelectorAll("ion-input, ion-textarea")), v2 = /* @__PURE__ */ new WeakMap(), M2 = /* @__PURE__ */ new WeakMap(), K = yield t.getResizeMode(), g = (n) => __async(null, null, function* () {
    yield new Promise(((o2) => e(n, o2)));
    const t3 = n.shadowRoot || n, i4 = t3.querySelector("input") || t3.querySelector("textarea"), s2 = f(n), l2 = s2 ? null : n.closest("ion-footer");
    if (i4) {
      if (s2 && b2 && !v2.has(n)) {
        const o2 = ((o3, n2, t4) => {
          if (!t4 || !n2) return () => {
          };
          const i5 = (t5) => {
            var i6;
            (i6 = n2) === i6.getRootNode().activeElement && f2(o3, n2, t5);
          }, r = () => f2(o3, n2, false), s3 = () => i5(true), d3 = () => i5(false);
          return l(t4, "ionScrollStart", s3), l(t4, "ionScrollEnd", d3), n2.addEventListener("blur", r), () => {
            u(t4, "ionScrollStart", s3), u(t4, "ionScrollEnd", d3), n2.removeEventListener("blur", r);
          };
        })(n, i4, s2);
        v2.set(n, o2);
      }
      if ("date" !== i4.type && "datetime-local" !== i4.type && (s2 || l2) && p2 && !M2.has(n)) {
        const t4 = ((n2, t5, i5, r, a, e2, s3, d3 = false) => {
          const l3 = e2 && (void 0 === s3 || s3.mode === i2.None);
          let u4 = false;
          const f3 = void 0 !== d ? d.innerHeight : 0, w3 = (o2) => {
            false !== u4 ? x(n2, t5, i5, r, o2.detail.keyboardHeight, l3, d3, f3, false) : u4 = true;
          }, p3 = () => {
            u4 = false, null == d || d.removeEventListener("ionKeyboardDidShow", w3), n2.removeEventListener("focusout", p3);
          }, m2 = () => __async(null, null, function* () {
            t5.hasAttribute(D) ? t5.removeAttribute(D) : (x(n2, t5, i5, r, a, l3, d3, f3), null == d || d.addEventListener("ionKeyboardDidShow", w3), n2.addEventListener("focusout", p3));
          });
          return n2.addEventListener("focusin", m2), () => {
            n2.removeEventListener("focusin", m2), null == d || d.removeEventListener("ionKeyboardDidShow", w3), n2.removeEventListener("focusout", p3);
          };
        })(n, i4, s2, l2, w2, S2, K, u3);
        M2.set(n, t4);
      }
    }
  });
  y2 && (() => {
    let o2 = true, n = false;
    const t3 = document;
    l(t3, "ionScrollStart", (() => {
      n = true;
    })), t3.addEventListener("focusin", (() => {
      o2 = true;
    }), true), t3.addEventListener("touchend", ((i4) => {
      if (n) return void (n = false);
      const r = t3.activeElement;
      if (!r) return;
      if (r.matches(m)) return;
      const a = i4.target;
      a !== r && (a.matches(m) || a.closest(m) || (o2 = false, setTimeout((() => {
        o2 || r.blur();
      }), 50)));
    }), false);
  })();
  for (const o2 of h2) g(o2);
  o.addEventListener("ionInputDidLoad", ((o2) => {
    g(o2.detail);
  })), o.addEventListener("ionInputDidUnload", ((o2) => {
    ((o3) => {
      if (b2) {
        const n = v2.get(o3);
        n && n(), v2.delete(o3);
      }
      if (p2) {
        const n = M2.get(o3);
        n && n(), M2.delete(o3);
      }
    })(o2.detail);
  }));
});
export {
  M as startInputShims
};
/*! Bundled license information:

@ionic/core/components/p-Cwv-vmkN.js:
  (*!
   * (C) Ionic http://ionicframework.com - MIT License
   *)
*/
//# sourceMappingURL=p-Cwv-vmkN-JMIGKRIJ.js.map
