import { useState } from 'react';
import { FiltersMap, OptionalFiltersMap } from '@wix/bex-core';
import {
  AmbassadorCollectionConfig,
  useWixPatternsContainer,
  useCreateAmbassadorCollection,
} from '@wix/bex-core/react';
import { GridState } from '../../state';

export function useAmbassadorGrid<T, F extends FiltersMap = OptionalFiltersMap>(
  config: AmbassadorCollectionConfig<T, F>,
) {
  const createCollection = useCreateAmbassadorCollection();
  const container = useWixPatternsContainer();

  const [state] = useState(
    () =>
      new GridState({
        collection: createCollection<T, F>(config),
        container,
      }),
  );

  return state;
}
