import { ARRAY, BIGINT, DATE, ERROR, MAP, OBJECT, PRIMITIVE, REGEXP, SET, VOID } from "./types.js";
var env = typeof self == "object" ? self : globalThis, deserializer = (e, s) => {
	let c = (s, c) => (e.set(c, s), s), l = (u) => {
		if (e.has(u)) return e.get(u);
		let [d, f] = s[u];
		switch (d) {
			case 0:
			case -1: return c(f, u);
			case 1: {
				let e = c([], u);
				for (let s of f) e.push(l(s));
				return e;
			}
			case 2: {
				let e = c({}, u);
				for (let [s, c] of f) e[l(s)] = l(c);
				return e;
			}
			case 3: return c(new Date(f), u);
			case 4: {
				let { source: e, flags: s } = f;
				return c(new RegExp(e, s), u);
			}
			case 5: {
				let e = c(/* @__PURE__ */ new Map(), u);
				for (let [s, c] of f) e.set(l(s), l(c));
				return e;
			}
			case 6: {
				let e = c(/* @__PURE__ */ new Set(), u);
				for (let s of f) e.add(l(s));
				return e;
			}
			case 7: {
				let { name: e, message: s } = f;
				return c(new env[e](s), u);
			}
			case 8: return c(BigInt(f), u);
			case "BigInt": return c(Object(BigInt(f)), u);
			case "ArrayBuffer": return c(new Uint8Array(f).buffer, f);
			case "DataView": {
				let { buffer: e } = new Uint8Array(f);
				return c(new DataView(e), f);
			}
		}
		return c(new env[d](f), u);
	};
	return l;
};
const deserialize = (e) => deserializer(/* @__PURE__ */ new Map(), e)(0);
export { deserialize };
