import { struct as p } from "../../../utils/struct/main.js";
import { getter as b, enumerable as i } from "../../../utils/struct/property.js";
import { isUndefined as l } from "../../../utils/value/is.js";
import { noop as d } from "../../../utils/common.js";
import { boolOrFalse as u } from "../../../utils/value/bool.js";
const P = (n) => {
  let r, t, o;
  const a = () => {
    if (l(r)) return;
    const e = r.abort.bind(r);
    r = void 0, e();
  }, m = () => (o = new Promise((e, c) => {
    if (t.addEventListener("abort", function _() {
      t.removeEventListener("abort", _), c(n);
    }), t.aborted) throw n;
  }), o.catch(d), o), s = (e = !1) => (u(e) && a(), l(r) && (r = new AbortController(), t = r.signal, o = m()), f), f = p({
    abort: i(a),
    promise: b(() => o),
    reason: i(n),
    refresh: i(s),
    signal: b(() => t)
  });
  return s();
};
export {
  P as createAbortable
};
