"use strict";var __rest=this&&this.__rest||function(e,a){var o={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&a.indexOf(t)<0&&(o[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(t=Object.getOwnPropertySymbols(e);r<t.length;r++)a.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(o[t[r]]=e[t[r]])}return o},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.RequestSamples=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),theme_1=require("@redocly/theme"),styled_components_1=__importDefault(require("styled-components")),PayloadSamples_1=require("../PayloadSamples"),CodeSample_1=require("./CodeSample"),useCodeSamples_1=require("./useCodeSamples"),models_1=require("../../models"),events_1=require("../../events"),store_1=require("../../jotai/store"),ServerListDropdown_1=require("../ServerListDropdown"),Language_1=require("../Language"),app_1=require("../../jotai/app"),Replay_1=require("../Replay"),common_1=require("../common"),hooks_1=require("../../hooks"),operation_1=require("../../jotai/operation");function RequestSamplesComponent(e){var{operation:a,disableFooter:o}=e,t=__rest(e,["operation","disableFooter"]);const r=(0,hooks_1.useOtelTelemetry)(),[{activeLanguage:s,languages:n},l]=(0,jotai_1.useAtom)(app_1.languageAtom),{samples:i}=(0,useCodeSamples_1.useCodeSamples)(a),{parser:p,options:{events:d,corsProxyUrl:u,hideReplay:_}}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),m=!(o||a.isWebhook||_||a.hideReplay),c=!!(null==n?void 0:n.length),y=(0,hooks_1.useActiveWithFallback)(i,s),g=e=>{l(e),r.send({type:"openapi_docs.select_language.clicked",payload:{language:e}})},x=(0,jotai_1.useAtomValue)(app_1.activeMimeNameAtom),{activeExampleName:j}=(0,jotai_1.useAtomValue)((0,operation_1.operationStore)(a.pointer)),v=(0,react_1.useCallback)((({lang:e,title:o})=>()=>{var t;const s=(0,events_1.createCodeSampleCopyEvent)({operation:a,label:o,lang:e,type:"request",activeMimeName:x,activeExampleName:j});r.send({type:"openapi_docs.copy_code_snippet.clicked",payload:{snippet_type:"request",language:e}}),null===(t=null==d?void 0:d.codeSamplesCopy)||void 0===t||t.call(d,s)}),[a,r,d,x,j]),S=()=>(0,jsx_runtime_1.jsxs)(StyledPanelHeader,{isExpandable:!1,withReplay:!c&&m,children:[(0,jsx_runtime_1.jsx)(StyledServerListDropdown,{operation:a}),c&&(0,jsx_runtime_1.jsx)(Language_1.LanguageDropdown,{activeTab:y,samples:i,onChange:g}),!c&&m&&(0,jsx_runtime_1.jsx)(Replay_1.Replay,{operation:a,corsProxyUrl:u,fullOpenApi:p.definition})]}),h=(0,react_1.useMemo)((()=>{if(m&&c)return(0,jsx_runtime_1.jsx)(ReplayWrapper,{children:(0,jsx_runtime_1.jsx)(Replay_1.Replay,{operation:a,corsProxyUrl:u,fullOpenApi:p.definition})})}),[m,c,a,u,p.definition]),f=(0,react_1.useMemo)((()=>i.map((e=>e.key===y?(0,jsx_runtime_1.jsx)("div",{children:(0,models_1.isPayloadSample)(e)?(0,jsx_runtime_1.jsx)(PayloadSamples_1.PayloadSamples,Object.assign({content:e.requestBodyContent,onCopyClick:v(e)},t)):(0,jsx_runtime_1.jsx)(CodeSample_1.CodeSample,Object.assign({lang:e.lang,source:e.source,externalSample:e,operation:a,onCopyClick:v(e)},t))},e.key+a.id):null))),[y,v,a,t,i]);return n&&!i.length?(0,jsx_runtime_1.jsx)(common_1.CodeBlockPanel,{className:"panel-request-samples",header:S,isExpandable:!1,expanded:!1}):i.length?(0,jsx_runtime_1.jsx)(common_1.CodeBlockPanel,{className:"panel-request-samples",header:S,footer:h,isExpandable:!1,children:f}):null}exports.RequestSamples=(0,react_1.memo)(RequestSamplesComponent);const StyledPanelHeader=(0,styled_components_1.default)(theme_1.PanelHeader)`
  flex-wrap: nowrap;
  ${({withReplay:e})=>e&&"padding: var(--spacing-xs) var(--spacing-sm);"}
`,StyledServerListDropdown=(0,styled_components_1.default)(ServerListDropdown_1.ServerListDropdown)`
  padding-right: var(--spacing-base);
  min-width: 0;
`,ReplayWrapper=styled_components_1.default.div`
  display: flex;
  justify-content: flex-end;
  border-top: var(--panel-border);
  padding: var(--spacing-base) var(--spacing-md) var(--spacing-md);
`;
//# sourceMappingURL=RequestSamples.js.map