import o from"react";import{EmbeddedReplay as M,StoreProvider as b}from"@redocly/openapi-docs";import{useLocation as A}from"react-router-dom";import{Admonition as I}from"@redocly/theme/markdoc/components/Admonition/Admonition";import{ErrorMessage as P,OpenApiComponentWrap as x}from"../styled.elements.js";import{useStore as R}from"../../hooks/use-store.js";import{getOperation as C}from"../../../../../markdoc/helpers/get-operation/index.js";import{getMockServerDocsConfig as y}from"../../../../templates/openapi-docs/mock-server-config.js";const L=S=>{const{descriptionFile:i,operationId:p,pointer:m,exampleKey:l,mimeType:u,requestBody:a,parameters:v,options:s,environment:r,environments:c,hideOtherSecuritySchemes:O}=S,h=A(),{store:e,error:g,baseSlug:t}=R(i),d=o.useMemo(()=>({...e?.options,...s}),[s,e?.options]),f=o.useMemo(()=>{const{mockServer:E,...k}=d;return{...k,mockServer:y(E,t??"")}},[d,t]),n=o.useMemo(()=>{if(e)return C(e,{operationId:p,pointer:m},f,{exampleKey:l,mimeType:u,environments:c,environment:r,requestBody:a})},[l,f,u,p,m,e,c,r,a]);return e?n?o.createElement(x,{"data-testid":"replay-openapi"},o.createElement(b,{key:`${h.pathname}-${i}-${p||m}`,options:{...s,disableRouter:!0,routingBasePath:t,mockServer:y(d.mockServer,t)},definition:e.definition,withState:{environments:c,allowedEnvironments:r?[r]:void 0,operation:{pointer:n.pointer,state:{requestValues:{body:a,...v}}}}},o.createElement(M,{activeOperationId:n.operationId||"",fullOpenApi:e.definition,corsProxyUrl:e.options.corsProxyUrl,pointer:n.pointer,hideOtherSecuritySchemes:O}))):o.createElement(I,{type:"danger"},"Cannot find OpenAPI operation by operationId or pointer in ",i):o.createElement(P,null,g)};export{L as ReplayOpenApi};
