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