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;
}
import { CloseCircleFill, CornerLeftUp, QuoteBefore } from "@sofa-design/icons";
import { ConfigProvider } from "antd";
import classNames from "clsx";
import React, { useContext, useMemo } from "react";
import { useRefFunction } from "../Hooks/useRefFunction";
import { useStyle } from "./style";
var POPUP_ICON_STYLE = {
    fontSize: 14,
    display: 'flex',
    alignItems: 'center'
};
/**
 * Quote 组件 - 引用组件
 *
 * 该组件用于显示代码引用或文档引用，支持显示文件名、行号范围、引用描述等信息。
 * 提供悬停显示详细内容的功能，支持关闭按钮和点击交互。
 *
 * @component
 * @description 引用组件，用于显示代码或文档引用信息
 * @param {QuoteProps} props - 组件属性
 * @param {string} [props.fileName] - 文件名
 * @param {string} [props.lineRange] - 行号范围
 * @param {string} props.quoteDescription - 引用描述
 * @param {string} [props.popupDetail] - 详细内容（悬停显示）
 * @param {boolean} [props.closable=false] - 是否显示关闭按钮
 * @param {() => void} [props.onClose] - 关闭回调
 * @param {string} [props.className] - 自定义CSS类名（已废弃，请使用 classNames.root）
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {Object} [props.classNames] - 自定义样式类名
 * @param {Object} [props.styles] - 自定义内联样式
 * @param {(fileName: string, lineRange?: string) => void} [props.onFileClick] - 点击文件名回调
 *
 * @example
 * ```tsx
 * <Quote
 *   fileName="example.js"
 *   lineRange="10-15"
 *   quoteDescription="函数定义"
 *   popupDetail="function example() { return 'hello'; }"
 *   closable
 *   onClose={() => console.log('关闭引用')}
 *   onFileClick={(fileName, lineRange) => {
 *     console.log('点击文件:', fileName, '行号:', lineRange);
 *   }}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的引用组件
 */ var QuoteComponent = function QuoteComponent(param) {
    var fileName = param.fileName, lineRange = param.lineRange, quoteDescription = param.quoteDescription, popupDetail = param.popupDetail, _param_popupDirection = param.popupDirection, popupDirection = _param_popupDirection === void 0 ? 'left' : _param_popupDirection, _param_closable = param.closable, closable = _param_closable === void 0 ? false : _param_closable, onClose = param.onClose, className = param.className, style = param.style, customClassNames = param.classNames, customStyles = param.styles, onFileClick = param.onFileClick;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-quote');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var handleFileClick = useRefFunction(function() {
        if (onFileClick && fileName) {
            onFileClick(fileName, lineRange);
        }
    });
    var cls = useMemo(function() {
        return {
            container: classNames("".concat(prefixCls, "-container"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.root, className),
            description: classNames("".concat(prefixCls, "-quoteDescription"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.description),
            closeButton: classNames("".concat(prefixCls, "-close-button"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.closeButton),
            icon: classNames("".concat(prefixCls, "-quote-icon"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.icon),
            popup: classNames("".concat(prefixCls, "-popup"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.popup),
            popupHeader: classNames("".concat(prefixCls, "-popup-header"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.popupHeader),
            popupTitle: classNames("".concat(prefixCls, "-popup-title"), hashId),
            popupRange: classNames("".concat(prefixCls, "-popup-range"), hashId),
            popupContent: classNames("".concat(prefixCls, "-popup-content"), hashId, customClassNames === null || customClassNames === void 0 ? void 0 : customClassNames.popupContent)
        };
    }, [
        prefixCls,
        hashId,
        customClassNames,
        className
    ]);
    var popupStyle = useMemo(function() {
        return _object_spread(_define_property({}, popupDirection, 0), customStyles === null || customStyles === void 0 ? void 0 : customStyles.popup);
    }, [
        popupDirection,
        customStyles === null || customStyles === void 0 ? void 0 : customStyles.popup
    ]);
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: cls.container,
        style: _object_spread({}, style, customStyles === null || customStyles === void 0 ? void 0 : customStyles.root),
        "data-testid": "quote-container"
    }, /*#__PURE__*/ React.createElement("div", {
        className: cls.icon,
        style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.icon,
        "data-testid": "quote-icon"
    }, /*#__PURE__*/ React.createElement(QuoteBefore, null)), /*#__PURE__*/ React.createElement("span", {
        className: cls.description,
        style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.description,
        "data-testid": "quote-description"
    }, quoteDescription), closable && /*#__PURE__*/ React.createElement("div", {
        onClick: onClose,
        className: cls.closeButton,
        style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.closeButton,
        "data-testid": "quote-close-button"
    }, /*#__PURE__*/ React.createElement(CloseCircleFill, null)), popupDetail && /*#__PURE__*/ React.createElement("div", {
        className: cls.popup,
        "data-testid": "quote-popup",
        style: popupStyle
    }, (fileName || lineRange) && /*#__PURE__*/ React.createElement("div", {
        className: cls.popupHeader,
        style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.popupHeader,
        onClick: handleFileClick,
        "data-testid": "quote-popup-header"
    }, /*#__PURE__*/ React.createElement("div", {
        style: POPUP_ICON_STYLE,
        "data-testid": "quote-popup-icon"
    }, /*#__PURE__*/ React.createElement(CornerLeftUp, null)), fileName && /*#__PURE__*/ React.createElement("span", {
        className: cls.popupTitle,
        "data-testid": "quote-popup-title"
    }, fileName), lineRange && /*#__PURE__*/ React.createElement("span", {
        className: cls.popupRange,
        "data-testid": "quote-popup-range"
    }, "(", lineRange, ")")), /*#__PURE__*/ React.createElement("div", {
        className: cls.popupContent,
        style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.popupContent,
        "data-testid": "quote-popup-content"
    }, popupDetail))));
};
QuoteComponent.displayName = 'Quote';
export var Quote = /*#__PURE__*/ React.memo(QuoteComponent);
