var __async = (__this, __arguments, generator) => {
  return new Promise((resolve, reject) => {
    var fulfilled = (value) => {
      try {
        step(generator.next(value));
      } catch (e) {
        reject(e);
      }
    };
    var rejected = (value) => {
      try {
        step(generator.throw(value));
      } catch (e) {
        reject(e);
      }
    };
    var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
    step((generator = generator.apply(__this, __arguments)).next());
  });
};
import Buffer2 from "buffer";
import processBrowser from "process/browser";
import console from "console-browserify";
var buffer = {
  Buffer: Buffer2
};
const workerMessageTypes = {
  SAVE_CONTEXT: "save-context",
  GET_CONTEXT: "get-context"
};
function sendToWorker(type, payload) {
  return __async(this, null, function* () {
    return new Promise((resolve, reject) => {
      chrome.runtime.sendMessage({ type, payload }, (response) => {
        if (response.error) {
          reject(response.error);
        } else {
          resolve(response);
        }
      });
    });
  });
}
function getPlaygroundUrl(cacheContextId) {
  return chrome.runtime.getURL(
    `./pages/playground.html?cache_context_id=${cacheContextId}`
  );
}
function activeTabId() {
  return __async(this, null, function* () {
    return new Promise((resolve, reject) => {
      chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
        var _a;
        if ((_a = tabs == null ? void 0 : tabs[0]) == null ? void 0 : _a.id) {
          resolve(tabs[0].id);
        } else {
          reject(new Error("No active tab found"));
        }
      });
    });
  });
}
function currentWindowId() {
  return __async(this, null, function* () {
    return new Promise((resolve, reject) => {
      chrome.windows.getCurrent((window) => {
        if (window == null ? void 0 : window.id) {
          resolve(window.id);
        } else {
          reject(new Error("No active window found"));
        }
      });
    });
  });
}
function getExtensionVersion() {
  return chrome.runtime.getManifest().version;
}
function getTabInfo(tabId) {
  return __async(this, null, function* () {
    return yield chrome.tabs.get(tabId);
  });
}
export {
  activeTabId,
  currentWindowId,
  getExtensionVersion,
  getPlaygroundUrl,
  getTabInfo,
  sendToWorker,
  workerMessageTypes
};
