"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
const STRING_1 = require("../../../constant/STRING");
const element = document.createElement('div');
element.style.display = 'none';
element.id = __1.SYSTEM_EXTENSION_ID;
document.body.appendChild(element);
element.addEventListener('message', function (event) {
    const { detail } = event;
    const { type, id, data } = detail;
    if (type === 'send') {
        const { type: _type, data: _data } = data;
        switch (_type) {
            case STRING_1.CALL:
                chrome.runtime.sendMessage(_data, (data) => {
                    if (chrome.runtime.lastError) {
                        const err = chrome.runtime.lastError.message.toLowerCase();
                        (0, __1.dispatchExtensionEvent)('callback', id, { err });
                    }
                    else {
                        (0, __1.dispatchExtensionEvent)('callback', id, data);
                    }
                });
                break;
            default:
                (0, __1.dispatchExtensionEvent)('callback', id, { err: 'not supported' });
        }
    }
    else {
        // ignore "callback"
    }
}, false);
//# sourceMappingURL=content.js.map