/*
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 { __extends, __values } from "tslib";
import { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { DependencyProperty } from "igniteui-angular-core";
import { ConsolidatedItemsPosition_$type } from "./ConsolidatedItemsPosition";
import { Defaults } from "./Defaults";
import { runOn, enumGetBox, markType, markDep, fromEnum } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity } from "igniteui-angular-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
/**
 * @hidden
 */
var ColumnSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ColumnSeries, _super);
    function ColumnSeries() {
        var _this = _super.call(this) || this;
        _this.vp = null;
        _this.vk = 0;
        _this.ab = ColumnSeries.$;
        _this.u3 = 2;
        return _this;
    }
    ColumnSeries.prototype.get_dk = function () {
        return true;
    };
    ColumnSeries.prototype.get_d5 = function () {
        return true;
    };
    ColumnSeries.prototype.gz = function () {
        if (!isNaN_(this.gy)) {
            return _super.prototype.gz.call(this);
        }
        return Defaults.h;
    };
    ColumnSeries.prototype.by = function () {
        return new ColumnSeriesView(this);
    };
    ColumnSeries.prototype.l4 = function (a) {
        _super.prototype.l4.call(this, a);
        this.vj = a;
    };
    ColumnSeries.prototype.b4 = function () {
        if (this.b5 == 0) {
            return 2;
        }
        return _super.prototype.b4.call(this);
    };
    ColumnSeries.prototype.r7 = function () {
        return 1;
    };
    ColumnSeries.prototype.get_c3 = function () {
        return true;
    };
    ColumnSeries.prototype.preferredCategoryMode = function (a) {
        return this.u3;
    };
    ColumnSeries.prototype.p3 = function (a) {
        if (this.vp == null) {
            this.vp = runOn(this, this.vm);
        }
        var b = this.u6 != null ? this.u6 : this.yAxis;
        var c = this.u0;
        return this.tu.c$d(this, a, c, b, this.rx, this.sx(this.b1), this.sy(this.b1), this.vp);
    };
    ColumnSeries.prototype.ez = function (a, b) {
        if (this.e2(a, b)) {
            return true;
        }
        if (this.qo(a, b)) {
            return true;
        }
        return false;
    };
    ColumnSeries.prototype.k2 = function (a, b) {
        _super.prototype.k2.call(this, a, b);
        var c = b;
        if (a && c.db != null) {
            c.db.count = 0;
        }
    };
    ColumnSeries.prototype.ge = function () {
        return this.u0.k3(this.b1.bv, this.b1.bu, this.getEffectiveViewport1(this.b1));
    };
    ColumnSeries.prototype.tf = function (a, b) {
        _super.prototype.tf.call(this, a, b);
        var c = a.f;
        if (!b.t()) {
            return;
        }
        var d = b.bv;
        var e = b.bu;
        var f = this.getEffectiveViewport1(b);
        var g = new ScalerParams(0, d, e, this.u6.cg, f);
        g.b = this.gg();
        var h = new ScalerParams(0, d, e, this.u0.cg, f);
        var i = this.u6;
        var j = i.ei(i.l6, g);
        var k = this.u0.k3(d, e, f);
        var l = this.u0;
        var m = b;
        if (isNaN_(k) || isInfinity(k)) {
            m.db.count = 0;
            return;
        }
        this.r5.a2(this, this.sp(), runOn(this, this.rq), this.sx(b), this.sy(b));
        this.r5.r = this.vn;
        this.r5.s = this.vo;
        this.r5.k = this.vn;
        this.r5.l = this.vo;
        var n = false;
        var o = this.r5.b;
        if (o != null) {
            n = true;
        }
        var p = this.u0.cm;
        var q = p ? this.u0 : null;
        var r = this.valueColumn.count;
        var s = this.sx(b);
        var t = 0;
        for (var u = 0; u < c.count; ++u) {
            var v = c._inner[u][0] - 0.5 * k;
            var w = this.vm(c._inner[u]);
            var x = j;
            w = Math.max(w, -100);
            x = Math.min(x, e.bottom + 100);
            var y = Math.abs(x - w);
            if (isInfinity(y) || isNaN_(y)) {
                continue;
            }
            var z = m.db.item(t);
            t++;
            z.width = k;
            z.height = y;
            if (n) {
                this.tb(c, u, r, l, h, b.q);
            }
            if (z.dataContext != null) {
                var aa = z.dataContext;
                if (s == 1) {
                    var ab = this.r5.aw(r, u)[0];
                    if (ab >= 0 && ab < this.cl.count) {
                        if (q != null && q.i$b != null && q.i$b.count > ab) {
                            ab = q.i$b._inner[ab];
                        }
                        aa.item = this.cl.item(ab);
                    }
                }
                else {
                    aa.item = null;
                }
            }
            this.r5.ad(z, false, false, false, false);
            z.ap = this.r5.k;
            z.aq = this.r5.l;
            m.dg(z, v, Math.min(x, w));
        }
        m.db.count = t;
        b.cy(a);
    };
    Object.defineProperty(ColumnSeries.prototype, "vl", {
        get: function () {
            return this.vk;
        },
        set: function (a) {
            if (this.vl != a) {
                var b = this.vl;
                this.vk = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.vl));
            }
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.prototype.vm = function (a) {
        if (a == null || a.length < 3) {
            return NaN;
        }
        switch (this.vl) {
            case 0: return a[1];
            case 1: return a[2];
            case 2: return (a[1] + a[2]) / 2;
            case 3:
                var b = (a[1] + a[2]) / 2;
                if (this.yAxis == null) {
                    return b;
                }
                var c = this.yAxis.el(b, new ScalerParams(1, this.ce.tq, this.ce.tp, this.yAxis.cg));
                if (c < this.yAxis.l6) {
                    return a[2];
                }
                else {
                    return a[1];
                }
            case 4:
                var d = (a[1] + a[2]) / 2;
                var e = this.yAxis.el(d, new ScalerParams(1, this.ce.tq, this.ce.tp, this.yAxis.cg));
                if (this.yAxis == null) {
                    return d;
                }
                if (e < this.yAxis.l6) {
                    return a[1];
                }
                else {
                    return a[2];
                }
            default: return (a[1] + a[2]) / 2;
        }
    };
    Object.defineProperty(ColumnSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.ss;
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.$t = markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:vn:vt', [1, 0], 'RadiusY:vo:vu', [1, 0]]);
    return ColumnSeries;
}(HorizontalAnchoredCategorySeries));
export { ColumnSeries };
/**
 * @hidden
 */
