/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-af8d194 | Cube Dev Team */
import { isSelector } from "../pipeline/index.js";

//#region src/tasty/utils/merge-styles.ts
function mergeStyles(...objects) {
	let styles = objects[0] ? { ...objects[0] } : {};
	let pos = 1;
	while (pos in objects) {
		const selectorKeys = Object.keys(styles).filter((key) => isSelector(key) && styles[key]);
		const newStyles = objects[pos];
		if (newStyles) {
			const resultStyles = {
				...styles,
				...newStyles
			};
			for (let key of selectorKeys) if (newStyles?.[key] === false) delete resultStyles[key];
			else if (newStyles?.[key] == null) resultStyles[key] = styles[key];
			else if (newStyles?.[key]) resultStyles[key] = {
				...styles[key],
				...newStyles[key]
			};
			styles = resultStyles;
		}
		pos++;
	}
	return styles;
}

//#endregion
export { mergeStyles };
//# sourceMappingURL=merge-styles.js.map