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;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
import { useEffect, useImperativeHandle, useRef } from "react";
/**
 * Refs 管理 Hook
 * 管理组件中所有的 refs 和相关逻辑
 */ export var useMarkdownInputFieldRefs = function useMarkdownInputFieldRefs(props) {
    var markdownEditorRef = useRef();
    var quickActionsRef = useRef(null);
    var actionsRef = useRef(null);
    var isSendingRef = useRef(false);
    // 同步外部 value 到编辑器
    useEffect(function() {
        var _props_value;
        var _markdownEditorRef_current_store, _markdownEditorRef_current;
        if (!markdownEditorRef.current) return;
        (_markdownEditorRef_current = markdownEditorRef.current) === null || _markdownEditorRef_current === void 0 ? void 0 : (_markdownEditorRef_current_store = _markdownEditorRef_current.store) === null || _markdownEditorRef_current_store === void 0 ? void 0 : _markdownEditorRef_current_store.setMDContent((_props_value = props.value) !== null && _props_value !== void 0 ? _props_value : '');
    }, [
        props.value
    ]);
    // 通过 ref 暴露编辑器实例，包装 store.setMDContent 以同步 value 状态，确保发送按钮正确响应
    // 使用 Proxy 包装 store，仅覆盖 setMDContent，保留 getMDContent、clearContent、focus 等全部方法
    useImperativeHandle(props.inputRef, function() {
        var editor = markdownEditorRef.current;
        var syncValueAndSetMDContent = function syncValueAndSetMDContent(md, plugins, options) {
            var _editor_store;
            if (md !== undefined) {
                props.setValue(md);
            }
            return editor === null || editor === void 0 ? void 0 : (_editor_store = editor.store) === null || _editor_store === void 0 ? void 0 : _editor_store.setMDContent(md, plugins, options);
        };
        if (!editor) {
            return {
                store: {
                    setMDContent: syncValueAndSetMDContent
                }
            };
        }
        var storeProxy = new Proxy(editor.store, {
            get: function get(target, prop) {
                if (prop === 'setMDContent') {
                    return syncValueAndSetMDContent;
                }
                return Reflect.get(target, prop);
            }
        });
        return _object_spread_props(_object_spread({}, editor), {
            store: storeProxy
        });
    }, [
        props.setValue
    ]);
    return {
        markdownEditorRef: markdownEditorRef,
        quickActionsRef: quickActionsRef,
        actionsRef: actionsRef,
        isSendingRef: isSendingRef
    };
};
