"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;
    }
});
var _react = require("react");
var ROOT_FONT_SIZE = 16;
var useAutoResize = function useAutoResize(active, ref, value, minAuto, maxAuto, resize, hiddenRef, size) {
    var previousHeight = (0, _react.useRef)();
    (0, _react.useEffect)(function() {
        if (active && ref && ref.current && hiddenRef && hiddenRef.current) {
            // проверка на пользовательский resize (вручную)
            var height = ref.current.clientHeight / ROOT_FONT_SIZE;
            if (resize && resize !== 'none' && previousHeight.current !== undefined && previousHeight.current !== height) {
                return;
            }
            var style = getComputedStyle(ref.current);
            var lineHeight = parseInt(style.lineHeight, 10);
            var lineHeightInRem = lineHeight / ROOT_FONT_SIZE;
            var minAutoHeight = minAuto ? minAuto * lineHeightInRem : 0;
            hiddenRef.current.style.height = "".concat(minAutoHeight, "rem");
            var lines = Math.floor(hiddenRef.current.scrollHeight / lineHeight);
            var newScrollHeight = lines * lineHeightInRem;
            var maxAutoHeight = maxAuto ? maxAuto * lineHeightInRem : newScrollHeight;
            var newHeight = Math.min(newScrollHeight, maxAutoHeight);
            ref.current.style.height = "".concat(newHeight, "rem");
            previousHeight.current = newHeight;
        }
    }, [
        resize,
        active,
        value,
        minAuto,
        maxAuto,
        size
    ]);
};
