"use strict";
/**
 * @prettier
 */
"use client";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _swaggerUi = _interopRequireDefault(require("#swagger-ui"));
const {
  config
} = _swaggerUi.default;
const SwaggerUI = ({
  spec = config.defaults.spec,
  url = config.defaults.url,
  layout = config.defaults.layout,
  requestInterceptor = config.defaults.requestInterceptor,
  responseInterceptor = config.defaults.responseInterceptor,
  supportedSubmitMethods = config.defaults.supportedSubmitMethods,
  queryConfigEnabled = config.defaults.queryConfigEnabled,
  plugins = config.defaults.plugins,
  displayOperationId = config.defaults.displayOperationId,
  showMutatedRequest = config.defaults.showMutatedRequest,
  docExpansion = config.defaults.docExpansion,
  defaultModelExpandDepth = config.defaults.defaultModelExpandDepth,
  defaultModelsExpandDepth = config.defaults.defaultModelsExpandDepth,
  defaultModelRendering = config.defaults.defaultModelRendering,
  presets = config.defaults.presets,
  deepLinking = config.defaults.deepLinking,
  showExtensions = config.defaults.showExtensions,
  showCommonExtensions = config.defaults.showCommonExtensions,
  filter = config.defaults.filter,
  requestSnippetsEnabled = config.defaults.requestSnippetsEnabled,
  requestSnippets = config.defaults.requestSnippets,
  tryItOutEnabled = config.defaults.tryItOutEnabled,
  displayRequestDuration = config.defaults.displayRequestDuration,
  withCredentials = config.defaults.withCredentials,
  persistAuthorization = config.defaults.persistAuthorization,
  oauth2RedirectUrl = config.defaults.oauth2RedirectUrl,
  onComplete = null
}) => {
  const [system, setSystem] = (0, _react.useState)(null);
  const SwaggerUIComponent = system?.getComponent("App", "root");
  const handleComplete = (0, _react.useCallback)(() => {
    if (typeof onComplete === "function") {
      onComplete();
    }
  }, [onComplete]);
  (0, _react.useEffect)(() => {
    setSystem((0, _swaggerUi.default)({
      plugins,
      spec,
      url,
      dom_id: null,
      domNode: null,
      layout,
      defaultModelsExpandDepth,
      defaultModelRendering,
      presets: [_swaggerUi.default.presets.apis, ...presets],
      requestInterceptor,
      responseInterceptor,
      onComplete: handleComplete,
      docExpansion,
      supportedSubmitMethods,
      queryConfigEnabled,
      defaultModelExpandDepth,
      displayOperationId,
      tryItOutEnabled,
      displayRequestDuration,
      requestSnippetsEnabled,
      requestSnippets,
      showMutatedRequest,
      deepLinking,
      showExtensions,
      showCommonExtensions,
      filter,
      persistAuthorization,
      withCredentials,
      ...(typeof oauth2RedirectUrl === "string" ? {
        oauth2RedirectUrl: oauth2RedirectUrl
      } : {})
    }));
  }, []);
  (0, _react.useEffect)(() => {
    if (system) {
      const prevStateUrl = system.specSelectors.url();
      if (url !== prevStateUrl) {
        system.specActions.updateSpec("");
        if (url) {
          system.specActions.updateUrl(url);
          system.specActions.download(url);
        }
      }
      const prevStateSpec = system.specSelectors.specStr();
      if (spec && spec !== prevStateSpec) {
        const updatedSpec = typeof spec === "object" ? JSON.stringify(spec) : spec;
        system.specActions.updateSpec(updatedSpec);
      }
    }
  }, [url, spec]);
  return SwaggerUIComponent ? /*#__PURE__*/_react.default.createElement(SwaggerUIComponent, null) : null;
};
SwaggerUI.System = _swaggerUi.default.System;
SwaggerUI.presets = _swaggerUi.default.presets;
SwaggerUI.plugins = _swaggerUi.default.plugins;
SwaggerUI.config = _swaggerUi.default.config;
var _default = exports.default = SwaggerUI;

