import { CollectionState, FiltersMap } from '@wix/bex-core';
import { ReactNode } from 'react';

export function useEmptyStateTexts<T, F extends FiltersMap>(props: {
  state: CollectionState<T, F>;
  subtitle?: ReactNode;
}) {
  const { state } = props;
  const {
    translate: t,
    result: { originQuery, hasAvailableItems },
  } = state;

  const { search, rawSearch } = originQuery;

  const subtitle = (() => {
    if (props.subtitle) {
      return props.subtitle;
    }

    if (hasAvailableItems && search != null) {
      return t('cairo.emptyState.subtitle.nothingMatches', {
        term: rawSearch,
      });
    }

    if (hasAvailableItems) {
      return t('cairo.emptyState.subtitle.nothingMatchesCriteria');
    }

    return t('cairo.emptyState.subtitle.nothingAvailable');
  })();

  const title = t('cairo.emptyState.title');

  return {
    title,
    subtitle,
  };
}
