/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-8ca04ef
 * Released under the MIT license.
 */

import { isSelector } from '../pipeline/index.js';
export 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]) {
                    resultStyles[key] = {
                        ...styles[key],
                        ...newStyles[key],
                    };
                }
            }
            styles = resultStyles;
        }
        pos++;
    }
    return styles;
}

        