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