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