var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { LogUtility } from '../../../utils/log';
import { BasePositionCalculationStrategy } from './base-position-calculation-strategy';
import { MapToComponentField } from 'vega-slimmer/core';
/**
 * calculate position by body container
 */
export class BodyPositionCalculationStrategy extends BasePositionCalculationStrategy {
  /**
   * Get the position of the element in the container according to the target element and the placement
   * If give a translocation, it will apply the translocation to the result.
   * Note: If you use this method to calculate the position, you should make container as relative position at first.
   *
   * @returns {ElementPositionBox} A function that takes in a container, element, target, placement, and translocation and
   * returns an ElementPositionBox.
   */
  getPosition() {
    const containerStyle = window.getComputedStyle(this.container);
    if (containerStyle.position !== 'relative') {
      LogUtility.warn(`Calculate position should make container as 'position: relative', otherwise the result might not be accurate.`);
    }
    return this.getPositionBox();
  }
  /**
   * It returns the position of an element relative to its container and also includes the scroll height of container.
   *
   * @returns {ElementBoundBox} An object with the properties width, height, top, and left.
   */
  getTargetBoundBox() {
    const containerRect = this.container.getBoundingClientRect();
    const targetRect = this.showConfig.target.getBoundingClientRect();
    const targetTop = targetRect.top - containerRect.top + this.container.scrollTop;
    const targetLeft = targetRect.left - containerRect.left + this.container.scrollLeft;
    return {
      width: targetRect.width,
      height: targetRect.height,
      top: targetTop,
      left: targetLeft,
    };
  }
  /**
   * "Get the width and height of an element."
   *
   * The function takes a single parameter, a container element, and returns an object with two
   * properties: width and height
   *
   * @returns {ElementScrollDimension} An object with two properties: width and height.
   */
  getElementScrollDimension() {
    return {
      width: this.container.scrollWidth,
      height: this.container.scrollHeight,
    };
  }
}
__decorate([
  MapToComponentField()
], BodyPositionCalculationStrategy.prototype, "container", void 0);
__decorate([
  MapToComponentField()
], BodyPositionCalculationStrategy.prototype, "showConfig", void 0);
