import t from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/helpers/defineProperty";import n from"@babel/runtime/helpers/toConsumableArray";import s from"@babel/runtime/regenerator";import{useState as a,useEffect as o,useRef as i}from"react";import{isEmpty as c}from"lodash";import{PER_PAGE as p}from"../constants.js";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import{mapAssetGetRequest as u,getAssets as l}from"../../../clients/jsonApi/index.js";import"../../../clients/subscriptions/constants.js";import"../../../clients/subscriptions.v1.js";import"../../../clients/subscriptions/subscriptions-client.factory.js";import"../../../clients/api/apiCore.js";import"../../../clients/constants.js";import"../../../clients/sso/auth0.js";import"../../../clients/sso/oauth2.js";import"../../../clients/api/rateLimiter.js";function m(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function f(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?m(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var d=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return{sort:"name",order:"asc",fields:["".concat(t,".name"),"".concat(t,".asset_id")].concat(n(e))}},b=function(t){var e,r,n;return f(f({},t.attributes),{},{id:+t.id,programId:+(null===(e=t.relationships)||void 0===e||null===(r=e.program)||void 0===r||null===(n=r.data)||void 0===n?void 0:n.id)})};function y(n){var i=n.appKey,c=n.assetType,p=n.assetId,l=n.parentAssetType,m=n.parentAssetId,y=n.queryParams,h=void 0===y?null:y,v=a([]),j=e(v,2),g=j[0],O=j[1],x=a(!0),w=e(x,2),P=w[0],k=w[1];return o((function(){function e(){return(e=t(s.mark((function t(){var e;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u(c)(f(f(f({},d(c)),{},r({per_page:1e4},l,m),i&&{app_key:i}),h));case 2:e=t.sent,O(e.data.map(b)),k(!1);case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}k(!0),function(){e.apply(this,arguments)}()}),[c,p,l,m,i]),{assets:g,loading:P}}function h(r){var n=r.appKey,m=r.assetType,y=r.companyId,h=r.currentValue,v=r.isMultiple,j=r.parentAssetId,g=r.parentAssetType,O=r.scrollPage,x=r.searchText,w=r.setCurrentOption,P=r.queryParams,k=r.assetFields,A=a([]),T=e(A,2),I=T[0],_=T[1],D=a(!1),C=e(D,2),q=C[0],E=C[1],K=i(),S=i();return o((function(){function e(){return(e=t(s.mark((function t(){var e;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u(m)(f(f({},d(m,k)),{},{ids:v?h:[h]},P));case 2:if(e=t.sent,!c(e.data)){t.next=7;break}return t.next=6,l(f(f({},d(m,k)),{},{ids:v?h:[h]},P));case 6:e=t.sent;case 7:w((function(){if(v)return e.data.map(b);var t=e.data[0];return t?b(t):null}));case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}(v?h.length:h)&&function(){e.apply(this,arguments)}()}),[]),o((function(){function e(){return(e=t(s.mark((function t(){var e,r,a,o,i;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,E(!0),e={per_page:p,page:O},g&&j&&(e[g]=j),y&&(e.company=y),x&&(e.search=x),n&&(e.app_key=n),r=u(m)(f(f(f({},d(m,k)),e),P)),S.current=r,t.next=11,r;case 11:if(a=t.sent,S.current===r){t.next=14;break}return t.abrupt("return");case 14:o=a.data.map(b),i=K.current!==m||1===O,_(i?o:function(t){return t.concat(o)}),K.current=m,t.next=23;break;case 20:t.prev=20,t.t0=t.catch(0),console.error(t.t0);case 23:E(!1);case 24:case"end":return t.stop()}}),t,null,[[0,20]])})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[m,g,j,y,x,O,n]),{assets:I,loading:q}}export{h as useAssetAutoCompleteSelectData,y as useAssetSelectData};
//# sourceMappingURL=index.js.map
