"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    ChatInputEditor: ()=>chat_input_editor_ChatInputEditor
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const resource_picker_provider_cjs_namespaceObject = require("../../providers/resource-picker-provider.cjs");
const external_chat_input_resource_picker_cjs_namespaceObject = require("./chat-input-resource-picker.cjs");
const index_cjs_namespaceObject = require("./tiptap/index.cjs");
const chat_input_editor_EditorWithPicker = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)(function(props, ref) {
    const { value, placeholder, minRows, maxRows, lineHeight, onChange, onKeyDown, editorRef } = props;
    const dropdownRef = (0, external_react_namespaceObject.useRef)(null);
    const { isOpenRef, drillDown, open, close, handleMentionEnd, setQuery } = (0, resource_picker_provider_cjs_namespaceObject.useAutopilotChatResourcePicker)();
    const drillDownRef = (0, external_react_namespaceObject.useRef)(drillDown);
    const valueRef = (0, external_react_namespaceObject.useRef)(value);
    (0, external_react_namespaceObject.useLayoutEffect)(()=>{
        drillDownRef.current = drillDown;
        valueRef.current = value;
    }, [
        drillDown,
        value
    ]);
    const handleChange = (0, external_react_namespaceObject.useCallback)((newValue)=>{
        if (isOpenRef.current && drillDownRef.current && !newValue.includes('@')) close();
        onChange(newValue);
    }, [
        close,
        onChange
    ]);
    const handleKeyDown = (0, external_react_namespaceObject.useCallback)((event)=>{
        if (isOpenRef.current && dropdownRef.current?.handleKeyDown(event)) return true;
        return onKeyDown?.(event) ?? false;
    }, [
        onKeyDown
    ]);
    const openResourcePicker = (0, external_react_namespaceObject.useCallback)(()=>{
        editorRef.current?.triggerMention();
    }, [
        editorRef
    ]);
    (0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>({
            focus: ()=>editorRef.current?.focus(),
            getSerializedContent: ()=>editorRef.current?.getSerializedContent() ?? valueRef.current,
            clear: ()=>editorRef.current?.clear(),
            openResourcePicker
        }), [
        editorRef,
        openResourcePicker
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.TipTapEditor, {
                ref: editorRef,
                value: value,
                placeholder: placeholder,
                minRows: minRows,
                maxRows: maxRows,
                lineHeight: lineHeight,
                onChange: handleChange,
                onKeyDown: handleKeyDown,
                onMentionStart: open,
                onMentionEnd: handleMentionEnd,
                onMentionQueryChange: setQuery
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_chat_input_resource_picker_cjs_namespaceObject.ResourcePickerDropdown, {
                ref: dropdownRef
            })
        ]
    });
});
const chat_input_editor_ChatInputEditor = /*#__PURE__*/ external_react_default().memo(/*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)(function(props, ref) {
    const editorRef = (0, external_react_namespaceObject.useRef)(null);
    const handleResourceSelect = (0, external_react_namespaceObject.useCallback)((resource, range)=>{
        editorRef.current?.insertResource(resource, range);
        editorRef.current?.focus();
    }, []);
    const handleDrillDown = (0, external_react_namespaceObject.useCallback)(()=>{
        editorRef.current?.clearMentionQuery();
    }, []);
    const handleClose = (0, external_react_namespaceObject.useCallback)(()=>{
        editorRef.current?.exitMention();
    }, []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(resource_picker_provider_cjs_namespaceObject.AutopilotChatResourcePickerProvider, {
        onResourceSelect: handleResourceSelect,
        onDrillDown: handleDrillDown,
        onClose: handleClose,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(chat_input_editor_EditorWithPicker, {
            ...props,
            ref: ref,
            editorRef: editorRef
        })
    });
}));
chat_input_editor_ChatInputEditor.displayName = 'ChatInputEditor';
exports.ChatInputEditor = __webpack_exports__.ChatInputEditor;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ChatInputEditor"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
