"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColumnInternalApi = exports.getAutoRowGroupColumnIdFor = void 0;
const ApiBase_1 = require("../Implementation/ApiBase");
const GeneralConstants_1 = require("../../Utilities/Constants/GeneralConstants");
function getAutoRowGroupColumnIdFor(columnId) {
    return `${GeneralConstants_1.AG_GRID_GROUPED_COLUMN}-${columnId}`;
}
exports.getAutoRowGroupColumnIdFor = getAutoRowGroupColumnIdFor;
class ColumnInternalApi extends ApiBase_1.ApiBase {
    /**
     * Retrieves 'ColumnType' property for a given Column
     *   isCumulativeAggregate(input: string): boolean {
     *     return !!this.getNodesFromExpression(input, 'CUMUL')?.length;
     *   }
     * @param columnId Column to use
     */
    getAgGridColumnType(columnId) {
        return this._adaptable.getAgGridColumnType(columnId);
    }
    /**
     * Retrieves a list providing the Friendly Name / Caption for all columns
     */
    getAllColumnFriendlyNames() {
        return this.getColumnApi()
            .getColumns()
            .map((c) => {
            return c.friendlyName;
        });
    }
    getAutoRowGroupColumnIdFor(columnId) {
        return getAutoRowGroupColumnIdFor(columnId);
    }
    /**
     * Retrieves AG Grid's field property for the column
     * @param columnId columnId to look up
     */
    getAgGridColumnFieldForAdaptableColumn(columnId) {
        const agGridColumn = this.getAgGridColumnForAdaptableColumn(columnId);
        return agGridColumn.getColDef().field || '';
    }
    /**
     * Retrieves AG Grid's column for an Adaptable column
     * @param columnId columnId to look up
     */
    getAgGridColumnForAdaptableColumn(columnId) {
        return this._adaptable.getAgGridColumnForColumnId(columnId);
    }
    getActiveColumnComparator(columnId, customSort, customSortComparer) {
        if ((!customSort || (customSort === null || customSort === void 0 ? void 0 : customSort.IsSuspended)) && !customSortComparer) {
            // defaults to AG-Grid column definition comparator if no CustomSort is defined&active
            const colDefComparator = this._adaptable.agGridColumnAdapter.getUserColDefProperty(columnId, 'comparator');
            return colDefComparator;
        }
        // CustomSort Comparer function takes precedence over CustomSort SortedValues
        const comparerFunction = customSortComparer
            ? customSortComparer.comparer
            : this.getCustomSortApi().internalApi.getDefaultCustomSortComparer(customSort.ColumnId, customSort.SortedValues);
        return comparerFunction;
    }
}
exports.ColumnInternalApi = ColumnInternalApi;
