"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AttachmentPicker = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const icons_1 = require("@gravity-ui/icons");
const uikit_1 = require("@gravity-ui/uikit");
const cn_1 = require("../../../utils/cn.js");
const ActionButton_1 = require("../../atoms/ActionButton/index.js");
const FileUploadDialog_1 = require("../FileUploadDialog/index.js");
const i18n_1 = require("./i18n/index.js");
require("./AttachmentPicker.css");
const b = (0, cn_1.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.
 */
const AttachmentPicker = ({ uploadOnly = true, disabled = false, fileDialogProps, onSelectFromStorage, buttonSize = 'm', uploadLabel = (0, i18n_1.i18n)('upload-label'), selectFromStorageLabel = (0, i18n_1.i18n)('select-from-storage-label'), className, }) => {
    const [dialogOpen, setDialogOpen] = (0, react_1.useState)(false);
    const handleUploadClick = () => setDialogOpen(true);
    const button = ((0, jsx_runtime_1.jsx)("div", { className: b('button-wrapper'), children: (0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { view: "flat", size: buttonSize, onClick: uploadOnly ? handleUploadClick : undefined, disabled: disabled, className: b('button'), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Paperclip, size: 16 }) }) }));
    return ((0, jsx_runtime_1.jsxs)("div", { className: b(null, className), children: [uploadOnly ? (button) : ((0, jsx_runtime_1.jsx)(uikit_1.DropdownMenu, { disabled: disabled, items: [
                    {
                        text: uploadLabel,
                        action: handleUploadClick,
                    },
                    {
                        text: selectFromStorageLabel,
                        action: () => onSelectFromStorage === null || onSelectFromStorage === void 0 ? void 0 : onSelectFromStorage(),
                    },
                ], renderSwitcher: (props) => ((0, jsx_runtime_1.jsx)("div", { className: b('button-wrapper'), children: (0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, Object.assign({ view: "flat", size: buttonSize, disabled: disabled, className: b('button') }, props, { children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Paperclip, size: 16 }) })) })) })), (0, jsx_runtime_1.jsx)(FileUploadDialog_1.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);
                } }))] }));
};
exports.AttachmentPicker = AttachmentPicker;
//# sourceMappingURL=AttachmentPicker.js.map
