import{jsx as e,jsxs as v}from"react/jsx-runtime";import{useMemo as w,useCallback as c}from"react";import{useAtom as S,useAtomValue as g}from"jotai";import{DropdownMenu as b}from"@redocly/theme/components/Dropdown/DropdownMenu";import{Dropdown as y}from"@redocly/theme/components/Dropdown/Dropdown";import{getOperationColor as A}from"@redocly/theme/core/openapi";import{HttpVerb as C}from"../common/index.js";import{PathWrapper as k,Path as j,StyledCopyButton as P,StyledDropdownMenuItem as V}from"./styled.js";import{PanelItem as x}from"../PanelItem/index.js";import{joinWithSeparator as D}from"../../services/index.js";import{getServerDisplayName as M,replaceVariables as _}from"../../utils/index.js";import{environmentAtom as E}from"../../jotai/app.js";import{useActiveWithFallback as N,useTelemetry as O}from"../../hooks/index.js";import{getServerEnvName as p}from"../../utils/environments.js";import{createTargetServerSwitchEvent as W}from"../../events/index.js";import{globalStoreAtom as I}from"../../jotai/store.js";const $=({operation:r,className:h})=>{const n=O(),[[d],m]=S(E),{options:{events:i}}=g(I),s=N(r.servers.map(t=>({...t,key:t.url})),d.server),a=c(t=>{t.stopPropagation()},[]),l=c(t=>()=>{if(r.servers.length!==1&&(m({environment:p(t)}),n.sendSwitchServersClickedMessage([{id:"button_switch_servers",object:"button",uri:typeof window<"u"?window.location.href:"",server:p(t)}]),i?.targetServerSwitch&&t)){const o=W({operation:r,serverUrl:t.url});i.targetServerSwitch(o)}},[r,m,n,i]),u=w(()=>r.servers.map(t=>{const o=D(_(t),r.path);return e(V,{onAction:l(t),children:e(x,{header:M(t),title:o,actions:[e(P,{data:o,toasterPlacement:"left",onCopyClick:a},o)],active:t.url===s,withCheckmark:!0})},o)}),[r.servers,r.path,l,a,s]),f=A({isAdditionalOperation:r.isAdditionalOperation,httpVerb:r.httpVerb});return e(y,{className:h,trigger:v(k,{variant:"ghost",children:[e(C,{color:f,children:r.httpVerb}),e(j,{children:r.path})]}),withArrow:!0,children:e(b,{children:u})})};export{$ as ServerListDropdown};
