function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
import { Paperclip } from "@sofa-design/icons";
import { ConfigProvider } from "antd";
import classNames from "clsx";
import React, { useContext } from "react";
import AttachmentButtonPopover, { SupportedFileFormats } from "./AttachmentButtonPopover";
import { useStyle } from "./style";
export * from "./AttachmentButtonPopover";
/**
 * `upLoadFileToServer` 已迁移至 `src/MarkdownInputField/utils/uploadFile.ts`，
 * 此处保留 re-export 兼容层，确保 `src/index.ts` 的公开 API 与下游调用方
 * （`FileUploadManager`、`hooks/usePasteHandler` 等）的导入路径不发生破坏性变更。
 */ export { upLoadFileToServer } from "../utils/uploadFile";
var ButtonContent = function ButtonContent(param) {
    var title = param.title, prefixCls = param.prefixCls;
    return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Paperclip, null), title !== null && title ? /*#__PURE__*/ React.createElement("span", {
        className: "".concat(prefixCls, "-title")
    }, title) : null);
};
/**
 * 附件上传按钮组件
 *
 * 提供文件附件上传功能，支持图片、文档、音频、视频等多种格式
 *
 * @example
 * ```tsx
 * <AttachmentButton
 *   supportedFormat={SupportedFileFormats.image}
 *   upload={uploadFile}
 *   fileMap={fileMap}
 *   onFileMapChange={setFileMap}
 *   uploadImage={handleUpload}
 * />
 * ```
 */ export var AttachmentButton = function AttachmentButton(param) {
    var disabled = param.disabled, uploadImage = param.uploadImage, title = param.title, supportedFormat = param.supportedFormat, locale = param.locale, render = param.render;
    var context = useContext(ConfigProvider.ConfigContext);
    var prefix = context === null || context === void 0 ? void 0 : context.getPrefixCls('agentic-md-editor-attachment-button');
    var _useStyle = useStyle(prefix), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var format = supportedFormat || SupportedFileFormats.image;
    var buttonContent = /*#__PURE__*/ React.createElement("div", {
        className: "".concat(prefix, "-inner")
    }, /*#__PURE__*/ React.createElement(ButtonContent, {
        title: title,
        prefixCls: prefix
    }));
    var handleWrapperClick = function handleWrapperClick(e) {
        if (disabled) {
            // disabled 时拦截所有点击，阻止冒泡至 Popover 内部触发上传
            e.stopPropagation();
            e.preventDefault();
        }
        if (!disabled) {
            uploadImage();
        }
    };
    var wrapper = render ? render({
        children: buttonContent,
        supportedFormat: format,
        locale: locale
    }) : /*#__PURE__*/ React.createElement(AttachmentButtonPopover, {
        supportedFormat: format,
        uploadImage: disabled ? undefined : uploadImage,
        locale: locale
    }, buttonContent);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames("".concat(prefix), hashId, _define_property({}, "".concat(prefix, "-disabled"), disabled)),
        onClick: handleWrapperClick,
        "data-testid": "attachment-button"
    }, wrapper));
};
