/*
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 * as tslib_1 from "tslib";
import { GridColumnOptionsViewBase } from "./GridColumnOptionsViewBase";
import { SummaryChooser } from "./SummaryChooser";
import { Popup } from "igniteui-webcomponents-layouts";
import { Size } from "igniteui-webcomponents-core";
import { GridColumnOptionsUtilities } from "./GridColumnOptionsUtilities";
import { runOn, markType, enumGetBox, delegateRemove, delegateCombine } from "igniteui-webcomponents-core";
import { ControlDisplayDensity_$type } from "igniteui-webcomponents-core";
import { Rect } from "igniteui-webcomponents-core";
import { GridColumnOptionsSectionBase } from "./GridColumnOptionsSectionBase";
import { ColumnSummaryDescription } from "./ColumnSummaryDescription";
import { stringFormat } from "igniteui-webcomponents-core";
import { stringIsNullOrWhiteSpace } from "igniteui-webcomponents-core";
/**
 * @hidden
 */
var GridColumnSummaryOptionsView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(GridColumnSummaryOptionsView, _super);
    function GridColumnSummaryOptionsView() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.o = null;
        _this.p = null;
        return _this;
    }
    Object.defineProperty(GridColumnSummaryOptionsView.prototype, "n", {
        get: function () {
            return this.b;
        },
        enumerable: true,
        configurable: true
    });
    GridColumnSummaryOptionsView.prototype.k = function () {
        var _this = this;
        _super.prototype.k.call(this);
        if (null == this.g || null == this.e) {
            return;
        }
        if (this.n.b2 == null) {
            var a_1;
            var b_1;
            var c_1;
            this.o = ((function () { var d = GridColumnOptionsUtilities.g(_this.e, GridColumnSummaryOptionsView.r, 1, _this.n.p, _this.n.j, new Size(1, 24, 24), a_1, b_1, _this.p, c_1, false, true); a_1 = d.p6; b_1 = d.p7; _this.p = d.p8; c_1 = d.p9; return d.ret; })());
            c_1.setStyleProperty("transform", "rotate(-90deg)");
            this.g.append(this.o);
            this.n.cg(a_1);
        }
        if (this.n.bv == null) {
            var d = new SummaryChooser();
            d.a2(this.e);
            this.n.ck(d);
            var e = this.e.createElement("div");
            var f = this.e.getSubRenderer(e);
            var g = new Popup();
            g.provideRenderer(f);
            g.appendPopupContent(d.c.container);
            this.n.ch(g);
        }
        document.addEventListener("mousedown", runOn(this, this.s), false);
    };
    GridColumnSummaryOptionsView.prototype.m = function () {
        _super.prototype.m.call(this);
        this.n.bf(this.n.b2);
        if (this.o != null) {
            this.o.setStyleProperty("margin", "0 -8px");
            switch (this.n.b2.g) {
                case 2:
                    this.p.setStyleProperty("margin", "0 -.25rem");
                    break;
                case 1:
                case 3:
                    this.p.setStyleProperty("margin", "0 -.5rem");
                    break;
            }
            this.p.setRawText(this.n.b9);
            this.p.setStyleProperty("font", this.n.aa.fontString);
        }
    };
    GridColumnSummaryOptionsView.prototype.t = function () {
        if (this.o != null) {
            var a = this.o.getNativeElement().getBoundingClientRect();
            var b = new Rect(4);
            b.left = (a.left);
            b.top = (a.top);
            b.width = (a.width);
            b.height = (a.height);
            return b;
        }
        return Rect.empty;
    };
    GridColumnSummaryOptionsView.prototype.u = function () {
        var a = this.t();
        a.x += window.pageXOffset;
        a.y += window.pageYOffset;
        return a;
    };
    GridColumnSummaryOptionsView.prototype.q = function () {
        return (window.innerWidth);
    };
    GridColumnSummaryOptionsView.prototype.s = function (e_) {
        this.n.cf();
    };
    GridColumnSummaryOptionsView.$t = markType(GridColumnSummaryOptionsView, 'GridColumnSummaryOptionsView', GridColumnOptionsViewBase.$);
    GridColumnSummaryOptionsView.r = "M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z";
    return GridColumnSummaryOptionsView;
}(GridColumnOptionsViewBase));
export { GridColumnSummaryOptionsView };
/**
 * @hidden
 */
