(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "../../../Divider", "./styles"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var Divider_1 = (0, tslib_1.__importDefault)(require("../../../Divider"));
    var styles_1 = require("./styles");
    var SelectMenu = function (props) {
        var innerProps = props.innerProps, selectProps = props.selectProps;
        var onInnerMenuOpen = selectProps.onInnerMenuOpen, isError = selectProps.isError;
        var menuRef = (0, react_1.useRef)(null);
        (0, react_1.useEffect)(function () {
            onInnerMenuOpen &&
                menuRef.current &&
                onInnerMenuOpen(menuRef.current.getBoundingClientRect());
        });
        (0, react_1.useEffect)(function () {
            if (menuRef.current) {
                var _a = menuRef.current.getBoundingClientRect(), bottom = _a.bottom, top_1 = _a.top, height = _a.height;
                if (bottom > window.innerHeight &&
                    top_1 > height + (props.selectProps.size === "l" ? 56 : 48)) {
                    menuRef.current.className = menuRef.current.className + " select-menu__top";
                }
            }
        }, []);
        return (react_1.default.createElement(styles_1.MenuStyle, (0, tslib_1.__assign)({ "data-element": "select-menu", ref: menuRef, isError: isError, iconRight: selectProps.iconRight }, innerProps),
            react_1.default.createElement(styles_1.MenuItemsWrapper, null, props.children),
            selectProps.buttonMenu && (react_1.default.createElement(styles_1.MenuButtonsWrapper, { className: selectProps.classNameButtonMenu },
                react_1.default.createElement(Divider_1.default, { className: "select-menu__divider" }),
                selectProps.buttonMenu))));
    };
    exports.default = SelectMenu;
});
