"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get getDynamicVariants () {
        return getDynamicVariants;
    },
    get getIntersectionStyles () {
        return getIntersectionStyles;
    },
    get getResponsiveCSS () {
        return getResponsiveCSS;
    },
    get getStaticVariants () {
        return getStaticVariants;
    }
});
const getStaticVariants = (config)=>{
    if (!config.variations) {
        return [];
    }
    const res = [];
    const { variations } = config;
    // eslint-disable-next-line guard-for-in
    for(const key in variations){
        const { css } = variations[key];
        css && res.push(css);
    }
    return res;
};
const getDynamicVariants = (config)=>{
    return (props)=>{
        const res = [];
        // eslint-disable-next-line guard-for-in
        for(const key in config.variations){
            if (key in props) {
                const variant = config.variations[key];
                const css = variant[props[key]];
                // no css for { modifier: true }
                css && Array.isArray(css) ? res.push(...css) : res.push(css);
            }
        }
        return res;
    };
};
const getResponsiveCSS = (media)=>media.map(({ from, to, size })=>{
        if (!size) {
            return '';
        }
        const parts = [];
        if (from !== undefined) {
            parts.push(`(min-width: ${from}px)`);
        }
        if (to !== undefined) {
            parts.push(`(max-width: ${to}px)`);
        }
        if (!parts.length) {
            return '';
        }
        return `@media ${parts.join(' and ')} { && { ${size} } }`;
    }).filter(Boolean).join('\n');
const getIntersectionStyles = (props, intersections)=>{
    if (!intersections) {
        return [];
    }
    return intersections.reduce((styles, item)=>{
        const hasMatchStyle = Object.entries(item).filter(([key])=>key !== 'style').every(([key, value])=>props[key] === value);
        if (hasMatchStyle) {
            styles.push(item.style);
        }
        return styles;
    }, []);
};
