"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CaretTopOverlay = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const CaretToolbar_1 = require("nice-ui/lib/4-card/Toolbar/ToolbarMenu/CaretToolbar");
const context_1 = require("../../context");
const hooks_1 = require("../../../../web/react/hooks");
const AfterTimeout_1 = require("../../../../web/react/util/AfterTimeout");
const CaretTopOverlay = () => {
    const { toolbar } = (0, context_1.useToolbarPlugin)();
    const showInlineToolbar = toolbar.showInlineToolbar;
    const [, toolbarVisibilityChangeTime] = (0, hooks_1.useSyncStore)(showInlineToolbar);
    const doHideForCoolDown = toolbarVisibilityChangeTime + 500 > Date.now();
    const enableAfterCoolDown = (0, hooks_1.useTimeout)(500, [doHideForCoolDown]);
    // biome-ignore lint/correctness/useExhaustiveDependencies: showInlineToolbar.next do not need to memoize
    const handleClose = React.useCallback(() => {
        setTimeout(() => {
            if (showInlineToolbar.value)
                showInlineToolbar.next([false, Date.now()]);
        }, 5);
    }, []);
    let element = (React.createElement(CaretToolbar_1.CaretToolbar, { disabled: !enableAfterCoolDown, menu: toolbar.getCaretMenu(), onPopupClose: handleClose }));
    if (doHideForCoolDown) {
        element = React.createElement(AfterTimeout_1.AfterTimeout, { ms: 500 }, element);
    }
    element = null;
    return element;
};
exports.CaretTopOverlay = CaretTopOverlay;
//# sourceMappingURL=CaretTopOverlay.js.map