import r from"@babel/runtime/helpers/slicedToArray";import{useState as t,useCallback as o,useEffect as e}from"react";import{isEmpty as n,sortBy as i,isEqual as u}from"lodash";import{getFormattedOptions as p}from"../utils/getFormattedOptions.js";var s=function(s){var a=s.value,l=s.options,m=s.groups,c=s.selectedGroup,d=s.isPrioritizedSelectedOptions,f=t(l),h=r(f,2),v=h[0],g=h[1],A=(null==l?void 0:l.some((function(r){return r.group})))||!n(m),O=p(l,A,c),y=o((function(r){if(!Array.isArray(r))return O;var t=new Set(r.map((function(r){return r.id})));return i(O,(function(r){return!t.has(r.id)}))}),[O.length]);return e((function(){d?g(y(a)):u(O,v)||g(O)}),[O]),{autocompleteOptions:v,handleAutocompleOptionsUpdate:function(){d&&g(y(a))},isGrouped:A}};export{s as useAutocompletOptions};
