/**
 * desktop/src/menu.ts — the native application menu.
 *
 * Built entirely from Electron's built-in roles (copy/paste/reload/zoom/…) so it
 * needs no cooperation from the (unchanged) frontend. There are deliberately no
 * page-driving custom actions here — the desktop shell adds native chrome, not
 * new terminal behaviour. The caller passes the result to Menu.setApplicationMenu.
 */
import { Menu, type MenuItemConstructorOptions } from 'electron'

export function buildAppMenu(): Menu {
  const isMac = process.platform === 'darwin'

  const template: MenuItemConstructorOptions[] = [
    ...(isMac ? [{ role: 'appMenu' } as MenuItemConstructorOptions] : []),
    {
      label: 'File',
      submenu: [isMac ? { role: 'close' } : { role: 'quit' }],
    },
    {
      label: 'Edit',
      submenu: [
        { role: 'undo' },
        { role: 'redo' },
        { type: 'separator' },
        { role: 'cut' },
        { role: 'copy' },
        { role: 'paste' },
        { role: 'selectAll' },
      ],
    },
    {
      label: 'View',
      submenu: [
        { role: 'reload' },
        { role: 'forceReload' },
        { role: 'toggleDevTools' },
        { type: 'separator' },
        { role: 'resetZoom' },
        { role: 'zoomIn' },
        { role: 'zoomOut' },
        { type: 'separator' },
        { role: 'togglefullscreen' },
      ],
    },
    {
      label: 'Window',
      submenu: [{ role: 'minimize' }, { role: 'close' }],
    },
  ]

  return Menu.buildFromTemplate(template)
}
