'use client';
import{__rest as e}from"tslib";import t,{useState as o,useRef as l,useMemo as r}from"react";import{twMerge as a}from"tailwind-merge";import"../../../contexts/BaseColorContext.js";import n from"../../../contexts/HoveredValueContext.js";import"../../../contexts/RootStylesContext.js";import i from"../../../contexts/SelectedValueContext.js";import s from"../../../hooks/useInternalState.js";import m from"../../../hooks/useSelectOnKeyDown.js";import c from"../../../assets/ArrowDownHeadIcon.js";import{BaseColors as d}from"../../../lib/constants.js";import{borderRadius as u,border as p,boxShadow as f}from"../../../lib/shape.js";import{sizing as h}from"../../../lib/sizing.js";import{spacing as g}from"../../../lib/spacing.js";import{fontSize as w,fontWeight as j}from"../../../lib/font.js";import{colorPalette as x,DEFAULT_COLOR as b}from"../../../lib/theme.js";import{mergeRefs as C,getColorClassNames as v,makeClassName as E}from"../../../lib/utils.js";import{constructValueToNameMapping as N,getSelectButtonColors as V,hasValue as R}from"../selectUtils.js";import y from"../../util-elements/Modal/Modal.js";const D=E("Dropdown"),S=t.forwardRef(((E,S)=>{const{defaultValue:M,value:k,onValueChange:I,placeholder:X="Select...",disabled:B=!1,icon:H,children:K,className:L}=E,O=e(E,["defaultValue","value","onValueChange","placeholder","disabled","icon","children","className"]),[P,T]=s(M,k),[z,A]=o(!1),U=l(null),Y=H,q=r((()=>N(K)),[K]),F=t.Children.map(K,(e=>e.props.value)),G=e=>{T(e),A(!1),null==I||I(e)},[J,Q]=m(G,F,z,A,P),W=R(P);return t.createElement("div",Object.assign({ref:C([U,S]),onKeyDown:Q,className:a(D("root"),"relative w-full min-w-[10rem]",L)},O),t.createElement("button",{type:"button",className:a(D("button"),"flex justify-between items-center w-full focus:outline-none focus:ring-2",V(W,B),v(d.Blue,x.lightRing).focusRingColor,Y?g.xl.paddingLeft:g.twoXl.paddingLeft,g.twoXl.paddingRight,g.sm.paddingY,u.md.all,p.sm.all,f.sm),onClick:()=>A(!z),disabled:B},t.createElement("div",{className:"flex justify-start items-center truncate"},Y?t.createElement(Y,{className:a(D("icon"),"shrink-0",h.lg.height,h.lg.width,v(b,x.lightText).textColor,g.lg.marginRight),"aria-hidden":"true"}):null,t.createElement("p",{className:a(D("text"),"whitespace-nowrap truncate",w.sm,j.md)},P?q.get(P):X)),t.createElement(c,{className:a(D("arrowDownIcon"),"flex-none",h.lg.height,h.lg.width,g.twoXs.negativeMarginRight,v(b,x.lightText).textColor),"aria-hidden":"true"})),t.createElement(y,{showModal:z,setShowModal:A,parentRef:U},t.createElement(i.Provider,{value:{selectedValue:P,handleValueChange:G}},t.createElement(n.Provider,{value:{hoveredValue:J}},t.Children.map(K,(e=>t.cloneElement(e)))))))}));S.displayName="Dropdown";export{S as default};
