1import { UnavailabilityError } from '@unimodules/core';
2import { v4 as uuidv4 } from 'uuid';
3
4import NotificationPresenter from './NotificationPresenterModule';
5import { NotificationContentInput } from './Notifications.types';
6
7let warningMessageShown = false;
8
9/**
10 * @deprecated Use `scheduleNotificationAsync` with an explicit notification handler.
11 * [Read more](https://expo.fyi/presenting-notifications-deprecated).
12 */
13export default async function presentNotificationAsync(
14  content: NotificationContentInput,
15  identifier: string = uuidv4()
16): Promise<string> {
17  if (__DEV__ && !warningMessageShown) {
18    console.warn(
19      '`presentNotificationAsync` has been deprecated in favor of using `scheduleNotificationAsync` + an explicit notification handler. Read more at https://expo.fyi/presenting-notifications-deprecated.'
20    );
21    warningMessageShown = true;
22  }
23
24  if (!NotificationPresenter.presentNotificationAsync) {
25    throw new UnavailabilityError('Notifications', 'presentNotificationAsync');
26  }
27
28  return await NotificationPresenter.presentNotificationAsync(identifier, content);
29}
30