import React, { useMemo } from "react";
import { AttachmentFileList } from "../AttachmentButton/AttachmentFileList";
import { MARKDOWN_INPUT_FIELD_TEST_IDS } from "../testIds";
/**
 * 附件列表渲染 Hook
 */ export var useAttachmentList = function useAttachmentList(param) {
    var attachment = param.attachment, fileMap = param.fileMap, handleFileRemoval = param.handleFileRemoval, handleFileRetry = param.handleFileRetry, updateAttachmentFiles = param.updateAttachmentFiles;
    return useMemo(function() {
        if (!(attachment === null || attachment === void 0 ? void 0 : attachment.enable)) return null;
        return React.createElement(AttachmentFileList, {
            fileMap: fileMap,
            onDelete: handleFileRemoval,
            onRetry: handleFileRetry,
            onPreview: (attachment === null || attachment === void 0 ? void 0 : attachment.onPreview) ? function(file) {
                var _attachment_onPreview;
                void Promise.resolve((_attachment_onPreview = attachment.onPreview) === null || _attachment_onPreview === void 0 ? void 0 : _attachment_onPreview.call(attachment, file)).catch(function() {});
            } : undefined,
            onClearFileMap: function onClearFileMap() {
                updateAttachmentFiles(undefined);
            },
            dataTestId: MARKDOWN_INPUT_FIELD_TEST_IDS.ATTACHMENT_LIST
        });
    }, [
        attachment === null || attachment === void 0 ? void 0 : attachment.enable,
        attachment === null || attachment === void 0 ? void 0 : attachment.onPreview,
        fileMap,
        handleFileRemoval,
        handleFileRetry,
        updateAttachmentFiles
    ]);
};
/**
 * BeforeTools 渲染 Hook
 *
 * 行为契约：依赖列表中任何字段变化都会触发重新渲染。`beforeToolsRender` 入参
 * 类型已收敛为 `SlotRenderState`，不再需要 ref 透传完整 `props` 对象。
 */ export var useBeforeTools = function useBeforeTools(param) {
    var beforeToolsRender = param.beforeToolsRender, attachment = param.attachment, value = param.value, fileMap = param.fileMap, onFileMapChange = param.onFileMapChange, fileUploadStatus = param.fileUploadStatus, fileUploadSummary = param.fileUploadSummary, disabled = param.disabled, typing = param.typing, isHover = param.isHover, isLoading = param.isLoading;
    return useMemo(function() {
        if (!beforeToolsRender) return null;
        return beforeToolsRender({
            attachment: attachment,
            value: value,
            fileMap: fileMap,
            onFileMapChange: onFileMapChange,
            fileUploadStatus: fileUploadStatus,
            fileUploadSummary: fileUploadSummary,
            disabled: disabled,
            typing: typing,
            isHover: isHover,
            isLoading: isLoading
        });
    }, [
        beforeToolsRender,
        attachment,
        value,
        fileMap,
        onFileMapChange,
        fileUploadStatus,
        fileUploadSummary,
        disabled,
        typing,
        isHover,
        isLoading
    ]);
};
