import {
  sdk
} from "./chunk-DTGEFKK4.js";

// src/hooks/api/auth.tsx
import { useMutation } from "@tanstack/react-query";
var useSignInWithEmailPass = (options) => {
  return useMutation({
    mutationFn: async (payload) => {
      const data = await sdk.auth.$actorType.$authProvider.mutate({
        $actorType: "member",
        $authProvider: "emailpass",
        ...payload
      });
      await sdk.auth.session.mutate({
        fetchOptions: {
          headers: {
            Authorization: `Bearer ${data.token}`
          }
        }
      });
      return data;
    },
    onSuccess: async (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useSignUpWithEmailPass = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.auth.$actorType.$authProvider.register.mutate({
      $actorType: "member",
      $authProvider: "emailpass",
      ...payload
    }),
    onSuccess: async (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
      await sdk.auth.session.mutate({
        fetchOptions: {
          headers: {
            Authorization: `Bearer ${data.token}`
          }
        }
      });
    },
    ...options
  });
};
var useSignUpForInvite = (options) => {
  return useMutation({
    mutationFn: async (payload) => {
      const result = await sdk.auth.$actorType.$authProvider.register.mutate({
        $actorType: "member",
        $authProvider: "emailpass",
        ...payload
      });
      return result;
    },
    ...options
  });
};
var useSignInForInvite = (options) => {
  return useMutation({
    mutationFn: async (payload) => {
      const result = await sdk.auth.$actorType.$authProvider.mutate({
        $actorType: "member",
        $authProvider: "emailpass",
        ...payload
      });
      return result;
    },
    ...options
  });
};
var useResetPasswordForEmailPass = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.auth.$actorType.$authProvider.resetPassword.mutate({
      $actorType: "member",
      $authProvider: "emailpass",
      identifier: payload.email,
      metadata: {}
    }),
    onSuccess: async (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useLogout = (options) => {
  return useMutation({
    mutationFn: () => sdk.auth.session.delete({}),
    ...options
  });
};
var useUpdateProviderForEmailPass = (token, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.auth.$actorType.$authProvider.update.mutate({
      $actorType: "member",
      $authProvider: "emailpass",
      ...payload,
      fetchOptions: {
        headers: {
          Authorization: `Bearer ${token}`
        }
      }
    }),
    onSuccess: async (data, variables, context) => {
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useSignInWithEmailPass,
  useSignUpWithEmailPass,
  useSignUpForInvite,
  useSignInForInvite,
  useResetPasswordForEmailPass,
  useLogout,
  useUpdateProviderForEmailPass
};
