import { MutationObserver as m } from "../../../../../../@tanstack_query-core@5.95.2/node_modules/@tanstack/query-core/build/modern/mutationObserver.js";
import { notifyManager as i } from "../../../../../../@tanstack_query-core@5.95.2/node_modules/@tanstack/query-core/build/modern/notifyManager.js";
import { noop as c, shouldThrowError as f } from "../../../../../../@tanstack_query-core@5.95.2/node_modules/@tanstack/query-core/build/modern/utils.js";
import { useState as l, useEffect as p, useCallback as s } from "../../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import { useQueryClient as b } from "./QueryClientProvider.js";
import { useSyncExternalStore as h } from "./utils.js";
function d(e, y) {
  const n = b(), [r] = l(
    () => new m(
      n,
      e
    )
  );
  p(() => {
    r.setOptions(e);
  }, [r, e]);
  const t = h(
    s(
      (o) => r.subscribe(i.batchCalls(o)),
      [r]
    ),
    () => r.getCurrentResult()
  ), u = s(
    (o, a) => {
      r.mutate(o, a).catch(c);
    },
    [r]
  );
  if (t.error && f(r.options.throwOnError, [t.error]))
    throw t.error;
  return { ...t, mutate: u, mutateAsync: t.mutate };
}
export {
  d as useMutation
};
