import { ToolbarCollectionProps } from './ToolbarCollection';
import { FiltersMap } from '@wix/bex-core';

export function checkConflictingToolbarProps<T, F extends FiltersMap>(
  props: ToolbarCollectionProps<T, F>,
) {
  const {
    tabs,
    views,
    title,
    dragAndDropBulkSubmit,
    dragAndDropSubmit,
    dragAndDropReorderModeToolbar,
  } = props;
  if (process.env.NODE_ENV !== 'production') {
    const tabsProp = { key: '`tabs`', val: tabs };
    const viewsProp = { key: '`views`', val: views };
    const titleProp = { key: '`title`', val: title?.props.title };
    const dragAndDropSubmitProp = {
      key: '`dragAndDropSubmit`',
      val: dragAndDropSubmit,
    };
    const dragAndDropBulkSubmitProp = {
      key: '`dragAndDropBulkSubmit`',
      val: dragAndDropBulkSubmit,
    };
    const dragAndDropReorderModeToolbarProp = {
      key: '`dragAndDropReorderModeToolbar`',
      val: dragAndDropReorderModeToolbar,
    };

    const conflictingProps = [
      [titleProp, tabsProp],
      [titleProp, viewsProp],
      [dragAndDropSubmitProp, dragAndDropReorderModeToolbarProp],
      [dragAndDropSubmitProp, dragAndDropBulkSubmitProp],
    ];

    if (title?.props.subtitle != null && title?.props.title == null) {
      throw new Error(
        'Cairo: Invalid `subtitle` provided and `title` not provided.',
      );
    }

    for (const pair of conflictingProps) {
      if (pair[0].val != null && pair[1].val != null) {
        throw new Error(
          `Cairo: Invalid both ${pair[0].key} and ${pair[1].key} props provided, either ${pair[0].key} or ${pair[1].key} is supported.`,
        );
      }
    }
  }
}
