/*
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 { TrendLineManagerBase$1 } from "./TrendLineManagerBase$1";
import { Point_$type, fromEnum, markType } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { TrendFitCalculator } from "./TrendFitCalculator";
import { TrendAverageCalculator } from "./TrendAverageCalculator";
import { PolarLinePlanner } from "./PolarLinePlanner";
import { isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
var PolarTrendLineManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(PolarTrendLineManager, _super);
    function PolarTrendLineManager() {
        var _this = _super.call(this, Point_$type) || this;
        _this.i = false;
        _this.h = 0;
        _this.k = 0;
        _this.j = 0;
        _this.l = null;
        _this.m = null;
        return _this;
    }
    PolarTrendLineManager.prototype.get_g$a = function () {
        return 2;
    };
    Object.defineProperty(PolarTrendLineManager.prototype, "g$a", {
        get: function () {
            return this.get_g$a();
        },
        enumerable: false,
        configurable: true
    });
    PolarTrendLineManager.prototype.n = function (a, b, c, d, e, f, g, h, i, j, k) {
        var e_1, _a;
        var l = j;
        var m = k;
        var n = new List$1(Point_$type, 0);
        if (!h.g.isEmpty && !h.f.isEmpty) {
            var o_1 = c;
            var p_1 = d;
            var q = 0;
            if (o_1 != null) {
                q = o_1.count;
            }
            if (p_1 != null) {
                q = Math.min(q, p_1.count);
            }
            if (b == 0) {
                this.a = null;
                this.d.clear();
                return;
            }
            if (this.c(b)) {
                this.d.clear();
                this.a = TrendFitCalculator.a(n, b, h, this.a, q, function (r) { return o_1.item(r); }, function (r) { return p_1.item(r); }, f, g, l, m);
            }
            if (this.b(b)) {
                this.a = null;
                TrendAverageCalculator.c(b, this.d, c, d, e);
                try {
                    for (var _b = __values(fromEnum(this.d)), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var r = _c.value;
                        var s = f(r.x);
                        var t = g(r.y);
                        if (!isNaN_(s) && !isNaN_(t)) {
                            n.add({ $type: Point_$type, x: s, y: t });
                        }
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return))
                            _a.call(_b);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
            }
            if (n.count > 0) {
                this.f(n, h, a, i);
            }
        }
    };
    PolarTrendLineManager.prototype.f = function (a, b, c, d) {
        var _this = this;
        if (d != null) {
            d.i = c;
        }
        var e = ((function () {
            var $ret = new PolarLinePlanner();
            $ret.m = function (f) { return a.item(f).x; };
            $ret.n = function (f) { return a.item(f).y; };
            $ret.a = d;
            $ret.q = a.count;
            $ret.l = b.b;
            $ret.o = function (f) { return _this.l(a.item(f).x, a.item(f).y); };
            $ret.p = function (f) { return _this.m(a.item(f).x, a.item(f).y); };
            $ret.f = _this.i;
            $ret.b = _this.h;
            $ret.ab = b.f;
            $ret.ac = b.g;
            return $ret;
        })());
        e.x(null, null);
    };
    PolarTrendLineManager.$t = markType(PolarTrendLineManager, 'PolarTrendLineManager', TrendLineManagerBase$1.$.specialize(Point_$type));
    return PolarTrendLineManager;
}(TrendLineManagerBase$1));
export { PolarTrendLineManager };
