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 { useImperativeHandle } from "react";
/**
 * 把内部 MarkdownEditor 实例透出到调用方传入的 `inputRef`。
 *
 * 单一职责：仅处理「内部实例 → 外部 ref」的桥接，并保证通过外部 ref
 * 直接调用 `store.setMDContent` 时也能同步主组件的受控 `value` 状态
 * （否则发送按钮等派生 disabled 状态不会更新）。
 *
 * 实现：用 `Proxy` 包装 `editor.store`，仅劫持 `setMDContent` 方法以
 * 在调用前同步 `setValue`，其余方法（`getMDContent` / `clearContent` /
 * `focus` 等）通过 `Reflect.get` 透传，保留完整的 store 表面。
 */ export var useExposeInputRef = function useExposeInputRef(param) {
    var inputRef = param.inputRef, markdownEditorRef = param.markdownEditorRef, setValue = param.setValue;
    useImperativeHandle(inputRef, function() {
        var editor = markdownEditorRef.current;
        var syncValueAndSetMDContent = function syncValueAndSetMDContent(md, plugins, options) {
            var _editor_store;
            if (md !== undefined) {
                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);
        };
        // editor 尚未就绪时，仍提供一个最小可用的 store，至少保证 setMDContent
        // 调用安全（同步外部 value，方便父组件做受控初始化）。
        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
        });
    }, [
        setValue
    ]);
};
