/*
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 { Base, EnumUtil, fromEnum, markType, getInstanceType } from "igniteui-angular-core";
import { IAxisVisualDataManager_$type } from "./IAxisVisualDataManager";
import { TextBlock } from "igniteui-angular-core";
import { VisualExportHelper } from "./VisualExportHelper";
import { ChartTitleVisualData } from "./ChartTitleVisualData";
import { HorizontalAlignment_$type } from "igniteui-angular-core";
import { VerticalAlignment_$type } from "igniteui-angular-core";
import { AxisTitlePosition_$type } from "./AxisTitlePosition";
import { RectData } from "igniteui-angular-core";
import { AppearanceHelper } from "igniteui-angular-core";
import { AxisVisualData } from "./AxisVisualData";
import { PathVisualData } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { RectangleVisualData } from "igniteui-angular-core";
import { AxisLabelVisualData } from "./AxisLabelVisualData";
import { PointData } from "igniteui-angular-core";
import { Size } from "igniteui-angular-core";
import { SizeData } from "igniteui-angular-core";
import { FontUtil } from "igniteui-angular-core";
/**
 * @hidden
 */
var AxisVisualDataManager = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(AxisVisualDataManager, _super);
    function AxisVisualDataManager() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    AxisVisualDataManager.prototype.c = function (a) {
        return a;
    };
    AxisVisualDataManager.prototype.d = function (a, b) {
        var c = VisualExportHelper.a(b);
        return c;
    };
    AxisVisualDataManager.prototype.a = function (a, b, c, d) {
        var e = new ChartTitleVisualData();
        var f = a.a4;
        var g = f.a9();
        e.viewport = RectData.b(g);
        var h = this.d(a, d);
        e.textPlotArea = RectData.b(h);
        var i = d._visibility == 0 && d.x != null;
        var j = a.av.af.d();
        var k = f.bg(d);
        var l = this.b(a, d, j);
        var m = AppearanceHelper.c(d, l);
        m.marginLeft = k.left;
        m.marginRight = k.right;
        m.marginTop = k.top;
        m.marginBottom = k.bottom;
        m.fontStretch = "Normal";
        m.textWrapping = "Wrap";
        m.visibility = i;
        if (a.be != null) {
            m.horizontalAlignment = EnumUtil.getName(HorizontalAlignment_$type, a.be.horizontalAlignment);
            m.verticalAlignment = EnumUtil.getName(VerticalAlignment_$type, a.be.verticalAlignment);
            m.textPosition = EnumUtil.getName(AxisTitlePosition_$type, a.be.position);
        }
        else {
            m.horizontalAlignment = EnumUtil.getName(HorizontalAlignment_$type, (0));
            m.verticalAlignment = EnumUtil.getName(VerticalAlignment_$type, (1));
            m.textPosition = EnumUtil.getName(AxisTitlePosition_$type, (0));
        }
        e.appearance = m;
        return e;
    };
    AxisVisualDataManager.prototype.exportVisualData = function (a) {
        var b = new AxisVisualData();
        b.viewport = RectData.b(a.kc);
        b.labelsViewport = RectData.b(a.a4.a9());
        b.type = this.c(getInstanceType(a).typeName);
        b.name = a.name;
        var c = new PathVisualData(1, "axisLine", a.a4.ba);
        b.axisLine = c;
        b.tickMarks = new PathVisualData(1, "tickMarks", a.av.af.aw);
        if (!a.av.ab.contains(a.av.af.aw)) {
            b.tickMarks.data.clear();
        }
        b.minorLines = new PathVisualData(1, "minorLines", a.a4.bc);
        b.majorLines = new PathVisualData(1, "majorLines", a.a4.bb);
        b.strips = new PathVisualData(1, "strips", a.a4.bd);
        if (a.g5 != null) {
            var d = this.a(a, a.bh, b.type, a.ir);
            b.title = d;
        }
        else {
            b.title = null;
        }
        var e = a.bh.getFontInfo();
        if (a.ay != null && a.ay.textStyle != null) {
            e = a.ay.h(a.bh.cu.j.ae);
        }
        var f, g, h, i;
        var j = a.av.af.aw.an.d;
        if (1 < j.count) {
            for (var k = 1; k < j.count; k++) {
                var l = j._inner[k];
                var m = j._inner[k - 1];
                f = l.d.x - l.c.x;
                g = l.d.y - l.c.y;
                h = m.d.x - m.c.x;
                i = m.d.y - m.c.y;
                if (1 == k) {
                    b.tickMarksLength = Math.sqrt(Math.pow(f, 2) + Math.pow(g, 2));
                }
            }
        }
        var n = a.av.ba;
        var o = a.av.af.g();
        if (n.count > 0) {
            var _loop_1 = function (p) {
                var e_1, _a;
                var q = a.av.ba._inner[p];
                var r = a.av.a9._inner[p];
                var s = ((function () {
                    var $ret = new AxisLabelVisualData();
                    $ret.labelPosition = q.c;
                    $ret.labelValue = r;
                    $ret.panelPosition = PointData.b(a.a4.a6());
                    return $ret;
                })());
                var t = new List$1(TextBlock.$, 0);
                try {
                    for (var _b = (e_1 = void 0, __values(fromEnum(o))), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var u = _c.value;
                        t.add(u);
                    }
                }
                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 (p < t.count) {
                    var v = this_1.b(a, t._inner[p], e);
                    s.appearance = AppearanceHelper.c(t._inner[p], v);
                    s.position = PointData.b(a.a4.a5(t._inner[p]));
                    s.size = SizeData.b(new Size(1, t._inner[p].m, t._inner[p].l));
                }
                b.labels.add(s);
            };
            var this_1 = this;
            for (var p = 0; p < n.count; p++) {
                _loop_1(p);
            }
        }
        var w = null;
        if (a.bo.a.count > 0) {
            for (var x = 0; x < a.bo.a.count; x++) {
                if (w == null) {
                    w = new List$1(RectangleVisualData.$, 0);
                }
                var y = new RectangleVisualData(1, "annotationBacking_" + x, a.bo.item(x));
                y.appearance.canvasLeft = a.bo.item(x).n;
                y.appearance.canvasTop = a.bo.item(x).o;
                w.add(y);
            }
        }
        b.annotationBackings = w;
        return b;
    };
    AxisVisualDataManager.prototype.b = function (a, b, c) {
        return FontUtil.getFontInfo(a.bh.cu.j.ae, b, c);
    };
    AxisVisualDataManager.$t = markType(AxisVisualDataManager, 'AxisVisualDataManager', Base.$, [IAxisVisualDataManager_$type]);
    return AxisVisualDataManager;
}(Base));
export { AxisVisualDataManager };
