!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")},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:()=>b});var n=r(6031),l=r.n(n),a=r(1116),i=r.n(a),u=r(2015),c=r.n(u),p=r(8619),s=r(3294),d=r(3209);function f(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 m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){i()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const b=({name:e,queryFunction:t,multiple:r=!1,placeholder:o="Select...",plainValue:n=!1,hiddenOptions:a=[],formatOption:i=e=>({value:e.id.toString(),label:e.name}),formatSelectedValue:f=null,queryParams:b=[],isMulti:y=!1})=>{const[v,O,h]=(0,s.useField)(e),[g,x]=(0,u.useState)([]),[j,P]=(0,u.useState)(!1),[S,E]=(0,u.useState)(""),k=v.value||(r?[]:null),q=O.touched&&O.error,w=async(e="")=>{P(!0);try{await t(e,...b,(e=>{const t=e.filter((e=>!a.includes(e.id))).map(i);x(t),P(!1)}))}catch(e){console.error("Error fetching options:",e),P(!1)}};(0,u.useEffect)((()=>{if(S){const e=setTimeout((()=>{w(S)}),d.mH);return()=>clearTimeout(e)}}),[S]),(0,u.useEffect)((()=>{w("")}),[]);return c().createElement(p.Autocomplete,{options:g,value:k,onChange:(e,t)=>{if(!r){const e=n?(null==t?void 0:t.value)||"":t;return void h.setValue(e)}const o=n?t.map((e=>e.value)):t.map((e=>f?f(e):{id:parseInt(e.value),name:e.label}));h.setValue(o)},loading:j,multiple:y,fullWidth:!0,getOptionLabel:e=>e.label||"",isOptionEqualToValue:(e,t)=>e.value===t.value,onInputChange:(e,t)=>E(t),renderInput:e=>{var t;return c().createElement(p.TextField,l()({},e,{placeholder:o,variant:"outlined",error:Boolean(q),helperText:q||"",slotProps:{input:m(m({},e.InputProps),{},{endAdornment:c().createElement(c().Fragment,null,j&&c().createElement(p.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:o})=>c().createElement("li",e,r&&c().createElement(p.Checkbox,{checked:o,sx:{mr:1}}),t.label)})};return o})()));
//# sourceMappingURL=async-select.js.map