import{jsx as t}from"react/jsx-runtime";import{useCallback as h,useMemo as s}from"react";import{Dropdown as k}from"@redocly/theme/components/Dropdown/Dropdown";import{DropdownMenu as y}from"@redocly/theme/components/Dropdown/DropdownMenu";import{LanguageItem as D}from"./LanguageItem.js";import{DropdownTriggerButton as x,StyledDropdownMenuItem as A}from"./styled.js";const B=({samples:o,activeTab:n,onChange:e,trigger:l,width:i,withArrow:f=!0,withCheckmark:d=!0,withIcon:c=!0})=>{const m=h(r=>()=>{const u=o.find(({key:a})=>a===r.key);u&&e(u.key)},[e,o]),g=s(()=>o.map(r=>t(A,{$width:i,onAction:m(r),children:t(D,{item:r,active:n===r.key,withCheckmark:d,withIcon:c})},r.key)),[n,m,o,i,d,c]),w=o.find(({key:r})=>r===n),p=l||t(x,{variant:"ghost",children:w?.title});return g.length>1?t(k,{trigger:p,withArrow:f,alignment:"end",children:t(y,{children:g})}):p};export{B as LanguageDropdown};
