"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GridInfoPopup = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const ArrayExtensions_1 = tslib_1.__importDefault(require("../../../Utilities/Extensions/ArrayExtensions"));
const EnvVars_1 = require("../../../EnvVars");
const AgGridModulesAdapter_1 = require("../../../agGrid/AgGridModulesAdapter");
const InfiniteTable_1 = require("../../../components/InfiniteTable");
const Panel_1 = tslib_1.__importDefault(require("../../../components/Panel"));
const Tabs_1 = require("../../../components/Tabs");
const PopupPanel_1 = require("../../Components/Popups/AdaptablePopup/PopupPanel");
const AdaptableObjectsSummary_1 = require("./AdaptableObjectsSummary");
const clsx_1 = tslib_1.__importDefault(require("clsx"));
const adaptableVersion = EnvVars_1.ADAPTABLE_VERSION;
const agGridVersion = AgGridModulesAdapter_1.AG_GRID_VERSION;
const GridInfoPopup = (props) => {
    const api = props.api;
    const keyValuePairs = [];
    const calcColumns = api.calculatedColumnApi
        .getCalculatedColumns()
        .map((c) => c.ColumnId);
    const actionColumns = api.actionColumnApi
        .getActionColumns()
        .map((ac) => ac.columnId);
    const freeTextColumns = api.freeTextColumnApi
        .getFreeTextColumns()
        .map((c) => c.ColumnId);
    const columnFilterDescription = api.filterApi.columnFilterApi.columnFiltersToString(api.filterApi.columnFilterApi.getColumnFilters());
    const gridFilterExpression = api.filterApi.gridFilterApi.getCurrentGridFilterExpression();
    const sorts = ArrayExtensions_1.default.IsNotNullOrEmpty(props.api.gridApi.getColumnSorts())
        ? api.gridApi.getColumnSorts().map((gs) => {
            return api.columnApi.getFriendlyNameForColumnId(gs.ColumnId) + ': ' + gs.SortOrder;
        })
        : null;
    const selectedRowInfo = api.gridApi.getSelectedRowInfo();
    if (api.optionsApi.getUserInterfaceOptions()?.showAdapTableVersion) {
        keyValuePairs.push({ Key: 'AdapTable Version', Value: adaptableVersion });
    }
    if (api.optionsApi.getUserInterfaceOptions()?.showAgGridVersion) {
        keyValuePairs.push({ Key: 'AG Grid Version', Value: agGridVersion });
    }
    keyValuePairs.push({ Key: 'Sorted Columns', Value: ArrayExtensions_1.default.IsNotNullOrEmpty(sorts) ? sorts.join('; ') : 'None' });
    keyValuePairs.push({ Key: 'Column Filters', Value: columnFilterDescription });
    keyValuePairs.push({ Key: 'Grid Filter', Value: gridFilterExpression });
    keyValuePairs.push({ Key: 'All Rows', Value: props.api.gridApi.getRowCount() });
    keyValuePairs.push({ Key: 'Visible Rows', Value: props.api.gridApi.getVisibleRowCount() });
    keyValuePairs.push({ Key: 'Selected Rows', Value: selectedRowInfo?.gridRows.length });
    keyValuePairs.push({ Key: 'Visible Selected Rows', Value: selectedRowInfo?.gridRows.filter((gr) => gr.rowNode?.displayed == true).length });
    keyValuePairs.push({ Key: 'All Columns', Value: props.api.gridApi.getColumnCount() });
    keyValuePairs.push({ Key: 'Visible Columns', Value: props.api.gridApi.getVisibleColumnCount() });
    keyValuePairs.push({ Key: 'Calculated Columns', Value: ArrayExtensions_1.default.IsNotNullOrEmpty(calcColumns)
            ? ArrayExtensions_1.default.createCommaSeparatedString(calcColumns)
            : 'None' });
    keyValuePairs.push({ Key: 'Free Text Columns', Value: ArrayExtensions_1.default.IsNotNullOrEmpty(freeTextColumns)
            ? ArrayExtensions_1.default.createCommaSeparatedString(freeTextColumns)
            : 'None' });
    keyValuePairs.push({ Key: 'CalcuActionlated Columns', Value: ArrayExtensions_1.default.IsNotNullOrEmpty(actionColumns)
            ? ArrayExtensions_1.default.createCommaSeparatedString(actionColumns)
            : 'None' });
    const domProps = {
        className: 'twa:flex-1 twa:min-h-0 twa:w-full',
    };
    keyValuePairs.map((keyValuePair) => {
        return {
            Key: keyValuePair.Key,
            Value: keyValuePair.Value === 'Ignore' ? null : keyValuePair.Value,
        };
    })
        .filter((x) => x.Value);
    const columnsMap = {
        Key: { field: 'Key', header: 'Property', defaultFlex: 1 },
        Value: { field: 'Value', header: 'Value', defaultFlex: 3 },
    };
    const baseClassName = 'ab-GridInfo';
    return (React.createElement(PopupPanel_1.PopupPanel, { className: (0, clsx_1.default)(baseClassName), headerText: 'Grid Info', glyphicon: 'info', scrollable: false },
        React.createElement(Panel_1.default, { className: "twa:flex-1 twa:border-none twa:shadow-md twa:overflow-hidden" },
            React.createElement(Panel_1.default.FlexBody, null,
                React.createElement(Tabs_1.Tabs, { className: "twa:flex-1 twa:min-h-0" },
                    React.createElement(Tabs_1.Tabs.Tab, null, "Grid Summary"),
                    React.createElement(Tabs_1.Tabs.Tab, null, "Grid State"),
                    React.createElement(Tabs_1.Tabs.Content, null,
                        React.createElement(InfiniteTable_1.DataSource, { data: keyValuePairs, primaryKey: "Key" },
                            React.createElement(InfiniteTable_1.InfiniteTableGrid, { domProps: domProps, columns: columnsMap }))),
                    React.createElement(Tabs_1.Tabs.Content, null,
                        React.createElement(AdaptableObjectsSummary_1.AdaptableObjectsSummary, { className: "twa:min-h-0 twa:overflow-auto twa:p-2" })))))));
};
exports.GridInfoPopup = GridInfoPopup;
