// Notification manager for push notifications


export interface NotificationOptions {
  enabled: boolean
  adminAnnouncements: boolean
  mentions: boolean
  replies: boolean
  sound: boolean
}

export class NotificationManager {
  private static instance: NotificationManager
  private options: NotificationOptions = {
    enabled: true,
    adminAnnouncements: true,
    mentions: true,
    replies: false,
    sound: true
  }

  static getInstance(): NotificationManager {
    if (!this.instance) {
      this.instance = new NotificationManager()
    }
    return this.instance
  }

  constructor() {
    this.loadOptions()
  }

  // Load notification options from localStorage
  private loadOptions(): void {
    try {
      const stored = localStorage.getItem('notification-options')
      if (stored) {
        this.options = { ...this.options, ...JSON.parse(stored) }
      }
    } catch (error) {
      console.warn('Failed to load notification options:', error)
    }
  }

  // Save notification options to localStorage
  private saveOptions(): void {
    try {
      localStorage.setItem('notification-options', JSON.stringify(this.options))
    } catch (error) {
      console.warn('Failed to save notification options:', error)
    }
  }

  // Get current options
  getOptions(): NotificationOptions {
    return { ...this.options }
  }

  // Update options
  updateOptions(newOptions: Partial<NotificationOptions>): void {
    this.options = { ...this.options, ...newOptions }
    this.saveOptions()
  }

  // Send a test notification
  async sendTestNotification(): Promise<void> {
    if (!this.options.enabled) {
      throw new Error('Notifications are disabled')
    }

    // const payload: NotificationPayload = {
    //   title: '🧪 Test Notification',
    //   body: 'This is a test notification from Ario',
    //   tag: 'test',
    //   icon: '/apple-touch-icon.png',
    //   badge: '/apple-touch-icon.png',
    //   data: {
    //     url: window.location.origin,
    //     timestamp: Date.now()
    //   }
    // }

    // await pushService.sendNotification(payload)
  }
}

// Export singleton instance
export const notificationManager = NotificationManager.getInstance()