import { __assign, __rest } from "tslib";
import React, { createContext, useContext } from 'react';
import { cn } from '../../utils/bem';
import { presetDefault } from './presets/presetDefault';
export { presetDefault } from './presets/presetDefault';
export var cnTheme = cn('Theme');
export function generateThemeClassNames(preset) {
    return {
        color: {
            primary: cnTheme({ color: preset.color.primary })
        },
        control: cnTheme({ control: preset.control }),
        font: cnTheme({ font: preset.font }),
        size: cnTheme({ size: preset.size }),
        space: cnTheme({ space: preset.space })
    };
}
var defaultContextValue = {
    theme: presetDefault,
    themeClassNames: generateThemeClassNames(presetDefault)
};
export var ThemeContext = createContext(defaultContextValue);
export var Theme = React.forwardRef(function (props, ref) {
    var className = props.className, children = props.children, _a = props.preset, preset = _a === void 0 ? presetDefault : _a, otherProps = __rest(props, ["className", "children", "preset"]);
    var mods = __assign(__assign({}, preset), { color: preset.color.primary });
    var themeClassNames = generateThemeClassNames(preset);
    return (React.createElement(ThemeContext.Provider, { value: { theme: preset, themeClassNames: themeClassNames } },
        React.createElement("div", __assign({}, otherProps, { ref: ref, className: cnTheme(mods, [className]) }), children)));
});
export function useTheme() {
    return useContext(ThemeContext);
}