var GridColumnSummaryOptions = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(GridColumnSummaryOptions, _super);
    function GridColumnSummaryOptions() {
        var _this = _super.call(this) || this;
        _this.b1 = null;
        _this.b3 = null;
        _this.bu = null;
        _this.b6 = null;
        _this.bx = 0;
        _this.bw = 0;
        _this.b4 = 0;
        return _this;
    }
    GridColumnSummaryOptions.prototype.f = function () {
        return new GridColumnSummaryOptionsView();
    };
    GridColumnSummaryOptions.prototype.bq = function () {
        if (this.column == null) {
            return false;
        }
        if (!this.column.gd) {
            return false;
        }
        return this.c.hy && this.c.t != 3;
    };
    GridColumnSummaryOptions.prototype.bc = function (a, b, c) {
        _super.prototype.bc.call(this, a, b, c);
        switch (a) {
            case "ActualBaseTheme":
            case "ActualDensity":
            case "ActualSummaryListDensity":
            case "BackgroundColor":
            case "TextColor":
                this.cm();
                this.cl();
                this.cn();
                break;
            case "SummaryListDensity":
                this.by = this.b0 == 0 ? this.q : this.b0;
                break;
            case "SummaryCaption":
            case "ActualLabelTextStyle":
            case "ActiveCount":
                this.bt.m();
                break;
        }
    };
    GridColumnSummaryOptions.prototype.br = function () {
        if (this.bu != null) {
            var a = this.bu.a();
            for (var b = 0; b < a.length; b++) {
                var c = new ColumnSummaryDescription(1, this.column.h4);
                switch (a[b]) {
                    case "avg":
                        c.n = 3;
                        break;
                    case "count":
                        c.n = 4;
                        break;
                    case "max":
                        c.n = 1;
                        break;
                    case "min":
                        c.n = 0;
                        break;
                    case "sum":
                        c.n = 2;
                        break;
                }
                for (var d = 0; d < this.c.b8.i.count; d++) {
                    var e = this.c.b8.i.item(d);
                    if (e.af == this.column.h4 && e.n == c.n) {
                        this.c.b8.i.removeAt(d);
                        d--;
                    }
                }
            }
            var f = this.bu.b();
            for (var g = 0; g < f.length; g++) {
                var h = new ColumnSummaryDescription(1, this.column.h4);
                switch (f[g]) {
                    case "avg":
                        h.n = 3;
                        break;
                    case "count":
                        h.n = 4;
                        break;
                    case "max":
                        h.n = 1;
                        break;
                    case "min":
                        h.n = 0;
                        break;
                    case "sum":
                        h.n = 2;
                        break;
                }
                var i = false;
                for (var j = 0; j < this.c.b8.i.count; j++) {
                    var k = this.c.b8.i.item(j);
                    if (k.af == this.column.h4 && k.n == h.n) {
                        i = true;
                        break;
                    }
                }
                if (!i) {
                    this.c.b8.i.add(h);
                }
            }
        }
        if (this.b3 != null && this.b3.t) {
            this.b3.ao();
        }
    };
    GridColumnSummaryOptions.prototype.bs = function () {
        if (this.b3 != null && this.b3.t) {
            this.b3.ao();
        }
    };
    GridColumnSummaryOptions.prototype.a5 = function () {
        _super.prototype.a5.call(this);
        if (this.column != null) {
            this.b5 = 0;
            for (var a = 0; a < this.c.b8.i.count; a++) {
                var b = this.c.b8.i.item(a);
                if (b.af == this.column.h4) {
                    switch (b.n) {
                        case 3:
                            this.bu.a4("avg", true);
                            this.b5++;
                            break;
                        case 4:
                            this.bu.a4("count", true);
                            this.b5++;
                            break;
                        case 1:
                            this.bu.a4("max", true);
                            this.b5++;
                            break;
                        case 0:
                            this.bu.a4("min", true);
                            this.b5++;
                            break;
                        case 2:
                            this.bu.a4("sum", true);
                            this.b5++;
                            break;
                    }
                }
            }
        }
    };
    Object.defineProperty(GridColumnSummaryOptions.prototype, "b9", {
        get: function () {
            if (this.b5 > 0) {
                return stringFormat("{0} ({1})", this.cb, this.b5);
            }
            else {
                return this.cb;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "b2", {
        get: function () {
            return this.b1;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "bv", {
        get: function () {
            return this.bu;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "bt", {
        get: function () {
            return this.e;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "cb", {
        get: function () {
            if (this.b6 == null) {
                var a = this.ai.b1("Column_Options_Summary_Average");
                return !stringIsNullOrWhiteSpace(a) ? a : "Summaries";
            }
            else {
                return this.b6;
            }
        },
        set: function (a) {
            var b = this.b6;
            this.b6 = a;
            if (b != this.b6) {
                this.ba("SummaryCaption", b, this.b6);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "b0", {
        get: function () {
            return this.bx;
        },
        set: function (a) {
            var b = this.bx;
            this.bx = a;
            if (b != this.bx) {
                this.ba("SummaryListDensity", enumGetBox(ControlDisplayDensity_$type, b), enumGetBox(ControlDisplayDensity_$type, this.bx));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "by", {
        get: function () {
            return this.bw;
        },
        set: function (a) {
            var b = this.bw;
            this.bw = a;
            if (b != this.bw) {
                this.ba("ActualSummaryListDensity", enumGetBox(ControlDisplayDensity_$type, b), enumGetBox(ControlDisplayDensity_$type, this.bw));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GridColumnSummaryOptions.prototype, "b5", {
        get: function () {
            return this.b4;
        },
        set: function (a) {
            var b = this.b4;
            this.b4 = a;
            if (b != this.b4) {
                this.ba("ActiveCount", b, this.b4);
            }
        },
        enumerable: true,
        configurable: true
    });
    GridColumnSummaryOptions.prototype.cf = function () {
        if (this.b3 != null && this.b3.t) {
            this.b3.ao();
        }
    };
    GridColumnSummaryOptions.prototype.cg = function (a) {
        if (this.b1 != null) {
            var b = this.b1;
            b.clicked = delegateRemove(b.clicked, runOn(this, this.ci));
        }
        this.b1 = a;
        if (this.b1 != null) {
            var c = this.b1;
            c.clicked = delegateCombine(c.clicked, runOn(this, this.ci));
        }
        this.cl();
    };
    GridColumnSummaryOptions.prototype.ch = function (a) {
        this.b3 = a;
        this.cn();
    };
    GridColumnSummaryOptions.prototype.ck = function (a) {
        if (this.bu != null) {
            var b = this.bu;
            b.summaryChanged = delegateRemove(b.summaryChanged, runOn(this, this.cj));
        }
        this.bu = a;
        if (this.bu != null) {
            var c = this.bu;
            c.summaryChanged = delegateCombine(c.summaryChanged, runOn(this, this.cj));
        }
        this.cm();
    };
    GridColumnSummaryOptions.prototype.cm = function () {
        if (this.bu != null) {
            this.bu.h = this.i;
            this.bu.l = this.by;
            this.bu.ba = this.bp;
        }
    };
    GridColumnSummaryOptions.prototype.cl = function () {
        if (this.b1 != null) {
            this.b1.ef = 0;
            this.b1.ak = false;
            this.b1.t7 = this.bp;
            this.bf(this.b1);
        }
    };
    GridColumnSummaryOptions.prototype.cn = function () {
        if (this.b3 != null) {
            this.b3.a8 = this.bm;
            this.b3.q = false;
        }
    };
    GridColumnSummaryOptions.prototype.ci = function (a, b) {
        if (this.b3 == null) {
            return;
        }
        if (this.b3.t) {
            this.b3.ao();
        }
        else {
            var c = this.bt.t();
            var d = this.bt.u();
            var e = this.bt.q();
            var f = 150;
            if (c.right > e - f - 10) {
                d.x -= f;
                d.y -= d.height;
            }
            else {
                d.x += d.width;
                d.y -= d.height;
            }
            this.b3.showRelativeToExclusionRect(d, 1, 0);
        }
    };
    GridColumnSummaryOptions.prototype.cj = function (a, b) {
        if (b.a) {
            this.b5++;
        }
        else {
            this.b5--;
        }
    };
    GridColumnSummaryOptions.$t = markType(GridColumnSummaryOptions, 'GridColumnSummaryOptions', GridColumnOptionsSectionBase.$);
    return GridColumnSummaryOptions;
}(GridColumnOptionsSectionBase));
export { GridColumnSummaryOptions };
//# sourceMappingURL=GridColumnSummaryOptionsView_combined.js.map
