"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var electron_1 = require("electron");
var config = require("../js/config");
var environment = require("../js/environment");
var windowManager = require("../js/window-manager");
var currentEnvironment = environment.getEnvironment();
var getPrimaryWindow = function () { return windowManager.getPrimaryWindow(); };
var reloadTemplate = {
    click: function () { return getPrimaryWindow().reload(); },
    label: 'Reload',
};
var devToolsTemplate = {
    label: 'Toggle DevTools',
    submenu: [
        {
            accelerator: 'Alt+CmdOrCtrl+I',
            click: function () { return getPrimaryWindow().webContents.toggleDevTools(); },
            label: 'Sidebar',
        },
        {
            click: function () {
                var command = 'document.getElementsByTagName("webview")[0].openDevTools({mode: "detach"})';
                return getPrimaryWindow().webContents.executeJavaScript(command);
            },
            label: 'First',
        },
        {
            click: function () {
                var command = 'document.getElementsByTagName("webview")[1].openDevTools({mode: "detach"})';
                return getPrimaryWindow().webContents.executeJavaScript(command);
            },
            label: 'Second',
        },
        {
            click: function () {
                var command = 'document.getElementsByTagName("webview")[2].openDevTools({mode: "detach"})';
                return getPrimaryWindow().webContents.executeJavaScript(command);
            },
            label: 'Third',
        },
    ],
};
var createEnvironmentTemplates = function () {
    var environmentTemplate = [];
    var _loop_1 = function (key) {
        var type = environment.BackendType[key];
        environmentTemplate.push({
            checked: currentEnvironment === type,
            click: function () {
                environment.setEnvironment(type);
                getPrimaryWindow().reload();
            },
            label: environment.BackendTypeLabel[key],
            type: 'radio',
        });
    };
    for (var key in environment.BackendType) {
        _loop_1(key);
    }
    return environmentTemplate;
};
var versionTemplate = {
    label: "Wire Version " + (config.VERSION || 'Development'),
};
var chromeVersionTemplate = {
    label: "Chrome Version " + process.versions.chrome,
};
var electronVersionTemplate = {
    label: "Electron Version " + process.versions.electron,
};
var separatorTemplate = {
    type: 'separator',
};
var menuTemplate = {
    id: 'Developer',
    label: 'Developer',
    submenu: __spread([
        devToolsTemplate,
        reloadTemplate,
        separatorTemplate
    ], createEnvironmentTemplates(), [
        separatorTemplate,
        versionTemplate,
        chromeVersionTemplate,
        electronVersionTemplate,
    ]),
};
var menuItem = new electron_1.MenuItem(menuTemplate);
exports.menuItem = menuItem;
//# sourceMappingURL=developer.js.map