"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
var globalCtx = global;
var internalWindow;
if (globalCtx.GLOAL_WINDOW_OPTS) {
    internalWindow = _1.createWindow(globalCtx.GLOAL_WINDOW_OPTS);
}
else {
    internalWindow = _1.createWindow();
}
exports.window = internalWindow;
/* tslint:disable*/
var dontOverride = new Set(Object.getOwnPropertyNames(globalCtx));
var windowObj = exports.window;
windowObj.Image = _1.Image;
windowObj.HTMLCanvasElement = _1.SdlCanvas;
windowObj.CanvasRenderingContext2D = _1.SdlContext;
dontOverride.add('Image');
dontOverride.add('HTMLCanvasElement');
dontOverride.add('CanvasRenderingContext2D');
dontOverride.add('XMLHttpRequest');
var _loop_1 = function (prop) {
    if (!dontOverride.has(prop) && !prop.startsWith('_') && !prop.startsWith('constructor') && !prop.startsWith('console')) {
        var descriptor = Object.getOwnPropertyDescriptor(windowObj.__proto__, prop);
        if (descriptor) {
            if (descriptor.value) {
                globalCtx[prop] = function () {
                    var args = Array.from(arguments);
                    return windowObj[prop].apply(windowObj, args);
                };
            }
            else {
                Object.defineProperty(globalCtx, prop, {
                    get: function () {
                        return windowObj[prop];
                    },
                    set: function (val) {
                        windowObj[prop] = val;
                    }
                });
            }
        }
        else if (typeof (windowObj[prop]) === 'function') {
            globalCtx[prop] = function () {
                var args = Array.from(arguments);
                return windowObj[prop]();
            };
        }
        else {
            globalCtx[prop] = windowObj[prop];
        }
    }
};
for (var prop in windowObj) {
    _loop_1(prop);
}
/* tslint:enable*/
globalCtx.window = exports.window;
globalCtx.Image = _1.Image;
globalCtx.HTMLCanvasElement = _1.SdlCanvas;
globalCtx.CanvasRenderingContext2D = _1.SdlContext;
//# sourceMappingURL=global.js.map