{"size": 2545, "ext": "js", "max_stars_repo_path": "packages/html/utils/styles.js", "max_stars_repo_name": "telerik/kendo-themes", "max_stars_repo_stars_event_min_datetime": "2018-02-07T08:22:40.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T14:38:23.000Z", "max_issues_repo_path": "packages/html/utils/styles.js", "max_issues_repo_name": "telerik/kendo-themes", "max_issues_repo_issues_event_min_datetime": "2018-02-05T09:42:04.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T15:31:10.000Z", "max_forks_repo_path": "packages/html/utils/styles.js", "max_forks_repo_name": "telerik/kendo-themes", "max_forks_repo_forks_event_min_datetime": "2018-02-09T19:56:54.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-02T10:09:41.000Z"}
{"max_stars_count": 97, "max_issues_count": 1630, "max_forks_count": 64, "avg_line_length": 19.7286821705, "max_line_length": 89, "alphanum_fraction": 0.4966601179}
import { isString, isArray, isObject } from './object';

const SPACE = ' ';

const sizeMap = {
    'small': 'sm',
    'medium': 'md',
    'large': 'lg'
};

const roundedMap = {
    'small': 'sm',
    'medium': 'md',
    'large': 'lg'
};

function lookup( map, key ) {
    let result = map[key];

    if (result) {
        return result;
    }

    return key;
}

function sizeClass( size, prefix ) {
    if ( size === 'none' ) {
        return '';
    }

    return `${prefix}-${lookup(sizeMap, size)}`;
}

function roundedClass( rounded ) {
    if ( rounded === 'none' ) {
        return '';
    }

    return `k-rounded-${lookup(roundedMap, rounded)}`;
}

function shapeClass( shape, prefix ) {
    if ( shape === 'none' ) {
        return '';
    }

    return `${prefix}-${shape}`;
}

function fillModeClass( fill, prefix ) {
    if ( fill === 'none' ) {
        return '';
    }

    return `${prefix}-${fill}`;
}

function themeColorClass( fill, color, prefix ) {
    if ( fill === 'none' || color === 'none' ) {
        return '';
    }

    return `${prefix}-${fill}-${color}`;
}

function classNames( ...args ) {

    /* eslint-disable arrow-body-style, no-nested-ternary */
    let result = new Set();
    let temp = args.flat().filter( arg => arg !== true && Boolean( arg ) );

    temp.forEach( className => {

        if ( isArray( className ) ) {
            classNames( className ).split( SPACE ).forEach( part => result.add( part ) );
            return;
        }

        if ( isString( className ) ) {
            className.split( SPACE ).forEach( part => result.add( part ) );
            return;
        }

        if ( isObject( className ) ) {
            for (let [ key, val ] of Object.entries( className )) {
                if (val === true) {
                    key.split( SPACE ).forEach( part => result.add( part ) );
                }
            }
        }
    });

    return [ ...result ].join( SPACE );
    /* eslint-enable */
}

function cssStyle( styleObj ) {
    let result = new Set();

    if ( styleObj === null || styleObj === undefined ) {
        return '';
    }

    if ( typeof styleObj === 'string' ) {
        return styleObj;
    }

    for (const [ key, value ] of Object.entries(styleObj)) {
        if ( typeof value === 'string' && value !== '' ) {
            result.add( `${key}: ${value};` );
        }
    }

    return [ ...result ].join( SPACE );
}


export {
    sizeClass,
    roundedClass,
    shapeClass,
    fillModeClass,
    themeColorClass,

    classNames,
    cssStyle,
};
