import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useMemo,useCallback}from"react";import{Dropdown,DropdownMenu}from"@redocly/theme";import{useAtom}from"jotai";import{HttpVerb}from"../common";import{PathWrapper,Path,StyledCopyButton,StyledDropdownMenuItem}from"./styled";import{PanelItem}from"../PanelItem";import{joinWithSeparator}from"../../services";import{replaceVariables}from"../../utils";import{environmentAtom}from"../../jotai/app";import{useActiveWithFallback}from"../../hooks";import{getServerEnvName}from"../../utils/environments";export const ServerListDropdown=({operation:e,className:r})=>{const[[t],o]=useAtom(environmentAtom),a=useActiveWithFallback(e.servers.map((e=>Object.assign(Object.assign({},e),{key:e.url}))),t.server),s=useCallback((e=>{e.stopPropagation()}),[]),n=useCallback((r=>()=>{1!==e.servers.length&&o({environment:getServerEnvName(r)})}),[e.servers.length,o]),i=useMemo((()=>e.servers.map((r=>{const t=replaceVariables(r),o=joinWithSeparator(t,e.path);return _jsx(StyledDropdownMenuItem,{onAction:n(r),children:_jsx(PanelItem,{header:r.description,title:replaceVariables(r),actions:[_jsx(StyledCopyButton,{data:o,toasterPlacement:"left",onCopyClick:s},o)],active:r.url===a,withCheckmark:!0})},o)}))),[e.servers,e.path,n,s,a]);return _jsx(Dropdown,{className:r,trigger:_jsxs(PathWrapper,{variant:"ghost",children:[_jsx(HttpVerb,{color:e.httpVerb,children:e.httpVerb}),_jsx(Path,{children:e.path})]}),withArrow:!0,children:_jsx(DropdownMenu,{children:i})})};
//# sourceMappingURL=ServerListDropdown.js.map