import e from"../../node_modules/classnames/index.js";import t,{useState as l,useCallback as r}from"react";import"../../node_modules/reactstrap/esm/index.js";import{DropdownItem as o}from"./DropdownItem.js";import{DropdownMenu as a}from"./DropdownMenu.js";import{DropdownToggle as n}from"./DropdownToggle.js";import s from"../../node_modules/@phosphor-icons/react/dist/icons/CaretDown.es.js";import i from"../Stack/Stack.js";import m from"../Text/Text.js";import{mapBootstrapSizeToTextSize as c}from"../utils.js";import{withEllipsis as p}from"../../utils/stringUtils.js";import{useToggle as d}from"../../utils/hooks.js";import f from"../Portal/CortexPortal.js";import u from"../Icon/icon.module.scss.js";import g from"./Dropdown.module.scss.js";import{__exports as E}from"../../_virtual/index.js";const y=(e="")=>"string"==typeof e?p(e,30):e,j=({defaultSelected:p,defaultText:j,disabled:w,label:b,light:x,onReset:k,onSelect:h,options:z,selected:C,showReset:D=!1,size:_="md",truncateText:R=!0,tight:S})=>{const T=c(_),[v,I]=l({left:0,top:0}),[N,A]=d(),F=r((e=>{const t=e?.target?.getBoundingClientRect();t&&I({left:t.x+t.width/2,top:t.y+window.scrollY}),A()}),[A]),P=r((e=>z.find((t=>t.key===e)).label),[z]),B=C?P(C):p?P(p):j,M=R?y(B):B,O=z.find((e=>e.key===C||e.label===M))?.icon,U=t.createElement(t.Fragment,null,N&&t.createElement(f,null,t.createElement("div",{style:{left:v.left,top:v.top}},t.createElement(a,null,z.map((e=>{const{icon:l}=e;return t.createElement(o,{key:e.key,"aria-label":e?.["aria-label"]??e.label,onClick:()=>h(e.key)},t.createElement(i,{alignItems:"center",row:!0,spacing:1},l&&t.createElement(m,{legacyColor:"primary",size:T},t.createElement(l,null)),t.createElement(m,{size:T},R?y(e.label):e.label)))})),D&&k&&t.createElement(t.Fragment,null,t.createElement(o,{className:"my-0",divider:!0}),t.createElement(o,{"aria-label":"Reset",onClick:k},t.createElement(m,{size:T},"Reset")))))));return t.createElement(E.Dropdown,{disabled:w,isOpen:N,toggle:F},t.createElement(n,{"aria-label":b,className:e("fw-normal","text-nowrap","no-underline",g.suppressActiveState,{"btn-link":x,"p-0":S}),color:"default"},t.createElement(i,{alignItems:"center",row:!0,spacing:1},O&&t.createElement(m,{legacyColor:"primary",light:x,size:T},t.createElement(O,null)),t.createElement(m,{legacyColor:w?"gray":"primary",light:x,size:T},M),t.createElement(m,{light:!0,size:T},t.createElement(s,{className:u.textAligned,size:"0.75rem"})))),U)};export{j as default};
//# sourceMappingURL=Dropdown.js.map
