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