/*
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.zm = null;
        _this.zh = 0;
        _this.ab = ColumnSeries.$;
        _this.y0 = 2;
        return _this;
    }
    ColumnSeries.prototype.bc = function () {
        return new ColumnSeries();
    };
    ColumnSeries.prototype.get_ee = function () {
        return true;
    };
    ColumnSeries.prototype.get_ez = function () {
        return true;
    };
    ColumnSeries.prototype.iq = function () {
        if (!isNaN_(this.ip)) {
            return _super.prototype.iq.call(this);
        }
        return Defaults.h;
    };
    ColumnSeries.prototype.cd = function () {
        return new ColumnSeriesView(this);
    };
    ColumnSeries.prototype.o2 = function (a) {
        _super.prototype.o2.call(this, a);
        this.zg = a;
    };
    ColumnSeries.prototype.cj = function () {
        if (this.ck == 0) {
            return 2;
        }
        return _super.prototype.cj.call(this);
    };
    ColumnSeries.prototype.vy = function () {
        return 1;
    };
    ColumnSeries.prototype.get_dv = function () {
        return true;
    };
    ColumnSeries.prototype.preferredCategoryMode = function (a) {
        return this.y0;
    };
    ColumnSeries.prototype.tu = function (a) {
        if (this.zm == null) {
            this.zm = runOn(this, this.zj);
        }
        var b = this.y3 != null ? this.y3 : this.yAxis;
        var c = this.yx;
        return this.xm.c$d(this, a, c, b, this.vo, this.wp(this.cg), this.wq(this.cg), this.zm);
    };
    ColumnSeries.prototype.f5 = function (a, b) {
        if (this.f8(a, b)) {
            return true;
        }
        if (this.uf(a, b)) {
            return true;
        }
        return false;
    };
    ColumnSeries.prototype.nk = function (a, b) {
        _super.prototype.nk.call(this, a, b);
        var c = b;
        if (a && c.de != null) {
            c.de.count = 0;
        }
    };
    ColumnSeries.prototype.h1 = function () {
        return this.yx.k4(this.cg.by, this.cg.bx, this.getEffectiveViewport1(this.cg));
    };
    ColumnSeries.prototype.w7 = function (a, b) {
        _super.prototype.w7.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.y3.ch, f);
        g.b = this.h3();
        var h = new ScalerParams(0, d, e, this.yx.ch, f);
        var i = this.y3;
        var j = i.ej(i.l7, g);
        var k = this.yx.k4(d, e, f);
        var l = this.yx;
        var m = b;
        if (isNaN_(k) || isInfinity(k)) {
            m.de.count = 0;
            return;
        }
        this.vw.a2(this, this.wg(), runOn(this, this.vh), this.wp(b), this.wq(b));
        this.vw.r = this.zk;
        this.vw.s = this.zl;
        this.vw.k = this.zk;
        this.vw.l = this.zl;
        var n = false;
        var o = this.vw.b;
        if (o != null) {
            n = true;
        }
        var p = this.yx.cn;
        var q = p ? this.yx : null;
        var r = this.valueColumn.count;
        var s = this.wp(b);
        var t = 0;
        for (var u = 0; u < c.count; ++u) {
            var v = c._inner[u][0] - 0.5 * k;
            var w = this.zj(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.w3(c, u, r, l, h, b.q);
            }
            if (z.dataContext != null) {
                var aa = z.dataContext;
                if (s == 1) {
                    var ab = this.vw.aw(r, u)[0];
                    if (ab >= 0 && ab < this.c7.count) {
                        if (q != null && q.i$b != null && q.i$b.count > ab) {
                            ab = q.i$b._inner[ab];
                        }
                        aa.item = this.c7.item(ab);
                    }
                }
                else {
                    aa.item = null;
                }
            }
            this.vw.ad(z, false, false, false, false);
            z.ap = this.vw.k;
            z.aq = this.vw.l;
            m.dj(z, v, Math.min(x, w));
        }
        m.de.count = t;
        b.c1(a);
    };
    Object.defineProperty(ColumnSeries.prototype, "zi", {
        get: function () {
            return this.zh;
        },
        set: function (a) {
            if (this.zi != a) {
                var b = this.zi;
                this.zh = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.zi));
            }
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.prototype.zj = function (a) {
        if (a == null || a.length < 3) {
            return NaN;
        }
        switch (this.zi) {
            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.cv.t7, this.cv.t6, 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.cv.t7, this.cv.t6, 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.wk;
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.$t = markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:zk:zq', [1, 0], 'RadiusY:zl:zr', [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.iv = Defaults.i;
            this.dd.uc = 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.hl + 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.a5.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 };
