function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
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 _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { ConfigProvider, Skeleton } from "antd";
import classNames from "classnames";
import React, { useContext, useEffect, useMemo, useState } from "react";
import { ReactEditor, useSlate } from "slate-react";
import { useTableStyle } from "./style";
import { SlateTable } from "./Table";
import { TablePropsProvider } from "./TableContext";
/**
 * 简单表格组件 - 仅支持只读显示
 * 用于替代复杂的 Handsontable 实现，提供基础的表格功能
 */ export var SimpleTable = function(props) {
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var baseCls = getPrefixCls('agentic-md-editor-content-table');
    var editor = useSlate();
    var _useTableStyle = useTableStyle(baseCls, {}), wrapSSR = _useTableStyle.wrapSSR, hashId = _useTableStyle.hashId;
    var _useState = _sliced_to_array(useState(false), 2), showAsText = _useState[0], setShowAsText = _useState[1];
    var tableNode = props.element;
    var tablePath = useMemo(function() {
        return ReactEditor.findPath(editor, props.element);
    }, [
        props.element
    ]);
    // 如果 finished 为 false，设置 5 秒超时，超时后显示为文本
    useEffect(function() {
        if (tableNode.finished === false) {
            setShowAsText(false);
            var timer = setTimeout(function() {
                setShowAsText(true);
            }, 5000);
            return function() {
                clearTimeout(timer);
            };
        } else {
            setShowAsText(false);
        }
    }, [
        tableNode.finished
    ]);
    // 如果是不完整状态
    if (tableNode.finished === false) {
        // 如果 5 秒后仍未完成，显示为文本
        if (showAsText) {
            return /*#__PURE__*/ React.createElement("div", props.attributes, /*#__PURE__*/ React.createElement("div", {
                style: {
                    padding: '8px 12px',
                    border: '1px solid #d9d9d9',
                    borderRadius: '4px',
                    color: 'rgba(0, 0, 0, 0.65)',
                    wordBreak: 'break-all'
                }
            }, "表格链接"), props.children);
        }
        // 5 秒内显示加载骨架屏
        return /*#__PURE__*/ React.createElement("div", props.attributes, /*#__PURE__*/ React.createElement(Skeleton, {
            active: true,
            paragraph: {
                rows: 3
            }
        }), props.children);
    }
    return wrapSSR(/*#__PURE__*/ React.createElement(TablePropsProvider, {
        tablePath: tablePath,
        tableNode: props.element
    }, /*#__PURE__*/ React.createElement("div", _object_spread_props(_object_spread({}, props.attributes), {
        "data-be": 'table',
        draggable: false,
        className: classNames("".concat(baseCls, "-container"), hashId),
        style: {
            position: 'relative'
        }
    }), /*#__PURE__*/ React.createElement(SlateTable, _object_spread_props(_object_spread({}, props), {
        hashId: hashId
    }), props.children))));
};
