'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var getBasePlacement = require('./getBasePlacement.js');
var getVariation = require('./getVariation.js');
var getMainAxisFromPlacement = require('./getMainAxisFromPlacement.js');
var enums = require('../enums.js');

function computeOffsets(_ref) {
  var reference = _ref.reference,
      element = _ref.element,
      placement = _ref.placement;
  var basePlacement = placement ? getBasePlacement.default(placement) : null;
  var variation = placement ? getVariation.default(placement) : null;
  var commonX = reference.x + reference.width / 2 - element.width / 2;
  var commonY = reference.y + reference.height / 2 - element.height / 2;
  var offsets;

  switch (basePlacement) {
    case enums.top:
      offsets = {
        x: commonX,
        y: reference.y - element.height
      };
      break;

    case enums.bottom:
      offsets = {
        x: commonX,
        y: reference.y + reference.height
      };
      break;

    case enums.right:
      offsets = {
        x: reference.x + reference.width,
        y: commonY
      };
      break;

    case enums.left:
      offsets = {
        x: reference.x - element.width,
        y: commonY
      };
      break;

    default:
      offsets = {
        x: reference.x,
        y: reference.y
      };
  }

  var mainAxis = basePlacement ? getMainAxisFromPlacement.default(basePlacement) : null;

  if (mainAxis != null) {
    var len = mainAxis === 'y' ? 'height' : 'width';

    switch (variation) {
      case enums.start:
        offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
        break;

      case enums.end:
        offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
        break;

      default:
    }
  }

  return offsets;
}

exports.default = computeOffsets;
//# sourceMappingURL=computeOffsets.js.map
