import t from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/asyncToGenerator";import e from"@babel/runtime/helpers/toConsumableArray";import n from"@babel/runtime/helpers/slicedToArray";import s from"@babel/runtime/regenerator";import{useState as o,useRef as i,useEffect as a}from"react";import{map as c,isEmpty as p,uniqBy as l}from"lodash";import{formatAsset as u,sortAsset as m,getRequestOptions as d}from"../utils/index.js";import"uuid";import"lodash/set";import"lodash/get";import"lodash/unset";import"moment";import{mapAssetGetRequest as f,getAssets as j}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";import{jsonaDataFormatter as b}from"../../../utils/jsonaDataFormatter.js";import{PER_PAGE as y}from"../../AssetEditor/constants.js";import"../../../constants/goals.js";import"../../../constants/segment.js";import"../../../constants/alerts.js";import"../../../constants/apps.js";import"../../../constants/drillstring.js";import"../../../constants/completion.js";import"../../../constants/appPackages.js";import"../../../constants/notifications.js";import"../../../constants/feed.js";import"../../../constants/bha.js";import{ASSET_TYPES as v}from"../../../constants/assetTypes.js";import"../../../constants/corvaCompanyId.js";import"../../GradientManager/configuration/constants.js";function g(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function h(r){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){t(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function O(t){var g,O,A=t.appKey,P=t.assetType,w=t.company,x=t.groups,D=t.isRequiredAssetId,I=t.parentAssetId,k=t.parentAssetType,_=t.searchValue,C=t.assetFields,T=t.currentValue,E=t.setCurrentOption,q=t.scrollPage,R=t.onActiveAssetIdChange,z=t.isDrillingPlatformApp,F=o([]),G=n(F,2),S=G[0],V=G[1],W=o(!1),K=n(W,2),L=K[0],M=K[1],N=i(null),B=i(null),H=i(null),J=i(null),Q=P===v.pad.type?[].concat(e(C),["pad.active","pad.parent_frac_fleet_id"]):C,U=(g=r(s.mark((function t(r){var n,o,i,a,p,j,v,g=arguments;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=g.length>1&&void 0!==g[1]&&g[1],t.prev=1,o=(null==r?void 0:r.type)||P,M(!0),i={per_page:y,page:q},k&&I&&(i[k]=I),w&&"all"!==w&&(i.company=w),_&&(i.search=_),A&&(i.app_key=A),N.current=w,a=f(o)(h(h({},d(o,Q)),i)),t.next=13,a;case 13:p=t.sent,j=b.deserialize(p),v=c(j,(function(t){return u({asset:t,group:null==r?void 0:r.name,isRequiredAssetId:D,isPrimaryAsset:!0,isDrillingPlatformApp:z})})).sort(m),N.current===w&&V(n?function(t){return l([].concat(e(t),e(v)),"id")}:v),t.next=22;break;case 19:t.prev=19,t.t0=t.catch(1),console.error(t.t0);case 22:return t.prev=22,M(!1),t.finish(22);case 25:case"end":return t.stop()}}),t,null,[[1,19,22,25]])}))),function(t){return g.apply(this,arguments)}),X=(O=r(s.mark((function t(){var r,e,n,o,i,a,c,l;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,f(P)(h(h({},d(P,Q)),{},{ids:T}));case 2:if(r=t.sent,!p(r.data)){t.next=7;break}return t.next=6,j(h(h({},d(P,Q)),{},{ids:T}));case 6:r=t.sent;case 7:e=b.deserialize(r),n=u({asset:e[0],isPrimaryAsset:!0,isRequiredAssetId:D,isDrillingPlatformApp:z}),E(n),P===v.rig.type?(c=z?Number(null===(o=r)||void 0===o||null===(i=o.included)||void 0===i||null===(a=i[0])||void 0===a?void 0:a.id):(null==n?void 0:n.activeWellId)||null,R(c)):P===v.intervention_unit.type&&(l=(null==n?void 0:n.activeWellId)||null,R(l));case 11:case"end":return t.stop()}}),t)}))),function(){return O.apply(this,arguments)});return a((function(){w&&V([])}),[w]),a((function(){var t=H.current!==_,r=J.current!==q,e=!t&&r&&q>1&&(J.current||0)<q;t&&(H.current=_),r&&(J.current=q),x?x.forEach((function(t){U(t,e)})):(P&&B.current&&B.current!==P&&V([]),B.current=P,U(null,e))}),[P,k,I,w,A,null==x?void 0:x.length,_,q]),a((function(){T&&X()}),[]),{assets:S,loading:L}}export{O as usePrimaryAssetSelectData};
//# sourceMappingURL=usePrimaryAssetSelectData.js.map
