import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/** @jsx jsx */

import { css, jsx } from '@emotion/react';
import { hexToEditorBorderPaletteColor } from '@atlaskit/editor-palette';
import { borderStyle, INLINE_IMAGE_ASPECT_RATIO_CSS_VAR_KEY, INLINE_IMAGE_BORDER_COLOR_CSS_VAR_KEY, INLINE_IMAGE_BORDER_SIZE_CSS_VAR_KEY, INLINE_IMAGE_WRAPPER_CLASS_NAME, interactiveStyle, selectedStyle, wrapperStyle } from './styles';

// The MediaImage component needs to obtain its parent's dimensions.
// To achieve this, we have added an additional wrapper that allows
// for better interaction with the parent element. This is necessary
//  because the parent size changes its box-sizing with the node border.
var sizeWrapperStyle = css({
  display: 'inline-flex',
  width: '100%',
  height: '100%'
});
export var InlineImageWrapper = function InlineImageWrapper(_ref) {
  var _ref2;
  var children = _ref.children,
    isSelected = _ref.isSelected,
    isInteractive = _ref.isInteractive,
    aspectRatio = _ref.aspectRatio,
    borderSize = _ref.borderSize,
    borderColor = _ref.borderColor,
    _ref$htmlAttrs = _ref.htmlAttrs,
    htmlAttrs = _ref$htmlAttrs === void 0 ? {} : _ref$htmlAttrs,
    onClick = _ref.onClick;
  var borderStyleVars = borderSize && borderColor ? (_ref2 = {}, _defineProperty(_ref2, INLINE_IMAGE_BORDER_SIZE_CSS_VAR_KEY, borderSize), _defineProperty(_ref2, INLINE_IMAGE_BORDER_COLOR_CSS_VAR_KEY, hexToEditorBorderPaletteColor(borderColor) || borderColor), _ref2) : {};
  var aspectStyleVars = aspectRatio ? _defineProperty({}, INLINE_IMAGE_ASPECT_RATIO_CSS_VAR_KEY, aspectRatio) : {};
  return (
    // eslint-disable-next-line @atlaskit/design-system/prefer-primitives
    jsx("span", _extends({
      style: _objectSpread(_objectSpread({}, borderStyleVars), aspectStyleVars),
      className: INLINE_IMAGE_WRAPPER_CLASS_NAME,
      css: [wrapperStyle, borderSize && borderColor && borderStyle, isSelected && selectedStyle, isInteractive && interactiveStyle],
      "data-testid": "inline-image-wrapper",
      onClick: onClick
    }, htmlAttrs), jsx("span", {
      css: sizeWrapperStyle
    }, children))
  );
};