import clsx from 'clsx';
/**
 * Build a variant-aware class generator.
 *
 * The returned function accepts the variant selection plus an optional
 * `class` / `className` escape hatch and returns the combined Tailwind
 * class string. Compound variants run after the base + per-variant
 * classes, so they take precedence when the Tailwind ordering matters.
 */
export function cv(base, config) {
    return function variantClass(props) {
        const selected = { ...config.defaultVariants, ...props };
        const variantClasses = [];
        for (const [key, valuesMap] of Object.entries(config.variants)) {
            const value = selected[key];
            if (value === undefined || value === null)
                continue;
            const cls = valuesMap[value];
            if (cls)
                variantClasses.push(cls);
        }
        const compoundClasses = [];
        if (config.compoundVariants) {
            for (const compound of config.compoundVariants) {
                const { class: cClass, className: _cn, ...match } = compound;
                const matches = Object.entries(match).every(([k, v]) => {
                    const current = selected[k];
                    if (Array.isArray(v))
                        return v.includes(current);
                    return current === v;
                });
                if (matches && cClass)
                    compoundClasses.push(cClass);
            }
        }
        return clsx(base, ...variantClasses, ...compoundClasses, (props?.class ?? props?.className));
    };
}
//# sourceMappingURL=cv.js.map