/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, runOn, markType, INotifyPropertyChanged_$type, PropertyChangedEventArgs, enumGetBox, delegateCombine, EnumUtil, delegateRemove } from "igniteui-webcomponents-core";
import { RenderingContext } from "igniteui-webcomponents-core";
import { Path } from "igniteui-webcomponents-core";
import { GridStyleRepository } from "./GridStyleRepository";
import { KeyFrameAnimationFactory } from "igniteui-webcomponents-core";
import { AnimationKeyFrameEffect } from "igniteui-webcomponents-core";
import { AnimationKeyFrameEffectTiming } from "igniteui-webcomponents-core";
import { CanvasViewRenderer } from "igniteui-webcomponents-core";
import { truncate, intDivide, isNaN_ } from "igniteui-webcomponents-core";
import { CellContentHorizontalAlignment_$type } from "./CellContentHorizontalAlignment";
import { ElevationHelper } from "igniteui-webcomponents-core";
import { BaseDOMEventProxy } from "igniteui-webcomponents-core";
import { DeviceUtils } from "igniteui-webcomponents-core";
import { BrushUtil } from "igniteui-webcomponents-core";
import { GridFilterDialogOpeningEventArgs } from "./GridFilterDialogOpeningEventArgs";
import { AnimationKeyFrameProperty } from "igniteui-webcomponents-core";
import { GridFilterDialogFilterChangeEventArgs } from "./GridFilterDialogFilterChangeEventArgs";
import { ColumnFilterConditionGroup } from "./ColumnFilterConditionGroup";
import { Stack$1 } from "igniteui-webcomponents-core";
import { List$1 } from "igniteui-webcomponents-core";
import { GridFilterDialogViewModelRow } from "./GridFilterDialogViewModelRow";
import { GridFilterDialogViewModelGroupingLevel } from "./GridFilterDialogViewModelGroupingLevel";
import { GridFilterDialogViewModelGrouping } from "./GridFilterDialogViewModelGrouping";
import { ColumnComparisonFilterCondition } from "./ColumnComparisonFilterCondition";
import { ColumnComparisonConditionOperatorType_$type } from "./ColumnComparisonConditionOperatorType";
import { Geometry } from "igniteui-webcomponents-core";
import { NativeUI } from "igniteui-webcomponents-core";
import { FilterDialogRenderCompletedEventArgs } from "./FilterDialogRenderCompletedEventArgs";
import { stringIsNullOrEmpty } from "igniteui-webcomponents-core";
import { GridFilterDialogViewModelGroupingLevelCollection } from "./GridFilterDialogViewModelGroupingLevelCollection";
import { ObservableCollection$1 } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
export let GridFilterDialogView = /*@__PURE__*/ (() => {
    class GridFilterDialogView extends Base {
        constructor(a) {
            super();
            this.b = null;
            this.q = null;
            this.ad = new Path();
            this.j = 0;
            this.i = 0;
            this.o = null;
            this.d = null;
            this.m = null;
            this.n = null;
            this.p = null;
            this.g = 0;
            this.f = 0;
            this.h = 1;
            this.l = 0;
            this.k = 0;
            this.e = false;
            this.c = null;
            this.b = a;
        }
        aa() {
            if (this.j != this.l || this.i != this.k) {
                this.v();
                this.j = this.l;
                this.j = this.k;
                this.o.setStyleProperty("width", this.l.toString() + "px");
                this.o.setStyleProperty("height", this.k.toString() + "px");
            }
            let a = Math.round(this.b.af * this.h);
            let b = Math.round(this.b.af * this.h);
            if (this.g != a || this.f != b) {
                this.o.setAttribute("width", a.toString());
                this.o.setAttribute("height", b.toString());
                this.g = truncate(Math.round(a));
                this.f = truncate(Math.round(b));
            }
            this.z();
            this.ad._fill = this.b.bp != null ? this.b.bp : GridStyleRepository.az;
            if (this.d.d && this.h != 1) {
                this.d.z();
                this.d.aa(this.h, this.h);
            }
            this.d.k(0, 0, this.l, this.k);
            this.d.s(this.ad);
            if (this.d.d && this.h != 1) {
                this.d.y();
            }
            this.b.bb();
        }
        v() {
            this.b.a6(this.l, this.k, this.ad);
        }
        u() {
            if (KeyFrameAnimationFactory.h == null) {
                KeyFrameAnimationFactory.h = this.m;
            }
        }
        a(a) {
            return new AnimationKeyFrameEffect(0, this.m.rootWrapper, 0, null, a);
        }
        x(a, b, c) {
            if (a == null) {
                if (this.o != null) {
                    this.o.destroy();
                }
                this.o = null;
                this.m = null;
                this.n = null;
                this.d = null;
                return;
            }
            this.h = (isNaN_(this.b.ae) ? this.b.ad : this.b.ae);
            let d = a;
            this.m = d;
            this.n = c;
            this.p = b;
            this.m.rootWrapper.addClass("ig-filter-icon");
            this.m.rootWrapper.setStyleProperty("cursor", "pointer");
            this.q = this.m.rootWrapper;
            let e = this.h;
            let f = Math.round(d.rootWrapper.width());
            let g = Math.round(d.rootWrapper.height());
            let h = this.b.af * e;
            let i = this.b.af * e;
            let j = this.m.createElement("canvas");
            j.setStyleProperty("position", "absolute");
            j.setStyleProperty("left", "0");
            j.setStyleProperty("top", "0");
            this.m.append(j);
            this.g = truncate(Math.round(h));
            this.f = truncate(Math.round(i));
            j.setAttribute("width", this.g.toString());
            j.setAttribute("height", this.g.toString());
            j.setStyleProperty("width", f.toString() + "px");
            j.setStyleProperty("height", g.toString() + "px");
            this.z();
            j.listen("mousedown", runOn(this, this.r));
            j.listen("mouseup", runOn(this, this.s));
            this.l = f;
            this.k = g;
            this.o = j;
            let k = this.m.get2DCanvasContext(this.o);
            this.d = new RenderingContext(new CanvasViewRenderer(), k);
            if (isNaN_(this.b.ae)) {
                this.b.ad = window.devicePixelRatio;
                this.h = this.b.ad;
            }
            this.aa();
        }
        z() {
            if (this.b.k == this.b.l) {
                this.m.rootWrapper.setStyleProperty("position", "relative");
                this.m.rootWrapper.setStyleProperty("left", "0px");
                this.m.rootWrapper.setStyleProperty("top", "0px");
                return;
            }
            this.m.rootWrapper.setStyleProperty("position", "absolute");
            if (this.b.l == 2) {
                this.m.rootWrapper.setStyleProperty("left", "unset");
                this.m.rootWrapper.setStyleProperty("right", this.b.aj + "px");
            }
            else {
                this.m.rootWrapper.setStyleProperty("left", this.b.ai + "px");
            }
            let a = intDivide(this.p.height(), 2) - (this.k / 2);
            this.m.rootWrapper.setStyleProperty("top", a + "px");
        }
        r(a) {
        }
        s(a) {
            if (a.button == 2) {
                return;
            }
            if (!this.e) {
                this.b.bd();
            }
            else {
                this.b.a2();
            }
        }
        ab() {
            this.aa();
        }
        y(a, b) {
            if (isNaN_(this.b.ae)) {
                this.b.ad = window.devicePixelRatio;
                this.h = this.b.ad;
            }
            this.l = a;
            this.k = b;
            this.aa();
        }
        w() {
            if (isNaN_(this.b.ae)) {
                this.b.ad = window.devicePixelRatio;
                if (this.h != this.b.ad) {
                    this.h = this.b.ad;
                    this.aa();
                    return;
                }
            }
            this.z();
        }
        ac(a) {
            this.e = true;
            let b = new GridFilterDialogPanel(this.b, this.o, this.m, this.n);
            b.a = this.b;
            b.s(a);
            this.c = b;
        }
        t() {
            this.e = false;
            if (this.c != null) {
                this.c.k();
                this.c.l();
                this.c = null;
            }
        }
    }
    GridFilterDialogView.$t = /*@__PURE__*/ markType(GridFilterDialogView, 'GridFilterDialogView');
    return GridFilterDialogView;
})();
/**
 * @hidden
 */
