import { EVT_SESSION_EXPIRED as l } from "../constants.js";
import { createPromisor as m } from "../../../async/promisor/main.js";
import { isFunction as p } from "../../../../utils/value/is.js";
import { boolOrFalse as c, falsify as h } from "../../../../utils/value/bool.js";
import { getter as _ } from "../../../../utils/struct/property.js";
import { noop as a } from "../../../../utils/common.js";
import { tryResolve as d } from "../../../../utils/async/main.js";
const y = async (t) => {
  const { specification: s } = t.context, e = await d(async () => {
    const o = s.autoRefresh;
    return p(o) ? o.call(s, t.session) : o;
  }).catch(h);
  return c(e);
}, v = (t) => {
  let s = t.context.emitter.on(l, () => n(!1)), e, o = m(async (r, f = !1) => {
    e = r;
    const u = c(f) || await y(t);
    e === r && u && t.pending && !t.refreshing && t.refresh(e).catch(a);
  }), n = (r = !1) => {
    t.refreshing || o(r);
  }, i = () => {
    s(), o.abort(), o = e = s = void 0, n = i = a;
  };
  return Object.defineProperties((r = !1) => n(r), {
    destruct: _(() => i, !1)
  });
};
export {
  y as _canAutofresh,
  v as createSessionAutofresher
};
