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