/**
 * DevExtreme (cjs/__internal/grids/grid_core/filter/m_filter_builder.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.filterBuilderModule = exports.FilterBuilderView = void 0;
var _renderer = _interopRequireDefault(require("../../../../core/renderer"));
var _extend = require("../../../../core/utils/extend");
var _message = _interopRequireDefault(require("../../../../localization/message"));
var _filter_builder = _interopRequireDefault(require("../../../../ui/filter_builder"));
var _ui = _interopRequireDefault(require("../../../../ui/popup/ui.popup"));
var _scroll_view = _interopRequireDefault(require("../../../../ui/scroll_view"));
var _accessibility = require("../../../../ui/shared/accessibility");
var _m_modules = _interopRequireDefault(require("../m_modules"));

function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    }
}

function _inheritsLoose(subClass, superClass) {
    subClass.prototype = Object.create(superClass.prototype);
    subClass.prototype.constructor = subClass;
    _setPrototypeOf(subClass, superClass)
}

function _setPrototypeOf(o, p) {
    _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
        o.__proto__ = p;
        return o
    };
    return _setPrototypeOf(o, p)
}
let FilterBuilderView = function(_modules$View) {
    _inheritsLoose(FilterBuilderView, _modules$View);

    function FilterBuilderView() {
        return _modules$View.apply(this, arguments) || this
    }
    var _proto = FilterBuilderView.prototype;
    _proto.init = function() {
        _modules$View.prototype.init.call(this);
        this._columnsController = this.getController("columns");
        this._filterSyncController = this.getController("filterSync")
    };
    _proto.optionChanged = function(args) {
        switch (args.name) {
            case "filterBuilder":
            case "filterBuilderPopup":
                this._invalidate();
                args.handled = true;
                break;
            default:
                _modules$View.prototype.optionChanged.call(this, args)
        }
    };
    _proto._renderCore = function() {
        this._updatePopupOptions()
    };
    _proto._updatePopupOptions = function() {
        if (this.option("filterBuilderPopup.visible")) {
            this._initPopup()
        } else if (this._filterBuilderPopup) {
            this._filterBuilderPopup.hide()
        }
    };
    _proto._disposePopup = function() {
        if (this._filterBuilderPopup) {
            this._filterBuilderPopup.dispose();
            this._filterBuilderPopup = void 0
        }
        if (this._filterBuilder) {
            this._filterBuilder.dispose();
            this._filterBuilder = void 0
        }
    };
    _proto._initPopup = function() {
        const that = this;
        that._disposePopup();
        that._filterBuilderPopup = that._createComponent(that.element(), _ui.default, (0, _extend.extend)({
            title: _message.default.format("dxDataGrid-filterBuilderPopupTitle"),
            contentTemplate: $contentElement => that._getPopupContentTemplate($contentElement),
            onOptionChanged(args) {
                if ("visible" === args.name) {
                    that.option("filterBuilderPopup.visible", args.value)
                }
            },
            toolbarItems: that._getPopupToolbarItems()
        }, that.option("filterBuilderPopup"), {
            onHidden() {
                (0, _accessibility.restoreFocus)(that);
                that._disposePopup()
            }
        }))
    };
    _proto._getPopupContentTemplate = function(contentElement) {
        const $contentElement = (0, _renderer.default)(contentElement);
        const $filterBuilderContainer = (0, _renderer.default)("<div>").appendTo((0, _renderer.default)(contentElement));
        this._filterBuilder = this._createComponent($filterBuilderContainer, _filter_builder.default, (0, _extend.extend)({
            value: this.option("filterValue"),
            fields: this._columnsController.getFilteringColumns()
        }, this.option("filterBuilder"), {
            customOperations: this._filterSyncController.getCustomFilterOperations()
        }));
        this._createComponent($contentElement, _scroll_view.default, {
            direction: "both"
        })
    };
    _proto._getPopupToolbarItems = function() {
        const that = this;
        return [{
            toolbar: "bottom",
            location: "after",
            widget: "dxButton",
            options: {
                text: _message.default.format("OK"),
                onClick() {
                    const filter = that._filterBuilder.option("value");
                    that.option("filterValue", filter);
                    that._filterBuilderPopup.hide()
                }
            }
        }, {
            toolbar: "bottom",
            location: "after",
            widget: "dxButton",
            options: {
                text: _message.default.format("Cancel"),
                onClick() {
                    that._filterBuilderPopup.hide()
                }
            }
        }]
    };
    return FilterBuilderView
}(_m_modules.default.View);
exports.FilterBuilderView = FilterBuilderView;
const filterBuilderModule = {
    defaultOptions: () => ({
        filterBuilder: {
            groupOperationDescriptions: {
                and: _message.default.format("dxFilterBuilder-and"),
                or: _message.default.format("dxFilterBuilder-or"),
                notAnd: _message.default.format("dxFilterBuilder-notAnd"),
                notOr: _message.default.format("dxFilterBuilder-notOr")
            },
            filterOperationDescriptions: {
                between: _message.default.format("dxFilterBuilder-filterOperationBetween"),
                equal: _message.default.format("dxFilterBuilder-filterOperationEquals"),
                notEqual: _message.default.format("dxFilterBuilder-filterOperationNotEquals"),
                lessThan: _message.default.format("dxFilterBuilder-filterOperationLess"),
                lessThanOrEqual: _message.default.format("dxFilterBuilder-filterOperationLessOrEquals"),
                greaterThan: _message.default.format("dxFilterBuilder-filterOperationGreater"),
                greaterThanOrEqual: _message.default.format("dxFilterBuilder-filterOperationGreaterOrEquals"),
                startsWith: _message.default.format("dxFilterBuilder-filterOperationStartsWith"),
                contains: _message.default.format("dxFilterBuilder-filterOperationContains"),
                notContains: _message.default.format("dxFilterBuilder-filterOperationNotContains"),
                endsWith: _message.default.format("dxFilterBuilder-filterOperationEndsWith"),
                isBlank: _message.default.format("dxFilterBuilder-filterOperationIsBlank"),
                isNotBlank: _message.default.format("dxFilterBuilder-filterOperationIsNotBlank")
            }
        },
        filterBuilderPopup: {}
    }),
    views: {
        filterBuilderView: FilterBuilderView
    }
};
exports.filterBuilderModule = filterBuilderModule;
