1 import { c } from 'ttag';
3 import type { BadgeType } from '@proton/components';
5 import type { SubscribedCalendar, VisualCalendar } from '../interfaces/calendar';
6 import { getIsCalendarDisabled, getIsCalendarProbablyActive, getIsSubscribedCalendar } from './calendar';
7 import { getCalendarHasSubscriptionParameters, getCalendarIsNotSyncedInfo } from './subscribe/helpers';
9 export enum CALENDAR_STATUS_TYPE {
17 export interface CalendarStatusBadge {
18 statusType: CALENDAR_STATUS_TYPE;
25 export const getDefaultCalendarBadge = (): CalendarStatusBadge => ({
26 statusType: CALENDAR_STATUS_TYPE.DEFAULT,
28 text: c('Calendar status').t`Default`,
31 export const getActiveCalendarBadge = (): CalendarStatusBadge => ({
32 statusType: CALENDAR_STATUS_TYPE.ACTIVE,
34 text: c('Calendar status').t`Active`,
37 export const getDisabledCalendarBadge = (): CalendarStatusBadge => ({
38 statusType: CALENDAR_STATUS_TYPE.DISABLED,
40 text: c('Calendar status').t`Disabled`,
43 export const getNotSyncedCalendarBadge = ({
49 }): CalendarStatusBadge => ({
50 statusType: CALENDAR_STATUS_TYPE.NOT_SYNCED,
56 export const getCalendarStatusBadges = (calendar: VisualCalendar | SubscribedCalendar, defaultCalendarID?: string) => {
57 const isDisabled = getIsCalendarDisabled(calendar);
58 const isActive = getIsCalendarProbablyActive(calendar);
59 const isDefault = calendar.ID === defaultCalendarID;
60 const isSubscribed = getIsSubscribedCalendar(calendar);
61 const isNotSyncedInfo = getCalendarHasSubscriptionParameters(calendar)
62 ? getCalendarIsNotSyncedInfo(calendar)
65 const badges: CalendarStatusBadge[] = [];
68 badges.push(getDefaultCalendarBadge());
72 badges.push(getActiveCalendarBadge());
76 badges.push(getDisabledCalendarBadge());
79 if (isSubscribed && isNotSyncedInfo) {
80 badges.push(getNotSyncedCalendarBadge({ text: isNotSyncedInfo.label, tooltipText: isNotSyncedInfo.text }));
83 return { isDisabled, isActive, isDefault, isSubscribed, isNotSyncedInfo, badges };