"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GridFilterApiImpl = void 0;
const tslib_1 = require("tslib");
const LayoutRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/LayoutRedux"));
const windowFactory_1 = require("../../View/Components/Popups/WindowPopups/windowFactory");
const GridFilterInternalApi_1 = require("../Internal/GridFilterInternalApi");
const ApiBase_1 = require("./ApiBase");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
class GridFilterApiImpl extends ApiBase_1.ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new GridFilterInternalApi_1.GridFilterInternalApi(_adaptable);
    }
    getCurrentGridFilter() {
        return this.getLayoutApi().getCurrentLayout()?.GridFilter;
    }
    getCurrentGridFilterExpression() {
        const gridFilter = this.getCurrentGridFilter();
        if (!gridFilter || gridFilter.IsSuspended) {
            return '';
        }
        return gridFilter.Expression;
    }
    setGridFilterExpression(filter) {
        this.dispatchAction(LayoutRedux.LayoutGridFilterSet(filter));
    }
    clearGridFilter() {
        this.dispatchAction(LayoutRedux.LayoutGridFilterClear());
    }
    openUIEditorForGridFilter(expression) {
        const preparedQuery = expression ?? this.getCurrentGridFilterExpression();
        this.getAdaptableInternalApi().showPopupWindow({
            id: windowFactory_1.WINDOW_GRID_FILTER_EDITOR,
            title: ModuleConstants.GridFilterFriendlyName,
            icon: 'filter-list',
            factoryId: windowFactory_1.WINDOW_GRID_FILTER_EDITOR,
            popupProps: {
                value: preparedQuery,
            },
        });
    }
    suspendGridFilter() {
        const gridFilter = this.getCurrentGridFilter();
        if (gridFilter && !gridFilter.IsSuspended) {
            this.dispatchAction(LayoutRedux.LayoutGridFilterSuspend());
        }
    }
    unSuspendGridFilter() {
        const gridFilter = this.getCurrentGridFilter();
        if (gridFilter && gridFilter.IsSuspended) {
            this.dispatchAction(LayoutRedux.LayoutGridFilterUnSuspend());
        }
    }
}
exports.GridFilterApiImpl = GridFilterApiImpl;
