/**
 * DevExtreme (cjs/viz/core/layout_element.js)
 * Version: 23.2.6 (build 24140-0112)
 * Build date: Sun May 19 2024
 *
 * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
"use strict";
exports.LayoutElement = LayoutElement;
exports.WrapperLayoutElement = WrapperLayoutElement;
var _common = require("../../core/utils/common");
var _object = require("../../core/utils/object");
const _round = Math.round;
const defaultOffset = {
    horizontal: 0,
    vertical: 0
};
const alignFactors = {
    center: .5,
    right: 1,
    bottom: 1,
    left: 0,
    top: 0
};

function LayoutElement(options) {
    this._options = options
}
LayoutElement.prototype = {
    constructor: LayoutElement,
    position: function(options) {
        const ofBBox = options.of.getLayoutOptions();
        const myBBox = this.getLayoutOptions();
        const at = options.at;
        const my = options.my;
        const offset = options.offset || defaultOffset;
        const shiftX = -alignFactors[my.horizontal] * myBBox.width + ofBBox.x + alignFactors[at.horizontal] * ofBBox.width + parseInt(offset.horizontal);
        const shiftY = -alignFactors[my.vertical] * myBBox.height + ofBBox.y + alignFactors[at.vertical] * ofBBox.height + parseInt(offset.vertical);
        this.shift(_round(shiftX), _round(shiftY))
    },
    getLayoutOptions: _common.noop
};

function WrapperLayoutElement(renderElement, bBox) {
    this._renderElement = renderElement;
    this._cacheBBox = bBox
}
const wrapperLayoutElementPrototype = WrapperLayoutElement.prototype = (0, _object.clone)(LayoutElement.prototype);
wrapperLayoutElementPrototype.constructor = WrapperLayoutElement;
wrapperLayoutElementPrototype.getLayoutOptions = function() {
    return this._cacheBBox || this._renderElement.getBBox()
};
wrapperLayoutElementPrototype.shift = function(shiftX, shiftY) {
    const bBox = this.getLayoutOptions();
    this._renderElement.move(_round(shiftX - bBox.x), _round(shiftY - bBox.y))
};
