//#region src/consent/index.ts
var e = {
	visitorIdKey: "tf_visitor_id",
	consentKey: "tf_consent",
	apiBasePath: "/api/v1/consent",
	cookieMaxAge: 31536e3
};
function t(t = {}) {
	let n = {
		...e,
		...t
	};
	function r() {
		return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
			let t = Math.random() * 16 | 0;
			return (e === "x" ? t : t & 3 | 8).toString(16);
		});
	}
	function i() {
		let e = localStorage.getItem(n.visitorIdKey);
		if (e !== null && e !== "") return e;
		let t = r();
		return localStorage.setItem(n.visitorIdKey, t), document.cookie = `${n.visitorIdKey}=${t}; path=/; max-age=${String(n.cookieMaxAge)}; SameSite=Lax`, t;
	}
	function a() {
		let e = localStorage.getItem(n.consentKey);
		if (e !== null && e !== "") try {
			return JSON.parse(e);
		} catch {
			return null;
		}
		return null;
	}
	function o(e) {
		localStorage.setItem(n.consentKey, JSON.stringify(e));
	}
	async function s() {
		try {
			let e = await fetch(`${n.apiBasePath}/categories`);
			if (!e.ok) throw Error("Failed to fetch categories");
			return (await e.json()).categories;
		} catch (e) {
			return console.error("Error fetching consent categories:", e), [];
		}
	}
	async function c() {
		try {
			let e = await fetch(n.apiBasePath, { headers: { "X-Visitor-ID": i() } });
			if (!e.ok) throw Error("Failed to check consent");
			return (await e.json()).consent;
		} catch (e) {
			return console.error("Error checking consent:", e), null;
		}
	}
	async function l(e, t = "banner") {
		try {
			let r = i();
			if (!(await fetch(n.apiBasePath, {
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					"X-Visitor-ID": r
				},
				body: JSON.stringify({
					visitor_id: r,
					categories: e,
					consent_method: t
				})
			})).ok) throw Error("Failed to save consent");
			return o(e), !0;
		} catch (e) {
			return console.error("Error saving consent:", e), !1;
		}
	}
	function u() {
		return {
			essential: !0,
			performance: !0,
			analytics: !0,
			advertising: !0,
			social_media: !0
		};
	}
	function d() {
		return {
			essential: !0,
			performance: !1,
			analytics: !1,
			advertising: !1,
			social_media: !1
		};
	}
	return {
		generateVisitorId: r,
		getVisitorId: i,
		getStoredConsent: a,
		setStoredConsent: o,
		fetchCategories: s,
		checkConsent: c,
		saveConsent: l,
		acceptAll: u,
		rejectAll: d,
		config: n
	};
}
var n = null;
function r(e) {
	return n ??= t(e), n;
}
var i = () => r().generateVisitorId(), a = () => r().getVisitorId(), o = () => r().getStoredConsent(), s = (e) => {
	r().setStoredConsent(e);
}, c = () => r().fetchCategories(), l = () => r().checkConsent(), u = (e, t) => r().saveConsent(e, t), d = () => r().acceptAll(), f = () => r().rejectAll();
//#endregion
export { d as acceptAll, l as checkConsent, t as createConsentManager, c as fetchCategories, i as generateVisitorId, r as getDefaultConsentManager, o as getStoredConsent, a as getVisitorId, f as rejectAll, u as saveConsent, s as setStoredConsent };

//# sourceMappingURL=index.js.map