"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 rebass_1 = require("rebass");
const Panel_1 = tslib_1.__importDefault(require("../../../components/Panel"));
const Tabs_1 = require("../../../components/Tabs");
const ArrayExtensions_1 = tslib_1.__importDefault(require("../../../Utilities/Extensions/ArrayExtensions"));
const Helper_1 = tslib_1.__importDefault(require("../../../Utilities/Helpers/Helper"));
const AdaptablePopover_1 = require("../../AdaptablePopover");
const AdaptableObjectCollection_1 = require("../../Components/AdaptableObjectCollection");
const AdaptableObjectRow_1 = require("../../Components/AdaptableObjectRow");
const PopupPanel_1 = require("../../Components/Popups/AdaptablePopup/PopupPanel");
const AdaptableObjectsSummary_1 = require("./AdaptableObjectsSummary");
const EnvVars_1 = require("../../../EnvVars");
const version = EnvVars_1.ADAPTABLE_VERSION;
const GridInfoPopup = (props) => {
    const CreateGridSummaries = (colItems) => {
        var _a;
        const returnRows = [];
        const calcColumns = props.api.calculatedColumnApi
            .getCalculatedColumns()
            .map((c) => c.ColumnId);
        const actionColumns = props.api.actionColumnApi
            .getActionColumns()
            .map((ac) => ac.columnId);
        const freeTextColumns = props.api.freeTextColumnApi
            .getFreeTextColumns()
            .map((c) => c.ColumnId);
        const columnFilterDescription = props.api.columnFilterApi.internalApi.columnFiltersToString(props.api.columnFilterApi.getColumnFilters());
        const gridFilterExpression = props.api.gridFilterApi.getCurrentGridFilterExpression();
        const sorts = ArrayExtensions_1.default.IsNotNullOrEmpty(props.api.gridApi.getColumnSorts())
            ? props.api.gridApi.getColumnSorts().map((gs) => {
                return props.api.columnApi.getFriendlyNameForColumnId(gs.ColumnId) + ': ' + gs.SortOrder;
            })
            : null;
        const selectedRowInfo = props.api.gridApi.getSelectedRowInfo();
        if ((_a = props.api.optionsApi.getUserInterfaceOptions()) === null || _a === void 0 ? void 0 : _a.showAdapTableVersion) {
            returnRows.push(createReadOnlyColItem(colItems, 'AdapTable Version', version));
        }
        returnRows.push(createReadOnlyColItem(colItems, 'Sorted Columns', ArrayExtensions_1.default.IsNotNullOrEmpty(sorts) ? sorts.join('; ') : 'None'));
        returnRows.push(createReadOnlyColItem(colItems, 'Column Filters', columnFilterDescription));
        returnRows.push(createReadOnlyColItem(colItems, 'Grid Filter', gridFilterExpression));
        returnRows.push(createReadOnlyColItem(colItems, 'All Rows', props.api.gridApi.getRowCount()));
        returnRows.push(createReadOnlyColItem(colItems, 'Visible Rows', props.api.gridApi.getVisibleRowCount()));
        returnRows.push(createReadOnlyColItem(colItems, 'Selected Rows', selectedRowInfo === null || selectedRowInfo === void 0 ? void 0 : selectedRowInfo.gridRows.length));
        returnRows.push(createReadOnlyColItem(colItems, 'Visible Selected Rows', selectedRowInfo === null || selectedRowInfo === void 0 ? void 0 : selectedRowInfo.gridRows.filter((gr) => { var _a; return ((_a = gr.rowNode) === null || _a === void 0 ? void 0 : _a.displayed) == true; }).length));
        returnRows.push(createReadOnlyColItem(colItems, 'All Columns', props.api.gridApi.getColumnCount()));
        returnRows.push(createReadOnlyColItem(colItems, 'Visible Columns', props.api.gridApi.getVisibleColumnCount()));
        returnRows.push(createReadOnlyColItem(colItems, 'Calculated Columns', ArrayExtensions_1.default.IsNotNullOrEmpty(calcColumns) ? calcColumns : 'None'));
        returnRows.push(createReadOnlyColItem(colItems, 'Free Text Columns', ArrayExtensions_1.default.IsNotNullOrEmpty(freeTextColumns) ? freeTextColumns : 'None'));
        returnRows.push(createReadOnlyColItem(colItems, 'Action Columns', ArrayExtensions_1.default.IsNotNullOrEmpty(actionColumns) ? actionColumns : 'None'));
        return returnRows;
    };
    const createReadOnlyColItem = (colItems, item1, item2, item3) => {
        let rowColItems = Helper_1.default.cloneObject(colItems);
        rowColItems[0].Content = item1;
        rowColItems[1].Content = item2;
        if (item3) {
            let infoButton = React.createElement(AdaptablePopover_1.AdaptablePopover, { headerText: null, bodyText: [item3] });
            rowColItems[2].Content = infoButton;
        }
        return rowColItems;
    };
    let propValueColItems = [
        { Content: 'Property', Size: 5 },
        { Content: 'Value', Size: 7 },
    ];
    let gridSummaries = CreateGridSummaries(propValueColItems).map((x, index) => {
        return React.createElement(AdaptableObjectRow_1.AdaptableObjectRow, { key: index, colItems: x });
    });
    const baseClassName = 'ab-GridInfo';
    return (React.createElement(PopupPanel_1.PopupPanel, { className: baseClassName, headerText: 'Grid Info', glyphicon: 'info' },
        React.createElement(rebass_1.Flex, { flexDirection: "column", flex: 1, height: "100%" },
            React.createElement(Panel_1.default, { flex: 1 },
                React.createElement(Tabs_1.Tabs, null,
                    React.createElement(Tabs_1.Tabs.Tab, null, "Grid Summary"),
                    React.createElement(Tabs_1.Tabs.Tab, null, "Grid Config"),
                    React.createElement(Tabs_1.Tabs.Content, null,
                        React.createElement(AdaptableObjectCollection_1.AdaptableObjectCollection, { margin: 2, colItems: propValueColItems, items: gridSummaries })),
                    React.createElement(Tabs_1.Tabs.Content, null,
                        React.createElement(AdaptableObjectsSummary_1.AdaptableObjectsSummary, null)))))));
};
exports.GridInfoPopup = GridInfoPopup;
