import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  fetchQuery,
  sdk
} from "./chunk-RIN4CBRB.js";

// src/hooks/api/invites.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var INVITES_QUERY_KEY = "invites";
var invitesQueryKeys = queryKeysFactory(INVITES_QUERY_KEY);
var useInvites = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.invites.query({ ...query }),
    queryKey: invitesQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateInvite = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.invites.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useResendInvite = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.invites.$id.resend.mutate({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteInvite = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.invites.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: invitesQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAcceptInvite = (inviteToken, options) => {
  return useMutation({
    mutationFn: ({ auth_token, ...body }) => fetchQuery("/admin/invites/accept", {
      method: "POST",
      query: { token: inviteToken },
      body,
      headers: { Authorization: `Bearer ${auth_token}` }
    }),
    onSuccess: (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useInvites,
  useCreateInvite,
  useResendInvite,
  useDeleteInvite,
  useAcceptInvite
};
