export async function requestNotificationPermission() {
  if (!('Notification' in window)) {
    console.log('This browser does not support notifications');
    return false;
  }

  if (Notification.permission === 'granted') {
    return true;
  }

  if (Notification.permission !== 'denied') {
    const permission = await Notification.requestPermission();
    return permission === 'granted';
  }

  return false;
}

export function sendNotification(title, options = {}) {
  if (Notification.permission === 'granted') {
    new Notification(title, {
      icon: '/logo.png',
      badge: '/badge.png',
      ...options
    });
  }
}

export function notifyHighScoreFlow(flow) {
  if (flow.rocketScore >= 5) {
    sendNotification('🚀🚀🚀 HIGH SCORE FLOW', {
      body: `${flow.Symbol}: ${flow.rocketDisplay}\nPremium: $${(flow.premium_num / 1000).toFixed(0)}K`,
      tag: `flow-${flow.Symbol}`,
      requireInteraction: true,
    });
  }
}

