var _excluded = ["children", "align", "margin", "background", "ref", "iconContainerProps"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import React, { Fragment } from "react";
import Flex from "../templates/flex";
import { Text } from "../typography";
import { Icon } from "../icon";
var rotateMap = {
  right: 1,
  bottom: 2,
  left: 3
};
var iconAlignmentProps = {
  alignSelf: "center"
};
var Container = function Container(_ref) {
  var children = _ref.children,
    align = _ref.align,
    _ref$margin = _ref.margin,
    margin = _ref$margin === void 0 ? [1] : _ref$margin,
    _ref$background = _ref.background,
    background = _ref$background === void 0 ? "tooltip" : _ref$background,
    ref = _ref.ref,
    _ref$iconContainerPro = _ref.iconContainerProps,
    iconContainerProps = _ref$iconContainerPro === void 0 ? {} : _ref$iconContainerPro,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var hasIconContainerProps = !!Object.keys(iconContainerProps);
  var IconContainer = hasIconContainerProps ? Flex : Fragment;
  return /*#__PURE__*/React.createElement(Flex, {
    ref: ref,
    column: align === "top",
    columnReverse: align === "bottom",
    rowReverse: align === "right",
    margin: margin
  }, /*#__PURE__*/React.createElement(Flex, _extends({
    background: background,
    padding: [1, 2],
    round: true,
    column: true
  }, rest), typeof children === "string" ? /*#__PURE__*/React.createElement(Text, {
    color: "tooltipText"
  }, children) : children), align && /*#__PURE__*/React.createElement(IconContainer, _extends({}, iconAlignmentProps, iconContainerProps), /*#__PURE__*/React.createElement(Icon, _extends({
    name: "triangle",
    color: background,
    rotate: rotateMap[align],
    height: "8px",
    width: "8px",
    "data-testid": "drop-arrow"
  }, hasIconContainerProps ? {} : iconAlignmentProps))));
};
export default Container;