import { useRef } from 'react';
import {
useMutation,
useQueryClient,
UseMutationOptions,
UseMutationResult,
MutateOptions,
QueryKey,
UseInfiniteQueryResult,
} from '@tanstack/react-query';
import { useDataProvider } from '../context/tushan';
import { useEvent } from '../hooks/useEvent';
import type {
BasicRecord,
DeleteManyParams,
GetListResult as OriginalGetListResult,
Identifier,
GetInfiniteListResult,
} from './types';
import { useResourceContext } from '../context/resource';
/**
* Get a callback to call the dataProvider.delete() method, the result and the loading state.
*
* @param {string} resource
* @param {Params} params The delete parameters { ids }
* @param {Object} options Options object to pass to the queryClient.
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
*
* @typedef Params
* @prop params.ids The resource identifiers, e.g. [123, 456]
*
* @returns The current mutation state. Destructure as [deleteMany, { data, error, isLoading }].
*
* The return value updates according to the request state:
*
* - initial: [deleteMany, { isLoading: false, isIdle: true }]
* - start: [deleteMany, { isLoading: true }]
* - success: [deleteMany, { data: [data from response], isLoading: false, isSuccess: true }]
* - error: [deleteMany, { error: [error from response], isLoading: false, isError: true }]
*
* The deleteMany() function must be called with a resource and a parameter object: deleteMany(resource, { ids, meta }, options)
*
* This hook uses react-query useMutation under the hood.
* This means the state object contains mutate, isIdle, reset and other react-query methods.
*
* @see https://tanstack.com/query/latest/docs/react/reference/useMutation
*
* @example // set params when calling the deleteMany callback
*
* import { useDeleteMany } from 'tushan';
*
* const BulkDeletePostsButton = ({ selectedIds }) => {
* const [deleteMany, { isLoading, error }] = useDeleteMany();
* const handleClick = () => {
* deleteMany('posts', { ids: selectedIds })
* }
* if (error) { return