import { isUndefined as f } from "../value/is.js";
import { ABORT_EVENT as c } from "./constants.js";
import { abortError as b, augmentSignalReason as s } from "./internals.js";
const d = (o = b()) => {
  if ("abort" in AbortSignal)
    return AbortSignal.abort(o);
  const r = new AbortController(), n = f(o) ? b() : o, { signal: e } = r;
  return r.abort(n), s(e, n), e;
}, m = (o) => {
  if ("any" in AbortSignal)
    return AbortSignal.any(o);
  let r = /* @__PURE__ */ new Set(), n = new AbortController();
  const { signal: e } = n;
  let l = function() {
    r.forEach((i) => i.removeEventListener(c, l)), r.clear();
    const a = this?.reason ?? b();
    n.abort(a), s(e, a), n = r = l = void 0;
  };
  r: {
    const a = /* @__PURE__ */ Symbol("<NIL_EXCEPTION>");
    let i = a;
    o: {
      try {
        for (const t of o) {
          if (!g(t)) throw new TypeError("Failed to convert value to 'AbortSignal'");
          if (t.aborted) break o;
          r.add(t);
        }
      } catch (t) {
        i = t;
        break o;
      }
      r.forEach((t) => t.addEventListener(c, l));
      break r;
    }
    if (l.call(e), i !== a) throw i;
  }
  return e;
}, g = (o) => o instanceof AbortSignal;
export {
  m as abortSignalForAny,
  d as abortedSignal,
  g as isAbortSignal
};
