import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Paperclip } from '@gravity-ui/icons';
import { DropdownMenu, Icon } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import { ActionButton } from "../../atoms/ActionButton/index.js";
import { FileUploadDialog } from "../FileUploadDialog/index.js";
import { i18n } from "./i18n/index.js";
import "./AttachmentPicker.css";
const b = block('attachment-picker');
/**
 * AttachmentPicker renders a paperclip button that either opens a file upload dialog
 * directly (uploadOnly) or shows a dropdown with upload / select-from-storage options.
 */
export const AttachmentPicker = ({ uploadOnly = true, disabled = false, fileDialogProps, onSelectFromStorage, buttonSize = 'm', uploadLabel = i18n('upload-label'), selectFromStorageLabel = i18n('select-from-storage-label'), className, }) => {
    const [dialogOpen, setDialogOpen] = useState(false);
    const handleUploadClick = () => setDialogOpen(true);
    const button = (_jsx("div", { className: b('button-wrapper'), children: _jsx(ActionButton, { view: "flat", size: buttonSize, onClick: uploadOnly ? handleUploadClick : undefined, disabled: disabled, className: b('button'), children: _jsx(Icon, { data: Paperclip, size: 16 }) }) }));
    return (_jsxs("div", { className: b(null, className), children: [uploadOnly ? (button) : (_jsx(DropdownMenu, { disabled: disabled, items: [
                    {
                        text: uploadLabel,
                        action: handleUploadClick,
                    },
                    {
                        text: selectFromStorageLabel,
                        action: () => onSelectFromStorage === null || onSelectFromStorage === void 0 ? void 0 : onSelectFromStorage(),
                    },
                ], renderSwitcher: (props) => (_jsx("div", { className: b('button-wrapper'), children: _jsx(ActionButton, Object.assign({ view: "flat", size: buttonSize, disabled: disabled, className: b('button') }, props, { children: _jsx(Icon, { data: Paperclip, size: 16 }) })) })) })), _jsx(FileUploadDialog, Object.assign({}, fileDialogProps, { open: dialogOpen, onClose: () => setDialogOpen(false), onCancel: () => {
                    var _a;
                    (_a = fileDialogProps.onCancel) === null || _a === void 0 ? void 0 : _a.call(fileDialogProps);
                    setDialogOpen(false);
                } }))] }));
};
//# sourceMappingURL=AttachmentPicker.js.map
