import { objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import { createElement } from 'react';
import 'prop-types';
import Portal from '../Portal/index.esm.js';

var pointerPosition = {
  top: pointerPositionTop,
  bottom: pointerPositionBottom
};
function TooltipPointer(_ref) {
  var position = _ref.position,
      triggerRect = _ref.triggerRect,
      _ref$style = _ref.style,
      style = _ref$style === void 0 ? {} : _ref$style;
  var getPointerPosition = pointerPosition[position];
  var positionStyle = triggerRect ? getPointerPosition(triggerRect) : {};
  return /*#__PURE__*/createElement(Portal, null, /*#__PURE__*/createElement("div", {
    style: _objectSpread2({}, positionStyle, {
      position: "absolute",
      width: 0,
      height: 0
    }, style)
  }));
}
var TOOLTIP_POINTER_SIZE = 6;
var TOOLTIP_POINTER_ADJUST = 1;
var pointerBorderTransparent = "".concat(TOOLTIP_POINTER_SIZE, "px solid transparent");
var pointerBorderFilled = "".concat(TOOLTIP_POINTER_SIZE, "px solid black");

function pointerPositionBottom(triggerRect) {
  return {
    borderLeft: pointerBorderTransparent,
    borderRight: pointerBorderTransparent,
    borderBottom: pointerBorderFilled,
    left: getPositionOffsetLeft(triggerRect),
    top: triggerRect.bottom + window.scrollY + TOOLTIP_POINTER_ADJUST
  };
}

function pointerPositionTop(triggerRect) {
  return {
    borderLeft: pointerBorderTransparent,
    borderRight: pointerBorderTransparent,
    borderTop: pointerBorderFilled,
    left: getPositionOffsetLeft(triggerRect),
    top: triggerRect.top - TOOLTIP_POINTER_SIZE + window.scrollY - TOOLTIP_POINTER_ADJUST
  };
}

function getPositionOffsetLeft(triggerRect) {
  return triggerRect.left + triggerRect.width / 2 - TOOLTIP_POINTER_SIZE;
}

TooltipPointer.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TooltipPointer",
  "props": {
    "style": {
      "defaultValue": {
        "value": "{}",
        "computed": false
      },
      "required": false,
      "tsType": {
        "name": "ReactCSSProperties",
        "raw": "React.CSSProperties"
      },
      "description": ""
    },
    "triggerRect": {
      "required": true,
      "tsType": {
        "name": "DOMRect"
      },
      "description": ""
    },
    "position": {
      "required": true,
      "tsType": {
        "name": "TooltipPosition"
      },
      "description": ""
    }
  }
};

if (typeof STORYBOOK_REACT_CLASSES !== "undefined") {
  STORYBOOK_REACT_CLASSES["src/components/Tooltip/TooltipPointer.tsx"] = {
    name: "TooltipPointer",
    docgenInfo: TooltipPointer.__docgenInfo,
    path: "src/components/Tooltip/TooltipPointer.tsx"
  };
}

export default TooltipPointer;
export { TOOLTIP_POINTER_ADJUST, TOOLTIP_POINTER_SIZE };
//# sourceMappingURL=TooltipPointer.esm.js.map
