import { eqi18n, equtils, Condition, Expression, DataKind, DataType, ExprTag, CondTag, LinkType, ValueEditor, EditorTag } from '@easyquery/core';
//----------------------------------
//  ConditionRow base widget
//----------------------------------
export function registerConditionWidgets($) {
    $.widget("eqjs.ConditionRow", {
        _condition: null,
        _parentPredicate: null,
        _parentPredicateWidget: null,
        _buttonsBlock: null,
        _enableButton: null,
        _deleteButton: null,
        _addConditionButton: null,
        _addPredicateButton: null,
        _checkBox: null,
        _keepShowingButtons: false,
        _isMouseOverBlock: false,
        _active: false,
        options: {
            queryPanel: null
        },
        getQuery: function () {
            return this.options.queryPanel.getQuery();
        },
        getContext: function () {
            return this.options.queryPanel.getContext();
        },
        getModel: function () {
            var query = this.getQuery();
            return query ? query.getModel() : null;
        },
        getCondition: function () {
            return this._condition;
        },
        getQueryPanel: function () {
            return this.options.queryPanel;
        },
        makeActive: function () {
            var queryPanel = this.getQueryPanel();
            if (queryPanel) {
                queryPanel.setActiveConditionWidget(this);
            }
        },
        makeInactive: function () {
            var queryPanel = this.getQueryPanel();
            if (queryPanel) {
                queryPanel.deactivateConditionWidget();
            }
        },
        activateByCondition: function (condition) {
            if (this._condition == condition) {
                this.makeActive();
            }
        },
        init: function (condition, parent, parentWidget) {
            this.element.get(0).condition = condition;
            this._condition = condition;
            this._parentPredicate = parent;
            this._parentPredicateWidget = parentWidget;
            if (this.isPredicate()) {
                this._buttonsToShow = this.options.queryPanel && this.options.queryPanel.options.buttons && this.options.queryPanel.options.buttons.predicate && $.isArray(this.options.queryPanel.options.buttons.predicate) ? this.options.queryPanel.options.buttons.predicate : ["addCondition", "addPredicate", "enable", "delete"];
            }
            else {
                this._buttonsToShow = this.options.queryPanel && this.options.queryPanel.options.buttons && this.options.queryPanel.options.buttons.condition && $.isArray(this.options.queryPanel.options.buttons.condition) ? this.options.queryPanel.options.buttons.condition : ["enable", "delete"];
            }
            ;
            this.refresh();
            if (this._condition.initAsActive) {
                this.makeActive();
                delete this._condition.initAsActive;
            }
            ;
        },
        _render: function () {
            this._clear();
            if (this.getModel() && this._condition) {
                this._refreshByCondition();
                if (!this._condition.readOnly) {
                    this._initButtons();
                    this._initCheckbox();
                    if (this.getQueryPanel().options.activeCondition == this._condition) {
                        this.makeActive();
                    }
                }
                this._postRender();
            }
        },
        _postRender: function () {
        },
        refresh: function () {
            this._render();
        },
        _isDisabled: function () {
            return this._condition.enabled === false;
        },
        _isParameterized: function () {
            return this._condition.parameterized;
        },
        _isInJoin: function () {
            return this._condition.inJoin;
        },
        _setOption: function (key, value) {
            if (arguments.length == 2) {
                if (key === "disabled") {
                    this._setConditionEnable(!value);
                }
                else if (key === "parameterized") {
                    this._setConditionParameterized(value);
                    this._render();
                }
                else if (key === "inJoin") {
                    this._setConditionAsInJoin(value);
                    this._render();
                }
                else {
                    this.options[key] = value;
                    this._render();
                }
                return this;
            }
            else {
                if (key === "disabled")
                    return this._isDisabled();
                else if (key === "parameterized") {
                    return this._isParameterized();
                }
                else if (key === "joinOnly") {
                    return this._isInJoin();
                }
                else
                    return this.options[key];
            }
        },
        _setConditionEnable: function (value, avoidSubConditionsProcessing) {
            if (this._parentPredicate) { //otherwise it is root predicate, can't change Enable
                if (!value || !('enabled' in this._parentPredicate) || this._parentPredicate.enabled) { //can't enable condition/predicate, if parent predicate is disabled
                    this._setConditionEnableCore(this._condition, value, avoidSubConditionsProcessing);
                    if (this._enableButton) {
                        if (!value) {
                            this._enableButton.removeClass('enabled');
                        }
                        else {
                            this._enableButton.addClass('enabled');
                        }
                    }
                    ;
                    this._render();
                    this._fireConditionChange({ type: "change" });
                }
            }
        },
        _setConditionEnableCore: function (cond, value, avoidSubConditionsProcessing) {
            cond.enabled = value;
            if (cond.conditions && !avoidSubConditionsProcessing) {
                var condLength = cond.conditions.length;
                for (var condIdx = 0; condIdx < condLength; condIdx++) {
                    this._setConditionEnableCore(cond.conditions[condIdx], value);
                }
            }
            if (this._parentPredicateWidget) {
                this._parentPredicateWidget._checkAllDisabled();
            }
        },
        _setConditionParameterized: function (value) {
            this._condition.parameterized = value;
            this._fireConditionChange({ type: "change" });
        },
        _setConditionAsInJoin: function (value) {
            this._condition.inJoin = value;
            this._fireConditionChange({ type: "change" });
        },
        _clear: function () {
            this.element.html('');
            this.element.removeClass();
        },
        _refreshByCondition: function () {
        },
        _fireConditionChange: function (options) {
            var self = this;
            options = options || {};
            this.getQuery().fireChangedEvent({
                "author": self.getQueryPanel(),
                "changeType": "condition." + options.type || "change",
                "what": options.what || "",
                "condition": options.condition || self._condition,
                "element": options.element || self.element
            });
        },
        remove: function () {
            var self = this;
            if (!self._parentPredicateWidget)
                return;
            self._parentPredicateWidget.removeCondition(self._condition);
        },
        isPredicate: function () {
            return false;
        },
        _getButtonsContainer: function () {
            return this.element;
        },
        _conditionMenuEventHandler: function (button, evt) {
            var self = this;
            switch (button) {
                case "addCondition":
                    if (evt.fromMenu) {
                        if (!('addNewCondition' in self)) {
                            return;
                        }
                        ;
                        //define the condition automatically added to the predicate
                        var attribute = self.getModel().getFirstUICAttr();
                        var attrid = attribute ? attribute.id : -1;
                        var operid = attribute ? attribute.operators[0] : -1;
                        var query = this.getQuery();
                        var condition = new Condition();
                        condition.tag = CondTag.Simple;
                        condition.blockId = self.getQueryPanel().getNewCondId();
                        condition.justAdded = true;
                        condition.enabled = true;
                        condition.operatorID = operid;
                        var expr = new Expression();
                        expr.tag = query.attrClassName;
                        expr.id = attrid;
                        expr.kind = DataKind.Attribute;
                        condition.expressions.push(expr);
                        //                        predicate.conditions.push(condition);
                        self.addCondition(condition);
                    }
                    else {
                        self._keepShowingButtons = true;
                        self.options.queryPanel.showEntitiesMenu({
                            anchor: evt.target,
                            selectedIds: null,
                            itemSelectedCallback: function (evt, data) {
                                var attrid = data.menuItem.data('id');
                                var attrobj = self.getModel().getAttributeById(attrid);
                                if ('addNewCondition' in self) {
                                    self.addNewCondition(attrid);
                                }
                            },
                            menuClosedCallback: function () {
                                self._keepShowingButtons = false;
                                if (!self._isMouseOverBlock)
                                    self._leaveButtonBlock();
                            }
                        });
                    }
                    ;
                    break;
                case "addPredicate":
                    if ('addNewPredicate' in self) {
                        self.addNewPredicate();
                    }
                    break;
                case "param":
                    self.option('parameterized', !self._isParameterized());
                    break;
                case "inJoin":
                    self.option('inJoin', !self._isInJoin());
                    break;
                case "enable":
                    self.option('disabled', !self._isDisabled());
                    if (self._enableButton && self._isMouseOverBlock) {
                        self._enableButton.trigger('mouseover');
                    }
                    ;
                    break;
                case "delete":
                    self.remove();
                    break;
                case "menu":
                    var menuOptions = self._getConditionMenuOptions();
                    if (!menuOptions.menu)
                        return;
                    self._keepShowingButtons = true;
                    menuOptions.menu.PopupMenu('showMenu', {
                        anchor: self._menuButton,
                        selectedIds: menuOptions.selectedItems,
                        itemSelectedCallback: function (evt, data) {
                            var itemid = data.menuItem.data('id');
                            evt = evt || {};
                            evt.fromMenu = true;
                            self._conditionMenuEventHandler(itemid, evt);
                        },
                        menuClosedCallback: function () {
                            self._keepShowingButtons = false;
                            if (!self._isMouseOverBlock)
                                self._leaveButtonBlock();
                        }
                    });
                    break;
            }
            ;
        },
        _getConditionMenuOptions: function () {
            var self = this;
            return {
                menu: self.options.queryPanel.options.conditionMenu,
                selectedItems: []
            };
        },
        _initButtons: function () {
            var self = this;
            var container = self._getButtonsContainer();
            var btnPlaceholder;
            if (!container)
                return;
            //navBlock.find('div').unbind();
            self._buttonsBlock = $("<div></div>")
                .addClass("eqjs-qp-condition-buttonsBlock")
                .appendTo(container);
            if (self._buttonsToShow.indexOf("addCondition") >= 0) {
                btnPlaceholder = $("<div></div>").addClass('eqjs-qp-button-placeholder').appendTo(self._buttonsBlock);
                self._addConditionButton = $("<div></div>")
                    .addClass("eqjs-qp-condition-button eqjs-qp-condition-button-addCondition")
                    .attr('title', eqi18n.getText('ButtonAddCondition'))
                    .appendTo(btnPlaceholder)
                    .click(function (evt) { self._conditionMenuEventHandler("addCondition", evt); });
            }
            ;
            if (self._buttonsToShow.indexOf("addPredicate") >= 0) {
                btnPlaceholder = $("<div></div>").addClass('eqjs-qp-button-placeholder').appendTo(self._buttonsBlock);
                self._addPredicateButton = $("<div></div>")
                    .addClass("eqjs-qp-condition-button eqjs-qp-condition-button-addPredicate")
                    .attr('title', eqi18n.getText('ButtonAddPredicate'))
                    .appendTo(btnPlaceholder)
                    .click(function () { self._conditionMenuEventHandler("addPredicate"); });
            }
            ;
            if (self._buttonsToShow.indexOf("enable") >= 0) {
                btnPlaceholder = $("<div></div>").addClass('eqjs-qp-button-placeholder').appendTo(self._buttonsBlock);
                self._enableButton = $("<div></div>")
                    .addClass("eqjs-qp-condition-button eqjs-qp-condition-button-enable")
                    .attr('title', eqi18n.getText('ButtonEnable'))
                    .appendTo(btnPlaceholder)
                    .click(function () { self._conditionMenuEventHandler("enable"); });
            }
            ;
            if (self._buttonsToShow.indexOf("delete") >= 0) {
                btnPlaceholder = $("<div></div>").addClass('eqjs-qp-button-placeholder').appendTo(self._buttonsBlock);
                self._deleteButton = $("<div></div>")
                    .addClass("eqjs-qp-condition-button eqjs-qp-condition-button-delete")
                    .attr('title', eqi18n.getText('ButtonDelete'))
                    .appendTo(btnPlaceholder)
                    .click(function () { self._conditionMenuEventHandler("delete"); });
            }
            ;
            if (self._buttonsToShow.indexOf("menu") >= 0) {
                btnPlaceholder = $("<div></div>").addClass('eqjs-qp-button-placeholder').appendTo(self._buttonsBlock);
                self._menuButton = $("<div></div>")
                    .addClass("eqjs-qp-condition-button eqjs-qp-condition-button-menu")
                    .attr('title', eqi18n.getText('ButtonMenu'))
                    .appendTo(btnPlaceholder)
                    .click(function () { self._conditionMenuEventHandler("menu"); });
            }
            ;
            if (self._enableButton) {
                if (self._isDisabled()) {
                    self._enableButton.removeClass('enabled');
                }
                else {
                    self._enableButton.addClass('enabled');
                }
            }
            ;
            container.find('[class*=eqjs-qp-condition-button]').hover(function () {
                $(this).addClass('eqjs-qp-condition-button-active');
            }, function () {
                $(this).removeClass('eqjs-qp-condition-button-active');
            });
            container.bind('mouseenter', function (event) {
                self._isMouseOverBlock = true;
                self._enterButtonBlock();
                event.stopPropagation();
                return false;
            })
                .bind('mouseleave', function (event) {
                self._isMouseOverBlock = false;
                if (!self._keepShowingButtons && self._buttonsBlock.is(':visible')) {
                    self._leaveButtonBlock();
                }
                event.stopPropagation();
                return false;
            });
            self._hideButtons();
            self._adjustButtonsVisibility();
        },
        _initCheckbox: function () {
            var self = this;
            var container = self._getButtonsContainer();
            if (!container)
                return;
            if (self.options.queryPanel.options.showCheckboxes) {
                self._checkBox = $('<div></div>')
                    .addClass("eqjs-qp-condelement eqjs-qp-condition-checkbox")
                    .attr('title', eqi18n.getText('ButtonEnable'))
                    .prependTo(container)
                    .click(function () {
                    self.option('disabled', !self._isDisabled());
                    self._adjustCheckbox();
                    self._checkBox.trigger('mouseover');
                });
                self._adjustCheckbox();
            }
        },
        _isFirstConditionInGroup: function () {
            var index = this._parentPredicate ? $.inArray(this._condition, this._parentPredicate.conditions) : 0;
            return (index == 0);
        },
        _renderConjunction: function () {
            var self = this;
            var container = self._getButtonsContainer();
            if (!container)
                return;
            if (self.options.queryPanel.options.showConjunctions && !self._isFirstConditionInGroup()) {
                var linkTypeStr = equtils.linkTypeToStr(this._parentPredicate.linkType);
                var conjuctionText = eqi18n.getText("Conj" + linkTypeStr);
                if (conjuctionText) {
                    self._conjuction = $("<span>" + conjuctionText + "</span>")
                        .addClass("eqjs-qp-condelement eqjs-qp-condition-conjuction")
                        .prependTo(container);
                }
            }
        },
        _adjustCheckbox: function () {
            var self = this;
            if (!self._checkBox)
                return;
            if (self._condition.enabled === false) {
                self._checkBox.removeClass('enabled');
            }
            else {
                self._checkBox.addClass('enabled');
            }
        },
        _adjustButtonsVisibility: function () {
        },
        _enterButtonBlock: function () {
            this._showButtons();
        },
        _leaveButtonBlock: function () {
        },
        _showButtons: function () {
        },
        _hideButtons: function () {
            if (this._addConditionButton) {
                this._addConditionButton.parent().hide();
            }
            if (this._addPredicateButton) {
                this._addPredicateButton.parent().hide();
            }
            if (this._enableButton) {
                this._enableButton.parent().hide();
            }
            /*
                        if (this._paramButton) {
                            this._paramButton.hide();
                        }
            */
            if (this._deleteButton) {
                this._deleteButton.parent().hide();
            }
            if (this._menuButton) {
                this._menuButton.parent().hide();
            }
        },
        internalActivate: function () {
            this._active = true;
            this.adjustActiveClass();
            this._hideButtons();
            this._adjustButtonsVisibility();
            //this.refresh();
        },
        internalDeactivate: function () {
            this._active = false;
            this.adjustActiveClass();
            this._hideButtons();
            this._adjustButtonsVisibility();
            //this.refresh();
        },
        adjustActiveClass: function () {
            if (this._active && this.options.queryPanel.options.accentActiveCondition) {
                this.element.addClass("active");
            }
            else {
                this.element.removeClass("active");
            }
        },
        /*
                setActiveConditionWidget: function () {
                    this.options.queryPanel.setActiveConditionWidget(this);
                },
        */
        isActive: function () {
            return this._active;
        },
        getLevel: function () {
            if (this._parentPredicateWidget) {
                return this._parentPredicateWidget.getLevel() + 1;
            }
            else {
                return 0;
            }
        },
        _renderLevelOffset: function () {
            var level = this.getLevel();
            var offsetDiv;
            for (var i = 0; i < level - 1; i++) {
                offsetDiv = $('<div></div>')
                    .addClass('eqjs-qp-level-offset')
                    .prependTo(this._getButtonsContainer());
            }
        }
    });
    //----------------------------------
    //  ConditionRow_SMPL widget
    //----------------------------------
    $.widget("eqjs.ConditionRow_" + CondTag.Simple, $.eqjs.ConditionRow, {
        _postRender: function () {
            if (this.options.queryPanel.options.spreadValueElement) {
                //adjust value elements max-width
                var veList = this.element.find('.eqjs-qp-valueelement');
                if (veList.length == 0)
                    return;
                var elList = this.element.find('.eqjs-qp-condelement');
                var oddWidth = 0;
                for (var i = 0; i < elList.length; i++) {
                    if (!$(elList[i]).hasClass('eqjs-qp-valueelement')) {
                        oddWidth = oddWidth + $(elList[i]).outerWidth(true);
                    }
                }
                var offset = $(veList[0]).outerWidth(true) - $(veList[0]).width();
                oddWidth = oddWidth + this._buttonsBlock.width() + veList.length * offset;
                var usefulWidth = this.element.width() - oddWidth;
                for (var i = 0; i < veList.length; i++) {
                    $(veList[i]).css('max-width', (usefulWidth / veList.length >> 0) + 'px');
                }
            }
        },
        _refreshByCondition: function () {
            var model = this.getModel();
            if (!this._condition || !model) {
                return;
            }
            var self = this;
            self.options.disabled = !self._condition.enabled || self._condition.readOnly;
            //$.data(this.element, 'condition', this._condition);
            this.element.addClass('eqjs-qp-row eqjs-qp-row-condition');
            if (this._condition.enabled === false)
                this.element.addClass('eqjs-qp-disabled');
            if (this._condition.readOnly)
                this.element.addClass('eqjs-qp-readonly');
            if (this._condition.justAdded) {
                //condition is just added. We need to add/setup expressions
                this._updateValueExpressions();
                this._condition.justAdded = false;
            }
            ;
            if (self._isInJoin()) {
                this.element.addClass('eqjs-qp-condition-injoin');
            }
            ;
            if (self._isParameterized()) {
                this.element.addClass('eqjs-qp-condition-parameterized');
            }
            var operator = model.getOperatorById(self._condition.operatorID);
            var arrFormat = equtils.parseOperatorFormat(operator);
            var item = null;
            var arrLength = arrFormat.length;
            for (var idx = 0; idx < arrLength; idx++) {
                item = arrFormat[idx];
                var baseExprElement, operatorLink;
                if (item.type === 'operator') {
                    //var linkText = self._getOperatorMainText(operator); 
                    if (this._condition.enabled !== false && !this._condition.readOnly) {
                        operatorLink = $('<a></a>', {
                            href: 'javascript:void(0)',
                            text: item.text
                        });
                    }
                    else {
                        operatorLink = $('<span></span>', {
                            text: item.text
                        });
                    }
                    var operatorBlock = $('<div></div>');
                    operatorBlock.addClass('eqjs-qp-condelement eqjs-qp-operelement');
                    operatorLink.appendTo(operatorBlock);
                    operatorBlock.appendTo(this.element);
                    if (this._condition.enabled !== false && !this._condition.readOnly) {
                        var menuOperatorsBlock = self._createOperatorsMenu(operatorLink);
                        operatorLink.click(function (e) {
                            e.preventDefault();
                            menuOperatorsBlock.PopupMenu('showMenu', {
                                anchor: operatorLink
                            });
                        });
                    }
                }
                else if (item.type === 'expression') {
                    if (item.index === 0) { //base expression
                        var baseAttrElement = this._createAttrElement(this._condition.expressions[0], function (attrobj, oldAttrId) {
                            var operid = attrobj.operators[0];
                            //                            var exprCount = self._condition.expressions.length;
                            //                            self._condition.expressions.splice(1, exprCount - 1);
                            var oldOperId = self._condition.operatorID;
                            self._condition.operatorID = operid;
                            self._updateValueExpressions(oldOperId, oldAttrId);
                        });
                        baseAttrElement.appendTo(this.element);
                    }
                    else {
                        var valueElement;
                        var valExpr = this._condition.expressions[item.index];
                        //check if value expression has a correct data type
                        if (valExpr.dataType === DataType.Unknown) {
                            self._updateExprDataType(valExpr, item.index);
                        }
                        if (valExpr.kind === DataKind.Attribute) {
                            valueElement = this._createAttrElement(valExpr);
                            valueElement.appendTo(this.element);
                        }
                        else {
                            valueElement = $('<div></div>');
                            valueElement.appendTo(this.element);
                            this._createValueEditor(valueElement, valExpr, item.index);
                        }
                    }
                }
                else if (item.type === 'text') {
                    var textBlock = $('<span></span>')
                        .addClass('eqjs-qp-condelement')
                        .text(item.text)
                        .attr("title", item.text)
                        .appendTo(this.element);
                }
            }
            if (self.options.queryPanel.options.accentActiveCondition) {
                self.element.click(function () {
                    if (self._active) {
                        self.makeInactive();
                    }
                    else {
                        self.makeActive();
                    }
                });
            }
            self.adjustActiveClass();
            self._adjustCheckbox();
            this._renderConjunction();
            this._renderLevelOffset();
            var qp = this.getQueryPanel();
            if (qp && qp.options.conditionRenderedCallback) {
                qp.options.conditionRenderedCallback(this.element);
            }
        },
        _updateExprDataType: function (expr, index) {
            var model = this.getModel();
            var attributeID = this._condition.expressions[0].id;
            var attribute = model.getAttributeById(attributeID);
            if (!attribute)
                return;
            var operatorID = this._condition.operatorID;
            var operator = model.getOperatorById(operatorID);
            var operand = model.getOperand(attribute, operator, index);
            expr.dataType = operand.dataType;
        },
        _createAttrElement: function (expr, callback) {
            var self = this;
            var model = this.getModel();
            var attrElementDiv = $('<div></div>');
            var attrId = expr.id;
            var attrObj = attrId ? this.getModel().getAttributeById(attrId) : null;
            var attrElement;
            var attrFormat = self.options.queryPanel.options.attrElementFormat;
            if (this._condition.enabled !== false && !this._condition.readOnly) {
                var attrText = attrObj ? model.getAttributeText(attrObj, attrFormat) : eqi18n.getText("MsgEmptyAttrValue");
                attrElement = $('<a href="javascript:void(0)">' + attrText + '</a>');
                attrElement.attr("title", attrText);
                attrElement.click(function (e) {
                    e.preventDefault();
                    self.options.queryPanel.showEntitiesMenu({
                        anchor: attrElement,
                        selectedIds: null,
                        itemSelectedCallback: function (evt, data) {
                            var newAttrId = data.menuItem.data('id');
                            var newAttrObj = self.getModel().getAttributeById(newAttrId);
                            expr.id = newAttrId;
                            if (callback) {
                                callback(newAttrObj, attrId);
                            }
                            self.refresh();
                            self._fireConditionChange({ type: "change", what: "attribute" });
                            return false;
                        },
                        itemFilterCallback: function (item) { return true; } ///!!!!! change in future
                    });
                });
            }
            else {
                attrElement = $('<span>' + model.getAttributeText(attrObj, attrFormat) + '</span>');
            }
            attrElementDiv.addClass('eqjs-qp-condelement eqjs-qp-attrelement');
            attrElement.appendTo(attrElementDiv);
            return attrElementDiv;
        },
        _getOperatorCaption: function (operator) {
            // tries to get it from EasyQuery.texts.Operators list
            // if not found - uses the one from the model
            var caption = eqi18n.getText('Operators', operator.id, 'caption');
            if (!caption)
                caption = operator.caption;
            return caption;
        },
        _operatorChanged: function (oldOperID, newOperID) {
            var self = this;
            self._updateValueExpressions(oldOperID);
            self.refresh();
            self._fireConditionChange({ type: "change", what: "operator" });
        },
        _areCompatibleTypes: function (expr1, expr2) {
            if (typeof (expr1.dataType) === "undefined")
                return true;
            //            if (type2 == "WideString" || type2 == "String")
            //                return true;
            return (expr1.dataType == expr2.dataType) && (expr1.kind == expr2.kind);
        },
        _areCompatibleEditors: function (editor1, editor2) {
            if (!editor1 || !editor2) {
                if (editor1 == editor2)
                    return true; //if both editors null
                else
                    return false;
            }
            if (editor1 == editor2)
                return true; //if editors are equal
            if (editor1.tag == editor2.tag) {
                if (editor1.tag == EditorTag.Edit || editor1.tag == EditorTag.DateTime)
                    return true;
                if (editor1.tag == EditorTag.CustomList && editor1.name == editor2.name)
                    return true;
                if (editor1.id == editor2.id)
                    return true;
            }
            return false;
        },
        _updateValueExpressions: function (oldOperatorId, oldAttrId) {
            var self = this;
            var model = this.getModel();
            var attributeID = self._condition.expressions[0].id;
            var attribute = model.getAttributeById(attributeID);
            if (!attribute)
                return;
            var operatorID = self._condition.operatorID;
            var operator = model.getOperatorById(operatorID);
            if (!operator)
                return;
            //var exprType = (operator.exprType && operator.exprType !== 'Unknown') ? operator.exprType : attribute.dataType;
            var exprCount = self._condition.expressions.length;
            //var newEditor = self._getDefaultEditor(operatorID, attributeID);
            var operand;
            var oldOperator;
            var oldOperand;
            if (oldOperatorId) {
                oldOperator = model.getOperatorById(oldOperatorId);
                //    var oldExprType = (oldOperator && oldOperator.exprType && oldOperator.exprType !== 'Unknown') ? oldOperator.exprType : attribute.dataType;
                //    var oldEditor = self._getDefaultEditor(oldOperatorID, attributeID);
            }
            //add  necessary expressions
            var i = 1;
            while (i < operator.paramCount) {
                operand = model.getOperand(attribute, operator, i);
                if (oldOperator) {
                    oldOperand = model.getOperand(attribute, oldOperator, i);
                }
                if (operand.dataType === DataType.Unknown) {
                    operand.dataType = attribute.dataType;
                }
                if (i >= exprCount) {
                    var valExpr = self._createValueExpression(operand);
                    self._condition.expressions.push(valExpr); //exprType, operator.kind));
                }
                else {
                    var oldExpr = $.extend({}, self._condition.expressions[i]);
                    //recreate value expressions according to attribute and operator
                    var newExpr = self._createValueExpression(operand); //exprType, operator.kind);
                    var oldExprDefault;
                    if (oldOperand) {
                        oldExprDefault = self._createValueExpression(oldOperand).value;
                    }
                    self._condition.expressions[i] = newExpr;
                    var oldEditor = self._getExprEditor(oldExpr, i, oldOperatorId, oldAttrId);
                    var newEditor = self._getExprEditor(newExpr, i);
                    if ((!oldExprDefault || oldExprDefault != oldExpr.value) && self._areCompatibleEditors(oldEditor, newEditor)) {
                        self._tryToAssignExprValue(newExpr, oldExpr);
                    }
                }
                i++;
            }
            if (exprCount > i) {
                //remove all redundant expressions
                self._condition.expressions.splice(i, exprCount - i);
            }
        },
        //set the value of some expression by the type of another expression (if their types are compatible)
        _tryToAssignExprValue: function (expr, oldExpr) {
            if (!oldExpr.value || oldExpr.value == '')
                return;
            if (this._areCompatibleTypes(oldExpr, expr)) {
                expr.value = oldExpr.value;
            }
        },
        _createValueExpression: function (operand) {
            var self = this;
            var newExpr = new Expression();
            if (operand.kind === DataKind.Query) {
                newExpr.tag = ExprTag.Query;
                newExpr.dataType = operand.dataType;
                newExpr.kind = operand.kind;
                newExpr.query = this.getModel().createQuery();
            }
            else if (operand.kind === DataKind.Attribute) {
                var defAttr = self.getModel().getFirstAttributeByFilter(function (attr) {
                    return attr.usedInCondition == true && (!operand.dataType || attr.dataType == operand.dataType);
                });
                var attrId = defAttr ? defAttr.id : null;
                newExpr.tag = ExprTag.EntityAttribute;
                newExpr.dataType = operand.dataType;
                newExpr.kind = operand.kind;
                newExpr.id = attrId;
                newExpr.value = attrId;
            }
            else {
                var defValue;
                if (operand.defValue && operand.defValue != "") {
                    defValue = operand.defValue;
                }
                else if (operand.editor && operand.editor.defValue) {
                    defValue = operand.editor.defValue;
                }
                else {
                    defValue = '';
                }
                newExpr.tag = ExprTag.Constant;
                newExpr.dataType = operand.dataType;
                newExpr.kind = operand.kind;
                newExpr.value = defValue;
                /*
                /////////////////////////////////////////////
                //  set default value / text for new expression
                /////////////////////////////////////////////
                                var editor = self._getDefaultEditor(self._condition.operatorID, self._condition.expressions[0].id);
                                if (editor) {
                                    newExpr.value = editor.value.?
                                }
                */
            }
            ;
            return newExpr;
        },
        _createOperatorsMenu: function (operatorLink) {
            var self = this;
            if (!self._condition || !self.getModel())
                return;
            var items = [];
            var attr = self.getModel().getAttributeById(self._condition.expressions[0].id);
            if (attr) {
                var operator = null;
                var operLength = attr.operators.length;
                for (var opIndex = 0; opIndex < operLength; opIndex++) {
                    operator = self.getModel().findOperatorById(attr.operators[opIndex]);
                    if (operator && !(self.options.queryPanel.options.isSubQuery && operator.kind === DataKind.Query)) {
                        var caption = self._getOperatorCaption(operator);
                        items.push({ id: operator.id, text: caption });
                    }
                }
            }
            var menuOperatorsBlock = $('<div></div>')
                .appendTo(operatorLink.parent())
                .hide();
            var menuId = self.element.attr('id');
            if (menuId) {
                menuId += '-OperatorsMenu';
            }
            var menuOptions = {
                items: items,
                id: menuId,
                domWriteItemsId: self.options.queryPanel.options.domWriteItemsId,
                onMenuItemSelected: function (evt, data) {
                    operatorLink.text(data.menuItem.text);
                    var oldOperatorID = self._condition.operatorID;
                    self._condition.operatorID = data.menuItem.id;
                    self._operatorChanged(oldOperatorID, self._condition.operatorID);
                    return false;
                }
            };
            $.extend(menuOptions, self.options.queryPanel.options.menuOptions);
            menuOperatorsBlock.PopupMenu(menuOptions);
            return menuOperatorsBlock;
        },
        /*
                _getDefaultEditor: function (operatorId, attributeId) {
                    var editor = null;
                
                    var operator = this.getModel().findOperatorById(operatorId);
                    var attribute = this.getModel().getAttributeById(attributeId);
        
                    if (operator && operator.defaultEditor) {
                        editor = operator.defaultEditor;
                    }
                    else if (attribute && attribute.defaultEditor) {
                        editor = attribute.defaultEditor;
                    };
        
                    return editor;
                },
        */
        _getExprEditor: function (expr, index, operatorID, attrId) {
            var model = this.getModel();
            var attributeId = attrId || this._condition.expressions[0].id;
            var attribute = model.getAttributeById(attributeId);
            operatorID = operatorID || this._condition.operatorID;
            var operator = model.getOperatorById(operatorID);
            var operand = model.getOperand(attribute, operator, index);
            var editor = new ValueEditor();
            if (operand && operand.editor && operand.editor.tag !== "Unknown") {
                editor = $.extend({}, operand.editor);
            }
            else {
                if (attribute && attribute.defaultEditor) {
                    editor = $.extend({}, attribute.defaultEditor);
                }
            }
            if (expr && expr.kind === DataKind.Query) {
                editor.tag = EditorTag.SubQuery;
            }
            // else if (expr && expr.kind === DataKind.Scalar && (expr.dataType === DataType.Date || expr.dataType === DataType.DateTime)) {
            //      editor.tag = 'DATETIME';           
            // }
            if (!editor.tag || editor.tag == EditorTag.Unknown) {
                editor.tag = EditorTag.Edit;
            }
            return editor;
        },
        _createValueEditor: function (element, expr, index) {
            var self = this;
            var editor = self._getExprEditor(expr, index);
            if (editor) {
                var funcBody = "element.ValueEditor_" + editor.tag + "({parentWidget:self, editor: editorObj, onChange:exprChangedCallback}); " +
                    "element.ValueEditor_" + editor.tag + "('init', expr);";
                var addWidget = new Function("self, element, expr, editorObj, exprChangedCallback", funcBody);
                var exprChangedCallback = function () {
                    var model = self.getModel();
                    var op = model.getOperatorById(self._condition.operatorID);
                    if (op.isRange) {
                        var expr1 = self._condition.expressions[1];
                        var expr2 = self._condition.expressions[2];
                        if (self._compareExpressions(expr1, expr2) > 0) {
                            if (expr1 == expr) {
                                self._copyExpr(expr1, expr2);
                            }
                            else {
                                self._copyExpr(expr2, expr1);
                            }
                            self.refresh();
                        }
                    }
                    self._fireConditionChange({ type: "change", what: "value" });
                };
                addWidget(this, element, expr, editor, exprChangedCallback);
            }
        },
        _compareExpressions: function (expr1, expr2) {
            var val1, val2, dtp = expr1.dataType, model = this.getModel();
            if (dtp === DataType.Date || dtp === DataType.DateTime) {
                val1 = model.getDateOrMacroValue(expr1.value);
                val2 = model.getDateOrMacroValue(expr2.value);
                return val1 >= val2 ? 1 : -1;
            }
            else if (dtp === DataType.Time) {
                val1 = model.getTimeOrMacroValue(expr1.value);
                val2 = model.getTimeOrMacroValue(expr2.value);
                return val1 >= val2 ? 1 : -1;
            }
            else if (dtp === DataType.Int32 || dtp === DataType.Int64 || dtp === DataType.Byte || dtp === DataType.Word) {
                val1 = expr1.value !== "" ? parseInt(expr1.value) : 0;
                val2 = expr2.value !== "" ? parseInt(expr2.value) : 0;
                return val1 - val2;
            }
            else if (dtp === DataType.Float || dtp === DataType.Currency) {
                val1 = expr1.value !== "" ? parseFloat(expr1.value) : 0;
                val2 = expr2.value !== "" ? parseFloat(expr2.value) : 0;
                return val1 - val2;
            }
            return 0;
        },
        _copyExpr: function (expr1, expr2) {
            expr2.value = expr1.value;
            expr2.text = expr1.text;
        },
        _showButtons: function () {
            var queryPanel = this.options.queryPanel;
            /*
                        if (queryPanel.options.allowParameterization && this._paramButton && this._condition.enabled != false) {
                            this._paramButton.show();
                            if (this._condition.parameterized) {
                                this._paramButton.addClass('turnedon');
                            }
            
                        }
            */
            if (!queryPanel.options.showCheckboxes && this._enableButton) {
                this._enableButton.parent().show();
            }
            ;
            if (this._deleteButton) {
                this._deleteButton.parent().show();
            }
            ;
            if (this._menuButton) {
                this._menuButton.parent().show();
            }
            ;
        },
        _adjustButtonsVisibility: function () {
            if (this.options.queryPanel.options.alwaysShowButtonsInConditions || (this.options.queryPanel.options.accentActiveCondition && this._active)) {
                this._showButtons();
            }
        },
        _leaveButtonBlock: function () {
            if (this.options.queryPanel.options.alwaysShowButtonsInConditions != true && (!this._active || this.options.queryPanel.options.accentActiveCondition != true)) {
                this._hideButtons();
            }
        },
        _getConditionMenuOptions: function () {
            var self = this;
            var arrSelected = [];
            if (!self._isDisabled()) {
                arrSelected.push("enable");
            }
            ;
            if (self._isParameterized()) {
                arrSelected.push("param");
            }
            ;
            if (self._isInJoin()) {
                arrSelected.push("inJoin");
            }
            ;
            return {
                menu: self.options.queryPanel.options.conditionMenu,
                selectedItems: arrSelected
            };
        }
        //        getMaxValueWidth: function () {
        //            return '300px';
        //        }
    });
    //----------------------------------
    //  ConditionRow_PDCT widget
    //----------------------------------
    $.widget("eqjs.ConditionRow_" + CondTag.Predicate, $.eqjs.ConditionRow, {
        _predicateRowBlock: null,
        _getButtonsContainer: function () {
            return this._predicateRowBlock;
        },
        _parsePredicateText: function (predicateRowBlock, key) {
            var self = this;
            var linkTypeChanged = function () {
                self.refresh();
                self._fireConditionChange({ type: "change", what: "link" });
            };
            var predString = eqi18n.getText(key);
            var pos = predString.indexOf('{lt}');
            if (pos < 0) { //invalid format
                predicateRowBlock.text(eqi18n.getText('ErrIncorrectPredicateTitleFormat'));
                predicateRowBlock.addClass('eqjs-qp-error');
            }
            else {
                if (pos > 0) {
                    var predicateText1 = $('<span></span>')
                        .addClass('eqjs-qp-predelement')
                        .text(predString.substring(0, pos))
                        .appendTo(predicateRowBlock);
                }
                var predicateLinkTypeDiv = $('<div></div>');
                predicateLinkTypeDiv.PredicateLinkType({ queryPanel: self.options.queryPanel, parentWidget: self, onChange: linkTypeChanged });
                predicateLinkTypeDiv.PredicateLinkType('init', self._condition);
                predicateLinkTypeDiv.appendTo(predicateRowBlock);
                var predicateText2 = $('<span></span>')
                    .addClass('eqjs-qp-predelement')
                    .text(predString.substring(pos + 4))
                    .appendTo(predicateRowBlock);
            }
        },
        _refreshPredicateRow: function () {
            var self = this;
            if (!self._predicateRowBlock)
                return;
            self._predicateRowBlock.html('');
            self._predicateRowBlock.addClass('eqjs-qp-row eqjs-qp-row-predicate');
            if (self._condition.enabled === false) {
                self._predicateRowBlock.addClass('eqjs-qp-disabled');
            }
            self._parsePredicateText(self._predicateRowBlock, 'PredicateTitle');
            if (self.options.queryPanel.options.accentActiveCondition) {
                self._predicateRowBlock.click(function () {
                    if (self._active) {
                        self.makeInactive();
                    }
                    else {
                        self.makeActive();
                    }
                });
            }
            self.adjustActiveClass();
            this._renderConjunction();
            this._renderLevelOffset();
        },
        _refreshByCondition: function () {
            var self = this;
            self.element.addClass('eqjs-qp-predicate');
            self._predicateRowBlock = $('<div></div>');
            self._predicateRowBlock.appendTo(self.element);
            self._refreshPredicateRow();
            self._addConditions(self.element);
            var qp = this.getQueryPanel();
            if (qp && qp.options.predicateRenderedCallback) {
                qp.options.predicateRenderedCallback(this._predicateRowBlock);
            }
        },
        _addConditions: function (element) {
            //Conditions block
            var conditionsBlock = $('<div></div>');
            conditionsBlock.addClass('eqjs-qp-conditions');
            conditionsBlock.appendTo(element);
            var condCount = this._condition.conditions.length;
            for (var condIdx = 0; condIdx < condCount; condIdx++) {
                var cond = this._condition.conditions[condIdx];
                var newCondBlock = $('<div></div>');
                if (!cond.blockId) {
                    this.trySetBlockId(cond);
                }
                if (cond.blockId) {
                    newCondBlock.attr('id', cond.blockId);
                }
                newCondBlock.appendTo(conditionsBlock);
                var funcBody = "element.ConditionRow_" + cond.tag + "({queryPanel: self.options.queryPanel, model: self.getModel()}); " +
                    "element.ConditionRow_" + cond.tag + "('init', self._condition.conditions[idx], self._condition, self);";
                var addWidget = new Function("self, element, idx", funcBody);
                addWidget(this, newCondBlock, condIdx);
            }
            //(!conditionsBlock.children().length) ? conditionsBlock.hide() : conditionsBlock.show();
            return conditionsBlock;
        },
        _checkAllDisabled: function () {
            if (this._parentPredicate) {
                var allDisabled = true;
                var condLength = this._condition.conditions.length;
                for (var condIdx = 0; condIdx < condLength; condIdx++) {
                    if (this._condition.conditions[condIdx].enabled) {
                        allDisabled = false;
                        break;
                    }
                }
                if (allDisabled) {
                    this._setConditionEnable(false, true);
                }
            }
        },
        _moveDraggedItem: function (condition, newPredicate, newIdx) {
        },
        isPredicate: function () {
            return true;
        },
        _containsActiveCondition: function (predicate) {
            var self = this;
            var predicateCond = predicate || self._condition;
            var activeCond = self.options.queryPanel._activeConditionWidget;
            if (activeCond) {
                activeCond = activeCond.getCondition();
            }
            return self.options.queryPanel.predicateContainsCondition(predicateCond, activeCond);
        },
        removeCondition: function (cond) {
            var self = this;
            var index = $.inArray(cond, self._condition.conditions);
            if (index >= 0) {
                if (self._condition.conditions.length == 1 && self._parentPredicate) { //the last condition in the predicate, need to remove the predicate themself
                    self.remove();
                }
                else {
                    if (cond == self.options.queryPanel.options.activeCondition) {
                        self.makeActive();
                    }
                    self._condition.conditions.splice(index, 1);
                    self.refresh();
                    self._fireConditionChange({ type: "delete", "condition": cond });
                }
            }
        },
        addCondition: function (cond, index) {
            if (!cond || ($.isArray(cond) && cond.length == 0)) {
                return;
            }
            var self = this;
            if (typeof index == "number") {
                self._condition.conditions.push.apply(self._condition.conditions, [index, 0].concat(cond));
            }
            else {
                self._condition.conditions.push.apply(self._condition.conditions, [].concat(cond));
            }
            var condArr = [].concat(cond);
            $.each(condArr, function (index, value) {
                self.trySetBlockId(value);
            });
            cond.initAsActive = true;
            self.refresh();
            self._fireConditionChange({ type: "add", "condition": cond });
        },
        trySetBlockId: function (cond) {
            var parentPanel = this.getQueryPanel();
            var blockId = (cond.tag == CondTag.Predicate) ? parentPanel.getNewPredId() : parentPanel.getNewCondId();
            if (blockId) {
                cond.blockId = blockId;
            }
        },
        addNewCondition: function (attrid, operid, index) {
            var self = this;
            var attribute, condToAdd, cond, realOperId;
            var query = this.getQuery();
            var model = query.getModel();
            var checkAttrUIC = function (attr) {
                var luaid;
                if (attr && !attr.usedInCondition) {
                    if (attr.lookupAttr) {
                        luaid = attr.lookupAttr;
                        attr = model.getAttributeById(luaid);
                        if (!attr || !attr.usedInCondition) {
                            attr = null;
                        }
                    }
                    else
                        attr = null;
                }
                return attr;
            };
            var createConditionObject = function (attr, operIdNew) {
                var condition = new Condition();
                condition.tag = CondTag.Simple;
                condition.enabled = true;
                condition.justAdded = true;
                condition.operatorID = operIdNew;
                var expr = new Expression();
                expr.kind = DataKind.Attribute;
                expr.tag = query.attrClassName;
                expr.id = attr.id;
                condition.expressions.push(expr);
                return condition;
            };
            if (Array.isArray(attrid)) {
                condToAdd = [];
                var attrLength = attrid.length;
                for (var i = 0; i < attrLength; i++) {
                    attribute = model.getAttributeById(attrid[i]);
                    attribute = checkAttrUIC(attribute);
                    if (!attribute) {
                        continue;
                    }
                    realOperId = operid ? operid : model.getDefaultOperatorIdForAttr(attribute);
                    cond = createConditionObject(attribute, realOperId);
                    if (cond)
                        condToAdd.push(cond);
                }
            }
            else {
                attribute = model.getAttributeById(attrid);
                attribute = checkAttrUIC(attribute);
                if (!attribute) {
                    return;
                }
                realOperId = operid ? operid : model.getDefaultOperatorIdForAttr(attribute);
                condToAdd = createConditionObject(attribute, realOperId);
            }
            self.addCondition(condToAdd, index);
            return condToAdd;
        },
        addNewPredicate: function () {
            var self = this;
            //define the condition automatically added to the new predicate
            var attribute = self.getModel().getFirstUICAttr();
            var attrid = attribute ? attribute.id : -1;
            var operid = attribute ? attribute.operators[0] : -1;
            var query = this.getQuery();
            var condition = new Condition();
            condition.blockId = self.getQueryPanel().getNewCondId();
            condition.tag = CondTag.Simple;
            condition.enabled = true;
            condition.justAdded = true;
            condition.operatorID = operid;
            var expr = new Expression();
            expr.kind = DataKind.Attribute;
            expr.tag = query.attrClassName;
            expr.id = attrid;
            condition.expressions.push(expr);
            var lType = self._condition.linkType === LinkType.All ? LinkType.Any : LinkType.All;
            var predicate = new Condition();
            predicate.tag = CondTag.Predicate;
            predicate.linkType = lType;
            predicate.conditions.push(condition);
            this.addCondition(predicate);
        },
        _showButtons: function () {
            if (this._condition.enabled != false) {
                if (this._addConditionButton) {
                    this._addConditionButton.parent().show();
                    //                    this._addConditionButton.removeClass("eqjs-qp-condition-button-hidden");
                    //                    this._addConditionButton.css('background-image', '');
                }
                if (this._addPredicateButton) {
                    this._addPredicateButton.parent().show();
                    //                    this._addPredicateButton.removeClass("eqjs-qp-condition-button-hidden");
                    //                    this._addPredicateButton.css('background-image', '');
                }
            }
            if (!this.options.queryPanel.options.showCheckboxes && this._enableButton) {
                this._enableButton.parent().show();
                //                this._enableButton.removeClass("eqjs-qp-condition-button-hidden");
                //                this._enableButton.css('background-image', '');
            }
            if (this._deleteButton) {
                this._deleteButton.parent().show();
                //                this._deleteButton.removeClass("eqjs-qp-condition-button-hidden");
                //                this._deleteButton.css('background-image', '');
            }
            ;
            if (this._menuButton) {
                this._menuButton.parent().show();
            }
        },
        _adjustButtonsVisibility: function () {
            if (this.options.queryPanel.options.alwaysShowButtonsInPredicates || (this.options.queryPanel.options.accentActiveCondition && this._active)) {
                this._showButtons();
            }
        },
        _leaveButtonBlock: function () {
            if (this.options.queryPanel.options.alwaysShowButtonsInPredicates != true && (!this._active || this.options.queryPanel.options.accentActiveCondition != true)) {
                this._hideButtons();
            }
        },
        internalActivate: function () {
            this._active = true;
            this.adjustActiveClass();
            this._hideButtons();
            this._adjustButtonsVisibility();
        },
        internalDeactivate: function () {
            this._active = false;
            this.adjustActiveClass();
            this._hideButtons();
            this._adjustButtonsVisibility();
        },
        adjustActiveClass: function () {
            if (this._active && this.options.queryPanel.options.accentActiveCondition) {
                this._predicateRowBlock.addClass("active");
            }
            else {
                this._predicateRowBlock.removeClass("active");
            }
        },
        _getConditionMenuOptions: function () {
            var self = this;
            var arrSelected = [];
            if (!self._isDisabled()) {
                arrSelected.push("enable");
            }
            ;
            return {
                menu: self.options.queryPanel.options.predicateMenu,
                selectedItems: arrSelected
            };
        }
    });
    //----------------------------------
    //  RootPredicate widget
    //----------------------------------
    $.widget("eqjs.RootPredicate", $.eqjs["ConditionRow_" + CondTag.Predicate], {
        _showButtons: function () {
            if (this._addConditionButton) {
                this._addConditionButton.parent().show();
                //                this._addConditionButton.removeClass("eqjs-qp-condition-button-hidden");
                //                this._addConditionButton.css('background-image', '');
            }
            ;
            if (this._addPredicateButton) {
                this._addPredicateButton.parent().show();
                //                this._addPredicateButton.removeClass("eqjs-qp-condition-button-hidden");
                //                this._addPredicateButton.css('background-image', '');
            }
            ;
            if (this._menuButton) {
                this._menuButton.parent().show();
            }
            ;
        },
        _initCheckbox: function () {
        },
        _renderConjunction: function () {
        },
        _refreshPredicateRow: function () {
            var self = this;
            if (!self._predicateRowBlock)
                return;
            self._predicateRowBlock.html('');
            self._predicateRowBlock.addClass('eqjs-qp-row eqjs-qp-row-predicate eqjs-qp-row-predicate-root');
            self._parsePredicateText(self._predicateRowBlock, 'RootPredicateTitle');
            if (self.options.queryPanel.options.accentActiveCondition) {
                self._predicateRowBlock.click(function () {
                    if (self._active) {
                        self.makeInactive();
                    }
                    else {
                        self.makeActive();
                    }
                });
            }
            self.adjustActiveClass();
        },
        _refreshByCondition: function () {
            var self = this;
            self.element.addClass('eqjs-qp-predicate eqjs-qp-predicate-root');
            //var minusHeight = 0;
            //Root row block
            if (self.options.queryPanel && self.options.queryPanel.options.showRootRow) {
                self._predicateRowBlock = $('<div></div>');
                self._predicateRowBlock.appendTo(self.element);
                self._refreshPredicateRow();
                //minusHeight += self._predicateRowBlock.outerHeight();
            }
            var condBlock = self._addConditions(self.element);
            condBlock.addClass('eqjs-qp-conditions-root');
            /*
                        if (self.options.queryPanel.options.showAddRow) {
                            var addRowHeight = self.options.queryPanel.addRowHeight;
                            minusHeight += addRowHeight + 9;
                        }
                        var panelHeight = self.options.queryPanel.element.innerHeight();
                        if (condBlock) {
                            condBlock.css({ 'max-height': (panelHeight - minusHeight) + 'px' });
                        }
            */
        },
        _getConditionMenuOptions: function () {
            var self = this;
            return {
                menu: self.options.queryPanel.options.rootPredicateMenu,
                selectedItems: []
            };
        }
    });
}
//# sourceMappingURL=eq.condition.js.map