"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImgSettingsButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const icons_1 = require("@gravity-ui/icons");
const uikit_1 = require("@gravity-ui/uikit");
const classname_1 = require("../../../../../classname.js");
const common_1 = require("../../../../../i18n/common/index.js");
const hooks_1 = require("../../../../../react-utils/hooks.js");
const react_node_view_1 = require("../../../../../react-utils/react-node-view.js");
const ImageForm_1 = require("./ImageForm/index.js");
require("./ImgSettingsButton.css");
const b = (0, classname_1.cn)('img-settings-button');
const ImgSettingsButton = function ({ node, view, updateAttributes, visible, edit, toggleEdit, nodeElement, unsetEdit, onDelete, }) {
    const [anchorElement, setAnchorElement] = (0, hooks_1.useElementState)();
    const [popupOpen, _setPopupOpen, unsetPopupOpen, togglePopup] = (0, hooks_1.useBooleanState)(false);
    const placement = ['bottom-end', 'bottom-start'];
    const handleEdit = () => {
        toggleEdit();
        unsetPopupOpen();
    };
    const isVisibleImageForm = edit;
    const isVisibleEditButton = !edit && (visible || popupOpen);
    const isVisiblePopup = !edit && popupOpen;
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isVisibleImageForm && ((0, jsx_runtime_1.jsx)(ImageForm_1.ImageForm, { node: node, view: view, updateAttributes: updateAttributes, anchorElement: nodeElement, unsetEdit: unsetEdit })), isVisibleEditButton && ((0, jsx_runtime_1.jsx)(uikit_1.Button, { onClick: togglePopup, ref: setAnchorElement, size: "s", view: 'raised', className: b(null, react_node_view_1.ReactNodeStopEventCn), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Ellipsis, className: react_node_view_1.ReactNodeStopEventCn }) })), (0, jsx_runtime_1.jsx)(uikit_1.Popup, { open: isVisiblePopup, anchorElement: anchorElement, onOpenChange: unsetPopupOpen, placement: placement, children: (0, jsx_runtime_1.jsxs)(uikit_1.Menu, { children: [(0, jsx_runtime_1.jsx)(uikit_1.Menu.Item, { onClick: handleEdit, children: (0, common_1.i18n)('edit') }), (0, jsx_runtime_1.jsx)(uikit_1.Menu.Item, { onClick: onDelete, children: (0, common_1.i18n)('delete') })] }) })] }));
};
exports.ImgSettingsButton = ImgSettingsButton;
//# sourceMappingURL=ImgSettingsButton.js.map
