'use strict';

const {
	app,
	BrowserWindow, 
	Menu
} = require('electron');

const util = require('./util');

const MENU_SEPARATOR = { type: 'separator' };

module.exports = {
	init() {
		this.createMenu();
	},
	
	createMenu() {
		this.template = [
			{
				label: 'Electron Icon',
				submenu: [
					{ label: 'Quit Electron Icon', accelerator: 'CommandOrControl+Q', click: () => app.quit() }
				]
			},
			{
				label: 'File',
				submenu: [
					{ label: 'Close Window', accelerator: 'CommandOrControl+W', role: 'close' },
					MENU_SEPARATOR,
					{ label: 'Export Open Windows As PNGs', accelerator: 'CommandOrControl+P', click: () => util.captureIcons() },
					{ label: 'Create Icons From PNGs', accelerator: 'CommandOrControl+I', click: () => util.createIcons() },
					{ label: 'Export PNGs and Create Icons', accelerator: 'Shift+CommandOrControl+I', click: () => util.captureAndCreateIcons() }
				]
			},
			{
				label: 'View',
				submenu: [
					{ label: 'Reload', accelerator: 'CommandOrControl+R', click: () => BrowserWindow.getFocusedWindow().reload() },
					{ label: 'Reload All', accelerator: 'Shift+CommandOrControl+R', click: () => util.reloadWindows() }
				]
			},
			{
				label: 'Window',
				submenu: [
					{ label: 'Minimize', accelerator: 'CommandOrControl+M', role: 'minimize' }
				]
			},
			{
				label: 'Debug',
				submenu: [
					{ label: 'Log Window Bounds', accelerator: 'CommandOrControl+L', click: () => util.logWindowBounds() },
					{ label: 'Toggle DevTools', accelerator: 'Alt+CommandOrControl+I', click: () => BrowserWindow.getFocusedWindow().toggleDevTools() }
				]
			}
		];
		
		const menu = Menu.buildFromTemplate(this.template);
		Menu.setApplicationMenu(menu);
	}
};

@@ -1217,32 +1217,159 @@
 %0A%09%09%09%09submenu: %5B%0A
+%09%09%09%09%09%7B label: 'Arrange Windows', accelerator: 'CommandOrControl+A', click: () =%3E util.arrangeWindows() %7D,%0A%09%09%09%09%09MENU_SEPARATOR,%0A
 %09%09%09%09%09%7B label: 'M

Add "Arrange Windows" menu item