"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _flex = _interopRequireDefault(require("../templates/flex"));
var _typography = require("../typography");
var _icon = require("../icon");
var _excluded = ["children", "align", "margin", "background", "ref", "iconContainerProps"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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; }
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["default"] : _react.Fragment;
  return /*#__PURE__*/_react["default"].createElement(_flex["default"], {
    ref: ref,
    column: align === "top",
    columnReverse: align === "bottom",
    rowReverse: align === "right",
    margin: margin
  }, /*#__PURE__*/_react["default"].createElement(_flex["default"], _extends({
    background: background,
    padding: [1, 2],
    round: true,
    column: true
  }, rest), typeof children === "string" ? /*#__PURE__*/_react["default"].createElement(_typography.Text, {
    color: "tooltipText"
  }, children) : children), align && /*#__PURE__*/_react["default"].createElement(IconContainer, _extends({}, iconAlignmentProps, iconContainerProps), /*#__PURE__*/_react["default"].createElement(_icon.Icon, _extends({
    name: "triangle",
    color: background,
    rotate: rotateMap[align],
    height: "8px",
    width: "8px",
    "data-testid": "drop-arrow"
  }, hasIconContainerProps ? {} : iconAlignmentProps))));
};
var _default = exports["default"] = Container;