import { useState as S, useCallback as f } from "react";
function I(p) {
  const [n, a] = S(null);
  return [f((t, r, l) => {
    const o = n ?? t, h = Math.min(o || 0, t), c = Math.max(o || 0, t), d = r.slice(h, c + 1).map((e) => p(e)), u = d.some((e) => !l.has(e)), s = [];
    return d.forEach((e) => {
      u ? (l.has(e) || s.push(e), l.add(e)) : (l.delete(e), s.push(e));
    }), a(u ? c : null), s;
  }, [n]), (t) => {
    a(t);
  }];
}
export {
  I as default
};
