1 import { c } from 'ttag';
3 import type { NEWSLETTER_SUBSCRIPTIONS_BITS } from '@proton/shared/lib/helpers/newsletter';
4 import isTruthy from '@proton/utils/isTruthy';
6 import { getEmailSubscriptionsMap } from './constants/email-subscriptions';
8 export const getEmailSubscriptionCategories = (news: NEWSLETTER_SUBSCRIPTIONS_BITS[]) => {
9 const emailSubscriptionMap = getEmailSubscriptionsMap();
10 const categoryTitles = news
11 .map((newsKind) => emailSubscriptionMap[newsKind]?.title)
12 .filter((title) => isTruthy(title));
14 if (!categoryTitles.length) {
18 const allCategoryTitlesExceptTheLastOne = categoryTitles.slice(0, -1).join(', ');
19 const lastCategoryTitle = categoryTitles[categoryTitles.length - 1];
21 return categoryTitles.length > 1
22 ? c('news').t`${allCategoryTitlesExceptTheLastOne} and ${lastCategoryTitle}`