import e from"@babel/runtime/helpers/objectWithoutProperties";import t from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/slicedToArray";import{jsxs as o,jsx as n}from"react/jsx-runtime";import{memo as i,useState as a,useEffect as l,useMemo as s,useCallback as p}from"react";import c from"classnames";import{makeStyles as u}from"@material-ui/core";import{sortBy as d}from"lodash";import{Search as m}from"../Search/Search.js";import{mapAssetGetRequest as f}from"../../clients/jsonApi/index.js";import"../../utils/index.js";import b from"../../effects/useLoadedData.js";import{jsonaDataFormatter as h}from"../../utils/jsonaDataFormatter.js";var g=["listbox","paper"];function v(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 r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?v(Object(o),!0).forEach((function(r){t(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):v(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}var j=u((function(e){return{listbox:{maxHeight:360},paper:{width:364},footer:{fontSize:12,color:e.palette.primary.text6,lineHeight:"16.872px",padding:"8px 16px"}}})),y=function(e){var t;return{data:h.deserialize(e.data),total:Number(null===(t=e.headers)||void 0===t?void 0:t.get("total"))||0}},x=[],P={},S={data:[],total:0},D=i((function(t){var i=t.selectedAssets,u=void 0===i?x:i,h=t.onChange,v=t.label,D=t.className,w=t.type,C=t.customRequestQueryParams,F=t.classes,A=void 0===F?{}:F,E=j(),I=b({loadFn:f(w,!0),initialData:S,getDataFromResponseFn:y,isCacheEnabled:!0}),N=I.isLoading,z=I.setIsLoading,H=I.data,L=I.loadData,R=null!=H?H:S,k=R.data,T=R.total,q=a(""),Q=r(q,2),W=Q[0],_=Q[1];l((function(){J("",C)}),[]);var B=s((function(){return u.map((function(e){return O(O({},e),{},{id:e.id,label:e.name})}))}),[u]),G=s((function(){var e={};return(B.length?k.concat(B):k).forEach((function(t){e[t.id]=O(O({},t),{},{id:t.id,label:t.name})})),Object.values(d(e,"label"))}),[k,u,W]),J=p((function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=O(O(O({},P),{},{per_page:50},t),{},{fields:["".concat(w,".name")].concat((null==t?void 0:t.fields)||[])});L(O({search:e},r))}),[]),K=function(){_(""),J("",C)},M=s((function(){var e,t=0===(e=T-(null==k?void 0:k.length))?null:e;return t&&!N&&W?o("div",{className:E.footer,children:[t," additional items not displayed. Continue typing for more refined results."]}):null}),[k,N,!!W,T]),U=A.listbox,V=A.paper,X=e(A,g);return n(m,{value:B,onChange:function(e,t,r){if("reset"!==r){var o=t.map((function(e){return O(O({},e),{},{name:e.label})}));h(o)}},TextFieldProps:{label:v},className:D,classes:O({listbox:c(E.listbox,U),paper:c(E.paper,V)},X),loading:N,options:G,placeholder:"",multiple:!0,filterSelectedOptions:!1,AutocompleteProps:{forcePopupIcon:!0},isHiddenAllOption:!0,onInputChangeCallback:function(e,t){"reset"!==t&&""!==e?e.trimStart()!==W&&(_(e.trimStart()),z(!0),J(e.trimStart(),C)):K()},onInputReset:K,paperFooter:M,getOptionSelected:function(e,t){return+e.id==+t.id},isPrioritizedSelectedOptions:!0})}));export{D as default};
//# sourceMappingURL=AssetsMultipleSelector.js.map
