import { h } from '@stencil/core/internal/client';
import { C as table, ai as tableHead, aj as tableHeadRow, ak as tableRow, al as tableFoot, am as tableFootRow, an as tableFootCell, ao as tableEmpty, ap as tableError, E as tableCell } from './parts.js';
import { S as Spinner } from './spinner.js';

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

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

const TableErrorState = (props) => {
    const { columnSpan, errorMessage } = props;
    if (!columnSpan || !errorMessage) {
        return null;
    }
    return (h("tr", null, h("td", { class: "error-state", part: 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 (h("tr", null, h("td", { class: "loading-state", part: tableCell, colSpan: columnSpan, style: { textAlign: 'center' } }, h(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;
    }
}

export { Table as T, TableWrapper as a, TableComponent as b, TableHead as c, TableHeadRow as d, TableBody as e, TableLoadingState as f, TableEmptyState as g, TableErrorState as h, TableRow as i, TableFoot as j, TableFootRow as k, TableFootCell as l };
