import{jsx as _jsx}from"react/jsx-runtime";import{memo,useCallback}from"react";import{useAtomValue}from"jotai";import{PayloadSamples,StyledCodeBlock}from"../PayloadSamples";import{createCodeSampleCopyEvent}from"../../events";import{globalOptionsAtom}from"../../jotai/store";import{Summary}from"./Summary";import{Tabs}from"../Tabs";import{CodeBlockPanel}from"../common";import{useOtelTelemetry,useTranslate}from"../../hooks";import{activeMimeNameAtom}from"../../jotai/app";import{operationStore}from"../../jotai/operation";function ResponseSamplesComponent({operation:e,activeResponseTab:o,onTabChange:a}){const t=useOtelTelemetry(),{events:n}=useAtomValue(globalOptionsAtom),s=useTranslate(),l=e.responses.filter((e=>{var o,a;return null!==(a=null===(o=e.content)||void 0===o?void 0:o.hasSample)&&void 0!==a&&a})),m=e.responses.map((({code:e})=>({key:e,title:e}))),p=(null==m?void 0:m.find((({key:e})=>e===o)))||(null==m?void 0:m[0]),r=useAtomValue(activeMimeNameAtom),{activeExampleName:i}=useAtomValue(operationStore(e.pointer)),c=useCallback((()=>{var o;t.send({type:"openapi_docs.copy_code_snippet.clicked",payload:{snippet_type:"response"}});const a=createCodeSampleCopyEvent({operation:e,type:"response",activeMimeName:r,activeExampleName:i});null===(o=null==n?void 0:n.codeSamplesCopy)||void 0===o||o.call(n,a)}),[t,e,n,r,i]);if(!l.length)return null;return _jsx(CodeBlockPanel,{className:"panel-response-samples",header:()=>_jsx(Summary,{tabs:_jsx(Tabs,{tabs:m,activeTab:p,onChange:e=>a(e.key)})}),isExpandable:!1,children:e.responses.map((e=>{var o;return e.code===p.key?_jsx("div",{children:(null===(o=null==e?void 0:e.content)||void 0===o?void 0:o.hasSample)?_jsx(PayloadSamples,{content:e.content,onCopyClick:c}):_jsx(StyledCodeBlock,{source:s("openapi.noResponseContent","No content")})},e.code):null}))})}export const ResponseSamples=memo(ResponseSamplesComponent);
//# sourceMappingURL=ResponseSamples.js.map