/*
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-react-core";
import { ConsolidatedItemsPosition_$type } from "./ConsolidatedItemsPosition";
import { Defaults } from "./Defaults";
import { runOn, enumGetBox, markType, markDep, fromEnum } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, isInfinity } from "igniteui-react-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
/**
 * @hidden
 */
var ColumnSeries = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(ColumnSeries, _super);
    function ColumnSeries() {
        var _this = _super.call(this) || this;
        _this.zk = null;
        _this.zf = 0;
        _this.ab = ColumnSeries.$;
        _this.yy = 2;
        return _this;
    }
    ColumnSeries.prototype.get_ed = function () {
        return true;
    };
    ColumnSeries.prototype.get_ey = function () {
        return true;
    };
    ColumnSeries.prototype.ip = function () {
        if (!isNaN_(this.io)) {
            return _super.prototype.ip.call(this);
        }
        return Defaults.h;
    };
    ColumnSeries.prototype.cg = function () {
        return new ColumnSeriesView(this);
    };
    ColumnSeries.prototype.o0 = function (a) {
        _super.prototype.o0.call(this, a);
        this.ze = a;
    };
    ColumnSeries.prototype.cm = function () {
        if (this.cn == 0) {
            return 2;
        }
        return _super.prototype.cm.call(this);
    };
    ColumnSeries.prototype.vw = function () {
        return 1;
    };
    ColumnSeries.prototype.get_du = function () {
        return true;
    };
    ColumnSeries.prototype.preferredCategoryMode = function (a) {
        return this.yy;
    };
    ColumnSeries.prototype.ts = function (a) {
        if (this.zk == null) {
            this.zk = runOn(this, this.zh);
        }
        var b = this.y1 != null ? this.y1 : this.yAxis;
        var c = this.yv;
        return this.xk.c$d(this, a, c, b, this.vm, this.wn(this.cj), this.wo(this.cj), this.zk);
    };
    ColumnSeries.prototype.f4 = function (a, b) {
        if (this.f7(a, b)) {
            return true;
        }
        if (this.ud(a, b)) {
            return true;
        }
        return false;
    };
    ColumnSeries.prototype.nj = function (a, b) {
        _super.prototype.nj.call(this, a, b);
        var c = b;
        if (a && c.de != null) {
            c.de.count = 0;
        }
    };
    ColumnSeries.prototype.h0 = function () {
        return this.yv.k4(this.cj.by, this.cj.bx, this.getEffectiveViewport1(this.cj));
    };
    ColumnSeries.prototype.w5 = function (a, b) {
        _super.prototype.w5.call(this, a, b);
        var c = a.f;
        if (!b.t()) {
            return;
        }
        var d = b.by;
        var e = b.bx;
        var f = this.getEffectiveViewport1(b);
        var g = new ScalerParams(0, d, e, this.y1.ch, f);
        g.b = this.h2();
        var h = new ScalerParams(0, d, e, this.yv.ch, f);
        var i = this.y1;
        var j = i.ej(i.l7, g);
        var k = this.yv.k4(d, e, f);
        var l = this.yv;
        var m = b;
        if (isNaN_(k) || isInfinity(k)) {
            m.de.count = 0;
            return;
        }
        this.vu.a2(this, this.we(), runOn(this, this.vf), this.wn(b), this.wo(b));
        this.vu.r = this.zi;
        this.vu.s = this.zj;
        this.vu.k = this.zi;
        this.vu.l = this.zj;
        var n = false;
        var o = this.vu.b;
        if (o != null) {
            n = true;
        }
        var p = this.yv.cn;
        var q = p ? this.yv : null;
        var r = this.valueColumn.count;
        var s = this.wn(b);
        var t = 0;
        for (var u = 0; u < c.count; ++u) {
            var v = c._inner[u][0] - 0.5 * k;
            var w = this.zh(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.de.item(t);
            t++;
            z.width = k;
            z.height = y;
            if (n) {
                this.w1(c, u, r, l, h, b.q);
            }
            if (z.dataContext != null) {
                var aa = z.dataContext;
                if (s == 1) {
                    var ab = this.vu.aw(r, u)[0];
                    if (ab >= 0 && ab < this.c6.count) {
                        if (q != null && q.i$b != null && q.i$b.count > ab) {
                            ab = q.i$b._inner[ab];
                        }
                        aa.item = this.c6.item(ab);
                    }
                }
                else {
                    aa.item = null;
                }
            }
            this.vu.ad(z, false, false, false, false);
            z.ap = this.vu.k;
            z.aq = this.vu.l;
            m.dj(z, v, Math.min(x, w));
        }
        m.de.count = t;
        b.c1(a);
    };
    Object.defineProperty(ColumnSeries.prototype, "zg", {
        get: function () {
            return this.zf;
        },
        set: function (a) {
            if (this.zg != a) {
                var b = this.zg;
                this.zf = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.zg));
            }
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.prototype.zh = function (a) {
        if (a == null || a.length < 3) {
            return NaN;
        }
        switch (this.zg) {
            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.em(b, new ScalerParams(1, this.cy.t3, this.cy.t2, this.yAxis.ch));
                if (c < this.yAxis.l7) {
                    return a[2];
                }
                else {
                    return a[1];
                }
            case 4:
                var d = (a[1] + a[2]) / 2;
                var e = this.yAxis.em(d, new ScalerParams(1, this.cy.t3, this.cy.t2, this.yAxis.ch));
                if (this.yAxis == null) {
                    return d;
                }
                if (e < this.yAxis.l7) {
                    return a[1];
                }
                else {
                    return a[2];
                }
            default: return (a[1] + a[2]) / 2;
        }
    };
    Object.defineProperty(ColumnSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.wi;
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.$t = markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:zi:zo', [1, 0], 'RadiusY:zj:zp', [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.dd = null;
        _this.df = null;
        _this.dk = new Rectangle();
        _this.de = null;
        _this.dd = a;
        _this.de = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.dl);
            $ret.activate = runOn(_this, _this.dg);
            $ret.disactivate = runOn(_this, _this.di);
            $ret.destroy = runOn(_this, _this.dh);
            return $ret;
        })());
        return _this;
    }
    ColumnSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        this.df = new List$1(Rectangle.$, 0);
        if (!this.q) {
            this.dd.iu = Defaults.i;
            this.dd.ua = Defaults.c;
        }
    };
    ColumnSeriesView.prototype.dl = function () {
        var a = new Rectangle();
        this.df.add(a);
        a._visibility = 1;
        return a;
    };
    ColumnSeriesView.prototype.dg = function (a) {
        a._visibility = 0;
    };
    ColumnSeriesView.prototype.di = function (a) {
        a._visibility = 1;
    };
    ColumnSeriesView.prototype.dh = function (a) {
        this.df.remove(a);
    };
    ColumnSeriesView.prototype.dj = function (a, b, c) {
        if (!this.isDirty) {
            this.as();
        }
        a.o = c;
        a.n = b;
    };
    ColumnSeriesView.prototype.ac = function (a) {
        return this.df._inner[a];
    };
    ColumnSeriesView.prototype.ab = function (a) {
        var b = this.df._inner[a];
        this.dk._visibility = b._visibility;
        this.dk.n = b.n;
        this.dk.o = b.o;
        this.dk.width = b.width;
        this.dk.height = b.height;
        var c = this.bs(a);
        this.dk._fill = c;
        this.dk._stroke = c;
        this.dk.ad = this.e.hk + 3;
        return this.dk;
    };
    ColumnSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.df.count; c++) {
                var d = this.aa(c, b);
                this.bf(d, c, b);
                a.w(d);
            }
        }
    };
    ColumnSeriesView.prototype.an = function (a) {
        var e_1, _a, e_2, _b;
        _super.prototype.an.call(this, a);
        var b = 0;
        var c = new List$1(Rectangle.$, 0);
        try {
            for (var _c = __values(fromEnum(this.de.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 };