export let GridFilterDialogPanel = /*@__PURE__*/ (() => {
    class GridFilterDialogPanel extends Base {
        constructor(a, b, c, d) {
            super();
            this.b = null;
            this.j = null;
            this.d = null;
            this.i = 264;
            this.a = null;
            this.h = null;
            this.f = null;
            this.e = null;
            this.g = null;
            this.b = a;
            let e = c.createElement("div");
            let f = c.getSubRenderer(e);
            e.setStyleProperty("position", "absolute");
            e.setStyleProperty("width", this.i + "px");
            e.setStyleProperty("top", "0px");
            e.setStyleProperty("left", "0px");
            e.setStyleProperty("display", "none");
            e.setStyleProperty("z-index", "10000");
            e.setStyleProperty("background-color", "#fff");
            e.setStyleProperty("border-radius", "3px");
            e.setStyleProperty("overflow", "auto");
            let g = ElevationHelper.e(12, this.b.bo, this.b.bn, this.b.bm);
            e.setStyleProperty("boxShadow", g);
            e.listen("mousedown", runOn(this, this.n));
            this.onDocumentKeyDown = this.onDocumentKeyDown.bind(this);
            this.onDocumentMouseClick = this.onDocumentMouseClick.bind(this);
            this.h = b;
            this.f = f;
            this.g = e;
            this.e = d;
        }
        n(a) {
            a.stopPropagation();
        }
        onDocumentKeyDown(a) {
            if (BaseDOMEventProxy.cv(a) == 8) {
                this.b.a2();
            }
        }
        onDocumentMouseClick(e_) {
            let filterIconCanvas_ = this.b.aq();
            let a = (e_.srcElement === filterIconCanvas_ || e_.target === filterIconCanvas_);
            if (!a) {
                this.b.a2();
            }
        }
        onFilterApplyClick() {
            this.b.a2();
        }
        onFilterCancelClick() {
            this.b.a2();
        }
        s(a) {
            this.m();
            this.g.setStyleProperty("display", "block");
            this.f.appendToBody(this.g);
            if (this.j == null) {
                this.e.getPortal(this.g, "GridColumnOptions", (b) => {
                    this.d = b;
                    let comp_ = b.componentRef;
                    let col_ = a;
                    let displayDensity_ = a.grid.fl;
                    let buttonDensity_ = GridFilterDialogPanel.c(displayDensity_, true);
                    let filterListDensity_ = GridFilterDialogPanel.c(displayDensity_, true);
                    this.j = comp_.i;
                    let options_ = this.j;
                    options_.column = col_;
                    options_.density = displayDensity_;
                    options_.buttonDensity = buttonDensity_;
                    options_.summaryListDensity = filterListDensity_;
                    options_.filterListDensity = filterListDensity_;
                    options_.filterApplyButtonClick = delegateCombine(options_.filterApplyButtonClick, runOn(this, this.onFilterApplyClick));
                    options_.filterCancelButtonClick = delegateCombine(options_.filterCancelButtonClick, runOn(this, this.onFilterCancelClick));
                }, false);
            }
            document.addEventListener("keydown", this.onDocumentKeyDown, false);
            document.addEventListener("mousedown", this.onDocumentMouseClick, false);
        }
        m() {
            let a = this.h.width();
            let filterIcon_ = this.h.getNativeElement();
            let boundingRect_ = filterIcon_.getBoundingClientRect();
            let b = (boundingRect_.left);
            let c = (boundingRect_.right);
            let gridDiv_ = this.e.rootWrapper.getNativeElement();
            let gridBoundingRect_ = gridDiv_.getBoundingClientRect();
            let d = (gridBoundingRect_.right);
            let e = (window.innerWidth);
            let f = true;
            if (b > e - this.i - 10) {
                f = false;
            }
            if (f) {
                this.g.setStyleProperty("left", this.h.getOffset().left + "px");
            }
            else {
                let g = Math.max(10, this.h.getOffset().left - (this.i - a));
                this.g.setStyleProperty("left", g + "px");
            }
            this.g.setStyleProperty("top", (this.h.getOffset().top + this.h.outerHeight()) + "px");
        }
        k() {
            document.removeEventListener("keydown", this.onDocumentKeyDown, false);
            document.removeEventListener("mousedown", this.onDocumentMouseClick, false);
            let options_ = this.j;
            options_.filterApplyButtonClick = delegateRemove(options_.filterApplyButtonClick, runOn(this, this.onFilterApplyClick));
            options_.filterCancelButtonClick = delegateRemove(options_.filterCancelButtonClick, runOn(this, this.onFilterCancelClick));
            ;
            options_.column = null;
            this.g.setStyleProperty("display", "none");
            this.g.remove();
        }
        l() {
            this.f.destroy();
            this.g.unlistenAll();
            this.j = null;
            this.g = null;
            if (this.d != null) {
                this.d.destroy();
            }
        }
        static c(a, b) {
            switch (a) {
                case 1: return b ? 2 : 1;
                case 2: return b ? 3 : 1;
                case 3: return b ? 3 : 2;
                case 0: return a;
                default: return a;
            }
        }
    }
    GridFilterDialogPanel.$t = /*@__PURE__*/ markType(GridFilterDialogPanel, 'GridFilterDialogPanel');
    return GridFilterDialogPanel;
})();
/**
 * @hidden
 */
