import { useMemo } from 'react';

import usePermissions from 'src/hooks/usePermissions';
import { useLokaliseTranslation as useTranslation } from 'src/utils/i18n';

import { UserPermissions } from 'src/utils/permissions';

const { VIEW_BIRTHDAYS, VIEW_ANNIVERSARIES } = UserPermissions;

type CelebrationTitleResponse = {
  title: string;
  notFound: string;
};

const useCelebrationTitle = (): CelebrationTitleResponse => {
  const { t } = useTranslation('celebrations');

  const { hasAll: canViewBirthdays } = usePermissions([VIEW_BIRTHDAYS]);
  const { hasAll: canViewAnniversaries } = usePermissions([VIEW_ANNIVERSARIES]);

  const titleObject = useMemo(() => {
    if (canViewBirthdays && canViewAnniversaries)
      return { title: t('celebrations_title'), notFound: t('no_celebration') };
    if (canViewBirthdays)
      return { title: t('birthday_title'), notFound: t('n0_birthdays') };
    if (canViewAnniversaries)
      return { title: t('anniversary_title'), notFound: t('no_anniversaries') };

    // Default fallback
    return { title: t('celebrations_title'), notFound: t('no_celebration') };
  }, [canViewBirthdays, canViewAnniversaries, t]);

  return titleObject;
};

export default useCelebrationTitle;
