"use strict";
exports.__esModule = true;
exports.useOverflow = void 0;
var tslib_1 = require("tslib");
var react_1 = require("react");
var useComponentSize_1 = require("../useComponentSize/useComponentSize");
var getMaxWidth = function (element) {
    if (element instanceof Window) {
        return element.outerWidth;
    }
    if (element instanceof Document) {
        return element.documentElement.offsetWidth;
    }
    if (element instanceof HTMLElement) {
        return element.offsetWidth;
    }
    if (element.current) {
        return element.current.offsetWidth;
    }
    return 0;
};
var useOverflow = function (props) {
    var currentRef = props.currentRef, containerRef = props.containerRef;
    var _a = (0, tslib_1.__read)((0, react_1.useState)(false), 2), isOverflow = _a[0], setIsOverflow = _a[1];
    var size = (0, useComponentSize_1.useComponentSize)(currentRef);
    (0, react_1.useEffect)(function () {
        var _a;
        var container = containerRef || ((_a = currentRef.current) === null || _a === void 0 ? void 0 : _a.parentElement);
        if (container && currentRef.current) {
            var cs = container instanceof HTMLElement
                ? getComputedStyle(container)
                : {
                    paddingLeft: '0',
                    paddingTop: '0',
                    paddingBottom: '0',
                    paddingRight: '0'
                };
            var padding = {
                top: parseFloat(cs.paddingTop),
                left: parseFloat(cs.paddingLeft),
                right: parseFloat(cs.paddingRight),
                bottom: parseFloat(cs.paddingBottom)
            };
            if (getMaxWidth(container) - padding.left - padding.right < currentRef.current.scrollWidth) {
                setIsOverflow(true);
            }
            else {
                setIsOverflow(false);
            }
        }
    }, [size.width, size.height]);
    return isOverflow;
};
exports.useOverflow = useOverflow;
