/*
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 { ChartSelection } from "./ChartSelection";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, 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.ac0 = null;
        _this.acv = 0;
        _this.ab = ColumnSeries.$;
        _this.ace = 2;
        return _this;
    }
    ColumnSeries.prototype.bj = function () {
        return new ColumnSeries();
    };
    ColumnSeries.prototype.get_ez = function () {
        return true;
    };
    ColumnSeries.prototype.get_fl = function () {
        return true;
    };
    ColumnSeries.prototype.jk = function () {
        if (!isNaN_(this.jj)) {
            return _super.prototype.jk.call(this);
        }
        return Defaults.h;
    };
    ColumnSeries.prototype.cs = function () {
        return new ColumnSeriesView(this);
    };
    ColumnSeries.prototype.qz = function (a) {
        _super.prototype.qz.call(this, a);
        this.acu = a;
    };
    ColumnSeries.prototype.cy = function () {
        if (this.cz == 0) {
            return 2;
        }
        return _super.prototype.cy.call(this);
    };
    ColumnSeries.prototype.y2 = function () {
        return 1;
    };
    ColumnSeries.prototype.get_ed = function () {
        return true;
    };
    ColumnSeries.prototype.preferredCategoryMode = function (a) {
        return this.ace;
    };
    ColumnSeries.prototype.wl = function (a) {
        if (this.ac0 == null) {
            this.ac0 = runOn(this, this.acx);
        }
        var b = this.ach != null ? this.ach : this.yAxis;
        var c = this.acb;
        return this.aay.c$d(this, a, c, b, this.ys, this.zt(this.cv), this.zu(this.cv), this.ac0);
    };
    ColumnSeries.prototype.gw = function (a, b) {
        if (this.gz(a, b)) {
            return true;
        }
        if (this.xf(a, b)) {
            return true;
        }
        return false;
    };
    ColumnSeries.prototype.o5 = function (a, b) {
        _super.prototype.o5.call(this, a, b);
        var c = b;
        if (a && c.dg != null) {
            c.dg.count = 0;
        }
    };
    ColumnSeries.prototype.iw = function () {
        return this.acb.k8(this.cv.by, this.cv.bx, this.getEffectiveViewport1(this.cv));
    };
    ColumnSeries.prototype.ak = function (a, b) {
        var c = new List$1(ChartSelection.$, 0);
        this.p2(a, c, b);
        return c.toArray();
    };
    ColumnSeries.prototype.p2 = function (a, b, c) {
        this.aaa(a, b, c, this.yr, 1);
    };
    ColumnSeries.prototype.aai = function (a, b) {
        _super.prototype.aai.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.ach.ch, f);
        g.b = this.iy();
        var h = new ScalerParams(0, d, e, this.acb.ch, f);
        var i = this.ach;
        var j = i.el(i.me, g);
        var k = this.acb.k8(d, e, f);
        var l = this.acb;
        var m = b;
        if (isNaN_(k) || isInfinity(k)) {
            m.dg.count = 0;
            return;
        }
        this.y0.a2(this, this.zk(), runOn(this, this.yk), this.zt(b), this.zu(b));
        this.y0.r = this.acy;
        this.y0.s = this.acz;
        this.y0.k = this.acy;
        this.y0.l = this.acz;
        var n = false;
        var o = this.y0.b;
        if (o != null) {
            n = true;
        }
        var p = this.acb.cn;
        var q = p ? this.acb : null;
        var r = this.valueColumn.count;
        var s = this.zt(b);
        var t = 0;
        for (var u = 0; u < c.count; ++u) {
            var v = c._inner[u][0] - 0.5 * k;
            var w = this.acx(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.dg.item(t);
            t++;
            z.width = k;
            z.height = y;
            var aa = this.y0.aw(r, u)[0];
            if (p && a.m != null && u >= 0 && u < a.m.count) {
                aa = truncate(Math.round(a.m._inner[u]));
            }
            if (n) {
                this.aae(c, u, r, l, h, b.q, aa);
            }
            if (z.dataContext != null) {
                var ab = z.dataContext;
                if (s == 1) {
                    if (aa >= 0 && aa < this.dn.count) {
                        if (q != null && q.i$b != null && q.i$b.count > aa) {
                            aa = q.i$b._inner[aa];
                        }
                        ab.item = this.dn.item(aa);
                    }
                }
                else {
                    ab.item = null;
                }
            }
            this.y0.ad(z, false, false, false, false);
            z.ap = this.y0.k;
            z.aq = this.y0.l;
            m.dl(z, v, Math.min(x, w));
        }
        m.dg.count = t;
        b.c3(a);
    };
    Object.defineProperty(ColumnSeries.prototype, "acw", {
        get: function () {
            return this.acv;
        },
        set: function (a) {
            if (this.acw != a) {
                var b = this.acw;
                this.acv = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.acw));
            }
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.prototype.acx = function (a) {
        if (a == null || a.length < 3) {
            return NaN;
        }
        switch (this.acw) {
            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.eo(b, new ScalerParams(1, this.db.wk, this.db.wj, this.yAxis.ch));
                if (c < this.yAxis.me) {
                    return a[2];
                }
                else {
                    return a[1];
                }
            case 4:
                var d = (a[1] + a[2]) / 2;
                var e = this.yAxis.eo(d, new ScalerParams(1, this.db.wk, this.db.wj, this.yAxis.ch));
                if (this.yAxis == null) {
                    return d;
                }
                if (e < this.yAxis.me) {
                    return a[1];
                }
                else {
                    return a[2];
                }
            default: return (a[1] + a[2]) / 2;
        }
    };
    Object.defineProperty(ColumnSeries.prototype, "useHighMarkerFidelity", {
        get: function () {
            return this.zo;
        },
        enumerable: false,
        configurable: true
    });
    ColumnSeries.$t = markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:acy:ac4', [1, 0], 'RadiusY:acz:ac5', [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.df = null;
        _this.dh = null;
        _this.dm = new Rectangle();
        _this.dg = null;
        _this.df = a;
        _this.dg = ((function () {
            var $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(_this, _this.dn);
            $ret.activate = runOn(_this, _this.di);
            $ret.disactivate = runOn(_this, _this.dk);
            $ret.destroy = runOn(_this, _this.dj);
            return $ret;
        })());
        return _this;
    }
    ColumnSeriesView.prototype.au = function () {
        _super.prototype.au.call(this);
        this.dh = new List$1(Rectangle.$, 0);
        if (!this.q) {
            this.df.jp = Defaults.i;
            this.df.w8 = Defaults.c;
        }
    };
    ColumnSeriesView.prototype.dn = function () {
        var a = new Rectangle();
        this.dh.add(a);
        a._visibility = 1;
        return a;
    };
    ColumnSeriesView.prototype.di = function (a) {
        a._visibility = 0;
    };
    ColumnSeriesView.prototype.dk = function (a) {
        a._visibility = 1;
    };
    ColumnSeriesView.prototype.dj = function (a) {
        this.dh.remove(a);
    };
    ColumnSeriesView.prototype.dl = function (a, b, c) {
        if (!this.isDirty) {
            this.as();
        }
        a.o = c;
        a.n = b;
    };
    ColumnSeriesView.prototype.ac = function (a) {
        return this.dh._inner[a];
    };
    ColumnSeriesView.prototype.ab = function (a) {
        var b = this.dh._inner[a];
        this.dm._visibility = b._visibility;
        this.dm.n = b.n;
        this.dm.o = b.o;
        this.dm.width = b.width;
        this.dm.height = b.height;
        var c = this.bs(a);
        this.dm._fill = c;
        this.dm._stroke = c;
        this.dm.ad = this.e.ie + 3;
        return this.dm;
    };
    ColumnSeriesView.prototype.a8 = function (a, b) {
        _super.prototype.a8.call(this, a, b);
        if (a.d) {
            for (var c = 0; c < this.dh.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.dg.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.bc.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 };
