import { useEffect } from 'react';
import { TableState } from '../../state';
import { FiltersMap } from '@wix/bex-core';
import {
  getBulkAssignStatus,
  getDisabledTooltipContent,
} from './TagsBulkAssignUtils';

interface UseTagsBulkAssignUtilsProps<T1, F1 extends FiltersMap> {
  state: TableState<T1, F1>;
}

export function useTagsBulkAssignUtils<T1, F1 extends FiltersMap>({
  state,
}: UseTagsBulkAssignUtilsProps<T1, F1>) {
  const { tagsBulkAssignButtonState } =
    state.toolbar.tagsCollectionState?.tagsBulkAssignPopoverState ?? {};

  const { hasReachedMaxSelectedItems, isDuringApplyChanges } =
    getBulkAssignStatus({
      state: state.toolbar,
    });
  useEffect(() => {
    if (tagsBulkAssignButtonState) {
      const tooltipContent = getDisabledTooltipContent({
        state: state.toolbar,
      });
      tagsBulkAssignButtonState.setTooltipContent(tooltipContent);
    }
  }, [hasReachedMaxSelectedItems, isDuringApplyChanges]);
}
