import { useMutation } from "@tanstack/react-query";
import { api, useDbTableName } from "../api";
import { useUpdateLayerCounter } from "../stores/useUpdateLayerCounter";

export const useUpdateStatus = ({ onSuccess }) => {
  const { toggleUpdateCounter } = useUpdateLayerCounter();
  const dbTable = useDbTableName();

  return useMutation({
    mutationFn: (params) => {
      return api.put(
        `https://postamates.spatialsystems.ru/api/${dbTable}/update_status/?${params.toString()}`
      );
    },
    onSuccess: () => {
      toggleUpdateCounter();
      onSuccess?.();
    },
  });
};
