import { h } from './core-15e24a78.js';
import { d as concatClasses } from './utils-3aef1637.js';
import { T as TableClasses } from './table.utils-259f424b.js';
import { C as ColumnRenderer } from './column.renderer-5d1eab0d.js';
var Td = function (_a) {
    var classList = _a.classList, column = _a.column, columnIndex = _a.columnIndex, offset = _a.offset, renderer = _a.renderer, row = _a.row, rowIndex = _a.rowIndex;
    var attrs = ColumnRenderer.columnAttributes(column, columnIndex, row);
    var refFn = function (r) { return column.initCell(r, offset); };
    // TODO: abstract this out better
    if (column.cellTemplate) {
        return h("td", Object.assign({}, attrs, { class: classList, ref: function (r) { return 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));
    }
};
var Tr = function (_a, children) {
    var classList = _a.classList;
    return (h("tr", { tabindex: "0", class: classList }, children));
};
var Row = function (_a, children) {
    var columns = _a.columns, offsets = _a.offsets, pinBoundaries = _a.pinBoundaries, renderer = _a.renderer, row = _a.row, rowIndex = _a.rowIndex, cellRenderers = _a.cellRenderers;
    return [
        h(Tr, { classList: TableClasses.row }, columns.map(function (column, columnIndex) {
            var props = {
                classList: concatClasses(ColumnRenderer.columnCellClasses(column), ColumnRenderer.pinnedBorderClass(columnIndex, pinBoundaries)),
                column: column,
                columnIndex: columnIndex,
                offset: offsets[columnIndex],
                renderer: renderer,
                row: row,
                rowIndex: rowIndex
            };
            return column.internal ? h(Td, Object.assign({}, props)) : cellRenderers.find(function (r) { return r.when(column, rowIndex, columnIndex); }).cell(props);
        })),
        children
    ];
};
export { Row as R, Tr as T, Td as a };
