import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/slicedToArray";import l from"@babel/runtime/regenerator";import{useState as n,useEffect as s}from"react";import{ALL_SECTION_KEY as o}from"../constants.js";import{getCoordinatedWells as i}from"../utils/getCoordinatedWells.js";import"geolib";import"../../../utils/convert.js";import"moment";import"../../../utils/index.js";import"lodash";import{partitionSelectedWellIds as c,applyPartitionToOffsetSettings as a}from"./use-save-reset/partitionSelectedWellIds.js";function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);t&&(l=l.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,l)}return r}function u(t){for(var r=1;r<arguments.length;r++){var l=null!=arguments[r]?arguments[r]:{};r%2?d(Object(l),!0).forEach((function(r){e(t,r,l[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(l)):d(Object(l)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(l,e))}))}return t}var f=function(e){var d=e.isAllWellsLoaded,f=e.syncAutoEnabled,p=e.isXtoIdas,b=e.offsetSettings,m=e.externalOffsets,W=e.subjectWellId,v=e.maxOffsetWellNumber,I=e.localMaxOffsetSize,j=e.idasWellIds,O=e.owsWellIds,y=e.wellhubWellIds,h=e.onSave,w=n(!0),g=r(w,2),x=g[0],S=g[1];s((function(){S(!0)}),[W]),s((function(){if(!p&&d){var e=function(){var e=t(l.mark((function e(){var t,r,n,s,d,f,p,w,g,x,S,P,k,D,A;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(m&&null!==W){e.next=2;break}return e.abrupt("return");case 2:if(t=void 0===(null==b?void 0:b.isSynced)||(null==b?void 0:b.isSynced),r=!0,!t){e.next=23;break}if(s=m[o]||[],d=new Set(s),f=((null==b?void 0:b.selectedWellIds)||[]).every((function(e){return d.has(e)})),s.length===(null==b||null===(n=b.selectedWellIds)||void 0===n?void 0:n.length)&&f){e.next=20;break}return e.next=11,i(s,W);case 11:p=e.sent,w=p.slice(0,I+1).map((function(e){return e.id})),g=c({selectedWellIds:w,subjectWellId:null!=W?W:void 0,idasWellIds:j,owsWellIds:O,wellhubWellIds:y}),x=a(u(u({},b),{},{subjectWellId:W,selectedWellIds:w,offsetWellsLimited:v<=w.length}),g),S=new Set(w),P=p.filter((function(e){return S.has(e.id)})),h(x,P),e.next=21;break;case 20:r=!1;case 21:e.next=24;break;case 23:r=!1;case 24:if(r){e.next=31;break}return e.next=27,i((null==b?void 0:b.selectedWellIds)||[],W);case 27:k=e.sent,D=c({selectedWellIds:(null==b?void 0:b.selectedWellIds)||[],subjectWellId:null!=W?W:void 0,idasWellIds:j,owsWellIds:O,wellhubWellIds:y}),A=a(u({},b),D),h(A,k);case 31:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();f&&x&&b&&m&&(e(),S(!1))}}),[b,m,W,v,f,p,d,x,I,j,O,y,h])};export{f as useAutoSyncOffsetWells};
//# sourceMappingURL=useAutoSyncOffsetWells.js.map
