"use strict";
/**
 * Style utility functions for BFUI
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSpacing = getSpacing;
exports.classNames = classNames;
exports.getFocusStyles = getFocusStyles;
exports.getVariantStyle = getVariantStyle;
exports.getEdgeSpacing = getEdgeSpacing;
const react_1 = require("@chakra-ui/react");
/**
 * Spacing utility to convert spacing values to CSS values
 * @param space The spacing value (theme token or direct value)
 * @returns The CSS value for spacing
 */
function getSpacing(space) {
    if (typeof space === 'number') {
        return `${space}px`;
    }
    if (typeof space === 'string') {
        // If it's a direct value (with units), return it
        if (space.includes('px') ||
            space.includes('em') ||
            space.includes('rem') ||
            space.includes('%')) {
            return space;
        }
        // If it's a theme token, look it up
        const themeSpace = react_1.theme.space;
        const themeSpacing = themeSpace[space];
        return themeSpacing !== undefined ? themeSpacing : space;
    }
    return space;
}
/**
 * Combines class names, filtering out falsy values
 * @param classes Array of class names or conditions
 * @returns Combined class string
 */
function classNames(...classes) {
    return classes.filter(Boolean).join(' ');
}
/**
 * Creates a style object for applying focus styles
 * @returns Style object for focus state
 */
function getFocusStyles() {
    return {
        boxShadow: 'outline',
        outline: 'none',
    };
}
/**
 * Get a style based on a variant
 * @param styles Object with styles for each variant
 * @param variant Current variant
 * @param defaultVariant Default variant to use if variant is not found
 * @returns The style for the variant
 */
function getVariantStyle(styles, variant, defaultVariant) {
    return (variant in styles ? styles[variant] : styles[defaultVariant]);
}
/**
 * Get spacing from a variety of input types
 * @param spacing The spacing (number, string, or object for responsive)
 * @returns An object with CSS properties for the spacing
 */
function getEdgeSpacing(spacing, property = 'padding') {
    if (typeof spacing === 'number' || typeof spacing === 'string') {
        return {
            [property]: getSpacing(spacing),
        };
    }
    // Handle responsive object
    // Cast Chakra theme breakpoints so we can index dynamically
    const bps = react_1.theme.breakpoints;
    return Object.entries(spacing).reduce((acc, [breakpoint, value]) => {
        if (breakpoint === 'base') {
            acc[property] = getSpacing(value);
        }
        else {
            // Look up breakpoint value or default to '0px'
            const minWidth = bps[breakpoint] || '0px';
            acc[`@media screen and (min-width: ${minWidth})`] = {
                [property]: getSpacing(value),
            };
        }
        return acc;
    }, {});
}
//# sourceMappingURL=styleUtils.js.map