import {getMainFinishChartData} from '@apis';
import {useQuery} from '@tanstack/react-query';

export function useChartData() {
  const {data} = useQuery({
    queryKey: [getMainFinishChartData.name],
    async queryFn({signal}) {
      const data = await getMainFinishChartData(signal);

      if (data.msg === '200') {
        return data.data.reverse().map(function ({dateTime, amount, count}) {
          return {
            name: dateTime,
            value: amount,
            data: count,
          };
        });
      }

      return [];
    },

    initialData: [],
  });

  return data;
}
