import { nextRequestId as e } from "./serialization.utils.mjs";
import { DeviceEventEmitter as t } from "react-native";
//#region libs/shared/sdk/src/react-native/bridge/HinkalRNWorker.ts
var n = class {
	onmessage = null;
	onerror = null;
	requestId = e();
	subscription;
	constructor(e) {
		this.variant = e, this.subscription = t.addListener("FROM_WEBVIEW_WORKER", (e) => {
			console.log("FROM_WEBVIEW_WORKER", e), !(!e || e.requestId !== this.requestId) && (e.type === "RESULT" ? this.onmessage?.({ data: e.data }) : e.type === "ERROR" && this.onerror?.(Error(e.error ?? "WebView worker error")));
		});
	}
	postMessage(e) {
		console.log("postMessage", e), t.emit("TO_WEBVIEW_WORKER", {
			__requestId: this.requestId,
			variant: this.variant,
			message: e
		});
	}
	terminate() {
		this.subscription?.remove?.(), this.subscription = null;
	}
};
//#endregion
export { n as HinkalRNWorker };
