import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import classNames from 'classnames';
import React, { forwardRef } from 'react';
import { CLS_PREFIX } from '../../constants';
const OFFSET = 23;

const calculate = (rect, placement) => {
  const placementTop = rect.height / 2;
  let placementLeft = 0;

  switch (placement) {
    case 'left':
      placementLeft = Math.min(OFFSET, rect.height / 2);
      break;

    case 'right':
      placementLeft = rect.width - Math.min(OFFSET, rect.height / 2);
      break;

    case 'center':
      placementLeft = rect.width / 2;
      break;
  }

  const top = rect.top + placementTop - OFFSET + window.pageYOffset;
  const left = rect.left + placementLeft - OFFSET + window.pageXOffset;
  return {
    top,
    left
  };
};

const SpotPulsar = /*#__PURE__*/forwardRef(function SpotPulsar({
  baseClassName = "".concat(CLS_PREFIX, "spot-pulsar"),
  className,
  rect,
  placement = 'center',
  ...props
}, ref) {
  const position = calculate(rect, placement);
  return /*#__PURE__*/React.createElement("div", _extends({
    className: classNames(baseClassName, className),
    style: {
      transform: "translate(".concat(position.left, "px, ").concat(position.top, "px)")
    }
  }, props, {
    ref: ref
  }), /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__ring")
  }), /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__ring")
  }));
});
SpotPulsar.displayName = 'SpotPulsar';
export default SpotPulsar;