"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResponseSamples=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),PayloadSamples_1=require("../PayloadSamples"),events_1=require("../../events"),store_1=require("../../jotai/store"),Summary_1=require("./Summary"),Tabs_1=require("../Tabs"),common_1=require("../common"),hooks_1=require("../../hooks"),app_1=require("../../jotai/app"),operation_1=require("../../jotai/operation");function ResponseSamplesComponent({operation:e,activeResponseTab:o,onTabChange:a}){const s=(0,hooks_1.useOtelTelemetry)(),{events:t}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),n=(0,hooks_1.useTranslate)(),r=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})),i=e.responses.map((({code:e})=>({key:e,title:e}))),l=(null==i?void 0:i.find((({key:e})=>e===o)))||(null==i?void 0:i[0]),p=(0,jotai_1.useAtomValue)(app_1.activeMimeNameAtom),{activeExampleName:m}=(0,jotai_1.useAtomValue)((0,operation_1.operationStore)(e.pointer)),u=(0,react_1.useCallback)((()=>{var o;s.send({type:"openapi_docs.copy_code_snippet.clicked",payload:{snippet_type:"response"}});const a=(0,events_1.createCodeSampleCopyEvent)({operation:e,type:"response",activeMimeName:p,activeExampleName:m});null===(o=null==t?void 0:t.codeSamplesCopy)||void 0===o||o.call(t,a)}),[s,e,t,p,m]);if(!r.length)return null;return(0,jsx_runtime_1.jsx)(common_1.CodeBlockPanel,{className:"panel-response-samples",header:()=>(0,jsx_runtime_1.jsx)(Summary_1.Summary,{tabs:(0,jsx_runtime_1.jsx)(Tabs_1.Tabs,{tabs:i,activeTab:l,onChange:e=>a(e.key)})}),isExpandable:!1,children:e.responses.map((e=>{var o;return e.code===l.key?(0,jsx_runtime_1.jsx)("div",{children:(null===(o=null==e?void 0:e.content)||void 0===o?void 0:o.hasSample)?(0,jsx_runtime_1.jsx)(PayloadSamples_1.PayloadSamples,{content:e.content,onCopyClick:u}):(0,jsx_runtime_1.jsx)(PayloadSamples_1.StyledCodeBlock,{source:n("openapi.noResponseContent","No content")})},e.code):null}))})}exports.ResponseSamples=(0,react_1.memo)(ResponseSamplesComponent);
//# sourceMappingURL=ResponseSamples.js.map