"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var electron_1 = require("electron");
var eventType_1 = require("../lib/eventType");
var locale = require("../locale/locale");
var environment = require("./environment");
electron_1.webFrame.setZoomFactor(1.0);
electron_1.webFrame.setVisualZoomLevelLimits(1, 1);
window.locStrings = locale.LANGUAGES[locale.getCurrent()];
window.locStringsDefault = locale.LANGUAGES.en;
window.isMac = environment.platform.IS_MAC_OS;
var getSelectedWebview = function () { return document.querySelector('.Webview:not(.hide)'); };
var getWebviewById = function (id) {
    return document.querySelector(".Webview[data-accountid=\"" + id + "\"]");
};
var subscribeToMainProcessEvents = function () {
    electron_1.ipcRenderer.on(eventType_1.EVENT_TYPE.UI.SYSTEM_MENU, function (event, action) {
        var selectedWebview = getSelectedWebview();
        if (selectedWebview) {
            selectedWebview.send(action);
        }
    });
    electron_1.ipcRenderer.on(eventType_1.EVENT_TYPE.WRAPPER.RELOAD, function () {
        var webviews = document.querySelectorAll('webview');
        webviews.forEach(function (webview) { return webview.reload(); });
    });
};
var setupIpcInterface = function () {
    window.sendBadgeCount = function (count) {
        electron_1.ipcRenderer.send(eventType_1.EVENT_TYPE.UI.BADGE_COUNT, count);
    };
    window.sendDeleteAccount = function (accountID, sessionID) {
        var accountWebview = getWebviewById(accountID);
        if (!accountWebview) {
            console.error("Webview for account \"" + accountID + "\" does not exist");
            return;
        }
        console.log("Processing deletion of \"" + accountID + "\"");
        var viewInstanceId = accountWebview.getWebContents().id;
        electron_1.ipcRenderer.send(eventType_1.EVENT_TYPE.ACCOUNT.DELETE_DATA, viewInstanceId, accountID, sessionID);
    };
    window.sendLogoutAccount = function (accountId) {
        var accountWebview = getWebviewById(accountId);
        if (accountWebview) {
            accountWebview.send(eventType_1.EVENT_TYPE.ACTION.SIGN_OUT);
        }
    };
};
var addDragRegion = function () {
    if (environment.platform.IS_MAC_OS) {
        var titleBar = document.createElement('div');
        titleBar.className = 'drag-region';
        document.body.appendChild(titleBar);
    }
};
setupIpcInterface();
subscribeToMainProcessEvents();
electron_1.ipcRenderer.on(eventType_1.EVENT_TYPE.ACTION.SWITCH_ACCOUNT, function (event, accountIndex) {
    window.dispatchEvent(new CustomEvent(eventType_1.EVENT_TYPE.ACTION.SWITCH_ACCOUNT, { detail: { accountIndex: accountIndex } }));
});
window.addEventListener('DOMContentLoaded', function () {
    addDragRegion();
});
window.addEventListener('focus', function () {
    var selectedWebview = getSelectedWebview();
    if (selectedWebview) {
        selectedWebview.focus();
    }
});
//# sourceMappingURL=preload.js.map