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