import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { apiClient } from '../lib/api-client';
export function useSessions() {
    return useQuery({
        queryKey: ['sessions'],
        queryFn: () => apiClient.getSessions(),
        refetchInterval: 5000,
    });
}
export function useSession(sessionId) {
    const { data: sessions } = useSessions();
    return sessions?.find((s) => s.id === sessionId);
}
export function useCreateSession() {
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: (data) => apiClient.createSession(data),
        onSuccess: () => {
            queryClient.invalidateQueries({ queryKey: ['sessions'] });
        },
    });
}
export function useUpdateSession(sessionId) {
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: (data) => apiClient.updateSession(sessionId, data),
        onSuccess: async () => {
            await queryClient.invalidateQueries({ queryKey: ['sessions'] });
            await queryClient.invalidateQueries({ queryKey: ['session', sessionId] });
        },
    });
}
export function useDeleteSession() {
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: (sessionId) => apiClient.deleteSession(sessionId),
        onSuccess: () => {
            queryClient.invalidateQueries({ queryKey: ['sessions'] });
        },
    });
}
//# sourceMappingURL=useSessions.js.map