"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getBodyStyles = getBodyStyles;
exports.getArrowStyles = getArrowStyles;
exports.getInnerStyles = getInnerStyles;
exports.Padding = exports.Inner = exports.Arrow = exports.Body = void 0;

var _index = require("../styles/index.js");

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

var _utils = require("./utils.js");

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
 * Main popover container element that gets positioned next to the anchor
 */
function getBodyStyles(props) {
  var $isOpen = props.$isOpen,
      $isAnimating = props.$isAnimating,
      $placement = props.$placement,
      $popoverOffset = props.$popoverOffset,
      $showArrow = props.$showArrow,
      $theme = props.$theme;
  return _objectSpread({
    position: 'absolute',
    top: 0,
    left: 0,
    zIndex: 1050,
    backgroundColor: $theme.colors.background,
    borderRadius: $theme.borders.useRoundedCorners ? $theme.borders.radius300 : '0px',
    boxShadow: $theme.lighting.shadow600,
    transitionProperty: 'opacity,transform',
    transitionDuration: $isAnimating ? '0.1s' : '0s',
    transitionTimingFunction: $isOpen ? $theme.animation.easeOutCurve : $theme.animation.easeInCurve,
    opacity: $isAnimating && $isOpen ? 1 : 0,
    transform: $isAnimating && $isOpen ? (0, _utils.getEndPosition)($popoverOffset) : (0, _utils.getStartPosition)($popoverOffset, $placement, $showArrow)
  }, (0, _utils.getPopoverMarginStyles)($showArrow, $placement));
}

var Body = (0, _index.styled)('div', getBodyStyles);
/**
 * Arrow shown between the popover and the anchor element
 */

exports.Body = Body;
Body.displayName = "Body";

function getArrowStyles(props) {
  var $arrowOffset = props.$arrowOffset,
      $placement = props.$placement,
      $theme = props.$theme;
  return _objectSpread({
    backgroundColor: $theme.colors.backgroundAlt,
    boxShadow: $theme.lighting.shadow600,
    width: "".concat(_constants.ARROW_WIDTH, "px"),
    height: "".concat(_constants.ARROW_WIDTH, "px"),
    transform: 'rotate(45deg)',
    position: 'absolute',
    zIndex: 1
  }, (0, _utils.getArrowPositionStyles)($arrowOffset, $placement));
}

var Arrow = (0, _index.styled)('div', getArrowStyles);
/**
 * Extra div that holds the popover content. This extra element
 * is needed for the arrow–the arrow is just a 45deg rotated div,
 * and rendering this extra element on top with a solid background
 * clips the part of the arrow that extends into the popover.
 */

exports.Arrow = Arrow;
Arrow.displayName = "Arrow";

function getInnerStyles(_ref) {
  var $theme = _ref.$theme;
  return {
    backgroundColor: $theme.colors.backgroundAlt,
    color: $theme.colors.foreground,
    borderRadius: $theme.borders.useRoundedCorners ? $theme.borders.radius300 : '0px',
    position: 'relative',
    zIndex: 2 // Above "Arrow"

  };
}

var Inner = (0, _index.styled)('div', getInnerStyles);
/**
 * A drop-in component that provides the recommended padding
 * for popovers. Mostly a convenience for users so they don't
 * have to define this themselves.
 */

exports.Inner = Inner;
Inner.displayName = "Inner";
var Padding = (0, _index.styled)('div', {
  padding: '12px'
});
exports.Padding = Padding;
Padding.displayName = "Padding";