"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "textSkeleton", {
    enumerable: true,
    get: function() {
        return textSkeleton;
    }
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
const _TextSkeletonstyles = require("./TextSkeleton.styles");
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
const variousWidth = [
    7.58,
    5.27,
    13.54,
    6.63,
    0.28,
    14.8,
    0.33,
    11.26,
    14.1,
    10.59,
    3.38,
    13.5,
    7.71,
    3.34,
    7.96
];
const textSkeleton = (Component)=>({ lines, width, roundness, customGradientColor, lighter, animationType = 'shimmer', customFadeInColor, customFadeOutColor, size = 'bodyM', view = 'default', ...props })=>{
        const [fixedWidth, setFixedWidth] = (0, _react.useState)(null);
        const [linesWidth, setLinesWidth] = (0, _react.useState)([]);
        (0, _react.useEffect)(()=>{
            if (!width) {
                setFixedWidth(null);
                const computedLengths = Array(lines).fill(0).reduce((acc, _, i)=>{
                    let w;
                    // Последняя строка
                    if (i === lines - 1 && lines !== 1) {
                        w = 45 - variousWidth[i % variousWidth.length];
                    } else if (lines === 1 || lines === 2) {
                        // Единственная или первая из двух
                        w = 100;
                    } else {
                        w = 100 - variousWidth[i % variousWidth.length];
                    }
                    return {
                        ...acc,
                        [i]: w
                    };
                }, {});
                setLinesWidth(Object.values(computedLengths));
                return;
            }
            if (!Number.isNaN(Number(width))) {
                setFixedWidth(`${width}%`);
            } else {
                setFixedWidth(String(width));
            }
        }, [
            width,
            lines
        ]);
        // TODO: Подумать как можно обойти явное приведение типов
        const ComponentSkeleton = Component;
        return /*#__PURE__*/ _react.default.createElement(_TextSkeletonstyles.StyledTextSkeleton, props, Array.from(Array(lines), (_, i)=>{
            return /*#__PURE__*/ _react.default.createElement(ComponentSkeleton, {
                key: `line:${i}`,
                size: size,
                view: view,
                roundness: roundness,
                animationType: animationType,
                lighter: lighter,
                customGradientColor: customGradientColor,
                customFadeInColor: customFadeInColor,
                customFadeOutColor: customFadeOutColor,
                style: {
                    width: fixedWidth || `${linesWidth[i]}%`
                }
            });
        }));
    };
