import { useClickedPointConfig } from "../../stores/useClickedPointConfig";
import { useQuery } from "@tanstack/react-query";
import { api } from "../../api";

export const useGetClickedPoint = (enabled, onSuccess) => {
  const { clickedPointConfig } = useClickedPointConfig();

  const { data, isInitialLoading, isFetching } = useQuery(
    ["clicked-point", clickedPointConfig?.id],
    async () => {
      const params = new URLSearchParams({
        "location_ids[]": [clickedPointConfig.id],
      });

      const { data } = await api.get(
        `/api/placement_points?${params.toString()}`
      );

      return data;
    },
    {
      enabled,
      onSuccess,
    }
  );

  return { data, isLoading: isInitialLoading || isFetching };
};
