"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.th = void 0;
exports.extendTheme = extendTheme;
exports.omitThemingProps = omitThemingProps;
exports.useStyleConfig = useStyleConfig;
exports.useTh = useTh;
exports.useTheme = useTheme;
const styled_components_1 = require("@xstyled/styled-components");
const react_1 = require("react");
const styled_components_2 = require("styled-components");
const theme_1 = __importDefault(require("../theme"));
const utils_1 = require("../utils");
/** Merges provided theme extensions and overrides with default VUI theme. */
function extendTheme(extensions) {
    return (0, utils_1.merge)(theme_1.default, extensions);
}
/** Removes specific theming keys from the given props. */
function omitThemingProps(props) {
    const { size, variant } = props, rest = __rest(props, ["size", "variant"]); // eslint-disable-line @typescript-eslint/no-unused-vars
    return rest;
}
/** Re-export of xstyled 'th' with custom typing and screen getter. */
const th = styled_components_1.th;
exports.th = th;
th.screen = (0, styled_components_1.themeGetter)({
    name: 'screen',
    key: 'screens',
    compose: styled_components_1.getPx,
});
/**
 * Combines baseStyle, size and variant styling from a component's theme configuration.
 * @param component - name of any component configured in the theme
 * @param props - props object of the given component
 */
function useStyleConfig(component, props = {}) {
    var _a, _b, _c, _d;
    const theme = useTheme();
    const { baseStyle, defaultProps, parts = [], sizes, variants } = (_a = theme === null || theme === void 0 ? void 0 : theme.components[component]) !== null && _a !== void 0 ? _a : {};
    const mergedProps = Object.assign(Object.assign({}, props), { colorScheme: (_b = props === null || props === void 0 ? void 0 : props.colorScheme) !== null && _b !== void 0 ? _b : defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.colorScheme, size: (_c = props === null || props === void 0 ? void 0 : props.size) !== null && _c !== void 0 ? _c : defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.size, variant: (_d = props === null || props === void 0 ? void 0 : props.variant) !== null && _d !== void 0 ? _d : defaultProps === null || defaultProps === void 0 ? void 0 : defaultProps.variant });
    const { colorScheme, size, variant } = mergedProps;
    return (0, react_1.useMemo)(() => {
        var _a, _b, _c;
        const baseStyles = (_a = (0, utils_1.runIfFn)(baseStyle, mergedProps)) !== null && _a !== void 0 ? _a : {};
        const sizeStyles = (_b = (0, utils_1.runIfFn)(sizes === null || sizes === void 0 ? void 0 : sizes[size], mergedProps)) !== null && _b !== void 0 ? _b : {};
        const variantStyles = (_c = (0, utils_1.runIfFn)(variants === null || variants === void 0 ? void 0 : variants[variant], mergedProps)) !== null && _c !== void 0 ? _c : {};
        let styles = {};
        if (parts.length > 0)
            parts.forEach((part) => {
                var _a, _b, _c;
                styles[part] = (0, utils_1.merge)((_a = baseStyles[part]) !== null && _a !== void 0 ? _a : {}, (_b = sizeStyles[part]) !== null && _b !== void 0 ? _b : {}, (_c = variantStyles[part]) !== null && _c !== void 0 ? _c : {});
            });
        else
            styles = (0, utils_1.merge)(baseStyles, sizeStyles, variantStyles);
        return styles;
    }, [colorScheme, size, variant]);
}
/** Returns theme value at the given path. */
function useTh(path, defaultValue) {
    const theme = useTheme();
    return th(path, defaultValue)({ theme });
}
/** Returns the theme object with extensions. */
function useTheme() {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    return (0, styled_components_2.useTheme)();
}
//# sourceMappingURL=theme.js.map