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

import { parseStyle } from '../utils/styles.js';
function setCSSValue(styles, styleName, presetName, isPropOnly = false) {
    styles[`--${styleName}`] = (() => {
        if (presetName === 'inherit') {
            return 'inherit';
        }
        const defaultValue = `var(--default-${styleName}, ${styleName === 'font-family'
            ? 'var(--font, NonexistentFontName)'
            : 'inherit'})`;
        const fontSuffix = styleName === 'font-family' ? ', var(--font, sans-serif)' : '';
        if (presetName === 'default') {
            return `${defaultValue}${fontSuffix}`;
        }
        else {
            return `var(--${presetName}-${styleName}, ${defaultValue})${fontSuffix}`;
        }
    })();
    if (!isPropOnly) {
        styles[styleName] = styles[`--${styleName}`];
    }
}
export function presetStyle({ preset, fontSize, lineHeight, textTransform, letterSpacing, fontWeight, fontStyle, font, }) {
    if (!preset)
        return;
    if (preset === true)
        preset = '';
    const processed = parseStyle(preset);
    let { mods } = processed.groups[0] ?? { mods: [] };
    const isStrong = mods.includes('strong');
    const isItalic = mods.includes('italic');
    const isIcon = mods.includes('icon');
    const isTight = mods.includes('tight');
    mods = mods.filter((mod) => mod !== 'bold' && mod !== 'italic' && mod !== 'icon' && mod !== 'tight');
    const name = mods[0] || 'default';
    const styles = {};
    if (!fontSize) {
        setCSSValue(styles, 'font-size', name);
    }
    if (!lineHeight) {
        setCSSValue(styles, 'line-height', name);
    }
    if (!letterSpacing) {
        setCSSValue(styles, 'letter-spacing', name);
    }
    if (!fontWeight) {
        setCSSValue(styles, 'font-weight', name);
    }
    if (!fontStyle) {
        setCSSValue(styles, 'font-style', name);
    }
    if (!textTransform) {
        setCSSValue(styles, 'text-transform', name);
    }
    if (!font) {
        setCSSValue(styles, 'font-family', name);
    }
    setCSSValue(styles, 'bold-font-weight', name, true);
    setCSSValue(styles, 'icon-size', name, true);
    if (isStrong) {
        styles['font-weight'] = 'var(--bold-font-weight)';
    }
    if (isItalic) {
        styles['font-style'] = 'italic';
    }
    if (isIcon) {
        styles['font-size'] = 'var(--icon-size)';
        styles['line-height'] = 'var(--icon-size)';
    }
    if (isTight) {
        styles['line-height'] = 'var(--font-size)';
    }
    return styles;
}
presetStyle.__lookupStyles = [
    'preset',
    'fontSize',
    'lineHeight',
    'letterSpacing',
    'textTransform',
    'fontWeight',
    'fontStyle',
    'font',
];

        