"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableDataModel = void 0;
class TableDataModel {
    constructor(args) {
        this.resultsRunner = args.resultsRunner;
        this.columnsConfig =
            args.columnsConfig ?? this.getResultOptions().defaultColumnConfig;
    }
    getColumns() {
        return this.resultsRunner.getColumnNames();
    }
    getVisibleColumns() {
        return this.getColumns().filter((column) => this.columnsConfig ? this.columnsConfig[column]?.visible : true);
    }
    getRows() {
        return this.resultsRunner.getRows();
    }
    getRowsCount() {
        return this.getRows().length;
    }
    getColumnsCount() {
        return this.getColumns().length;
    }
    static getTableHeaderSortConfig(columnNames, query) {
        return columnNames.reduce((acc, col) => {
            const sortBy = query.sortBy.find((sort) => sort.name === col);
            return {
                ...acc,
                [col]: {
                    direction: sortBy?.direction,
                },
            };
        }, {});
    }
    getResultOptions() {
        const columns = this.getColumns().reduce((acc, key) => ({
            ...acc,
            [key]: {
                visible: this.columnsConfig?.[key]?.visible ?? true,
                reference: key,
                label: this.columnsConfig?.[key]?.label ?? key,
                frozen: this.columnsConfig?.[key]?.frozen ?? false,
            },
        }), {});
        return { defaultColumnConfig: columns };
    }
    getConfig() {
        return this.columnsConfig;
    }
    static getColumnsAccessorFn(column) {
        return (row) => row[column];
    }
    mergeConfig(chartKind) {
        return {
            type: chartKind,
            display: {},
            metadata: {
                version: 1,
            },
            columns: this.getResultOptions().defaultColumnConfig,
        };
    }
    // eslint-disable-next-line class-methods-use-this
    async getPivotedChartData() {
        // Not implemented in table yet
        return {
            queryUuid: undefined,
            columns: [],
            fileUrl: '',
            indexColumn: undefined,
            results: [],
            valuesColumns: [],
            columnCount: undefined,
        };
    }
    // eslint-disable-next-line class-methods-use-this
    getDataDownloadUrl() {
        // Not implemented in table yet
        return '';
    }
    getPivotedTableData() {
        return {
            columns: this.getColumns(),
            rows: this.getRows(),
        };
    }
    // eslint-disable-next-line class-methods-use-this
    getSpec(_display) {
        return {
            spec: {
                columns: this.columnsConfig,
                visibleColumns: this.getVisibleColumns(),
            },
            tableData: undefined,
        };
    }
}
exports.TableDataModel = TableDataModel;
//# sourceMappingURL=TableDataModel.js.map