'use strict';

var index = require('./index-p7cvUYAE.js');
var parts = require('./parts-BXshb_S-.js');
var spinner = require('./spinner-C6ZGOB2P.js');

const TableWrapper = (props, children) => {
    return (index.h("div", Object.assign({ class: "table-wrapper", part: "table-wrapper" }, props), children));
};
const TableComponent = (props, children) => {
    return (index.h("table", Object.assign({ class: "table table-hover", part: parts.table }, props), children));
};
const TableBody = (props, children) => {
    return (index.h("tbody", Object.assign({ class: "table-body" }, props), children));
};
const TableRow = (props, children) => {
    return (index.h("tr", Object.assign({ part: parts.tableRow }, props), children));
};
const TableHead = (props, children) => {
    return (index.h("thead", Object.assign({ class: "table-head sticky-top", part: parts.tableHead }, props), children));
};
const TableHeadRow = (props, children) => {
    return (index.h("tr", Object.assign({ class: "table-light text-nowrap", part: parts.tableHeadRow }, props), children));
};
const TableFoot = (props, children) => {
    return (index.h("tfoot", Object.assign({ class: "sticky-bottom", part: parts.tableFoot }, props), children));
};
const TableFootRow = (props, children) => {
    return (index.h("tr", Object.assign({ class: "table-light align-middle", part: parts.tableFootRow }, props), children));
};
const TableFootCell = (props, children) => {
    return (index.h("td", Object.assign({ part: parts.tableFootCell }, props), children));
};

const TableEmptyState = (props) => {
    const { columnSpan, isEmpty } = props;
    if (!columnSpan || !isEmpty) {
        return null;
    }
    return (index.h("tr", null, index.h("td", { class: "empty-state", part: parts.tableEmpty, colSpan: columnSpan, style: { textAlign: 'center' } }, "No results")));
};

const TableErrorState = (props) => {
    const { columnSpan, errorMessage } = props;
    if (!columnSpan || !errorMessage) {
        return null;
    }
    return (index.h("tr", null, index.h("td", { class: "error-state", part: parts.tableError, colSpan: columnSpan, "data-test-id": "table-error-state", style: { textAlign: 'center' } }, "An unexpected error occurred: ", errorMessage)));
};

const TableLoadingState = (props) => {
    const { columnSpan, isLoading } = props;
    if (!columnSpan || !isLoading) {
        return null;
    }
    return (index.h("tr", null, index.h("td", { class: "loading-state", part: parts.tableCell, colSpan: columnSpan, style: { textAlign: 'center' } }, index.h(spinner.Spinner, null))));
};

class Table {
    get columnData() {
        return this.columnKeys.map((key) => this.tableColumns[key]());
    }
    get rowData() {
        return this.collection.map((dataEntry, index) => {
            return this.columnKeys.map((key) => this.tableCells[key](dataEntry, index));
        });
    }
    set collectionData(collection) {
        this.collection = collection;
    }
    constructor(collection, columns, tableColumns, tableCells) {
        this.columnKeys = columns.split(',');
        this.collection = collection;
        this.tableColumns = tableColumns;
        this.tableCells = tableCells;
    }
}

exports.Table = Table;
exports.TableBody = TableBody;
exports.TableComponent = TableComponent;
exports.TableEmptyState = TableEmptyState;
exports.TableErrorState = TableErrorState;
exports.TableFoot = TableFoot;
exports.TableFootCell = TableFootCell;
exports.TableFootRow = TableFootRow;
exports.TableHead = TableHead;
exports.TableHeadRow = TableHeadRow;
exports.TableLoadingState = TableLoadingState;
exports.TableRow = TableRow;
exports.TableWrapper = TableWrapper;
