import{jsx as t}from"react/jsx-runtime";import{memo as b,useCallback as i}from"react";import{useAtomValue as n}from"jotai";import{PayloadSamples as h,StyledCodeBlock as v}from"../PayloadSamples/index.js";import{createCodeSampleCopyEvent as k}from"../../events/index.js";import{globalOptionsAtom as T}from"../../jotai/store.js";import{Summary as g}from"./Summary.js";import{Tabs as x}from"../Tabs/index.js";import{CodeBlockPanel as N}from"../common/index.js";import{useTelemetry as A,useTranslate as E}from"../../hooks/index.js";import{activeMimeNameAtom as M}from"../../jotai/app.js";import{operationStore as P}from"../../jotai/operation.js";function R({operation:o,activeResponseTab:d,onTabChange:f,onPanelToggle:a}){const m=A(),{events:r}=n(T),y=E(),C=o.responses.filter(e=>e.content?.hasSample??!1),s=o.responses.map(({code:e})=>({key:e,title:e})),p=s?.find(({key:e})=>e===d)||s?.[0],l=n(M),{activeExampleName:c}=n(P(o.pointer)),u=i(()=>{m.sendCopyCodeSnippetClickedMessage({snippetType:"response"});const e=k({operation:o,type:"response",activeMimeName:l,activeExampleName:c});r?.codeSamplesCopy?.(e)},[m,o,r,l,c]),S=i(e=>{a?.(e,"response-samples")},[a]);return C.length?t(N,{className:"panel-response-samples",header:()=>t(g,{tabs:t(x,{tabs:s,activeTab:p,onChange:e=>f(e.key)})}),isExpandable:!1,children:o.responses.map(e=>e.code===p.key?t("div",{"data-testid":"response-payload-sample",children:e?.content?.hasSample?t(h,{content:e.content,onCopyClick:u,onPanelToggle:S}):t(v,{source:y("openapi.noResponseContent","No content")})},e.code):null)}):null}const J=b(R);export{J as ResponseSamples};
