"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],s]=(0,jotai_1.useAtom)(app_1.environmentAtom),i=(0,hooks_1.useActiveWithFallback)(e.servers.map((e=>Object.assign(Object.assign({},e),{key:e.url}))),t.server),n=(0,react_1.useCallback)((e=>{e.stopPropagation()}),[]),o=(0,react_1.useCallback)((r=>()=>{1!==e.servers.length&&s({environment:(0,environments_1.getServerEnvName)(r)})}),[e.servers.length,s]),a=(0,react_1.useMemo)((()=>e.servers.map((r=>{const t=(0,utils_1.replaceVariables)(r),s=(0,services_1.joinWithSeparator)(t,e.path);return(0,jsx_runtime_1.jsx)(styled_1.StyledDropdownMenuItem,{onAction:o(r),children:(0,jsx_runtime_1.jsx)(PanelItem_1.PanelItem,{header:r.description,title:(0,utils_1.replaceVariables)(r),actions:[(0,jsx_runtime_1.jsx)(styled_1.StyledCopyButton,{data:s,toasterPlacement:"left",onCopyClick:n},s)],active:r.url===i,withCheckmark:!0})},s)}))),[e.servers,e.path,o,n,i]);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:a})})};exports.ServerListDropdown=ServerListDropdown;
//# sourceMappingURL=ServerListDropdown.js.map