import { defaultValues_exports } from "./config/dist/esm/defaultValues/index.mjs";

//#region ../react-intlayer/dist/esm/@intlayer/core/dist/esm/getStorageAttributes.mjs
/**
* Creates a cookie entry with default values for missing attributes
*/
const createCookieEntry = (options) => {
	const { name, path, expires, domain, secure, sameSite, httpOnly } = options ?? {};
	return {
		name: name ?? defaultValues_exports.Routing.COOKIE_NAME,
		attributes: {
			path,
			expires,
			domain,
			secure,
			sameSite,
			httpOnly
		}
	};
};
/**
* Creates a web storage entry (localStorage or sessionStorage) with default name
*/
const createWebStorageEntry = (options) => {
	const { name } = options ?? {};
	return { name: name ?? defaultValues_exports.Routing.LOCALE_STORAGE_NAME };
};
/**
* Creates a header entry with default name
*/
const createHeaderEntry = (options) => {
	const { name } = options ?? {};
	return { name: name ?? defaultValues_exports.Routing.HEADER_NAME };
};
/**
* Determines if a storage entry is a cookie based on its properties
*/
const isCookieEntry = (entry) => {
	return entry.type === "cookie" || "sameSite" in entry || "httpOnly" in entry || "secure" in entry;
};
/**
* Determines the storage type from a string literal
*/
const isStorageType = (value) => {
	return value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
};
/**
* Processes a single storage entry and returns the appropriate storage attributes
*/
const processStorageEntry = (entry) => {
	if (typeof entry === "string") {
		if (!isStorageType(entry)) return {
			cookies: [],
			localStorage: [],
			sessionStorage: [],
			headers: []
		};
		if (entry === "cookie") return { cookies: [createCookieEntry()] };
		if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
		if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
		if (entry === "header") return { headers: [createHeaderEntry()] };
	}
	if (typeof entry === "object" && entry !== null) {
		const typedEntry = entry;
		if (isCookieEntry(typedEntry)) return { cookies: [createCookieEntry(typedEntry)] };
		if ("type" in typedEntry && typedEntry.type === "localStorage") {
			const { name: name$1,...rest$1 } = typedEntry;
			return { localStorage: [createWebStorageEntry({
				name: name$1,
				...rest$1
			})] };
		}
		if ("type" in typedEntry && typedEntry.type === "sessionStorage") {
			const { name: name$1,...rest$1 } = typedEntry;
			return { sessionStorage: [createWebStorageEntry({
				name: name$1,
				...rest$1
			})] };
		}
		if ("type" in typedEntry && typedEntry.type === "header") {
			const { name: name$1,...rest$1 } = typedEntry;
			return { headers: [createHeaderEntry({
				name: name$1,
				...rest$1
			})] };
		}
		const { name,...rest } = typedEntry;
		return { localStorage: [createWebStorageEntry({
			name,
			...rest
		})] };
	}
	return {
		cookies: [],
		localStorage: [],
		sessionStorage: [],
		headers: []
	};
};
/**
* Merges multiple partial storage attributes into a single result
*/
const mergeStorageAttributes = (accumulated, partial) => {
	return {
		cookies: [...accumulated.cookies, ...partial.cookies ?? []],
		localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
		sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
		headers: [...accumulated.headers, ...partial.headers ?? []]
	};
};
/**
* Extracts and normalizes storage configuration into separate arrays for each storage type
*
* @param options - The storage configuration from IntlayerConfig
* @returns An object containing arrays for cookies, localStorage, and sessionStorage
*/
const getStorageAttributes = (options) => {
	const emptyResult = {
		cookies: [],
		localStorage: [],
		sessionStorage: [],
		headers: []
	};
	if (options === false || options === void 0) return emptyResult;
	if (Array.isArray(options)) return options.reduce((acc, entry) => {
		return mergeStorageAttributes(acc, processStorageEntry(entry));
	}, emptyResult);
	return mergeStorageAttributes(emptyResult, processStorageEntry(options));
};

//#endregion
export { getStorageAttributes };
//# sourceMappingURL=getStorageAttributes.mjs.map