import PushNotification from 'react-native-push-notification';
import moment from 'moment'

export function formatDate(date) {
  var monthNames = [
    "January", "February", "March",
    "April", "May", "June", "July",
    "August", "September", "October",
    "November", "December"
  ];

  var day = date.getDate();
  var monthIndex = date.getMonth();

  return 'Today, ' + day + ' ' + monthNames[monthIndex];
}

export function scheduleLocalNotification(message, date, id, payload) {
  //message: type String
  //date: type String  format 'YYYY-MM-DD HH:mm' (NOTIFICATION_DATE_TIME_FORMAT)

  //construct the notification parameters
  // const fireDate = moment(date, NOTIFICATION_DATE_TIME_FORMAT).toDate();
  const fireDate = date
  const notification = {
    id: id, //for android cancel notification (must be stringified number)
    message,
    number: 0, //necessary for iOS cancellation (not sure why)
    date: fireDate,
    //for android only
    data: JSON.stringify(payload),
  };

  //schedule the notification
  PushNotification.localNotificationSchedule(notification);
}