// OS notifications. Electron's Notification API doesn't have a separate
// permission prompt on desktop — permission is implicit and always
// granted — so `notify:permission` is a compatibility shim that keeps
// the renderer's existing plugin-notification call-sites working
// without branching.

import { ipcMain, Notification } from 'electron';

import { CHANNELS, type NotifyArgs } from '../ipc-types';

export function register(): void {
  ipcMain.handle(CHANNELS.NOTIFY_SHOW, async (_evt, args: NotifyArgs): Promise<void> => {
    if (!Notification.isSupported()) return;
    const n = new Notification({
      title: args.title,
      body: args.body,
      silent: args.silent ?? true,
    });
    n.show();
  });

  ipcMain.handle(
    CHANNELS.NOTIFY_PERMISSION,
    async (): Promise<'granted' | 'denied' | 'default'> => 'granted',
  );
}
