import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Ellipsis } from '@gravity-ui/icons';
import { Button, Icon, Menu, Popup } from '@gravity-ui/uikit';
import { cn } from "../../../../../classname.js";
import { i18n as i18nCommon } from "../../../../../i18n/common/index.js";
import { useBooleanState, useElementState } from "../../../../../react-utils/hooks.js";
import { ReactNodeStopEventCn } from "../../../../../react-utils/react-node-view.js";
import { ImageForm } from "./ImageForm/index.js";
import "./ImgSettingsButton.css";
const b = cn('img-settings-button');
export const ImgSettingsButton = function ({ node, view, updateAttributes, visible, edit, toggleEdit, nodeElement, unsetEdit, onDelete, }) {
    const [anchorElement, setAnchorElement] = useElementState();
    const [popupOpen, _setPopupOpen, unsetPopupOpen, togglePopup] = 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 (_jsxs(_Fragment, { children: [isVisibleImageForm && (_jsx(ImageForm, { node: node, view: view, updateAttributes: updateAttributes, anchorElement: nodeElement, unsetEdit: unsetEdit })), isVisibleEditButton && (_jsx(Button, { qa: "g-md-image-settings-button", onClick: togglePopup, ref: setAnchorElement, size: "s", view: 'raised', className: b(null, ReactNodeStopEventCn), children: _jsx(Icon, { data: Ellipsis, className: ReactNodeStopEventCn }) })), _jsx(Popup, { open: isVisiblePopup, anchorElement: anchorElement, onOpenChange: unsetPopupOpen, placement: placement, children: _jsxs(Menu, { qa: "g-md-image-settings-menu", children: [_jsx(Menu.Item, { extraProps: { 'aria-label': i18nCommon('edit') }, onClick: handleEdit, children: i18nCommon('edit') }), _jsx(Menu.Item, { extraProps: { 'aria-label': i18nCommon('delete') }, onClick: onDelete, children: i18nCommon('delete') })] }) })] }));
};
//# sourceMappingURL=ImgSettingsButton.js.map
