"use strict";
(() => {
  // src/constant/STRING.ts
  var CALL = "call";

  // src/client/extension/index.ts
  var SYSTEM_EXTENSION_ID = "___SYSTEM__EXTENSION___";
  function getExtensionElement() {
    return document.getElementById(SYSTEM_EXTENSION_ID);
  }
  function dispatchExtensionEvent(type, id, data) {
    const element2 = getExtensionElement();
    element2.dispatchEvent(
      new CustomEvent("message", {
        detail: { type, id, data }
      })
    );
  }

  // src/client/extension/src/content.ts
  var element = document.createElement("div");
  element.style.display = "none";
  element.id = 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 CALL:
            chrome.runtime.sendMessage(_data, (data2) => {
              if (chrome.runtime.lastError) {
                const err = chrome.runtime.lastError.message.toLowerCase();
                dispatchExtensionEvent("callback", id, { err });
              } else {
                dispatchExtensionEvent("callback", id, data2);
              }
            });
            break;
          default:
            dispatchExtensionEvent("callback", id, { err: "not supported" });
        }
      } else {
      }
    },
    false
  );
  var content_default = null;
})();
//# sourceMappingURL=content.js.map
