/* eslint-disable @typescript-eslint/no-redeclare */ /* eslint-disable @typescript-eslint/no-use-before-define */ 'use client';
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 React from "react";
import { useSlateSelection } from "slate-react";
import { useSelStatus } from "../../../hooks/editor";
// 原生表格编辑器已集成
import { SimpleTable } from "./SimpleTable";
import { TableCellIndex } from "./TableCellIndex";
import { Td } from "./Td";
/**
 * Th 组件 - 表格头部单元格组件
 *
 * 该组件用于渲染表格的头部单元格，支持选择状态显示和样式自定义。
 * 集成到 Slate 编辑器中，提供表格编辑功能。
 *
 * @component
 * @description 表格头部单元格组件，渲染表格头部
 * @param {RenderElementProps & {style?: React.CSSProperties}} props - 组件属性
 * @param {Object} props.attributes - 元素属性
 * @param {React.ReactNode} props.children - 子组件内容
 * @param {React.CSSProperties} [props.style] - 自定义样式
 * @param {Element} props.element - 表格头部元素
 *
 * @example
 * ```tsx
 * <Th
 *   attributes={attributes}
 *   element={headerElement}
 *   style={{ fontWeight: 'bold' }}
 * >
 *   表头内容
 * </Th>
 * ```
 *
 * @returns {React.ReactElement} 渲染的表格头部单元格组件
 *
 * @remarks
 * - 集成 Slate 编辑器
 * - 支持选择状态高亮
 * - 提供自定义样式支持
 * - 类型安全检查
 * - 响应式布局
 */ export var Th = function(param) {
    var attributes = param.attributes, children = param.children, style = param.style, element = param.element;
    if (element.type !== 'header-cell') {
        throw new Error('Element "Th" must be of type "header-cell"');
    }
    useSlateSelection();
    // 简化的选中状态检查 - 暂时返回 false，后续可以完善
    var selected = false;
    return /*#__PURE__*/ React.createElement("th", _object_spread({
        style: _object_spread({
            backgroundColor: selected ? '#bae6fd' : undefined
        }, style)
    }, attributes), children);
};
// 包装组件，用于在组件内部调用 hooks
var ThWrapper = function(props) {
    return /*#__PURE__*/ React.createElement(Th, props);
};
var TdWrapper = function(props) {
    var _useSelStatus = _sliced_to_array(useSelStatus(props.element), 2), path = _useSelStatus[1];
    return /*#__PURE__*/ React.createElement(Td, _object_spread_props(_object_spread({}, props), {
        cellPath: path
    }));
};
var TableCellIndexWrapper = function(param) {
    var targetRow = param.targetRow;
    var _useSelStatus = _sliced_to_array(useSelStatus(targetRow), 2), path = _useSelStatus[1];
    // 从路径中提取行索引和表格路径
    var rowIndex = path ? path[path.length - 1] : undefined;
    var tablePath = path ? path.slice(0, -1) : undefined;
    return /*#__PURE__*/ React.createElement(TableCellIndex, {
        targetRow: targetRow,
        rowIndex: rowIndex,
        tablePath: tablePath
    });
};
// 导出组件供测试使用
export { Td } from "./Td";
export var tableRenderElement = function(props, config) {
    switch(props.element.type){
        case 'table':
            return /*#__PURE__*/ React.createElement(SimpleTable, props);
        case 'table-head':
            return /*#__PURE__*/ React.createElement("thead", _object_spread({
                style: {
                    borderBottomWidth: '1px',
                    borderBottomStyle: 'solid',
                    borderBottomColor: '#e5e7eb',
                    fontSize: '13px',
                    textTransform: 'uppercase',
                    backgroundColor: '#f1f5f9'
                }
            }, props.attributes), props.children);
        case 'table-footer':
            return /*#__PURE__*/ React.createElement("tfoot", props.attributes, props.children);
        case 'table-row':
            return /*#__PURE__*/ React.createElement("tr", props.attributes, (config === null || config === void 0 ? void 0 : config.readonly) ? null : /*#__PURE__*/ React.createElement(TableCellIndexWrapper, {
                targetRow: props.element
            }), props.children);
        case 'header-cell':
            return /*#__PURE__*/ React.createElement(ThWrapper, _object_spread({
                style: {
                    verticalAlign: 'middle'
                }
            }, props));
        case 'table-cell':
            return /*#__PURE__*/ React.createElement(TdWrapper, _object_spread({
                style: {
                    verticalAlign: 'middle'
                }
            }, props));
        default:
            return null;
    }
};
