"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 _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
var _hooks = require("../../../hooks");
var _ui = require("../../../ui");
var _Lozenge = _interopRequireDefault(require("../Lozenge"));
var _styles = require("../styles");
var _styles2 = require("./styles");
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); }
/**
 * @jsxRuntime classic
 * @jsx jsx
 */

// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled, @typescript-eslint/consistent-type-imports -- Ignored via go/DSP-18766; jsx required at runtime for @jsxRuntime classic

var inlineWrapperStyles = (0, _react2.css)({
  maxWidth: '100%',
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
  'tr &': {
    maxWidth: 'inherit'
  },
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors -- Ignored via go/DSP-18766
  '.rich-media-item': {
    maxWidth: '100%'
  }
});
var hoverStyles = (0, _react2.css)({
  '&:hover': {
    boxShadow: "0 0 0 1px ".concat("var(--ds-border-input, #8C8F97)")
  }
});
var InlineExtension = function InlineExtension(props) {
  var node = props.node,
    pluginInjectionApi = props.pluginInjectionApi,
    macroInteractionDesignFeatureFlags = props.macroInteractionDesignFeatureFlags,
    isNodeSelected = props.isNodeSelected,
    children = props.children,
    isNodeHovered = props.isNodeHovered,
    setIsNodeHovered = props.setIsNodeHovered,
    isLivePageViewMode = props.isLivePageViewMode;
  var _ref = macroInteractionDesignFeatureFlags || {},
    showMacroInteractionDesignUpdates = _ref.showMacroInteractionDesignUpdates;
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(pluginInjectionApi, ['width'], function (states) {
      var _states$widthState;
      return {
        width: (_states$widthState = states.widthState) === null || _states$widthState === void 0 ? void 0 : _states$widthState.width
      };
    }),
    width = _useSharedPluginState.width;
  var hasChildren = !!children;
  var classNames = (0, _classnames.default)('extension-container', 'inline', {
    'with-overlay': !showMacroInteractionDesignUpdates,
    'with-children': hasChildren,
    'with-danger-overlay': showMacroInteractionDesignUpdates
  });
  var rendererContainerWidth = 0;
  if ((0, _experiments.editorExperiment)('platform_editor_preview_panel_responsiveness', true, {
    exposure: true
  })) {
    if (width) {
      var padding = width > _editorSharedStyles.akEditorFullPageNarrowBreakout ? (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() : _editorSharedStyles.akEditorGutterPaddingReduced;
      rendererContainerWidth = width - padding * 2;
    }
  } else {
    rendererContainerWidth = width ? width - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2 : 0;
  }
  var handleMouseEvent = function handleMouseEvent(didHover) {
    if (setIsNodeHovered) {
      setIsNodeHovered(didHover);
    }
  };
  var inlineExtensionInternal = (0, _react2.jsx)(_react.Fragment, null, showMacroInteractionDesignUpdates && !isLivePageViewMode && (0, _react2.jsx)(_Lozenge.default, {
    node: node,
    isNodeSelected: isNodeSelected,
    isNodeHovered: isNodeHovered,
    showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates,
    setIsNodeHovered: setIsNodeHovered,
    pluginInjectionApi: pluginInjectionApi
  }), (0, _react2.jsx)("div", {
    "data-testid": "inline-extension-wrapper",
    css: [
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
    _styles2.wrapperStyle, inlineWrapperStyles, showMacroInteractionDesignUpdates && !isLivePageViewMode && hoverStyles]
    // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
    ,
    className: classNames,
    onMouseEnter: function onMouseEnter() {
      return handleMouseEvent(true);
    }
    // @atlassian/a11y/mouse-events-have-key-events: hover border is also accessible via keyboard selection.
    // No-ops here satisfy the rule without duplicating state updates.
    ,
    onFocus: (0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? function () {} : undefined,
    onMouseLeave: function onMouseLeave() {
      return handleMouseEvent(false);
    },
    onBlur: (0, _expValEquals.expValEquals)('editor_a11y__enghealth-46814_fy26', 'isEnabled', true) ? function () {} : undefined
  }, (0, _react2.jsx)("div", {
    css: _styles.overlay,
    className: "extension-overlay"
  }), children ? children : (0, _react2.jsx)(_Lozenge.default, {
    node: node,
    isNodeSelected: isNodeSelected,
    showMacroInteractionDesignUpdates: showMacroInteractionDesignUpdates,
    pluginInjectionApi: pluginInjectionApi
  })));
  return (0, _react2.jsx)(_ui.WidthContext.Provider, {
    value: (0, _ui.createWidthContext)(rendererContainerWidth)
  }, inlineExtensionInternal);
};
var _default = exports.default = InlineExtension;