import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useSeamClient } from '../../../lib/seam/use-seam-client.js';
export function useEvents(params, options) {
    const { client } = useSeamClient();
    const queryClient = useQueryClient();
    const { data, ...rest } = useQuery({
        enabled: client != null,
        queryKey: ['events', 'list', params],
        queryFn: async () => {
            if (client == null)
                return [];
            return await client.events.list(params);
        },
        onSuccess: (events) => {
            for (const event of events) {
                queryClient.setQueryData(['events', 'get', { event_id: event.event_id }], event);
            }
        },
        refetchInterval: options?.refetchInterval ?? 30000,
    });
    return { ...rest, events: data };
}
//# sourceMappingURL=use-events.js.map