"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__awaiter=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,a){function i(e){try{u(o.next(e))}catch(e){a(e)}}function s(e){try{u(o.throw(e))}catch(e){a(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}u((o=o.apply(e,t||[])).next())}))},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Replay=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),theme_1=require("@redocly/theme"),jotai_1=require("jotai"),deepmerge_1=__importDefault(require("deepmerge")),ReplayOverlay=(0,react_1.lazy)((()=>__awaiter(void 0,void 0,void 0,(function*(){return Promise.resolve().then((()=>__importStar(require("@redocly/replay")))).then((e=>({default:e.ReplayOverlay})))})))),store_1=require("../../jotai/store"),replay_1=require("../../jotai/replay"),operation_1=require("../../jotai/operation"),constants_1=require("../../constants"),app_1=require("../../jotai/app"),utils_1=require("./utils"),hooks_1=require("../../hooks"),utils_2=require("../../utils");function ReplayComponent({operation:e,corsProxyUrl:t,fullOpenApi:r}){var o,n;const a=(0,hooks_1.useTranslate)(),i=(0,hooks_1.useOtelTelemetry)(),s=(0,react_1.useRef)(null),{mockServer:u,oAuth2RedirectURI:l,routingBasePath:_}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),c=(0,jotai_1.useAtomValue)(replay_1.allOperationsAtom),{parser:p}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),d=(0,jotai_1.useAtomValue)(app_1.userClaimsAtom),[m,f]=(0,react_1.useState)(!1),[h,y]=(0,jotai_1.useAtom)(replay_1.replayStateAtom),[j,v]=(0,jotai_1.useAtom)(operation_1.allOperations),[[,O],A]=(0,jotai_1.useAtom)(app_1.environmentAtom);(0,theme_1.useFocusTrap)(s),(0,theme_1.useModalScrollLock)(m);const x=(0,react_1.useCallback)((({operations:e,environment:t,environments:r})=>{const o=e.reduce(((e,t)=>{t.requestValues.body=t.requestValues.body instanceof URLSearchParams?Object.fromEntries(t.requestValues.body.entries()):t.requestValues.body;const{path:r,method:o}=t.sourcePath,n=utils_2.JsonPointer.compile(["paths",r,o]);return e[n]=(0,deepmerge_1.default)((0,operation_1.getDefaultOperationStore)(n),t),e}),{});v(Object.assign(Object.assign({},j),o)),A({environment:t,environments:r})}),[j,v,A]),b=()=>{h!==constants_1.LOADING_STATE.LOADING&&(m||i.send({type:"openapi_docs.try_it.opened"}),f(!m)),h===constants_1.LOADING_STATE.NOT_LOADED&&y(constants_1.LOADING_STATE.LOADING)},g=(0,react_1.useCallback)((e=>{if(!e)return;const t=c.find((t=>t.operationId===e));return _+(null==t?void 0:t.href)}),[c,_]);return r?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(theme_1.Button,{onClick:b,variant:"primary",iconPosition:"left",icon:h===constants_1.LOADING_STATE.LOADING?(0,jsx_runtime_1.jsx)(theme_1.CircleDashIcon,{}):(0,jsx_runtime_1.jsx)(theme_1.RocketIcon,{}),children:h===constants_1.LOADING_STATE.LOADING?a("openapi.loading","Loading..."):a("openapi.tryIt","Try it")}),m&&(0,jsx_runtime_1.jsx)(react_1.Suspense,{children:(0,jsx_runtime_1.jsx)(theme_1.Portal,{mountId:"api-content",children:(0,jsx_runtime_1.jsx)("div",{ref:s,children:(0,jsx_runtime_1.jsx)(ReplayOverlay,{activeOperationId:e.operationId||e.pointer,source:{data:r,type:"openapi"},onRequestChange:x,onClose:b,onLoad:()=>y(constants_1.LOADING_STATE.LOADED),settings:{corsProxyUrl:t,mockServer:u,environment:O,apiId:null===(n=null===(o=null==p?void 0:p.definition.info)||void 0===o?void 0:o["x-metadata"])||void 0===n?void 0:n.apiId,oAuth2RedirectURI:l,disableCollectionsTab:!0,disableWorkflowTab:!0,storageKey:_,convertOperationToReplayValue:(e,t,r)=>(0,utils_1.convertOperationToReplayValueForRedoc)(d)(e,t,r),getOperationUrl:g}})})})})]}):null}exports.Replay=(0,react_1.memo)(ReplayComponent);
//# sourceMappingURL=Replay.js.map