import { isDevelopment as e } from "../constants/vite.constants.mjs";
import { chainIds as t } from "../constants/chains.constants.mjs";
import { WorkerFactory as n } from "./workerFactory.mjs";
//#region libs/shared/common/src/webworker/performTaskWithWorker.ts
var r = async (r) => {
	let i = await n.getWebWorker(r.type);
	return new Promise((n, a) => {
		let o = {};
		if (typeof window < "u" && window.location) {
			let { origin: e, protocol: t, host: n, port: r, hostname: i, href: a } = window.location;
			o = {
				origin: e,
				protocol: t,
				host: n,
				port: r,
				hostname: i,
				href: a
			};
		}
		i.onMessage((e) => {
			n(e), i.terminate();
		}), i.onError((e) => {
			a(e), i.terminate();
		});
		let s = {
			payload: r.payload,
			metadata: {
				hostLocation: o,
				constants: {
					chains: { chainIds: t },
					isDevelopment: e
				}
			}
		};
		i.postMessage(s);
	});
};
//#endregion
export { r as performTaskWithWorker };
