import { jsx } from 'react/jsx-runtime';
import React__default from 'react';
import { cn } from '../../../utils/cn.js';
import { UTILITY_COLUMN_ID, alignmentClasses } from './Table.utils.js';

/**
 * Internal TableCell component used by the data-driven API
 * Handles both header and data cells with proper theming and accessibility
 *
 * @internal This component is used internally by the Table component
 */
function TableCellComponent({ column, row, rowId, isHeader = false, isFrozen = false, isLastFrozen = false, isSelected = false, theme, children, }) {
    const Cell = isHeader ? 'th' : 'td';
    const isUtilityColumn = column.id === UTILITY_COLUMN_ID;
    // For header cells, render the column header content
    if (isHeader) {
        const cellClasses = cn(theme === null || theme === void 0 ? void 0 : theme.headerStyle, isFrozen && (theme === null || theme === void 0 ? void 0 : theme.frozenColumnStyle), isLastFrozen && (theme === null || theme === void 0 ? void 0 : theme.lastFrozenColumnStyle), column.align && alignmentClasses[column.align], isUtilityColumn && 'whitespace-nowrap');
        return (jsx(Cell, { className: cellClasses, "data-frozen": isFrozen ? 'true' : isLastFrozen ? 'last' : undefined, style: { width: column.width }, role: "columnheader", "aria-label": typeof column.header === 'string' ? column.header : column.id, children: children || column.header }));
    }
    // For data cells, extract value using accessor (string key or function)
    const value = typeof column.accessor === 'function'
        ? column.accessor(row)
        : row[column.accessor];
    // Use custom cell renderer if provided, otherwise display raw value
    const content = column.cell ? column.cell(row) : value;
    // Generate tooltip content if tooltip is enabled
    const tooltipContent = typeof column.tooltip === 'function'
        ? column.tooltip(row)
        : column.tooltip
            ? String(value)
            : undefined;
    const cellClasses = cn(theme === null || theme === void 0 ? void 0 : theme.cellStyle, isFrozen && (theme === null || theme === void 0 ? void 0 : theme.frozenColumnStyle), isLastFrozen && (theme === null || theme === void 0 ? void 0 : theme.lastFrozenColumnStyle), isSelected && "bg-[var(--color-primary-50)]/50 dark:bg-[var(--color-primary-500)]/20", column.align && alignmentClasses[column.align], column.ellipsis && 'truncate', isUtilityColumn && 'whitespace-nowrap');
    return (jsx(Cell, { className: cellClasses, "data-frozen": isFrozen ? 'true' : isLastFrozen ? 'last' : undefined, style: { width: column.width }, title: tooltipContent, role: "cell", children: children || content }));
}
TableCellComponent.displayName = 'TableCell';
const TableCell = React__default.memo(TableCellComponent);

export { TableCell };