var ColumnSeriesView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ColumnSeriesView, _super);
    function ColumnSeriesView(a) {
        var _this = _super.call(this, a) || this;
        _this.da = null;
        _this.dc = null;
        _this.dh = new Rectangle();
        _this.db = null;
        _this.da = a;
        _this.db = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.di);
            $ret.activate = runOn(_this, _this.dd);
            $ret.disactivate = runOn(_this, _this.df);
            $ret.destroy = runOn(_this, _this.de);
            return $ret;
        })());
        return _this;
    }
    ColumnSeriesView.prototype.as = function () {
        _super.prototype.as.call(this);
        this.dc = new List$1(Rectangle.$, 0);
        if (!this.q) {
            this.da.g4 = Defaults.i;
            this.da.ql = Defaults.c;
        }
    };
    ColumnSeriesView.prototype.di = function () {
        var a = new Rectangle();
        this.dc.add(a);
        a._visibility = 1;
        return a;
    };
    ColumnSeriesView.prototype.dd = function (a) {
        a._visibility = 0;
    };
    ColumnSeriesView.prototype.df = function (a) {
        a._visibility = 1;
    };
    ColumnSeriesView.prototype.de = function (a) {
        this.dc.remove(a);
    };
    ColumnSeriesView.prototype.dg = function (a, b, c) {
        if (!this.isDirty) {
            this.aq();
        }
        a.o = c;
        a.n = b;
    };
    ColumnSeriesView.prototype.ac = function (a) {
        return this.dc._inner[a];
    };
    ColumnSeriesView.prototype.ab = function (a) {
        var b = this.dc._inner[a];
        this.dh._visibility = b._visibility;
        this.dh.n = b.n;
        this.dh.o = b.o;
        this.dh.width = b.width;
        this.dh.height = b.height;
        var c = this.bp(a);
        this.dh._fill = c;
        this.dh._stroke = c;
        this.dh.ad = this.e.fy + 3;
        return this.dh;
    };
    ColumnSeriesView.prototype.a6 = function (a, b) {
        _super.prototype.a6.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.dc.count; c++) {
                var d = this.aa(c, b);
                this.bd(d, c, b);
                a.w(d);
            }
        }
    };
    ColumnSeriesView.prototype.al = function (a) {
        var e_1, _a, e_2, _b;
        _super.prototype.al.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _c = __values(fromEnum(this.db.a)), _d = _c.next(); !_d.done; _d = _c.next()) {
                var d = _d.value;
                c.add(d);
            }
        }
        catch (e_1_1) {
            e_1 = { error: e_1_1 };
        }
        finally {
            try {
                if (_d && !_d.done && (_a = _c.return))
                    _a.call(_c);
            }
            finally {
                if (e_1)
                    throw e_1.error;
            }
        }
        c.aa(function (e, f) {
            if (e.n < f.n) {
                return -1;
            }
            else if (e.n > f.n) {
                return 1;
            }
            else {
                return 0;
            }
        });
        try {
            for (var _e = __values(fromEnum(c)), _f = _e.next(); !_f.done; _f = _e.next()) {
                var e = _f.value;
                this.e.a9.exportRectangleData(a, e, "column" + b, ["Main", "Fill"]);
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_f && !_f.done && (_b = _e.return))
                    _b.call(_e);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        b++;
    };
    ColumnSeriesView.$t = markType(ColumnSeriesView, 'ColumnSeriesView', AnchoredCategorySeriesView.$);
    return ColumnSeriesView;
}(AnchoredCategorySeriesView));
export { ColumnSeriesView };
