import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/slicedToArray";import a from"@babel/runtime/regenerator";import o from"prop-types";import{useState as n,useEffect as i}from"react";import{isEqual as s,minBy as m}from"lodash";import p from"./TracesEditModal.js";import{FEED_ITEM_TYPES as c}from"../../constants/feed.js";import{getAppStorage as u}from"../../clients/jsonApi/index.js";import{jsx as d}from"react/jsx-runtime";var f=function(o){var f,l,h,b,y=o.feedItem,D=o.onSave,x=o.onClose,v=o.minDateSec,T=o.maxDateSec,g=o.assetId,C=y.context[c.TRACES_MEMO],M=C.attachment,S=C.timestamp,R={body:C.body,attachment:M},q=n(R),A=r(q,2),N=A[0],E=A[1],j=n(S),I=r(j,2),O=I[0],_=I[1],w=n(C.holeDepth),k=r(w,2),P=k[0],G=k[1],L=n(C.bitDepth),V=r(L,2),z=V[0],B=V[1],F=n(!1),H=r(F,2),J=H[0],K=H[1],Q=(f=O,l=v,h=T,Number.isNaN(f)?"Can't parse date or time format":f<l||f>h?"Should be in range of available traces data":""),U=Number.isNaN(O)||!N.body&&!N.attachment||S===O&&s(R,N),W=(b=t(a.mark((function e(t){var r,o,n,i;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t+5,o="{timestamp#gte#".concat(t-5,"}AND{timestamp#lte#").concat(r,"}"),K(!0),e.prev=4,e.next=7,u("corva","wits",g,{limit:10,query:o});case 7:n=e.sent,i=n&&m(n,(function(e){return Math.abs(e.timestamp-t)})),G(i.data.hole_depth),B(i.data.bit_depth),e.next=16;break;case 13:e.prev=13,e.t0=e.catch(4),console.error(e.t0);case 16:K(!1);case 17:case"end":return e.stop()}}),e,null,[[4,13]])}))),function(e){return b.apply(this,arguments)});return i((function(){O&&!Q&&S!==O&&W(O)}),[Q,O,S]),d(p,{postValue:N,onPostChange:E,timestampMs:1e3*O,timestampError:Q,minDateMs:1e3*v,maxDateMs:1e3*T,isDepthDataLoading:J,isApplyDisabled:U,holeDepth:P,bitDepth:z,userCompanyId:y.company_id,onTimestampChange:function(e){_(e.unix())},onApply:function(){return D({context:e({},c.TRACES_MEMO,{body:N.body,attachment:N.attachment,timestamp:O,holeDepth:P,bitDepth:z})})},onClose:x})};f.propTypes={feedItem:o.shape().isRequired,onSave:o.func.isRequired,onClose:o.func.isRequired,minDateSec:o.oneOfType([o.number,o.string]).isRequired,maxDateSec:o.oneOfType([o.number,o.string]).isRequired,assetId:o.oneOfType([o.number,o.string]).isRequired};export{f as default};
//# sourceMappingURL=TracesEditModalContainer.js.map
