import { useRef as m } from "react";
import { warningOnce as v } from "../../../rc-util/es/warning.mjs";
function b(t, c) {
  var s = m(null);
  function g() {
    try {
      var r = t.selectionStart, n = t.selectionEnd, e = t.value, i = e.substring(0, r), f = e.substring(n);
      s.current = {
        start: r,
        end: n,
        value: e,
        beforeTxt: i,
        afterTxt: f
      };
    } catch {
    }
  }
  function h() {
    if (t && s.current && c)
      try {
        var r = t.value, n = s.current, e = n.beforeTxt, i = n.afterTxt, f = n.start, a = r.length;
        if (r.endsWith(i))
          a = r.length - s.current.afterTxt.length;
        else if (r.startsWith(e))
          a = e.length;
        else {
          var l = e[f - 1], o = r.indexOf(l, f - 1);
          o !== -1 && (a = o + 1);
        }
        t.setSelectionRange(a, a);
      } catch (u) {
        v(!1, "Something warning of cursor restore. Please fire issue about this: ".concat(u.message));
      }
  }
  return [g, h];
}
export {
  b as default
};
