"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _classnames = _interopRequireDefault(require("classnames"));
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _hooks = require("../../../hooks");
var _ui = require("../../../ui");
var _Lozenge = _interopRequireDefault(require("../Lozenge"));
var _styles = require("../styles");
var _styles2 = require("./styles");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
/** @jsx jsx */

var InlineExtension = function InlineExtension(props) {
  var node = props.node,
    pluginInjectionApi = props.pluginInjectionApi,
    showMacroInteractionDesignUpdates = props.showMacroInteractionDesignUpdates,
    isNodeSelected = props.isNodeSelected,
    children = props.children,
    isNodeHovered = props.isNodeHovered,
    setIsNodeHovered = props.setIsNodeHovered;
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['width']),
    widthState = _useSharedPluginState.widthState;
  var hasChildren = !!children;
  var classNames = (0, _classnames.default)('extension-container', 'inline', 'with-overlay', {
    'with-children': hasChildren,
    'with-danger-overlay': showMacroInteractionDesignUpdates
  });
  var rendererContainerWidth = widthState ? widthState.width - _editorSharedStyles.akEditorGutterPadding * 2 : 0;
  var extendedInlineExtension = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.inline_extension.extended_lcqdn') || false;
  var handleMouseEvent = function handleMouseEvent(didHover) {
    if (setIsNodeHovered) {
      setIsNodeHovered(didHover);
    }
  };
  var inlineExtensionInternal = (0, _react2.jsx)(_react.Fragment, null, showMacroInteractionDesignUpdates && (0, _react2.jsx)(_Lozenge.default, {
    node: node,
    isNodeSelected: isNodeSelected,
    isNodeHovered: isNodeHovered,
    showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates
  }), (0, _react2.jsx)("div", {
    "data-testid": "inline-extension-wrapper",
    css: [_styles2.wrapperStyle, extendedInlineExtension && _styles2.inlineWrapperStyels],
    className: classNames,
    onMouseEnter: function onMouseEnter() {
      return handleMouseEvent(true);
    },
    onMouseLeave: function onMouseLeave() {
      return handleMouseEvent(false);
    }
  }, (0, _react2.jsx)("div", {
    css: _styles.overlay,
    className: "extension-overlay"
  }), children ? children : (0, _react2.jsx)(_Lozenge.default, {
    node: node,
    isNodeSelected: isNodeSelected,
    showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates
  })));
  if (extendedInlineExtension) {
    return (0, _react2.jsx)(_ui.WidthContext.Provider, {
      value: (0, _ui.createWidthContext)(rendererContainerWidth)
    }, inlineExtensionInternal);
  }
  return inlineExtensionInternal;
};
var _default = exports.default = InlineExtension;