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,useOtelTelemetry}from"../../hooks";import{getServerEnvName}from"../../utils/environments";export const ServerListDropdown=({operation:e,className:r})=>{const t=useOtelTelemetry(),[[o],s]=useAtom(environmentAtom),a=useActiveWithFallback(e.servers.map((e=>Object.assign(Object.assign({},e),{key:e.url}))),o.server),n=useCallback((e=>{e.stopPropagation()}),[]),i=useCallback((r=>()=>{1!==e.servers.length&&(s({environment:getServerEnvName(r)}),t.send({type:"openapi_docs.switch_servers.clicked",payload:{server:getServerEnvName(r)}}))}),[e.servers.length,s,t]),m=useMemo((()=>e.servers.map((r=>{const t=joinWithSeparator(replaceVariables(r),e.path);return _jsx(StyledDropdownMenuItem,{onAction:i(r),children:_jsx(PanelItem,{header:r.description,title:t,actions:[_jsx(StyledCopyButton,{data:t,toasterPlacement:"left",onCopyClick:n},t)],active:r.url===a,withCheckmark:!0})},t)}))),[e.servers,e.path,i,n,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:m})})};
//# sourceMappingURL=ServerListDropdown.js.map