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 { ConfigProvider } from "antd";
import classNames from "classnames";
import React, { createElement, useContext } from "react";
import { debugInfo } from "../../../../Utils/debugUtils";
import { useEditorStore } from "../../store";
import { useStyle } from "./style";
export var ListContext = /*#__PURE__*/ React.createContext(null);
/**
 * 列表组件，用于渲染有序或无序列表。
 *
 * @param {ElementProps<ListNode>} props - 组件的属性。
 * @param {ListNode} props.element - 列表节点元素，包含列表的相关信息。
 * @param {React.HTMLAttributes<HTMLDivElement>} props.attributes - 传递给列表容器的属性。
 * @param {React.ReactNode} props.children - 列表项的子元素。
 *
 * @returns {JSX.Element} 渲染的列表组件。
 *
 * @component
 * @example
 * ```tsx
 * <List element={element} attributes={attributes} children={children} />
 * ```
 */ export var List = function(param) {
    var element = param.element, attributes = param.attributes, children = param.children;
    var _element_children;
    // 支持新的列表类型和向后兼容
    // 新格式：numbered-list 或 bulleted-list
    // 旧格式：list 类型，通过 order 属性判断
    var isOrdered = element.type === 'numbered-list' || element.type === 'list' && element.order === true;
    // 获取 task 属性（支持旧格式和新格式）
    var task = element.task;
    debugInfo('List - 渲染列表', {
        type: element.type,
        isOrdered: isOrdered,
        task: task,
        start: isOrdered ? element.start : undefined,
        childrenCount: (_element_children = element.children) === null || _element_children === void 0 ? void 0 : _element_children.length
    });
    var _useEditorStore = useEditorStore(), store = _useEditorStore.store, markdownContainerRef = _useEditorStore.markdownContainerRef;
    var context = useContext(ConfigProvider.ConfigContext);
    var baseCls = context.getPrefixCls('agentic-md-editor-list');
    var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var listContent = React.useMemo(function() {
        // 支持新的列表类型和向后兼容
        var isOrdered = element.type === 'numbered-list' || element.type === 'list' && element.order === true;
        var task = element.task;
        var start = isOrdered ? element.start : undefined;
        var tag = isOrdered ? 'ol' : 'ul';
        debugInfo('List - useMemo 渲染', {
            tag: tag,
            type: element.type,
            start: start,
            task: task
        });
        return wrapSSR(/*#__PURE__*/ React.createElement(ListContext.Provider, {
            value: {
                hashId: hashId
            }
        }, /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({
            className: classNames("".concat(baseCls, "-container"), hashId, 'relative'),
            "data-be": 'list'
        }, attributes), {
            onDragStart: function(e) {
                debugInfo('List - 拖拽开始');
                store.dragStart(e, markdownContainerRef.current);
            }
        }), /*#__PURE__*/ createElement(tag, _object_spread({
            className: classNames(baseCls, hashId, isOrdered ? 'ol' : 'ul')
        }, start !== undefined && {
            start: start
        }, task && {
            'data-task': 'true'
        }), children))));
    }, [
        element.type,
        element.order,
        element.task,
        element.start,
        element.children,
        baseCls,
        hashId,
        attributes,
        children,
        store,
        markdownContainerRef,
        wrapSSR
    ]);
    return listContent;
};