export let GridFilterDialog = /*@__PURE__*/ (() => {
    class GridFilterDialog extends Base {
        constructor() {
            super();
            this.am = null;
            this.w = true;
            this.propertyChanged = null;
            this.ab = NaN;
            this.aa = 1;
            this.j = 2;
            this.i = 0;
            this.ag = 0;
            this.ah = 0;
            this.bl = null;
            this.ac = DeviceUtils.g(24);
            this.bo = null;
            this.bn = null;
            this.bm = null;
            this.m = null;
            this.u = null;
            this.v = false;
            this.f = null;
            this.dialogOpening = null;
            this.filterChanging = null;
            this.filterChanged = null;
            this.r = null;
            this.renderCompleted = null;
            this.r = new GridFilterDialogView(this);
            this.bo = BrushUtil.g(66, 0, 0, 0);
            this.bn = BrushUtil.g(30, 0, 0, 0);
            this.bm = BrushUtil.g(20, 0, 0, 0);
        }
        get an() {
            return this.am;
        }
        set an(a) {
            this.am = a;
        }
        get x() {
            return this.w;
        }
        set x(a) {
            let b = this.w;
            this.w = a;
            if (b != this.w) {
                this.ba("IsAnimationEnabled", b, this.w);
            }
        }
        get ae() {
            return this.ab;
        }
        set ae(a) {
            let b = this.ab;
            this.ab = a;
            this.ba("PixelScalingRatio", b, this.ab);
        }
        get ad() {
            return this.aa;
        }
        set ad(a) {
            let b = this.aa;
            this.aa = a;
            this.ba("ActualPixelScalingRatio", b, this.aa);
        }
        get l() {
            return this.j;
        }
        set l(a) {
            let b = this.j;
            this.j = a;
            if (b != this.j) {
                this.ba("IconHorizontalAlignment", enumGetBox(CellContentHorizontalAlignment_$type, b), enumGetBox(CellContentHorizontalAlignment_$type, this.j));
            }
        }
        get k() {
            return this.i;
        }
        set k(a) {
            let b = this.i;
            this.i = a;
            if (b != this.i) {
                this.ba("HeaderTextALignment", enumGetBox(CellContentHorizontalAlignment_$type, b), enumGetBox(CellContentHorizontalAlignment_$type, this.i));
            }
        }
        get ai() {
            return this.ag;
        }
        set ai(a) {
            let b = this.ag;
            this.ag = a;
            if (b != this.ag) {
                this.ba("CellPaddingLeft", b, this.ag);
            }
        }
        get aj() {
            return this.ah;
        }
        set aj(a) {
            let b = this.ah;
            this.ah = a;
            if (b != this.ah) {
                this.ba("CellPaddingRight", b, this.ah);
            }
        }
        get bp() {
            return this.bl;
        }
        set bp(a) {
            let b = this.bl;
            this.bl = a;
            if (b != this.bl) {
                this.ba("IconColor", b, this.bl);
            }
        }
        get af() {
            return this.ac;
        }
        set af(a) {
            let b = this.ac;
            this.ac = a;
            if (b != this.ac) {
                this.ba("ViewSize", b, this.ac);
            }
        }
        get y() {
            return this.r.e;
        }
        ba(a, b, c) {
            this.be(a, b, c);
            if (this.propertyChanged != null) {
                this.propertyChanged(this, new PropertyChangedEventArgs(a));
            }
        }
        be(a, b, c) {
            switch (a) {
                case "PixelScalingRatio":
                    this.ad = this.ae;
                    break;
                case "ActualPixelScalingRatio":
                    this.r.ab();
                    break;
                case "IconHorizontalAlignment":
                case "IconColor":
                case "HeaderTextALignment":
                case "CellPaddingLeft":
                case "CellPaddingRight":
                case "ViewSize":
                    this.r.ab();
                    break;
            }
        }
        bf(a, b, c) {
            this.r.x(a, b, c);
        }
        bd() {
            let a = null;
            let b = 0;
            if (this.dialogOpening != null) {
                let c = new GridFilterDialogOpeningEventArgs();
                this.dialogOpening(this, c);
                this.m = c.a;
            }
            this.bj(this.m);
            if (this.m != null) {
                let d = this.m;
                d.propertyChanged = delegateCombine(d.propertyChanged, runOn(this, this.a3));
            }
        }
        a3(a, b) {
            switch (b.propertyName) {
                case "IsHidden":
                    this.a2();
                    break;
            }
        }
        bj(a) {
            this.r.ac(a);
        }
        a9() {
        }
        a4() {
            this.r.u();
            if (this.u == null) {
                let a = new AnimationKeyFrameEffectTiming();
                a.g = 200;
                a.b = 0;
                this.u = KeyFrameAnimationFactory.f.c(this.r.a(a).m(new AnimationKeyFrameProperty(1, 0)).m(new AnimationKeyFrameProperty(1, 1)));
            }
        }
        bi() {
            if (this.filterChanged != null) {
                this.filterChanged(this, ((() => {
                    let $ret = new GridFilterDialogFilterChangeEventArgs();
                    $ret.a = this.f;
                    return $ret;
                })()));
            }
        }
        bh() {
            if (this.filterChanged != null) {
                this.filterChanged(this, ((() => {
                    let $ret = new GridFilterDialogFilterChangeEventArgs();
                    $ret.a = null;
                    return $ret;
                })()));
            }
        }
        bg(a, b) {
            let c = this.e(a);
            if (b) {
                if (this.filterChanged != null) {
                    this.filterChanged(this, ((() => {
                        let $ret = new GridFilterDialogFilterChangeEventArgs();
                        $ret.a = c;
                        return $ret;
                    })()));
                }
            }
            else {
                if (this.filterChanging != null) {
                    this.filterChanging(this, ((() => {
                        let $ret = new GridFilterDialogFilterChangeEventArgs();
                        $ret.a = c;
                        return $ret;
                    })()));
                }
            }
        }
        e(a) {
            let b = new ColumnFilterConditionGroup();
            b.f = a.k;
            let c = new Stack$1(ColumnFilterConditionGroup.$);
            let d = 0;
            let e = b;
            for (let f = 0; f < a.f.count; f++) {
                let g = this.h(d, c, a, f);
                while (g != null) {
                    e.h(g);
                    e = g;
                    d++;
                    g = this.h(d, c, a, f);
                }
                g = this.g(d, c, a, f);
                while (g != null) {
                    e = g;
                    d--;
                    g = this.g(d, c, a, f);
                }
                if (e == null) {
                    e = b;
                }
                if (this.z(a, a.f._inner[f])) {
                    continue;
                }
                e.h(this.d(a.f._inner[f]));
            }
            if (b.g == 0) {
                return null;
            }
            return b;
        }
        z(a, b) {
            let c = 0;
            for (let d = 0; d < b.e.length; d++) {
                if (b.e[d] == b.l) {
                    c = d;
                    break;
                }
            }
            if (b.d[c] > 0 && b.i == null) {
                return true;
            }
            if (a.a != 0 && b.d[c] > 0 && typeof b.i === 'string' && stringIsNullOrEmpty(b.i)) {
                return true;
            }
            return false;
        }
        g(a, b, c, d) {
            let e = this.al(c, d);
            if (a > e) {
                b.e();
                return b.d();
            }
            return null;
        }
        al(a, b) {
            let c = a.c(b);
            if (c == null) {
                return 0;
            }
            return a.e.indexOf(c);
        }
        h(a, b, c, d) {
            let e = this.al(c, d);
            if (a < e) {
                let f = c.b(d);
                let g = new ColumnFilterConditionGroup();
                g.f = f.a;
                b.h(g);
                return g;
            }
            return null;
        }
        d(a) {
            let b = new ColumnComparisonFilterCondition();
            b.e = this.c(a.l);
            b.j = a.i;
            return b;
        }
        c(a) {
            return EnumUtil.getEnumValue(ColumnComparisonConditionOperatorType_$type, EnumUtil.parse(ColumnComparisonConditionOperatorType_$type, a, true));
        }
        bc(a) {
            this.bg(a, false);
        }
        s(a, b) {
            let c = new GridFilterDialogViewModel();
            if (a != null) {
                this.a1(c, a, b);
            }
            else {
                let d = new GridFilterDialogViewModelRow();
                d.f = b;
                d.e = GridFilterDialog.a(b);
                d.d = GridFilterDialog.b(b);
                d.l = GridFilterDialog.au(b[0]);
                c.f.add(d);
            }
            return c;
        }
        a1(a, b, c) {
            if (b.b()) {
                let d = b;
                for (let e = 0; e < d.g; e++) {
                    let f = d.item(e);
                    this.a1(a, f, c);
                }
            }
            else {
                a.f.add(this.t(b, c));
            }
        }
        t(a, b) {
            let c = new GridFilterDialogViewModelRow();
            c.l = GridFilterDialog.au(a.e);
            c.f = b;
            c.e = GridFilterDialog.a(b);
            c.i = GridFilterDialog.ao(GridFilterDialog.ak(a.e), a.e, a);
            c.j = GridFilterDialog.ap(GridFilterDialog.ak(a.e), a.e, a);
            c.d = GridFilterDialog.b(b);
            return c;
        }
        static ak(a) {
            return ColumnComparisonFilterCondition.h(a);
        }
        static ao(a, b, c) {
            if (a == 0) {
                return "";
            }
            return c.j != null ? c.j.toString() : "";
        }
        static ap(a, b, c) {
            return "";
        }
        static b(a) {
            return ColumnComparisonFilterCondition.d(a);
        }
        static a(a) {
            let b = new Array(a.length);
            for (let c = 0; c < a.length; c++) {
                b[c] = EnumUtil.getName(ColumnComparisonConditionOperatorType_$type, a[c]);
            }
            return b;
        }
        static au(a) {
            return EnumUtil.getName(ColumnComparisonConditionOperatorType_$type, a);
        }
        a8(a, b) {
            this.r.y(a, b);
        }
        a7() {
            this.r.w();
        }
        a6(a, b, c) {
            let d = Geometry.a("M12 14c -1.1 0 -2 -0.9 -2 -2 s0.9 -2 2 -2 s2 0.9 2 2 S13.1 14 12 14 z M12 8c -1.1 0 -2 -0.9 -2 -2 s0.9 -2 2 -2 s2 0.9 2 2 S13.1 8 12 8z M12 16 c1.1 0 2 0.9 2 2s -0.9 2 -2 2 s-2 -0.9 -2 -2 S10.9 16 12 16z");
            c.ak = d;
            c._fill = this.bp == null ? GridStyleRepository.az : this.bp;
        }
        bk() {
            this.v = false;
            if (NativeUI.e(this.r.q) == 1) {
                return;
            }
            if (this.x) {
                this.a4();
                if (this.u.playbackRate < 0) {
                    this.u.reverse();
                }
                else {
                    this.u.play();
                }
                this.u.finished.f((a) => this.u.commitStyles());
            }
            else {
                NativeUI.t(this.r.q, 1);
            }
        }
        a5() {
            this.v = true;
            if (!this.y) {
                if (this.x) {
                    this.a4();
                    if (this.u.playbackRate < 0) {
                        this.u.play();
                    }
                    else {
                        this.u.reverse();
                    }
                    this.u.finished.f((a) => this.u.commitStyles());
                }
                else {
                    NativeUI.t(this.r.q, 0);
                }
                this.v = false;
            }
        }
        a2() {
            this.r.t();
            this.a9();
            if (this.v) {
                this.a5();
            }
            if (this.m != null) {
                let a = this.m;
                a.propertyChanged = delegateRemove(a.propertyChanged, runOn(this, this.a3));
                this.m = null;
            }
        }
        aq() {
            return this.r.o.getNativeElement();
        }
        bb() {
            if (this.renderCompleted != null) {
                this.renderCompleted(this, new FilterDialogRenderCompletedEventArgs());
            }
        }
    }
    GridFilterDialog.$t = /*@__PURE__*/ markType(GridFilterDialog, 'GridFilterDialog', Base.$, [INotifyPropertyChanged_$type]);
    return GridFilterDialog;
})();
/**
 * @hidden
 */
