import { useCallback } from 'react';
import {
  CollectionOptimisticActionsBaseParams,
  CollectionState,
  FiltersMap,
} from '@wix/bex-core';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import {
  createNestedOptimisticActions,
  NestedOptimisticActionsState,
} from '../state/NestedTableState/createNestedOptimisticActions';

export function useCreateNestedOptimisticActions() {
  const container = useWixPatternsContainer();

  return useCallback(
    <T, F extends FiltersMap>(
      collection: CollectionState<T, F>,
      state?: NestedOptimisticActionsState<T, F>,
      params?: Partial<CollectionOptimisticActionsBaseParams<T, F>>,
    ) => {
      return createNestedOptimisticActions(
        container,
        collection,
        state,
        params,
      );
    },
    [],
  );
}
