"use strict";
exports.__esModule = true;
exports.useTheme = exports.Theme = exports.ThemeContext = exports.generateThemeClassNames = exports.cnTheme = exports.presetDefault = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importStar)(require("react"));
var bem_1 = require("../../utils/bem");
var presetDefault_1 = require("./presets/presetDefault");
var presetDefault_2 = require("./presets/presetDefault");
(0, tslib_1.__createBinding)(exports, presetDefault_2, "presetDefault");
exports.cnTheme = (0, bem_1.cn)('Theme');
function generateThemeClassNames(preset) {
    return {
        color: {
            primary: (0, exports.cnTheme)({ color: preset.color.primary })
        },
        control: (0, exports.cnTheme)({ control: preset.control }),
        font: (0, exports.cnTheme)({ font: preset.font }),
        size: (0, exports.cnTheme)({ size: preset.size }),
        space: (0, exports.cnTheme)({ space: preset.space })
    };
}
exports.generateThemeClassNames = generateThemeClassNames;
var defaultContextValue = {
    theme: presetDefault_1.presetDefault,
    themeClassNames: generateThemeClassNames(presetDefault_1.presetDefault)
};
exports.ThemeContext = (0, react_1.createContext)(defaultContextValue);
exports.Theme = react_1["default"].forwardRef(function (props, ref) {
    var className = props.className, children = props.children, _a = props.preset, preset = _a === void 0 ? presetDefault_1.presetDefault : _a, otherProps = (0, tslib_1.__rest)(props, ["className", "children", "preset"]);
    var mods = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, preset), { color: preset.color.primary });
    var themeClassNames = generateThemeClassNames(preset);
    return (react_1["default"].createElement(exports.ThemeContext.Provider, { value: { theme: preset, themeClassNames: themeClassNames } },
        react_1["default"].createElement("div", (0, tslib_1.__assign)({}, otherProps, { ref: ref, className: (0, exports.cnTheme)(mods, [className]) }), children)));
});
function useTheme() {
    return (0, react_1.useContext)(exports.ThemeContext);
}
exports.useTheme = useTheme;
