!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={3209:(e,t,r)=>{r.d(t,{mH:()=>o});const o=250},1116:e=>{e.exports=require("@babel/runtime/helpers/defineProperty")},6031:e=>{e.exports=require("@babel/runtime/helpers/extends")},2462:e=>{e.exports=require("@babel/runtime/helpers/objectWithoutProperties")},8619:e=>{e.exports=require("@mui/material")},3294:e=>{e.exports=require("formik")},2015:e=>{e.exports=require("react")}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var l=t[o]={exports:{}};return e[o](l,l.exports,r),l.exports}(()=>{r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t}})(),(()=>{r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})}})(),(()=>{r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var o={};r.r(o),r.d(o,{default:()=>v});var n=r(6031),l=r.n(n),i=r(1116),a=r.n(i),u=r(2462),c=r.n(u),p=r(2015),s=r.n(p),d=r(8619),f=r(3294),m=r(3209);const b=["name","queryFunction","multiple","placeholder","plainValue","hiddenOptions","formatOption","formatSelectedValue","queryParams","isMulti"];function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,o)}return r}function O(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?y(Object(r),!0).forEach((function(t){a()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const v=e=>{let{name:t,queryFunction:r,multiple:o=!1,placeholder:n="Select...",plainValue:i=!1,hiddenOptions:a=[],formatOption:u=e=>({value:e.id.toString(),label:e.name}),formatSelectedValue:y=null,queryParams:v=[],isMulti:h=!1}=e,g=c()(e,b);const[x,P,j]=(0,f.useField)(t),[S,E]=(0,p.useState)([]),[q,k]=(0,p.useState)(!1),[w,T]=(0,p.useState)(""),V=x.value||(o?[]:null),F=P.touched&&P.error,I=async(e="")=>{k(!0);try{await r(e,...v,(e=>{const t=e.filter((e=>!a.includes(e.id))).map(u);E(t),k(!1)}))}catch(e){console.error("Error fetching options:",e),k(!1)}};(0,p.useEffect)((()=>{if(w){const e=setTimeout((()=>{I(w)}),m.mH);return()=>clearTimeout(e)}}),[w]),(0,p.useEffect)((()=>{I("")}),[]);return s().createElement(d.Autocomplete,l()({options:S,value:V,onChange:(e,t)=>{if(!o){const e=i?(null==t?void 0:t.value)||"":t;return void j.setValue(e)}const r=i?t.map((e=>e.value)):t.map((e=>y?y(e):{id:parseInt(e.value),name:e.label}));j.setValue(r)},loading:q,multiple:h,fullWidth:!0,getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.value===t.value,onInputChange:(e,t)=>T(t),renderInput:e=>{var t;return s().createElement(d.TextField,l()({},e,{placeholder:n,variant:"outlined",error:Boolean(F),helperText:F||"",slotProps:{input:O(O({},e.InputProps),{},{endAdornment:s().createElement(s().Fragment,null,q&&s().createElement(d.CircularProgress,{color:"inherit",size:20}),null===(t=e.InputProps)||void 0===t?void 0:t.endAdornment)}),inputLabel:{shrink:!1}},sx:{"& input::placeholder":{color:"#00000061",opacity:1}}}))},renderOption:(e,t,{selected:r})=>s().createElement("li",e,o&&s().createElement(d.Checkbox,{checked:r,sx:{mr:1}}),t.label)},g))};return o})()));
//# sourceMappingURL=async-select.js.map