/*
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 { 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
 */
export let GridColumnSummaryOptionsView = /*@__PURE__*/ (() => {
    class GridColumnSummaryOptionsView extends GridColumnOptionsViewBase {
        constructor() {
            super(...arguments);
            this.o = null;
            this.p = null;
        }
        get n() {
            return this.b;
        }
        k() {
            super.k();
            if (null == this.g || null == this.e) {
                return;
            }
            if (this.n.b2 == null) {
                let a;
                let b;
                let c;
                this.o = ((() => { let d = GridColumnOptionsUtilities.g(this.e, GridColumnSummaryOptionsView.r, 1, this.n.p, this.n.j, new Size(1, 24, 24), a, b, this.p, c, false, true); a = d.p6; b = d.p7; this.p = d.p8; c = d.p9; return d.ret; })());
                c.setStyleProperty("transform", "rotate(-90deg)");
                this.g.append(this.o);
                this.n.cg(a);
            }
            if (this.n.bv == null) {
                let d = new SummaryChooser();
                d.a2(this.e);
                this.n.ck(d);
                let e = this.e.createElement("div");
                let f = this.e.getSubRenderer(e);
                let g = new Popup();
                g.provideRenderer(f);
                g.appendPopupContent(d.c.container);
                this.n.ch(g);
            }
            document.addEventListener("mousedown", runOn(this, this.s), false);
        }
        m() {
            super.m();
            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);
            }
        }
        t() {
            if (this.o != null) {
                let a = this.o.getNativeElement().getBoundingClientRect();
                let 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;
        }
        u() {
            let a = this.t();
            a.x += window.pageXOffset;
            a.y += window.pageYOffset;
            return a;
        }
        q() {
            return (window.innerWidth);
        }
        s(e_) {
            this.n.cf();
        }
    }
    GridColumnSummaryOptionsView.$t = /*@__PURE__*/ markType(GridColumnSummaryOptionsView, 'GridColumnSummaryOptionsView', GridColumnOptionsViewBase.$);
    GridColumnSummaryOptionsView.r = "M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z";
    return GridColumnSummaryOptionsView;
})();
/**
 * @hidden
 */
export let GridColumnSummaryOptions = /*@__PURE__*/ (() => {
    class GridColumnSummaryOptions extends GridColumnOptionsSectionBase {
        constructor() {
            super();
            this.b1 = null;
            this.b3 = null;
            this.bu = null;
            this.b6 = null;
            this.bx = 0;
            this.bw = 0;
            this.b4 = 0;
        }
        f() {
            return new GridColumnSummaryOptionsView();
        }
        bq() {
            if (this.column == null) {
                return false;
            }
            if (!this.column.gd) {
                return false;
            }
            return this.c.hy && this.c.t != 3;
        }
        bc(a, b, c) {
            super.bc(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;
            }
        }
        br() {
            if (this.bu != null) {
                let a = this.bu.a();
                for (let b = 0; b < a.length; b++) {
                    let 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 (let d = 0; d < this.c.b8.i.count; d++) {
                        let e = this.c.b8.i.item(d);
                        if (e.af == this.column.h4 && e.n == c.n) {
                            this.c.b8.i.removeAt(d);
                            d--;
                        }
                    }
                }
                let f = this.bu.b();
                for (let g = 0; g < f.length; g++) {
                    let 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;
                    }
                    let i = false;
                    for (let j = 0; j < this.c.b8.i.count; j++) {
                        let 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();
            }
        }
        bs() {
            if (this.b3 != null && this.b3.t) {
                this.b3.ao();
            }
        }
        a5() {
            super.a5();
            if (this.column != null) {
                this.b5 = 0;
                for (let a = 0; a < this.c.b8.i.count; a++) {
                    let 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;
                        }
                    }
                }
            }
        }
        get b9() {
            if (this.b5 > 0) {
                return stringFormat("{0} ({1})", this.cb, this.b5);
            }
            else {
                return this.cb;
            }
        }
        get b2() {
            return this.b1;
        }
        get bv() {
            return this.bu;
        }
        get bt() {
            return this.e;
        }
        get cb() {
            if (this.b6 == null) {
                let a = this.ai.b1("Column_Options_Summary_Average");
                return !stringIsNullOrWhiteSpace(a) ? a : "Summaries";
            }
            else {
                return this.b6;
            }
        }
        set cb(a) {
            let b = this.b6;
            this.b6 = a;
            if (b != this.b6) {
                this.ba("SummaryCaption", b, this.b6);
            }
        }
        get b0() {
            return this.bx;
        }
        set b0(a) {
            let b = this.bx;
            this.bx = a;
            if (b != this.bx) {
                this.ba("SummaryListDensity", enumGetBox(ControlDisplayDensity_$type, b), enumGetBox(ControlDisplayDensity_$type, this.bx));
            }
        }
        get by() {
            return this.bw;
        }
        set by(a) {
            let b = this.bw;
            this.bw = a;
            if (b != this.bw) {
                this.ba("ActualSummaryListDensity", enumGetBox(ControlDisplayDensity_$type, b), enumGetBox(ControlDisplayDensity_$type, this.bw));
            }
        }
        get b5() {
            return this.b4;
        }
        set b5(a) {
            let b = this.b4;
            this.b4 = a;
            if (b != this.b4) {
                this.ba("ActiveCount", b, this.b4);
            }
        }
        cf() {
            if (this.b3 != null && this.b3.t) {
                this.b3.ao();
            }
        }
        cg(a) {
            if (this.b1 != null) {
                let b = this.b1;
                b.clicked = delegateRemove(b.clicked, runOn(this, this.ci));
            }
            this.b1 = a;
            if (this.b1 != null) {
                let c = this.b1;
                c.clicked = delegateCombine(c.clicked, runOn(this, this.ci));
            }
            this.cl();
        }
        ch(a) {
            this.b3 = a;
            this.cn();
        }
        ck(a) {
            if (this.bu != null) {
                let b = this.bu;
                b.summaryChanged = delegateRemove(b.summaryChanged, runOn(this, this.cj));
            }
            this.bu = a;
            if (this.bu != null) {
                let c = this.bu;
                c.summaryChanged = delegateCombine(c.summaryChanged, runOn(this, this.cj));
            }
            this.cm();
        }
        cm() {
            if (this.bu != null) {
                this.bu.h = this.i;
                this.bu.l = this.by;
                this.bu.ba = this.bp;
            }
        }
        cl() {
            if (this.b1 != null) {
                this.b1.ef = 0;
                this.b1.ak = false;
                this.b1.t7 = this.bp;
                this.bf(this.b1);
            }
        }
        cn() {
            if (this.b3 != null) {
                this.b3.a8 = this.bm;
                this.b3.q = false;
            }
        }
        ci(a, b) {
            if (this.b3 == null) {
                return;
            }
            if (this.b3.t) {
                this.b3.ao();
            }
            else {
                let c = this.bt.t();
                let d = this.bt.u();
                let e = this.bt.q();
                let 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);
            }
        }
        cj(a, b) {
            if (b.a) {
                this.b5++;
            }
            else {
                this.b5--;
            }
        }
    }
    GridColumnSummaryOptions.$t = /*@__PURE__*/ markType(GridColumnSummaryOptions, 'GridColumnSummaryOptions', GridColumnOptionsSectionBase.$);
    return GridColumnSummaryOptions;
})();
//# sourceMappingURL=GridColumnSummaryOptionsView_combined.js.map
