'use strict';

const core = require('./core-b7b9d752.js');
const utils = require('./utils-2a7c8f6e.js');
const table_utils = require('./table.utils-12a2d306.js');
const column_renderer = require('./column.renderer-62044f6a.js');

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

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

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

exports.Row = Row;
exports.Td = Td;
exports.Tr = Tr;
