import { FiltersPanelSelectedFiltersSection } from './FiltersPanelSelectedFiltersSection';
import { FiltersMap, QueryPendingState } from '@wix/bex-core';
import { ToolbarCollectionState } from '../../state';
import { DiscardChangesModal } from '../DiscardChangesModal';

export type AddApplyFiltersButtonType = {
  FiltersPanelSelectedFiltersSection: typeof FiltersPanelSelectedFiltersSection;
  DiscardChangesModal: typeof DiscardChangesModal;
  QueryPendingState: typeof QueryPendingState;
  setStateObject: <T, F extends FiltersMap>(
    toolbar: ToolbarCollectionState<T, F>,
  ) => void;
};

export const AddApplyFiltersButton: AddApplyFiltersButtonType = {
  FiltersPanelSelectedFiltersSection,
  DiscardChangesModal,
  QueryPendingState,
  setStateObject: <T, F extends FiltersMap>(
    toolbar: ToolbarCollectionState<T, F>,
  ) => {
    toolbar.AddApplyFiltersButton = AddApplyFiltersButton;
    toolbar.pendingQuery ??= new QueryPendingState({
      toolbar,
      container: toolbar.container,
    });
  },
};
