"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _classnames = _interopRequireDefault(require("classnames"));

var _react = _interopRequireWildcard(require("react"));

var _constants = require("../../constants");

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
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__*/(0, _react.forwardRef)(function SpotPulsar({
  baseClassName = "".concat(_constants.CLS_PREFIX, "spot-pulsar"),
  className,
  rect,
  placement = 'center',
  ...props
}, ref) {
  const position = calculate(rect, placement);
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, className),
    style: {
      transform: "translate(".concat(position.left, "px, ").concat(position.top, "px)")
    }
  }, props, {
    ref: ref
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(baseClassName, "__ring")
  }), /*#__PURE__*/_react.default.createElement("div", {
    className: "".concat(baseClassName, "__ring")
  }));
});
SpotPulsar.displayName = 'SpotPulsar';
var _default = SpotPulsar;
exports.default = _default;