"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.RectangleSeriesDataLabelProvider = void 0;
var Point_1 = require("../../../../Core/Point");
var DataLabelProviderType_1 = require("../../../../types/DataLabelProviderType");
var dataLabelHelpers_1 = require("./dataLabelHelpers");
var DataLabelProvider_1 = require("./DataLabelProvider");
var RectangleDataLabelState_1 = require("./RectangleDataLabelState");
var text_1 = require("../../../../utils/text");
var RectangleSeriesDataLabelProvider = /** @class */ (function (_super) {
    __extends(RectangleSeriesDataLabelProvider, _super);
    function RectangleSeriesDataLabelProvider(options) {
        var _this = _super.call(this, options) || this;
        _this.type = DataLabelProviderType_1.EDataLabelProviderType.Rectangle;
        return _this;
    }
    /** @inheritDoc */
    RectangleSeriesDataLabelProvider.prototype.getDataLabelState = function (renderContext, renderPassData, style, color, yValues, parentSeries) {
        return new RectangleDataLabelState_1.RectangleDataLabelState(renderContext, renderPassData, style, color, yValues, parentSeries);
    };
    /** @inheritDoc */
    RectangleSeriesDataLabelProvider.prototype.getPosition = function (state, textBounds) {
        var _a = this.parentSeries, columnXMode = _a.columnXMode, columnYMode = _a.columnYMode;
        var _b = dataLabelHelpers_1.dataLabelHelpers.calcRectangleBorders(columnXMode, columnYMode, !state.isXFlipped, state.isYFlipped, state.xCoord(), state.yCoord(), state.x1Coord(), state.y1Coord(), state.isVerticalChart), xMin = _b.xMin, xMax = _b.xMax, yMin = _b.yMin, yMax = _b.yMax;
        var centerX = (xMin + xMax) / 2;
        var centerY = (yMin + yMax) / 2;
        var rotationCenter = new Point_1.Point(centerX, centerY);
        var lineBounds = textBounds.GetLineBounds(0);
        var yOffset = textBounds.m_fHeight - lineBounds.m_fHeight;
        lineBounds.delete();
        var xRes = centerX;
        var yRes = centerY - yOffset;
        // Positioning to center
        xRes -= textBounds.m_fWidth / 2;
        yRes += (0, text_1.getTextHeightToBaseline)(textBounds) / 2;
        return { position: new Point_1.Point(xRes, yRes), rotationAngle: 0, rotationCenter: rotationCenter };
    };
    /** @inheritDoc */
    RectangleSeriesDataLabelProvider.prototype.toJSON = function () {
        var json = _super.prototype.toJSON.call(this);
        var options = {};
        Object.assign(json.options, options);
        return json;
    };
    return RectangleSeriesDataLabelProvider;
}(DataLabelProvider_1.DataLabelProvider));
exports.RectangleSeriesDataLabelProvider = RectangleSeriesDataLabelProvider;
