function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { forwardRef } from "react";
import { applySpacing } from "../../mixins/applySpacing";
import { cx } from "../../utils";
import { classes } from "./tokens";
export var typographyRootCompose = function typographyRootCompose(defaultArgs) {
    return function(Root) {
        return /*#__PURE__*/ forwardRef(function(props, ref) {
            var size = props.size, children = props.children, breakWord = props.breakWord, noWrap = props.noWrap, medium = props.medium, _props_bold = props.bold, bold = _props_bold === void 0 ? defaultArgs === null || defaultArgs === void 0 ? void 0 : defaultArgs.defaultBold : _props_bold, extraBold = props.extraBold, color = props.color, isNumeric = props.isNumeric, isItalic = props.isItalic, className = props.className, style = props.style, rest = _object_without_properties(props, [
                "size",
                "children",
                "breakWord",
                "noWrap",
                "medium",
                "bold",
                "extraBold",
                "color",
                "isNumeric",
                "isItalic",
                "className",
                "style"
            ]);
            // TODO: Временное решение. Основное решение будет основано на указание тега по-умолчанию в конфигурации
            // TODO: компонента и сбросе стилей по-умолчанию для тега
            var isHeading = (defaultArgs === null || defaultArgs === void 0 ? void 0 : defaultArgs.type) === 'heading';
            var ariaHeadingLevel = isHeading ? size === null || size === void 0 ? void 0 : size.split('')[1] : null;
            // Порядок определяет приоритет: extraBold и medium перебивают дефолтный bold
            // TODO: Нужно менять поведение, не должен быть bold по-умолчанию
            var fontWeightClass = [
                extraBold && classes.typoExtraBold,
                medium && classes.typoMedium,
                bold && classes.typoBold
            ].find(Boolean);
            return /*#__PURE__*/ React.createElement(Root, _object_spread({
                size: size,
                ref: ref,
                className: cx(noWrap && classes.typoWithNoWrap, breakWord && classes.typoWithBreakWord, fontWeightClass, isNumeric && classes.typoIsNumeric, isItalic && classes.typoIsItalic, className),
                style: _object_spread({
                    color: color
                }, style, applySpacing(rest)),
                "aria-level": ariaHeadingLevel,
                role: isHeading ? 'heading' : undefined
            }, rest), children);
        });
    };
};
