/* eslint-disable @tanstack/query/exhaustive-deps */
import { useQuery } from '@tanstack/react-query';
import apiFetch from '@wordpress/api-fetch';
import { addQueryArgs } from '@wordpress/url';

export const useGetChartData = ( periods = {} ) => {
	const periodStart = periods?.start || '';
	const periodEnd = periods?.end || '';

	return useQuery( {
		queryKey: [ 'chartData', periodStart, periodEnd ],
		queryFn: () => {
			return apiFetch( {
				path: addQueryArgs( 'download-monitor/v1/reports/graph_data', periods ),
			} );
		},
	} );
};
