import { signInWithPassword } from "@/lib/auth"
import { useMutation } from "@tanstack/react-query"
import { useParams, useRouter } from "@/framework/navigation"

export const useBackOfficeLogin = () => {
  const router = useRouter()
  const { lang } = useParams<{ lang?: string }>()
  return useMutation({
    mutationFn: async ({ email, password }: { email: string; password: string }) => {
      return await signInWithPassword(email, password)
    },
    onSuccess: () => {
      router.replace(`/${lang || 'en'}/backoffice/candidates`)
    },
    onError: (error) => {
      console.error('BackOffice login failed:', error)
    }
  })
}
