"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Extension = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _providerFactory = require("../provider-factory");
var _ExtensionComponent = require("./ExtensionComponent");
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 _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/react/no-class-components, @typescript-eslint/no-explicit-any
var Extension = exports.Extension = /*#__PURE__*/function (_Component) {
  function Extension(props) {
    var _this;
    (0, _classCallCheck2.default)(this, Extension);
    _this = _callSuper(this, Extension, [props]);
    (0, _defineProperty2.default)(_this, "renderWithProvider", function (_ref) {
      var _pluginInjectionApi$e;
      var extensionProvider = _ref.extensionProvider;
      var _this$props = _this.props,
        node = _this$props.node,
        getPos = _this$props.getPos,
        editorView = _this$props.editorView,
        handleContentDOMRef = _this$props.handleContentDOMRef,
        extensionHandlers = _this$props.extensionHandlers,
        references = _this$props.references,
        editorAppearance = _this$props.editorAppearance,
        pluginInjectionApi = _this$props.pluginInjectionApi,
        eventDispatcher = _this$props.eventDispatcher,
        macroInteractionDesignFeatureFlags = _this$props.macroInteractionDesignFeatureFlags,
        showLivePagesBodiedMacrosRendererView = _this$props.showLivePagesBodiedMacrosRendererView,
        showUpdatedLivePages1PBodiedExtensionUI = _this$props.showUpdatedLivePages1PBodiedExtensionUI,
        rendererExtensionHandlers = _this$props.rendererExtensionHandlers;

      // Extensions are not yet using the new plugin architecture, and the use of the pluginInjectionApi
      // is not type safe in editor-common.
      // @ts-ignore
      var currentState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.currentState();
      var _ref2 = currentState || {},
        contentMode = _ref2.contentMode,
        mode = _ref2.mode;
      var isLivePageViewMode = contentMode === 'live-view' || mode === 'view';
      return /*#__PURE__*/_react.default.createElement(_ExtensionComponent.ExtensionComponent, {
        editorView: editorView,
        node: node,
        getPos: getPos,
        references: references,
        extensionProvider: extensionProvider,
        handleContentDOMRef: handleContentDOMRef,
        extensionHandlers: extensionHandlers,
        editorAppearance: editorAppearance,
        pluginInjectionApi: pluginInjectionApi,
        eventDispatcher: eventDispatcher,
        macroInteractionDesignFeatureFlags: macroInteractionDesignFeatureFlags,
        showLivePagesBodiedMacrosRendererView: showLivePagesBodiedMacrosRendererView,
        showUpdatedLivePages1PBodiedExtensionUI: showUpdatedLivePages1PBodiedExtensionUI,
        rendererExtensionHandlers: rendererExtensionHandlers,
        isLivePageViewMode: isLivePageViewMode
      });
    });
    _this.providerFactory = props.providerFactory || new _providerFactory.ProviderFactory();
    return _this;
  }
  (0, _inherits2.default)(Extension, _Component);
  return (0, _createClass2.default)(Extension, [{
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      if (!this.props.providerFactory) {
        // new ProviderFactory is created if no `providers` has been set
        // in this case when component is unmounted it's safe to destroy this providerFactory
        this.providerFactory.destroy();
      }
    }
  }, {
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react.default.createElement(_providerFactory.WithProviders, {
        providers: ['extensionProvider'],
        providerFactory: this.providerFactory,
        renderNode: this.renderWithProvider
      });
    }
  }]);
}(_react.Component);
(0, _defineProperty2.default)(Extension, "displayName", 'Extension');