1import { BadgeModule } from './BadgeModule.types';
2
3let lastSetBadgeCount = 0;
4
5const badgeModule: BadgeModule = {
6  addListener: () => {},
7  removeListeners: () => {},
8  getBadgeCountAsync: async () => {
9    return lastSetBadgeCount;
10  },
11  setBadgeCountAsync: async (badgeCount, options) => {
12    // If this module is loaded in SSR (NextJS), we can't modify the badge.
13    // It also can't load the badgin module, that instantly invokes methods on window.
14    if (typeof window === 'undefined') {
15      return false;
16    }
17    const badgin = require('badgin');
18    if (badgeCount > 0) {
19      badgin.set(badgeCount, options);
20    } else {
21      badgin.clear();
22    }
23    lastSetBadgeCount = badgeCount;
24    return true;
25  },
26};
27
28export default badgeModule;
29