//#region src/utils/domain-validation.ts
function validateOrigin(origin, allowedDomains) {
	if (!origin || allowedDomains.length === 0) return false;
	let hostname;
	let host;
	try {
		const url = new URL(origin);
		hostname = url.hostname;
		host = url.host;
	} catch {
		return false;
	}
	for (const domain of allowedDomains) {
		if (domain === "*") return true;
		const target = domain.includes(":") && !domain.startsWith("*") ? host : hostname;
		if (domain.startsWith("*.")) {
			const suffix = domain.slice(2);
			if (hostname === suffix || hostname.endsWith(`.${suffix}`)) return true;
		} else if (target === domain) return true;
	}
	return false;
}

//#endregion
export { validateOrigin };