var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import React from 'react';
import warning from 'warning';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { PopupMenu } from '../../internal/PopupMenu/index.js';
import { isTestEnv } from '../../lib/currentEnvironment.js';
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
import { rootNode } from '../../lib/rootNode/index.js';
import { createPropsGetter } from '../../lib/createPropsGetter.js';
import { getDropdownMenuTheme } from './getDropdownMenuTheme.js';
/**
 * Выпадающее меню `DropdownMenu` раскрывается по клику на переданный в `caption` элемент.
 */
var DropdownMenu = /** @class */ (function (_super) {
    __extends(DropdownMenu, _super);
    function DropdownMenu(props) {
        var _this = _super.call(this, props) || this;
        _this.getProps = createPropsGetter(DropdownMenu_1.defaultProps);
        _this.popupMenu = null;
        _this.open = function () {
            if (_this.popupMenu) {
                _this.popupMenu.open();
            }
        };
        _this.close = function () {
            if (_this.popupMenu) {
                _this.popupMenu.close();
            }
        };
        _this.refPopupMenu = function (ref) {
            _this.popupMenu = ref;
        };
        if (!props.caption) {
            warning(false, 'Prop "caption" is required!!!');
        }
        return _this;
    }
    DropdownMenu_1 = DropdownMenu;
    DropdownMenu.prototype.render = function () {
        var _this = this;
        return (React.createElement(ThemeContext.Consumer, null, function (theme) {
            return React.createElement(ThemeContext.Provider, { value: getDropdownMenuTheme(theme) }, _this.renderMain());
        }));
    };
    DropdownMenu.prototype.renderMain = function () {
        if (!this.props.caption) {
            return null;
        }
        var _a = this.getProps(), positions = _a.positions, disableAnimations = _a.disableAnimations;
        return (React.createElement(CommonWrapper, __assign({ rootNodeRef: this.setRootNode }, this.props),
            React.createElement(PopupMenu, { id: this.props.id, "aria-label": this.props['aria-label'], ref: this.refPopupMenu, caption: this.props.caption, menuMaxHeight: this.props.menuMaxHeight, menuWidth: this.props.menuWidth, preventIconsOffset: this.props.preventIconsOffset, popupHasPin: false, positions: positions, disableAnimations: disableAnimations, header: this.props.header, footer: this.props.footer, width: this.props.width, corners: this.props.corners, onClose: this.props.onClose, onOpen: this.props.onOpen, popupMenuId: this.props.popupMenuId }, this.props.children)));
    };
    var DropdownMenu_1;
    DropdownMenu.__KONTUR_REACT_UI__ = 'DropdownMenu';
    DropdownMenu.displayName = 'DropdownMenu';
    DropdownMenu.defaultProps = {
        disableAnimations: isTestEnv,
        positions: ['bottom left', 'bottom right', 'top left', 'top right'],
    };
    DropdownMenu = DropdownMenu_1 = __decorate([
        rootNode
    ], DropdownMenu);
    return DropdownMenu;
}(React.Component));
export { DropdownMenu };
//# sourceMappingURL=DropdownMenu.js.map