import{r as o,D as x,j as a,bC as z,d as b,z as v,bD as A}from"./index-Cziemgsu.js";const P=({value:E,options:i,onChange:y,id:S,name:h,disabled:d,success:u,error:r,help:m,wrapperClassName:j,toggleClassName:C,dropdownClassName:_,searchable:w="auto",takeFocus:f,header:B,selectRef:N,initialPosition:O="left",...D})=>{const[l,s]=o.useState(!1),c=o.useId(),L=o.useId(),t=S||L,p=o.useId(),g=!!r;x("visibilitychange",()=>{document.visibilityState==="hidden"&&s(!1)}),x("blur",()=>{s(!1)},window),o.useImperativeHandle(N,()=>({open:()=>{var e;s(!0),(e=document.getElementById(t))==null||e.focus()},focus:()=>{var e;return(e=document.getElementById(t))==null?void 0:e.focus()},close:s.bind(null,!1),isOpen:l}),[l]),o.useEffect(()=>{if(f){const e=document.getElementById(t);e==null||e.focus()}},[f]);const I=i.find(e=>e.value===E),M=a.jsx("span",{className:"toggle-label u-truncate",children:I?z(I):"Select an option"}),T=e=>{var n;(n=document.getElementById(t))==null||n.focus(),s(!1),y(e)};return a.jsx(b.Field,{...D,className:v("p-custom-select",j),error:r,forId:t,help:m,helpId:p,isSelect:!0,success:u,validationId:c,children:a.jsx(b.ContextualMenu,{"aria-describedby":[m?p:null,u?c:null].filter(Boolean).join(" "),"aria-errormessage":g?c:void 0,"aria-invalid":g,toggleClassName:v("p-custom-select__toggle","p-form-validation__input",C,{active:l}),toggleLabel:M,visible:l,onToggleMenu:e=>{e!==l&&s(e)},toggleProps:{id:t,disabled:d,tabIndex:d?-1:0},className:"p-custom-select__wrapper",dropdownClassName:_,style:{width:"100%"},autoAdjust:!0,position:O,children:e=>a.jsx(A,{searchable:w,name:h||"",options:i||[],onSelect:T,onClose:()=>{var n;e(),(n=document.getElementById(t))==null||n.focus()},header:B,toggleId:t})})})};export{P as C};
