"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const RightOutlined_1 = tslib_1.__importDefault(require("@ant-design/icons/RightOutlined"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const rc_dropdown_1 = tslib_1.__importDefault(require("rc-dropdown"));
const react_1 = tslib_1.__importDefault(require("react"));
const type_1 = require("../utils/type");
const warning_1 = require("../utils/warning");
const Placements = (0, type_1.tuple)('topLeft', 'topCenter', 'topRight', 'bottomLeft', 'bottomCenter', 'bottomRight');
class Dropdown extends react_1.default.Component {
    constructor() {
        super(...arguments);
        this.renderOverlay = (prefixCls) => {
            // rc-dropdown already can process the function of overlay, but we have check logic here.
            // So we need render the element to check and pass back to rc-dropdown.
            const { overlay } = this.props;
            let overlayNode;
            if (typeof overlay === 'function') {
                overlayNode = overlay();
            }
            else {
                overlayNode = overlay;
            }
            overlayNode = react_1.default.Children.only(overlayNode);
            const overlayProps = overlayNode.props;
            // Warning if use other mode
            (0, warning_1.warning)(!overlayProps.mode || overlayProps.mode === 'vertical', `[Dropdown] mode="${overlayProps.mode}" is not supported for Dropdown's Menu.`);
            // menu cannot be selectable in dropdown defaultly
            // menu should be focusable in dropdown defaultly
            const { selectable = false, focusable = true } = overlayProps;
            const expandIcon = (react_1.default.createElement("span", { className: `${prefixCls}-menu-submenu-arrow` },
                react_1.default.createElement(RightOutlined_1.default, { className: `${prefixCls}-menu-submenu-arrow-icon` })));
            const fixedModeOverlay = typeof overlayNode.type === 'string'
                ? overlay
                : react_1.default.cloneElement(overlayNode, {
                    mode: 'vertical',
                    selectable,
                    focusable,
                    expandIcon,
                });
            return fixedModeOverlay;
        };
        this.renderDropDown = () => {
            const { prefixCls: customizePrefixCls, children, trigger, disabled, getPopupContainer } = this.props;
            const prefixCls = customizePrefixCls || 'kt-dropdown';
            const child = react_1.default.Children.only(children);
            const dropdownTrigger = react_1.default.cloneElement(child, {
                className: (0, classnames_1.default)(child.props.className, `${prefixCls}-trigger`),
                disabled,
            });
            const triggerActions = disabled ? [] : trigger;
            let alignPoint;
            if (triggerActions && triggerActions.indexOf('contextMenu') !== -1) {
                alignPoint = true;
            }
            return (react_1.default.createElement(rc_dropdown_1.default, Object.assign({ alignPoint: alignPoint }, this.props, { prefixCls: prefixCls, getPopupContainer: getPopupContainer, transitionName: this.getTransitionName(), trigger: triggerActions, overlay: () => this.renderOverlay(prefixCls) }), dropdownTrigger));
        };
    }
    getTransitionName() {
        const { placement = '', transitionName } = this.props;
        if (transitionName !== undefined) {
            return transitionName;
        }
        if (placement.indexOf('top') >= 0) {
            return 'slide-down';
        }
        return 'slide-up';
    }
    render() {
        return this.renderDropDown();
    }
}
exports.default = Dropdown;
Dropdown.defaultProps = {
    mouseEnterDelay: 0.15,
    mouseLeaveDelay: 0.1,
    placement: 'bottomLeft',
};
//# sourceMappingURL=dropdown.js.map