"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.PolarColumnDataLabelState = void 0;
var ValueName_1 = require("../../../../../types/ValueName");
var vectorToArray_1 = require("../../../../../utils/vectorToArray");
var PolarDataLabelState_1 = require("./PolarDataLabelState");
var PolarColumnDataLabelState = /** @class */ (function (_super) {
    __extends(PolarColumnDataLabelState, _super);
    function PolarColumnDataLabelState(renderContext, renderPassData, style, color, yValues, parentSeries) {
        var _this = _super.call(this, renderContext, renderPassData, style, color, yValues, parentSeries) || this;
        _this.x1CoordCache = undefined;
        _this.zeroXCoordCache = undefined;
        _this.zeroYCoordCache = undefined;
        _this.accumulatedWidthCoordCache = undefined;
        /**
         * Accumulated width array. Is used to get an information about the start angle, which is needed for {@link EPolarLabelMode.Width}
         */
        _this.accumulatedWidthValues = [];
        // if (parentSeries.columnXMode === EColumnMode.Width) {
        //     this.fillAccumulatedWidthValues();
        // }
        var pointSeries = renderPassData.pointSeries;
        // If x1Values are undefined we use xValues to prevent an error
        _this.x1Values = pointSeries.getYValuesByName(ValueName_1.EValueName.X1)
            ? (0, vectorToArray_1.vectorToArrayViewF64)(pointSeries.getYValuesByName(ValueName_1.EValueName.X1), renderContext.webAssemblyContext)
            : _this.xValues;
        _this.columnWidthProperty = parentSeries.getDataPointWidth(renderPassData.xCoordinateCalculator, parentSeries.dataPointWidth, parentSeries.dataPointWidthMode);
        _this.isFlippedProperty = renderPassData.xCoordinateCalculator.isFlipped;
        return _this;
    }
    PolarColumnDataLabelState.prototype.fillAccumulatedWidthValues = function () {
        this.accumulatedWidthValues = [];
        var prevValue = 0;
        this.accumulatedWidthValues.push(prevValue);
        for (var i = 0; i < this.xValues.length - 1; i++) {
            prevValue += this.xValues[i];
            this.accumulatedWidthValues.push(prevValue);
        }
    };
    Object.defineProperty(PolarColumnDataLabelState.prototype, "columnWidth", {
        get: function () {
            return this.columnWidthProperty;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PolarColumnDataLabelState.prototype, "isFlipped", {
        get: function () {
            return this.isFlippedProperty;
        },
        enumerable: false,
        configurable: true
    });
    PolarColumnDataLabelState.prototype.x1Val = function (index) {
        return this.x1Values[this.getIndexInternal(index)];
        //return this.parentSeries.dataSeries.getNativeValue(this.x1Values, this.getIndexInternal(index));
    };
    PolarColumnDataLabelState.prototype.accumulatedWidth = function (index) {
        if (this.accumulatedWidthValues) {
            return this.accumulatedWidthValues[this.getIndexInternal(index)];
        }
        else {
            return this.xVal(index);
        }
    };
    PolarColumnDataLabelState.prototype.accumulatedWidthCoord = function (index) {
        if (index !== undefined)
            return this.renderPassData.xCoordinateCalculator.getCoordinate(this.accumulatedWidth(index));
        else {
            if (this.accumulatedWidthCoordCache !== undefined)
                return this.accumulatedWidthCoordCache;
            else
                this.accumulatedWidthCoordCache = this.renderPassData.xCoordinateCalculator.getCoordinate(this.accumulatedWidth());
            return this.accumulatedWidthCoordCache;
        }
    };
    Object.defineProperty(PolarColumnDataLabelState.prototype, "index", {
        get: function () {
            return this.indexProperty;
        },
        set: function (value) {
            this.xCoordCache = undefined;
            this.yCoordCache = undefined;
            this.x1CoordCache = undefined;
            this.accumulatedWidthCoordCache = undefined;
            this.indexProperty = value;
        },
        enumerable: false,
        configurable: true
    });
    PolarColumnDataLabelState.prototype.x1Coord = function (index) {
        if (index !== undefined)
            return this.renderPassData.xCoordinateCalculator.getCoordinate(this.x1Val(index));
        else {
            if (this.x1CoordCache !== undefined)
                return this.x1CoordCache;
            else
                this.x1CoordCache = this.renderPassData.xCoordinateCalculator.getCoordinate(this.x1Val());
            return this.x1CoordCache;
        }
    };
    Object.defineProperty(PolarColumnDataLabelState.prototype, "zeroXCoord", {
        get: function () {
            if (!this.zeroXCoordCache) {
                this.zeroXCoordCache = this.renderPassData.xCoordinateCalculator.getCoordinate(0);
            }
            return this.zeroXCoordCache;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(PolarColumnDataLabelState.prototype, "zeroYCoord", {
        get: function () {
            if (!this.zeroYCoordCache) {
                this.zeroYCoordCache = this.renderPassData.yCoordinateCalculator.getCoordinate(0);
            }
            return this.zeroYCoordCache;
        },
        enumerable: false,
        configurable: true
    });
    return PolarColumnDataLabelState;
}(PolarDataLabelState_1.PolarDataLabelState));
exports.PolarColumnDataLabelState = PolarColumnDataLabelState;