export let GridFilterDialogViewModel = /*@__PURE__*/ (() => {
    class GridFilterDialogViewModel extends Base {
        constructor() {
            super();
            this.a = 0;
            this.e = null;
            this.k = false;
            this.m = 0;
            this.f = null;
            this.onModified = null;
            this.k = false;
            this.f = new GridFilterDialogViewModelRowCollection();
            this.f.ae = this;
            this.e = new GridFilterDialogViewModelGroupingLevelCollection();
            this.f.ag = runOn(this, this.u);
            let a = this.f;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.t));
        }
        n() {
            let a = new GridFilterDialogViewModelRow();
            let b = ColumnComparisonFilterCondition.c(this.a);
            a.f = b;
            a.e = GridFilterDialog.a(b);
            a.d = GridFilterDialog.b(b);
            a.l = GridFilterDialog.au(b[0]);
            this.f.add(a);
        }
        u(a) {
            if (this.onModified != null) {
                this.onModified(this);
            }
        }
        t(a, b) {
            switch (b.action) {
                case 0:
                    if (b.newItems != null) {
                        for (let c = 0; c < b.newItems.count; c++) {
                            let d = b.newItems.item(c);
                            this.q(c + b.newStartingIndex, d);
                        }
                    }
                    break;
                case 1:
                    if (b.oldItems != null) {
                        for (let e = 0; e < b.oldItems.count; e++) {
                            this.r(b.oldStartingIndex);
                        }
                    }
                    break;
                case 2:
                    if (b.oldItems != null) {
                        for (let f = 0; f < b.oldItems.count; f++) {
                            this.r(b.oldStartingIndex);
                        }
                    }
                    if (b.newItems != null) {
                        for (let g = 0; g < b.newItems.count; g++) {
                            let h = b.newItems.item(g);
                            this.q(g + b.newStartingIndex, b.newItems.item(g));
                        }
                    }
                    break;
                case 4:
                    this.s();
                    break;
            }
            if (this.onModified != null) {
                this.onModified(this);
            }
        }
        r(a) {
            let b = this.c(a);
            if (b == null) {
                return;
            }
            let c = this.b(a);
            if (c == null) {
                return;
            }
            this.w(c, a);
            for (let d = b.indexOf(c) + 1; d < b.count; d++) {
                this.v(b._inner[d], -1);
            }
        }
        w(a, b) {
            a.b--;
        }
        s() {
            this.e.clear();
        }
        q(a, b) {
            let c = this.c(a);
            if (c == null) {
                return;
            }
            let d = this.b(a);
            if (d == null) {
                return;
            }
            this.p(d, a);
            for (let e = c.indexOf(d) + 1; e < c.count; e++) {
                this.v(c._inner[e], +1);
            }
        }
        v(a, b) {
            a.c += b;
            a.b -= b;
        }
        p(a, b) {
            a.b++;
        }
        b(a) {
            for (let b = this.e.count - 1; b >= 0; b--) {
                for (let c = 0; c < this.e._inner[b].count; c--) {
                    if (this.e._inner[b]._inner[c].c <= a && this.e._inner[b]._inner[c].b >= a) {
                        return this.e._inner[b]._inner[c];
                    }
                }
            }
            return null;
        }
        c(a) {
            for (let b = this.e.count - 1; b >= 0; b--) {
                for (let c = 0; c < this.e._inner[b].count; c--) {
                    if (this.e._inner[b]._inner[c].c <= a && this.e._inner[b]._inner[c].b >= a) {
                        return this.e._inner[b];
                    }
                }
            }
            return null;
        }
        h(a, b) {
            let c = this.d(a, b);
            if (this.i(c, a, b)) {
                if (this.e.count < this.m) {
                    return true;
                }
                else {
                    return false;
                }
            }
            return true;
        }
        i(a, b, c) {
            if (a == null) {
                return false;
            }
            for (let d = 0; d < a.count; d++) {
                if (this.j(a._inner[d], b, c)) {
                    return true;
                }
            }
            return false;
        }
        j(a, b, c) {
            if (c > a.c || b > a.b) {
                return false;
            }
            return true;
        }
        d(a, b) {
            if (this.e.count == 0) {
                return null;
            }
            for (let c = 0; c < this.e.count; c++) {
                if (!this.i(this.e._inner[c], a, b)) {
                    return this.e._inner[c];
                }
            }
            return this.e._inner[this.e.count - 1];
        }
        aa(a, b) {
            for (let c = 0; c < this.e.count; c++) {
                for (let d = 0; d < this.e._inner[c].count; d++) {
                    if (this.e._inner[c]._inner[d].c == a && this.e._inner[c]._inner[d].b == b) {
                        this.e._inner[c].removeAt(d);
                        break;
                    }
                }
            }
            this.x();
            if (this.onModified != null) {
                this.onModified(this);
            }
        }
        x() {
            for (let a = this.e.count - 1; a >= 0; a--) {
                let b = new List$1(GridFilterDialogViewModelGrouping.$, 0);
                for (let c = 0; c < this.e._inner[a].count; c++) {
                    let d = this.e._inner[a]._inner[c];
                    if (a > 0) {
                        if (!this.i(this.e._inner[a - 1], d.c, d.b)) {
                            b.add(d);
                        }
                    }
                }
                for (let e = 0; e < b.count; e++) {
                    this.e._inner[a].remove(b._inner[e]);
                    this.e._inner[a - 1].add(b._inner[e]);
                }
                if (this.e._inner[a].count == 0) {
                    this.e.removeAt(a);
                }
            }
            this.y();
        }
        y() {
            for (let a = this.e.count - 1; a >= 0; a--) {
                let b = new List$1(GridFilterDialogViewModelGrouping.$, 0);
                for (let c = 0; c < this.e._inner[a].count; c++) {
                    b.add(this.e._inner[a]._inner[c]);
                }
                b.aa((d, e) => Base.compareSimple(d.c, e.c));
                this.e._inner[a].clear();
                for (let d = 0; d < this.e._inner[a].count; d++) {
                    this.e._inner[a].add(b._inner[d]);
                }
            }
        }
        l(a, b) {
            for (let c = 0; c < this.e.count; c++) {
                for (let d = 0; d < this.e._inner[c].count; d++) {
                    if (this.e._inner[c]._inner[d].c == a && this.e._inner[c]._inner[d].b == b) {
                        return true;
                    }
                }
            }
            return false;
        }
        z(a, b) {
            for (let c = 0; c < this.e.count; c++) {
                for (let d = 0; d < this.e._inner[c].count; d++) {
                    if (this.e._inner[c]._inner[d].c == a && this.e._inner[c]._inner[d].b == b) {
                        this.e._inner[c]._inner[d].a = !this.e._inner[c]._inner[d].a;
                    }
                }
            }
            if (this.onModified != null) {
                this.onModified(this);
            }
        }
        o(a, b, c) {
            if (!this.h(a, b)) {
                return;
            }
            let d = this.d(a, b);
            let e = d;
            if (this.i(d, a, b)) {
                this.e.add(new GridFilterDialogViewModelGroupingLevel());
                e = this.d(a, b);
            }
            e.add(((() => {
                let $ret = new GridFilterDialogViewModelGrouping();
                $ret.c = a;
                $ret.b = b;
                $ret.a = c;
                return $ret;
            })()));
            this.y();
            if (this.onModified != null) {
                this.onModified(this);
            }
        }
    }
    GridFilterDialogViewModel.$t = /*@__PURE__*/ markType(GridFilterDialogViewModel, 'GridFilterDialogViewModel');
    return GridFilterDialogViewModel;
})();
/**
 * @hidden
 */
