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

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

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

  return state;
}
