/**
 * NestedGrid - 嵌套表格类
 * 用于在单元格内渲染子表格，使用 ViewerRegistry 渲染单元格
 */
import type DataGrid from "./DataGrid";
import Paint from "./Paint";
interface NestedColumn {
    title: string;
    key: string;
    width?: number;
    align?: string;
    type?: string;
    viewerType?: string;
    options?: any[];
    originalViewer?: string;
    canEdit?: boolean;
    isLink?: boolean;
    linkKey?: string;
    fileMeta?: string;
    [key: string]: any;
}
interface NestedData {
    [key: string]: any;
}
/** 矩形选区范围 */
interface SelectionRange {
    startRow: number;
    startCol: number;
    endRow: number;
    endCol: number;
}
/** 选区锚点（鼠标按下或 Shift 参考点） */
interface SelectionAnchor {
    row: number;
    col: number;
}
interface NestedGridOptions {
    columns: NestedColumn[];
    data: NestedData[];
    x: number;
    y: number;
    width: number;
    height: number;
    parentGrid: DataGrid;
    parentCell: any;
    displayRows?: number;
    hasMore?: boolean;
}
declare class NestedGrid {
    columns: NestedColumn[];
    data: NestedData[];
    x: number;
    y: number;
    width: number;
    height: number;
    parentGrid: DataGrid;
    parentCell: any;
    painter: Paint;
    rowHeight: number;
    scrollY: number;
    hoveredCell: {
        col: number;
        row: number;
    } | null;
    hoverRowIndex: number;
    selectedCell: {
        col: number;
        row: number;
    } | null;
    editingCell: {
        col: number;
        row: number;
    } | null;
    displayRows?: number;
    expanded: boolean;
    expandButtonHeight: number;
    expandButtonHovered: boolean;
    hasMore: boolean;
    parentRowBgColor: string | undefined;
    private redrawScheduled;
    private redrawTimer;
    private _lastHoverViewerType;
    private _lastHoverViewerData;
    selectionRange: SelectionRange | null;
    selectionAnchor: SelectionAnchor | null;
    selectionEnd: SelectionAnchor | null;
    additionalSelectedCells: Set<string>;
    isSelecting: boolean;
    autofill: {
        enable: boolean;
        /** autofill 拖拽区域范围 */
        range: SelectionRange | null;
        /** 是否为主动发起 autofill 的子表（区分跨子表场景中被动设置的子表） */
        isSource: boolean;
    };
    /** 标记刚刚完成了 autofill 拖拽，用于跳过紧接着的 click 事件触发的编辑 */
    justFinishedAutofill: boolean;
    private offscreenCanvas;
    private offscreenCtx;
    private cacheValid;
    private lastDataHash;
    progressDrag: {
        isDragging: boolean;
        cell: {
            col: number;
            row: number;
        } | null;
        startValue: number;
        currentValue: number;
    };
    rowDrag: {
        pending: boolean;
        isDragging: boolean;
        fromRowIndex: number;
        currentRowIndex: number;
        position: 'front' | 'tail' | null;
        mouseDownY: number;
        ghostEl: HTMLDivElement | null;
    };
    constructor(options: NestedGridOptions);
    getColumnWidth(index: number): number;
    getCellBounds(colIndex: number, rowIndex: number): {
        x: number;
        y: number;
        width: number;
        height: number;
    };
    getRequiredHeight(): number;
    getVisibleRowCount(): number;
    needExpandButton(): boolean;
    isMouseInsideAbsolute(mouseX: number, mouseY: number): boolean;
    isMouseInside(mouseX: number, mouseY: number): boolean;
    isMouseOnExpandButton(mouseX: number, mouseY: number): boolean;
    getCellAtPosition(mouseX: number, mouseY: number): {
        col: number;
        row: number;
    } | null;
    handleMouseMove(mouseX: number, mouseY: number): boolean;
    /**
     * Reset the last hovered viewer's state (e.g. hide image popper).
     * Called when mouse leaves the nested grid or moves to non-cell areas.
     */
    resetLastHoverViewer(): void;
    private isProgressCell;
    private isMouseOnProgressBar;
    handleMouseDown(mouseX: number, mouseY: number, e?: {
        ctrlKey?: boolean;
        metaKey?: boolean;
        shiftKey?: boolean;
        altKey?: boolean;
        button?: number;
    }): boolean;
    private handleProgressDragMove;
    handleMouseUp(_mouseX: number, _mouseY: number): boolean;
    isMouseOnEditIcon(mouseX: number, mouseY: number, cell: {
        col: number;
        row: number;
    }): boolean;
    isCellEditable(colIndex: number, rowIndex?: number): boolean;
    getSelectLabel(colIndex: number, value: any): string;
    /**
     * 处理右键菜单事件，返回上下文信息
     * @param mouseX 鼠标相对于嵌套表格的 X 坐标
     * @param mouseY 鼠标相对于嵌套表格的 Y 坐标
     * @param clientX 鼠标屏幕 X 坐标（用于菜单定位）
     * @param clientY 鼠标屏幕 Y 坐标（用于菜单定位）
     * @returns 右键菜单上下文信息
     */
    handleContextMenu(mouseX: number, mouseY: number, clientX: number, clientY: number): {
        nestedRowData: NestedData | null;
        nestedRowIndex: number;
        nestedColKey: string;
        nestedColIndex: number;
        parentRowData: any;
        parentColKey: string;
        selectionRange: SelectionRange | null;
        clientX: number;
        clientY: number;
    };
    /**
     * 处理点击事件，返回点击信息
     * @param mouseX 鼠标相对于嵌套表格的 X 坐标
     * @param mouseY 鼠标相对于嵌套表格的 Y 坐标
     * @returns 点击信息对象，如果没有点击到有效区域则返回 null
     */
    handleClick(mouseX: number, mouseY: number): {
        type: 'expand' | 'cell' | 'editIcon' | 'booleanToggle' | 'viewerClick';
        cell?: {
            row: number;
            col: number;
        };
        needsRedraw?: boolean;
        expandInfo?: {
            parentId: any;
            moduleColkey: string;
            expanded: boolean;
        };
        editInfo?: {
            bounds: {
                x: number;
                y: number;
                width: number;
                height: number;
            };
            column: NestedColumn;
            value: any;
            rowData: NestedData;
            parentRowData: any;
            parentColKey: string;
        };
    } | null;
    /**
     * Handle double-click inside nested grid.
     * Delegates to viewer.onDblClick (e.g. FileViewer opens file detail on dblclick).
     * Returns true if the double-click was handled by a viewer.
     */
    handleDblClick(mouseX: number, mouseY: number): {
        type: 'editIcon';
        cell: {
            row: number;
            col: number;
        };
        editInfo: {
            bounds: {
                x: number;
                y: number;
                width: number;
                height: number;
            };
            column: any;
            value: any;
            rowData: any;
            parentRowData: any;
            parentColKey: string;
        };
    } | null;
    /**
     * Check if mouse is on the boolean checkbox area within a cell
     */
    private isMouseOnBooleanCheckbox;
    /**
     * 获取单元格的编辑信息
     * @param colIndex 列索引
     * @param rowIndex 行索引
     * @returns 单元格编辑信息
     */
    getCellEditInfo(colIndex: number, rowIndex: number): {
        bounds: {
            x: number;
            y: number;
            width: number;
            height: number;
        };
        column: NestedColumn;
        value: any;
        displayValue: string;
        rowData: NestedData;
    };
    /**
     * 启动编辑（已废弃，编辑器启动逻辑已移至 Events.ts）
     * 保留此方法是为了兼容性
     */
    startEdit(colIndex: number, rowIndex: number): void;
    updateParentRowHeight(): void;
    updateRowHeight(newRowHeight: number): void;
    finishEdit(value: any): void;
    cancelEdit(): void;
    draw(): void;
    /**
     * 绘制选区覆盖层（选区边框、autofill 手柄、autofill 虚线边框）。
     * 必须在 Cell.draw() 的 ctx.restore()（解除 clip）之后调用，
     * 以避免 autofill 手柄等突出 Cell 边界的元素被裁剪掉。
     */
    drawOverlays(): void;
    /**
     * 创建跟随鼠标的 DOM 浮层（Alt 子行拖动排序专用）。
     * 样式与主表 DataGrid.createDragGhostEl 对齐，显示被拖子行的 name 字段值。
     */
    private createRowDragGhostEl;
    /**
     * 更新浮层位置，读取 DataGrid 缓存的最新鼠标 client 坐标（Events.ts handleMouseMove 中写入）。
     */
    private updateRowDragGhostPosition;
    /**
     * 从 DOM 中移除浮层元素。
     */
    private removeRowDragGhostEl;
    clearOtherNestedGridsSelection(): void;
    /**
     * 收集同列所有有选区的嵌套子表信息，触发 onNestedSelectionChange 回调
     */
    notifySelectionChange(): void;
    /**
     * 外部设置选区（跨子表框选时由 Events.ts 调用）
     */
    setExternalSelection(range: SelectionRange): void;
    /**
     * 清除当前子表格的所有选中状态
     */
    clearSelection(): void;
    /**
     * 根据锚点和结束点计算矩形选区范围
     */
    computeSelectionRange(anchor: SelectionAnchor, end: SelectionAnchor): SelectionRange;
    /**
     * 获取选区右下角 autofill 拖拽手柄的像素坐标（相对于嵌套表格本身，不含 this.x/this.y 偏移）
     * 手柄为 6×6 像素的小方块，居中于选区右下角交点
     */
    getAutofillCornerBounds(): {
        x: number;
        y: number;
        size: number;
    } | null;
    /**
     * 检测鼠标是否在 autofill 拖拽手柄上（相对坐标，即 mouseX/mouseY 已减去 this.x/this.y）
     */
    isInAutofillCorner(mouseX: number, mouseY: number): boolean;
    /**
     * 开始 autofill 拖拽
     */
    startAutofill(shiftKey?: boolean): void;
    /**
     * 结束 autofill 拖拽
     */
    endAutofill(): void;
    /**
     * 清除 autofill 状态
     */
    clearAutofill(): void;
    /**
     * 外部设置 autofill 范围（跨子表 autofill 拖拽时由 Events.ts 调用）。
     * 会同时设置 autofill.enable = true，这样绘制逻辑会渲染虚线边框和浅色高亮。
     */
    setExternalAutofill(range: SelectionRange): void;
    /**
     * 清除外部设置的 autofill 范围，同时重置 enable 标记
     */
    clearExternalAutofill(): void;
    /**
     * 判断某个 (row, col) 是否在选区内（矩形范围 或 散点多选）
     */
    isCellInSelection(row: number, col: number): boolean;
    /**
     * 获取所有选中的格子数组（从 selectionRange + additionalSelectedCells 推导）
     */
    getSelectedCells(): Array<{
        row: number;
        col: number;
    }>;
    /**
     * 性能优化：确保离屏 Canvas 存在且尺寸正确
     */
    private ensureOffscreenCanvas;
    /**
     * 性能优化：计算数据哈希，用于检测数据变化
     * 使用简化的哈希方法，避免深度比较的性能开销
     */
    private computeDataHash;
    /**
     * 使缓存失效（数据变化时调用）
     */
    invalidateCache(): void;
    /**
     * 增量更新：替换整个数据数组
     * @param newData 新的数据数组
     * @param redraw 是否立即重绘（默认 true）
     */
    updateData(newData: NestedData[], redraw?: boolean): void;
    /**
     * 增量更新：替换指定行的数据
     * @param rowIndex 行索引
     * @param rowData 新的行数据
     * @param redraw 是否立即重绘（默认 true）
     */
    updateRow(rowIndex: number, rowData: NestedData, redraw?: boolean): void;
    /**
     * 增量更新：更新指定单元格的值
     * @param rowIndex 行索引
     * @param colKey 列 key
     * @param value 新值
     * @param redraw 是否立即重绘（默认 true）
     */
    updateCell(rowIndex: number, colKey: string, value: any, redraw?: boolean): void;
    private getDisplayValue;
    /**
     * 使用 ViewerRegistry 渲染嵌套表格的单元格
     */
    private drawCellWithViewer;
    /**
     * 构建嵌套表格单元格的 ViewerRenderContext
     */
    private buildNestedViewerContext;
    /**
     * 构建嵌套表格单元格的 CellViewerData
     * 处理不同类型数据的包装和转换
     */
    private buildNestedViewerData;
    /**
     * Draw loading indicator for a nested cell.
     * Mirrors Cell.drawLoadingIndicator logic: rotating icon at cell right side.
     */
    private drawNestedLoadingIndicator;
    /**
     * 兜底文本渲染（当 viewer 不可用时）
     */
    private drawFallbackText;
    private drawPersonCell;
    private drawStatusCell;
    private drawProgressCell;
    private drawDatetimeCell;
    private drawBooleanCell;
    private drawPlaceholderText;
    private drawRoundedRect;
    private truncateText;
    private getPersonInitial;
    private hashString;
    private scheduleRedraw;
    updatePosition(x: number, y: number): void;
}
export default NestedGrid;
