/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { comparePriority, isInteractiveAtomic, isModifierAtomic } from "../types/StateAxis.js";
//#region ../tailwind-internal/dist/packages/automated-config/dist/utils/canonicalizeStateKey.js
/*! © 2026 Yahoo, Inc. UDS Tailwind Internal v0.0.0-development */
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
function canonicalizeStateKey(atoms) {
	if (atoms.length === 0) return "rest";
	const seen = /* @__PURE__ */ new Set();
	const modifiers = [];
	const interactives = [];
	for (const atom of atoms) {
		if (seen.has(atom)) continue;
		seen.add(atom);
		if (isModifierAtomic(atom)) modifiers.push(atom);
		else if (isInteractiveAtomic(atom)) interactives.push(atom);
		else throw new Error(`canonicalizeStateKey received an unrecognized atom "${atom}". Atoms must be in MODIFIER_ATOMICS or INTERACTIVE_ATOMICS — see StateAxis.`);
	}
	modifiers.sort(comparePriority);
	interactives.sort(comparePriority);
	const ordered = [...modifiers, ...interactives];
	return ordered.length === 0 ? "rest" : ordered.join("&");
}
/**
* Splits a canonical (or legacy) state key into its atomic parts.
* `'rest'` and `''` produce an empty array.
*/
function splitStateKey(stateKey) {
	if (!stateKey || stateKey === "rest") return [];
	return stateKey.split("&");
}
//#endregion
export { canonicalizeStateKey, splitStateKey };
