1import{r,j as a,H as ue}from"./index.c19e81ac.js";import{u as ce}from"./ed5a659c.js";function fe({value:d,options:q=[],onChange:G,placeholder:b="Select",className:K="",searchable:y=!0,searchPlaceholder:J,loading:l=!1}){const F=J||(b&&/^select\s+/i.test(b)?b.replace(/^select\s+/i,"Search "):`Search ${b}`),[u,O]=r.useState(!1),[T,R]=r.useState(""),[v,X]=r.useState({top:0,left:0,width:0,maxHeight:280,placement:"bottom"}),[h,m]=r.useState(-1),[_,N]=r.useState({visible:!1,thumbH:0,thumbTop:0}),z=r.useRef(null),E=r.useRef(null),H=r.useRef(null),Y=r.useRef(null),w=r.useRef(null),P=r.useRef(null),I=r.useRef(!1),C=r.useRef(!1),U=r.useId(),g=r.useMemo(()=>q.map(e=>e&&typeof e=="object"?{value:String(e.value),label:String(e.label??e.value)}:{value:String(e),label:String(e)}),[q]),c=r.useMemo(()=>{const e=T.trim().toLowerCase();return e?g.filter(t=>t.label.toLowerCase().includes(e)||t.value.toLowerCase().includes(e)):g},[g,T]),Z=r.useMemo(()=>{const e=g.find(t=>t.value===String(d)||t.label===String(d));return e?e.label:d||""},[g,d]);function k(){const e=w.current;if(!e)return;const{scrollTop:t,scrollHeight:o,clientHeight:n}=e;if(o<=n+1){N({visible:!1,thumbH:0,thumbTop:0});return}const s=Math.max(28,n/o*n),i=n-s,f=i<=0?0:t/(o-n)*i;N({visible:!0,thumbH:s,thumbTop:f})}function D(e=0){O(!0),m(e)}function x({focusTrigger:e=!1}={}){O(!1),R(""),m(-1),e&&(C.current=!0,requestAnimationFrame(()=>{var t;(t=E.current)==null||t.focus(),requestAnimationFrame(()=>{C.current=!1})}))}function B(e){e&&(G(typeof e=="object"&&e!==null?e.value:e),x({focusTrigger:!0}))}function j(){const e=g.findIndex(t=>t.value===d);return e>=0?e:0}function V(){const e=w.current;if(!e)return 1;const t=e.querySelector('[role="option"]'),o=(t==null?void 0:t.offsetHeight)||36;if(o<=0)return 1;const n=Math.max(1,Math.floor(e.clientHeight/o));return Math.max(1,n-1)}function A(e){c.length&&m(t=>{const o=t<0?e>0?-1:c.length:t;return Math.min(Math.max(o+e,0),c.length-1)})}function ee(e,t){var s;if(!e)return;const o=Array.from(document.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')).filter(i=>{var p;if(i===e)return!0;if((p=H.current)!=null&&p.contains(i)||i.getAttribute("aria-hidden")==="true"||i.closest('[aria-hidden="true"]'))return!1;const f=window.getComputedStyle(i);return!(f.visibility==="hidden"||f.display==="none")}),n=o.indexOf(e);n<0||(s=o[t?n-1:n+1])==null||s.focus()}r.useLayoutEffect(()=>{if(!u)return;function e(){const o=E.current,n=H.current;if(!o)return;const s=o.getBoundingClientRect(),i=4,f=12,p=window.innerHeight-s.bottom-f,L=s.top-f,M=280,S=p<180&&L>p,se=Math.max(120,S?L-i:p-i),$=Math.min(M,se);let Q=s.bottom+i;if(S){const ie=(n==null?void 0:n.offsetHeight)||$;Q=Math.max(f,s.top-i-Math.min(ie,$))}X({top:Q,left:s.left,width:Math.max(s.width,240),maxHeight:$,placement:S?"top":"bottom"})}e();const t=requestAnimationFrame(e);return window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{cancelAnimationFrame(t),window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[u,c.length]),r.useLayoutEffect(()=>{if(!u)return;k();const e=w.current;if(!e)return;e.addEventListener("scroll",k);const t=typeof ResizeObserver<"u"?new ResizeObserver(k):null;return t==null||t.observe(e),()=>{e.removeEventListener("scroll",k),t==null||t.disconnect()}},[u,c]),r.useEffect(()=>{if(!u){R(""),m(-1),N({visible:!1,thumbH:0,thumbTop:0});return}const e=c.findIndex(o=>o.value===d);m(e>=0?e:c.length?0:-1),requestAnimationFrame(()=>{var o,n;y?(o=Y.current)==null||o.focus():(n=H.current)==null||n.focus()});function t(o){var s,i;const n=o.target;(s=z.current)!=null&&s.contains(n)||(i=H.current)!=null&&i.contains(n)||x()}return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[u,y]),r.useEffect(()=>{u&&m(c.length?0:-1)},[T]),r.useEffect(()=>{if(!u||h<0)return;const e=w.current,t=e==null?void 0:e.querySelectorAll('[role="option"]')[h];t==null||t.scrollIntoView({block:"nearest"})},[h,u]),r.useEffect(()=>{function e(o){const n=P.current,s=w.current;if(!n||!s)return;const i=o.clientY-n.startY,{scrollHeight:f,clientHeight:p}=s,L=f-p,M=p-n.thumbH;if(M<=0)return;const S=Math.min(Math.max(n.startTop+i,0),M);s.scrollTop=S/M*L}function t(){P.current=null}return document.addEventListener("mousemove",e),document.addEventListener("mouseup",t),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",t)}},[]);function W(e){if(["Escape","ArrowDown","ArrowUp","PageDown","PageUp","Home","End","Enter","Tab"].includes(e.ke
1y)){if(e.preventDefault(),e.stopPropagation(),e.key==="Escape"){x({focusTrigger:!0});return}if(e.key==="ArrowDown"){A(1);return}if(e.key==="ArrowUp"){A(-1);return}if(e.key==="PageDown"){A(V());return}if(e.key==="PageUp"){A(-V());return}if(e.key==="Home"){c.length&&m(0);return}if(e.key==="End"){c.length&&m(c.length-1);return}if(e.key==="Enter"){h>=0&&c[h]&&B(c[h]);return}e.key==="Tab"&&(x(),requestAnimationFrame(()=>ee(E.current,e.shiftKey)))}}function te(){if(!l&&!C.current){if(I.current){I.current=!1;return}u||D(j())}}function ne(){I.current=!0}function re(e){l||e.key!=="Tab"&&(u||(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="Enter"||e.key===" ")&&(e.preventDefault(),D(j())))}function oe(e){e.key==="Tab"&&!u&&document.activeElement===E.current&&D(j())}return r.useEffect(()=>{l&&u&&x()},[l]),a.jsxs("div",{className:`dropdown${u?" is-open":""}${l?" is-loading":""}${K?` ${K}`:""}`,ref:z,children:[a.jsxs("button",{type:"button",ref:E,className:"dropdown__trigger","aria-haspopup":"listbox","aria-expanded":u,"aria-controls":U,"aria-label":b,"aria-busy":l,disabled:l,onMouseDown:ne,onFocus:te,onClick:()=>{l||(u?x({focusTrigger:!0}):D(j()))},onKeyDown:re,onKeyUp:oe,children:[a.jsx("span",{className:d?"dropdown__value":"dropdown__placeholder",children:l?"Loadingâ¦":Z||b}),l?a.jsx("span",{className:"dropdown__spinner","aria-hidden":"true"}):a.jsx(ce,{className:"icon dropdown__chevron",strokeWidth:2})]}),u&&ue.createPortal(a.jsxs("div",{ref:H,className:`dropdown__menu dropdown__menu--${v.placement}`,style:{top:v.top,left:v.left,minWidth:v.width,width:v.width,maxHeight:v.maxHeight},tabIndex:y?-1:0,onKeyDown:y?void 0:W,children:[y?a.jsx("div",{className:"dropdown__search",children:a.jsx("input",{ref:Y,type:"text",className:"dropdown__search-input",name:"dropdown-search",value:T,placeholder:F,"aria-label":F,"aria-autocomplete":"list","aria-controls":U,autoComplete:"off","data-lpignore":"true","data-1p-ignore":"true",onChange:e=>R(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:W})}):null,a.jsxs("div",{className:"dropdown__list-wrap",children:[a.jsx("ul",{ref:w,className:"dropdown__list",id:U,role:"listbox",children:c.length===0?a.jsx("li",{className:"dropdown__empty",role:"presentation",children:"No matches"}):c.map((e,t)=>a.jsx("li",{role:"presentation",children:a.jsx("button",{type:"button",role:"option",tabIndex:-1,"aria-selected":e.value===d,className:`dropdown__option${e.value===d?" is-selected":""}${t===h?" is-active":""}`,onMouseEnter:()=>m(t),onClick:()=>B(e),children:e.label})},`${e.value}-${e.label}`))}),_.visible?a.jsx("div",{className:"dropdown__scrollbar","aria-hidden":"true",children:a.jsx("div",{className:"dropdown__scrollbar-thumb",style:{height:_.thumbH,transform:`translateY(${_.thumbTop}px)`},onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),P.current={startY:e.clientY,startTop:_.thumbTop,thumbH:_.thumbH}}})}):null]})]}),document.body)]})}
1export{fe as D};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.