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

export function useChartData() {
  const {data} = useQuery({
    queryKey: [getMainMaterialChartData.name],
    async queryFn({signal}) {
      const data = await getMainMaterialChartData(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;
}
