"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = _default;

/*
 * @Author: lianghaosen
 * @Date: 2018-12-01 10:32:39
 * @Last Modified by: lianghaosen
 * @Last Modified time: 2020-01-14 15:15:55
 */

/**
 * 获取要定位的元素在页面上的期望位置
 * @param {NodeElement} el 要定位的元素
 * @param {NodeElement} bindNode 定位基准元素
 * @param {string} align 对齐方式 共12种对齐方式 top left,top,top right,let top,left,left bottom ...
 */
function _default(el, bindNode, alignType, offset) {
  var elOffset = el.getBoundingClientRect();
  var bindNodeOffset = bindNode.getBoundingClientRect();
  var placement = {};
  var direction = [["left", "right"], ["top", "bottom"]];
  var s = ["width", "height"];
  direction.forEach(function (d, index) {
    if (alignType[0] === d[0]) {
      placement[d[0]] = bindNodeOffset[d[0]] - elOffset[s[index]];
    } else if (alignType[0] === d[1]) {
      placement[d[0]] = bindNodeOffset[d[0]] + bindNodeOffset[s[index]];
    } else if (alignType[1] == d[0]) {
      placement[d[0]] = bindNodeOffset[d[0]];
    } else if (alignType[1] == d[1]) {
      placement[d[0]] = bindNodeOffset[d[0]] + bindNodeOffset[s[index]] - elOffset[s[index]];
    } else {
      placement[d[0]] = bindNodeOffset[d[0]] + (bindNodeOffset[s[index]] - elOffset[s[index]]) / 2;
    }
  });

  if (offset) {
    placement.left += offset.left;
    placement.right += offset.right;
  }

  placement.right = placement.left + elOffset.width;
  placement.bottom = placement.top + elOffset.height;
  return placement;
}