import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { apiClient } from '../lib/api-client';
export function useCreateBranch(sessionId) {
    const queryClient = useQueryClient();
    return useMutation({
        mutationFn: (data) => {
            if (!sessionId)
                throw new Error('No session ID');
            return apiClient.createBranch(sessionId, data);
        },
        onSuccess: () => {
            queryClient.invalidateQueries({ queryKey: ['sessions'] });
            if (sessionId) {
                queryClient.invalidateQueries({
                    queryKey: ['branches', sessionId],
                });
            }
        },
    });
}
export function useBranches(sessionId) {
    return useQuery({
        queryKey: ['branches', sessionId],
        queryFn: () => {
            if (!sessionId)
                throw new Error('No session ID');
            return apiClient.listBranches(sessionId);
        },
        enabled: Boolean(sessionId),
    });
}
export function useParentSession(sessionId) {
    return useQuery({
        queryKey: ['parentSession', sessionId],
        queryFn: () => {
            if (!sessionId)
                throw new Error('No session ID');
            return apiClient.getParentSession(sessionId);
        },
        enabled: Boolean(sessionId),
    });
}
//# sourceMappingURL=useBranch.js.map