"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapWindow = wrapWindow;
const _1 = require("../Class/$");
const Value_1 = require("./Value");
function wrapWindow(window, system) {
    return new (class Window_ extends _1.$ {
        constructor() {
            super(...arguments);
            this.__ = ['W'];
        }
        async send(data) {
            window.postMessage(data, '*');
        }
        postMessage(data, target) {
            window.postMessage(data, target, [data]);
        }
        addListener(event, listener) {
            const _listener = (event) => {
                if (event.source === window) {
                    const data = (0, Value_1.wrapValue)(event.data, system);
                    listener(data);
                }
            };
            window.addEventListener(event, _listener);
            return () => {
                window.removeEventListener(event, _listener);
            };
        }
    })(system);
}
//# sourceMappingURL=Window.js.map