"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("@babel/runtime/helpers/defineProperty"),r=require("@babel/runtime/helpers/asyncToGenerator"),s=require("@babel/runtime/helpers/slicedToArray"),n=require("@babel/runtime/regenerator"),a=require("react"),u=require("lodash"),i=require("../utils/index.js");require("uuid"),require("lodash/set"),require("lodash/get"),require("lodash/unset"),require("moment");var o=require("../../../clients/jsonApi/index.js");require("../../../clients/subscriptions.js"),require("../../../clients/api/apiCore.js"),require("../../../clients/constants.js"),require("../../../clients/sso/auth0.js"),require("../../../clients/sso/oauth2.js");var c=require("../../../utils/jsonaDataFormatter.js");require("../../../constants/goals.js"),require("../../../constants/segment.js"),require("../../../constants/alerts.js"),require("../../../constants/apps.js"),require("../../../constants/drillstring.js"),require("../../../constants/completion.js"),require("../../../constants/appPackages.js"),require("../../../constants/notifications.js"),require("../../../constants/feed.js"),require("../../../constants/bha.js");var l=require("../../../constants/assetTypes.js");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("../../../utils/env.js"),require("../../GradientManager/configuration/constants.js");var d=p(e),f=p(t),q=p(r),y=p(s),j=p(n);function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,s)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){f.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}exports.usePrimaryAssetSelectData=function(e){var t,r=e.appKey,s=e.assetType,n=e.company,p=e.groups,f=e.isRequiredAssetId,m=e.parentAssetId,v=e.parentAssetType,h=e.searchText,g=e.assetFields,A=e.currentValue,O=e.setCurrentOption,P=e.onActiveAssetIdChange,S=a.useState([]),I=y.default(S,2),T=I[0],x=I[1],E=a.useState(!1),_=y.default(E,2),w=_[0],D=_[1],R=a.useRef(null),k=(t=q.default(j.default.mark((function e(t){var a,p,q,y,S,I,T,E;return j.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,a=(null==t?void 0:t.type)||s,D(!0),p={per_page:1e4},v&&m&&(p[v]=m),n&&"all"!==n&&(p.company=n),h&&(p.search=h),r&&(p.app_key=r),R.current=n,q=a===l.ASSET_TYPES.pad.type?[].concat(d.default(g),["pad.active","pad.parent_frac_fleet_id","pad.current"]):g,y=o.mapAssetGetRequest(a)(b(b({},i.getRequestOptions(a,q)),p)),e.next=13,y;case 13:S=e.sent,I=c.jsonaDataFormatter.deserialize(S),T=I.map((function(e){return i.formatAsset({asset:e,group:null==t?void 0:t.name,isRequiredAssetId:f,isPrimaryAsset:!0})})).filter(Boolean).sort(i.sortAsset),R.current===n&&x((function(e){return[].concat(d.default(e),d.default(T))})),A&&a===s&&(E=T.find((function(e){return A===e.id||e.assetId&&A===e.assetId})),u.isEmpty(E)||O(E),a===l.ASSET_TYPES.rig.type&&P(null==E?void 0:E.activeWellId)),e.next=23;break;case 20:e.prev=20,e.t0=e.catch(0),console.error(e.t0);case 23:return e.prev=23,D(!1),e.finish(23);case 26:case"end":return e.stop()}}),e,null,[[0,20,23,26]])}))),function(e){return t.apply(this,arguments)});return a.useEffect((function(){n&&x([])}),[n]),a.useEffect((function(){p?p.forEach((function(e){k(e)})):k()}),[s,v,m,n,r,null==p?void 0:p.length]),{assets:T,loading:w}},exports.useSecondaryAssetSelectData=function(e){var t=e.appKey,r=e.assetType,s=e.assetId,n=e.company,u=e.parentAssetType,l=e.parentAssetId,p=e.queryParams,d=e.assetFields,m=e.activeWellId,v=e.isRequiredAssetId,h=a.useState([]),g=y.default(h,2),A=g[0],O=g[1],P=a.useState(!0),S=y.default(P,2),I=S[0],T=S[1];return a.useEffect((function(){function e(){return(e=q.default(j.default.mark((function e(){var s,a;return j.default.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.mapAssetGetRequest(r)(b(b(b({},i.getRequestOptions(r,d)),{},f.default({per_page:1e4,company:"all"!==n?n:null},u,l),t&&{app_key:t}),p));case 2:s=e.sent,a=c.jsonaDataFormatter.deserialize(s),O(a.map((function(e){return i.formatAsset({asset:e,activeWellId:m,isRequiredAssetId:v})})).sort(i.sortAsset)),T(!1);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}T(!0),function(){e.apply(this,arguments)}()}),[r,s,u,l,t,m,n]),{assets:A,loading:I}};
