"use strict";var __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"),styled_components_1=__importDefault(require("styled-components")),jotai_1=require("jotai"),replay_1=require("@redocly/replay"),store_1=require("../../jotai/store"),replay_2=require("../../jotai/replay"),operation_1=require("../../jotai/operation"),constants_1=require("../../constants"),app_1=require("../../jotai/app"),utils_1=require("../../utils"),utils_2=require("./utils");function ReplayComponent({operation:e,corsProxyUrl:t,fullOpenApi:r}){var o,a;const i=(0,react_1.useRef)(null),{routingBasePath:n,mockServer:s,oAuth2RedirectURI:_}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),{parser:l}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),[u,c]=(0,react_1.useState)(!1),[p,m]=(0,jotai_1.useAtom)(replay_2.replayStateAtom),[,d]=(0,jotai_1.useAtom)(app_1.unsupportedFeatureScreenAtom),j=(0,jotai_1.useSetAtom)((0,operation_1.operationStore)(e.pointer)),[v,A]=(0,jotai_1.useAtom)(app_1.activeMimeNameAtom),[[,x],y]=(0,jotai_1.useAtom)(app_1.environmentAtom);(0,theme_1.useFocusTrap)(i),(0,theme_1.useModalScrollLock)(u);const h=(0,react_1.useCallback)((({requestValues:e,activeExampleName:t,activeMimeName:r,environment:o,environments:a,activeSecuritySchemeIds:i})=>{j((r=>Object.assign(Object.assign({},r),{requestValues:e,activeExampleName:t,activeSecuritySchemeIds:i}))),A(r||v),y({environment:o,environments:a})}),[j,A,v,y]),f=()=>{(0,utils_1.isMobile)({tablet:!0})?d(!0):(p!==constants_1.LOADING_STATE.LOADING&&c(!u),p===constants_1.LOADING_STATE.NOT_LOADED&&m(constants_1.LOADING_STATE.LOADING))};return(0,jsx_runtime_1.jsxs)(Wrapper,{children:[(0,jsx_runtime_1.jsx)("span",{children:"Experience it firsthand in the API Explorer!"}),(0,jsx_runtime_1.jsx)(theme_1.Button,{onClick:f,variant:"primary",iconPosition:"left",icon:p===constants_1.LOADING_STATE.LOADING?(0,jsx_runtime_1.jsx)(theme_1.CircleDashIcon,{}):(0,jsx_runtime_1.jsx)(theme_1.RocketIcon,{}),children:p===constants_1.LOADING_STATE.LOADING?"Loading...":"Try it"}),u&&(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:i,children:(0,jsx_runtime_1.jsx)(replay_1.ReplayOverlay,{value:(0,utils_2.convertOperationToReplayValue)(e,r),onRequestChange:h,onClose:f,corsProxyUrl:t,operationUrl:n+e.href,onLoad:()=>m(constants_1.LOADING_STATE.LOADED),mockServer:s,environment:x,apiId:null===(a=null===(o=null==l?void 0:l.definition.info)||void 0===o?void 0:o["x-metadata"])||void 0===a?void 0:a.apiId,oAuth2RedirectURI:_})})})})]})}exports.Replay=(0,react_1.memo)(ReplayComponent);const Wrapper=styled_components_1.default.div`
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-top: var(--panel-border);
  padding: var(--spacing-base) var(--spacing-md) var(--spacing-md);

  & > span {
    font-weight: var(--font-weight-regular);
    color: var(--text-color-primary);
  }
`;
//# sourceMappingURL=Replay.js.map