import*as e from"react";import{StoreProvider as S,ResponseSamples as v,normalizeOptions as g}from"@redocly/openapi-docs";import{ErrorMessage as b,OpenApiComponentWrap as E}from"../styled.elements";import{useStore as R}from"../../hooks/use-store";import{getOperation as C}from"../../../../../markdoc/helpers/get-operation/index.js";import{getMockServerDocsConfig as O}from"../../../../templates/openapi-docs/mock-server-config.js";function x(a){const{descriptionFile:m,operationId:i,pointer:p,exampleKey:t}=a,{store:o,error:c,baseSlug:s}=R(m),[l,f]=e.useState(),r=e.useMemo(()=>({...o?.options,mockServer:O(o?.options?.mockServer,s||"")}),[o?.options,s]),n=e.useMemo(()=>{if(o)return C(o,{operationId:i,pointer:p},g(r),{exampleKey:t})},[t,r,i,p,o]),d=e.useCallback(u=>{f(u)},[]);return o?n?e.createElement(E,{"data-testid":"openapi-response-sample"},e.createElement(S,{options:r,definition:o.definition,withState:{operation:{pointer:n.pointer,state:{activeExampleName:t}}}},e.createElement(v,{operation:n,activeResponseTab:l,onTabChange:d}))):e.createElement("pre",{style:{color:"red"}},"Cannot find OpenAPI operation by operationId or pointer"):e.createElement(b,null,c)}export{x as OpenApiResponseSample};
