"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamedQueryModule = void 0;
const tslib_1 = require("tslib");
const NamedQueryRedux = tslib_1.__importStar(require("../Redux/ActionsReducers/NamedQueryRedux"));
const ModuleConstants = tslib_1.__importStar(require("../Utilities/Constants/ModuleConstants"));
const getObjectTagsViewItems_1 = require("../Utilities/getObjectTagsViewItems");
const EditCurrentQueryButton_1 = require("../View/NamedQuery/EditCurrentQueryButton");
const NamedQueryWizard_1 = require("../View/NamedQuery/Wizard/NamedQueryWizard");
const AdaptableModuleBase_1 = require("./AdaptableModuleBase");
class NamedQueryModule extends AdaptableModuleBase_1.AdaptableModuleBase {
    constructor(api) {
        super(ModuleConstants.NamedQueryModuleId, ModuleConstants.NamedQueryFriendlyName, 'grid-filter', 'NamedQueryPopup', 'Creates Named Queries', api);
    }
    getModuleAdaptableObjects() {
        return this.api.namedQueryApi.getNamedQueries();
    }
    getTeamSharingAction() {
        return {
            ModuleEntities: this.api.namedQueryApi.getNamedQueries(),
            AddAction: NamedQueryRedux.NamedQueryAdd,
            EditAction: NamedQueryRedux.NamedQueryEdit,
        };
    }
    getExplicitlyReferencedColumnIds(namedQuery) {
        return this.api.expressionApi.getColumnsFromExpression(namedQuery.BooleanExpression);
    }
    getReferencedNamedQueryNames(namedQuery) {
        return this.api.namedQueryApi.internalApi.getReferencedNamedQueryNames(namedQuery.BooleanExpression);
    }
    toView(query) {
        return {
            abObject: query,
            items: [
                {
                    name: 'Query Name',
                    values: [query.Name],
                },
                {
                    name: 'Expression',
                    values: [this.api.internalApi.getAdaptableQueryExpressionText(query)],
                },
                (0, getObjectTagsViewItems_1.getObjectTagsViewItems)(query, this.api),
            ],
        };
    }
    toViewAll() {
        return this.getModuleAdaptableObjects().map((query) => this.toView(query));
    }
    getViewProperties() {
        return {
            getDeleteAction: NamedQueryRedux.NamedQueryDelete,
            newTooltipText: 'Create New Named Query',
            emptyView: "Click 'New' to create a Named Query that can be referenced in other Expressions",
            getEditWizard: () => NamedQueryWizard_1.NamedQueryWizard,
            getStatusBarPanelProps: () => {
                const queryMaxLength = 15;
                const query = this.api.filterApi.gridFilterApi.getCurrentGridFilterExpression();
                let text = query;
                let popover = null;
                if (query.length > queryMaxLength) {
                    text = query.substring(0, queryMaxLength - 3) + '...';
                    popover = query;
                }
                return {
                    content: text || 'No Query',
                    extraActions: [EditCurrentQueryButton_1.EditGridFilterButton],
                    popover,
                };
            },
        };
    }
}
exports.NamedQueryModule = NamedQueryModule;