export let GridFilterDialogViewModelRowCollection = /*@__PURE__*/ (() => {
    class GridFilterDialogViewModelRowCollection extends ObservableCollection$1 {
        constructor() {
            super(GridFilterDialogViewModelRow.$, 0);
            this.ae = null;
            this.af = null;
            this.collectionChanged = delegateCombine(this.collectionChanged, runOn(this, this.ah));
        }
        ah(a, b) {
            if (b.oldItems != null) {
                for (let c = 0; c < b.oldItems.count; c++) {
                    let d = b.oldItems.item(c);
                    d.propertyChanged = delegateRemove(d.propertyChanged, runOn(this, this.ai));
                }
            }
            if (b.newItems != null) {
                for (let e = 0; e < b.newItems.count; e++) {
                    let f = b.newItems.item(e);
                    f.propertyChanged = delegateCombine(f.propertyChanged, runOn(this, this.ai));
                }
            }
        }
        ai(a, b) {
            if (this.af != null) {
                this.af(this.ae);
            }
        }
        get ag() {
            return this.af;
        }
        set ag(a) {
            this.af = a;
        }
    }
    GridFilterDialogViewModelRowCollection.$t = /*@__PURE__*/ markType(GridFilterDialogViewModelRowCollection, 'GridFilterDialogViewModelRowCollection', /*@__PURE__*/ ObservableCollection$1.$.specialize(GridFilterDialogViewModelRow.$));
    return GridFilterDialogViewModelRowCollection;
})();
//# sourceMappingURL=GridFilterDialogView_combined.js.map
