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 j,useTranslate as A}from"../../hooks/index.js";import{activeMimeNameAtom as E}from"../../jotai/app.js";import{operationStore as M}from"../../jotai/operation.js";function P({operation:o,activeResponseTab:d,onTabChange:f,onPanelToggle:a}){const m=j(),{events:p}=n(T),y=A(),C=o.responses.filter(e=>e.content?.hasSample??!1),s=o.responses.map(({code:e})=>({key:e,title:e})),r=s?.find(({key:e})=>e===d)||s?.[0],l=n(E),{activeExampleName:c}=n(M(o.pointer)),u=i(()=>{m.sendCopyCodeSnippetClickedMessage([{object:"code_snippet",snippetType:"response"}]);const e=k({operation:o,type:"response",activeMimeName:l,activeExampleName:c});p?.codeSamplesCopy?.(e)},[m,o,p,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:r,onChange:e=>f(e.key)})}),isExpandable:!1,children:o.responses.map(e=>e.code===r.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(P);export{J as ResponseSamples};
