"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecondaryActionButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const ClickAwayListener_1 = __importDefault(require("@mui/material/ClickAwayListener"));
const react_1 = require("react");
const DotsVOutlineMd_1 = require("../../../../icons/DotsVOutlineMd");
const useMenu_1 = require("../../../useMenu");
const CardGridSecondaryAction_1 = require("../../CardGridSecondaryAction");
const CardActionContext_1 = require("../CardActionContext");
const styles_1 = require("./styles");
const SecondaryActionButton = ({ renderActions, }) => {
    const buttonRef = (0, react_1.useRef)(null);
    const { open, anchorRef, handleOpenMenu, handleCloseMenu } = (0, useMenu_1.useMenu)(buttonRef);
    const { isDisabled, isDisabledCard } = (0, react_1.useContext)(CardActionContext_1.CardActionContext);
    // Если контент единожды отрендерился, то будем рендерить его дальше,
    // чтобы были актуальные статусы loading для блокировки действий
    const [isOnceOpen, setIsOnceOpen] = (0, react_1.useState)(false);
    const handleOpen = () => {
        setIsOnceOpen(true);
        handleOpenMenu();
    };
    return ((0, jsx_runtime_1.jsxs)(CardGridSecondaryAction_1.SecondaryActionsMenuProvider, { value: { open, anchorEl: anchorRef.current }, children: [(0, jsx_runtime_1.jsx)(ClickAwayListener_1.default, { onClickAway: handleCloseMenu, mouseEvent: "onMouseUp", children: (0, jsx_runtime_1.jsx)(styles_1.StyledIconButton, { ref: anchorRef, onClick: handleOpen, selected: open, variant: "outlined", color: "grey", disabled: isDisabled || isDisabledCard, children: (0, jsx_runtime_1.jsx)(DotsVOutlineMd_1.DotsVOutlineMd, {}) }) }), isOnceOpen && renderActions({ isLoading: false })] }));
};
exports.SecondaryActionButton = SecondaryActionButton;
