import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(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; })(); }
import React, { Component } from 'react';
import { ProviderFactory, WithProviders } from '../provider-factory';
import { ExtensionComponent } from './ExtensionComponent';
// Ignored via go/ees005
// eslint-disable-next-line @repo/internal/react/no-class-components, @typescript-eslint/no-explicit-any
export var Extension = /*#__PURE__*/function (_Component) {
  function Extension(props) {
    var _this;
    _classCallCheck(this, Extension);
    _this = _callSuper(this, Extension, [props]);
    _defineProperty(_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.createElement(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();
    return _this;
  }
  _inherits(Extension, _Component);
  return _createClass(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.createElement(WithProviders
      // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- there seems to be an existing bug where the Extension component can't be resized if this is memoised because it doesn't rerender so this can't be memoised without a larger refactor
      , {
        providers: ['extensionProvider'],
        providerFactory: this.providerFactory,
        renderNode: this.renderWithProvider
      });
    }
  }]);
}(Component);
_defineProperty(Extension, "displayName", 'Extension');