"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get ROOT_FONT_SIZE () {
        return ROOT_FONT_SIZE;
    },
    get useAutoResize () {
        return useAutoResize;
    }
});
const _react = require("react");
const ROOT_FONT_SIZE = 16;
const useAutoResize = (active, ref, value, minAuto, maxAuto, resize, hiddenRef, size)=>{
    const previousHeight = (0, _react.useRef)();
    (0, _react.useEffect)(()=>{
        if (active && ref && ref.current && hiddenRef && hiddenRef.current) {
            // проверка на пользовательский resize (вручную)
            const height = ref.current.clientHeight / ROOT_FONT_SIZE;
            if (resize && resize !== 'none' && previousHeight.current !== undefined && previousHeight.current !== height) {
                return;
            }
            const style = getComputedStyle(ref.current);
            const lineHeight = parseInt(style.lineHeight, 10);
            const lineHeightInRem = lineHeight / ROOT_FONT_SIZE;
            const minAutoHeight = minAuto ? minAuto * lineHeightInRem : 0;
            hiddenRef.current.style.height = `${minAutoHeight}rem`;
            const lines = Math.floor(hiddenRef.current.scrollHeight / lineHeight);
            const newScrollHeight = lines * lineHeightInRem;
            const maxAutoHeight = maxAuto ? maxAuto * lineHeightInRem : newScrollHeight;
            const newHeight = Math.min(newScrollHeight, maxAutoHeight);
            ref.current.style.height = `${newHeight}rem`;
            previousHeight.current = newHeight;
        }
    }, [
        resize,
        active,
        value,
        minAuto,
        maxAuto,
        size
    ]);
};
