import { h } from './core-34fac203.js';
import { d as concatClasses } from './utils-3aef1637.js';
import { T as TableClasses } from './table.utils-2f05f2ec.js';
import { a as ColumnRenderer } from './column.renderer-85fb4a57.js';

const Td = ({ classList, column, columnIndex, offset, renderer, row, rowIndex }) => {
    const attrs = ColumnRenderer.columnAttributes(column, columnIndex, row);
    const refFn = r => column.initCell(r, offset);
    // TODO: abstract this out better
    if (column.cellTemplate) {
        return h("td", Object.assign({}, attrs, { class: classList, ref: r => renderer.cellTemplate(r, offset, column, row, rowIndex, column.cellTemplate) }));
    }
    else if (column.cellFormatter) {
        return h("td", Object.assign({}, attrs, { class: classList, innerHTML: column.cellFormatter(row, column, rowIndex), ref: refFn }));
    }
    else {
        return h("td", Object.assign({}, attrs, { class: classList, ref: refFn }), column.cellRenderer(row, column, rowIndex));
    }
};

const Tr = ({ classList }, children) => (h("tr", { tabindex: "0", class: classList }, children));

const Row = ({ columns, offsets, pinBoundaries, renderer, row, rowIndex, cellRenderers }, children) => [
    h(Tr, { classList: TableClasses.row }, columns.map((column, columnIndex) => {
        const props = {
            classList: concatClasses(ColumnRenderer.columnCellClasses(column), ColumnRenderer.pinnedBorderClass(columnIndex, pinBoundaries)),
            column,
            columnIndex,
            offset: offsets[columnIndex],
            renderer,
            row,
            rowIndex
        };
        return column.internal ? h(Td, Object.assign({}, props)) : cellRenderers.find(r => r.when(column, rowIndex, columnIndex)).cell(props);
    })),
    children
];

export { Row as R, Tr as T, Td as a };
