"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Popover = exports.PopoverPosition = exports.PopoverTriggerType = void 0;
const tslib_1 = require("tslib");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const rc_tooltip_1 = tslib_1.__importDefault(require("rc-tooltip"));
const react_1 = tslib_1.__importStar(require("react"));
require("./styles.less");
const button_1 = require("../button");
var PopoverTriggerType;
(function (PopoverTriggerType) {
    PopoverTriggerType["hover"] = "hover";
    PopoverTriggerType["click"] = "click";
    PopoverTriggerType["focus"] = "focus";
})(PopoverTriggerType || (exports.PopoverTriggerType = PopoverTriggerType = {}));
var PopoverPosition;
(function (PopoverPosition) {
    PopoverPosition["top"] = "top";
    PopoverPosition["bottom"] = "bottom";
    PopoverPosition["left"] = "left";
    PopoverPosition["right"] = "right";
    PopoverPosition["topLeft"] = "topLeft";
    PopoverPosition["topRight"] = "topRight";
    PopoverPosition["bottomLeft"] = "bottomLeft";
    PopoverPosition["bottomRight"] = "bottomRight";
    PopoverPosition["leftTop"] = "leftTop";
    PopoverPosition["leftBottom"] = "leftBottom";
    PopoverPosition["rightTop"] = "rightTop";
    PopoverPosition["rightBottom"] = "rightBottom";
})(PopoverPosition || (exports.PopoverPosition = PopoverPosition = {}));
const Popover = ({ children, trigger = PopoverTriggerType.hover, visible, content, position = PopoverPosition.top, showArrow = true, title, titleClassName, overlay, overlayClassName, overlayStyle, action, delay, zIndex = 1000, onClickAction, onVisibleChange, getTooltipContainer, ...restProps }) => {
    const handleActionClick = (0, react_1.useCallback)((event) => {
        if (onClickAction) {
            onClickAction(event);
        }
    }, [onClickAction]);
    const overlayContent = (0, react_1.useMemo)(() => {
        if (overlay) {
            return overlay;
        }
        else {
            if (!title && !content) {
                return null;
            }
            return (react_1.default.createElement(react_1.default.Fragment, null,
                title && (react_1.default.createElement("p", { className: (0, classnames_1.default)('kt-popover-title', titleClassName) },
                    title,
                    action && (react_1.default.createElement(button_1.Button, { size: 'small', type: 'link', onClick: handleActionClick }, action)))),
                content || ''));
        }
    }, [overlay, content, action, handleActionClick]);
    if (!overlayContent) {
        return children;
    }
    return (react_1.default.createElement(rc_tooltip_1.default, { ...restProps, visible: visible, placement: position, mouseEnterDelay: delay ? delay / 1000 : undefined, trigger: trigger, showArrow: showArrow, onVisibleChange: onVisibleChange, overlayClassName: overlayClassName, prefixCls: 'kt-popover', overlayStyle: overlayStyle, getTooltipContainer: getTooltipContainer, overlay: overlayContent, zIndex: zIndex },
        react_1.default.createElement("div", { className: 'kt-popover-trigger' }, children)));
};
exports.Popover = Popover;
//# sourceMappingURL=index.js.map