"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ServerListDropdown=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),theme_1=require("@redocly/theme"),jotai_1=require("jotai"),common_1=require("../common"),styled_1=require("./styled"),PanelItem_1=require("../PanelItem"),services_1=require("../../services"),utils_1=require("../../utils"),app_1=require("../../jotai/app"),hooks_1=require("../../hooks"),environments_1=require("../../utils/environments"),ServerListDropdown=({operation:e,className:r})=>{const t=(0,hooks_1.useOtelTelemetry)(),[[s],i]=(0,jotai_1.useAtom)(app_1.environmentAtom),n=(0,hooks_1.useActiveWithFallback)(e.servers.map((e=>Object.assign(Object.assign({},e),{key:e.url}))),s.server),o=(0,react_1.useCallback)((e=>{e.stopPropagation()}),[]),a=(0,react_1.useCallback)((r=>()=>{1!==e.servers.length&&(i({environment:(0,environments_1.getServerEnvName)(r)}),t.send({type:"openapi_docs.switch_servers.clicked",payload:{server:(0,environments_1.getServerEnvName)(r)}}))}),[e.servers.length,i,t]),_=(0,react_1.useMemo)((()=>e.servers.map((r=>{const t=(0,services_1.joinWithSeparator)((0,utils_1.replaceVariables)(r),e.path);return(0,jsx_runtime_1.jsx)(styled_1.StyledDropdownMenuItem,{onAction:a(r),children:(0,jsx_runtime_1.jsx)(PanelItem_1.PanelItem,{header:r.description,title:t,actions:[(0,jsx_runtime_1.jsx)(styled_1.StyledCopyButton,{data:t,toasterPlacement:"left",onCopyClick:o},t)],active:r.url===n,withCheckmark:!0})},t)}))),[e.servers,e.path,a,o,n]);return(0,jsx_runtime_1.jsx)(theme_1.Dropdown,{className:r,trigger:(0,jsx_runtime_1.jsxs)(styled_1.PathWrapper,{variant:"ghost",children:[(0,jsx_runtime_1.jsx)(common_1.HttpVerb,{color:e.httpVerb,children:e.httpVerb}),(0,jsx_runtime_1.jsx)(styled_1.Path,{children:e.path})]}),withArrow:!0,children:(0,jsx_runtime_1.jsx)(theme_1.DropdownMenu,{children:_})})};exports.ServerListDropdown=ServerListDropdown;
//# sourceMappingURL=ServerListDropdown.js.map