{"size": 3086, "ext": "js", "max_stars_repo_path": "shell/menu.config.js", "max_stars_repo_name": "mrfoe7/reqlpro", "max_stars_repo_stars_event_min_datetime": "2017-11-29T23:10:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T07:57:30.000Z", "max_issues_repo_path": "shell/menu.config.js", "max_issues_repo_name": "mrfoe7/reqlpro", "max_issues_repo_issues_event_min_datetime": "2017-11-28T16:22:22.000Z", "max_issues_repo_issues_event_max_datetime": "2020-05-13T21:00:07.000Z", "max_forks_repo_path": "shell/menu.config.js", "max_forks_repo_name": "mrfoe7/reqlpro", "max_forks_repo_forks_event_min_datetime": "2018-02-12T00:08:18.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-11T19:37:19.000Z"}
{"max_stars_count": 31, "max_issues_count": 9, "max_forks_count": 19, "avg_line_length": 20.038961039, "max_line_length": 85, "alphanum_fraction": 0.4837977965}
'use strict';

const { createNewWindow, launchFeedbackPopup } = require('./main.electron-utils.js');
const { Menu, shell } = require('electron');

function createMenu() {

  // Menu Option
  let quitMenuOption = {
    label: 'Quit',
    accelerator: 'CmdOrCtrl+W',
    selector: 'terminate:',
    role: 'close'
  };

  // Menu Option Alternative
  if (process.platform === 'darwin') {
    quitMenuOption = {
      label: 'Quit',
      accelerator: 'Cmd+Q',
      selector: 'terminate:'
    }
  }

  // Submenus
  const mainSubMenu = {
    label: 'ReqlPro (Beta)',
    submenu: [
      {
        label: 'About ReqlPro (Beta)',
        click: function() {
          createNewWindow('new-window', {
            path: '/about.html',
            width: 300,
            height: 200
          });
        }
      },
      {
        label: 'New Window',
        accelerator: 'Command+N',
        click: function() {
          createNewWindow('new-window', {});
        }
      },
      {
        label: 'Hide ReqlPro',
        accelerator: 'Command+H',
        selector: 'hide:'
      },
      {
        label: 'Hide Others',
        accelerator: 'Command+Shift+H',
        selector: 'hideOtherApplications:'
      },
      {
        label: 'Show All',
        selector: 'unhideAllApplications:'
      },
      {
        type: 'separator'
      },
    ]
  };
  const editSubMenu = {
    label: 'Edit',
    submenu: [
      {
        label: 'Undo',
        accelerator: 'Command+Z',
        selector: 'undo:'
      },
      {
        label: 'Redo',
        accelerator: 'Shift+Command+Z',
        selector: 'redo:'
      },
      {
        type: 'separator'
      },
      {
        label: 'Cut',
        accelerator: 'Command+X',
        selector: 'cut:'
      },
      {
        label: 'Copy',
        accelerator: 'Command+C',
        selector: 'copy:'
      },
      {
        label: 'Paste',
        accelerator: 'Command+V',
        selector: 'paste:'
      },
      {
        label: 'Select All',
        accelerator: 'Command+A',
        selector: 'selectAll:'
      }
    ]
  };
  const windowWubMenu = {
    label: 'Window',
    submenu: [
      {
        label: 'Minimize',
        accelerator: 'Command+M',
        selector: 'performMiniaturize:'
      },
      {
        label: 'Close',
        accelerator: 'Command+W',
        selector: 'performClose:'
      },
      {
        type: 'separator'
      },
      {
        label: 'Bring All to Front',
        selector: 'arrangeInFront:'
      }
    ]
  };
  const helpSubMenu = {
    label: 'Help',
    submenu: [
      {
        label: 'Help Center',
        click: function() {
          shell.openExternal('http://reqlpro.com/support');
        }
      },
      {
        label: 'Feedback',
        click: function() {
          launchFeedbackPopup();
          // HS.beacon.open();
        }
      }
    ]
  };

  const template = [mainSubMenu, editSubMenu, windowWubMenu, helpSubMenu];

  mainSubMenu.submenu.push(quitMenuOption);

  return Menu.buildFromTemplate(template);
}

module.exports = {
  createMenu: createMenu
};
