import { t as __exportAll } from "./chunk-ClPoSABd.mjs";
import { i as matchPattern, n as interpolateDestination, t as compilePattern } from "./patterns-CrCYkMBb.mjs";

//#region src/redirects/cache.ts
var cache_exports = /* @__PURE__ */ __exportAll({
	getCachedPatternRules: () => getCachedPatternRules,
	invalidateRedirectCache: () => invalidateRedirectCache,
	matchCachedPatterns: () => matchCachedPatterns,
	setCachedPatternRules: () => setCachedPatternRules
});
/**
* Cached pattern rules with compiled regexes.
* null = not yet populated, array = cached.
*/
let cachedPatternRules = null;
/**
* Invalidate the cached redirect pattern rules.
* Call when redirects are created, updated, or deleted.
*/
function invalidateRedirectCache() {
	cachedPatternRules = null;
}
/**
* Get the cached compiled pattern rules, or null if the cache is cold.
*/
function getCachedPatternRules() {
	return cachedPatternRules;
}
/**
* Populate the pattern rules cache from a list of enabled pattern redirects.
*/
function setCachedPatternRules(redirects) {
	cachedPatternRules = redirects.map((r) => ({
		redirect: r,
		compiled: compilePattern(r.source)
	}));
	return cachedPatternRules;
}
/**
* Match a path against the cached pattern rules.
* Returns the resolved destination and matching redirect, or null.
*/
function matchCachedPatterns(rules, pathname) {
	for (const { redirect, compiled } of rules) {
		const params = matchPattern(compiled, pathname);
		if (params) return {
			redirect,
			destination: interpolateDestination(redirect.destination, params)
		};
	}
	return null;
}

//#endregion
export { setCachedPatternRules as a, matchCachedPatterns as i, getCachedPatternRules as n, invalidateRedirectCache as r, cache_exports as t };
//# sourceMappingURL=cache-E3Dts-yT.mjs.map