"use strict";
exports.__esModule = true;
exports.useThemeVars = exports.defaultVars = void 0;
var tslib_1 = require("tslib");
// @ts-nocheck
var react_1 = require("react");
var Theme_1 = require("../../components/Theme/Theme");
var helpers_1 = require("./helpers");
var helpers_2 = require("./helpers");
(0, tslib_1.__createBinding)(exports, helpers_2, "defaultVars");
var getVars = function (cssVars, element) {
    var vars = {};
    var style = getComputedStyle(element);
    for (var i = 0; i < cssVars.length; i++) {
        vars[cssVars[i]] = style.getPropertyValue(cssVars[i]).trim();
    }
    return vars;
};
var addElement = function (mods) {
    var element = document.createElement('div');
    element.setAttribute('class', (0, Theme_1.cnTheme)(mods));
    document.body.append(element);
    return element;
};
var useThemeVars = function (options) {
    var variables = (options === null || options === void 0 ? void 0 : options.vars) || helpers_1.defaultVars;
    var theme = (0, Theme_1.useTheme)().theme;
    return (0, react_1.useMemo)(function () {
        var elementPrimary = addElement((0, tslib_1.__assign)((0, tslib_1.__assign)({}, theme), { color: theme.color.primary }));
        var themeVars = {
            color: {
                primary: getVars(variables.color.primary, elementPrimary)
            },
            control: getVars(variables.control, elementPrimary),
            font: getVars(variables.font, elementPrimary),
            size: getVars(variables.size, elementPrimary),
            space: getVars(variables.space, elementPrimary),
            shadow: getVars(variables.shadow, elementPrimary)
        };
        document.body.removeChild(elementPrimary);
        return themeVars;
    }, (0, tslib_1.__spreadArray)([
        theme.color.primary,
        theme.control,
        theme.font,
        theme.size,
        theme.space
    ], (0, tslib_1.__read)(((options === null || options === void 0 ? void 0 : options.deps) ? options.deps : [])), false));
};
exports.useThemeVars = useThemeVars;
