(this["webpackJsonpgonzo-test-client"]=this["webpackJsonpgonzo-test-client"]||[]).push([[81],{zx8b:function(e,t,n){"use strict";var a=n("UB5X"),s=n.n(a),i=n("q1tI"),r=n.n(i),c=n("/MKj"),l=n("e/I0"),o=n("tbNj"),m=n("zDJl"),u=n("VyNe"),p=n("BbMY"),d=n("erjJ"),h=n("y6dH"),b=n("/wPd"),g=n("uSQv"),f=n("3Z9Z"),E=n("JI6e"),w=n("tDQA"),v=n("d/v1"),I=n("3t43"),S=n("pJVQ"),C=n("4huo"),D=n("02dk"),y=n("kCVf"),O=n("0MVo"),j=n("mwIZ"),N=n.n(j),x=n("vzZS"),k=n("MeEv"),M=n.n(k),L=n("qzmO"),F=n("ANjH"),P=n("f0zD"),z=n("LCzB");class U extends r.a.Component{constructor(...e){super(...e),this.seconds=Math.floor(this.props.time/1e3),this.state={running:!1},this.setRunning=()=>{this.setState({running:!0})},this.stopRunning=()=>{this.setState({running:!1})},this.start=({DevID:e,useImpulse:t}={})=>{const{time:n,impulses:a}=this.props;e&&(t?Object(L.F)(e,{impulses:a},{onSuccess:this.handleEnd,onFailure:this.stopRunning}):Object(L.E)(e,{time:n},{onSuccess:this.setRunning,onFailure:this.stopRunning}))},this.stop=({DevID:e,useImpulse:t}={})=>{e&&Object(L.H)(e,{onSuccess:this.setRunning,onFailure:this.stopRunning})},this.handleEnd=()=>{this.setState({running:!1})},this.toggleStart=()=>{const{running:e}=this.state,{device:t,useImpulse:n}=this.props;t&&(e?this.stop({DevID:t.DevID,useImpulse:n}):this.start({DevID:t.DevID,useImpulse:n}))}}componentDidUpdate(e,t,n){const{device:a}=this.props,{running:s}=this.state,i=N()(e.device,"DevID");i!==N()(a,"DevID")&&i&&s&&this.stop({DevID:i,useImpulse:e.useImpulse})}render(){const{seconds:e}=this,{running:t}=this.state,{children:n,t:a,device:s}=this.props;return r.a.createElement("div",null,!!t&&r.a.createElement(x.a,{boxColor:"info"},r.a.createElement(M.a,{backward:!0,seconds:e,showHours:!1,showMinutes:!1,label:a("newSettings.feeding.waterCalibration.testWater.running"),endLabel:" s",callback:this.handleEnd})),n,r.a.createElement(g.a,{className:"w-100",type:"button",disabled:!s,onClick:this.toggleStart},a("newSettings.feeding.waterCalibration.testWater.".concat(t?"stop":"start"))))}}U.defaultProps={time:5e3,impulses:400,useImpulse:!1},U=Object(c.connect)(null,e=>Object(F.b)({show:P.d},e))(U);var R=Object(z.a)()(U),T=n("IXwn"),A=n("I8zd"),B=n("Ty5D"),J=n("p7iN");const H="settings-feeding-water-calibration-destination",V=Object(w.a)(H);class X extends i.Component{constructor(e){super(e),this.onChange=(e="device")=>{const{change:t}=this.props;t("type",e)};const{initialize:t}=this.props;t({type:"device"})}render(){const{device:e,chamber:t,type:n,handleSubmit:a,submitting:s,t:i}=this.props,c=12/(+!!e+1+ +!!t);return r.a.createElement("form",{onSubmit:a},i("newSettings.feeding.waterCalibration.chooseDestination"),r.a.createElement(f.a,null,!!e&&r.a.createElement(E.a,{className:"pointer",lg:c,onClick:()=>this.onChange("device")},r.a.createElement(u.a,{shadow:!1,className:"h-100",selected:"device"===n},r.a.createElement("h5",null," ",i("newSettings.feeding.waterCalibration.setOnDevice")),r.a.createElement("div",{className:"opacity-50 text-wrap"},e.Name))),!!t&&r.a.createElement(E.a,{className:"pointer",lg:c,onClick:()=>this.onChange("chamber")},r.a.createElement(u.a,{shadow:!1,className:"h-100",selected:"chamber"===n},r.a.createElement("h5",null," ",i("newSettings.feeding.waterCalibration.setOnChamber")),r.a.createElement("div",{className:"opacity-50 text-wrap"},t.name.join(" - ")||"?"))),r.a.createElement(E.a,{className:"pointer",lg:c,onClick:()=>this.onChange("all")},r.a.createElement(u.a,{shadow:!1,className:"h-100",selected:"all"===n},r.a.createElement("h5",null," ",i("newSettings.feeding.waterCalibration.setOnAll")),r.a.createElement("div",{className:"opacity-50 text-wrap"},i("newSettings.feeding.waterCalibration.setOnAllText"))))),r.a.createElement(T.a,{fixed:!0,renderInPortal:!1},r.a.createElement(g.a,{isLoading:s,buttonStyle:"round",buttonColor:"success",icon:r.a.createElement("i",{className:"fas fa-plus"})})))}}X=Object(S.a)({form:H,onSubmit:(e,t,n)=>{const{device:a,chamber:s,efficiency:i,useImpulse:r,farm:c,history:l}=n,{type:o}=e,m={Efficiency:+i,Type:+r};switch(o){case"all":m.AllDevices=!0;break;case"chamber":m.PlcmntIDs=[s.id];break;case"device":m.DevIDs=[a.DevID];break;default:console.error("this should not happen")}return Object(J.a)(m).then(e=>{Object(J.c)(e),l.push("/".concat(c,"/settings"))}).catch(e=>{Object(J.b)(e)})},destroyOnUnmount:!0,forceUnregisterOnUnmount:!0})(X),X=Object(c.connect)((function(e,t){const n={DevID:t.DevID};t.placementId&&(n.level=A.a.CHAMBER,n.id=t.placementId);const a=Object(o.b)(),s=Object(l.b)();return function(e,t){return{farm:e.location.farm,device:a(e,n),chamber:s(e,n),type:V(e,"type"),actions:V(e,"actions")}}}))(X),X=Object(B.o)(X);var Z=Object(z.a)()(X),q=n("XoCd"),Q=n("udB/"),W=n("XM6k"),G=n("pxzG"),K=n("eASP");const Y="settings-feeding-water-calibration-form",_=Object(w.a)(Y);class $ extends i.Component{constructor(e){super(e),this.state={step:1},this.handleStepClick=(e=1)=>{this.setState({step:e})},this.onNext=()=>{this.setState(e=>({step:e.step+1}))},this.button=()=>{const{dispenser:e,efficiencyList:t,useImpulse:n,initialized:a}=this.props,{step:i}=this.state,c=a?t.reduce((e,t)=>(e||0)+(t||0),0)/Math.max(1,t.length):0,l=n?this.convertToImpulsesPerLiter(c):this.convertToLitersPer60Seconds(c),o=!![!1,!e,!1,!s()(l)||l<=0][i-1];return r.a.createElement(T.a,{fixed:!0},r.a.createElement(g.a,{buttonColor:"success",buttonStyle:"round",disabled:o,icon:r.a.createElement("i",{className:"fas fa-arrow-right"}),onClick:this.onNext}))},this.options=()=>{const{dispensers:e,buildingsMap:t,useImpulse:n}=this.props,a=[];return e.forEach(e=>{const s=Object(y.m)({device:e});if(1===s.length){const i="".concat(Object(y.l)(t,s[0])," | ").concat(Object(O.e)(e.Address));e.hasWater()&&(!n||n&&e.hasFlowMeter())&&a.push({name:i,value:{DevID:e.DevID,placementId:s[0],name:i}})}}),a},this.convertToLitersPer60Seconds=e=>4*e,this.convertToImpulsesPerLiter=e=>Math.round(400/Math.max(1,e)*1e3),this.formatter=e=>Object(G.h)(e,{unit:K.a.MEDIUM,fixed:2,showUnit:!0}),this.efficiencyFormatter=e=>{const{useImpulse:t,t:n}=this.props;return t?n("newSettings.feeding.waterCalibration.efficiencyPerLiter",{impulses:this.convertToImpulsesPerLiter(e)}):n("newSettings.feeding.waterCalibration.efficiencyPer60Seconds",{efficiency:Object(G.h)(this.convertToLitersPer60Seconds(e),{unit:K.a.MEDIUM,fixed:2,showUnit:!0})})},this.renderEfficiency=({fields:e,efficiency:t,meta:{touched:n,error:a,submitFailed:s}})=>{const{t:i}=this.props;return r.a.createElement(r.a.Fragment,null,e.map((e,t)=>r.a.createElement(v.a,{name:e,id:e,label:i("newSettings.feeding.waterCalibration.measurement",{number:t+1}),component:q.a,min:0,valueFormatter:this.formatter,max:15e3,step:10})),i("newSettings.feeding.waterCalibration.averageEfficiency",{efficiency:this.efficiencyFormatter(t),count:e.length}),r.a.createElement(f.a,null,r.a.createElement(E.a,{lg:6},r.a.createElement(g.a,{onClick:()=>e.length>1&&e.remove(e.length-1),type:"button",disabled:e.length<=1,className:"w-100 mb-0",buttonStyle:"text",buttonColor:"error",icon:r.a.createElement("i",{className:"fas fa-trash"})},i("newSettings.feeding.waterCalibration.deleteLast"))),r.a.createElement(E.a,{lg:6},r.a.createElement(g.a,{onClick:()=>e.push(0),type:"button",className:"w-100 mb-0",buttonStyle:"text",icon:r.a.createElement("i",{className:"fas fa-plus"})},i("newSettings.feeding.waterCalibration.newMeasurement")))))};const{initialize:t}=this.props;t({efficiencyList:[0]})}componentDidUpdate(e,t,n){const{change:a,useImpulse:s}=this.props;e.useImpulse!==s&&a("dispenser",null)}render(){const{t:e,dispenser:t,initialized:n,efficiencyList:a,useImpulse:s}=this.props,i=n?a.reduce((e,t)=>(e||0)+(t||0),0)/Math.max(1,a.length):0,c=s?this.convertToImpulsesPerLiter(i):this.convertToLitersPer60Seconds(i)/2,{step:l}=this.state,o=this.options(),m=()=>r.a.createElement("svg",{viewBox:"0 0 270.93334 270.93334"});return r.a.createElement("div",null,r.a.createElement(Q.a,{isLoading:!n}),r.a.createElement(u.a,null,r.a.createElement(p.a,{activeStep:l,onClickStep:this.handleStepClick},r.a.createElement(r.a.Fragment,null,r.a.createElement(d.a,{label:e("newSettings.feeding.waterCalibration.beginning")}),r.a.createElement(d.a,{label:e("newSettings.feeding.waterCalibration.chooseDispenser")}),r.a.createElement(d.a,{label:e("newSettings.feeding.waterCalibration.prepareDispenser")}),r.a.createElement(d.a,{label:e("calibration")}),r.a.createElement(d.a,{label:e("summary")}))),1===l&&r.a.createElement(r.a.Fragment,null,r.a.createElement("div",{className:"calibration"},r.a.createElement("div",{className:"calibration-container"},r.a.createElement(h.a,{src:b.a,loading:m})),r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.prepareBucketAndScale")),this.button())),2===l&&r.a.createElement(r.a.Fragment,null,r.a.createElement(f.a,{className:"justify-content-center"},r.a.createElement(E.a,{lg:6},r.a.createElement(R,{useImpulse:s,impulses:40,device:t||void 0,time:3e3},r.a.createElement(v.a,{name:"useImpulse",id:"useImpulse",label:e("newSettings.feeding.waterCalibration.useImpulse"),options:o,component:W.a}),r.a.createElement(v.a,{name:"dispenser",id:"dispenser",required:!0,label:e("location"),options:o,component:C.b}),s?r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.testRunImpulse",{count:40})):r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.testRun",{count:Math.floor(3)}))))),this.button()),3===l&&r.a.createElement(r.a.Fragment,null,r.a.createElement("div",{className:"calibration"},r.a.createElement("div",{className:"calibration-container"},r.a.createElement(h.a,{src:D.a,loading:m})),r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.putBucketUnderPipe")),this.button())),4===l&&r.a.createElement(r.a.Fragment,null,r.a.createElement(f.a,{className:"justify-content-center"},r.a.createElement(E.a,{lg:6},r.a.createElement(R,{useImpulse:s,impulses:400,device:t||void 0,time:15e3},s?r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.runCalibrationImpulse",{count:400})):r.a.createElement("p",null,e("newSettings.feeding.waterCalibration.runCalibration",{count:Math.floor(15)}))),r.a.createElement(I.a,{efficiency:i,component:this.renderEfficiency,name:"efficiencyList",rerenderOnEveryChange:!0}),this.button()))),5===l&&!!t&&!!c&&r.a.createElement(r.a.Fragment,null,r.a.createElement(Z,{useImpulse:!!s,efficiency:c,DevID:t.DevID,placementId:t.placementId}))))}}$=Object(S.a)({form:Y,destroyOnUnmount:!0,forceUnregisterOnUnmount:!0})($),$=Object(c.connect)((function(){return function(e){const t=Object(o.c)();return{dispenser:_(e,"dispenser"),efficiencyList:_(e,"efficiencyList"),useImpulse:_(e,"useImpulse"),buildingsMap:Object(l.a)(e),dispensers:t(e,{DevType:[m.d.DISPENSER_NRF]})}}}))($);t.a=Object(z.a)()($)}}]); //# sourceMappingURL=main~bf9dda47.49681760.chunk.js.map