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