/**
 * DevExtreme (cjs/__internal/viz/chart_components/rolling_stock.js)
 * Version: 24.1.7-build-24272-1937
 * Build date: Sat Sep 28 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.RollingStock = void 0;
class RollingStock {
    constructor(label, isRotated, shiftFunction) {
        const bBox = label.getBoundingRect();
        const {
            x: x
        } = bBox;
        const {
            y: y
        } = bBox;
        const endX = bBox.x + bBox.width;
        const endY = bBox.y + bBox.height;
        this.labels = [label];
        this.shiftFunction = shiftFunction;
        this.bBox = {
            start: isRotated ? x : y,
            width: isRotated ? bBox.width : bBox.height,
            end: isRotated ? endX : endY,
            oppositeStart: isRotated ? y : x,
            oppositeEnd: isRotated ? endY : endX
        };
        this.initialPosition = isRotated ? bBox.x : bBox.y
    }
    toChain(nextRollingStock) {
        const nextRollingStockBBox = nextRollingStock.getBoundingRect();
        nextRollingStock.shift(nextRollingStockBBox.start - this.bBox.end);
        this.changeBoxWidth(nextRollingStockBBox.width);
        this.labels = this.labels.concat(nextRollingStock.labels)
    }
    getBoundingRect() {
        return this.bBox
    }
    shift(shiftLength) {
        this.labels.forEach((label => {
            const bBox = label.getBoundingRect();
            const coords = this.shiftFunction(bBox, shiftLength);
            if (!label.hideInsideLabel(coords)) {
                label.shift(coords.x, coords.y)
            }
        }));
        this.bBox.end -= shiftLength;
        this.bBox.start -= shiftLength
    }
    setRollingStockInCanvas(canvas) {
        if (this.bBox.end > canvas.end) {
            this.shift(this.bBox.end - canvas.end)
        }
    }
    getLabels() {
        return this.labels
    }
    value() {
        return this.labels[0].getData().value
    }
    getInitialPosition() {
        return this.initialPosition
    }
    changeBoxWidth(width) {
        this.bBox.end += width;
        this.bBox.width += width
    }
}
exports.RollingStock = RollingStock;
