/*! For license information please see main.35586cd8.chunk.js.LICENSE.txt */ (this["webpackJsonplanddiary-client"]=this["webpackJsonplanddiary-client"]||[]).push([[3],{105:function(e){e.exports=JSON.parse('[{"countryName":"South Africa","countryShortCode":"ZA","locale":"en-ZA","regions":[{"name":"Eastern Cape","shortCode":"EC"},{"name":"Free State","shortCode":"FS"},{"name":"Gauteng","shortCode":"GT"},{"name":"KwaZulu-Natal","shortCode":"NL"},{"name":"Limpopo","shortCode":"LP"},{"name":"Mpumalanga","shortCode":"MP"},{"name":"Northern Cape","shortCode":"NC"},{"name":"North West","shortCode":"NW"},{"name":"Western Cape","shortCode":"WC"},{"name":"Unknown","shortCode":"Unknown"}]},{"countryName":"Eswatini","countryShortCode":"SZ","regions":[{"name":"Hhohho","shortCode":"HH"},{"name":"Lubombo","shortCode":"LU"},{"name":"Manzini","shortCode":"MA"},{"name":"Shiselweni","shortCode":"SH"}]},{"countryName":"Malawi","countryShortCode":"MW","regions":[{"name":"Balaka","shortCode":"BA"},{"name":"Blantyre","shortCode":"BL"},{"name":"Chikwawa","shortCode":"CK"},{"name":"Chiradzulu","shortCode":"CR"},{"name":"Chitipa","shortCode":"CT"},{"name":"Dedza","shortCode":"DE"},{"name":"Dowa","shortCode":"DO"},{"name":"Karonga","shortCode":"KR"},{"name":"Kasungu","shortCode":"KS"},{"name":"Likoma","shortCode":"LK"},{"name":"Lilongwe","shortCode":"LI"},{"name":"Machinga","shortCode":"MH"},{"name":"Mangochi","shortCode":"MG"},{"name":"Mchinji","shortCode":"MC"},{"name":"Mulanje","shortCode":"MU"},{"name":"Mwanza","shortCode":"MW"},{"name":"Mzimba","shortCode":"MZ"},{"name":"Nkhata Bay","shortCode":"NE"},{"name":"Nkhotakota","shortCode":"NB"},{"name":"Nsanje","shortCode":"NS"},{"name":"Ntcheu","shortCode":"NU"},{"name":"Ntchisi","shortCode":"NI"},{"name":"Phalombe","shortCode":"PH"},{"name":"Rumphi","shortCode":"RU"},{"name":"Salima","shortCode":"SA"},{"name":"Thyolo","shortCode":"TH"},{"name":"Zomba","shortCode":"ZO"}]},{"countryName":"Mozambique","countryShortCode":"MZ","regions":[{"name":"Cabo Delgado","shortCode":"P"},{"name":"Gaza","shortCode":"G"},{"name":"Inhambane","shortCode":"I"},{"name":"Manica","shortCode":"B"},{"name":"Maputo","shortCode":"L"},{"name":"Maputo (City)","shortCode":"MPM"},{"name":"Nampula","shortCode":"N"},{"name":"Niassa","shortCode":"A"},{"name":"Sofala","shortCode":"S"},{"name":"Tete","shortCode":"T"},{"name":"Zambezia","shortCode":"Q"}]},{"countryName":"Namibia","countryShortCode":"NA","regions":[{"name":"Erongo","shortCode":"ER"},{"name":"Hardap","shortCode":"HA"},{"name":"Kavango East","shortCode":"KE"},{"name":"Kavango West","shortCode":"KW"},{"name":"Karas","shortCode":"KA"},{"name":"Khomas","shortCode":"KH"},{"name":"Kunene","shortCode":"KU"},{"name":"Ohangwena","shortCode":"OW"},{"name":"Omaheke","shortCode":"OH"},{"name":"Omusati","shortCode":"OS"},{"name":"Oshana","shortCode":"ON"},{"name":"Oshikoto","shortCode":"OT"},{"name":"Otjozondjupa","shortCode":"OD"},{"name":"Zambezi","shortCode":"CA"}]},{"countryName":"Tanzania, United Republic of","countryShortCode":"TZ","regions":[{"name":"Arusha","shortCode":"01"},{"name":"Coast","shortCode":"19"},{"name":"Dar es Salaam","shortCode":"02"},{"name":"Dodoma","shortCode":"03"},{"name":"Iringa","shortCode":"04"},{"name":"Kagera","shortCode":"05"},{"name":"Kigoma","shortCode":"08"},{"name":"Kilimanjaro","shortCode":"09"},{"name":"Lindi","shortCode":"12"},{"name":"Manyara","shortCode":"26"},{"name":"Mara","shortCode":"13"},{"name":"Mbeya","shortCode":"14"},{"name":"Morogoro","shortCode":"16"},{"name":"Mtwara","shortCode":"17"},{"name":"Mwanza","shortCode":"18"},{"name":"Pemba North","shortCode":"06"},{"name":"Pemba South","shortCode":"10"},{"name":"Rukwa","shortCode":"20"},{"name":"Ruvuma","shortCode":"21"},{"name":"Shinyanga","shortCode":"22"},{"name":"Singida","shortCode":"23"},{"name":"Tabora","shortCode":"24"},{"name":"Tanga","shortCode":"25"},{"name":"Zanzibar North","shortCode":"07"},{"name":"Zanzibar Central/South","shortCode":"11"},{"name":"Zanzibar Urban/West","shortCode":"15"}]},{"countryName":"Zambia","countryShortCode":"ZM","regions":[{"name":"Central","shortCode":"02"},{"name":"Copperbelt","shortCode":"08"},{"name":"Eastern","shortCode":"03"},{"name":"Luapula","shortCode":"04"},{"name":"Lusaka","shortCode":"09"},{"name":"Muchinga","shortCode":"10"},{"name":"Northern","shortCode":"05"},{"name":"North-Western","shortCode":"06"},{"name":"Southern","shortCode":"07"},{"name":"Western","shortCode":"01"}]},{"countryName":"Zimbabwe","countryShortCode":"ZW","regions":[{"name":"Bulawayo","shortCode":"BU"},{"name":"Harare","shortCode":"HA"},{"name":"Manicaland","shortCode":"MA"},{"name":"Mashonaland Central","shortCode":"MC"},{"name":"Mashonaland East","shortCode":"ME"},{"name":"Mashonaland West","shortCode":"MW"},{"name":"Masvingo","shortCode":"MV"},{"name":"Matabeleland North","shortCode":"MN"},{"name":"Matabeleland South","shortCode":"MS"},{"name":"Midlands","shortCode":"MI"}]},{"countryName":"Unknown","countryShortCode":"Unknown","locale":"en-ZA","regions":[{"name":"Unknown","shortCode":"Unknown"}]}]')},1296:function(e,t,a){},1306:function(e,t){},1308:function(e,t){},1344:function(e,t){},1345:function(e,t){},1698:function(e,t,a){"use strict";a.r(t);var n=a(0),i=a.n(n),r=a(41),l=a.n(r),s=a(45),o=(a(906),a(35)),c=a(80),d=(a(1296),a(1767)),m=({component:e,props:t,...a})=>i.a.createElement(c.Route,Object.assign({},a,{render:a=>i.a.createElement(e,Object.assign({},a,t))}));var p=({component:e,props:t,...a})=>{const n=t.getFromGlobalState("subscription");console.log("sub",n);const r=n&&n.length>=1&&(e=>{const t=new Date,a=(new Date(e.nextSubscription)-t)/864e5;return console.log(a),a>-15})(n[0]);return!t.isAuthenticated||r||document.location.pathname.includes("subscription")||document.location.pathname.includes("trial")||document.location.pathname.includes("messages")?i.a.createElement(c.Route,Object.assign({},a,{render:a=>t.isAuthenticated?i.a.createElement(e,Object.assign({},a,t)):i.a.createElement(c.Redirect,{to:`/login?redirect=${a.location.pathname}${a.location.search}`})})):(console.log(document.location.pathname),i.a.createElement(c.Redirect,{to:"/subscription"}))};var h=({component:e,props:t,...a})=>{const n=function(e,t=window.location.href){e=e.replace(/[[]]/g,"\\$&");const a=new RegExp("[?&]"+e+"(=([^&#]*)|&|#|$)","i").exec(t);return a?a[2]?decodeURIComponent(a[2].replace(/\+/g," ")):"":null}("redirect");return i.a.createElement(c.Route,Object.assign({},a,{render:a=>t.isAuthenticated?i.a.createElement(c.Redirect,{to:""===n||null===n?"/":n}):i.a.createElement(e,Object.assign({},a,t))}))},g=a(1744),u=a(1729),b=a(1732),v=a(7),y=a(1731),f=a(1733),E=a(420),S=a(84),C=a.n(S),x=a(4),k=a(214),w=a.n(k),T=a(1700);var D=Object(v.a)(e=>({card:{height:"100%"},cardHeader:{paddingBottom:"6px"},cardContent:{paddingTop:"6px"},cardActions:{paddingBottom:"0px",paddingTop:"0px"},cardExpand:{padding:"0px"},title:{fontSize:14},pos:{marginBottom:12},expand:{transform:"rotate(0deg)",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}),{withTheme:!0})((function(e){const{classes:t,children:a,title:n,subHeader:r,elevation:l,avatar:s,action:o,expandedContent:c,expanded:d,handleExpandClick:m,handleAddExpandedContent:p,disableContentPadding:h}=e;return i.a.createElement(u.a,{elevation:l,className:t.card,onClick:m||void 0},i.a.createElement(y.a,{className:t.cardHeader,avatar:s,action:o,title:n,subheader:r}),i.a.createElement(b.a,{className:t.cardContent,style:h?{padding:"0px"}:void 0},a),m&&i.a.createElement(i.a.Fragment,null,i.a.createElement(f.a,{disableSpacing:!0,className:t.cardActions},p&&i.a.createElement(E.a,{color:"secondary","aria-label":"add"},i.a.createElement(C.a,{onClick:p})),i.a.createElement(E.a,{className:Object(x.a)(t.expand,{[t.expandOpen]:d}),"aria-expanded":d,"aria-label":"show more"},i.a.createElement(w.a,null))),i.a.createElement(T.a,{in:d,timeout:"auto",unmountOnExit:!0},i.a.createElement(b.a,{className:t.cardExpand,onClick:function(e){e.stopPropagation()}},c))))})),P=a(660);var F=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center",height:"100%"}}))((function(e){const{classes:t}=e;return i.a.createElement("div",{className:t.center},i.a.createElement(P.a,{className:t.progress,color:"secondary"}))}));function N(e){const{children:t,isloading:a,style:n}=e;return i.a.createElement(i.a.Fragment,null,a?i.a.createElement(F,{style:n}):i.a.createElement(i.a.Fragment,null,t))}N.defaultProps={style:{height:"100%"}};var B=a(120),L=a(140),A=a.n(L),O=a(156),I=a(662),G=a(667),R=a(278),U=a.n(R),M=a(172),W=a.n(M),z=a(666),K=a(276),H=a(792),q=a.n(H),V=a(105);function j(e,t){(e=String(e).replace(/[^0-9a-f]/gi,"")).length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;let a,n,i="#";for(n=0;n<3;n+=1)a=parseInt(e.substr(2*n,2),16),a=Math.round(Math.min(Math.max(0,a+a*t),255)).toString(16),i+=("00"+a).substr(a.length);return i}function $(e,t,a){let n;return n=!0===e.numeric&&t?t.toLocaleString(a):t,n}function Y(e,t){e=e.replace("#","");return`rgba(${parseInt(e.substring(0,2),16)},${parseInt(e.substring(2,4),16)},${parseInt(e.substring(4,6),16)},${t/100})`}function _(){return(new Date).toISOString().substr(0,10)}function Z(){const e=new Date;let t=e.getMinutes();t=t>=10?t:"0".concat(t);let a=e.getHours();a=a>=10?a:"0".concat(a);return`${a}:${t}`}function J(e,t,a){const n=new Date(e);return void 0!==t&&(n.setHours(parseInt(t.substring(0,2))),n.setMinutes(parseInt(t.substring(4,6)))),void 0!==a&&n.setDate(n.getDate()+(parseInt(a)+1)),n.toISOString().substring(0,10)}function Q(e){if(!e)return"en-ZA";if(!e.country)return"en-ZA";const t=V.filter(t=>t.countryName===e.country);return t[0].locale?t[0].locale?t[0].locale:"":"en-ZA"}function X(e,t,a){const n=a(e);n||alert("Could not find in global state",e);const i=n.find(e=>e.sk===t);let r="";return i&&(r=i.name),r}function ee(e){if(!e)return null;if(e.hasOwnProperty("lat")||e.hasOwnProperty("lng"))return e;const t=e.indexOf("lon");if(-1===t)return null;return{lat:parseFloat(e.substring(4,t).trim()),lng:parseFloat(e.substring(t+4,e.length).trim())}}function te(e,t,a){const n=a(e);n||alert("Could not find in global state",e);return n.find(e=>e.sk===t)}function ae(e,t,a){if(a||(a="name"),!t)return"";const n=t.find(t=>t.sk===e);let i="";return n&&(i=n[a]),i}const ne=e=>{const t=e||[];if(0===(null===t||void 0===t?void 0:t.length))return{};let a=0,n=0;for(const i of t)a+=i.lat,n+=i.lng;return{lat:a/t.length,lng:n/t.length}};function ie(e){const t=new FileReader;return new Promise((a,n)=>{t.onerror=()=>{t.abort(),n(new DOMException("Problem parsing input file."))},t.onload=()=>{a(t.result)},t.readAsText(e)})}function re(e){if(!e)return null;const t=e,a=t&&t.slice(0,t.indexOf("\n")),n=a&&-1!==a.indexOf(",")?",":";",i=t.slice(0,t.indexOf("\n")).split(n);return t.slice(t.indexOf("\n")+1).split("\n").map(e=>{const t=e.split(n);return i.reduce((e,a,n)=>(e[a.replace("\r","")]=t[n]?t[n].trim().replace("\r",""):"",e),{})})}const le={aqua:"#00ffff",azure:"#f0ffff",beige:"#f5f5dc",black:"#000000",blue:"#0000ff",brown:"#a52a2a",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgrey:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",gold:"#ffd700",green:"#008000",indigo:"#4b0082",khaki:"#f0e68c",lightblue:"#add8e6",lightcyan:"#e0ffff",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightyellow:"#ffffe0",lime:"#00ff00",magenta:"#ff00ff",maroon:"#800000",navy:"#000080",olive:"#808000",orange:"#ffa500",red:"#ff0000",silver:"#c0c0c0"},se={pestings:"Monitoring",fertilisings:"Fertiliser",waterings:"Irrigation",sprayings:"Plant Protection",harvestings:"Harvesting",activities:"Agronomic Activity"};var oe=a(2),ce=a.n(oe),de=a(1776),me=a(661);function pe(e){return"small"===e?{width:"7px",height:"7px",marginLeft:"0px",marginRight:"0px"}:"medium"===e?{width:"15px",height:"15px",marginLeft:"5px",marginRight:"5px"}:{width:"30",height:"30"}}function he(e){const{classes:t,status:a,hideIfGreen:n,size:r}=e;if(!a)return null;const l=a.status+"Avatar",s=function(e){return e.messages?e.messages.reduce((e,t)=>e.concat(t).concat(", "),""):""}(a);return i.a.createElement(i.a.Fragment,null,function(e,t,a,n,r,l){return t&&"green"===e.status?null:i.a.createElement(I.a,{placement:"top",title:n},i.a.createElement(de.a,{className:r[l],style:pe(a)}))}(a,n,r,s,t,l))}he.propTypes={status:ce.a.object.isRequired,hideIfGreen:ce.a.bool.isRequired,size:ce.a.string.isRequired};var ge=Object(v.a)(e=>({greenAvatar:{margin:10,color:K.a[500],backgroundColor:K.a[500]},redAvatar:{margin:10,color:e.palette.error.dark,backgroundColor:e.palette.error.dark},amberAvatar:{margin:10,color:me.a[500],backgroundColor:me.a[500]}}),{withTheme:!0})(he),ue=a(26),be=a(669),ve=a(670),ye=a(665),fe=a(663),Ee=a(784),Se=a(664),Ce=a(783),xe=a(781),ke=a(794),we=a.n(ke),Te=a(1734),De=a(795),Pe=a.n(De),Fe=a(668),Ne=a(1735);function Be(e){let t=0;for(let a=0;a!isNaN(Date.parse(e));return n(e[a])&&n(t[a])?new Date(t[a])-new Date(e[a]):t[a]e[a]?1:0}function Ie(e){const{classes:t,onSelectAllClick:a,order:n,orderBy:r,numSelected:l,rowCount:s,onRequestSort:o,headCells:c,multiSelect:d,userAvatar:m,clean:p}=e;return i.a.createElement(fe.a,null,i.a.createElement(Se.a,null,d&&i.a.createElement(ye.a,{padding:"checkbox"},i.a.createElement(xe.a,{indeterminate:l>0&&l{return i.a.createElement(ye.a,{key:e.id,style:{minWidth:e.minWidth,maxWidth:e.maxWidth,overflow:"hidden",borderBottom:p?"none":void 0},align:e.numeric?"right":"left",padding:e.disablePadding?"none":"default",sortDirection:r===e.id&&n},i.a.createElement(Ce.a,{active:r===e.id,direction:n,onClick:(a=e.id,e=>{o(e,a)})},e.label,r===e.id?i.a.createElement("span",{className:t.visuallyHidden},"desc"===n?"sorted descending":"sorted ascending"):null));var a})))}const Ge=Object(z.a)(e=>({root:{paddingLeft:e.spacing(2),paddingRight:e.spacing(1)},highlight:"light"===e.palette.type?{color:e.palette.secondary.main,backgroundColor:Object(ue.j)(e.palette.secondary.light,.85)}:{color:e.palette.text.primary,backgroundColor:e.palette.secondary.dark},spacer:{flex:"1 1 100%"},actions:{color:e.palette.text.secondary,display:"inline-flex"},title:{flex:"0 0 auto"},margin:{margin:e.spacing(1)},extendedIcon:{paddingRight:e.spacing(1)}})),Re=e=>{const t=Ge(),{numSelected:a,heading:n,handleAddItem:r,disableAdd:l,editDisabled:s,handleEditItem:o,handleShowDetail:c,showDetailSelected:d,showEditButton:m,showSummarySelected:p,handleShowSummary:h,Extract:g}=e;return console.log(e),i.a.createElement(G.a,{className:Object(x.a)(t.root,{[t.highlight]:a>0})},i.a.createElement("div",{className:t.title},i.a.createElement(B.a,{variant:"subtitle2",id:"tableTitle"},n)),i.a.createElement("div",{className:t.spacer}),i.a.createElement("div",{className:t.actions},h&&i.a.createElement(I.a,{title:"Results are averaged and gouped"},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p,onChange:h,name:"checkedB",color:"secondary"}),label:"Averaged"})),c&&i.a.createElement(I.a,{title:"Detail"},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:d,onChange:c,name:"checkedB",color:"secondary"}),label:"Detail"})),m&&o&&i.a.createElement("div",{style:{float:"right",marginLeft:"auto"}},i.a.createElement(I.a,{title:"Edit item"},i.a.createElement(Te.a,{variant:"extended",size:"medium",color:"primary",disabled:s,"aria-label":"add",className:t.margin,onClick:o},i.a.createElement(we.a,{className:t.extendedIcon}),"View"))),g&&i.a.createElement("div",{style:{float:"right",marginLeft:"auto"}},g),r&&"subscription"!==e.id&&i.a.createElement("div",{style:{float:"right",marginLeft:"auto"}},i.a.createElement(I.a,{title:"Add"},i.a.createElement(Te.a,{variant:"extended",disabled:l,size:"medium",color:"primary","aria-label":"add",className:t.margin,onClick:r},i.a.createElement(C.a,{className:t.extendedIcon}),"Add")))))},Ue=Object(z.a)(e=>({root:{},paper:{},table:{},tableWrapper:{width:"100%",overflowX:"hidden"},visuallyHidden:{border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",top:20,width:1},cached:{fontSize:15,color:e.palette.secondary.main},margin:{margin:e.spacing(1)},syncError:{fontSize:15,color:"red"}}));function Me(e){const t=Ue(),{rows:a,headCells:r,maxHeight:l,handleEditItem:s,disableAdd:o,editDisabled:c,heading:d,dense:m,showEditButton:p,parentSK:h,hideHeading:g,displayToolbar:u,handleSelect:b,multiSelect:v,selectedRow:y,parent:f,handleAddItem:E,rowKeyName:S,actionType:C,grandParentSK:x,recordType:k,clean:w,noPagination:T,hideHeader:D,padFirstCol:P,disablePadFirstCol:F,userAvatar:N,ancestorsInRow:L,handleShowDetail:A,showDetailSelected:O,showSummarySelected:I,handleShowSummary:G,orderByProperty:R,orderType:M,Extract:z}=e,[K,H]=i.a.useState("desc"),[q,V]=i.a.useState("date"),[j,$]=i.a.useState([]),[Y,_]=i.a.useState(0),[Z,J]=i.a.useState(25);let Q=Z;T&&(Q=a?a.length:3),Object(n.useEffect)(()=>{R&&V(R),R&&H(M)},[]);const X=T?0:Q-Math.min(Q,a.length-Y*Q),ee=w?"hidden":void 0;return i.a.createElement(i.a.Fragment,null,u&&i.a.createElement(Re,{numSelected:j.length,id:e.id,heading:g?null:d,handleAddItem:E,showDetailSelected:O,handleShowDetail:A,showSummarySelected:I,handleShowSummary:G,showEditButton:p,editDisabled:c,handleEditItem:s,disableAdd:o,Extract:z}),i.a.createElement("div",{className:t.tableWrapper},i.a.createElement(Ne.a,{style:{maxHeight:l,overflowX:ee}},i.a.createElement(be.a,{stickyHeader:!0,className:t.table,"aria-labelledby":"tableTitle",size:m?"small":"medium"},!D&&i.a.createElement(Ie,{classes:t,numSelected:j.length,order:K,orderBy:q,onSelectAllClick:v?function(e){if(e.target.checked){const e=a.map(e=>e[S]);$(e)}else $([])}:void 0,onRequestSort:function(e,t){H(q===t&&"desc"===K?"asc":"desc"),V(t)},rowCount:a.length,headCells:r,multiSelect:v,clean:w,userAvatar:N}),i.a.createElement(ve.a,null,a&&function(e,t){const a=e.map((e,t)=>[e,t]);return a.sort((e,a)=>{const n=t(e[0],a[0]);return 0!==n?n:e[1]-a[1]}),a.map(e=>e[0])}(a,function(e,t){return"desc"===e?(e,a)=>Oe(e,a,t):(e,a)=>-Oe(e,a,t)}(K,q)).slice(Y*Q,Y*Q+Q).map((e,a)=>{const n=v?(l=e[S],-1!==j.indexOf(l)):y===e[S];var l;const s="enhanced-table-checkbox-"+a;return i.a.createElement(Se.a,{hover:!0,onClick:e.disabled?void 0:v?t=>function(e,t){const a=j.indexOf(t);let n=[];-1===a?n=n.concat(j,t):0===a?n=n.concat(j.slice(1)):a===j.length-1?n=n.concat(j.slice(0,-1)):a>0&&(n=n.concat(j.slice(0,a),j.slice(a+1))),$(n)}(0,e[S]):b?t=>b(t,L?e[h]:f,e[S],e[C],L?e.blockSK:x,k,e):void 0,role:"checkbox","aria-checked":n,tabIndex:-1,key:e[S]+"_"+Math.floor(100+900*Math.random()),selected:n,style:e.disabled?{fontStyle:"oblique",cursor:"pointer"}:{cursor:"pointer"}},v&&i.a.createElement(ye.a,{padding:"checkbox"},i.a.createElement(xe.a,{checked:n,inputProps:{"aria-labelledby":s}})),N&&i.a.createElement(ye.a,{style:{verticalAlign:"top",maxWidth:"20px",paddingLeft:F?P:void 0,borderBottom:w?"none":void 0}},i.a.createElement(Ae,{userKey:e[S],name:e.name}," ")),r.map((a,n)=>{const r=a.numeric?"right":"left";return 0===n?a.combine?i.a.createElement(ye.a,{style:{verticalAlign:"top",borderBottom:w?"none":void 0,minWidth:a.minWidth,maxWidth:a.maxWidth,overflow:"hidden",paddingLeft:F?P:void 0},component:"th",id:s,scope:"row"},a.combine&&a.combine.map((n,r)=>{const l=a.numeric?parseInt(e[n.id])>=0?"green":"red":"inherit",s=e.attention&&0===r?i.a.createElement(Pe.a,{color:"secondary"}):void 0,o=e.alert&&0===r?i.a.createElement(B.a,{color:"error"},e.alert):void 0,c=e.cached&&0===r?e.syncError?i.a.createElement(W.a,{className:t.syncError}):i.a.createElement(U.a,{className:t.cached}):void 0;return i.a.createElement(i.a.Fragment,null,c,s,o,i.a.createElement("div",{style:{color:l,opacity:n.opacity}},`${e[n.id]} ${n.postfix?n.postfix:""}`))})):i.a.createElement(ye.a,{style:{verticalAlign:"top",borderBottom:w?"none":void 0,minWidth:a.minWidth,fontSize:a.fontSize,maxWidth:a.maxWidth,overflow:"hidden",paddingLeft:F?P:void 0},component:"th",id:s,scope:"row"},e[a.id]):a.combine?i.a.createElement(ye.a,{style:{verticalAlign:"top",borderBottom:w?"none":void 0,minWidth:a.minWidth,maxWidth:a.maxWidth,overflow:"hidden"},align:r},a.combine&&a.combine.map((t,n)=>{const r=a.numeric?parseInt(e[t.id])>=0?"green":"red":"inherit";return t.postfix?i.a.createElement("div",{style:{color:r,opacity:t.opacity}},`${e[t.id]} ${t.postfix?t.postfix:""}`):i.a.createElement("div",{style:{color:r,opacity:t.opacity}},e[t.id])})):i.a.createElement(ye.a,{style:{verticalAlign:"top",borderBottom:w?"none":void 0,minWidth:a.minWidth,fontSize:a.fontSize,maxWidth:a.maxWidth,overflow:"hidden"},align:r},e[a.id])}))}),X>0&&i.a.createElement(Se.a,{style:{height:49*X}},i.a.createElement(ye.a,{colSpan:r.length})))))),!T&&i.a.createElement(Ee.a,{rowsPerPageOptions:[5,10,25,50,100,1e3],component:"div",labelRowsPerPage:"Rows",count:a.length,rowsPerPage:Q,page:Y,backIconButtonProps:{"aria-label":"previous page"},nextIconButtonProps:{"aria-label":"next page"},onChangePage:function(e,t){_(t)},onChangeRowsPerPage:function(e){J(+e.target.value),_(0)}}))}Me.defaultProps={padFirstCol:"0px",maxHeight:void 0,parentSK:"plantingSK"};var We={RECENTS_LEN:3},ze=a(273),Ke=a(270);const{RECENTS_LEN:He}=We;function qe(e){const t={};e.forEach(e=>{const a=e.blockNumber,n=e.plantingLabel,i=e.name,r=e.value;if(Date.parse(e.date)>Date.now()){}t[a]||(t[a]={}),t[a][n]||(t[a][n]={}),t[a][n][i]||(t[a][n][i]={totalObservations:0,observationCount:0,value:0}),t[a][n][i].totalObservations+=r,t[a][n][i].observationCount+=1,t[a][n][i].value+=r}),Object.keys(t).forEach(e=>{Object.keys(t[e]).forEach(a=>{Object.keys(t[e][a]).forEach(n=>{const{value:i,observationCount:r}=t[e][a][n],l=r>0?i/r:0;t[e][a][n].average=l})})});const a=[],n={};return e.forEach(e=>{const i=e.blockNumber,r=e.plantingLabel,l=e.name,s=`${i}_${r}_${l}`;if(!n[s]){n[s]=!0;const{average:o,value:c,observationCount:d}=t[i][r][l],m={...e,average:o.toFixed(2),value:c.toFixed(2),observationCount:d.toFixed(2)};delete m.actualObservations,a.push(m)}}),a}function Ve(e){const{recordType:t,handleSelect:a,getFromGlobalState:n,blocks:r,clean:l,displayToolbar:s,noPagination:o,hideHeader:c,handleAddItem:d,selectedRow:m,showAll:p,handleShowDetail:h,showDetail:g,handleShowSummary:u,showSummary:b,data:v}=e;if(!v)return null;const y=n("userDetail");return i.a.createElement("div",{style:{paddingLeft:"2px",paddingRight:"2px"}},i.a.createElement(Me,{displayToolbar:s,noPagination:o,hideHeader:c,heading:v.title,rows:p?v.rows:v.mostRecent,headCells:v.headCells,handleSelect:a,handleAddItem:y&&y.rights&&!y.rights.readOnly?d:null,actionType:"actionType",rowKeyName:"sk",recordType:t,clean:l,selectedRow:m,ancestorsInRow:!0,showDetailSelected:g,handleShowDetail:h,handleShowSummary:u,showSummarySelected:b,maxHeight:"350px",dense:!!g}))}function je(e,t){return e.reduce((e,a)=>((e[a[t]]=e[a[t]]||[]).push(a),e),{})}const $e=(e,t,a,n,i)=>{Object.keys(e).forEach(r=>{if("object"===typeof e[r]&&null!==e[r]){if(Array.isArray(e[r])){let l=e[r].reduce((e,a)=>e+parseFloat(a[t]),0);if(isNaN(l)&&(l=-1e3),n){const t=e[r].reduce((e,t)=>e+parseFloat(t[n]),0);isNaN(t),"divide"===i&&(l/=t)}e[r]=l,a&&(e[r]=Math.round(e[r]))}$e(e[r],t,a,n,i)}})};function Ye(e,t,a,n,i,r,l){const s=function(e,t){const a={};return e||e.length?(e.forEach(e=>{t.reduce((a,n,i)=>(a[e[n]]=a[e[n]]||(i+1===t.length?[]:{}),a[e[n]]),a).push(e)}),a):a}(e,t);$e(s,a,i,r,l);const o={data:[],keys:[]},c={};return e||e.length?(Object.keys(s).forEach(e=>{const t={};t.name=e,Object.keys(s[e]).forEach(a=>{t[a]=s[e][a];-1===o.keys.indexOf(a)&&o.keys.push(a)}),o.data.push(t)}),o.name=n,o):c}function _e(e,t,a,n,i,r){const l=je(e,t),s={data:[],keys:[]};return Object.keys(l).forEach(e=>{let t=l[e].reduce((e,t)=>e+parseFloat(t[a]),0);r&&(t=Math.round(t));const i={};i.name=e,i[n]=t,s.data.push(i)}),s.keys.push(n),s.name=i,s}function Ze(e,t){const a={red:3,amber:2,green:1};return a[e]>a[t]?e:t}function Je(e){const t=new Date(new Date-new Date(e)).getFullYear()-1970;let a="";switch(!0){case t>0&&t<=3:a="0 - 3";break;case(t>3&&t)<=6:a="3 - 6";break;case(t>6&&t)<=9:a="6 - 9";break;case t>9&&t<=12:a="9 - 12";break;case t>12&&t<=15:a="12 - 15";break;case t>15&&t<=18:a="15 - 18";break;case t>18&&t<=21:a="18 - 21";break;case t>21&&t<=24:a="21 - 24";break;case t>24:a="24 +";break;default:a="unknown"}return a}function Qe(e,t,a){if(e&&t&&a){const n=a*(1e4/(e*t));return Math.trunc(n)}}function Xe(e){if(!e)return null;const t=[];let a=0;for(let n=0;n{const n=e("transactions"),i=new Date(t),r=new Date(a);r.setDate(r.getDate()+1);return{transactions:n.filter(e=>{const t=new Date(e.createdAt);return t>=i&&t<=r}),headCells:n.length>0?Object.keys(n[0]):[]}};function tt(e,t,a,n,i,r,l,s,o,c){let d=0,m={};const p={blockNumber:" ",litersApplied:" ",date:" ",duration:" ",volumePerHour:" ",flowunit:" ",operator:" ",plantingLabel:" "},h=Q(a("farm")[0]),g={rows:[],headCells:[],title:"",mostRecent:[]};if(!t)return g;const u=performance.now();t=t&&t.sort((e,t)=>(""+e.number).localeCompare(t.number,void 0,{numeric:!0}));const b=a("crops");if(!b)return g;if(t.forEach(t=>{t.plantings&&t.plantings.forEach(u=>{if(u[e]&&u[e].length>0){const v=ut(e,u,t,a,n,i,r,!0,b,l,s,void 0,!0,c);if(!o&&"waterings"===e&&"irrigated"===t.irrigated){const e=v.rows.reduce((e,t)=>e+t.actualLiters,0);d+=e,m={strong:!0,blockNumber:"Total",litersApplied:(e/1e3).toLocaleString(h)+" kL",date:"",duration:"",volumePerHour:"",flowunit:"",operator:"",plantingLabel:""}}if(!o&&"harvestings"===e){const e=v.rows.reduce((e,t)=>e+t.harvestTotalNoUnit,0);d+=e}g.rows=g.rows.concat(v.rows),o||"waterings"!==e||"irrigated"!==t.irrigated||(g.rows.push(m),g.rows.push(p)),g.headCells=v.headCells,g.title=v.title}})}),o||"waterings"!==e||g.rows.push({strong:!0,blockNumber:"Grand Total",litersApplied:(d/1e3).toLocaleString(h)+" kL",date:"",duration:"",volumePerHour:"",flowunit:"",operator:"",plantingLabel:""}),o||"harvestings"!==e||g.rows.push({strong:!0,blockNumber:"Grand Total",harvestTotal:(d/1e3).toLocaleString(h)+" t",date:"",duration:"",volumePerHour:"",flowunit:"",operator:"",plantingLabel:""}),!o&&"fertilisings"===e){const e=g.rows.filter(e=>"Total"!==e.blockNumber),t=e.reduce((e,t)=>e+Number(t.totalLiquid),0),a=e.reduce((e,t)=>e+Number(t.totalSolid),0),n=e.reduce((e,t)=>e+Number(t.nPerHa),0),i=e.reduce((e,t)=>e+Number(t.pPerHa),0),r=e.reduce((e,t)=>e+Number(t.kPerHa),0);g.rows.push({strong:!0,blockNumber:"Grand Total",numeric:!0,totalLiquid:t,totalSolid:a,nPerHa:n,pPerHa:i,kPerHa:r})}const v=performance.now();return console.log(`exiting batchrecords ${v-u} milliseconds.`),g}function at(e,t,a,n,i,r,l,s,o){e&&(t.plantingLabel=n,t.blockNumber=a,t.plantingSK=r,t.blockSK=l,t.cropName=s,t.varietyName=o,t.plantingName=i)}function nt(e,t,a,n){if(e)if(n){const e=[{id:"blockNumber",combine:[{id:"blockNumber",opacity:1},{id:"plantingLabel",opacity:.6}],numeric:!1,disablePadding:!1,label:"Block"}];t.splice(a,0,...e)}else{const e=[{id:"blockNumber",numeric:!1,disablePadding:!1,label:"Block"},{id:"cropName",numeric:!1,disablePadding:!1,label:"Crop"},{id:"varietyName",numeric:!1,disablePadding:!1,label:"Variety"},{id:"plantingName",numeric:!1,disablePadding:!1,label:"Planting"}];t.splice(a,0,...e)}}const it=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];function rt(e,t,a,n,i,r,l){if(!t)return console.error("targetDetail does not exist for stageDetail",e),null;const s={block:a.number,planting:n.name,stageSK:e.sk,stageDescription:e.stageDescription,targetSK:t.detail.sk,targetName:t.detail.name,type:t.type,rag:"unknown",value:null,radius:3,cnt:l,actualObservations:0,color:"green",date:i,threshold:null,thresholdValue:0,recordType:"Monitoring",unit:e.unit,procedure:e.procedure};switch(e.unitNum){case"Present":case"Number":{const t=e.quantityOfUnit,a=r.length;s.actualObservations=a;const n=r.reduce((e,t)=>e+parseFloat(t),0),o=0===a?0:n/a;s.value=o,isNaN(s.value)&&console.log("Error: isNaN",s.value),s.radius=3*(l+1);const c=o*(t/a);if("Yes"===e.threshold)if(s.thresholdValue=c,"Yes"===e.thresholdConstant){const t=parseFloat(e.thresholdLow),a=parseFloat(e.thresholdMedium),n=parseFloat(e.thresholdHigh);s.threshold={low:t,med:a,high:n},c=t&&c=a&&c=n?(s.rag="high",s.color="red"):(s.rag="unknown",s.color="black")}else{const t=it[new Date(i).getMonth()],a=e.variableThreshold&&e.variableThreshold[t]?e.variableThreshold[t]:{low:0,med:0,high:0};s.threshold=a;const n=parseFloat(a?a.low:0),r=parseFloat(a?a.med:0),l=parseFloat(a?a.high:0);c=n&&c=r&&c=l?(s.rag="high",s.color="red"):(s.rag="unknown",s.color="black")}else s.color="black";break}case"Scale":{const t=r.length;s.actualObservations=t;const a=r.reduce((e,t)=>e+t,0),n=0===t?0:a/t;if(s.value=n,s.color="black",s.radius=3*(l+1),"Yes"===e.threshold&&"Yes"===e.thresholdConstant){const a=n*(e.quantityOfUnit/t);s.thresholdValue=a;const i=parseFloat(e.thresholdLow),r=parseFloat(e.thresholdMedium),l=parseFloat(e.thresholdHigh);s.threshold={low:i,med:r,high:l},a=i&&a=r&&a=l?(s.rag="high",s.color="red"):(s.rag="unknown",s.color="black")}break}}return s}function lt(e,t){-1===e.findIndex(e=>e===t)&&e.push(t)}function st(e,t){if(!e)return[];const a=t("targetsTypesSetting");return e.map(e=>{const t={};if(t.sk=e.sk,t.targetType=ae(e.targetType,a,"name"),t.name=e.targetDetail&&e.targetDetail.name,t.cropSpecific=e.targetDetail&&e.targetDetail.cropSpecific,t.observableOn="",t.stages="",t.isDisabled=e.isDisabled?"Yes":"No",t.mobileDescription="Not crop specific",t.targetSK=e.targetDetail.sk,"Yes"===e.cropSpecific){t.observableOn=e.targetDetail&&e.targetDetail.observableOn[0].name,t.observableOnSk=e.targetDetail&&e.targetDetail.observableOn[0].sk;const a=e.targetDetail.observableOn[0].stages&&e.targetDetail.observableOn[0].stages.filter(e=>!0===e.selected);t.stages=e.targetDetail&&a?a.length:0,t.mobileDescription=`Crop specific, Stages: ${t.stages} `,t.stagesDescrip="";for(let n=0;n{const t=new Map;e.flatMap(e=>e.plantings).forEach(e=>{e.harvestings.forEach(a=>{const n=new Date(a.date),i=n.getFullYear(),r=ot(n),l=`${i}_${r}`;e.name;t.has(e.name)||t.set(e.name,[]);const s=t.get(e.name),o=s.find(e=>e.week===l);o?o.totalKgs+=parseInt(a.harvestTotal):s.push({crop:e.name,totalKgs:a.harvestTotal,year:i,week:l,yearWeek:l,weekNumber:r})})});const a=[];t.forEach((e,t)=>{a.push(...e)});const n=[];return t.forEach((e,t)=>{e.forEach(e=>{const a=n.find(t=>t.week===e.week);if(a)a["totalKgs_"+t]=e.totalKgs;else{const a={week:e.week,["totalKgs_"+t]:e.totalKgs};a.year=e.year,a.weekNumber=e.weekNumber,n.push(a)}})}),n.sort((e,t)=>e.year!==t.year?e.year-t.year:e.weekNumber-t.weekNumber)},dt=e=>{const t=new Map;e.flatMap(e=>e.plantings).forEach(e=>{e.waterings.forEach(a=>{const n=new Date(a.date),i=n.getFullYear(),r=ot(n),l=`${i}_${r}`;e.name;t.has(e.name)||t.set(e.name,[]);const s=t.get(e.name),o=s.find(e=>e.week===l);o?o.totalLiters+=parseInt(a.actualLiters):s.push({plant:e.plant,totalLiters:a.actualLiters,year:i,week:l,yearWeek:l,weekNumber:r})})});const a=[];t.forEach((e,t)=>{a.push(...e)});const n=[];return t.forEach((e,t)=>{e.forEach(e=>{const a=n.find(t=>t.week===e.week);if(a)a["totalLiters_"+t]=e.totalLiters;else{const a={week:e.week,["totalLiters_"+t]:e.totalLiters};a.year=e.year,a.weekNumber=e.weekNumber,n.push(a)}})}),n.sort((e,t)=>e.year!==t.year?e.year-t.year:e.weekNumber-t.weekNumber)};function mt(e,t){const a={},n=[],i={circles:[]},r={liters:0,kg:0,n:0,p:0,k:0,ca:0,mg:0,s:0,zn:0,b:0,fe:0,mn:0,cu:0,mo:0};for(let l=0;e&&le.sk===o.product);a[o.product]=t.find(e=>e.sk===o.product),lt(n,null===e||void 0===e?void 0:e.name)}const c=a[o.product],d={nPerHa:0,pPerHa:0,kPerHa:0,caPerHa:0,mgPerHa:0,sPerHa:0,bPerHa:0,fePerHa:0,mnPerHA:0,znPerHa:0,cuPerHa:0,moPerHa:0};if(d.total||(d.total=o.volume),d.unit=null===c||void 0===c?void 0:c.unit,"liter"===(null===c||void 0===c?void 0:c.unit)?(d.totalLiquid=(d.total/1e3).toFixed(2),d.totalSolid="",r.liters+=Number(d.total)):(d.totalLiquid="",d.totalSolid=(d.total/1e3).toFixed(2),r.kg+=Number(d.total)),(null===c||void 0===c?void 0:c.totalUnit)||(d.totalUnit=""),d.qtyUnit=d.totalUnit,"g"===d.totalUnit&&(d.totalUnit="kg",d.total/=1e3),"ml"===d.totalUnit&&(d.totalUnit="l",d.total/=1e3),(null===c||void 0===c?void 0:c.unit)||(d.unit=""),null===c||void 0===c?void 0:c.nitrogenP){const e=c.nitrogenP?Number(d.total*c.nitrogenP/100/l.size):0;r.n+=e,d.nPerHa=e}if(null===c||void 0===c?void 0:c.phosphorusP){const e=c.phosphorusP?Number(d.total*c.phosphorusP/100/l.size):0;r.p+=e,d.pPerHa=e}if(null===c||void 0===c?void 0:c.potassiumP){const e=c.potassiumP?Number(d.total*c.potassiumP/100/l.size):0;r.k+=e,d.kPerHa=e}if(null===c||void 0===c?void 0:c.caP){const e=c.caP?Number(d.total*c.caP/100/l.size):0;r.ca+=e,d.caPerHa=e}if(null===c||void 0===c?void 0:c.mgP){const e=c.mgP?Number(d.total*c.mgP/100/l.size):0;r.mg+=e,d.mgPerHa=e}if(null===c||void 0===c?void 0:c.sP){const e=c.sP?Number(d.total*c.sP/100/l.size):0;r.s+=e,d.sPerHa=e}if(null===c||void 0===c?void 0:c.znP){const e=c.znP?Number(d.total*c.znP/100/l.size):0;r.zn+=e,d.znPerHa=e}if(null===c||void 0===c?void 0:c.bP){const e=c.bP?Number(d.total*c.bP/100/l.size):0;r.b+=e,d.bPerHa=e}if(null===c||void 0===c?void 0:c.feP){const e=c.feP?Number(d.total*c.feP/100/l.size):0;r.fe+=e,d.fePerHa=e}if(null===c||void 0===c?void 0:c.mnP){const e=c.mnP?Number(d.total*c.mnP/100/l.size):0;r.mn+=e,d.mnPerHA=e}if(null===c||void 0===c?void 0:c.cuP){const e=c.cuP?Number(d.total*c.cuP/100/l.size):0;r.cu+=e,d.cuPerHa=e}if(null===c||void 0===c?void 0:c.moP){const e=c.moP?Number(d.total*c.moP/100/l.size):0;r.mo+=e,d.moPerHa=e}d.block=null===s||void 0===s?void 0:s.number,d.planting=null===l||void 0===l?void 0:l.name,d.date=null===o||void 0===o?void 0:o.date,d.product=null===c||void 0===c?void 0:c.name,d.productSK=null===c||void 0===c?void 0:c.sk,d.productUnit=null===c||void 0===c?void 0:c.unit,i.circles.push(d)}}}return i.distinctFertilisers=n,i}function pt(e,t,a){const n={},i={},r=[],l=[],s=[],o={circles:[],targetTypes:{}};for(let c=0;e&&ce.sk===h.monitoringSK);e?n[g]=e.targetDetail.observableOn[0].stages.find(e=>e.sk===h.stageSK):console.error("setting not found monitoringSK",h.monitoringSK)}else{t.find(e=>e.sk===h.monitoringSK)?n[g]=t.find(e=>e.sk===h.monitoringSK).targetDetail.nonCropDetail:console.error("setting not found monitoringSK",h.monitoringSK)}n[g]||console.error("stageDetail[stageID] not found StageSK",h.stageSK,"targetDetailSK",h.targetDetailSK)}if(n[g]&&!i[h.monitoringSK]){const e=t.find(e=>e.sk===h.monitoringSK),o=e&&e.targetType,c=e&&e.targetDetail;c||console.error("targetDetail not found",h.monitoringSK),i[h.monitoringSK]={};const d=(a||[]).find(e=>e.sk===o);i[h.monitoringSK].type=d?d.name:"unknown",i[h.monitoringSK].detail=c,lt(r,i[h.monitoringSK].type),lt(l,i[h.monitoringSK].detail.name),lt(s,n[g]&&n[g].stageDescription?n[g].stageDescription:"")}i[h.monitoringSK]||console.error("targetDetail not found 2",h.monitoringSK);for(let t=0;h&&n[g]&&te.sk===t.crop))||void 0===v?void 0:v.varieties,"cultivar"),u.plantingLabel=`${u.cropName} - ${u.varietyName}`,u.plantingName=t.name);const y=Q(n("farm")[0]);switch(u.locale=y,e){case"fertilisings":{const a={liters:0,kg:0,n:0,p:0,k:0},i=n("combinations").filter(e=>"Fertiliser"===e.combinationType),l=n("fertilisers").concat(i);let o=t[e]?t[e]:[];if(d&&m&&(o=o.filter(e=>e.date>=d&&e.date<=m)),u.rows=o?o.map(e=>{var i;const s={...e};s.date=ht(s.date),console.log("fertilisers",s),s.productName=ae(e.product,l),!r&&g&&(s.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:""),s.isComplete=s.completed?"Yes":"No",at(b,s,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName),s.endTime=s.endTime?s.endTime:"Busy",console.log(e);const o=l.find(t=>t.sk===e.product);if(s.advisor=null===o||void 0===o?void 0:o.advisor,s.nPerHa=0,s.pPerHa=0,s.kPerHa=0,e.total||(s.total=e.volume),"l"===e.totalUnit||"ml"===e.totalUnit){const e="ml"===s.totalUnit?(s.total/1e3).toFixed(2):parseFloat(s.total).toFixed(2);s.totalLiquid=e,s.totalSolid="",a.liters+=Number(e)}else{s.totalLiquid="",console.log(s.totalUnit);const e="g"===s.totalUnit?(s.total/1e3).toFixed(2):parseFloat(s.total).toFixed(2);s.totalSolid=e,a.kg+=Number(e)}if(e.totalUnit||(s.totalUnit=""),s.qtyUnit=s.totalUnit,e.unit||(s.unit=""),null===o||void 0===o?void 0:o.nitrogenP){const e="g"===s.totalUnit||"ml"===s.totalUnit?Number(s.total*o.nitrogenP/100/t.size).toFixed(2)/1e3:Number(s.total*o.nitrogenP/100/t.size);a.n+=e,s.nPerHa=e.toFixed(2)}if(null===o||void 0===o?void 0:o.phosphorusP){const e="g"===s.totalUnit||"ml"===s.totalUnit?Number(s.total*o.phosphorusP/100/t.size).toFixed(2)/1e3:Number(s.total*o.phosphorusP/100/t.size);a.p+=e,s.pPerHa=e.toFixed(2)}if(null===o||void 0===o?void 0:o.potassiumP){const e="g"===s.totalUnit||"ml"===s.totalUnit?Number(s.total*o.potassiumP/100/t.size).toFixed(2)/1e3:Number(s.total*o.potassiumP/100/t.size);a.k+=e,s.kPerHa=e.toFixed(2)}s.volume=e.volume?`${e.volume.toLocaleString(y)} ${s.qtyUnit} / ${null===s||void 0===s?void 0:s.unit}`:"0",s.totalUnit=`${s.total&&y&&(null===(i=s.total)||void 0===i?void 0:i.toLocaleString(y))} ${s.totalUnit} ${e.totalOverride?" (override)":""}`,s.calculatedVolumeDisplay="";const c=te("operators",e.operator,n);return s.operator=c?`${c.name} ${c.surname}`:"",s}):[],p||(u.rows=u.rows&&u.rows.sort((e,t)=>new Date(t.date)-new Date(e.date))),u.mostRecent=u.rows&&u.rows.slice(0,s),u.headCells=r?[{id:"date",combine:[{id:"date",opacity:1},{id:"productName",opacity:.6}],numeric:!1,disablePadding:!1,label:"Date"},{id:"totalUnit",combine:[{id:"totalUnit",opacity:1}],numeric:!0,disablePadding:!1,label:"Total"}]:[{id:"date",numeric:!1,disablePadding:!1,label:"Date"},{id:"productName",numeric:!1,disablePadding:!1,label:"Product"},{id:"totalLiquid",numeric:!0,disablePadding:!1,label:"Total L"},{id:"totalSolid",numeric:!0,disablePadding:!1,label:"Total kg"},{id:"volume",numeric:!0,disablePadding:!1,label:"Applied QTY"},{id:"nPerHa",numeric:!0,disablePadding:!1,label:"(N) kg/ha"},{id:"pPerHa",numeric:!0,disablePadding:!1,label:"(P) kg/ha"},{id:"kPerHa",numeric:!0,disablePadding:!1,label:"(K) kg/ha"},{id:"operator",numeric:!0,disablePadding:!1,label:"Operator"},{id:"advisor",numeric:!0,disablePadding:!1,label:"Advisor"}],!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),!r)if(h){const e={strong:!0,blockNumber:"Total",numeric:!0,totalLiquid:a.liters.toFixed(2),totalSolid:a.kg.toFixed(2),nPerHa:parseFloat(a.n.toFixed(2)),pPerHa:parseFloat(a.p.toFixed(2)),kPerHa:parseFloat(a.k.toFixed(2))};u.rows.push(e)}else{const e={strong:!0,date:"Total",numeric:!0,totalLiquid:a.liters.toFixed(2),totalSolid:a.kg.toFixed(2),nPerHa:a.n,pPerHa:a.p,kPerHa:a.k};u.rows.push(e)}return nt(b,u.headCells,0,r),u.title="Fertiliser Records",u}case"waterings":{let i=t[e]?t[e]:[];d&&m&&(i=i.filter(e=>e.date>=d&&e.date<=m)),u.rows=i?i.map(e=>{var t;const i={...e};i.date=ht(i.date),i.duration=i.duration.toLocaleString(y),a.volumePerHour||(a.volumePerHour=0,i.actualLiters=0),i.volumePerHour=a.volumePerHour.toLocaleString(y),i.flowunit=a.flowunit,!r&&g&&(i.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:""),i.litersApplied=(null===(t=i.actualLiters)||void 0===t?void 0:t.toLocaleString(y))+" \u2113",at(b,i,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName);const l=te("operators",e.operator,n);return i.operator=l?`${l.name} ${l.surname}`:"",i}):[],p||(u.rows=u.rows&&u.rows.sort((e,t)=>new Date(t.date)-new Date(e.date))),u.mostRecent=u.rows&&u.rows.slice(0,s);const l=0;if(!h){const e={strong:!0,date:"Total",duration:"",volumePerHour:"",litersApplied:(u.rows.reduce((e,t)=>e+t.actualLiters,0)/1e3).toLocaleString(y)+" kl",operator:""};u.rows.push(e)}return u.headCells=r?[{id:"date",combine:[{id:"date",opacity:1},{id:"duration",opacity:.6,postfix:"hour"},{id:"volumePerHour",opacity:.6,postfix:"l/h"}],numeric:!1,disablePadding:!1,label:"Date"},{id:"litersApplied",combine:[{id:"litersApplied",opacity:1}],numeric:!0,disablePadding:!1,label:"(liter)"}]:[{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"duration",numeric:!0,disablePadding:!1,label:"Duration open (hr)"},{id:"volumePerHour",numeric:!0,disablePadding:!1,label:"Flow rate (L/hr)"},{id:"litersApplied",combine:[{id:"litersApplied",opacity:1}],numeric:!0,disablePadding:!1,label:"Total water (L)"},{id:"operator",numeric:!1,disablePadding:!1,label:"Operator"}],!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),u.title="Irrigation Records",u.total=l,nt(b,u.headCells,0,r),u}case"pestings":{var f;const e=n("monitorings"),l=n("targetsTypesSetting"),o={...a};o.plantings=[t];const c=pt([o],e,l);return d&&m&&(c.circles=c.circles?c.circles.filter(e=>e.observationData.date>=d&&e.observationData.date<=m):[]),u.rows=c.circles?c.circles.map(e=>{const t={};t.date=ht(e.observationData.date),t.capturedDateTime=new Date(parseInt(e.createdAt)).toLocaleString(),t.sk=e.sk,t.blockSK=e.blockSK,t.targetType=e.observationData.type,t.name=e.observationData.targetName,t.stageDescription=e.observationData.stageDescription,t.actualObservations=e.observationData.actualObservations,t.value=e.observationData.value,t.rag=e.observationData.threshold?e.observationData.rag:"none";const a=function(e){if("green"===e){const e="Value is within threshold";return{icon:i.a.createElement(I.a,{placement:"top",title:e},i.a.createElement(de.a,{style:{margin:3,color:"#fff",backgroundColor:K.a[500],width:15,height:15}},i.a.createElement("checkIcon",null))),ragOrder:2}}if("orange"===e){const e="Value is close to threshold";return{icon:i.a.createElement(I.a,{placement:"top",title:e},i.a.createElement(de.a,{style:{margin:3,color:"#fff",backgroundColor:me.a[500],width:15,height:15}},i.a.createElement("checkIcon",null))),ragOrder:1}}if("red"===e){const e="Value exceed threshold";return{icon:i.a.createElement(I.a,{placement:"top",title:e},i.a.createElement(de.a,{style:{margin:3,color:"#fff",backgroundColor:ze.a[500],width:15,height:15}},i.a.createElement("checkIcon",null))),ragOrder:0}}return{icon:i.a.createElement(I.a,{placement:"top",title:"Value does not have a threshold"},i.a.createElement(de.a,{style:{margin:3,color:"#fff",backgroundColor:Ke.a[500],width:15,height:15}},i.a.createElement("checkIcon",null))),ragOrder:3}}(e.observationData.color);t.ragIcon=a.icon,t.ragOrder=a.ragOrder,t.thresholdValue=e.observationData.thresholdValue,t.threshold=e.observationData.threshold?`Low: ${e.observationData.threshold.low} Medium: ${e.observationData.threshold.med} High: ${e.observationData.threshold.high}`:"",t.cropSpecific=e.targetDetail.detail.cropSpecific,!r&&g&&(t.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:"");const n=e.createdByDetail;return t.operator=n?`${n.name} ${n.surname}`:"",at(b,t,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName),t}):[],u.mostRecent=u.rows&&(null===(f=qe(u.rows))||void 0===f?void 0:f.slice(0,s)),r?(u.headCells=[{id:"ragIcon",numeric:!1,disablePadding:!1,label:"",type:"icon"},{id:"date",combine:[{id:"date",opacity:1},{id:"targetType",opacity:1},{id:"name",opacity:.6},{id:"stageDescription",opacity:.4}],numeric:!1,disablePadding:!1,label:"Target"}],u.rows=u.rows):(u.headCells=[{id:"ragIcon",numeric:!1,disablePadding:!1,label:"",type:"icon"},{id:"rag",numeric:!1,disablePadding:!1,label:"Threshold status"},{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"capturedDateTime",numeric:!1,disablePadding:!1,label:"Captured at",minWidth:"80px"},{id:"targetType",numeric:!1,disablePadding:!1,label:"Target Type"},{id:"name",numeric:!0,disablePadding:!1,label:"Name"},{id:"stageDescription",numeric:!0,disablePadding:!1,label:"Stage Description"},{id:"cropSpecific",numeric:!0,disablePadding:!1,label:"Crop Specific"},{id:"value",numeric:!1,disablePadding:!1,label:"Sum Of Observations"},{id:"observationCount",numeric:!1,disablePadding:!1,label:"Number Of Observations"},{id:"average",numeric:!1,disablePadding:!1,label:"% Incidence or Average"},{id:"threshold",numeric:!1,disablePadding:!1,label:"Threshold"},{id:"operator",numeric:!1,disablePadding:!1,label:"Operator"}],u.rows=qe(u.rows)),u.title="Monitoring Records",!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),nt(b,u.headCells,3,r),u}case"activities":{const a=n("agronomistActs");let i=t[e]?t[e]:[];return d&&m&&(i=i.filter(e=>e.date>=d&&e.date<=m)),u.rows=i?i.map(e=>{const t={...e};t.date=ht(t.date),!r&&g&&(t.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:"");const i=a&&a.find(t=>t.sk===e.activity);i&&(t.name=i.name,t.description=i.description,at(b,t,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName));const l=te("operators",e.operator,n);return t.operator=l?`${l.name} ${l.surname}`:"",t}):[],p||(u.rows=u.rows&&u.rows.sort((e,t)=>new Date(t.date)-new Date(e.date))),u.mostRecent=u.rows&&u.rows.slice(0,s),u.headCells=r?[{id:"date",opacity:1,label:"Date"},{id:"name",opacity:1,label:"Activity"}]:[{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"name",numeric:!1,disablePadding:!1,label:"Activity"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"},{id:"operator",numeric:!1,disablePadding:!1,label:"Operator"}],u.title="Agronomic Activity Records",!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),nt(b,u.headCells,0,r),u}case"sprayings":{const a=n("combinations").filter(e=>"Plant Protection"===e.combinationType),i=n("chemicals").concat(a),l=(e=>{if(!e)return[];return e.map(e=>{const t={};return t.sk=e.sk,t.name=e.targetDetail.name,t})})(n("monitorings")),o=n("chemequips");let c=t[e]?t[e]:[];return d&&m&&(c=c.filter(e=>e.date>=d&&e.date<=m)),u.rows=c?c.map(e=>{const t={...e};t.date=ht(t.date),t.startTime=t.time,t.endTime=t.endTime?t.endTime:"Busy",!r&&g&&(t.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:""),t.productName=ae(e.product,i),t.phiLapse=t.endDate?e.phiLapse:"Busy",at(b,t,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName),t.totalVolume=t.endDate?parseFloat(e.volume).toLocaleString(y)+" \u2113":"Busy",t.weather=t.endDate?e.weather:"Busy";const a=i.find(t=>t.sk===e.product);if(a){t.tradeName=a.name,t.advisor=null===a||void 0===a?void 0:a.advisor,t.activeIngredient=a.aIngredient,t.unit=null===a||void 0===a?void 0:a.unit;const i=te("operators",e.operator,n);t.operator=i?`${i.name} ${i.surname}`:"";const r=e&&e.reasons&&e.reasons.find(e=>!0===e.applied);r&&(t.phi=r.phi,t.dosageUnit=r.dosageUnit,t.dosage=r.dosage?r.dosage.toLocaleString(y):"")}if(t.reasonsString="",e.reasons){const a=e.reasons.length;e.reasons.map((e,n)=>{const i=ae(e.target,l);return t.reasonsString=t.reasonsString.concat(i),nnew Date(t.date)-new Date(e.date))),u.mostRecent=u.rows&&u.rows.slice(0,s),u.headCells=r?[{id:"date",combine:[{id:"date",opacity:1},{id:"tradeName",opacity:.6}],numeric:!1,disablePadding:!1,label:"Date"},{id:"totalVolume",combine:[{id:"totalVolume",opacity:1}],numeric:!0,disablePadding:!1,label:"( per block)"}]:[{id:"date",numeric:!1,disablePadding:!1,label:"Date"},{id:"endTime",numeric:!1,disablePadding:!1,label:"End time"},{id:"reasonsString",numeric:!1,disablePadding:!1,label:"Target"},{id:"tradeName",numeric:!1,disablePadding:!1,label:"Trade name"},{id:"activeIngredient",numeric:!1,disablePadding:!1,label:"Active Ingredient",minWidth:"150px"},{id:"dosage",numeric:!0,disablePadding:!1,label:"Dosage"},{id:"dosageUnit",numeric:!1,disablePadding:!1,label:"Dosage unit"},{id:"chemEquipsString",numeric:!1,disablePadding:!1,label:"Equipment"},{id:"phi",numeric:!1,disablePadding:!1,label:"PHI (days)"},{id:"phiLapse",numeric:!1,disablePadding:!1,label:"Withholding period end"},{id:"totalVolume",numeric:!0,disablePadding:!1,label:"Total volume (L)"},{id:"weather",numeric:!1,disablePadding:!1,label:"Weather"},{id:"operator",numeric:!1,disablePadding:!1,label:"Operator"},{id:"advisor",numeric:!0,disablePadding:!1,label:"Advisor"}],u.title="Plant Protection Applications",!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),nt(b,u.headCells,0,r),u}case"harvestings":{const a=n("harvestequips");let i=t[e]?t[e]:[];if(d&&m&&(i=i.filter(e=>e.date>=d&&e.date<=m)),0===i.length)return u;const l=(e,t)=>{try{return new Date(e.date).toLocaleString(t)}catch(a){return console.error("Locale error:",a.message),new Date(e.date).toLocaleString("en-US")}};u.rows=i?i.map(e=>{const t={...e};t.harvestTotalNoUnit=t.harvestTotal;const i=l(e.date,y);t.date=i.substring(0,i.indexOf(",")),t.dater=ht(e.date),console.log("harvestDate - ",new Date(e.date).toLocaleString(y)),t.harvestTotal=t.harvestTotal+" kg",t.createTime=gt(t.createdAt),t.clientTime=gt(t.clientCreateDate),t.harvestUnits=t.harvestUnits?t.harvestUnits:0;const s=te("operators",e.operator,n);return t.operator=s?`${s.name} ${s.surname}`:"",!r&&g&&(t.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:""),at(b,t,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName),t.equipName=e.harvestEquip?e.totalHarvestOverride?ae(e.harvestEquip,a)+" (override)":ae(e.harvestEquip,a):"override",t}):[],p||(u.rows=u.rows&&u.rows.sort((e,t)=>new Date(e.createdAt)-new Date(t.createdAt))),u.mostRecent=u.rows&&u.rows.slice(0,s);const o=u.rows.reduce((e,t)=>e+(t.harvestUnits?1*t.harvestUnits:0),0).toLocaleString(),c=(u.rows.reduce((e,t)=>e+parseFloat(t.harvestTotalNoUnit),0)/1e3).toLocaleString(y)+" t";if(u.headCells=r?[{id:"dater",combine:[{id:"date",opacity:1},{id:"equipName",opacity:.6},{id:"harvestUnits",opacity:.6,postfix:"units"}],numeric:!1,disablePadding:!1,label:"Date"},{id:"harvestTotal",combine:[{id:"harvestTotal",opacity:1}],numeric:!0,disablePadding:!1,label:"Total"}]:[{id:"dater",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"equipName",numeric:!1,disablePadding:!1,label:"Equipment"},{id:"harvestUnits",numeric:!0,disablePadding:!1,label:"Units"},{id:"harvestTotal",numeric:!0,disablePadding:!1,label:"Harvested"},{id:"deliveryNote",numeric:!0,disablePadding:!1,label:"Delivery Note"},{id:"operator",numeric:!0,disablePadding:!1,label:"Operator"},{id:"clientTime",numeric:!1,disablePadding:!1,label:"Time stamp"}],u.title="Harvest Records",!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),nt(b,u.headCells,0,r),!r){let e={};e=b?{strong:!0,blockNumber:"Total",duration:"",harvestTotalNoUnit:0,volumePerHour:"",harvestUnits:o,harvestTotal:c}:{strong:!0,date:"Total",duration:"",harvestTotalNoUnit:0,volumePerHour:"",harvestUnits:o,harvestTotal:c},u.rows.push(e),u.rows.push({blockNumber:" ",date:" ",harvestTotalNoUnit:0})}return u}case"packings":{const a=n("packequips");let i=t[e]?t[e]:[];return d&&m&&(i=i.filter(e=>e.date>=d&&e.date<=m)),u.rows=i?i.map(e=>{const t={...e};t.equipName=ae(e.packEquip,a),t.wastepName=ae(e.wasteEquip,a),t.packTotal=t.packTotal+" kg",!r&&g&&(t.updatedBy=e.createdByDetail?`${e.createdByDetail.name} ${e.createdByDetail.surname} ${new Date(parseInt(e.createdAt)).toLocaleString()}`:""),t.wasteTotal=t.wasteTotal+" kg",at(b,t,u.blockNumber,u.plantingLabel,u.plantingName,u.plantingSK,u.blockSK,u.cropName,u.varietyName);const n=(e.packTotal-e.wasteTotal)/e.packTotal*100;return t.conversionRatio=n.toFixed(1)+" %",t}):[],p||(u.rows=u.rows&&u.rows.sort((e,t)=>new Date(t.date)-new Date(e.date))),u.mostRecent=u.rows&&u.rows.slice(0,s),u.headCells=r?[{id:"date",combine:[{id:"date",opacity:1},{id:"equipName",opacity:.6},{id:"packUnits",opacity:.6,postfix:"units"}],numeric:!1,disablePadding:!1,label:"Date"},{id:"packTotal",combine:[{id:"packTotal",opacity:1}],numeric:!0,disablePadding:!1,label:"Total"}]:[{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"wastepName",numeric:!1,disablePadding:!1,label:"Waste Equipment"},{id:"wasteUnits",numeric:!0,disablePadding:!1,label:"Units"},{id:"wasteTotal",numeric:!0,disablePadding:!1,label:"Waste Total"},{id:"equipName",numeric:!1,disablePadding:!1,label:"Equipment"},{id:"packUnits",numeric:!0,disablePadding:!1,label:"Units"},{id:"packTotal",numeric:!0,disablePadding:!1,label:"Pack Total"},{id:"conversionRatio",numeric:!0,disablePadding:!1,label:"Conversion Ratio"},{id:"consignment",numeric:!0,disablePadding:!1,label:"Consignment Note"},{id:"deliveryNote",numeric:!0,disablePadding:!1,label:"Delivery Note"},{id:"destination",numeric:!0,disablePadding:!1,label:"Destination"}],u.title="Packing Records",!r&&g&&u.headCells.push({id:"updatedBy",numeric:!1,disablePadding:!1,fontSize:"9px",label:"Updated by"}),nt(b,u.headCells,0,r),u}default:return u}}const bt=We.RECENTS_LEN;function vt(e){const{recordType:t,planting:a,handleSelect:n,getFromGlobalState:r,block:l,clean:s,displayToolbar:o,noPagination:c,hideHeader:d,handleAddItem:m,selectedRow:p,showAll:h}=e;let g=ut(t,a,l,r,s,0,bt,void 0,void 0,void 0,void 0,void 0,void 0,!0);const u=r("userDetail");return i.a.createElement("div",null,i.a.createElement(Me,{displayToolbar:o,noPagination:c,hideHeader:d,heading:g.title,rows:h?g.rows:g.mostRecent,headCells:g.headCells,handleSelect:n,handleAddItem:u&&u.rights&&!u.rights.readOnly?m:null,parent:a,grandParentSK:l.sk,actionType:"actionType",rowKeyName:"sk",recordType:t,clean:s,selectedRow:p}))}var yt=a(1737),ft=a(1741),Et=a(1739),St=a(1738),Ct=a(672),xt=a(1712),kt=a(1743),wt=a(339),Tt=a.n(wt),Dt=a(196),Pt=a.n(Dt),Ft=a(195),Nt=a.n(Ft),Bt=a(782),Lt=a(427),At=a.n(Lt),Ot=a(340),It=a.n(Ot),Gt=a(36),Rt=a.n(Gt),Ut=a(1740),Mt=({isloading:e,text:t,loadingText:a,className:n="",disabled:r=!1,size:l=12,...s})=>i.a.createElement(Ct.a,Object.assign({disabled:r||e},s),e&&i.a.createElement(P.a,{className:n,size:l}),e?a:t);var Wt=Object(v.a)(e=>({submit:{margin:e.spacing(1)}}),{withTheme:!0})((function(e){const{open:t,handleConfirm:a,handleCancel:n,title:r,message:l,classes:s,loading:o,actionText:c}=e;return i.a.createElement("div",null,i.a.createElement(yt.a,{open:t,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description"},i.a.createElement(St.a,{id:"alert-dialog-title"},r),i.a.createElement(Et.a,null,l&&i.a.createElement(Ut.a,{id:"alert-dialog-description"},l)),i.a.createElement(ft.a,null,i.a.createElement(Mt,{onClick:a,variant:"contained",color:"primary",className:s.submit,disabled:o,isloading:o,text:c||"Delete",loadingText:c?c+"..":"Deleting.."}),i.a.createElement(Ct.a,{onClick:n,color:"secondary",variant:"contained",className:s.submit,disabled:o},"Cancel"))))})),zt=a(673);var Kt=Object(v.a)(e=>({submit:{margin:e.spacing(1)}}),{withTheme:!0})((function(e){const{open:t,handleConfirm:a,handleCancel:n,title:r,startDate:l,endDate:s,classes:o,loading:c,handleSetStartDate:d,handleSetEndDate:m,averaged:p,averagedChecked:h,handleSetAveraged:g}=e;return i.a.createElement("div",null,i.a.createElement(yt.a,{open:t,onClose:n,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description"},i.a.createElement(St.a,{id:"alert-dialog-title"},r),i.a.createElement(Et.a,null,i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"startDate",label:"Start Date",name:"startDate",InputLabelProps:{shrink:!0},value:l,onChange:d}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"endDate",label:"End Date",name:"endDate",InputLabelProps:{shrink:!0},value:s,onChange:m}),p&&g&&i.a.createElement(i.a.Fragment,null,i.a.createElement(I.a,{title:"Results are averaged and gouped"},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:h,onChange:g,name:"checkedB",color:"secondary"}),label:"Averaged"}))," ")),i.a.createElement(ft.a,null,i.a.createElement(Mt,{onClick:a,variant:"contained",color:"primary",className:o.submit,disabled:c,isloading:c,text:"Submit",loadingText:"Generating."}),i.a.createElement(Ct.a,{onClick:n,color:"secondary",variant:"contained",className:o.submit,disabled:c},"Cancel"))))})),Ht=a(797),qt=a.n(Ht),Vt=a(426),jt=a.n(Vt),$t=a(799),Yt=a.n($t),_t=a(275),Zt=a(1742),Jt=a(1710),Qt=a(798),Xt=a.n(Qt);const ea={success:qt.a,warning:Xt.a,error:jt.a,info:Yt.a},ta=Object(z.a)(e=>({success:{backgroundColor:K.a[600]},error:{backgroundColor:e.palette.error.dark},info:{backgroundColor:_t.a[600]},warning:{backgroundColor:me.a[700]},icon:{fontSize:20},iconVariant:{opacity:.9,marginRight:e.spacing(1)},message:{display:"flex",alignItems:"center"}}));function aa(e){const t=ta(),{className:a,message:n,onClose:r,variant:l,...s}=e,o=ea[l];return i.a.createElement(Jt.a,Object.assign({className:Object(x.a)(t[l],a),"aria-describedby":"client-snackbar",message:i.a.createElement("span",{id:"client-snackbar",className:t.message},i.a.createElement(o,{className:Object(x.a)(t.icon,t.iconVariant)}),n),action:[i.a.createElement(E.a,{key:"close","aria-label":"close",color:"inherit",onClick:r},i.a.createElement(Tt.a,{className:t.icon}))]},s))}const na=Object(z.a)(e=>({margin:{margin:e.spacing(1)}}));function ia(e){const t=na(),{open:a,messageText:n,setClose:r,variant:l,id:s,position:o,autoHideDuration:c,vertical:d,horizontal:m}=e;if(!a)return null;function p(e,t){"clickaway"!==t&&r()}return i.a.createElement("div",null,i.a.createElement(Zt.a,{id:s,anchorOrigin:{vertical:d,horizontal:m},open:a,autoHideDuration:c,onClose:p},i.a.createElement(aa,{onClose:p,variant:l,className:t.margin,message:n})))}ia.defaultProps={autoHideDuration:6e5,vertical:"bottom",horizontal:"left"};const ra=Object(z.a)(e=>({root:{display:"flex",alignItems:"center",color:"inherit"},wrapper:{position:"relative",color:"inherit"},fabProgress:{color:e.palette.secondary.main,position:"absolute",top:12,left:0,zIndex:1}}));function la(e){const t=ra(),{loading:a,success:n,onClick:r,disabled:l,icon:s}=e,o=Object(x.a)({[t.buttonSuccess]:n});return i.a.createElement("div",{className:t.root},i.a.createElement("div",{className:t.wrapper},i.a.createElement(E.a,{edge:"start",color:"inherit",onClick:r,className:o,"aria-label":"save",disabled:l},n?s:i.a.createElement(jt.a,null)),a&&i.a.createElement(P.a,{size:24,className:t.fabProgress})))}var sa={Read:{static:["posts:list","home-page:visit"]},changeSettings:{static:["openSettingsPage","openDocumentsPage","openPlantingPage"]},manageInventory:{static:["openInventoryPage"]},viewDashboard:{static:["viewDashboard","viewReports"]},createActivities:{static:["createActivities"]},allowedActivities:{static:["fertilisings","sprayings","waterings","harvestings","pestings","activities"]},Admin:{static:["fertilisings","accessSettings","editFolders","editAsset","submitDialogs","deleteAsset","accessDashboard"]}};const oa=e=>((e,t,a,n,i)=>{if("administrator"===t)return!0;if(i)return!0;const r=e[t];if(!r)return!1;const l=r.static;if(l&&l.includes(a))return!0;const s=r.dynamic;if(s){const e=s[a];return!!e&&e(n)}return!1})(sa,e.role,e.perform,e.data,e.isAdministrator)?e.yes():e.no();oa.defaultProps={yes:()=>null,no:()=>null,isAdministrator:!1};var ca=oa,da=a(869);const ma=new class{async open(e){return await Object(da.a)(e,5,{upgrade(e,t,a){switch(console.log("got db",t,"new",a),t){case 0:console.log("executing version 0");case 1:e.createObjectStore("farms",{keyPath:"sk"}),console.log("executing version 1");case 2:e.createObjectStore("calls",{keyPath:"id",autoIncrement:!0}),console.log("executing version 2");case 3:e.deleteObjectStore("calls"),console.log("executing version 3"),e.createObjectStore("calls",{keyPath:"sk"});case 4:console.log("executing version 4"),e.createObjectStore("defaults",{keyPath:"sk"})}}})}async put(e,t,a,n){try{let i=await this.getAll(e,t,n);if(i){const e=i.records.findIndex(e=>e.sk===a.sk);-1!==e?i.records[e]=a:i.records.push(a)}else i={records:[a],sk:n};const r=(await this.open(e)).transaction(t,"readwrite");r.store.put(i),await r.done}catch(i){throw console.log("put error caught",i),i}}async putFlat(e,t,a){try{const n=(await this.open(e)).transaction(t,"readwrite");n.store.put(a),await n.done}catch(n){throw console.log("put error caught",n),n}}async delete(e,t,a,n){try{let i=await this.getAll(e,t,n);if(i){const n=i.records.findIndex(e=>e.sk===a.sk);-1!==n&&i.records.splice(n,1);const r=(await this.open(e)).transaction(t,"readwrite");r.store.put(i),await r.done}}catch(i){throw console.log("put error caught",i),i}}async delete2(e,t,a){try{const n=(await this.open(e)).transaction(t,"readwrite");n.store.delete(a),await n.done}catch(n){throw console.log("delete error caught",n),n}}async replaceAll(e,t,a,n){try{const i=(await this.open(e)).transaction(t,"readwrite");i.store.delete(a),i.store.put(n),await i.done}catch(i){throw console.log("replaceAll error caught",i),i}}async getAll(e,t,a){try{let n=a;if(!n){const t=await this.getAllFlat(e,"defaults");t&&t.length>0&&(n=t[0].activeSite)}const i=await this.open(e);return await i.get(t,n)}catch(n){throw console.log("getAll error caught",n),n}}async getAllFlat(e,t){try{const a=await this.open(e);return await a.getAll(t)}catch(a){throw console.log("getAll error caught",a),a}}},pa="timeout of 7000ms exceeded",ha={timeout:3e4};async function ga(e){const t=e.filter(e=>"blocks"===e.type),a=e.filter(e=>"plantings"===e.type),n=e.filter(e=>"waterings"===e.type),i=e.filter(e=>"pestings"===e.type),r=e.filter(e=>"fertilisings"===e.type),l=e.filter(e=>"sprayings"===e.type),s=e.filter(e=>"harvestings"===e.type),o=e.filter(e=>"packings"===e.type),c=e.filter(e=>"activities"===e.type),d=e.filter(e=>"allFarms"===e.type);t.forEach(e=>{e.plantings=a.filter(t=>t.sk.startsWith(e.sk)),e.plantings||(e.plantings=[]),a.forEach(e=>{const t=e.sk;e.waterings=n&&n.filter(e=>e.sk.startsWith(t)),e.pestings=i&&i.filter(e=>e.sk.startsWith(t)),e.fertilisings=r&&r.filter(e=>e.sk.startsWith(t)),e.sprayings=l&&l.filter(e=>e.sk.startsWith(t)),e.harvestings=s&&s.filter(e=>e.sk.startsWith(t)),e.packings=o&&o.filter(e=>e.sk.startsWith(t)),e.activities=c&&c.filter(e=>e.sk.startsWith(t))})});let m=e.filter(e=>"crops"===e.type);const p=e.filter(e=>"varieties"===e.type);m||(m={}),m.forEach(e=>{e.varieties=p.filter(t=>t.sk.startsWith(e.sk)),e.varieties||(e.varieties=[])});let h=e.filter(e=>"gen_crops"===e.type),g=e.filter(e=>"gen_varieties"===e.type);h||(h=[]),g||(g=[]);let u=e.filter(e=>"farm"===e.type);u||(u=[],u.push({}));let b=e.filter(e=>"chemicals"===e.type);const v=e.filter(e=>"chemcrops"===e.type),y=e.filter(e=>"chemcropsTargets"===e.type);b||(b={}),b.forEach(e=>{e.chemcrops=v.filter(t=>t.sk.startsWith(e.sk)),e.chemcrops||(e.chemcrops=[]);for(let t=0;ta.sk.startsWith(e.chemcrops[t].sk))});let f=e.filter(e=>"chemequips"===e.type);f||(f=[]);let E=e.filter(e=>"harvestequips"===e.type);E||(E=[]);let S=e.filter(e=>"clusters"===e.type);S||(S=[]);let C=e.filter(e=>"farms"===e.type);C||(C=[]);let x=e.filter(e=>"packequips"===e.type);x||(x=[]);let k=e.filter(e=>"operators"===e.type);k||(k=[]);let w=e.filter(e=>"agronomistActs"===e.type);w||(w=[]);let T=e.filter(e=>"fertilisers"===e.type);const D=e.filter(e=>"fertcrops"===e.type);T||(T={}),T.forEach(e=>{e.fertcrops=D.filter(t=>t.sk.startsWith(e.sk)),e.fertcrops||(e.fertcrops=[])});let P=e.filter(e=>"pests"===e.type);P||(P=[]);let F=e.filter(e=>"monitorings"===e.type);F||(F=[]);let N=e.filter(e=>"facilities"===e.type);N||(N=[]);let B=e.filter(e=>"targetsTypesSetting"===e.type);B=B&&B.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),B||(B=[]);let L=e.filter(e=>"cropTypesSetting"===e.type);L=L&&L.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),L||(L=[]);let A=e.filter(e=>"cropsSetting"===e.type);A=A&&A.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),A||(A=[]);let O=e.filter(e=>"productProcessorTypes"===e.type);O=O&&O.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),O||(O=[]);let I=e.filter(e=>"productProcessors"===e.type);I=I&&I.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),I||(I=[]);let G=e.filter(e=>"combinations"===e.type);G=G&&G.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),G||(G=[]);let R=e.filter(e=>"filters"===e.type);R=R&&R.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),R||(R=[]);let U=e.filter(e=>"myProductProcessors"===e.type);U=U&&U.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),U||(U=[]);const M=e.filter(e=>"monitorStations"===e.type);F.forEach(e=>{e.monitorStations=M.filter(t=>t.sk.startsWith(e.sk)),e.monitorStations||(e.monitorStations=[])});let W=e.filter(e=>"monitoringsOther"===e.type);W||(W=[]);const z=e.filter(e=>"monitorOtherStations"===e.type);W.forEach(e=>{e.monitorStations=z.filter(t=>t.sk.startsWith(e.sk)),e.monitorStations||(e.monitorStations=[])});let K=e.filter(e=>"irrigations"===e.type);K||(K=[]);let H=e.filter(e=>"apiKeys"===e.type);H||(H=[]);let q=e.filter(e=>"transaction"===e.type);q||(q=[]);let V=e.filter(e=>"subscription"===e.type);console.log(V,"subscription"),V||(V=[]);let j=e.filter(e=>"inv_chemical"===e.type);j||(j=[]);let $=e.filter(e=>"inv_fertiliser"===e.type);$||($=[]);let Y=e.filter(e=>"users"===e.type);Y||(Y=[]);let _=e.filter(e=>"folders"===e.type);_||(_=[]);let Z=e.filter(e=>"files"===e.type);Z||(Z=[]);let J=e.filter(e=>"invite"===e.type);J||(J=[]);let Q=e.filter(e=>"SentInvite"===e.type);Q||(Q=[]);let X=e.filter(e=>"SentSharedInvite"===e.type);X||(X=[]),console.log("this are invites->",J,Q,X);let ee=e.filter(e=>"siteAccess"===e.type);ee||(ee=[]);let te=null;if(ee.length>0){const e=ee.find(e=>e.default);te=e?e.tenantId:ee[ee.length-1].tenantId}else e.filter(e=>"farm"===e.type)[0]&&(te=e.filter(e=>"farm"===e.type)[0].activeTenant);return{blocks:t,crops:m,farm:u,chemicals:b,fertilisers:T,pests:P,monitorings:F,monitoringsOther:W,irrigations:K,chemequips:f,harvestequips:E,clusters:S,packequips:x,operators:k,agronomistActs:w,inv_chemical:j,inv_fertiliser:$,users:Y,farms:C,transactions:q,invites:J,siteList:ee,activeSite:te,sentInvites:Q,sentSharedInvites:X,folders:_,files:Z,myGenCrops:h,subscription:V,genVarieties:g,targetsTypesSetting:B,cropTypesSetting:L,cropsSetting:A,facilities:N,productProcessorTypes:O,productProcessors:I,myProductProcessors:U,filters:R,apiKeys:H,combinations:G,allFarms:d}}function ua(e,t){if(t){const{...t}=e;return t}switch(e.type){case"blocks":{const{plantings:t,...a}=e;return a}case"plantings":{const{waterings:t,pestings:a,fertilisings:n,sprayings:i,harvestings:r,...l}=e;return l}case"farm":{const{...t}=e;return t}case"chemicals":{const{...t}=e;return t}case"chemequips":{const{...t}=e;return t}case"fertilisers":{const{...t}=e;return t}case"pests":{const{...t}=e;return t}case"monitorings":{const{...t}=e;return t}case"irrigations":{const{...t}=e;return t}default:{const{...t}=e;return t}}}function ba(e,t,a,n,i,r){const l=a("blocks"),s=l.findIndex(e=>e.sk===i);if(-1===s)return void alert("impossible - we don't have this block!");const{plantings:o}=l[s],c=l[s].plantings.findIndex(e=>e.sk===r),d=o[c][e.type],m=d?o[c][e.type].findIndex(t=>t.sk===e.sk):-1;var p;-1===m?(d||(l[s].plantings[c][e.type]=[]),(null===(p=e.items||[])||void 0===p?void 0:p.length)>=1?(e.items.filter(t=>t.type===e.type).map(t=>{l[s].plantings[c][e.type].push(t)}),console.log("new records ->",l[s].plantings[c][e.type])):l[s].plantings[c][e.type].push(e),n({blocks:l})):(l[s].plantings[c][e.type][m]=e,n({blocks:l}))}async function va(e,t,a){console.log("replaying cache");let n={};try{const i=await ma.getAll(e,t,a);if(i&&i.records)for(const r of i.records)if(!r.payload.syncError){n=r,r.payload.cached=!1,r.payload.syncError=!1,r.payload.syncMessage="";await o.a[r.method](r.api,r.route,{body:r.payload,timeout:r.params.timeout});await ma.put(e,"farms",r.payload,a),await ma.delete(e,t,r,a)}}catch(i){if("Network Error"===i.message||i.message===pa)return void console.log("Synch failed - network");if(i.response&&i.response.data&&"Update failed"===i.response.data.error.substring(0,13)){console.log("Synch failed - conflict"),n.payload.cached=!0,n.payload.syncError=!0,n.syncError=!0,n.syncMessage=i.response.data.error,await ma.put(e,t,n,a),i.response.data.error="Syncronisation failure: "+i.response.data.error,i.message="Syncronisation failure";const r={...n.payload};throw r.cached=!0,r.syncError=!0,await ma.put(e,"farms",r,a),i}throw console.log("replayCache exception caught",i),i.response&&i.response.data.error.message?i.response.data.error.message="Syncronisation failure: "+i.response.data.error.message:i.message&&(i.message="Syncronisation failure: "+i.message),i}}async function ya(e,t,a,n){console.log("api post from Storage");let i={status:!1,online:!0};try{await va(e,"calls",n),"apiKeys"===a.type?await o.a.post("farms","/apiKey",{body:a,timeout:3e4}):await o.a.post("farms","/farms",{body:a,timeout:3e4}),await ma.put(e,"farms",a,n),i={status:!0,online:!0,cached:!1}}catch(r){if(console.log("caught here"),"Network Error"!==r.message&&r.message!==pa)throw r;{console.log("failed to create object, storing request locally");const r={stamp:(new Date).valueOf(),sk:Rt.a.v1(),method:"post",api:"farms",route:"/farms",params:ha,syncError:!1,syncMessage:"",payload:a};await ma.put(e,t,r,n);const l={...a};l.cached=!0,await ma.put(e,"farms",l,n),i={status:!0,online:!1,cached:!0}}}return i}async function fa(e,t,a,n){console.log("api post from Storage - Batch");let i={status:!1,online:!0};try{await va(e,"calls",n),await o.a.post("farms","/batchCreate",{body:a,timeout:3e4});for(const t of a.items)await ma.put(e,"farms",t,n);i={status:!0,online:!0,cached:!1}}catch(r){if(console.log("caught here"),"Network Error"!==r.message&&r.message!==pa)throw r;{console.log("failed to create object, storing request locally");const r={stamp:(new Date).valueOf(),method:"post",api:"farms",route:"/batchCreate",params:ha,syncError:!1,syncMessage:"",payload:a};await ma.put(e,t,r,n);const l={...a};for(const t of l.items)t.cached=!0,await ma.put(e,"farms",t,n);i={status:!0,online:!1,cached:!0}}}return i}function Ea(){return console.log("api get from Storage"),o.a.get("farms","/listSites",ha)}function Sa(e){return console.log("api get from Storage"),o.a.post("farms","/subscribe/update",{body:e})}function Ca(e){return console.log("api get from Storage"),fetch(e)}function xa(e,t,a=null,n=null){return console.log("api get from Storage"),o.a.get("farms",`/adminSettings/${e}?selection=${t}&filter=${a||""}&filterValue=${n||""}`,ha)}function ka(e){return console.log("api post from Storage"),o.a.del("farms","/farms",{body:e})}function wa(e){return console.log("api post from Storage"),o.a.post("farms","/archive",{body:e})}function Ta(e){return console.log("api post from Storage"),o.a.post("farms","/tenant",{body:e})}function Da(e){return console.log("api post from Storage"),o.a.post("farms","/user",{body:e})}function Pa(e){if(!e)return"";if(e.response&&e.response.data){if(e.response.data.error){if(e.response.data.error&&"string"===typeof e.response.data.error.valueOf())return e.response.data.error;if(e.response.data.error.message)return e.response.data.error.message;if(e.response.data.error.message)return e.response.data.error}if(e.response.data.message)return e.response.data.message}return e.message?e.message:"Unknown error"}function Fa(e){return console.log("api post from storage"),o.a.post("farms","/downloadUrl",{body:e})}async function Na(e,t,a){console.log("synchronise api get from Storage");let n=a,i={status:!1,records:[],updateStatus:!1,recordsUpdated:[]};try{n&&await va(e,"calls",n),n||(n="default");const a=await o.a.get("farms","/farmsList/"+n,{...ha}),r=await async function(e){try{const t=await fetch(e),a=await t.text(),n=JSON.parse(a),i={status:!0,records:n,updateStatus:!1,recordsUpdated:[]};return console.log("Data Object:",i),n}catch(t){throw console.error("Error fetching or parsing data:",t),t}}(a);if(i.records=r,i.records&&i.records.industryView)return i;null===n&&i.records.length>0&&(n=i.records[0].farmId);const l={records:i.records,sk:n};await ma.replaceAll(e,t,n,l);const s=l.records.filter(e=>"siteAccess"===e.type);let c=null;if(s&&s.length>0){const e=s.find(e=>e.default);c=e?e.tenantId:s[s.length-1].tenantId}const d={sk:e,activeSite:n};await ma.putFlat(e,"defaults",d),i.status=!0}catch(r){if("Network Error"===r.message||r.message===pa)return console.log("failed to synchronise return offline",r),i=await ma.getAll(e,"farms",n),i?i.status=!0:i={records:[],status:!0},i;if("Syncronisation failure"===r.message)return i.status=!0,i=await ma.getAll(e,"farms",n),i.message="Your synchroniation failed. They are marked with an error.",i;if(""===r.message)return i.status=!0,i.records=[],i;throw console.log("Exception caught could not synchronise recods",r),r}return i}async function Ba(e,t,a,n,i){if(!n)return null;const r=e("targetDetail");if(r&&r[n]&&r[n][i])return r[n][i];try{const a=e("activeSite"),l=await xa(a,n.concat("_"),"observableOn",i),s={...r};return s[n]||(s[n]={}),s[n][i]||(s[n][i]={}),s[n][i]=l,t({targetDetail:s}),s[n][i]}catch(l){return a({open:!0,variant:"error",messageText:Pa(l)}),!1}}async function La(e,t,a,n,i){if(!n)return null;const r=e("genCrops"),l=e("cropsDetail");if(r&&r[n]&&r[n].length&&l&&l[n]&&l[n].length)return{fromCache:!0,crops:r[n],cropsDetail:l[n]};let s=e("activeSite");""!==s&&s||(s="default");try{const e=await xa(s,n.concat("_"));let a=e.filter(e=>"cropsSetting"===e.type);a=a&&a.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1}));let i=e.filter(e=>"cropsDetail"===e.type);i=i&&i.sort((e,t)=>(""+e.name).localeCompare(t.rootStock,void 0,{numeric:!1}));const o={...r};o[n]=a;const c={...l};return c[n]=i,t({genCrops:o}),t({cropsDetail:c}),{crops:o[n],cropsDetail:c[n]}}catch(o){return a({open:!0,variant:"error",messageText:Pa(o)}),!1}}const Aa=i.a.forwardRef((e,t)=>i.a.createElement(xt.a,Object.assign({direction:"left",ref:t},e)));i.a.forwardRef((e,t)=>i.a.createElement(xt.a,Object.assign({direction:"up",ref:t},e)));class Oa extends n.Component{constructor(e){super(e),this.setSnackClose=()=>{this.setState({messageText:"",success:!0})},this.confirmDelete=()=>{this.setState({confirmDeleteOpen:!0})},this.confirmReinviteopen=()=>{this.setState({confirmReInvite:!0})},this.generatePDF=()=>{this.setState({dateRangeDialogOpen:!0,reportType:"pdf"})},this.generateCSV=()=>{this.setState({dateRangeDialogOpen:!0,reportType:"csv"})},this.handleCancelGeneratePDF=()=>{this.setState({dateRangeDialogOpen:!1,reportType:""})},this.handleCancelGenerateCSV=()=>{this.setState({dateRangeDialogOpen:!1,reportType:""})},this.handleCancelConfirmDialog=()=>{this.setState({confirmDeleteOpen:!1})},this.cancelReinvite=()=>{this.setState({confirmReInvite:!1})},this.setReportStartDate=e=>{this.setState({reportStartDate:e.target.value})},this.setReportEndDate=e=>{this.setState({reportEndDate:e.target.value})},this.handleGeneratePDF=()=>{this.props.onGeneratePDF(this.state.reportStartDate,this.state.reportEndDate),this.setState({dateRangeDialogOpen:!1,reportType:""})},this.handleGenerateCSV=()=>{this.props.onGenerateCSV(this.state.reportStartDate,this.state.reportEndDate),this.setState({dateRangeDialogOpen:!1,reportType:""})},this.handleReinvite=async()=>{try{this.setState({isDeleting:!0}),this.setState({messageText:""});const e=this.props.getFromGlobalState("activeSite"),t={...this.props.dialogObject,activeTenant:e};return await async function(e){return console.log("api post from storage"),o.a.post("farms","/deleteRejectedInvitation",{body:e})}(t),null===t||void 0===t||delete t.rejected,await Da(t),this.props.handleDeleteDialogObject(t,this.props.parentKey),this.setState({isDeleting:!1}),this.setState({success:!0}),this.handleCancelConfirmDialog(),this.props.setClose(),void this.props.setSnack({open:!0,variant:"info",autoHideDuration:4e3,messageText:"User re-invitation sent. You can view the user post acceptance."})}catch(u){var e,t,a,n,i,r,l,s,c,d,m,p,h,g;this.handleCancelConfirmDialog(),this.props.setSnack({open:!0,variant:"error",message:u.response?`${(null===(e=u.response.data)||void 0===e||null===(t=e.error)||void 0===t?void 0:t.message)?null===(a=u.response.data)||void 0===a||null===(n=a.error)||void 0===n?void 0:n.message:null===(i=u.response)||void 0===i||null===(r=i.data)||void 0===r?void 0:r.error}, api src: ${null===(l=u.response)||void 0===l||null===(s=l.data)||void 0===s?void 0:s.src} `:u.message}),this.setState({success:!1,isDeleting:!1,messageText:u.response?""+((null===(c=u.response.data)||void 0===c||null===(d=c.error)||void 0===d?void 0:d.message)?null===(m=u.response.data)||void 0===m||null===(p=m.error)||void 0===p?void 0:p.message:null===(h=u.response)||void 0===h||null===(g=h.data)||void 0===g?void 0:g.error):null===u||void 0===u?void 0:u.message})}},this.handleDelete=async e=>{this.setState({isDeleting:!0}),this.setState({messageText:""});try{const e={...this.props.dialogObject};if(this.props.isNew)return;let t=!0;if(this.props.handleDeletePreExecute?t=await this.props.handleDeletePreExecute(e):!this.props.handleDeletePreExecuteOnly&&this.props.handlePreExecute&&(t=await this.props.handlePreExecute(e)),t&&!this.props.handleDeletePreExecuteOnly){const t=this.props.getFromGlobalState("activeSite");await wa({sk:e.sk,archiveName:"trash",type:e.type,activeTenant:t})}this.props.handleDeleteDialogObject(e,this.props.parentKey),this.setState({isDeleting:!1}),this.setState({success:!0}),this.handleCancelConfirmDialog(),this.props.setClose()}catch(o){var t,a,n,i,r,l,s;this.handleCancelConfirmDialog(),this.setState({success:!1,isDeleting:!1,messageText:o.response?""+((null===(t=o.response)||void 0===t||null===(a=t.data)||void 0===a||null===(n=a.error)||void 0===n?void 0:n.message)?null===(i=o.response.data)||void 0===i||null===(r=i.error)||void 0===r?void 0:r.message:null===(l=o.response)||void 0===l||null===(s=l.data)||void 0===s?void 0:s.error):null===o||void 0===o?void 0:o.message})}},this.handleSubmit=async(e,t)=>{!this.props.rejectedUser&&e.preventDefault();const a=[];if(this.props.preExecuteOnly){this.setState({isSubmitting:!0});const e=await this.props.handlePreExecute(t);e.status?(this.setState({isSubmitting:!1}),this.props.setClose()):this.setState({success:!1,isSubmitting:!1,messageText:e.errorMSG})}else if(this.props.noServerInteraction)this.props.handleUpdateDialogObject(t,this.props.parentKey);else{this.setState({isSubmitting:!0}),this.setState({messageText:""});try{const e=this.props.getFromGlobalState("userDetail");let t={...this.props.dialogObject};const i={};if(this.props.batchInserting){let a=[];for(const n of t.items){console.log("item",n);const t={...n.record};if(((null===t||void 0===t?void 0:t.combinations)||[]).length>=1){const i=t.combinations.map(t=>(delete t.combinations,{...t,sk:n.planting.concat(this.props.skPrimary.concat(Rt.a.v1())),clientCreateDate:(new Date).valueOf(),createdAt:(new Date).valueOf(),clientTime:(new Date).valueOf(),createdByDetail:e?{sk:e.sk,email:(null===e||void 0===e?void 0:e.email)?null===e||void 0===e?void 0:e.email:"",name:null===e||void 0===e?void 0:e.name,surname:e.surname}:void 0,version:0}));console.log("combsRecords",i),a=[...a,...i],console.log("recordList",a),n.record=t}else t.sk=n.planting.concat(this.props.skPrimary.concat(Rt.a.v1())),t.type=this.props.dynamoType,t.clientCreateDate=(new Date).valueOf(),t.createdAt=t.clientCreateDate,t.clientTime=t.clientCreateDate,t.createdByDetail=e?{sk:e.sk,email:(null===e||void 0===e?void 0:e.email)?null===e||void 0===e?void 0:e.email:"",name:null===e||void 0===e?void 0:e.name,surname:e.surname}:void 0,t.version=0,a.push(t),n.record={...t}}i.type=this.props.dynamoType,i.items=a,i.activeTenant=this.props.getFromGlobalState("activeSite"),i.sk=Rt.a.v1(),console.log("recordsObject",i)}else this.props.isNew&&(this.props.parentKey?t.sk=this.props.parentKey.concat(this.props.skPrimary.concat(Rt.a.v1())):t.sk=this.props.skPrimary.concat(Rt.a.v1()),t.type=this.props.dynamoType,t.clientCreateDate=(new Date).valueOf(),t.createdAt=t.clientCreateDate,t.clientTime=t.clientCreateDate,t.createdByDetail=e?{sk:e.sk,email:(null===e||void 0===e?void 0:e.email)?null===e||void 0===e?void 0:e.email:"",name:null===e||void 0===e?void 0:e.name,surname:e.surname}:void 0,t.version=0,t.activeTenant=this.props.getFromGlobalState("activeSite"),((null===t||void 0===t?void 0:t.combinations)||[]).length>=1&&t.combinations.map(n=>{const i={...n};delete i.combinations,this.props.parentKey?i.sk=this.props.parentKey.concat(this.props.skPrimary.concat(Rt.a.v1())):i.sk=this.props.skPrimary.concat(Rt.a.v1())||i.sk,i.activeTenant=this.props.getFromGlobalState("activeSite"),i.clientCreateDate=(new Date).valueOf(),i.createdAt=t.clientCreateDate,i.clientTime=t.clientCreateDate,i.createdByDetail=e?{sk:e.sk,email:(null===e||void 0===e?void 0:e.email)?null===e||void 0===e?void 0:e.email:"",name:null===e||void 0===e?void 0:e.name,surname:e.surname}:void 0,i.version=0,i.activeTenant=this.props.getFromGlobalState("activeSite"),a.push(i)}));let r=!0;this.props.handlePreExecute&&(r=await this.props.handlePreExecute(t));let l={};if(this.props.batchInserting){if(l=await fa(this.props.getFromGlobalState("currentUser").username,"calls",ua(i,!0),this.props.getFromGlobalState("activeSite")),l.status)for(const a of t.items)a.record.cached=l.cached}else if(r){var n;const e=t.version?t.version:0;t.version=e+1,t.activeTenant=this.props.getFromGlobalState("activeSite"),t.combinations&&(null===t||void 0===t||null===(n=t.combinations)||void 0===n?void 0:n.length)>=1?(t.sk=Rt.a.v1(),t.items=a,delete t.combinations,l=await fa(this.props.getFromGlobalState("currentUser").username,"calls",ua(t,!0),this.props.getFromGlobalState("activeSite"))):l=await ya(this.props.getFromGlobalState("currentUser").username,"calls",ua(t),this.props.getFromGlobalState("activeSite")),console.log("we are inserted a new product",t),l.status&&(t.cached=l.cached)}this.setState({isSubmitting:!1}),this.setState({success:!0}),this.props.handleUpdateDialogObject(t,this.props.parentKey),this.props.setClose()}catch(i){this.setState({success:!1,isSubmitting:!1,messageText:Pa(i)})}}},this.state={isSubmitting:!1,success:!0,confirmDeleteOpen:!1,confirmReInvite:!1,dateRangeDialogOpen:!1,reportType:"",isDeleting:!1,reportStartDate:"",reportEndDate:(new Date).toISOString().substr(0,10),messageText:""}}render(){const{deleteLabel:e,rejectedUser:t,classes:a,open:n,isNew:r,setClose:l,children:s,valid:o,title:c,newTitle:d,dialogObject:m,disableActions:p,maxWidth:h,onGeneratePDF:g,changed:u,pdfRequested:b,reportPDF:v,csvRequested:y,reportCSV:f,onGenerateCSV:S,allowDelete:C,subTitle:x,disableDelete:k}=this.props,{isSubmitting:w,success:T,reportType:D,confirmDeleteOpen:P,confirmReInvite:F,isDeleting:N,dateRangeDialogOpen:L,reportStartDate:A,reportEndDate:O}=this.state,R=r?d:c,U=!window.matchMedia("(min-width: 850px)").matches,M=this.props.getFromGlobalState("userDetail");return console.log(m),i.a.createElement(i.a.Fragment,null,P&&i.a.createElement(Wt,{open:P,loading:N,title:"Confirm",message:e||"Are you sure you want to delete this record and all the associated records?",handleConfirm:this.handleDelete,handleCancel:this.handleCancelConfirmDialog}),F&&i.a.createElement(Wt,{actionText:"Reinvite",open:F,loading:N,title:"Confirm",message:"Are you sure you want to re-invite this user?",handleConfirm:this.handleReinvite,handleCancel:this.cancelReinvite}),L&&i.a.createElement(Kt,{open:L,loading:N,title:"Report Date Range",handleConfirm:"pdf"===D?this.handleGeneratePDF:this.handleGenerateCSV,handleCancel:"pdf"===D?this.handleCancelGeneratePDF:this.handleCancelGenerateCSV,startDate:A,endDate:O,handleSetStartDate:this.setReportStartDate,handleSetEndDate:this.setReportEndDate}),i.a.createElement(yt.a,{fullScreen:U,maxWidth:h,disableBackdropClick:!0,open:n,onClose:l,"aria-labelledby":"responsive-dialog-title",TransitionComponent:U?Aa:void 0},U&&i.a.createElement(kt.a,{className:a.appBar},i.a.createElement(G.a,null,i.a.createElement(E.a,{edge:"start",color:"inherit",onClick:l,"aria-label":"close"},i.a.createElement(Tt.a,null)),i.a.createElement(B.a,{variant:"h6",className:a.title},i.a.createElement("div",null,R,i.a.createElement("div",{style:{fontSize:"10px"}},x))),!r&&C&&i.a.createElement(E.a,{disabled:k,className:a.deleteButton,edge:"start",color:"inherit",onClick:this.confirmDelete,"aria-label":"close"},i.a.createElement(It.a,null)),i.a.createElement(ca,{role:M&&M.rights&&M.rights.viewDashboard?"viewDashboard":"noAccess",perform:"viewReports",isAdministrator:M&&M.rights&&M.rights.administrator,yes:()=>i.a.createElement("div",{style:{display:"flex",float:"right"}},S&&i.a.createElement(i.a.Fragment,null,!y&&i.a.createElement(I.a,{title:"Generate CSV report"},i.a.createElement(E.a,{edge:"start",color:"primary",onClick:this.generateCSV,"aria-label":"close"},i.a.createElement(Nt.a,null))),y&&f),g&&i.a.createElement(i.a.Fragment,null,!b&&i.a.createElement(I.a,{title:"Generate PDF report"},i.a.createElement(E.a,{edge:"start",color:"primary",onClick:this.generatePDF,"aria-label":"close"},i.a.createElement(Pt.a,null))),b&&v))}),!p&&i.a.createElement(la,{onClick:this.handleSubmit,success:T,icon:i.a.createElement(At.a,null),loading:w,disabled:!u||w||!o}))),i.a.createElement(St.a,{style:{minHeight:"20px"},id:"responsive-dialog-title"},!U&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",null,R,i.a.createElement(E.a,{"aria-label":"close",className:a.closeButton,onClick:l},i.a.createElement(Tt.a,null)),!r&&C&&i.a.createElement(E.a,{disabled:k,className:a.deleteButton,edge:"start",color:"inherit",onClick:this.confirmDelete,"aria-label":"close"},i.a.createElement(It.a,null)),i.a.createElement(ca,{role:M&&M.rights&&M.rights.viewDashboard?"viewDashboard":"noAccess",perform:"viewReports",isAdministrator:M&&M.rights&&M.rights.administrator,yes:()=>i.a.createElement("div",{style:{display:"flex",float:"right"}},S&&!U&&i.a.createElement(i.a.Fragment,null,!y&&i.a.createElement(I.a,{title:"Generate CSV report"},i.a.createElement(E.a,{color:"primary",edge:"start",className:a.pdfButton,onClick:this.generateCSV,"aria-label":"close"},i.a.createElement(Nt.a,null))),y&&f),g&&!U&&i.a.createElement(i.a.Fragment,null,!b&&i.a.createElement(I.a,{title:"Generate PDF report"},i.a.createElement(E.a,{color:"primary",edge:"start",className:a.pdfButton,onClick:this.generatePDF,"aria-label":"close"},i.a.createElement(Pt.a,null))),b&&v))}),i.a.createElement("div",{style:{fontSize:"12px"}},x)))),i.a.createElement(Et.a,null,i.a.createElement("form",{onSubmit:this.handleSubmit,className:a.form},s,i.a.createElement("div",{style:{fontSize:"10px",marginTop:"30px"}},m&&m.createdByDetail?m.createdByDetail.name&&m.createdByDetail.surname&&i.a.createElement("div",{style:{fontSize:"10px"}},`Updated by: ${m.createdByDetail.name} ${m.createdByDetail.surname}`):m&&m.createdByEmail?"Updated by: "+m.createdByEmail:"",m&&m.createdAt&&i.a.createElement("div",{style:{fontSize:"10px"}},"Updated on: "+new Date(parseInt(m.createdAt)).toLocaleString())))),i.a.createElement(Bt.a,{smDown:!0},i.a.createElement(ft.a,null,!p&&i.a.createElement(i.a.Fragment,null,t&&i.a.createElement(Ct.a,{variant:"contained",color:"tertiary",className:a.submit,onClick:this.confirmReinviteopen,disabled:this.state.isSubmitting}," ","Re-Invite"," "),i.a.createElement(Mt,{onClick:this.handleSubmit,variant:"contained",color:"primary",className:a.submit,disabled:!u||w||!o||M.rights.readOnly,isloading:this.state.isSubmitting,text:r?"Add":"Update",loadingText:r?"Adding...":"Updating..."}),i.a.createElement(Ct.a,{variant:"contained",color:"secondary",className:a.submit,onClick:l,disabled:this.state.isSubmitting}," ","Close"," ")))),i.a.createElement(ia,{open:!T,setClose:this.setSnackClose.bind(this),messageText:this.state.messageText,variant:"error"})))}}Oa.defaultProps={subTitle:""};var Ia=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{flexWrap:"wrap",[e.breakpoints.up("sm")]:{minWidth:"400px"},[e.breakpoints.down("xs")]:{marginBottom:e.spacing(8)}},closeButton:{float:"right",marginLeft:"auto",color:e.palette.grey[500]},deleteButton:{float:"right",marginLeft:"auto"},pdfButton:{float:"right",marginLeft:"auto"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1}}))(Oa);class Ga extends n.Component{constructor(e){super(e),this.handleSelect=(e,t,a,n,i)=>{},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0}}}componentDidMount(){}render(){const{open:e,isNew:t,setClose:a,title:n,children:r,onGeneratePDF:l,pdfRequested:s,reportPDF:o,getFromGlobalState:c,subTitle:d,reportCSV:m,csvRequested:p,onGenerateCSV:h}=this.props;return i.a.createElement(Ia,{open:e,dialogObject:void 0,setClose:a,isNew:t,disableActions:!0,handleUpdateDialogObject:void 0,skPrimary:void 0,dynamoType:void 0,valid:void 0,title:n,subTitle:d,maxWidth:"lg",parentKey:void 0,plantingKey:void 0,onGeneratePDF:l,pdfRequested:s,reportPDF:o,onGenerateCSV:h,csvRequested:p,reportCSV:m,getFromGlobalState:c},r)}}var Ra=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Ga),Ua=a(9),Ma=a(74),Wa=a.n(Ma),za=a(174),Ka=a.n(za);const Ha=Ua.f.create({body:{paddingTop:35,paddingBottom:55,paddingHorizontal:35},sectionRight:{marginBottom:10,paddingBottom:10,textAlign:"right",width:"60%"},sectionLeft:{marginBottom:10,paddingBottom:10,width:"40%"},section:{display:"flex",flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"},sectionNoPadLeft:{margin:10,padding:10,marginLeft:0,paddingLeft:0},textHeader:{fontSize:24,paddingBottom:10},textSubHeader:{fontSize:14},textOpac:{fontSize:10,opacity:.6},text:{fontSize:10},table:{display:"table",width:"auto",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderRightWidth:0,borderBottomWidth:0},tableRow:{margin:"auto",flexDirection:"row"},tableCol1Header:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableColHeader:{borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol1:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol:{borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCellHeader:{margin:3,fontSize:10,fontWeight:500},tableCell:{margin:3,fontSize:8,wrap:!0},tableCellStrong:{margin:3,fontSize:8,fontWeight:"bold",wrap:!0},pageNumber:{position:"absolute",fontSize:12,bottom:30,left:0,right:0,textAlign:"right",color:"grey",paddingRight:20,marginRight:20},logoText:{position:"absolute",fontSize:10,bottom:30,left:20,textAlign:"left",textDecoration:"none"},logo:{width:30,height:30,paddingLeft:2},farmLogo:{maxWidth:"150px"}}),qa=e=>i.a.createElement(Ua.h,{style:Ha.table},i.a.createElement(Ua.h,{fixed:!0,style:Ha.tableRow},e.data.headCells&&e.data.headCells.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Ha.tableColHeader,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:Ha.tableCellHeader},t.label))))),e.data.rows&&e.data.rows.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:Ha.tableRow},e.data.headCells&&e.data.headCells.map(a=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Ha.tableCol,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:t.strong?Ha.tableCellStrong:Ha.tableCell},$(a,t[a.id],e.data.locale))))))))),Va=e=>i.a.createElement(Ua.h,{wrap:!1,style:Ha.section},e.logoURL&&i.a.createElement(Ua.h,{style:Ha.sectionLeft},i.a.createElement(Ua.b,{cache:!0,style:Ha.farmLogo,src:e.logoURL})),!e.logoURL&&i.a.createElement(Ua.h,{style:Ha.sectionLeft}),i.a.createElement(Ua.h,{style:Ha.sectionRight},i.a.createElement(Ua.g,{style:Ha.textHeader},e.farm.name),e.farm.gapnum&&i.a.createElement(Ua.g,{style:Ha.textOpac},"GLOBAL.G.A.P: "+e.farm.gapnum),e.farm.puc&&i.a.createElement(Ua.g,{style:Ha.textOpac},"Production Unit Code (PUC): "+e.farm.puc),e.farm.vatNo&&i.a.createElement(Ua.g,{style:Ha.textOpac},"VAT Number: "+e.farm.vatNo),i.a.createElement(Ua.g,{style:Ha.textOpac},"Tel: "+e.farm.contactNum),i.a.createElement(Ua.g,{style:Ha.textOpac},"email: "+e.farm.email),e.farm.geoLocation&&i.a.createElement(Ua.g,{style:Ha.textOpac},"Geolocation: "+(e.farm.geoLocation.lat&&e.farm.geoLocation.lng?`Lat: ${e.farm.geoLocation.lat.toFixed(7)} Lng: ${e.farm.geoLocation.lng.toFixed(7)}`:e.farm.geoLocation)),i.a.createElement(Ua.g,{style:Ha.textOpac},"Address: "+e.farm.address1),i.a.createElement(Ua.g,{style:Ha.textOpac},""+e.farm.address2),i.a.createElement(Ua.g,{style:Ha.textOpac},""+e.farm.country),i.a.createElement(Ua.g,{style:Ha.textOpac},""+e.farm.province),i.a.createElement(Ua.g,{style:Ha.textOpac},""+e.farm.pCode))),ja=e=>i.a.createElement(Ua.a,null,i.a.createElement(Ua.e,{size:"A4",style:Ha.body,orientation:"landscape"},i.a.createElement(Va,e),i.a.createElement(Ua.h,{style:[Ha.sectionNoPadLeft,{paddingBottom:0,paddingTop:0,marginTop:0,marginBottom:0}]},i.a.createElement(Ua.g,{style:Ha.textSubHeader},"Block: "+e.block.number),i.a.createElement(Ua.g,{style:Ha.textSubHeader},"Crop: "+e.crop.name),i.a.createElement(Ua.g,{style:Ha.textSubHeader},"Variety: "+e.variety),e.plantingName&&i.a.createElement(Ua.g,{style:Ha.textSubHeader},"Planting: "+e.plantingName),i.a.createElement(Ua.g,{style:Ha.textSubHeader},"Plants: "+e.planting.totalPlants),i.a.createElement(Ua.g,{style:Ha.textSubHeader},`Size: ${e.planting.size} ha`),i.a.createElement(Ua.g,{style:Ha.textOpac},"Report Date: "+_()),e.startDate&&e.endDate&&i.a.createElement(Ua.g,{style:Ha.textOpac},`Report range: From: ${e.startDate} To: ${e.endDate}`)),i.a.createElement(Ua.h,{style:Ha.sectionNoPadLeft},i.a.createElement(Ua.g,{style:Ha.textSubHeader},e.data.title)),i.a.createElement(qa,e),i.a.createElement(Ua.g,{style:Ha.pageNumber,render:({pageNumber:e,totalPages:t})=>`Page: ${e} / ${t}`,fixed:!0}),i.a.createElement(Ua.h,{wrap:!1,style:Ha.logoText},i.a.createElement(Ua.c,{style:{textDecoration:"none"},wrap:!1,src:"landdiary.com"},i.a.createElement(Ua.g,{wrap:!1,style:{borderRadius:3,paddingLeft:"3px",paddingBottom:"2px"}},i.a.createElement(Ua.b,{style:Ha.logo,src:Ka.a})," ")))));class $a extends n.Component{constructor(e){super(e),this.getLogoUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0},logoURL:void 0}}async componentDidMount(){if(this.props.farm&&this.props.farm.logoKey){const e=await this.getLogoUrl(this.props.farm.logoKey,this.props.farm.logoFileType);this.setState({logoURL:e})}}render(){const{recordType:e,farm:t,planting:a,getFromGlobalState:n,block:r,startDate:l,endDate:s,onDownloaded:o}=this.props,c=ut(e,a,r,n,void 0,0,void 0,void 0,void 0,l,s);c.headCells&&(c.headCells=c.headCells.filter(e=>"icon"!==e.type));const d=te("crops",a.crop,n),m=ae(a.variety,d.varieties,"cultivar"),p=a.name?a.name:"",{logoURL:h}=this.state;return t.logoKey&&!h?i.a.createElement("div",{style:{color:"inherit",float:"right",marginLeft:"auto"}},i.a.createElement(la,{key:"pdf",onClick:o,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:!0,disabled:!0})):i.a.createElement(Ua.d,{document:i.a.createElement(ja,{plantingName:p,data:c,block:r,farm:t,crop:d,variety:m,planting:a,startDate:l,endDate:s,logoURL:h}),fileName:`${t.name} ${c.title} ${_()}`,style:{color:"inherit",float:"right",marginLeft:"auto"}},({blob:e,url:t,loading:a,error:n})=>i.a.createElement(la,{key:"pdf",onClick:o,success:!n,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:a,disabled:a}))}}var Ya=Object(v.a)(Ha)($a),_a=a(175);class Za extends n.Component{constructor(e){super(e),this.state={csvData:[],loading:!1,title:""}}componentDidMount(){const{recordType:e,getFromGlobalState:t,planting:a,startDate:n,endDate:i,block:r}=this.props;this.setState({loading:!0});const l=ut(e,a,r,t,void 0,0,void 0,void 0,void 0,n,i);l.headCells&&(l.headCells=l.headCells.filter(e=>"icon"!==e.type));const s=[];s.push(l.headCells.map(e=>e.label));for(let o=0;o({actions:{},badgeChild:{padding:e.spacing(0,.5),margin:"1px"},badge:{color:"#2196f3",paddingBottom:"1px"},padding:{padding:e.spacing(0,2)},statusBar:{display:"flex",flexDirection:"row"},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",float:"left",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"},add:{left:"50%",marginLeft:"-24px",marginBottom:"10px"},buttonLink:{},cardExpand:{padding:"2px"},pdfButton:{float:"right",marginLeft:"auto",color:e.palette.grey[500]},paper:{marginLeft:"4px"},heading:{marginTop:"4px",cursor:"pointer"},buttonRight:{margin:e.spacing(1),float:"right",marginLeft:"auto"},buttonLeft:{margin:e.spacing(1),float:"left",marginRight:"auto"},noneAvatar:{margin:10,backgroundColor:"#fff",width:7,height:7},greenAvatar:{margin:10,color:"#fff",backgroundColor:K.a[500],width:7,height:7},redAvatar:{margin:10,color:"#fff",backgroundColor:e.palette.error.dark,width:7,height:7}}));function Xa(e){var t;const a=Qa(),[n,r]=i.a.useState(!1),[l,s]=i.a.useState(!1),[o,c]=i.a.useState(!1),[d,m]=i.a.useState(!1),[p,h]=i.a.useState(!1),{type:g,expandedRecord:u,blockSK:b,plantingSK:v,onAddRecord:y,getFromGlobalState:f,planting:E,block:S,farm:C,onClickViewTableItem:x,showAll:k,setCloseShowAll:w,title:T,noPagination:D}=e,P=u.plantingSK===v&&u.recordType===g;let F=f("crops");const N=`Block ${S.number} ${ae(E.crop,F,"name")} - ${E.variety?ae(E.variety,null===(t=F.find(e=>e.sk===E.crop))||void 0===t?void 0:t.varieties,"cultivar"):""} - ${E.name?E.name:""}`;return i.a.createElement(i.a.Fragment,null,k&&P&&i.a.createElement(Ra,{open:k,setClose:w,isNew:!1,onGeneratePDF:((e,t)=>{r(!0),c(e),m(t)}).bind(this),pdfRequested:n,csvRequested:l,onGenerateCSV:((e,t)=>{s(!0),c(e),m(t)}).bind(this),getFromGlobalState:f,reportPDF:i.a.createElement(Ya,{startDate:o,endDate:d,color:"secondary",className:a.pdfButton,setPDFDone:()=>{},onDownloaded:()=>{r(!1)},planting:E,block:S,farm:C,recordType:g,getFromGlobalState:f}),reportCSV:i.a.createElement(Ja,{startDate:o,endDate:d,color:"secondary",className:a.pdfButton,setCSVDone:()=>{},onDownloaded:()=>{s(!1)},planting:E,block:S,farm:C,recordType:g,getFromGlobalState:f}),title:T,subTitle:N},i.a.createElement(vt,{displayToolbar:!0,dense:!0,showAll:!0,noPagination:D,recordType:g,planting:E,block:S,farm:C,type:g,handleSelect:x.bind(this),getFromGlobalState:f,handleAddItem:y.bind(this,b,v,g),clean:!0})),i.a.createElement(O.a,{elevation:0,className:a.paper},i.a.createElement("br",null)))}var en=a(1703),tn=a(1708),an=a(431),nn=a.n(an),rn=a(871),ln=a(560);function sn(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M23,4.1V2.3L21.2,2.1C21.1,2.1 20.5,2 19.5,2C15.4,2 12.4,3.2 10.7,5.3C9.4,4.5 7.6,4 5.5,4C4.5,4 3.8,4.1 3.8,4.1L1.9,4.4L2,6.1C2.1,9.1 3.6,14.8 8.8,14.8C8.9,14.8 8.9,14.8 9,14.8V18.2C5.2,18.7 2,20 2,20V22H22V20C22,20 18.8,18.7 15,18.2V15C21.3,14.9 23,7.8 23,4.1M12,18C11.7,18 11.3,18 11,18V12.4C11,12.4 10.8,9 8,9C8,9 9.5,9.8 9.9,12.7C9.5,12.8 9.1,12.8 8.8,12.8C4.2,12.8 4,6.1 4,6.1C4,6.1 4.6,6 5.5,6C7.4,6 10.5,6.4 11.4,9.1C11.9,4.6 17,4 19.5,4C20.4,4 21,4.1 21,4.1C21,4.1 21,13.1 14.7,13.1C14.5,13.1 14.2,13.1 14,13.1C14,11.1 16,8.1 16,8.1C13,9.1 13,13 13,13V18C12.7,18 12.3,18 12,18Z"}),">")}function on(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M20,8H17.19C16.74,7.2 16.12,6.5 15.37,6L17,4.41L15.59,3L13.42,5.17C12.96,5.06 12.5,5 12,5C11.5,5 11.05,5.06 10.59,5.17L8.41,3L7,4.41L8.62,6C7.87,6.5 7.26,7.21 6.81,8H4V10H6.09C6.03,10.33 6,10.66 6,11V12H4V14H6V15C6,15.34 6.03,15.67 6.09,16H4V18H6.81C8.47,20.87 12.14,21.84 15,20.18C15.91,19.66 16.67,18.9 17.19,18H20V16H17.91C17.97,15.67 18,15.34 18,15V14H20V12H18V11C18,10.66 17.97,10.33 17.91,10H20V8M16,15A4,4 0 0,1 12,19A4,4 0 0,1 8,15V11A4,4 0 0,1 12,7A4,4 0 0,1 16,11V15M14,10V12H10V10H14M10,14H14V16H10V14Z"}),">")}function cn(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M3,3H21V5A2,2 0 0,0 19,7V19A2,2 0 0,1 17,21H7A2,2 0 0,1 5,19V7A2,2 0 0,0 3,5V3M7,5V7H12V8H7V9H10V10H7V11H10V12H7V13H12V14H7V15H10V16H7V19H17V5H7Z"}),">")}function dn(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M10.5,3C8,3 6,5 6,7.5C6,8.11 6.13,8.71 6.37,9.27C5.5,10.12 5,11.28 5,12.5C5,15 7,17 9.5,17C10,17 10.5,16.89 11,16.72V21H13V15.77C13.5,15.91 14,16 14.5,16A5.5,5.5 0 0,0 20,10.5A5.5,5.5 0 0,0 14.5,5C14.41,5 14.33,5 14.24,5C13.41,3.76 12,3 10.5,3M10.5,5C11.82,5 12.91,6.03 13,7.35C13.46,7.12 14,7 14.5,7A3.5,3.5 0 0,1 18,10.5A3.5,3.5 0 0,1 14.5,14C13.54,14 12.63,13.61 11.96,12.91C11.76,14.12 10.72,15 9.5,15A2.5,2.5 0 0,1 7,12.5C7,11.12 7.8,10.54 9,9.79C8.2,8.76 8,8.16 8,7.5A2.5,2.5 0 0,1 10.5,5Z"}),">")}function mn(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M19.5,12c0.93,0,1.78,0.28,2.5,0.76V8c0-1.1-0.9-2-2-2h-6.29l-1.06-1.06l1.41-1.41l-0.71-0.71L9.82,6.35l0.71,0.71 l1.41-1.41L13,6.71V9c0,1.1-0.9,2-2,2h-0.54c0.95,1.06,1.54,2.46,1.54,4c0,0.34-0.04,0.67-0.09,1h3.14 C15.3,13.75,17.19,12,19.5,12z"}),i.a.createElement("path",{d:"M19.5,13c-1.93,0-3.5,1.57-3.5,3.5s1.57,3.5,3.5,3.5s3.5-1.57,3.5-3.5S21.43,13,19.5,13z M19.5,18 c-0.83,0-1.5-0.67-1.5-1.5s0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5S20.33,18,19.5,18z"}),i.a.createElement("path",{d:"M4,9h5c0-1.1-0.9-2-2-2H4C3.45,7,3,7.45,3,8C3,8.55,3.45,9,4,9z"}),i.a.createElement("path",{d:"M9.83,13.82l-0.18-0.47L10.58,13c-0.46-1.06-1.28-1.91-2.31-2.43l-0.4,0.89l-0.46-0.21l0.4-0.9C7.26,10.13,6.64,10,6,10 c-0.53,0-1.04,0.11-1.52,0.26l0.34,0.91l-0.47,0.18L4,10.42c-1.06,0.46-1.91,1.28-2.43,2.31l0.89,0.4l-0.21,0.46l-0.9-0.4 C1.13,13.74,1,14.36,1,15c0,0.53,0.11,1.04,0.26,1.52l0.91-0.34l0.18,0.47L1.42,17c0.46,1.06,1.28,1.91,2.31,2.43l0.4-0.89 l0.46,0.21l-0.4,0.9C4.74,19.87,5.36,20,6,20c0.53,0,1.04-0.11,1.52-0.26l-0.34-0.91l0.47-0.18L8,19.58 c1.06-0.46,1.91-1.28,2.43-2.31l-0.89-0.4l0.21-0.46l0.9,0.4C10.87,16.26,11,15.64,11,15c0-0.53-0.11-1.04-0.26-1.52L9.83,13.82z M7.15,17.77c-1.53,0.63-3.29-0.09-3.92-1.62c-0.63-1.53,0.09-3.29,1.62-3.92c1.53-0.63,3.29,0.09,3.92,1.62 C9.41,15.38,8.68,17.14,7.15,17.77z"}),">")}var pn=Object(v.a)(e=>({progress:{margin:e.spacing(2)},icon:{border:"2px solid "+e.palette.secondary.main,color:"inherit",width:"30px",height:"30px",borderRadius:"50%",padding:e.spacing(1),alignItems:"center",alignContent:"center",justifyContent:"center",display:"flex"},selected:{color:"red !important"},iconButton:{float:"left",width:"70px",height:"70px",color:"inherit",fontSize:"large"},root:{display:"inline-flex"},iconContainer:{textAlign:"center",width:"60px"},label:{color:"inherit"},valueText:{fontSize:"0.9rem",marginLeft:"3px",paddingBottom:"15px"},button:{border:"3px solid white",padding:"8px"},listItem:{},badge:{margin:e.spacing(2)}}))((function(e){const{classes:t,water:a,chemical:n,plantingSK:r,handleSelectType:l,selectedIcon:s,blockSK:o,userDetail:c,disabled:d}=e;return i.a.createElement("div",{className:t.root},i.a.createElement(tn.a,{style:{width:"50%"}},i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("fertilisings")?"fertilisings":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem},i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:d,className:t.button,style:{border:"fertilisings"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"fertilisings")},i.a.createElement(sn,{edge:"start",color:d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{style:{fontSize:"0.9rem"}},"Fertilisers")))}),i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("waterings")?"waterings":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem}," ",i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:a.disabled||d,className:t.button,style:{border:"waterings"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"waterings")},i.a.createElement(nn.a,{edge:"start",color:a.disabled||d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{color:a.disabled?"grey":void 0,style:{fontSize:"0.9rem"}},"Irrigation")))}),i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("pestings")?"pestings":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem},i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:d,className:t.button,style:{border:"pestings"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"pestings")},i.a.createElement(on,{edge:"start",color:d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{style:{fontSize:"0.9rem"}},"Monitoring")))})),i.a.createElement(tn.a,{style:{width:"50%"}},i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("sprayings")?"sprayings":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem},i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:d,className:t.button,style:{border:"sprayings"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"sprayings")},i.a.createElement(cn,{edge:"start",color:d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{style:{fontSize:"0.9rem"}},"Plant Protection")))}),i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("harvestings")?"harvestings":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem},i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:d,className:t.button,style:{border:"harvestings"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"harvestings")},i.a.createElement(dn,{edge:"start",color:n.status&&"red"===n.status?"error":d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{style:{fontSize:"0.9rem"}},"Harvest")))}),i.a.createElement(ca,{role:c&&c.rights&&c.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:c.rights&&c.rights.allowedActivities&&c.rights.allowedActivities.includes("activities")?"activities":"noAccess",yes:()=>i.a.createElement(en.a,{className:t.listItem},i.a.createElement("div",{className:t.iconContainer},i.a.createElement(E.a,{disabled:d,className:t.button,style:{border:"activities"===s?"3px solid #63c7c8":void 0},size:"large",onClick:l.bind(this,o,r,"activities")},i.a.createElement(mn,{edge:"start",color:d?"grey":"secondary",style:{fontSize:"x-large"}})),i.a.createElement(B.a,{style:{fontSize:"0.9rem"}},"Agronomic Activity")))})))}));const hn=(e,t)=>{const a=e.find(e=>e.sk===t);let n="";return a&&(n=a.name),n};class gn extends i.a.Component{constructor(e){super(e),this.getChildStatus=(e,t)=>{if(!e)return"none";switch(t){case"sprayings":{const t=new Date;for(const a of e){if(void 0===a.phiLapse)return"red";if(new Date(a.phiLapse.substring(0,10))>t)return"red"}return"none"}default:return"none"}},this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.state={selectedTab:0}}PlantingItem(e,t,a,n,r,l,s,o,c,d,m,p,h,g,u,b,v,y,S,C,k){const D=t===e.sk,P=this.getChildStatus(e.sprayings,"sprayings"),F=D&&function(e){const t={fertilisings:{value:0,unit:""},waterings:{value:0,tasks:0,unit:""},pestings:{value:0,unit:""},sprayings:{value:0,unit:""},harvestings:{value:0,unit:""},packings:{value:0,unit:""}};return t.fertilisings.value=e&&e.fertilisings?e.fertilisings.reduce((e,t)=>e+(!0===t.completed?parseFloat(t.volume):0),0):0,t.fertilisings.unit="",t.waterings.value=e&&e.waterings?e.waterings.reduce((e,t)=>e+(t.completed?parseFloat(t.actualLiters):0),0):0,t.waterings.unit="\u2113",t.waterings.tasks=e&&e.waterings?e.waterings.reduce((e,t)=>e+(t.completed?0:1),0):0,t.pestings.value=e&&e.pestings?e.pestings.reduce((e,t)=>e+parseFloat(t.units),0):0,t.pestings.unit="",t.sprayings.value=e&&e.sprayings?e.sprayings.reduce((e,t)=>e+(!0===t.completed?parseFloat(t.volume):0),0):0,t.sprayings.unit="\u2113",t.harvestings.value=e&&e.harvestings?e.harvestings.reduce((e,t)=>e+parseFloat(t.harvestTotal),0):0,t.harvestings.unit="\u338f",t.packings.value=e&&e.packings?e.packings.reduce((e,t)=>e+parseFloat(t.packTotal),0):0,t.packings.unit="\u338f",t}(e),N=e.disabled;return i.a.createElement(O.a,{elevation:0,key:e.sk,className:r.planting},i.a.createElement(f.a,{style:D?{borderBottom:"1px solid rgba(0, 0, 0, .125)"}:void 0,className:r.actions,disableSpacing:!0,onClick:a.bind(this,e.sk)},i.a.createElement(E.a,{className:Object(x.a)(r.expand,{[r.expandOpen]:D}),"aria-expanded":D,"aria-label":"show more"},i.a.createElement(w.a,null)),i.a.createElement("div",{style:{marginRight:"5px",cursor:"pointer"}}," ",i.a.createElement(i.a.Fragment,null,e.cached&&!e.syncError&&i.a.createElement(U.a,{className:r.cached}),e.cached&&e.syncError&&i.a.createElement(W.a,{className:r.syncError}),i.a.createElement(B.a,{variant:"subtitle2"},new Date(e.date).toLocaleDateString()),i.a.createElement(B.a,{style:{opacity:.6},variant:"subtitle2"},`${hn(m,e.crop)} - ${((e,t,a)=>{const n=e.find(e=>e.sk===t);let i="";if(n){const e=n.varieties.find(e=>e.sk===a);e&&(i=e.cultivar)}return i})(m,e.crop,e.variety)} - ${e.name?e.name:""}`))),i.a.createElement(ge,{status:e.status,hideIfGreen:!0,size:"small"}),D&&i.a.createElement(ca,{role:k&&k.rights&&k.rights.changeSettings?"changeSettings":"noAccess",perform:"openPlantingPage",yes:()=>i.a.createElement(I.a,{placement:"top",title:"View Planting"},i.a.createElement(E.a,{"aria-label":"Edit",color:"primary",className:r.editButton,onClick:n.bind(this,l,e.sk,g)},i.a.createElement(A.a,null)))})),i.a.createElement(T.a,{in:D,timeout:"auto",unmountOnExit:!0},i.a.createElement(O.a,{elevation:0,className:r.paper},D&&i.a.createElement(pn,{disabled:N,fertiliser:{total:F.fertilisings},water:{total:F.waterings,disabled:"dryLand"===g.irrigated||void 0},pest:{total:F.pestings},chemical:{total:F.sprayings,status:P},harvest:{total:F.harvestings},pack:{total:F.packings},userDetail:h("userDetail"),plantingSK:e.sk,blockSK:l,block:g,handleSelectType:c,selectedIcon:d.plantingSK===e.sk?d.recordType:void 0}),d.plantingSK===e.sk&&"fertilisings"===d.recordType&&i.a.createElement(Xa,{records:e.fertilisings,displayFields:["date","productName"],plantingSK:e.sk,blockSK:l,title:"Fertiliser",type:"fertilisings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"waterings"===d.recordType&&i.a.createElement(Xa,{records:e.waterings,displayFields:["date","duration"],plantingSK:e.sk,blockSK:l,title:"Irrigation",type:"waterings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"pestings"===d.recordType&&i.a.createElement(Xa,{records:e.pestings,displayFields:["date","pest"],plantingSK:e.sk,blockSK:l,title:"Monitoring",type:"pestings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"sprayings"===d.recordType&&i.a.createElement(Xa,{records:e.sprayings,displayFields:["date","product"],plantingSK:e.sk,blockSK:l,title:"Plant Protection",type:"sprayings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getDisplayHeader:p,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"harvestings"===d.recordType&&i.a.createElement(Xa,{records:e.harvestings,displayFields:["date","harvestTotal"],plantingSK:e.sk,blockSK:l,title:"Harvesting",type:"harvestings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"packings"===d.recordType&&i.a.createElement(Xa,{records:e.packings,displayFields:["date","packTotal"],plantingSK:e.sk,blockSK:l,title:"Packing",type:"packings",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C}),d.plantingSK===e.sk&&"activities"===d.recordType&&i.a.createElement(Xa,{records:e.pestings,displayFields:["date","name"],plantingSK:e.sk,blockSK:l,title:"Agronomic",type:"activities",onViewRecord:s,onAddRecord:o,onViewReport:u,handleExpandClick:c,expandedRecord:d,getFromGlobalState:h,planting:e,block:g,onClickViewTableItem:b,onViewAll:v,showAll:y,setCloseShowAll:S,farm:C,noPagenation:!1}))))}render(){const e=e=>{const t=e.product,a=this.props.getFromGloblState("chemicals"),n=hn(a,t);return`${e.date} | ${n}`},{classes:t,expandedPlanting:a,handleExpandClick:n,plantings:r,onClickAdd:l,blockSK:s,onClickView:o,onClickViewRecord:c,onClickAddRecord:d,handleExpandRecordClick:m,expandedRecord:p,settings:h,getFromGlobalState:g,block:u,onClickViewReport:b,onClickViewTableItem:v,onClickViewAll:y,showAll:f,setCloseShowAll:S}=this.props,x=this.props.getFromGlobalState("farm"),k=this.props.getFromGlobalState("userDetail");return console.log("plantings",r),i.a.createElement("div",{className:t.root},i.a.createElement(G.a,{style:{paddingLeft:"8px",paddingRight:"8px"}},i.a.createElement("div",{className:t.title},i.a.createElement(B.a,{variant:"subtitle2",id:"tableTitle"},"Plantings")),i.a.createElement("div",{className:t.spacer}),i.a.createElement(ca,{role:k&&k.rights&&k.rights.changeSettings?"changeSettings":"noAccess",perform:"openSettingsPage",yes:()=>i.a.createElement("div",{className:t.actionsH},i.a.createElement(I.a,{title:"Add Planting"},i.a.createElement(E.a,{size:"medium",color:"secondary","aria-label":"add",onClick:l.bind(this,s,u)},i.a.createElement(C.a,null))))})),r&&r.map(i=>this.PlantingItem(i,a,n,o,t,s,c,d,m,p,h,e,g,u,b,v,y,f,S,x[0],k)))}}var un=Object(v.a)(e=>({actionsOld:{border:"1px solid rgba(0, 0, 0, .125)",paddingRight:"16px",margin:"8px",alignItems:"self-end",borderRadius:"8px"},planting:{border:"1px solid rgba(0, 0, 0, .125)",margin:"4px",marginBottom:"8px"},actions:{alignItems:"self-end",paddingRight:"4px",paddingLeft:"4px"},cardExpand:{padding:"2px"},spacer:{flex:"1 1 100%"},actionsH:{color:e.palette.text.secondary,display:"inline-flex"},title:{flex:"0 0 auto"},expand:{transform:"rotate(0deg)",padding:"4px",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"},addPlanting:{left:"50%",marginLeft:"-24px",marginBottom:"10px"},editButton:{float:"left",marginLeft:"auto"},editPlanting:{paddingLeft:"1px"},paper:{flexGrow:1,display:"flex",flexDirection:"column",border:"none",paddingLeft:"4px",paddingRight:"4px"},cached:{fontSize:15,color:e.palette.secondary.main},syncError:{fontSize:15,color:"red"}}))(gn),bn=a(552),vn=a(551),yn=a(813),fn=a.n(yn),En=a(553),Sn=a(568),Cn=a(1774),xn=a(741),kn=a(1709),wn=a(159),Tn=a(579),Dn=a.n(Tn);function Pn(e){const t=new window.google.maps.LatLngBounds;for(let a=0;a{const a=e.getArray();for(let n=0,i=a.length;n{const t=e.getArray();for(let n=0,i=t.length;n{P(e),T(e)},[T]);i.a.useEffect(()=>{if(!D)return;const e=(e,t)=>{e&&D.fitBounds(e),t&&D.setCenter(t)};let t;if(p.length){const a=y?p.filter(e=>e.sk===y):p;t=Pn(a),e(t)}else navigator.geolocation.getCurrentPosition(a=>{const{latitude:n,longitude:i}=a.coords,r={lat:n,lng:i};t=new window.google.maps.LatLngBounds(new window.google.maps.LatLng(r.lat-.1,r.lng-.1),new window.google.maps.LatLng(r.lat+.1,r.lng+.1)),e(t,S?null:r),T(w)},()=>{t=Pn([]),e(t)})},[D,p,y]);const B=i.a.useCallback(e=>{T(null)},[]);return F?i.a.createElement("div",{style:E},i.a.createElement(wn.c,{mapContainerStyle:Ln,center:t,zoom:n,onClick:o,drawingMode:u,options:{streetViewControl:!1,mapTypeId:"satellite",disableDoubleClickZoom:!0},onLoad:N,onUnmount:B},C&&i.a.createElement("button",{onClick:C},"Recenter"),b&&i.a.createElement(wn.e,{url:b,options:{preserveViewport:!1,clickable:!0,suppressInfoWindows:!1},onClick:v}),u&&i.a.createElement(wn.b,{onMarkerComplete:m,options:{drawingMode:u},onPolygonComplete:c}),p&&p.map(e=>i.a.createElement(i.a.Fragment,{key:e.sk},i.a.createElement(wn.h,{onClick:d?d.bind(this,e.sk):void 0,paths:e.paths,options:Rn(e)}),i.a.createElement(wn.g,{position:Bn(e),mapPaneName:wn.g.OVERLAY_MOUSE_TARGET},i.a.createElement("span",{style:{color:"white",fontWeight:"bold"}},e.label)))),h&&h.map(e=>i.a.createElement(wn.a,{key:e.id,onClick:f?f.bind(this,e):void 0,center:e,options:Un(e)})),g&&i.a.createElement(wn.d,{onCloseClick:s?s.bind(this):null,position:g.position},i.a.createElement("div",{style:Gn},g.content)),a&&a.map(e=>i.a.createElement(i.a.Fragment,{key:e.sk},i.a.createElement(wn.f,{position:e.position,clickable:e.clickable?e.clickable:void 0,icon:e.icon,onClick:r?r.bind(this,e.sk):void 0}))))):i.a.createElement(i.a.Fragment,null)}Mn.defaultProps={markers:[],polygons:[],circles:[],infoWindow:null,onSelectMarker:null,onCloseMarker:null,onPolygonComplete:null,onPolygonClick:null,onCircleClick:null,onCloseInfoWindow:null,onClick:null,onMarkerComplete:null,mode:null,kmlLayerSrc:null,onLayerClick:null,selectedPoly:"",keepBounds:!1,style:{height:"600px",width:"100%"},recenter:null,isModalOpen:!1};var Wn=Mn,zn=a(268),Kn=a.n(zn);const Hn=Object(z.a)(e=>({root:{"& > *":{padding:e.spacing(1)}}}));function qn(e){const t=Hn(),{message:a}=e;return i.a.createElement("div",{className:t.root},i.a.createElement(O.a,{elevation:1},i.a.createElement(Kn.a,{size:"medium"}),i.a.createElement(B.a,{variant:"subtitle1"},a)))}function Vn(e,t){return a=e,isNaN(parseFloat(a))||!isFinite(a)?{valid:!1,msg:"Must be a valid number"}:et.max?{valid:!1,msg:"Maximum value "+t.max}:{valid:!0,msg:""};var a}function jn(e,t,a){const n=a.find(t=>t.name===e),i={msg:"",isValid:!1};if(!n)return i.isValid=!0,i;if(n.conditions){if(!t[n.condition.name])return i.isValid=!0,i;if(t[n.condition.name]!==n.condition.value)return i.isValid=!0,i}let r={};const l=t[e];return void 0===l?(i.msg="Is required",i.isValid=!1,i):n.type&&"number"===n.type?(r=Vn(l,n),i.msg=r.msg,i.isValid=r.valid,i):l&&0!==l.length?n.type&&"number"===n.type?(r=Vn(l,n),i.msg=r.msg,i.isValid=r.valid,i):n.type&&"password"===n.type?(r=function(e,t){return e.length()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())?et.max?{valid:!1,msg:"Maximum value "+t.max}:{valid:!0,msg:""}:{valid:!1,msg:"Not a valid email address"}}(l,n),i.msg=r.msg,i.isValid=r.valid,i):n.type&&"object"===n.type?(r=function(e,t){return e?Object.keys(e).lengtht.max?{valid:!1,msg:"Maximum value "+t.max}:{valid:!0,msg:""}:{valid:!1,msg:"Must select at least one"}}(l,n),i.msg=r.msg,i.isValid=r.valid,i):(r=function(e,t){return e.lengtht.max?{valid:!1,msg:"Maximum length "+t.max}:{valid:!0,msg:""}}(l,n),i.msg=r.msg,i.isValid=r.valid,i):(i.msg="Is required",i.isValid=!1,i)}function $n(e,t){let a=!0;for(var n of t)if(!n.condition||n.condition&&e.hasOwnProperty(n.condition.name)&&e[n.condition.name]===n.condition.value){if(e&&e.hasOwnProperty(n.name)){if(jn(n.name,e,t).isValid)continue;a=!1;break}a=!1;break}return a}const Yn=[{name:"number",min:1,max:40},{name:"size",min:1,max:40},{name:"soilType",min:1,max:40},{name:"slope",min:1,max:40},{name:"irrigated",min:1,max:40},{name:"irrigationSystem",condition:{name:"irrigated",value:"irrigated"},min:1,max:100},{name:"volumePerHour",condition:{name:"irrigated",value:"irrigated"},min:1,max:40},{name:"flowunit",condition:{name:"irrigated",value:"irrigated"},min:1,max:40}];class _n extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Yn),this.handleChange=e=>{let t={...this.state.block};t[e.target.id]=e.target.value,this.setState({block:t,changed:!0})},this.handleRadioChange=(e,t)=>{let a={...this.state.block};a[e]=t.target.value,this.setState({block:a,changed:!0})},this.handleToggle=e=>t=>{let a={...this.state.block};a[e]=t.target.checked,this.setState({block:a,changed:!0})},this.handleColorChange=e=>{let t={...this.state.block};t.color=e,this.setState({block:t,changed:!0})},this.onMapClick=e=>{const t={...this.state.block};t.paths||(t.paths=[]),t.paths.push({lat:e.latLng.lat(),lng:e.latLng.lng()}),this.setState({block:t})},this.blockDrawn=e=>{const t={...this.state.block};t.paths=[];const a=e.getPath().getArray();a&&a.map(e=>{t.paths.push({lat:e.lat(),lng:e.lng()})});const n=window.google.maps.geometry.spherical.computeArea(e.getPath());t.size=n/1e4,t.size=t.size.toFixed(4),this.setState({block:t,changed:!0})},this.getLogoUrl=async(e,t)=>Fa({activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t}),this.state={isloading:!1,isNew:this.props.isNew,block:{},errors:{count:0},changed:!1,locationLoading:!1,locale:"en-ZA",farmKml:null}}componentDidMount(){this.props.isNew?this.setState({block:{}}):this.setState({block:this.props.block})}validateField(e,t){let a=jn(e,this.state.block,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,userLocation:t,open:a,isNew:n,setClose:r,handleUpdateBlocks:l,handleDeleteBlock:s,getFromGlobalState:o,farm:c,otherBlockPolygons:d}=this.props,{block:m,errors:p}=this.state;if(!c[0])return null;const h=m&&(u=d,b="#d3d3d3",v="#FFFFFF",y=m.sk,u&&b?u.map(e=>{const t={...e};return e.sk!==y&&(t.color=b,t.strokeColor=v),t}):[]);var u,b,v,y;const f=ee(c[0].geoLocation)?ee(c[0].geoLocation):t,E=$n(m,Yn),S=h?h.findIndex(e=>e.sk===m.sk):-1;return m.paths&&-1===S?h.push({label:m.number,sk:m.sk,paths:m.paths,color:m.color,clickable:!0}):m.paths&&(h[S]={label:m.number,sk:m.sk,paths:m.paths,color:m.color,clickable:!0,strokeWeight:2}),i.a.createElement(Ia,{open:a,dialogObject:m,setClose:r,isNew:n,handleUpdateDialogObject:l.bind(this),handleDeleteDialogObject:s.bind(this),allowDelete:!0,skPrimary:"init_block_",dynamoType:"blocks",changed:this.state.changed,valid:E,newTitle:"New Block",title:m.number,getFromGlobalState:o},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(qn,{message:"Select a color and map your block using the ploygon tool."})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(bn.a,{shrink:!0,htmlFor:"color"},"Block Color"),i.a.createElement(fn.a,{name:"color",id:"color",defaultValue:"Color",value:m.color,onChange:e=>this.handleColorChange(e)})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Wn,{center:f,style:{height:"500px",width:"100%"},zoom:16,mode:"polygon",polygons:h,selectedPoly:m.sk,onPolygonComplete:this.blockDrawn.bind(this),isModalOpen:a,userLocation:t})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"number"},"Block Number"),i.a.createElement(zt.a,{margin:"normal",required:!0,id:"number",name:"number",style:{minWidth:"200px"},value:m.number,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.number||void 0,helperText:p.number}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"size"},"Size (Hectares)"),i.a.createElement(zt.a,{margin:"normal",required:!0,style:{minWidth:"200px"},inputProps:{min:"0.00001",step:"any"},type:"number",id:"size",name:"size",value:m.size,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.size||void 0,helperText:p.size}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"soilType"},"Soil Type"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,displayEmpty:!0,value:m.soilType,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.soilType||void 0,inputProps:{name:"soilType",id:"soilType"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Clay"},"Clay"),i.a.createElement("option",{value:"Clay loam"},"Clay loam"),i.a.createElement("option",{value:"Loam"},"Loam"),i.a.createElement("option",{value:"Loamy Sand"},"Loamy Sand"),i.a.createElement("option",{value:"Sand"},"Sand"),i.a.createElement("option",{value:"Sandy clay"},"Sandy clay"),i.a.createElement("option",{value:"Sandy clay loam"},"Sandy clay loam"),i.a.createElement("option",{value:"Sandy loam"},"Sandy loam"),i.a.createElement("option",{value:"Silt"},"Silt"),i.a.createElement("option",{value:"Silt loam"},"Silt loam"),i.a.createElement("option",{value:"Silty clay"},"Silty clay"),i.a.createElement("option",{value:"Silty clay loam"},"Silty clay loam"),i.a.createElement("option",{value:"Gravel"},"Gravel"),i.a.createElement("option",{value:"Unknown"},"Unknown")),p.soilType&&i.a.createElement(En.a,{className:e.helperText},p.soilType))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"slope"},"Slope"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,displayEmpty:!0,value:m.slope,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.slope||void 0,inputProps:{name:"slope",id:"slope"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Flat"},"Flat"),i.a.createElement("option",{value:"Gentle"},"Gentle"),i.a.createElement("option",{value:"Gentle to moderate"},"Gentle to moderate"),i.a.createElement("option",{value:"Moderate"},"Moderate"),i.a.createElement("option",{value:"Steep"},"Steep"),i.a.createElement("option",{value:"Unknown"},"Unknown")),p.slope&&i.a.createElement(En.a,{className:e.helperText},p.slope))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{shrink:!0,component:"legend",required:!0},"Irrigation"),i.a.createElement(xn.a,{"aria-label":"irrigated",name:"irrigated",id:"irrigated",className:e.group,value:m.irrigated,onChange:this.handleRadioChange.bind(this,"irrigated")},i.a.createElement(Fe.a,{value:"dryLand",control:i.a.createElement(Cn.a,null),label:"Dry Land"}),i.a.createElement(Fe.a,{value:"irrigated",control:i.a.createElement(Cn.a,null),label:"Irrigated"}),p.irrigated&&i.a.createElement(En.a,{className:e.helperText},p.irrigated)))),"irrigated"===m.irrigated&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"irrigationSystem"},"Irrigation Type"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"150px"},displayEmpty:!0,value:m.irrigationSystem,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.irrigationSystem||void 0,inputProps:{name:"irrigationSystem",id:"irrigationSystem"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Dry Land"},"Dry Land"),i.a.createElement("option",{value:"Micro"},"Micro"),i.a.createElement("option",{value:"Pivot"},"Pivot"),i.a.createElement("option",{value:"Drip"},"Drip"),i.a.createElement("option",{value:"Watercart"},"Watercart"),i.a.createElement("option",{value:"Overhead Sprinklers"},"Overhead Sprinklers"),i.a.createElement("option",{value:"Drag Line"},"Drag Line"),i.a.createElement("option",{value:"Ultra Low Flow Drip"},"Ultra Low Flow Drip"),i.a.createElement("option",{value:"Low Flow Drip"},"Low Flow Drip"),i.a.createElement("option",{value:"Flood"},"Flood"),i.a.createElement("option",{value:""})),p.irrigationSystem&&i.a.createElement(En.a,{className:e.helperText},p.irrigationSystem))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",inputProps:{min:"0.00001",step:"any"},style:{minWidth:"150px"},id:"volumePerHour",label:"Liters (per hour)",name:"volumePerHour",value:m.volumePerHour,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.volumePerHour||void 0,helperText:p.volumePerHour})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{shrink:!0,component:"legend",required:!0},"Per"),i.a.createElement(xn.a,{"aria-label":"flowunit",name:"flowunit",id:"flowunit",className:e.group,value:m.flowunit,onChange:this.handleRadioChange.bind(this,"flowunit")},i.a.createElement(Fe.a,{value:"hectare",control:i.a.createElement(Cn.a,null),label:"Hectare"}),i.a.createElement(Fe.a,{value:"plant",control:i.a.createElement(Cn.a,null),label:"Plant"}),p.flowunit&&i.a.createElement(En.a,{className:e.helperText},p.flowunit)))))))}}var Zn=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(_n),Jn=a(818),Qn=a.n(Jn),Xn=a(145),ei=a.n(Xn),ti=a(742),ai=a(1745);class ni extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,this.state.requiredFields),this.plantedSize=e=>e&&e.plantings&&e.plantings.length>0?e.plantings.reduce((e,t)=>e+parseFloat(t.size),0):0,this.handleClusterItemChange=e=>{this.setState({selectedClusterItem:e.target.value})},this.handleAddCluster=e=>{const t={...this.state.planting},{selectedCluster:a,selectedClusterItem:n}=this.state;t.clusters||(t.clusters=[]);let i=t.clusters.find(e=>e.sk===a.sk);i||(t.clusters.push({sk:a.sk}),i=t.clusters.find(e=>e.sk===a.sk)),i.items||(i.items=[]);i.items.find(e=>e===n)||i.items.push(n),this.setState({planting:t,changed:!0,openedCluster:i.sk})},this.handleClusterChange=e=>{const t=this.props.getFromGlobalState("clusters").find(t=>t.sk===e.target.value);this.setState({selectedCluster:t})},this.handleChange=e=>{const t={...this.state.planting};t[e.target.id]=e.target.value,this.setState({planting:t,changed:!0})},this.handleSwitchChange=e=>{const t={...this.state.planting};t.disabled=!t.disabled,console.log(t.disabled),this.setState({planting:t,changed:!0})},this.handleLocalChange=e=>{this.setState({[e.target.id]:e.target.value,changed:!0})},this.handleLocalChangeSetVariety=e=>{const{cultivarType:t,cultivarName:a,rootStockType:n}=this.state,i=e.target.value,{crops:r}=this.props.metaData,l={...this.state.planting},s=r.find(e=>e.sk===l.crop).varieties.find(e=>e.cultivarType===t&&e.cultivar===a&&e.rootStockType===n&&e.rootStock===i);l.variety=s.sk,this.setState({rootStockName:i,planting:l,changed:!0})},this.handleClusterOpen=e=>{const{openedCluster:t}=this.state;t===e?this.setState({openedCluster:""}):this.setState({openedCluster:e})},this.handleDeleteCluster=e=>{const t={...this.state.planting};if(!t.clusters)return;const a=t.clusters.findIndex(t=>t.sk===e);-1!==a&&t.clusters.splice(a,1),this.setState({planting:t,changed:!0})},this.handleDeleteClusterItem=(e,t)=>{const a={...this.state.planting};if(!a.clusters)return;const n=a.clusters.find(t=>t.sk===e);if(!n)return;const i=n.items.find(e=>e===t);-1!==i&&n.items.splice(i,1),this.setState({planting:a,changed:!0})},this.createUnique=(e,t)=>{const a=[];for(let n=0;n{const t={...this.state.planting};t.totalPlantsOverride=!t.totalPlantsOverride,this.setState({planting:t,changed:!0})},this.state={isloading:!1,cultivarType:null,cultivarName:null,rootStockType:null,rootStockName:null,isNew:this.props.isNew,planting:this.props.planting,openedCluster:"",selectedCluster:null,selectedClusterItem:null,errors:{count:0},disabled:!1,varieties:[],changed:!1,requiredFields:[{name:"size",min:0,max:1e13,type:"number"},{name:"crop",min:1,max:100},{name:"name",min:1,max:100},{name:"variety",min:1,max:300},{name:"plantSpacing",min:1,max:40,condition:{name:"totalPlantsOverride",value:!1}},{name:"plantDensity",min:1,max:40,condition:{name:"totalPlantsOverride",value:!1}},{name:"totalPlants",min:1,max:40},{name:"date",min:1,max:40}]}}componentDidMount(){if(this.props.isNew){const e=new Date;this.setState({planting:{totalPlantsOverride:!1,date:e.toISOString().substr(0,10)}})}else{const{planting:e}=this.state,{crops:t}=this.props.metaData;if(e.variety&&e.crop){const a=t.find(t=>t.sk===e.crop)&&t.find(t=>t.sk===e.crop).varieties.find(t=>t.sk===e.variety);a&&this.setState({cultivarType:a.cultivarType,cultivarName:a.cultivar,rootStockType:a.rootStockType,rootStockName:a.rootStock})}}}validateField(e,t){const a=jn(e,this.state.planting,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}generateRows(e){const t=[];if(!e)return t;const{getFromGlobalState:a}=this.props,n=a("cropTypesSetting");return n||0!==n.length?(e.forEach(e=>{const a=e.cropType?e.cropType:e.sk.substring(0,e.sk.indexOf("_setchild_")),i=n.find(e=>e.sk===a),r=i?i.name:"";e.varieties&&e.varieties.forEach(a=>{const n=`${a.cultivarType} ${a.cultivar} ${a.rootStockType}`;t.push({parentSK:e.sk,sk:a.sk,varietyCombo:n,cropType:r,name:e.name,cultivarType:a.cultivarType,rootStockType:a.rootStockType,rootStock:a.rootStock,variety:a.cultivar})})}),t):t}render(){var e;const{classes:t,open:a,isNew:n,setClose:r,handleUpdatePlantings:l,blockSK:s,metaData:o,allowDelete:c,handleDeletePlantings:d,block:m,getFromGlobalState:p}=this.props,{planting:h,errors:u,requiredFields:b,selectedCluster:v,selectedClusterItem:y,openedCluster:f,cultivarType:S,cultivarName:x,rootStockType:k,rootStockName:D}=this.state,P=$n(h,b),{crops:F}=o;if(!h)return null;!h.totalPlantsOverride&&o.block&&(h.totalPlants=Qe(h.plantSpacing,h.plantDensity,h.size?h.size:o.block.size)),h.size||(h.size=m.size);const N=o.clusters?o.clusters:[];return i.a.createElement(Ia,{open:a,dialogObject:h,setClose:r,isNew:n,handleUpdateDialogObject:l.bind(this),skPrimary:"_planting_",dynamoType:"plantings",valid:P,changed:this.state.changed,newTitle:"New Planting",subTitle:`Block ${m.number} v.${h.version?h.version:"0"}`,title:`${ae(h.crop,o.crops,"name")} - ${h.variety?ae(h.variety,F.find(e=>e.sk===h.crop)&&(null===(e=F.find(e=>e.sk===h.crop))||void 0===e?void 0:e.varieties),"cultivar"):""} - ${h.name?h.name:""} `,parentKey:s,allowDelete:c&&d,handleDeleteDialogObject:d?d.bind(this):void 0,getFromGlobalState:p},i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(ai.a,{checked:h.disabled,onChange:this.handleSwitchChange,name:"disabled",id:"disabled",color:"primary"}),label:"Disable Planting"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"text",id:"name",label:"Name",name:"name",value:h.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.name||void 0,helperText:u.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(O.a,{className:t.cluster},i.a.createElement(bn.a,{shrink:!0},"Available clusters"),i.a.createElement(vn.a,{className:t.formControlC},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Cluster group"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:v?v.sk:"",onChange:this.handleClusterChange,onBlur:this.handleBlur,inputProps:{name:"clusterGroup",id:"clusterGroup"}},i.a.createElement("option",{value:""}),N&&N.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))),i.a.createElement(vn.a,{className:t.formControlC},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Cluster"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:y?y.name:"",onChange:this.handleClusterItemChange,onBlur:this.handleBlur,inputProps:{name:"clusterGroupItem",id:"clusterGroupItem"}},i.a.createElement("option",{value:""}),v&&v.list&&v.list.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))),i.a.createElement(vn.a,{className:t.formControlC},i.a.createElement(B.a,{style:{paddingLeft:"12px"},variant:"subtitle1"},"Add to cluster",i.a.createElement(I.a,{placement:"top",title:"Add to cluster"},i.a.createElement(E.a,{disabled:!v||!y,"aria-label":"Add",color:"secondary",className:t.menuButton,onClick:this.handleAddCluster},i.a.createElement(C.a,null))))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(B.a,{variant:"subtitle1"}," Clusters for this planting"),i.a.createElement(tn.a,{component:"nav","aria-label":"main mailbox folders"},h.clusters&&h.clusters.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement(en.a,{button:!0,onClick:t=>this.handleClusterOpen(e.sk)},i.a.createElement(ti.a,{primary:ae(e.sk,N,"name")}),f===e.sk?i.a.createElement(Qn.a,null):i.a.createElement(w.a,null),i.a.createElement(E.a,{"aria-label":"Delete",color:"secondary",className:t.menuButton,id:e.sk,inputProps:{name:e.sk,id:e.sk},onClick:t=>this.handleDeleteCluster(e.sk)},i.a.createElement(ei.a,null))),i.a.createElement(T.a,{in:f===e.sk,timeout:"auto",unmountOnExit:!0},i.a.createElement(tn.a,{component:"div",disablePadding:!0},e.items&&e.items.map(a=>{var n;return i.a.createElement(en.a,{button:!0,className:t.nested},i.a.createElement(ti.a,{primary:ae(a,null===(n=N.find(t=>t.sk===e.sk))||void 0===n?void 0:n.list,"name")}),i.a.createElement(E.a,{"aria-label":"Delete",color:"secondary",className:t.menuButton,id:a,inputProps:{name:a,id:a},onClick:t=>this.handleDeleteClusterItem(e.sk,a)},i.a.createElement(ei.a,null)))})))))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"text",id:"cluster",label:"Clusters (Optional)",name:"cluster",value:h.cluster,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.cluster||void 0,helperText:u.cluster})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"size",label:"Size (Hectares)",name:"size",value:h.size,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.size||void 0,helperText:u.size})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Crop"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:h.crop,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.crop||void 0,inputProps:{name:"crop",id:"crop"}},i.a.createElement("option",{value:""}),F&&F.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),u.crop&&i.a.createElement(En.a,{className:t.helperText},u.crop))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cultivarType"},"Cultivar type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:0===F.filter(e=>e.sk===h.crop).length,value:S,onChange:this.handleLocalChange,inputProps:{name:"cultivarType",id:"cultivarType"}},i.a.createElement("option",{value:""}),F&&h.crop&&F.find(e=>e.sk===h.crop)&&this.createUnique(F.find(e=>e.sk===h.crop).varieties,"cultivarType").map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cultivarName"},"Cultivar name"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:null===S,value:x,onChange:this.handleLocalChange,inputProps:{name:"cultivarName",id:"cultivarName"}},i.a.createElement("option",{value:""}),F&&h.crop&&F.find(e=>e.sk===h.crop)&&this.createUnique(F.find(e=>e.sk===h.crop).varieties.filter(e=>e.cultivarType===S),"cultivar").map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cultivarName"},"Rootstock type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:null===x,value:k,onChange:this.handleLocalChange,inputProps:{name:"rootStockType",id:"rootStockType"}},i.a.createElement("option",{value:""}),F&&h.crop&&S&&x&&this.createUnique(F.find(e=>e.sk===h.crop).varieties.filter(e=>e.cultivarType===S&&e.cultivar===x),"rootStockType").map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cultivarName"},"Rootstock name"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:null===k,value:D,onChange:this.handleLocalChangeSetVariety,inputProps:{name:"rootStockName",id:"rootStockName"}},i.a.createElement("option",{value:""}),F&&h.crop&&S&&x&&k&&this.createUnique(F.find(e=>e.sk===h.crop).varieties.filter(e=>e.cultivarType===S&&e.cultivar===x&&e.rootStockType===k),"rootStock").map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},style:{minWidth:"150px"},id:"plantSpacing",label:"Plant Spacing in m",name:"plantSpacing",value:h.plantSpacing,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.plantSpacing||void 0,helperText:u.plantSpacing})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},style:{minWidth:"150px"},id:"plantDensity",label:"Row spacing in m",name:"plantDensity",value:h.plantDensity,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.plantDensity||void 0,helperText:u.plantDensity})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:h.totalPlants>=-1||void 0,htmlFor:"totalPlants"},"Total plants in block"),i.a.createElement(zt.a,{margin:"normal",required:!0,style:{minWidth:"150px"},type:"number",inputProps:{min:"0.0000000001",step:"any"},id:"totalPlants",name:"totalPlants",disabled:!h.totalPlantsOverride,value:h.totalPlants,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.totalPlants||void 0,helperText:u.totalPlants}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"plantingOverride",control:i.a.createElement(Cn.a,{color:"secondary",name:"totalPlantsOverride",checked:h.totalPlantsOverride,onClick:this.overrideTotalPlants}),label:"Override"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"date",id:"date",label:"Plant Date",name:"date",InputLabelProps:{shrink:!0},value:h.date,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.date||void 0,helperText:u.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"date",id:"harvestDate",label:"Next harvest Date",name:"harvestDate",InputLabelProps:{shrink:!0},value:h.harvestDate,onChange:this.handleChange,onBlur:this.handleBlur,error:!!u.harvestDate||void 0,helperText:u.harvestDate}))))}}var ii=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},formControlC:{minWidth:100,margin:e.spacing(1)},cluster:{padding:e.spacing(1),margin:e.spacing(1)},nested:{paddingLeft:e.spacing(4)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(ni),ri=a(743);function li(e){const{classes:t,onChange:a,operators:n,title:r,value:l,handleBlur:s,error:o,team:c}=e,d=function(e){if(!e)return{};const t={},a=e&&e.filter(e=>e.enabled).sort((e,t)=>(""+e.surname).localeCompare(t.surname,void 0,{numeric:!1}));for(let n=0;ni.a.createElement("option",{value:e[0]},e[0]))),o&&i.a.createElement(En.a,{className:t.helperText},o))),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"assignedTo"},r),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:l,onChange:a,onBlur:s,error:!!o||void 0,inputProps:{name:"operator",id:"operator"}},i.a.createElement("option",{"aria-label":"None",value:""}),d&&d[c]&&d[c].map(e=>i.a.createElement("option",{value:e.sk},`${e.name} ${e.surname}`))),o&&i.a.createElement(En.a,{className:t.helperText},o))))}li.defaultProps={error:""};var si=Object(v.a)(e=>({progress:{margin:e.spacing(2)},helperText:{color:"red"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))(li);var oi=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,handleBlur:r,handleChange:l,block:s,planting:o,metaData:c}=e;return a.actualLiters=((e,t,a)=>{if(!e)return;const n=a.flowunit;let i=0;return"hectare"===n?i=parseFloat(e)*parseFloat(a.volumePerHour)*parseFloat(t.size?t.size:a.size):"plant"===n&&(i=e*a.volumePerHour*t[0].totalPlants),Math.round(i)})(a.duration,o,s),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:a.date,onChange:l.bind(this),onBlur:r,error:!!n.date||void 0,helperText:n.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",fullWidth:!0,id:"duration",label:"Duration",name:"duration",value:a.duration,InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"hours"),min:"0.00001",step:"any"},onChange:l.bind(this),onBlur:r.bind(this),error:!!n.duration||void 0,helperText:n.duration})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"actualLiters"},"Applied"),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"liters"),min:"0.00001",step:"any"},fullWidth:!0,id:"actualLiters",name:"actualLiters",value:a.actualLiters,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.actualLiters||void 0,helperText:n.actualLiters}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:l.bind(this),operators:c.operators,title:"Operator",value:a.operator,team:a.team,onBlur:r,error:n.operator})))}));var ci=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)},paper:{margin:e.spacing(2),padding:e.spacing(2)},tooltip:{backgroundColor:"white"}}))((function(e){var t;const{classes:a,record:n,errors:r,handleBlur:l,metaData:s,overrideTotal:o,handleChange:c,planting:d}=e,m=e.getFromGlobalState("combinations").filter(e=>"Fertiliser"===e.combinationType);console.log("data we are looking for",m,n);let p=!1;m.length>=1&&(p=!0);const h=m.find(e=>e.sk===n.product)||null,u=!!h;u&&(n.combinations=n.combinations||[]);const b=s.fertilisers.filter(e=>!e.isDisabled).concat(m);let v;if(n.endDate=n.endDate?n.endDate:_(),n.startDate=n.startDate?n.startDate:_(),n.endDate&&(n.endTime=n.endTime?n.endTime:Z()),n.product){const e=((e,t)=>{if(!e)return;return t.find(t=>t.sk===e)})(n.product,b);v=null===e||void 0===e?void 0:e.unit}return n.unit&&("plant"===n.unit?n.totalUnit="kg"===v?"g":"ml":n.totalUnit="kg"===v?"kg":"l"),n.volume&&!n.totalOverride&&("plant"===n.unit?n.total=(n.volume*d[0].totalPlants).toFixed(2):"ha"===n.unit?n.total=(n.volume*d[0].size).toFixed(2):n.total=n.volume),console.log("record",n),i.a.createElement(g.a,{container:!0,className:a.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:n.date,onChange:c.bind(this),onBlur:l,error:!!r.date||void 0,helperText:r.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"time",id:"endTime",label:"End Time",name:"endTime",InputLabelProps:{shrink:!0},value:n.endTime,onChange:c.bind(this),onBlur:l,error:!!r.endTime||void 0,helperText:r.endTime})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Fertiliser"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:n.product,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.product||void 0,inputProps:{name:"product",id:"product"}},i.a.createElement("option",{value:""}),b&&b.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.product&&i.a.createElement(En.a,{className:a.helperText},r.product))),u?null===h||void 0===h||null===(t=h.combinationProducts)||void 0===t?void 0:t.map((e,t)=>{var o,m,p,h;return i.a.createElement(g.a,{item:!0,style:{marginTop:20},container:!0,className:a.root,spacing:1,alignItems:"flex-end",key:t},"chemical"===e.type?i.a.createElement(g.a,{style:{border:"1px solid #eee",padding:5},container:!0},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===e||void 0===e||null===(o=e.selectedChemical)||void 0===o?void 0:o.name," (Chemical)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,onChange:a=>{var i;const r={...n};r.product=null===e||void 0===e||null===(i=e.selectedChemical)||void 0===i?void 0:i.sk,r.type="sprayings",r.chemrigs=a.target.value;const l=n.combinations||[];l.splice(t,1,r),n.combinations=l},onBlur:l.bind(this),error:!!r.chemrigs||void 0,inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),s.chemequips&&s.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.chemrigs&&i.a.createElement(En.a,{className:a.helperText},r.chemrigs))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",type:"number",inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",name:"numRigs",InputLabelProps:{shrink:!0},onChange:e=>{var a;const i=n.combinations[t]||{};i.numRigs=e.target.value;const r=null===(a=(null===s||void 0===s?void 0:s.chemequips)||[])||void 0===a?void 0:a.find(e=>e.sk===i.chemrigs);i.volume=(parseFloat((null===r||void 0===r?void 0:r.capacity)||1)*e.target.value).toFixed(2);const l=n.combinations||[];l.splice(t,1,i),n.combinations=l},onBlur:l.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",type:"number",InputLabelProps:{shrink:!0},disabled:!0,id:"volume",label:"Total volume",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"liters"),min:"0.00001",step:"any"},value:null===(m=n.combinations[t])||void 0===m?void 0:m.volume,onBlur:l.bind(this),error:!!r.volume||void 0,helperText:r.volume}))):i.a.createElement(g.a,{container:!0,className:a.root,spacing:1,alignItems:"flex-end",style:{border:"1px solid #eee",padding:5}},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement("label",{style:{marginTop:20}},null===e||void 0===e||null===(p=e.selectedFertiliser)||void 0===p?void 0:p.name," (fertiliser)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,onChange:a=>{var i;const r=n.combinations[t]||{...n};delete r.combinations,r.product=null===e||void 0===e||null===(i=e.selectedFertiliser)||void 0===i?void 0:i.sk,r.type="fertilisings",r.unit=a.target.value,a.target.value&&("plant"===a.target.value?r.totalUnit="kg"===(null===e||void 0===e?void 0:e.selectedFertiliser.unit)?"g":"ml":r.totalUnit="kg"===(null===e||void 0===e?void 0:e.selectedFertiliser.unit)?"kg":"l");const l=n.combinations||[];l.splice(t,1,r),n.combinations=l},onBlur:l.bind(this),error:!!r.unit||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"cluster"},"Cluster"),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),r.unit&&i.a.createElement(En.a,{className:a.helperText},r.unit))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},id:"volume",label:"Applied quantity",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},onChange:e=>{const a=n.combinations[t]||{};a.volume=e.target.value,e.target.value&&("plant"===a.unit?a.total=(parseFloat(e.target.value)*d[0].totalPlants).toFixed(2):"ha"===a.unit?a.total=(parseFloat(e.target.value)*d[0].size).toFixed(2):a.total=parseFloat(e.target.value));const i=n.combinations||[];i.splice(t,1,a),n.combinations=i},onBlur:l.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"total",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},label:"Total",name:"total",value:null===(h=n.combinations[t])||void 0===h?void 0:h.total,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.total||void 0,helperText:r.total}))))}):i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:n.unit,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.unit||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"cluster"},"Cluster"),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),r.unit&&i.a.createElement(En.a,{className:a.helperText},r.unit))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},id:"volume",label:"Applied quantity",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},value:n.volume,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"total",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},label:"Total",name:"total",value:n.total,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.total||void 0,helperText:r.total}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"totalOverride",control:i.a.createElement(Cn.a,{color:"secondary",name:"totalHarvestOverride",checked:n.totalOverride,id:"totalOverride",onClick:o.bind(this)}),label:"Override"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:c.bind(this),operators:s.operators,title:"Operator",value:n.operator,team:n.team,onBlur:l,error:r.operator})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"notes",label:"Notes",name:"notes",multiline:!0,rowsMax:"4",value:n.notes,onChange:c.bind(this),onBlur:l.bind(this),error:!!r.notes||void 0,helperText:r.notes})))})),di=a(1754),mi=a(830),pi=a.n(mi),hi=a(829),gi=a.n(hi),ui=a(826),bi=a.n(ui),vi=a(823),yi=a.n(vi),fi=a(827),Ei=a.n(fi),Si=a(824),Ci=a.n(Si),xi=a(832),ki=a.n(xi),wi=a(831),Ti=a.n(wi),Di=a(825),Pi=a.n(Di),Fi=a(828),Ni=a.n(Fi),Bi=a(281),Li=a.n(Bi),Ai=a(1755),Oi=a(1773),Ii=a(1747),Gi=a(530);const Ri=Object(z.a)({root:{flexGrow:1,backgroundColor:"inherit"}});function Ui(e){const{children:t,value:a,index:n,...r}=e;return i.a.createElement(B.a,Object.assign({component:"div",role:"tabpanel",hidden:a!==n,id:"scrollable-auto-tabpanel-"+n,"aria-labelledby":"scrollable-auto-tab-"+n},r),i.a.createElement(Gi.a,{p:0},t))}function Mi(e){const t=Ri(),{children:a,value:n,handleChange:r,selectedTab:l}=e;return i.a.createElement(O.a,{className:t.root,elevation:0},i.a.createElement(Oi.a,{value:n,onChange:r,indicatorColor:"secondary",textColor:"primary",variant:"scrollable",scrollButtons:"auto"},a&&a.length&&a.filter(e=>e).map((e,t)=>i.a.createElement(Ii.a,Object.assign({label:e.props.heading},function(e){return{id:"scrollable-auto-tab-"+e,"aria-controls":"scrollable-auto-tabpanel-"+e}}(t))))),a&&a.length&&a.map((e,t)=>i.a.createElement(Ui,{value:n,index:t},n===t&&e)))}Oi.a.propTypes={className:ce.a.string,handleChange:ce.a.func,value:ce.a.any.isRequired,selectedTab:ce.a.number.isRequired,children:ce.a.oneOfType([ce.a.arrayOf(ce.a.node),ce.a.node]).isRequired};var Wi=a(1748),zi=a(1749);class Ki extends n.Component{constructor(e){super(e),this.state={}}render(){const{classes:e,open:t,setClose:a,children:n}=this.props;return i.a.createElement(yt.a,{open:t,onClose:a,"aria-labelledby":"responsive-dialog-title",fullScreen:!1},i.a.createElement(Et.a,null,n,i.a.createElement(ft.a,null,i.a.createElement(Ct.a,{variant:"contained",color:"secondary",className:e.submit,onClick:a}," Close "))))}}var Hi=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1}}))(Ki);class qi extends n.Component{constructor(e){super(e),this.getTargetUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",contentType:t};return await Fa(a)},this.getUrls=async(e,t)=>{if(!e)return null;if(e.images)for(const a of e.images)if(!t[a.Key]){const e=await this.getTargetUrl(a.Key,a.fileType);t[a.Key]=e}return t},this.state={isloading:!1,isNew:this.props.isNew,targetStage:this.props.targetStage,changed:!1}}async componentDidMount(){const{getFromGlobalState:e,setGlobalState:t}=this.props,a={...e("imageUrls")},{targetStage:n}=this.props;t({imageUrls:await this.getUrls(n,a)})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,targetStage:l,getFromGlobalState:s,onClose:o}=this.props,{pest:c,errors:d}=this.state,m=s("imageUrls"),p=s("isMobile");return l?i.a.createElement(Hi,{open:!0,setClose:o,isMobile:p},i.a.createElement("div",{style:{zIndex:6e3}},i.a.createElement(B.a,{variant:"subtitle1"},l&&l.procedure?l.procedure:""),i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{className:e.root},i.a.createElement(Wi.a,{className:e.imageList,cols:l&&l.images&&l.images.length>1?2.5:1},l&&l.images&&l.images.map((e,t)=>i.a.createElement(zi.a,{key:e.Key,style:{minWidth:"220px",height:"220px"}},m&&m[e.Key]?i.a.createElement("img",{key:e.Key,style:{objectFit:"cover",height:"100%"},alt:"target",src:m[e.Key]}):i.a.createElement("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}},i.a.createElement(P.a,{color:"secondary"})))))))))):null}}var Vi=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},root:{display:"flex",flexWrap:"wrap",justifyContent:"space-around",overflow:"hidden",backgroundColor:e.palette.background.paper},imageList:{flexWrap:"nowrap",transform:"translateZ(0)"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{color:e.palette.primary.light},titleBar:{background:"linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, rgba(0,0,0,0) 100%)"},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)}}))(qi),ji=a(1750);Object(z.a)(e=>({root:{width:"100%",maxWidth:360,backgroundColor:e.palette.background.paper},nested:{paddingLeft:e.spacing(4)}}));var $i=a(580),Yi=(a(1536),a(819)),_i=a.n(Yi),Zi=a(820),Ji=a.n(Zi),Qi=a(821),Xi=a.n(Qi),er=a(822),tr=a.n(er);Object($i.registerPlugin)(Xi.a,tr.a,_i.a,Ji.a);class ar extends n.Component{constructor(e){super(e),this.handleProcessing=(e,t,a,n,i,r,l,s,c,d,m)=>{const p={loaded:{},total:0},h=this.props.folder;let g=[];Array.isArray(t)?g=t.map(e=>{const t={...e};return t.isThumb=!1,t.isPreview=!1,"thumb"===t.name&&(t.file.isThumb=!0),"preview"===t.name&&(t.file.isPreview=!0),t.file}):g.push(t),g.forEach(e=>{let t=h;e.isThumb&&(t=`${h}${this.props.thumbNailFolder}/`),e.isPreview&&(t=h+"preview/");let a=`${h}${e.name}`;if(s){const t=e.name.substring(e.name.indexOf("."),e.name.length);a=`${h}${c}${t}`}p.total+=e.size;try{(function(e,t,a,n,i,r,l,s,c,d=null,m=null){const p=new XMLHttpRequest;o.a.post("farms","/signedUrl",{body:{activeTenant:n,path:i,contentType:t.type,type:"files",isGeneral:d,setId:m}}).then(e=>{!e.status||e.status>=200&&e.status<300?(p.open("PUT",e),p.upload.onprogress=function(e){s(e.lengthComputable,e.loaded,e.total)},p.onload=function(){p.status>=200&&p.status<300?r(i):l("Failed to upload file")},p.onerror=function(e){l("Failed to upload file")},p.send(t)):l("Could not get the upload URL")}).catch(e=>{e&&l(e.response.data.error)})})(0,e,0,this.props.activeTenant,a,n,i,r,l,d,m)}catch(g){throw g}})},this.state={files:[],thumbFiles:[]}}componentDidMount(){}handleInit(){this.setState({thumbFiles:[]})}handleProgress(e){}handleOnLoad(e,t,a,n,i,r,l){console.log("onload")}getTotal(e){let t=0;return Object.values(e).forEach(e=>t+=e),t}render(){const{acceptedFileTypes:e,maxFileSize:t,maxFiles:a,forceName:n,fileName:r,allowFileTypeValidation:l,imageTransformVariantsIncludeOriginal:s,imageResizeTargetWidth:o,imageResizeTargetHeight:c,allowImageResize:d,allowImageTransform:m,allowImageExifOrientation:p,onFileUploadStart:h,allowMultiple:g,isGeneral:u,setId:b,onError:v,imageTransformOutputQuality:y,error:f}=this.props;return i.a.createElement("div",{className:"App"},i.a.createElement($i.FilePond,{ref:e=>this.pond=e,allowImagePreview:!1,allowFileTypeValidation:l,credits:!1,imageTransformOutputQuality:y,maxFileSize:t,acceptedFileTypes:e,files:this.state.files,allowMultiple:g,allowImageResize:d,allowImageTransform:m,allowImageExifOrientation:p,maxFiles:this.props.generateIcon?1:a,server:{process:(e,t,a,i,l,s,o)=>{this.handleProcessing(e,t,a,i,l,s,o,n,r,u,b)}},oninit:()=>this.handleInit(),labelFileProcessingError:function(e){return console.log("serverError",e),f?(v(f),"Upload error: "+e.message):(v&&v(e),"Upload error: "+e.message)},imageResizeTargetWidth:d?o:void 0,imageResizeTargetHeight:d?c:void 0,imageResizeMode:d?"contain":void 0,oninitfile:e=>{h&&h(e)},onaddfile:(e,t)=>{e&&v&&v(e)},onpreparefile:(e,t)=>{},onprocessfile:(e,t)=>{e&&v&&v(e),this.props.onFileUploaded&&this.props.onFileUploaded(t,this.state.files),console.log("processfile",t.serverId)},onupdatefiles:e=>{}}))}}ar.defaultProps={maxFiles:20,generatePreview:!0,imageTransformVariantsIncludeOriginal:!0,thumbNailFolder:"thumbs",containerImageFileName:"",imageResizeTargetWidth:800,imageResizeTargetHeight:180,allowImagePreview:!0,allowImageResize:!0,allowImageTransform:!0,allowImageExifOrientation:!0,generateIcon:!1,onFileUploadStart:null,allowMultiple:!0,allowFileTypeValidation:!1,acceptedFileTypes:[],forceName:!1,fileName:null,maxFileSize:"20MB",isGeneral:!1,setId:"",onError:null,imageTransformOutputQuality:null};var nr=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},section:{margin:e.spacing(2,4)}}))(ar);class ir extends n.Component{constructor(e){super(e),this.getTargetUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.getUrls=async(e,t)=>{if(!e)return null;for(let a=0;a{},this.onFileUploadStart=e=>{},this.fileUploadedLocal=async(e,t)=>{const{fileUploaded:a,getFromGlobalState:n,setGlobalState:i}=this.props,r={...n("imageUrls")};if(!r[e.serverId]){const t=await this.getTargetUrl(e.serverId,e.fileType);r[e.serverId]=t,i({imageUrls:r})}await a(e,t,t.stageSK,t.set,t.subSet)},this.state={isloading:!1,isNew:this.props.isNew,targetStage:this.props.targetStage,changed:!1}}async componentDidMount(){const{getFromGlobalState:e,setGlobalState:t}=this.props,a={...e("imageUrls")},{record:n,monitoring:i}=this.props,r=n.observations?n.observations.find(e=>e.stageSK===i.stageSK):null,l=r&&r.pictures?r.pictures:null,s=l&&l[i.set]&&l[i.set][i.subSet]?l[i.set][i.subSet]:[];t({imageUrls:await this.getUrls(s,a)})}shouldComponentUpdate(e,t){return!e.uploading}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,monitoring:l,getFromGlobalState:s,onClose:o,fileUploaded:c,record:d,onFileUploadStart:m}=this.props,p=s("imageUrls"),h=s("isMobile"),u=d.observations?d.observations.find(e=>e.stageSK===l.stageSK):null,b=u&&u.pictures?d.observations.find(e=>e.stageSK===l.stageSK).pictures:[],v=b&&b[l.set]&&b[l.set][l.subSet]?b[l.set][l.subSet]:[];return l?i.a.createElement(Hi,{open:!0,setClose:o,isMobile:h},i.a.createElement("div",{style:{zIndex:6e3}},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{className:e.root},i.a.createElement(Wi.a,{className:e.imageList,cols:d&&l.images&&l.images.length>1?2.5:1},v&&v.map((e,t)=>i.a.createElement(zi.a,{key:e.Key,style:{maxWidth:"220px",height:"220px"}},p&&p[e.Key]?i.a.createElement("img",{key:e.Key,style:{objectFit:"cover",height:"100%"},alt:"target",src:p[e.Key]}):i.a.createElement("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}},i.a.createElement(P.a,{color:"secondary"}))))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{style:{minWidth:"240px"}},i.a.createElement(nr,{activeTenant:this.props.getFromGlobalState("activeSite"),generateThumbnail:!1,generatePreview:!1,onFileUploaded:e=>c(e,l,l.stageSK,l.set,l.subSet),folder:`images/monitoring/${l.stageSK}/`,isGeneral:!1,allowImageResize:!0,imageResizeTargetWidth:300,imageResizeTargetHeight:300,imageTransformVariantsIncludeOriginal:!1,getFromGlobalState:this.props.getFromGlobalState,onFileUploadStart:m})))))):null}}var rr=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},root:{display:"flex",flexWrap:"wrap",justifyContent:"space-around",overflow:"hidden",backgroundColor:e.palette.background.paper},imageList:{flexWrap:"nowrap",transform:"translateZ(0)"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{color:e.palette.primary.light},titleBar:{background:"linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, rgba(0,0,0,0) 100%)"},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)}}))(ir),lr=a(1751),sr=a(1753),or=a(1752);var cr=Object(v.a)(e=>({root:{width:"100%",display:"block",padding:"0px"},heading:{fontSize:e.typography.pxToRem(15)},secondaryHeading:{fontSize:e.typography.pxToRem(15),color:e.palette.text.secondary},icon:{verticalAlign:"bottom",height:20,width:20},details:{width:"100%",display:"block",padding:"0px"},column1:{flexBasis:"60%"},column2:{flexBasis:"30%"},column2B:{flexBasis:"40%",paddingLeft:"8px",float:"right"},column3:{flexBasis:"10%"},helper:{borderLeft:"2px solid "+e.palette.divider,padding:e.spacing(1,2)},link:{color:e.palette.primary.main,textDecoration:"none","&:hover":{textDecoration:"underline"}}}),{withTheme:!0})((function(e){const{classes:t,handleExpand:a,children:n,heading:r,headingComponent:l,detailHeading:s,expandIcon:o,expanded:c,type:d,overwriteDisplay:m,onClear:p,onSave:h,disablePadding:g,action:u,detailComponent:b,disabled:v}=e;let y=!1,f=g?{borderBottom:0,padding:"0px",display:"block"}:void 0;f=m?{display:"block"}:f;const E=o||i.a.createElement(w.a,null);return y=d?c===d:c===r,i.a.createElement(lr.a,{mountOnEnter:!0,disabled:v,style:g?{borderBottom:0,boxShadow:"none",border:"none",borderTop:0}:void 0,elevation:g?0:void 0,classes:{root:t.root},unmountOnExit:!0,TransitionProps:{unmountOnExit:!0},className:t.root,expanded:y,onChange:e=>{a(r)}},i.a.createElement(or.a,{expandIcon:E,"aria-controls":"panel1c-content",id:"panel1c-header",elevation:g?0:void 0,style:g?{borderBottom:0}:void 0},!l&&i.a.createElement("div",{className:t.column1},i.a.createElement(B.a,{className:t.heading},r)),l&&i.a.createElement("div",{className:t.column1},l),!b&&i.a.createElement("div",{className:t.column2B},i.a.createElement(B.a,{className:t.secondaryHeading},s)),b&&i.a.createElement("div",{className:t.column2},b),y&&u&&i.a.createElement("div",{className:t.column3},u)),i.a.createElement(sr.a,{elevation:g?0:void 0,style:f},n))}));const dr=Object(v.a)(e=>({badge:{right:-3,top:0,border:"2px solid "+e.palette.background.paper,padding:"0 4px"}}))(di.a),mr=(e,t,a)=>{let n;return"right"===e?n="Number"===t||"Percentage"===t?i.a.createElement(yi.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36}):"Present"===t?i.a.createElement(Ci.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36}):i.a.createElement(Pi.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36}):"left"===e&&(n="Number"===t||"Percentage"===t?i.a.createElement(bi.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36}):"Present"===t?i.a.createElement(Ei.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36}):i.a.createElement(Ni.a,{color:a?"primary":"secondary",style:{fontSize:"36px"},size:36})),n},pr=(e,t,a,n,r,l,s,o,c,d,m,p,h,g,u,b,v,y,f)=>{let S="";const C=n.observations?n.observations.findIndex(e=>e.stageSK===t.sk||e.targetDetailSK===t.sk):-1,x=a&&a.set?a.set:0,k=a[t.sk]&&a[t.sk].subSet?a[t.sk].subSet:0,w=((e,t,a,n)=>{const i=e.observations?e.observations.findIndex(e=>e.stageSK===n.sk):-1;return!!(-1!==i&&e.observations[i].entries.length>t&&e.observations[i].entries[t].length>a)})(n,x,k,t),T=!f&&!y&&(!b||b&&v&&b.accuracy>50);let D=0;if(S=w?n.observations[C].entries[x][k]:"",-1!==C){var P,F;if("Present"===t.unitNum)1===S&&(S="Present"),0===S&&(S="Absent");else S=(null===n||void 0===n?void 0:n.observations)&&(null===n||void 0===n?void 0:n.observations[C])&&(null===n||void 0===n||null===(P=n.observations[C])||void 0===P?void 0:P.entries[x])&&(null===n||void 0===n||null===(F=n.observations[C])||void 0===F?void 0:F.entries[x][k])||0;D=n.observations[C].pictures&&n.observations[C].pictures[x]&&n.observations[C].pictures[x][k]?n.observations[C].pictures[x][k].length:0}const N=mr("right",t.unitNum,T),B=mr("left",t.unitNum,T);return i.a.createElement(i.a.Fragment,null,i.a.createElement("div",null,i.a.createElement("div",{style:{overflow:"hidden",display:"inline-block",maxWidth:"65%",whiteSpace:"nowrap",textOverflow:"ellipsis"}},i.a.createElement(bn.a,{style:{display:"inline",maxWidth:"60px"},shrink:!0},t.stageDescription?`${t.stageDescription} (${t.unit?t.unit:""})`:"")),i.a.createElement("div",{style:{float:"right"}},i.a.createElement(E.a,{onClick:a=>g(a,e,t.sk,x,k,t.unitNum)},i.a.createElement(dr,{color:"primary",badgeContent:D},i.a.createElement(gi.a,{color:"secondary"}))),i.a.createElement(E.a,{onClick:a=>u(a,e,t.sk,x,k,t.unitNum)},i.a.createElement(dr,{color:"primary",badgeContent:0},i.a.createElement(pi.a,{color:"secondary"}))))),i.a.createElement("div",{style:{width:"100%",textAlign:"center",whiteSpace:"nowrap",marginTop:"12px"}},t.quantityOfUnit&&parseInt(t.quantityOfUnit)>1&&i.a.createElement("div",{style:{display:"inline-block",marginTop:"14px",marginBottom:"14px"}},i.a.createElement(E.a,{edge:"start",color:"inherit",disabled:0===k,onClick:e=>h(e,t.sk),"aria-label":"save"},i.a.createElement(Ti.a,{color:0===k?"primary":"secondary",style:{fontSize:"36px"},size:36}))),i.a.createElement(di.a,{color:t.quantityOfUnit&&parseInt(t.quantityOfUnit)>1&&k+1===parseInt(t.quantityOfUnit)&&w||w&&k+1>=parseInt(t.quantityOfUnit)?"primary":"error",showZero:!0,invisible:!t.quantityOfUnit||t.quantityOfUnit&&1===parseInt(t.quantityOfUnit),badgeContent:t.quantityOfUnit&&parseInt(t.quantityOfUnit)>1?`${k+1}/${parseInt(t.quantityOfUnit)} Obs`:0,className:m.badge},i.a.createElement(O.a,{elevation:3},i.a.createElement("div",{style:{display:"inline-block"}},i.a.createElement(E.a,{edge:"end",disabled:T,onClick:a=>s(a,e,t.sk,x,k,t.unitNum),"aria-label":"save"},B)),i.a.createElement("div",{style:{display:"inline-block"}},i.a.createElement(vn.a,{className:m.formControl},i.a.createElement(zt.a,{margin:"normal",required:!0,disabled:T,shrink:!0,style:{marginTop:"0px",marginBottom:"0px",marginLeft:"6px",marginRight:"6px"},id:t.sk,name:t.sk,InputLabelProps:{shrink:!0},value:S,onChange:a=>r(a,e,t.sk,x,k,t.unitNum),onBlur:l}))),i.a.createElement("div",{style:{display:"inline-block"}},i.a.createElement(E.a,{edge:"start",disabled:T,onClick:a=>o(a,e,t.sk,x,k,t.unitNum),"aria-label":"save"},N)))),t.quantityOfUnit&&t.quantityOfUnit>1&&i.a.createElement("div",{style:{display:"inline-block"}},i.a.createElement(E.a,{edge:"end",color:"inherit",onClick:e=>p(e,t.sk),"aria-label":"save",disabled:!w},i.a.createElement(ki.a,{color:w?"secondary":"primary",style:{fontSize:"36px"},size:36})))))},hr=(e,t,a)=>{const n=a[0].crop,i=[];for(let r=0;re.monitorType===t);if(a.length>0){const t={...e[r]};t.targetDetail.observableOn[0].stages=[...a],i.push(t)}}}else if(e[r].targetDetail.nonCropDetail.monitorType===t){const t={...e[r]};i.push(t)}return i};var gr=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{maxWidth:"70px",marginTop:"0px",marginBottom:"0px"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},fabProgress:{color:e.palette.secondary.main,position:"absolute",top:12,left:0,zIndex:1}}))((function(e){const{classes:t,record:a,getFromGlobalState:r,handleTabChange:l,selectedTab:s,handleSettingExpand:o,expandedSetting:c,errors:d,handleBlur:m,handleChange:p,onAdd:h,onSubtract:u,metaData:b,planting:v,onForwardSubset:y,onBackSubset:f,setInfo:E,onForwardSet:S,onBackSet:C,isMobile:x,onChangeCounter:k,currentLocation:w,onTakePhoto:T,onShowTargetDetail:D,displayTargetDetail:P,selectedTargetDetail:F,onCloseTargetDetail:N,setGlobalState:L,displayMonitoringPictures:A,monitoringPicture:O,onCloseMonitoringPicture:I,fileUploaded:G,uploading:R,onFileUploadStart:U,isInBlock:M,block:W,foundBlock:z,handleSwitchChange:K,isNew:H,setSelectedTab:q}=e,V=!!(a&&a.geoLocations&&a.geoLocations[E.set]&&a.geoLocations[E.set].accuracy),j=hr(b.monitorings.filter(e=>!0!==e.isDisabled),"Field",v),$=Math.round(2*parseInt(v[0].totalPlants)/100),Y=b.targetTypes?b.targetTypes.filter(e=>j.some(t=>t.targetType===e.sk)):[];return Object(n.useEffect)(()=>{if(!H){var e,t,n;const i=hr(b.monitorings.filter(e=>!0!==e.isDisabled),"Field",v),r=(b.targetTypes?b.targetTypes.filter(e=>i.some(t=>t.targetType===e.sk)):[]).map((e,t)=>e.sk),l=(null===a||void 0===a||null===(e=a.observations[0])||void 0===e?void 0:e.monitoringSK)||null,s=null===i||void 0===i?void 0:i.find(e=>e.sk===l).targetType,c=null===i||void 0===i||null===(t=i.find(e=>e.sk===l))||void 0===t||null===(n=t.targetDetail)||void 0===n?void 0:n.name,d=r.indexOf(s);o(c),q(d)}},[]),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-end"},P&&i.a.createElement("div",{style:{zIndex:2e3}},i.a.createElement(Vi,{targetStage:F,getFromGlobalState:r,onClose:N,setGlobalState:L})),A&&i.a.createElement("div",{style:{zIndex:2e3}},i.a.createElement(rr,{monitoring:O,getFromGlobalState:r,onClose:I,setGlobalState:L,fileUploaded:G,record:a,uploading:R,onFileUploadStart:U})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:null===a||void 0===a?void 0:a.date,onChange:p.bind(this),onBlur:m,error:!!d.date||void 0,helperText:d.date}),i.a.createElement(Fe.a,{control:i.a.createElement(ai.a,{checked:a.ignoreLocation,onChange:K.bind(this),name:"ignoreLocation",id:"ignoreLocation",color:"primary"}),label:"Ignore location"})),w&&i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:8,lg:8,xl:8},i.a.createElement(B.a,{style:{margin:"5px",float:"right"},variant:"subtitle1"},""+(w&&w?`Accuracy: ${w.accuracy.toFixed(2)} m`:"Locating..."),i.a.createElement(Li.a,{style:w?w&&(null===w||void 0===w?void 0:w.accuracy)<50?{color:"green",paddingLeft:"8px"}:{color:"orange",paddingLeft:"8px"}:{color:"red",paddingLeft:"8px"}}))),!M&&!a.ignoreLocation&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{color:M?void 0:"error",style:{margin:"5px"},variant:"subtitle1"},`You are not in block: ${W.number}, you are in block: ${z?z.number+". Please move to that block or monitor for the block you are in.":"finding block..."}`)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Mi,{value:s,handleChange:l},Y&&Y.map(e=>i.a.createElement("div",{key:e.sk,heading:e.name,name:e.name,style:{width:"100%"}},j&&j.filter(t=>t.targetType===e.sk).map(e=>{if((e=>!!e&&("No"===e.cropSpecific||!!(e.targetDetail&&e.targetDetail.observableOn.length&&e.targetDetail.observableOn[0].stages.length&&e.targetDetail.observableOn[0].stages.filter(e=>e.selected).length)))(e))return i.a.createElement(cr,{heading:e.targetDetail.name,key:e.targetDetail.sk,overwriteDisplay:!0,expanded:c,handleExpand:o},c&&c===e.targetDetail.name&&"Yes"===e.cropSpecific&&e&&e.targetDetail&&e.targetDetail.observableOn&&e.targetDetail.observableOn.length&&e.targetDetail.observableOn[0].stages.filter(e=>e.selected).map(n=>i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},pr(e,n,E,a,k,m,u,h,0,0,t,y,f,v,T,D,w,x,V,a.ignoreLocation))),c&&c===e.targetDetail.name&&"No"===e.cropSpecific&&e&&e.targetDetail&&e.targetDetail.nonCropDetail&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},pr(e,e.targetDetail,E,a,k,m,u,h,0,0,t,y,f,v,T,D,w,x,V,a.ignoreLocation)))}))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ai.a,{variant:"progress",style:x?{position:"absolute",width:"80%",zIndex:1e3,bottom:0,color:E.set+1<$?"red":"green"}:{color:E.set+1<$?"red":"green"},backgroundColor:"inherit",steps:$,nextButton:i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{style:{margin:"5px"},variant:"subtitle1"},`${E.set?E.set+1:1}/${$}`),i.a.createElement(Mt,{onClick:()=>S(!1),variant:"contained",color:"primary",className:t.submit,disabled:!a.ignoreLocation&&!V&&(!w||w&&x&&w.accuracy>50),text:"Next",loadingText:"Next"})),backButton:i.a.createElement(Ct.a,{variant:"contained",color:"secondary",className:t.submit,onClick:C,disabled:!E||!E.set||0===E.set},"Back"),position:"static",activeStep:E&&E.set?E.set+1>$?$:E.set:0,className:t.stepper})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:8,lg:8,xl:8}))}));var ur=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,handleBlur:r,handleChange:l,metaData:s}=e,o=s.agronomistActs;return i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:a.date,onChange:l.bind(this),onBlur:r,error:!!n.date||void 0,helperText:n.date})),i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"activities"},"Activity"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a.activity,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.activity||void 0,inputProps:{name:"activity",id:"activity"}},i.a.createElement("option",{value:""}),o&&o.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),n.activity&&i.a.createElement(En.a,{className:t.helperText},n.activity))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:l.bind(this),operators:s.operators,title:"Operator",value:a.operator,team:a.team,onBlur:r,error:n.operator})))})),br=a(77),vr=a.n(br);const yr=Object(z.a)(e=>({root:{width:"100%",backgroundColor:e.palette.background.paper,maxHeight:"300px",overflowY:"auto"},formControl:{minWidth:120},rootLoad:{display:"flex","& > * + *":{marginLeft:e.spacing(2)}},nested:{paddingLeft:e.spacing(4)}}));function fr(e){const{data:t,handleToggle:a,checkedItems:n,pickApplied:r,handleApplied:l,handleReasonsDataChange:s,arrayName:o,readOnly:c,planting:d,loading:m,hideCheck:p,onSelectAll:h,allSelected:u,handleChange:b,handleBlur:v,handleReentryOverride:y}=e,f=yr();return i.a.createElement(i.a.Fragment,null,m&&i.a.createElement("div",{className:f.rootLoad}," ",i.a.createElement(P.a,{color:"secondary"})," "),h&&i.a.createElement(Fe.a,{value:"start",style:{float:"right"},control:i.a.createElement(xe.a,{checked:u,onChange:h,disableRipple:!0,inputProps:{"aria-labelledby":"SelectAll"}}),label:"Select All",labelPlacement:"start"}),i.a.createElement(tn.a,{className:f.root},t&&t.map(e=>{const t="checkbox-list-label-"+e.sk;return i.a.createElement("div",null,i.a.createElement(en.a,{className:f.nested,disableRipple:!0,disabled:e.disabled,key:e.sk,role:void 0,dense:!0,button:!0,onClick:a&&a.bind(this,e.sk,o,d)},!p&&!e.disabled&&i.a.createElement(ji.a,null,i.a.createElement(xe.a,{edge:"start",checked:n&&-1!==n.findIndex(t=>t.target===e.sk),tabIndex:-1,disableRipple:!0,disabled:!!e.disabled,inputProps:{"aria-labelledby":t}})),i.a.createElement(ti.a,{id:t,primary:""+e.name})),i.a.createElement(i.a.Fragment,null,n&&-1!==n.findIndex(t=>t.target===e.sk)&&i.a.createElement("div",{style:{marginLeft:"30px",marginBottom:"25px"}},i.a.createElement(g.a,{container:!0,className:f.root,spacing:1,alignItems:"flex-start"},r&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(kn.a,{required:!0},"Dosage applied"),i.a.createElement(Fe.a,{value:"applied",labelPlacement:"start",control:i.a.createElement(xe.a,{color:"secondary",name:"applied",id:e.sk,key:e.sk,checked:n.find(t=>t.target===e.sk).applied,onClick:t=>l(t,e.sk,o,d)})})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",disabled:c||n.find(t=>t.target===e.sk).reentryOverride,type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"days"),min:"0.00001",step:"any"},id:"reentry",label:"Re-entry Period",InputLabelProps:{shrink:!0},name:"reentry",value:n.find(t=>t.target===e.sk).reentry,onChange:t=>b(t,e.sk),onBlur:v})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"reentryOverride",label:"or deposit dry",labelPlacement:"end",disabled:c,control:i.a.createElement(xe.a,{color:"secondary",name:"reentryOverride",checked:n.find(t=>t.target===e.sk).reentryOverride,onClick:t=>y(t,e.sk)})})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,disabled:c,type:"number",id:"phi",label:"Pre-harvest interval (PHI)",name:"phi",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"days"),min:"0.00001",step:"any"},InputLabelProps:{shrink:!0},value:n.find(t=>t.target===e.sk).phi,onChange:t=>b(t,e.sk)})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,id:"dosage",label:"Dosage",disabled:c,name:"valperUnit",type:"number",value:n.find(t=>t.target===e.sk).dosage,onChange:t=>b(t,e.sk),InputLabelProps:{shrink:!0}})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:f.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cdosagerop"},"Dosage Unit"),i.a.createElement(Sn.a,{native:!0,disabled:c,required:!0,displayEmpty:!0,value:n.find(t=>t.target===e.sk).dosageUnit,onChange:t=>b(t,e.sk),inputProps:{name:"dosageUnit",id:"dosageUnit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"ml/ha"},"ml/ha"),i.a.createElement("option",{value:"L/ha"},"L/ha"),i.a.createElement("option",{value:"g/ha"},"g/ha"),i.a.createElement("option",{value:"kg/ha"},"kg/ha"),i.a.createElement("option",{value:"/ha"},"/ha"),i.a.createElement("option",{value:"/cluster"},"/cluster"),i.a.createElement("option",{value:"/trap"},"/trap"),i.a.createElement("option",{value:"g/L"},"g/L"),i.a.createElement("option",{value:"g/100L"},"g/100L"),i.a.createElement("option",{value:"ml/100L"},"ml/100L"),i.a.createElement("option",{value:"L/100L"},"L/100L"),i.a.createElement("option",{value:"/m2"},"/m2"),i.a.createElement("option",{value:"ml/plant"},"ml/plant"),i.a.createElement("option",{value:"g/plant"},"g/plant"))))))))})))}fr.defaultProps={onSelectAll:null,allSelected:!1};const Er=Object(z.a)(e=>({root:{width:"180px","& > *":{padding:e.spacing(1)}},paper:{marginBottom:e.spacing(2),padding:e.spacing(1)},formControl:{minWidth:120,marginTop:e.spacing(2)}}));function Sr(e){Er();const{metaData:t,handleSelect:a,checkedItems:n,handleReasonsDataChange:r,pickApplied:l,handleApplied:s,readOnly:o,arrayName:c,planting:d,expandedTarget:m,handleExpand:p,getFromGlobalState:h,handleToggle:g,handleChange:u,handleReentryOverride:b}=e,v=function(e,t){if(!e)return null;const a={},n=t("targetsTypesSetting");for(let i=0;ie.targetType===t);r&&r.length&&(a[t]=r)}return a}(st(t.monitorings,h),h);console.log(v);return i.a.createElement(i.a.Fragment,null,v&&Object.entries(v)&&Object.entries(v).map(e=>i.a.createElement(cr,{heading:e[0],expanded:m,handleExpand:p,expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(fr,{data:e[1],handleChange:u,checkedItems:n,handleToggle:g,handleReentryOverride:b,arrayName:c,planting:d,readOnly:o,pickApplied:l,handleApplied:s,handleReasonsDataChange:r}))))}var Cr=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)},paper:{margin:e.spacing(2),padding:e.spacing(2)},tooltip:{backgroundColor:"white",color:"black",fontSize:"12px",boxShadow:"0px 1px 3px 0px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 2px 1px -1px rgba(0,0,0,0.12)"}}))((function(e){var t;const{classes:a,record:n,errors:r,handleExpand:l,handleReentryOverride:s,handleTargetChange:o,handleApplied:c,expandedTarget:d,getFromGlobalState:m,handleBlur:p,handleChange:h,metaData:u,planting:b,handleToggle:v}=e,y=null===b||void 0===b?void 0:b[0].crop,f=m("combinations").filter(e=>{const t=e.combinationProducts.map(e=>{var t;return null===e||void 0===e||null===(t=e.selectedChemicalCrop)||void 0===t?void 0:t.crop});return"Plant Protection"===e.combinationType&&t.includes(y)}),E=f.map(e=>e.combinationProducts.map(e=>{var t;return null===e||void 0===e||null===(t=e.selectedChemicalCrop)||void 0===t?void 0:t.crop}));console.log(E,"cropTypes"),console.log("this is the data we want",f,y),f.map(e=>{});const S=((e,t)=>{const a=t[0].crop,n=[];return e.forEach(e=>{-1!==e.chemcrops.findIndex(e=>e.crop===a)&&n.push(e)}),n})(u.chemicals,b).concat(f);let C=[];if(n.product&&(console.log("record",n),C=((e,t,a)=>{if(!t)return[];const n=a("monitorings"),i=e.find(e=>e.sk===t);let r=[];var l;"combinations"===(null===i||void 0===i?void 0:i.type)?r=i.combinationProducts.flatMap(e=>{var t;return null===e||void 0===e||null===(t=e.selectedChemicalCrop)||void 0===t?void 0:t.targets}):r=null===i||void 0===i||null===(l=i.chemcrops[0])||void 0===l?void 0:l.targets;console.log("targets",r);return n.filter(e=>{var t;return null===(t=r||[])||void 0===t?void 0:t.some(t=>(null===t||void 0===t?void 0:t.target)===e.sk)})||[]})(S,n.product,m)),n.date=n.date?n.date:_(),n.time=n.time?n.time:Z(),n.endDate=n.endDate?n.endDate:_(),n.chemrigs&&n.numRigs){const e=u.chemequips.find(e=>e.sk===n.chemrigs);n.volume=(e.capacity*n.numRigs).toFixed(2)}const x=f.find(e=>e.sk===n.product)||null,k=!!x;if(k&&(n.combinations=n.combinations||[]),n.endDate){n.endTime=n.endTime?n.endTime:Z();const e=((null===n||void 0===n?void 0:n.reasons)||[]).length>0?null===n||void 0===n?void 0:n.reasons[0].phi:null;n.phiLapse=n.product&&n.endDate&&n.endTime&&((e,t,a,n,i,r,l,s)=>{if(!n||!i)return"";if(s)return J(n,i,l||0);const o=t.find(t=>t.sk===e);console.log("chem",o);const c=r&&r.find(e=>e.applied&&!0===e.applied);if(c&&(null===o||void 0===o?void 0:o.chemcrops)){const e=o.chemcrops.find(e=>e.crop===a[0].crop);if(e){const t=e.targets.find(e=>e.sk===c.sk);if(t){return J(n,i,l||t.phi)}}}return""})(n.product,S,b,n.date,n.endTime,n.reasons,e,k)}return i.a.createElement(g.a,{container:!0,className:a.root,spacing:1,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:n.date,onChange:h.bind(this),onBlur:p,error:!!r.date||void 0,helperText:r.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"time",id:"endTime",label:"End Time",name:"endTime",InputLabelProps:{shrink:!0},value:n.endTime,onChange:h.bind(this),onBlur:p,error:!!r.endTime||void 0,helperText:r.endTime})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Plant Protection"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:n.product,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.product||void 0,inputProps:{name:"product",id:"product"}},i.a.createElement("option",{value:""}),S&&S.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.product&&i.a.createElement(En.a,{className:a.helperText},r.product))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(bn.a,{shrink:!0,htmlFor:"reasons"},"Reasons"),i.a.createElement(Sr,{metaData:{monitorings:C},onBlur:p.bind(this),checkedItems:n.reasons,handleToggle:v,getFromGlobalState:m,handleExpand:l,expandedTarget:d,planting:b,pickApplied:!0,handleApplied:c,handleChange:o,handleReentryOverride:s,arrayName:"reasons"}),i.a.createElement(En.a,{className:a.helperText},r.reasons),r.reasons&&i.a.createElement(En.a,{className:a.helperText},r.reasons)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"weather"},"Weather"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:n.weather,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.weather||void 0,inputProps:{name:"weather",id:"weather"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Sunny"},"Sunny"),i.a.createElement("option",{value:"Cloudy"},"Cloudy"),i.a.createElement("option",{value:"Night"},"Night")))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!!n.phiLapse||void 0,htmlFor:"phiLapse"},"Withholding period end "),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"phiLapse",name:"phiLapse",value:n.phiLapse,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.phiLapse||void 0,helperText:r.phiLapse}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:h.bind(this),operators:u.operators,team:n.team,title:"Operator",value:n.operator,onBlur:p,error:r.operator})),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"notes",label:"Notes",name:"notes",multiline:!0,rowsMax:"4",value:n.notes,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.notes||void 0,helperText:r.notes}),k?null===x||void 0===x||null===(t=x.combinationProducts)||void 0===t?void 0:t.map((e,t)=>{var l,s,o,c;return i.a.createElement(g.a,{item:!0,style:{marginTop:20},container:!0,className:a.root,spacing:1,alignItems:"flex-end",key:t},"chemical"===e.type?i.a.createElement(g.a,{style:{border:"1px solid #eee",padding:5},container:!0},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===e||void 0===e||null===(l=e.selectedChemical)||void 0===l?void 0:l.name," (Chemical)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,onChange:a=>{var i;const r={...n};r.product=null===e||void 0===e||null===(i=e.selectedChemical)||void 0===i?void 0:i.sk,r.type="sprayings",r.chemrigs=a.target.value;const l=n.combinations||[];l.splice(t,1,r),n.combinations=l},onBlur:p.bind(this),error:!!r.chemrigs||void 0,inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),u.chemequips&&u.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.chemrigs&&i.a.createElement(En.a,{className:a.helperText},r.chemrigs))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",type:"number",inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",name:"numRigs",InputLabelProps:{shrink:!0},onChange:e=>{const a=n.combinations[t];a.numRigs=e.target.value;const i=u.chemequips.find(e=>e.sk===a.chemrigs);a.volume=parseFloat(null===i||void 0===i?void 0:i.capacity)*e.target.value;const r=n.combinations||[];r.splice(t,1,a),n.combinations=r},onBlur:p.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",type:"number",InputLabelProps:{shrink:!0},disabled:!0,id:"volume",label:"Total volume",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"liters"),min:"0.00001",step:"any"},value:null===(s=n.combinations[t])||void 0===s?void 0:s.volume,onBlur:p.bind(this),error:!!r.volume||void 0,helperText:r.volume}))):i.a.createElement(g.a,{container:!0,className:a.root,spacing:1,alignItems:"flex-end",style:{border:"1px solid #eee",padding:5}},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement("label",{style:{marginTop:20}},null===e||void 0===e||null===(o=e.selectedFertiliser)||void 0===o?void 0:o.name," (fertiliser)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,onChange:a=>{var i;const r=n.combinations[t]||{...n};delete r.combinations,r.product=null===e||void 0===e||null===(i=e.selectedFertiliser)||void 0===i?void 0:i.sk,r.type="fertilisings",r.unit=a.target.value,a.target.value&&("plant"===a.target.value?r.totalUnit="kg"===(null===e||void 0===e?void 0:e.selectedFertiliser.unit)?"g":"ml":r.totalUnit="kg"===(null===e||void 0===e?void 0:e.selectedFertiliser.unit)?"kg":"l");const l=n.combinations||[];l.splice(t,1,r),n.combinations=l},onBlur:p.bind(this),error:!!r.unit||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),r.unit&&i.a.createElement(En.a,{className:a.helperText},r.unit))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},id:"volume",label:"Applied quantity",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},onChange:e=>{const a=n.combinations[t]||{};a.volume=e.target.value,e.target.value&&("plant"===a.unit?a.total=parseFloat(e.target.value)*b[0].totalPlants:"ha"===a.unit?a.total=parseFloat(e.target.value)*b[0].size:a.total=parseFloat(e.target.value));const i=n.combinations||[];i.splice(t,1,a),n.combinations=i},onBlur:p.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"total",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},n.totalUnit?"l"===n.totalUnit?"liters":n.totalUnit:""),min:"0.00001",step:"any"},label:"Total",name:"total",value:null===(c=n.combinations[t])||void 0===c?void 0:c.total,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.total||void 0,helperText:r.total}))))}):i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:n.chemrigs,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.chemrigs||void 0,inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),u.chemequips&&u.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.chemrigs&&i.a.createElement(En.a,{className:a.helperText},r.chemrigs))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",disabled:!n.chemrigs,inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",name:"numRigs",InputLabelProps:{shrink:!0},value:n.numRigs,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.volume||void 0,helperText:r.volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},disabled:!0,id:"volume",label:"Total volume",name:"volume",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"liters"),min:"0.00001",step:"any"},value:n.volume,onChange:h.bind(this),onBlur:p.bind(this),error:!!r.volume||void 0,helperText:r.volume}))))})),xr=a(282),kr=a.n(xr);class wr extends n.Component{constructor(e){super(e),this.getCurrentLocation=()=>{const{onChange:e}=this.props,{locationLoaded:t,locationLoading:a}=this.state;this.setState({locationLoading:!0,locationLoaded:!1,error:null}),navigator.geolocation.getCurrentPosition(n=>{const i={lat:parseFloat(n.coords.latitude.toFixed(8)),lng:parseFloat(n.coords.longitude.toFixed(8)),accuracy:n.coords.accuracy,altitude:n.coords.altitude,altAcc:n.coords.altitudeAccuracy};this.setState({location:i,locationLoading:!1,locationLoaded:!0}),e(i,a,t)},e=>{this.setState({error:e.message,locationLoading:!1,locationLoaded:!1}),this.props.setSnack({open:!0,variant:"error",messageText:" Failed to find location "+e.message})},{enableHighAccuracy:!0,timeout:1e5,maximumAge:0})},this.state={locationLoading:!1,locationLoaded:!1,location:this.props.value,error:null}}render(){const{name:e,required:t,classes:a,id:n}=this.props,{location:r,error:l,locationLoading:s}=this.state;return i.a.createElement(vn.a,{fullWidth:!0,className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"geoLocation"},"Geolocation"),i.a.createElement(zt.a,{margin:"normal",required:t,style:{minWidth:"260px"},id:n,name:e,value:r?`lat:${r.lat} lng:${r.lng}`:"",onBlur:this.handleBlur,error:!!l||void 0,helperText:l}),l&&i.a.createElement(En.a,{className:a.helperText},l),i.a.createElement(la,{onClick:this.getCurrentLocation,success:!l,icon:i.a.createElement(kr.a,null),loading:s}))}}var Tr=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2),flexDirection:"row"},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1}}))(wr);var Dr=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,handleBlur:r,handleChange:l,metaData:s,overrideTotalHarvest:o,handleLocationChange:c,setSnack:d}=e,m=s.harvestEquips;return a.totalHarvestOverride||(a.totalHarvestOverride=!1,a.harvestEquip&&a.harvestUnits&&(a.harvestTotal=((e,t,a)=>{if(!e)return 0;if(!t)return 0;if(!a)return 0;let n=e.find(e=>e.sk===t);return n?a*n.capacity:void 0})(m,a.harvestEquip,a.harvestUnits))),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"date",id:"date",label:"Harvest Date",name:"date",InputLabelProps:{shrink:!0},value:a.date,onChange:l.bind(this),onBlur:r,error:!!n.date||void 0,helperText:n.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"harvestEquip"},"Harvest Unit"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a.harvestEquip,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.harvestEquip||void 0,inputProps:{name:"harvestEquip",id:"harvestEquip"}},i.a.createElement("option",{value:""}),m&&m.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),n.harvestEquip&&i.a.createElement(En.a,{className:t.helperText},n.harvestEquip))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,style:{minWidth:"200px"},type:"number",inputProps:{min:"0.00001",step:"any"},id:"harvestUnits",label:"Total Units",name:"harvestUnits",value:a.harvestUnits,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.harvestUnits||void 0,helperText:n.harvestUnits})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"harvestTotal"},"Total harvest in Kg"),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"harvestTotal",label:"",name:"harvestTotal",value:a.harvestTotal,onChange:l.bind(this),disabled:!a.totalHarvestOverride,onBlur:r.bind(this),error:!!n.harvestTotal||void 0,helperText:n.harvestTotal}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(Fe.a,{value:"harvestOverride",control:i.a.createElement(Cn.a,{color:"secondary",name:"totalHarvestOverride",checked:a.totalHarvestOverride,id:"totalHarvestOverride",onClick:o}),label:"Override"}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Tr,{onChange:c.bind(this),value:a.geoLocation,onBlur:r.bind(this),id:"geoLocation",required:!0,name:"geoLocation",setSnack:d})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:l.bind(this),operators:s.operators,title:"Operator",value:a.operator,team:a.team,onBlur:r,error:n.operator})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"text",id:"deliveryNote",label:"Delivery Note",name:"deliveryNote",value:a.deliveryNote,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.deliveryNote||void 0,helperText:n.deliveryNote})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:8,lg:8,xl:8}))}));const Pr=(e,t,a)=>{if(!e)return 0;if(!t)return 0;if(!a)return 0;let n=e.find(e=>e.sk===t);return n?a*n.capacity:void 0};var Fr=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,handleBlur:r,handleChange:l,metaData:s}=e,o=s;return a.packTotal=Pr(o,a.packEquip,a.packUnits),a.wasteTotal=Pr(o,a.wasteEquip,a.wasteUnits),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Packing Date",name:"date",InputLabelProps:{shrink:!0},value:a.date,onChange:l.bind(this),onBlur:r,error:!!n.date||void 0,helperText:n.date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"packEquip"},"Packing Unit"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a.packEquip,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.packEquip||void 0,inputProps:{name:"packEquip",id:"packEquip"}},i.a.createElement("option",{value:""}),o&&o.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),n.packingEquip&&i.a.createElement(En.a,{className:t.helperText},n.packingEquip))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"packUnits",label:"Total Pack Units",name:"packUnits",value:a.packUnits,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.packUnits||void 0,helperText:n.packUnits})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"packTotal",label:"Total packed in Kg",name:"packTotal",value:a.packTotal,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.packTotal||void 0,helperText:n.packTotal})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"wasteEquip"},"Waste Unit"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a.wasteEquip,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.wasteEquip||void 0,inputProps:{name:"wasteEquip",id:"wasteEquip"}},i.a.createElement("option",{value:""}),o&&o.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),n.wasteEquip&&i.a.createElement(En.a,{className:t.helperText},n.wasteEquip))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"wasteUnits",label:"Total Units",name:"wasteUnits",value:a.wasteUnits,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.wasteUnits||void 0,helperText:n.wasteUnits})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"wasteTotal",label:"Total waste in Kg",name:"wasteTotal",value:a.wasteTotal,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.wasteTotal||void 0,helperText:n.wasteTotal})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"destination"},"Destination"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a.destination,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.destination||void 0,inputProps:{name:"destination",id:"destination"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Local"},"Local"),i.a.createElement("option",{value:"Europe"},"Europe")),n.destination&&i.a.createElement(En.a,{className:t.helperText},n.application))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"consignment",label:"Consignment number",name:"consignment",value:a.consignment,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.consignment||void 0,helperText:n.consignment})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"text",id:"deliveryNote",label:"Delivery Note",name:"deliveryNote",value:a.deliveryNote,onChange:l.bind(this),onBlur:r.bind(this),error:!!n.deliveryNote||void 0,helperText:n.deliveryNote})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:8,lg:8,xl:8}))}));class Nr extends n.Component{constructor(e){super(e),this.setSelectedTab=e=>{this.setState({selectedTab:e})},this.handleBlur=e=>this.validateField(e.target.id,this.props.requiredFields),this.overrideCalculatedVolume=e=>{const t={...this.state.record};t.calculatedVolumeOverride=!t.calculatedVolumeOverride,this.setState({record:t,changed:!0})},this.overrideCalculatedProduct=e=>{const t={...this.state.record};t.calculatedProductOverride=!t.calculatedProductOverride,this.setState({record:t,changed:!0})},this.filterItems=(e,t)=>{const a=t[0].crop,n=[];return e.forEach(e=>{-1!==e.chemcrops.findIndex(e=>e.crop===a)&&n.push(e)}),n},this.handleChange=e=>{const t={...this.state.record};t[e.target.id]=e.target.value,t.createTime=Date.now(),this.setState({record:t,changed:!0})},this.handleSwitchChange2=e=>{const t={...this.state.record};t[e.target.id]=e.target.checked;let a=null;if(e.target.checked){var n,i;const e=ne(null===(n=this.props)||void 0===n||null===(i=n.block)||void 0===i?void 0:i.paths);a={latitude:e.lat,longitude:e.lng,accuracy:0}}this.setState({record:t,changed:!0,currentLocation:a})},this.handleLocationChange=e=>{const t={...this.state.record};t.geoLocation=e,this.setState({record:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.record};a[e]=t.target.value,this.setState({record:a,changed:!0})},this.handleCheckboxChange=e=>{const t={...this.state.record};t[e.target.id]=e.target.checked,this.setState({record:t,changed:!0})},this.handleExpand=e=>{const{expandedTarget:t}=this.state;t!==e?this.setState({expandedTarget:e}):this.setState({expandedTarget:""})},this.overrideHarvestTotal=e=>{const t={...this.state.record},a={...this.state.errors};t[e.target.id]=!t[e.target.id],t[e.target.id]&&(a.harvestEquip=void 0,a.harvestUnits=void 0),this.setState({errors:a,record:t,changed:!0})},this.handleSettingExpand=e=>{this.state.expandedSetting!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.overrideTotal=e=>{const t={...this.state.record},a={...this.state.errors};t[e.target.id]=!t[e.target.id],this.setState({errors:a,record:t,changed:!0})},this.handleSwitchChange=e=>t=>{const a={...this.state.record};a[e]=t.target.checked,this.setState({record:a,changed:!0})},this.handleComplexChange=(e,t,a)=>{const n={...this.state.record};n[a.target.id]=a.target.value,n[t]=a.target.value*this.props.inputData[e],this.setState({record:n,changed:!0})},this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.onForwardSubset=(e,t)=>{const{monitoringSet:a}=this.state,n={...a};n[t]||(n[t]={subSet:0}),n[t].subSet+=1,this.setState({monitoringSet:n})},this.onBackSubset=(e,t)=>{const{monitoringSet:a}=this.state,n={...a};n[t]||(n[t]={subSet:0}),n[t].subSet>0&&(n[t].subSet-=1,this.setState({monitoringSet:n}))},this.onForwardSet=async e=>{const{monitoringSet:t}=this.state;let a={...t},{set:n}=a;n||(n=0),a={set:n},e||(a.set+=1),this.setState({monitoringSet:a})},this.onBackSet=(e,t)=>{const{monitoringSet:a}=this.state;let n={...a},{set:i}=n;i||(i=0),n={set:i},n.set>0&&(n.set-=1,this.setState({monitoringSet:n}))},this.getTargetUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.fileUploadedLocal=async e=>{const{getFromGlobalState:t,setGlobalState:a}=this.props,n={...t("imageUrls")};if(!n[e.serverId]){const t=await this.getTargetUrl(e.serverId,e.fileType);n[e.serverId]=t,a({imageUrls:n})}},this.onFileUploadStart=()=>{this.setState({uploading:!0})},this.fileUploaded=async(e,t,a,n,i)=>{if(!e.serverId)return;const{record:r}=this.state,l={...r};let s;if(l.observations||(l.observations=[]),s=l.observations.findIndex(e=>e.stageSK&&e.stageSK===a),-1===s){const e={stageSK:a,monitoringSK:t.monitoring.sk,targetDetailSK:t.monitoring.targetDetail.sk,pictures:[],entries:[]};"Yes"===t.monitoring.cropSpecific?e.observableOnSK=t.monitoring.targetDetail.observableOn[0].sk:e.nonCropSecofocSK=t.monitoring.targetDetail.sk,s=l.observations.push(e),s-=1}const o=l.observations[s];if(o.pictures||(o.pictures=[]),o.pictures.length<=n){const e=o.pictures.length;for(let t=0;t{const{setSnack:t}=this.props;t({open:!0,variant:"error",messageText:" Failed to find location "+e.message})},this.locationFound=e=>{const{isMobile:t,block:a,getFromGlobalState:n}=this.props,i=e.coords;if(i.accuracy<200)if(function(e,t,a){if(!t||!a||!e)return!1;const n=Fn(e),i=[t,a],r=Dn()(n,i);return-1===r||0===r}(a.paths,i.latitude,i.longitude))this.setState({currentLocation:i,isInBlock:!0});else{const e=Nn(n("blocks"),i.latitude,i.longitude);this.setState({currentLocation:i,isInBlock:!1,foundBlock:e})}},this.onTakePhoto=(e,t,a,n,i)=>{e.preventDefault();const{record:r}=this.state;if("Yes"===t.cropSpecific)this.setState({displayMonitoringPicture:!0,monitoringPicture:{monitoring:t,stageSK:a,set:n,subSet:i}});else{this.setState({displayMonitoringPicture:!0,monitoringPicture:{monitoring:t,stageSK:null,set:n,subSet:i}})}},this.onCloseTargetDetail=()=>{this.setState({displayTargetDetail:!1,selectedTargetDetail:null})},this.onCloseMonitoringPicture=()=>{this.setState({monitoringPicture:null,displayMonitoringPicture:!1})},this.onShowTargetDetail=(e,t,a,n,i,r)=>{if(e.preventDefault(),"Yes"===t.cropSpecific)this.setState({displayTargetDetail:!0,selectedTargetDetail:t.targetDetail.observableOn[0].stages.find(e=>e.sk===a)});else{this.setState({displayTargetDetail:!0,selectedTargetDetail:t.targetDetail.nonCropDetail})}},this.onChangeCounter=(e,t,a,n,i,r)=>{if("Present"===r)return null;const{record:l}=this.state,s={...l};let o;if(s.observations||(s.observations=[]),o=s.observations.findIndex(e=>e.stageSK&&e.stageSK===a),-1===o){const e={stageSK:a,monitoringSK:t.sk,targetDetailSK:t.targetDetail.sk,entries:[],pictures:[]};"Yes"===t.cropSpecific?e.observableOnSK=t.targetDetail.observableOn[0].sk:e.nonCropSecofocSK="blee",o=s.observations.push(e),o-=1}const c=s.observations[o];if(c.entries.length<=n){const e=c.entries.length;for(let t=0;t{const{currentLocation:a}=this.state;if(t.geoLocations||(t.geoLocations=[]),t.geoLocations.length<=e){const a=t.geoLocations.length;for(let n=0;n{const{record:l}=this.state,s={...l};let o;s.observations||(s.observations=[]);let c={};"Yes"===t.cropSpecific?(o=s.observations.findIndex(e=>e.stageSK&&e.stageSK===a),-1===o&&(c={cropSpecific:!0,stageSK:a,monitoringSK:t.sk,targetDetailSK:t.targetDetail.sk,entries:[],pictures:[]},c.observableOnSK=t.targetDetail.observableOn[0].sk,o=s.observations.length,s.observations.push(c))):(o=s.observations.findIndex(e=>e.targetDetailSK&&e.targetDetailSK===t.targetDetail.sk),-1===o&&(c={cropSpecific:!1,monitoringSK:t.sk,targetDetailSK:t.targetDetail.sk,entries:[],pictures:[]},o=s.observations.length,s.observations.push(c)));const d=s.observations[o];if(d.entries.length<=n){const e=d.entries.length;for(let t=0;te&&(d.entries[n][i]=e),isNaN(d.entries[n][i])){}}else d.entries[n][i]=1;this.captureLocation(n,s),this.setState({record:s,changed:!0})},this.onSubtract=(e,t,a,n,i,r)=>{const{record:l}=this.state,s={...l};let o;s.observations||(s.observations=[]);let c={};"Yes"===t.cropSpecific?(o=s.observations.findIndex(e=>e.stageSK&&e.stageSK===a),-1===o&&(c={cropSpecific:!0,stageSK:a,monitoringSK:t.sk,targetDetailSK:t.targetDetail.sk,entries:[],pictures:[]},c.observableOnSK=t.targetDetail.observableOn[0].sk,o=s.observations.push(c),o-=1)):(o=s.observations.findIndex(e=>e.targetDetailSK&&e.targetDetailSK===t.targetDetail.sk),-1===o&&(c={cropSpecific:!1,monitoringSK:t.sk,targetDetailSK:t.targetDetail.sk,entries:[],pictures:[]},o=s.observations.push(c),o-=1));const d=s.observations[o];if(d.entries.length<=n){const e=d.entries.length;for(let t=0;t{const{record:a}=this.state,n={...a};n[t]||(n[t]=[]);const i=n[t].indexOf(e);-1===i?n[t].push(e):n[t].splice(i,1),this.setState({record:n,changed:!0})},this.handleTargetChange=(e,t)=>{const{record:a}=this.state,n={...a};n.reasons||(n.reasons=[]);const i=n.reasons.findIndex(e=>e.target===t);-1!==i&&(n.reasons[i][e.target.id]=e.target.value,this.setState({record:n,changed:!0}))},this.handleReentryOverride=(e,t)=>{const{record:a}=this.state,n={...a};n.reasons||(n.reasons=[]);const i=n.reasons.findIndex(e=>e.target===t);-1!==i&&(Object.hasOwn(n.reasons[i],"reentryOverride")?n.reasons[i].reentryOverride=!n.reasons[i].reentryOverride:n.reasons[i].reentryOverride=e.target.checked,this.setState({record:n,changed:!0}))},this.handleApplied=(e,t,a)=>{const{record:n}=this.state,i={...n};i[a]||(i[a]=[]);const r=i[a].findIndex(e=>e.target===t);if(-1!==r){for(let e=0;e{const{record:n}=this.state,{getFromGlobalState:i}=this.props,r={...n};r[t]||(r[t]=[]);const l=r[t].findIndex(t=>t.target===e);for(let s=0;s"Plant Protection"===e.combinationType),s=i("chemicals").concat(l).find(e=>e.sk===n.product),o="combinations"===s.type?s.combinationProducts.map(e=>e.selectedChemicalCrop).find(e=>{var t;return(null===e||void 0===e?void 0:e.crop)===(null===(t=a[0])||void 0===t?void 0:t.crop)}):s.chemcrops.find(e=>{var t;return(null===e||void 0===e?void 0:e.crop)===(null===(t=a[0])||void 0===t?void 0:t.crop)}),c=((null===o||void 0===o?void 0:o.targets)||[]).find(t=>t.target===e);(null===c||void 0===c?void 0:c.applied)&&(c.applied=!0),r[t].push({...c})}else r[t].splice(l,1);this.setState({record:r,changed:!0})},this.handleChange=this.handleChange.bind(this),this.handleSwitchChange2=this.handleSwitchChange2.bind(this),this.handleCheckboxChange=this.handleCheckboxChange.bind(this),this.handleSettingExpand=this.handleSettingExpand.bind(this),this.handleBlur=this.handleBlur.bind(this),this.handleTabChange=this.handleTabChange.bind(this),this.handleRadioChange=this.handleRadioChange.bind(this),this.onAdd=this.onAdd.bind(this),this.onSubtract=this.onSubtract.bind(this),this.onForwardSubset=this.onForwardSubset.bind(this),this.onBackSubset=this.onBackSubset.bind(this),this.onForwardSet=this.onForwardSet.bind(this),this.onBackSet=this.onBackSet.bind(this),this.handleLocationChange=this.handleLocationChange.bind(this),this.onChangeCounter=this.onChangeCounter.bind(this),this.handleLocationChange=this.handleLocationChange.bind(this),this.overrideHarvestTotal=this.overrideHarvestTotal.bind(this),this.handleTargetChange=this.handleTargetChange.bind(this),this.state={record:{},errors:{count:0},changed:!1,selectedTab:0,expandedSetting:"",monitoringSet:{set:0,subSet:0},watchId:"",currentLocation:null,isInBlock:!1,displayTargetDetail:!1,selectedTargetDetail:null,monitoringPicture:null,displayMonitoringPicture:!1,uploading:!1,foundBlock:null,expandedTarget:""}}componentDidMount(){const{isNew:e,recordType:t,record:a}=this.props;if(e){const e=new Date,a=`${e.getHours()}:${e.getMinutes()}`;if("pestings"===t){const e={enableHighAccuracy:!0,timeout:1e5,maximumAge:0},t=navigator.geolocation.watchPosition(this.locationFound,this.locationError,e);this.setState({watchId:t})}"sprayings"===t&&this.setState({record:{completed:!1,calculatedProductOverride:!1,calculatedVolumeOverride:!1,chemrigs:[],reasons:[]}}),"fertilisings"===t?this.setState({record:{totalOverride:!1,date:e.toISOString().substr(0,10),time:a}}):this.setState({record:{date:e.toISOString().substr(0,10),time:a}})}else this.setState({record:a,changed:!1});if("pestings"===t){const e={enableHighAccuracy:!0,timeout:1e5,maximumAge:0},t=navigator.geolocation.watchPosition(this.locationFound,this.locationError,e);this.setState({watchId:t})}}componentWillUnmount(){const{watchId:e}=this.state;navigator.geolocation.clearWatch(e)}setStateAsync(e){return new Promise(t=>{this.setState(e,t)})}updateParent(e,t){const{record:a}=this.state,n={...a};n[e]=t,this.setState({record:n})}validateField(e,t){const{record:a,errors:n}=this.state,i=jn(e,a,t),r={...n};r[e]=i.msg,this.setState({errors:r})}render(){var e;const{open:t,isNew:a,setClose:n,handleUpdateRecord:r,allowDelete:l,handleDeleteRecord:s,requiredFields:o,recordType:c,title:d,newTitle:m,plantingSK:p,blockSK:h,block:g,getFromGlobalState:u,planting:b,setSnack:v,isMobile:y,setGlobalState:f}=this.props,{record:E,errors:S,selectedTab:C,expandedSetting:x,monitoringSet:k,currentLocation:w,changed:T,displayTargetDetail:D,selectedTargetDetail:P,monitoringPicture:F,displayMonitoringPicture:N,uploading:B,isInBlock:L,foundBlock:A,expandedTarget:O}=this.state,I="pestings"===c||!a||$n(E,o),G=u("crops");return i.a.createElement(Ia,{open:t,dialogObject:E,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_record_",dynamoType:c,deleteLabel:"Are you sure you want to proceed? This action will permanently delete all records and information from this session.",valid:I,changed:T,newTitle:m,setSnack:this.props.setSnack,getFromGlobalState:u,title:d,lastUpdatedBy:{createdByEmail:(null===E||void 0===E?void 0:E.createdByEmail)?null===E||void 0===E?void 0:E.createdByEmail:"",createdAt:null===E||void 0===E?void 0:E.createdAt},subTitle:`Block ${g.number} ${ae(b.crop,G,"name")} ${b.variety?ae(b.variety,null===(e=G.find(e=>e.sk===b.crop))||void 0===e?void 0:e.varieties,"name"):""} v.${(null===E||void 0===E?void 0:E.version)?E.version:"0"} `,parentKey:p,plantingKey:p,allowDelete:l&&s,handleDeleteDialogObject:s?s.bind(this):void 0},"waterings"===c&&i.a.createElement(oi,{record:E,errors:S,handleChange:this.handleChange,handleBlur:this.handleBlur,metaData:{operators:u("operators").filter(e=>-1!==e.roles.indexOf("waterings"))},updateParent:this.updateParent.bind(this),block:g,setSnack:v,planting:g.plantings.filter(e=>e.sk===p),handleSwitchChange:this.handleSwitchChange}),"fertilisings"===c&&i.a.createElement(ci,{record:E,errors:S,handleChange:this.handleChange,handleBlur:this.handleBlur,metaData:{fertilisers:u("fertilisers"),operators:u("operators").filter(e=>-1!==e.roles.indexOf("fertilisings")),inventory:u("inv_fertiliser")},planting:u("blocks").find(e=>e.sk===h).plantings.filter(e=>e.sk===p),block:g,handleSwitchChange:this.handleSwitchChange,getFromGlobalState:u,overrideTotal:this.overrideTotal}),"pestings"===c&&i.a.createElement(gr,{record:E,errors:S,isNew:a,onAdd:this.onAdd,onSubtract:this.onSubtract,onForwardSubset:this.onForwardSubset,onBackSubset:this.onBackSubset,onForwardSet:this.onForwardSet,onBackSet:this.onBackSet,selectedTab:C,setSelectedTab:this.setSelectedTab,handleLocationChange:this.handleLocationChange,handleSettingExpand:this.handleSettingExpand,expandedSetting:x,handleCheckboxChange:this.handleCheckboxChange,handleTabChange:this.handleTabChange,handleChange:this.handleChange,handleRadioChange:this.handleRadioChange,handleBlur:this.handleBlur,handleSwitchChange:this.handleSwitchChange2,currentLocation:w,setInfo:k,setSnack:v,isMobile:y,getFromGlobalState:u,metaData:{targetTypes:u("targetsTypesSetting"),monitorings:u("monitorings"),operators:u("operators").filter(e=>-1!==e.roles.indexOf("pestings"))},planting:u("blocks").find(e=>e.sk===h).plantings.filter(e=>e.sk===p),onChangeCounter:this.onChangeCounter,onShowTargetDetail:this.onShowTargetDetail,onTakePhoto:this.onTakePhoto,selectedTargetDetail:P,displayTargetDetail:D,onCloseTargetDetail:this.onCloseTargetDetail,setGlobalState:f,onCloseMonitoringPicture:this.onCloseMonitoringPicture,monitoringPicture:F,displayMonitoringPictures:N,fileUploaded:this.fileUploaded,onFileUploadStart:this.onFileUploadStart,uploading:B,isInBlock:L,block:g,foundBlock:A}),"activities"===c&&i.a.createElement(ur,{record:E,errors:S,setSnack:v,handleChange:this.handleChange,handleBlur:this.handleBlur,metaData:{agronomistActs:u("agronomistActs"),operators:u("operators").filter(e=>-1!==e.roles.indexOf("activities"))},planting:u("blocks").find(e=>e.sk===h).plantings.filter(e=>e.sk===p)}),"sprayings"===c&&i.a.createElement(Cr,{record:E,errors:S,isNew:a,handleChange:this.handleChange,handleBlur:this.handleBlur,metaData:{chemicals:u("chemicals"),chemequips:u("chemequips"),pests:u("monitorings"),operators:u("operators").filter(e=>-1!==e.roles.indexOf("sprayings")),inventory:u("inv_chemical")},planting:u("blocks").find(e=>e.sk===h).plantings.filter(e=>e.sk===p),block:g,setSnack:v,handleToggle:this.handleToggleReasons,handleSwitchChange:this.handleSwitchChange,overrideCalculatedVolume:this.overrideCalculatedVolume,overrideCalculatedProduct:this.overrideCalculatedProduct,getFromGlobalState:u,handleExpand:this.handleExpand,expandedTarget:O,handleApplied:this.handleApplied,handleTargetChange:this.handleTargetChange,handleReentryOverride:this.handleReentryOverride}),"harvestings"===c&&i.a.createElement(Dr,{record:E,errors:S,handleLocationChange:this.handleLocationChange,handleChange:this.handleChange,handleBlur:this.handleBlur,setSnack:v,metaData:{operators:u("operators").filter(e=>-1!==e.roles.indexOf("harvestings")),harvestEquips:u("harvestequips")},overrideTotalHarvest:this.overrideHarvestTotal}),"packings"===c&&i.a.createElement(Fr,{record:E,errors:S,handleChange:this.handleChange,handleBlur:this.handleBlur,metaData:u("packequips")}))}}Nr.defaultProps={allowDelete:!1};var Br=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Nr),Lr=a(833),Ar=a.n(Lr);class Or extends n.Component{constructor(e){super(e),this.handleSelect=(e,t,a,n,i)=>{},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0}}}componentDidMount(){}render(){const{open:e,isNew:t,setClose:a,recordType:n,title:r,farm:l,planting:s,getFromGlobalState:o,block:c}=this.props;return i.a.createElement(Ia,{open:e,dialogObject:void 0,setClose:a,isNew:t,disableActions:!0,handleUpdateDialogObject:void 0,skPrimary:void 0,dynamoType:void 0,valid:void 0,title:r,maxWidth:"lg",parentKey:void 0,plantingKey:void 0,getFromGlobalState:o},i.a.createElement(vt,{recordType:n,planting:s,block:c,farm:l,handleSelect:this.handleSelect.bind(this),getFromGlobalState:o,showAll:!0}))}}var Ir=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Or),Gr=a(436),Rr=a.n(Gr);const Ur=Object(z.a)(e=>({root:{flexGrow:1},menuButton:{},title:{flexGrow:1,display:"none",[e.breakpoints.up("sm")]:{display:"block"}},search:{position:"relative",borderRadius:e.shape.borderRadius,backgroundColor:Object(ue.e)(e.palette.common.white,.15),"&:hover":{backgroundColor:Object(ue.e)(e.palette.common.white,.25)},marginLeft:0,[e.breakpoints.up("sm")]:{marginLeft:e.spacing(1),width:"auto"}},searchIcon:{width:e.spacing(7),height:"100%",position:"absolute",pointerEvents:"none",display:"flex",alignItems:"center",justifyContent:"center"},select:{"&:before":{},"&:after":{}},icon:{},input:{},inputRoot:{},inputInput:{padding:e.spacing(1,1,1,7),transition:e.transitions.create("width"),width:"100%",[e.breakpoints.up("sm")]:{width:120,"&:focus":{width:200}}}}));function Mr(e){const{onRefresh:t,onSwitchFarm:a,isMobile:n,onBlockReportPDF:r,pdfRequested:l,reportPDF:s,reportCSV:o,onBlockReportCSV:c,csvRequested:d,siteList:m,activeSite:p,getFromGlobalState:h}=e,g=Ur(),u=h("userDetail");return i.a.createElement("div",{className:g.root},i.a.createElement("div",{position:"static"},i.a.createElement(G.a,{style:{backgroundColor:"white",borderRadius:"4px"}},i.a.createElement("div",{className:g.search},i.a.createElement(ca,{role:u&&u.rights&&u.rights.viewDashboard?"viewDashboard":"noAccess",perform:"viewReports",isAdministrator:u&&u.rights&&u.rights.administrator,yes:()=>i.a.createElement("div",{style:{display:"flex",float:"left"}},!d&&i.a.createElement(I.a,{title:"Generate CSV report"},i.a.createElement(E.a,{edge:"start",className:g.menuButton,color:"primary",onClick:c,"aria-label":"close"},i.a.createElement(Nt.a,null))),d&&o,!l&&i.a.createElement(I.a,{title:"Generate PDF report"},i.a.createElement(E.a,{edge:"start",className:g.menuButton,color:"primary",onClick:r,"aria-label":"close"},i.a.createElement(Pt.a,null))),l&&s)})),n&&i.a.createElement(Sn.a,{native:!0,className:g.select,required:!0,value:p,onChange:a,inputProps:{name:"activeSite",id:"activeSite",classes:{icon:g.icon,root:g.input}}},m&&m.map(e=>i.a.createElement("option",{key:e.sk,value:e.tenantId},"Main site"===e.shortName?e.shortName2:e.shortName," ","-",e.entityType?e.entityType.charAt(0).toUpperCase():"F"))),t&&i.a.createElement("div",{style:{marginLeft:"auto",float:"right"}},i.a.createElement(E.a,{edge:"start",className:g.menuButton,"aria-label":"refreshr",color:"secondary",onClick:t},i.a.createElement(Rr.a,null))))))}const Wr=Ua.f.create({body:{paddingTop:35,paddingBottom:55,paddingHorizontal:35},sectionRight:{marginBottom:10,paddingBottom:10,textAlign:"right",width:"60%"},sectionLeft:{marginBottom:10,paddingBottom:10,width:"40%"},section:{display:"flex",flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"},sectionNoPadLeft:{margin:10,padding:10,marginLeft:0,paddingLeft:0},textHeader:{fontSize:24,paddingBottom:10},textSubHeader:{fontSize:14},textOpac:{fontSize:10,opacity:.6},text:{fontSize:10},table:{display:"table",width:"auto",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderRightWidth:0,borderBottomWidth:0},tableRow:{margin:"auto",flexDirection:"row"},tableCol1Header:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableColHeader:{borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol1:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol:{borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCellHeader:{margin:3,fontSize:10,fontWeight:500},tableCell:{margin:3,fontSize:8},tableCellStrong:{margin:3,fontSize:8,fontWeight:"bold"},pageNumber:{position:"absolute",fontSize:12,bottom:30,left:0,right:0,textAlign:"right",color:"grey",paddingRight:20,marginRight:20},logoText:{position:"absolute",fontSize:10,bottom:30,left:20,textAlign:"left",textDecoration:"none"},logo:{width:30,height:30,paddingLeft:2},farmLogo:{maxWidth:"150px"}}),zr=e=>i.a.createElement(Ua.h,{style:Wr.table},i.a.createElement(Ua.h,{fixed:!0,style:Wr.tableRow},e.headCells&&e.headCells.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Wr.tableColHeader,{width:100/e.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:Wr.tableCellHeader},t.label))))),e.rows&&e.rows.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:Wr.tableRow},e.headCells&&e.headCells.map(a=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Wr.tableCol,{width:100/e.headCells.length+"%"}]},i.a.createElement(Ua.g,{style:Wr.tableCell},"number"===typeof t[a.id]?t[a.id].toFixed(2):t[a.id])))))))),Kr=e=>i.a.createElement(Ua.h,{wrap:!1,style:Wr.section},e.logoURL&&i.a.createElement(Ua.h,{style:Wr.sectionLeft},i.a.createElement(Ua.b,{cache:!0,style:Wr.farmLogo,src:e.logoURL})),!e.logoURL&&i.a.createElement(Ua.h,{style:Wr.sectionLeft}),i.a.createElement(Ua.h,{style:Wr.sectionRight},i.a.createElement(Ua.g,{style:Wr.textHeader},e.farm.name),e.farm.gapnum&&i.a.createElement(Ua.g,{style:Wr.textOpac},"GLOBAL.G.A.P: "+e.farm.gapnum),e.farm.puc&&i.a.createElement(Ua.g,{style:Wr.textOpac},"Production Unit Code (PUC): "+e.farm.puc),e.farm.vatNo&&i.a.createElement(Ua.g,{style:Wr.textOpac},"VAT Number: "+e.farm.vatNo),i.a.createElement(Ua.g,{style:Wr.textOpac},"Tel: "+e.farm.contactNum),i.a.createElement(Ua.g,{style:Wr.textOpac},"email: "+e.farm.email),e.farm.geoLocation&&i.a.createElement(Ua.g,{style:Wr.textOpac},"Geolocation: "+(e.farm.geoLocation.lat&&e.farm.geoLocation.lng?`Lat: ${e.farm.geoLocation.lat.toFixed(7)} Lng: ${e.farm.geoLocation.lng.toFixed(7)}`:e.farm.geoLocation)),i.a.createElement(Ua.g,{style:Wr.textOpac},"Address: "+e.farm.address1),i.a.createElement(Ua.g,{style:Wr.textOpac},""+e.farm.address2),i.a.createElement(Ua.g,{style:Wr.textOpac},""+e.farm.country),i.a.createElement(Ua.g,{style:Wr.textOpac},""+e.farm.province),i.a.createElement(Ua.g,{style:Wr.textOpac},""+e.farm.pCode))),Hr=e=>i.a.createElement(Ua.a,null,i.a.createElement(Ua.e,{size:"A4",style:Wr.body,orientation:"landscape"},i.a.createElement(Kr,e),i.a.createElement(Ua.h,{style:[Wr.sectionNoPadLeft,{paddingBottom:0,paddingTop:0,marginTop:0,marginBottom:10}]},i.a.createElement(Ua.g,{style:Wr.textSubHeader},"Block Census Report"),i.a.createElement(Ua.g,{style:Wr.textOpac},"Report Date: "+_())),i.a.createElement(zr,e),i.a.createElement(Ua.g,{style:Wr.pageNumber,render:({pageNumber:e,totalPages:t})=>`Page: ${e} / ${t}`,fixed:!0}),i.a.createElement(Ua.h,{wrap:!1,style:Wr.logoText},i.a.createElement(Ua.c,{style:{textDecoration:"none"},wrap:!1,src:"landdiary.com"},i.a.createElement(Ua.g,{wrap:!1,style:{borderRadius:3,paddingLeft:"3px",paddingBottom:"2px"}},i.a.createElement(Ua.b,{style:Wr.logo,src:Ka.a})," ")))));class qr extends n.Component{constructor(e){super(e),this.getLogoUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0}}}async componentDidMount(){if(this.props.farm&&this.props.farm.logoKey){const e=await this.getLogoUrl(this.props.farm.logoKey,this.props.farm.logoFileType);this.setState({logoURL:e})}}render(){const{farm:e,rows:t,headCells:a,onDownloaded:n}=this.props,{logoURL:r}=this.state;return e.logoKey&&!r?i.a.createElement("div",{style:{color:"inherit",float:"right",marginLeft:"auto"}},i.a.createElement(la,{key:"pdf",onClick:n,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:!0,disabled:!0})):i.a.createElement(Ua.d,{document:i.a.createElement(Hr,{reportName:"Block Census",rows:t,farm:e,headCells:a,logoURL:r}),fileName:`${e.name} Block Census Report ${_()}`,style:{color:"inherit",float:"right",marginLeft:"auto"}},({blob:e,url:t,loading:a,error:r})=>i.a.createElement(la,{key:"pdf",onClick:n,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:a,disabled:a}))}}var Vr=Object(v.a)(Wr)(qr);class jr extends n.Component{constructor(e){super(e),this.state={csvData:[],loading:!1,title:""}}componentDidMount(){const{recordType:e,getFromGlobalState:t,planting:a,startDate:n,endDate:i,block:r,rows:l,headCells:s,title:o}=this.props;this.setState({loading:!0});const c={rows:l,headCells:s,title:o};c.headCells&&(c.headCells=c.headCells.filter(e=>"icon"!==e.type));const d=[];d.push(c.headCells.map(e=>e.label));for(let m=0;m{let t=this.state.selectedBlock;t&&e.sk===t.sk?this.setState({selectedBlock:null}):this.setState({selectedBlock:e})},this.handlePlantingExpand=e=>{this.state.expanded!==e?this.setState({expanded:e}):this.setState({expanded:""})},this.handleClickAddNewPlanting=(e,t)=>{this.setState({openDialog:"planting",selectedBlock:t,isNew:!0,selectedBlockSK:e})},this.handleClickShowPlanting=(e,t,a,n)=>{n.stopPropagation();let i=a.plantings.find(e=>e.sk===t);this.setState({selectedPlanting:i,selectedBlockSK:a.sk,selectedBlock:a}),this.setState({openDialog:"planting",isNew:!1})},this.handleClickShowRecord=(e,t,a,n)=>{let i=this.props.getFromGlobalState("blocks").find(t=>t.sk===e),r=i.plantings.find(e=>e.sk===t),l=r[a].find(e=>e.sk===n);this.setState({selectedBlock:i,selectedPlanting:r,selectedBlockSK:i.sk,selectedPlantingSK:r.sk,selectedRecord:l,selectedRecordSK:l.sk}),this.setState({openDialog:a,isNew:!1}),console.log(l,this.props.getFromGlobalState("monitorings"))},this.handleClickShowTableRecord=(e,t,a,n,i,r)=>{let l=this.props.getFromGlobalState("blocks").find(e=>e.sk===i),s=l.plantings.find(e=>e.sk===t.sk),o=s[r].find(e=>e.sk===a);console.log(o,this.props.getFromGlobalState("monitorings")),this.setState({selectedBlock:l,selectedPlanting:s,selectedBlockSK:null===l||void 0===l?void 0:l.sk,selectedPlantingSK:null===s||void 0===s?void 0:s.sk,selectedRecord:o,selectedRecordSK:null===o||void 0===o?void 0:o.sk}),this.setState({openDialog:r,isNew:!1})},this.handleClickAddNewRecord=(e,t,a)=>{let n=this.props.getFromGlobalState("blocks").find(t=>t.sk===e),i=n.plantings.find(e=>e.sk===t);this.setState({selectedBlock:n,selectedPlanting:i,openDialog:a,isNew:!0,selectedBlockSK:e,selectedPlantingSK:t})},this.handleClickViewReport=(e,t,a)=>{let n=this.props.getFromGlobalState("blocks").find(t=>t.sk===e),i=n.plantings.find(e=>e.sk===t);this.setState({selectedBlock:n,selectedPlanting:i,reportDialogOpen:!0,viewRecordType:a,isNew:!1,selectedBlockSK:e,selectedPlantingSK:t})},this.handleClickViewAll=(e,t,a)=>{let n=this.props.getFromGlobalState("blocks").find(t=>t.sk===e),i=n.plantings.find(e=>e.sk===t);this.setState({recordExpanded:{plantingSK:t,recordType:a},selectedBlock:n,selectedPlanting:i,showAllDialogOpen:!0,viewRecordType:a,isNew:!1,selectedBlockSK:e,selectedPlantingSK:t})},this.handleRecordExpanded=(e,t,a)=>{a.stopPropagation(),this.setState({recordExpanded:{plantingSK:e,recordType:t}})},this.getStatusIcon=(e,t)=>!0===e?i.a.createElement(I.a,{placement:"top",title:"In Pre-harvest Interval"},i.a.createElement(de.a,{className:t.redAvatar},i.a.createElement("checkIcon",null))):i.a.createElement(I.a,{placement:"top",title:"Not in Pre-harvest Interval"},i.a.createElement(de.a,{className:t.greenAvatar},i.a.createElement("crossIcon",null))),this.handleSwitchFarm=async e=>{const t=e.target.value,a=this.props.getFromGlobalState("activeSite");e.target.value!==a&&(await this.props.refreshState(t),await this.props.sync(t))},this.getBlockItems=(e,t,a,n)=>{const i=function(e,t,a,n){const i=[],r=Q(n);let l=0,s=0,o=0;return e&&t&&a?(e.forEach(e=>{e.plantings&&e.plantings.forEach(a=>{var c,d,m,p,h,g,u,b;l+=Number(a.size),s+=Number(a.totalPlants),o+=null===(c=Number(e.size))||void 0===c?void 0:c.toFixed(2);const v=`${null===(d=ne(e.paths))||void 0===d||null===(m=d.lat)||void 0===m?void 0:m.toFixed(2)}, ${null===(p=ne(e.paths))||void 0===p||null===(h=p.lng)||void 0===h?void 0:h.toFixed(2)}`;i.push({country:null===n||void 0===n?void 0:n.country,province:null===n||void 0===n?void 0:n.province,farmName:(null===n||void 0===n?void 0:n.name)||(null===n||void 0===n?void 0:n.shortName),plantingName:null===a||void 0===a?void 0:a.name.replace(/_/g," "),blockNumber:null===e||void 0===e?void 0:e.number,blockSK:null===e||void 0===e?void 0:e.sk,plantingSK:null===a||void 0===a?void 0:a.sk,slope:null===e||void 0===e?void 0:e.slope,soilType:null===e||void 0===e?void 0:e.soilType,cropName:ae(null===a||void 0===a?void 0:a.crop,t),varietyName:ae(null===a||void 0===a?void 0:a.variety,null===(g=t.find(e=>e.sk===(null===a||void 0===a?void 0:a.crop)))||void 0===g?void 0:g.varieties,"cultivar"),plantingDate:null===a||void 0===a?void 0:a.date,plantSpacing:null===a||void 0===a?void 0:a.plantSpacing,rowSpacing:null===a||void 0===a?void 0:a.plantDensity,blockSize:null===(u=Number(null===e||void 0===e?void 0:e.size))||void 0===u?void 0:u.toFixed(2).toLocaleString(r),plantingSize:null===(b=Number(null===a||void 0===a?void 0:a.size))||void 0===b?void 0:b.toFixed(2).toLocaleString(r),totalPlants:Number(null===a||void 0===a?void 0:a.totalPlants).toLocaleString(r),irrigationType:null===e||void 0===e?void 0:e.irrigationSystem,irrigationFlowRate:"irrigated"===(null===e||void 0===e?void 0:e.irrigated)?e.volumePerHour.toLocaleString(r):"-",irrigationFlowRateUnit:null===e||void 0===e?void 0:e.flowunit,coordinates:v})})}),i.push({strong:!0,blockNumber:"Total",blockSize:o.toLocaleString(r)+" ha",plantingSize:l.toLocaleString(r)+" ha",totalPlants:s.toLocaleString(r)}),{retVal:i}):[]}(e,t,a,n);let r=[];return r=[{id:"blockNumber",numeric:!1,disablePadding:!1,label:"Block",minWidth:"30px"},{id:"blockSize",numeric:!1,disablePadding:!1,label:"Block Size (ha)",minWidth:"30px"},{id:"soilType",numeric:!1,disablePadding:!1,label:"Soil Type"},{id:"slope",numeric:!1,disablePadding:!1,label:"Slope"},{id:"cropName",numeric:!1,disablePadding:!1,label:"Crop",minWidth:"70px"},{id:"varietyName",numeric:!1,disablePadding:!1,label:"Variety",minWidth:"70px"},{id:"plantingName",numeric:!1,disablePadding:!1,label:"Planting Name",minWidth:"30px"},{id:"plantingSize",numeric:!1,disablePadding:!1,label:"Planting Size (ha)",minWidth:"30px"},{id:"plantingDate",numeric:!1,disablePadding:!1,label:"Planting Date",minWidth:"70px"},{id:"plantSpacing",numeric:!1,disablePadding:!1,label:"Plant Spacing (m)",minWidth:"30px"},{id:"rowSpacing",numeric:!1,disablePadding:!1,label:"Row Spacing (m)",minWidth:"30px"},{id:"totalPlants",numeric:!1,disablePadding:!1,label:"Plants",minWidth:"70px"},{id:"irrigationType",numeric:!1,disablePadding:!1,label:"Irrigation",minWidth:"70px"},{id:"irrigationFlowRate",numeric:!1,disablePadding:!1,label:"Flow rate (l/h)",minWidth:"70px"},{id:"irrigationFlowRateUnit",numeric:!1,disablePadding:!1,label:"Flow rate unit",minWidth:"70px"},{id:"coordinates",numeric:!1,disablePadding:!1,label:"Coordinates [middle point]",minWidth:"70px"}],{rows:i.retVal,headCells:r,totalSize:i.totalSize}},this.state={isloading:!0,isNew:!1,openDialog:"",reportDialogOpen:!1,showAllDialogOpen:!1,selectedBlock:null,selectedBlockSK:"",selectedRecordSK:"",selectedPlantingSK:"",expanded:"",recordExpanded:{plantingSK:"",recordType:""},pdf:!1,csv:!1}}async componentDidMount(){this.props.isAuthenticated&&this.setState({isloading:!1})}handleClickAddNew(){this.setState({openDialog:"block",isNew:!0})}handleClickShow(e,t){t.stopPropagation(),this.setState({selectedBlock:e,selectedBlockSK:e.sk}),this.setState({openDialog:"block",isNew:!1})}handleUpdateBlocks(e){var t=this.props.getFromGlobalState("blocks").findIndex(t=>t.sk===e.sk);if(-1===t){var a=this.props.getFromGlobalState("blocks");a.push(e),this.props.setGlobalState({blocks:a})}else{let a=this.props.getFromGlobalState("blocks");a[t]=e,this.props.setGlobalState({blocks:a})}}handleDeleteBlock(e,t){const{getFromGlobalState:a,setGlobalState:n}=this.props,i=a("blocks"),r=i.findIndex(t=>t.sk===e.sk);-1!==r?(i.splice(r,1),n({blocks:i})):alert("impossible - we don't have this block!")}setClosePlanting(){this.setState({openDialog:""})}handleUpdatePlantings(e,t){var a=this.props.getFromGlobalState("blocks").findIndex(e=>e.sk===t);if(-1!==a){var n=this.props.getFromGlobalState("blocks"),i=n[a].plantings,r=i?n[a].plantings.findIndex(t=>t.sk===e.sk):-1;-1===r?(i||(n[a].plantings=[]),n[a].plantings.push(e),this.props.setGlobalState({blocks:n})):(n[a].plantings[r]=e,this.props.setGlobalState({blocks:n}))}else alert("impossible - we don't have this block!")}handleDeleteRecord(e,t){const{getFromGlobalState:a,setGlobalState:n}=this.props,{selectedBlockSK:i,selectedPlantingSK:r}=this.state,l=a("blocks"),s=l.findIndex(e=>e.sk===i);if(-1===s)return void alert("impossible - we don't have this block!");const{plantings:o}=l[s],c=l[s].plantings.findIndex(e=>e.sk===r),d=o[c][e.type]?o[c][e.type].findIndex(t=>t.sk===e.sk):-1;if(-1===d)alert("impossible deleting a record that doesn't exist");else{if("fertilisings"===e.type||"sprayings"===e.type){const t=a("inv_chemical"),i=a("inv_fertiliser");if(t){const a=t.filter(t=>t.sk.startsWith(e.sk));a.length>0&&(a.forEach(e=>t.splice(t.indexOf(e),1)),n({inv_chemical:t}))}if(i){const t=i.filter(t=>t.sk.startsWith(e.sk));t.length>0&&(t.forEach(e=>i.splice(i.indexOf(e),1)),n({inv_fertiliser:i}))}}l[s].plantings[c][e.type].splice(d,1),n({blocks:l})}}handleDeletePlantings(e,t){var a=this.props.getFromGlobalState("blocks").findIndex(e=>e.sk===t);if(-1!==a){var n=this.props.getFromGlobalState("blocks"),i=n[a].plantings?n[a].plantings.findIndex(t=>t.sk===e.sk):-1;-1===i?alert("impossible - deleting a planting we don't have"):(n[a].plantings.splice(i,1),this.props.setGlobalState({blocks:n}))}else alert("impossible - we don't have this block!")}handleUpdateRecord(e,t){ba(e,0,this.props.getFromGlobalState,this.props.setGlobalState,this.state.selectedBlockSK,this.state.selectedPlantingSK)}setClose(){this.setState({openDialog:""})}setCloseReport(){this.setState({reportDialogOpen:!1})}setCloseViewAll(){this.setState({showAllDialogOpen:!1})}renderPlantings(e,t){return i.a.createElement(i.a.Fragment,null,e.map(e=>i.a.createElement(en.a,{key:e.sk,button:!0,className:t.nested},i.a.createElement(ji.a,null,i.a.createElement(Ar.a,null)),i.a.createElement(ti.a,{primary:e.Val}))))}getIrrigationName(e){return X("irrigations",e,this.props.getFromGlobalState)}renderBlocksList(e,t){return console.log(e),e.map(e=>i.a.createElement(g.a,{key:e.sk,style:{padding:"3px"},item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(D,{expanded:!(!this.state.selectedBlock||this.state.selectedBlock.sk!==e.sk)||void 0,disableContentPadding:!0,title:""+e.number,ariaLabel:"Block",subHeader:`${e.size} ha, ${e.slope} slope, ${e.soilType}, ${e.irrigated?"irrigated"===e.irrigated?e.volumePerHour+"l/hour":"Dry land":e.volumePerHour+"l/hour"} `,avatar:i.a.createElement(i.a.Fragment,null,i.a.createElement(ge,{status:{status:"green"},hideIfGreen:!1,size:"medium"}),e.cached&&!e.syncError&&i.a.createElement(U.a,{className:t.cached}),e.cached&&e.syncError&&i.a.createElement(W.a,{className:t.syncError})),handleExpandClick:this.handleExpandBlock.bind(this,e),expandedContent:i.a.createElement(un,{plantings:e.plantings,handleExpandClick:this.handlePlantingExpand,expandedPlanting:this.state.expanded,onClickAdd:this.handleClickAddNewPlanting,blockSK:e.sk,onClickView:this.handleClickShowPlanting,onClickViewRecord:this.handleClickShowRecord,onClickViewTableItem:this.handleClickShowTableRecord,onClickAddRecord:this.handleClickAddNewRecord,onClickViewReport:this.handleClickViewReport,onClickViewAll:this.handleClickViewAll,showAll:this.state.showAllDialogOpen,handleExpandRecordClick:this.handleClickViewAll,expandedRecord:this.state.recordExpanded,settings:this.props.getFromGlobalState("crops"),getFromGlobalState:this.props.getFromGlobalState,setCloseShowAll:this.setCloseViewAll.bind(this),block:e})})))}renderLander(){return i.a.createElement("div",{className:"lander"},i.a.createElement("h1",null,"Land Diary"),i.a.createElement("p",null,"Coming Soon"),i.a.createElement("div",null,i.a.createElement(s.b,{color:"primary",to:"/login"},"Login"),i.a.createElement(s.b,{to:"/signup",className:"btn btn-success btn-lg"},"Sign up")))}async refresh(){this.setState({isLoading:!0}),await this.props.sync(this.props.getFromGlobalState("activeSite")),this.setState({isLoading:!1})}blockReportPDF(){this.setState({pdf:!0})}blockReportCSV(){this.setState({csv:!0})}onDownloaded(){this.setState({pdf:!1})}onDownloadedCSV(){this.setState({csv:!1})}renderBlocks(e){!function(e){const t=new Date;if(e)for(const a of e){const e={status:"green",messages:[]};if(a.plantings){for(const n of a.plantings){const a={status:"green",messages:[]};if(n.sprayings){for(const e of n.sprayings){const n={status:"green",message:null};if(void 0!==e.phiLapse){new Date(e.phiLapse.substring(0,10))>t&&(n.status="red",n.message="In pre-harvest Interval")}else n.status="red",n.message="Pre-harvest date not defined";e.status=n,a.status=Ze(a.status,n.status),n.message&&a.messages.push(n.message)}e.status=Ze(e.status,a.status),a.messages.length>0&&e.messages.push(a.messages),n.status=a}}a.status=e}}}(this.props.getFromGlobalState("blocks"));let t=this.props.getFromGlobalState("farm")[0];this.props.getFromGlobalState("farms");console.log("farms",this.props.getFromGlobalState("farm"));let a=this.props.getFromGlobalState("blocks"),n=this.props.getFromGlobalState("crops");const r=this.props.getFromGlobalState("siteList").filter(e=>!e.isDisabled||!0!==e.isDisabled),l=this.props.getFromGlobalState("activeSite");let s=this.props.getFromGlobalState("irrigations");const o=!window.matchMedia("(min-width: 850px)").matches;a=a&&a.sort((e,t)=>(""+e.number).localeCompare(t.number,void 0,{numeric:!0}));const c=(this.state.pdf||this.state.csv)&&this.getBlockItems(a,n,s,t),{industryView:d,history:m}=this.props;return d&&m.push("/census"),i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{className:e.searchBar,key:"search",style:{padding:"3px",marginBottom:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(O.a,null," ",i.a.createElement(Mr,{pdfRequested:this.state.pdf,csvRequested:this.state.csv,onRefresh:this.refresh.bind(this),siteList:r,activeSite:l,getFromGlobalState:this.props.getFromGlobalState,isMobile:o,onSwitchFarm:this.handleSwitchFarm,onBlockReportPDF:this.blockReportPDF.bind(this),onBlockReportCSV:this.blockReportCSV.bind(this),reportPDF:i.a.createElement(Vr,{onDownloaded:this.onDownloaded.bind(this),color:"secondary",className:e.pdfButton,totalSize:c.totalSize,farm:t,headCells:c.headCells,rows:c.rows,getFromGlobalState:this.props.getFromGlobalState}),reportCSV:i.a.createElement($r,{onDownloaded:this.onDownloadedCSV.bind(this),color:"secondary",className:e.pdfButton,totalSize:c.totalSize,farm:t,headCells:c.headCells,rows:c.rows,getFromGlobalState:this.props.getFromGlobalState})})))),i.a.createElement(N,{isloading:this.state.isLoading},i.a.createElement(g.a,{container:!0,className:e.root2,spacing:2,alignItems:"flex-start"},this.renderBlocksList(this.props.getFromGlobalState("blocks"),e),"block"===this.state.openDialog&&i.a.createElement(Zn,{handleUpdateBlocks:this.handleUpdateBlocks.bind(this),handleDeleteBlock:this.handleDeleteBlock.bind(this),open:"block"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,block:this.state.selectedBlock,metaData:this.props.getFromGlobalState("irrigations"),getFromGlobalState:this.props.getFromGlobalState}),"planting"===this.state.openDialog&&i.a.createElement(ii,{handleUpdatePlantings:this.handleUpdatePlantings.bind(this),handleDeletePlantings:this.handleDeletePlantings.bind(this),allowDelete:!0,open:"planting"===this.state.openDialog,setClose:this.setClosePlanting.bind(this),isNew:this.state.isNew,planting:this.state.selectedPlanting,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,getFromGlobalState:this.props.getFromGlobalState,metaData:{clusters:this.props.getFromGlobalState("clusters"),crops:this.props.getFromGlobalState("crops"),block:this.state.selectedBlock}}),"waterings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"waterings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"waterings",newTitle:"New Irrigation",title:"Irrigation",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"date",min:1,max:40},{name:"duration",min:1,max:40},{name:"operator",min:1,max:200},{name:"actualLiters",min:0,max:1e13,type:"number"}]}),"fertilisings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"fertilisings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,setSnack:this.props.setSnack,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"fertilisings",newTitle:"New Fertilising",title:"Fertilising",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"date",min:1,max:40}]}),"pestings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"pestings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,setSnack:this.props.setSnack,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"pestings",isMobile:this.props.isMobile,newTitle:"New Monitoring",title:"Monitoring",getFromGlobalState:this.props.getFromGlobalState,setGlobalState:this.props.setGlobalState,requiredFields:[{name:"date",min:1,max:40}]}),"activities"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"activities"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,setSnack:this.props.setSnack,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"activities",newTitle:"New Activity",title:"Activity",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"activity",min:1,max:100},{name:"operator",min:1,max:200},{name:"date",min:1,max:40}]}),"sprayings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"sprayings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,setSnack:this.props.setSnack,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"sprayings",newTitle:"New Plant Protection",title:"Plant Protection",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"date",min:1,max:40}]}),"harvestings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"harvestings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,setSnack:this.props.setSnack,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"harvestings",newTitle:"New Harvesting",title:"Harvesting",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"harvestEquip",min:1,max:100,condition:{name:"totalHarvestOverride",value:!1}},{name:"harvestUnits",min:1,max:40,condition:{name:"totalHarvestOverride",value:!1}},{name:"harvestTotal",min:1,max:40},{name:"date",min:1,max:40}]}),"packings"===this.state.openDialog&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:"packings"===this.state.openDialog,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:"packings",newTitle:"New Packing",title:"Packing",getFromGlobalState:this.props.getFromGlobalState,requiredFields:[{name:"destination",min:1,max:40},{name:"consignment",min:1,max:40},{name:"packEquip",min:1,max:100},{name:"packUnits",min:1,max:40},{name:"packTotal",min:1,max:40},{name:"wasteEquip",min:1,max:100},{name:"wasteUnits",min:1,max:40},{name:"wasteTotal",min:1,max:40},{name:"date",min:1,max:40}]}),!0===this.state.reportDialogOpen&&i.a.createElement(Ir,{handleUpdateRecord:this.handleUpdateRecord.bind(this),open:this.state.reportDialogOpen,setClose:this.setCloseReport.bind(this),isNew:this.state.isNew,showAll:!0,planting:this.state.selectedPlanting,block:this.state.selectedBlock,farm:t,recordType:this.state.viewRecordType,getFromGlobalState:this.props.getFromGlobalState,title:Yr[this.state.viewRecordType]}))))}render(){const{classes:e}=this.props;return i.a.createElement(i.a.Fragment,null,this.props.isAuthenticated?this.renderBlocks(e):this.renderLander())}}var Zr=Object(v.a)(e=>({root:{flexGrow:1},root2:{flexGrow:1,marginTop:"5px"},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},fab:{margin:e.spacing(1)},fabFloat:{margin:e.spacing(1),top:"auto",right:20,bottom:80,left:"auto",position:"fixed"},submit:{margin:e.spacing(3,0,2)},list:{width:"100%",maxWidth:360,backgroundColor:e.palette.background.paper},heading:{[e.breakpoints.up("sm")]:{display:"none"}},searchBar:{[e.breakpoints.up("sm")]:{}},nested:{paddingLeft:e.spacing(4)},cardHeader:{paddingBottom:"6px"},cached:{fontSize:15,color:e.palette.secondary.main},syncError:{fontSize:15,color:"red"},greenAvatar:{margin:10,color:"#fff",backgroundColor:K.a[500],width:30,height:30},redAvatar:{margin:10,color:"#fff",backgroundColor:e.palette.error.dark,width:30,height:30}}))(_r),Jr=a(1756),Qr=a(437),Xr=a.n(Qr),el=a(182),tl=a.n(el),al=a(183),nl=a.n(al);class il extends n.Component{constructor(e){super(e),this.handleChange=e=>{this.setState({[e.target.id]:e.target.value})},this.showPassword=()=>{const{showPassword:e}=this.state;this.setState({showPassword:!e})},this.handleChangeClick=async e=>{e.preventDefault(),this.setState({changePasswordSubmitting:!0,message:"",success:!0});const{newPassword:t}=this.state;try{await o.b.completeNewPassword(this.state.currentUser,t);const e=await o.b.signIn(this.state.email,this.state.newPassword);await Ta({userName:e.username,email:this.state.email}),this.props.userHasAuthenticated(!0)}catch(a){this.setState({changePasswordSubmitting:!1,changingPassword:!1}),this.setState({success:!1,message:a.response?""+(a.response.data.error.message?a.response.data.error.message:a.response.data.error):a.message}),console.log("ERROR:",a)}},this.handleSubmit=async e=>{e.preventDefault(),this.setState({isloading:!0,message:"",success:!0});try{const e=await o.b.signIn(this.state.email,this.state.password);this.setState({currentUser:e}),"NEW_PASSWORD_REQUIRED"===e.challengeName?this.setState({changingPassword:!0}):this.props.userHasAuthenticated(!0),this.setState({isloading:!1})}catch(t){this.setState({isloading:!1}),this.setState({success:!1,message:t.response?""+(t.response.data.error.message?t.response.data.error.message:t.response.data.error):t.message}),console.log(t)}},this.setSnackClose=()=>{this.setState({message:"",success:!0})},this.state={isloading:!1,success:!0,message:"",email:"",password:"",currentUser:void 0,newPassword:"",confirmNewPassword:"",changingPassword:!1,changePasswordSubmitting:!1,showPassword:!1}}validateForm(){return this.state.email.length>0&&this.state.password.length>0}renderLogin(e){const{email:t,password:a,showPassword:n}=this.state;return i.a.createElement(Jr.a,{component:"main",maxWidth:"xs"},i.a.createElement("div",{className:e.paper},i.a.createElement(de.a,{className:e.avatar},i.a.createElement(Xr.a,null)),i.a.createElement(B.a,{component:"h1",variant:"h5"},"Sign in"),i.a.createElement("form",{onSubmit:this.handleSubmit,className:e.form,noValidate:!0},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"email",type:"email",inputProps:{autocapitalise:"none"},label:"Email Address",name:"email",autoComplete:"email",autoFocus:!0,value:t,onChange:this.handleChange}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,name:"password",label:"Password",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},n?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:n?"text":"password"},id:"password",autoComplete:"current-password",value:a,onChange:this.handleChange}),i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!this.validateForm(),isloading:this.state.isloading,text:"Login",loadingText:"Logging in\u2026"}),i.a.createElement(g.a,{container:!0,spacing:2,style:{paddingTop:"10px"}},i.a.createElement(g.a,{item:!0,xs:!0},i.a.createElement(B.a,{fullWidth:!0,component:s.b,to:"/login/reset",color:"secondary",href:"#",variant:"subtitle1"}," Forgot password?")),i.a.createElement(g.a,{item:!0},i.a.createElement(B.a,{fullWidth:!0,component:s.b,color:"secondary",to:"/signup",variant:"subtitle1"}," Don't have an account? Sign Up"))))))}validateChangeForm(){return this.state.newPassword.length>0&&this.state.newPassword===this.state.confirmNewPassword}renderChangePassword(e){const{changePasswordSubmitting:t,showPassword:a}=this.state;return i.a.createElement(Jr.a,{component:"main",maxWidth:"xs"},i.a.createElement("div",{className:e.paper},i.a.createElement("form",{onSubmit:this.handleChangeClick},i.a.createElement(zt.a,{margin:"normal",required:!0,InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},a?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:a?"text":"password"},fullWidth:!0,id:"newPassword",label:"New Password",name:"newPassword",autoFocus:!0,value:this.state.newPassword,onChange:this.handleChange}),i.a.createElement(zt.a,{margin:"normal",required:!0,InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},a?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:a?"text":"password"},fullWidth:!0,id:"confirmNewPassword",label:"Confirm Password",name:"confirmNewPassword",value:this.state.confirmNewPassword,onChange:this.handleChange}),i.a.createElement(Mt,{type:"submit",key:"loaderchange",id:"loaderchange",name:"loaderchange",variant:"contained",color:"primary",className:e.submit,disabled:!this.validateChangeForm(),isloading:t,text:"Change",loadingText:"Changing\u2026"}))))}render(){const{classes:e}=this.props,{changingPassword:t}=this.state;return i.a.createElement(i.a.Fragment,null,t?this.renderChangePassword(e):this.renderLogin(e),i.a.createElement(ia,{open:!this.state.success,setClose:this.setSnackClose.bind(this),messageText:this.state.message,variant:"error"}))}}var rl=Object(v.a)(e=>({paper:{marginTop:e.spacing(8),display:"flex",flexDirection:"column",alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},submit:{margin:e.spacing(1)}}))(il);const ll=Object(z.a)(e=>({submit:{margin:e.spacing(1)},buttonLeft:{textAlign:"left"}}));function sl(e){const t=ll(),{message:a,onChecked:n,checked:r,linkCaption:l,displayPolicy:s,handleCancel:o,id:c,onDisplayPolicy:d,policyCaption:m}=e;return i.a.createElement(i.a.Fragment,null,i.a.createElement(Ct.a,{disableRipple:!0,className:t.buttonLeft,color:"primary",onClick:d},l),s&&i.a.createElement(yt.a,{open:s,onClose:o,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description"},i.a.createElement(St.a,{id:"alert-dialog-title"},m),i.a.createElement(Et.a,null,a&&i.a.createElement(Ut.a,{id:"alert-dialog-description"},a)),i.a.createElement(ft.a,null,i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:r,onChange:n,name:c,id:c}),label:"I accept"}),i.a.createElement(Ct.a,{onClick:o,color:"primary",variant:"contained",className:t.submit},"Close"))))}const ol=Object(z.a)(e=>({paper:{width:"100%",marginBottom:e.spacing(2)}}));function cl(e){const t=ol();return i.a.createElement(O.a,{elevation:0,className:t.paper},i.a.createElement(B.a,{variant:"h6"},"Draft version under Beta"),i.a.createElement("br",null),i.a.createElement(B.a,null,'This is the privacy notice of Land Diary. In this document, "we", "our", or "us" refer to Land Diary (Pty) Ltd. We are company number K2021500741 registered in South Africa.'),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Introduction"),i.a.createElement(B.a,null,"This privacy notice aims to inform you about how we collect and process any information that we collect from you, or that you provide to us. It covers information that could identify you (\u201cpersonal information\u201d) and information that could not. In the context of the law and this notice, \u201cprocess\u201d means collect, store, transfer, use or otherwise act on information. It tells you about your privacy rights and how the law protects you. We are committed to protecting your privacy and the confidentiality of your personal information. Our policy is not just an exercise in complying with the law, but a continuation of our respect for you and your personal information. We undertake to preserve the confidentiality of all information you provide to us and hope that you reciprocate. Our policy complies with the Protection of Personal Information Act 2013. The law requires us to tell you about your rights and our obligations to you in regard to the processing and control of your personal information. Except as set out below, we do not share, sell, or disclose to a third party, any information collected through our website."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"1. Information we process"),i.a.createElement(B.a,null,"We may collect, use, store and transfer different kinds of personal information about you. We have collated these into groups as follows: Your identity includes information such as first name, last name, title, date of birth, and other identifiable information that you may have provided at some time. Your contact information includes information such as billing address, delivery address, email address, telephone numbers and any other information you have given to us for the purpose of communication or meeting. Your financial information includes information such as your bank account and payment card details. Transaction information includes details about payments or communications to and from you and information about the products and services you have purchased from us. Technical information includes your internet protocol (IP) address, browser type and version, time zone setting and location, browser plug-in types and versions, operating system and platform and other technology on the devices you use to access this website. Your profile includes information such as your username and password, purchases or orders made by you, your interests, preferences, feedback and survey responses. We may aggregate anonymous information such as statistical or demographic data for any purpose. Anonymous information is information that does not identify you as an individual. Aggregated information may be derived from your personal information but is not considered personal information in law because it does not reveal your identity. For example, we may aggregate profile information to assess interest in a product or service. However, if we combine or connect aggregated data with your personal information so that it can identify you in any way, we treat the combined data as personal information, and it will be used in accordance with this privacy notice."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"2. Special personal information"),i.a.createElement(B.a,null,"Special personal information is data about your race or ethnicity, religious or philosophical beliefs, sex life, political opinions, trade union membership, information about your health and biometric data. It also includes information about criminal convictions and offences. We do not collect any special personal information about you."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"3. If you do not provide personal information we need"),i.a.createElement(B.a,null,"Where we need to collect information by law, or under the terms of a contract, we have with you, and you fail to provide that information when requested, we may not be able to perform that contract. In that case, we may have to stop providing a service to you. If so, we will notify you of this at the time."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"The bases on which we process information about you"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"4. Information we process because we have a contractual obligation with you"),i.a.createElement(B.a,null,"When you create an account, or otherwise agree to our terms and conditions, a contract is formed between you and us. In order to carry out our obligations under that contract, we must process the information you give us. Some of this information may be personal information. We may use it in order to: verify your identity for security purposes provide you with our services We process this information on the basis there is a contract between us, or that you have requested we use the information before we enter into a legal contract. We shall continue to process this information until the contract between us ends or is terminated by either party under the terms of the contract."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"5. Information we process with your consent"),i.a.createElement(B.a,null,"Through certain actions when otherwise there is no contractual relationship between us, such as when you browse our website or ask us to provide you more information about our business, including our products and services, you provide your consent to us to process information that may be personal information. Wherever possible, we aim to obtain your explicit consent to process this information, for example, by asking you to agree to our use of cookies. If you have given us explicit permission to do so, we may from time to time, pass your name and contact information to selected associates whom we consider may provide services or products you would find useful. We continue to process your information on this basis until you withdraw your consent or it can be reasonably assumed that your consent no longer exists. You may withdraw your consent at any time by instructing us at info@landdiary.co.za. However, if you do so, you may not be able to use our website or our services further."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"6. Information we process for the purposes of legitimate interests"),i.a.createElement(B.a,null,"We may process the information on the basis there is a legitimate interest, either to you or to us, of doing so. Where we process your information on this basis, we do after having given careful consideration to: whether the same objective could be achieved through other means whether processing (or not processing) might cause you harm whether you would expect us to process your information, and whether you would, in the round, consider it reasonable to do so For example, we may process your information on this basis for the purposes of: record-keeping for the proper and necessary administration of LandDiary responding to unsolicited communication from you to which we believe you would expect a response protecting and asserting the legal rights of any party insuring against or obtaining professional advice that is required to manage Land Diary risk protecting your interests where we believe we have a duty to do so"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"7. Information we process because we have a legal obligation"),i.a.createElement(B.a,null,"Sometimes, we must process your information in order to comply with a statutory obligation. For example, we may be required to give information to legal authorities if they so request or if they have the proper authorization such as a search warrant or court order. This may include your personal information."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Specific uses of information you provide to us"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"8. Information relating to your method of payment"),i.a.createElement(B.a,null,"Payment information is never taken by us or transferred to us either through our website or otherwise. Our employees and contractors never have access to it. At the point of payment, you are transferred to a secure page on the website of PayFast or some other reputable payment service provider. That page may be branded to look like a page on our website, but it is not controlled by us."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"9. Information about your direct debit"),i.a.createElement(B.a,null,"When you agree to set up a direct debit arrangement, the information you give to us is passed to our own bank [name of bank] for processing according to our instructions. We do not keep a copy."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"10. Communicating with us"),i.a.createElement(B.a,null,"When you contact us, whether by telephone, through our website or by e-mail, we collect the information you have given to us in order to reply with the information you need. We record your request and our reply in order to increase the efficiency of our business. We keep personally identifiable information associated with your messages, such as your name and email address so as to be able to track our communications with you to provide a high-quality service."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"11. Complaining"),i.a.createElement(B.a,null,"When we receive a complaint, we record all the information you have given to us. We use that information to resolve your complaint. If your complaint reasonably requires us to contact some other person, we may decide to give to that other person some of the information contained in your complaint. We do this as infrequently as possible, but it is a matter for our sole discretion as to whether we do give information, and if we do, what that information is. We may also compile statistics showing information obtained from this source to assess the level of service we provide, but not in a way that could identify you or any other person."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Use of information we collect through automated systems when you visit our website"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"12. Cookies"),i.a.createElement(B.a,null,"Cookies are small text files that are placed on your computer's hard drive by your web browser when you visit any website. They allow information gathered on one web page to be stored until it is needed for use on another, allowing a website to provide you with a personalized experience and the website owner with statistics about how you use the website so that it can be improved. Some cookies may last for a defined period, such as one day or until you close your browser. Others last indefinitely. Your web browser should allow you to delete any you choose. It also should allow you to prevent or limit their use. Our website uses cookies. They are placed by software that operates on our servers, and by software operated by third parties whose services we use. When you first visit our website, we ask you whether you wish us to use cookies. If you choose not to accept them, we shall not use them for your visit except to record that you have not consented to their use for any other purpose. If you choose not to use cookies or you prevent their use through your browser settings, you will not be able to use all the functionality of our website. We use cookies in the following ways: to track how you use our app to record whether you have seen specific messages we display on our app to keep you signed in to our app"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"13. Personal identifiable information from your browsing activity"),i.a.createElement(B.a,null,"Requests by your web browser to our servers for web pages and other content on our website are recorded. We record information such as your geographical location, your Internet service provider and your IP address. We also record information about the software you are using to browse our website, such as the type of computer or device and the screen resolution. We use this information in aggregate to assess the popularity of the webpages on our website and how we perform in providing content to you. If combined with other information we know about you from previous visits, the information possibly could be used to identify you personally, even if you are not signed in to our website."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Disclosure and sharing of your information"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Information we obtain from third parties"),i.a.createElement(B.a,null,"Although we do not disclose your personal information to any third party (except as set out in this notice), we sometimes receive information that is indirectly made up from your personal information from third parties whose services we use. No such information is personally identifiable to you."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"15. Credit reference"),i.a.createElement(B.a,null,"To assist in combating fraud, we share information with credit reference agencies, so far as it relates to clients or customers who instruct their credit card issuer to cancel payment to us without having first provided an acceptable reason to us and given us the opportunity to refund their money."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"16. Information may be processed outside South Africa"),i.a.createElement(B.a,null,"Our websites are hosted in the United States of America. We may also use outsourced services in countries outside South Africa from time to time in other aspects of our business. Accordingly, information obtained within South Africa or any other country could be processed outside South Africa. For example, some of the software our website uses may have been developed in the United States of America."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Control over your own information"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"17. Your duty to inform us of changes"),i.a.createElement(B.a,null,"It is important that the personal information we hold about you is accurate and current. Please keep us informed if your personal information changes."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"18. Access to your personal information"),i.a.createElement(B.a,null,"At any time you may review or update personally identifiable information that we hold about you, by signing in to your account. To obtain a copy of any information that is not provided on our website you should contact us to make that request.` After receiving the request, we will tell you when we expect to provide you with the information, and whether we require any fee for providing it to you."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"19. Removal of your information"),i.a.createElement(B.a,null,"If you wish us to remove personally identifiable information from our website, you should contact us to make your request. This may limit the service we can provide to you."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"20. Verification of your information"),i.a.createElement(B.a,null,"When we receive any request to access, edit or delete personal identifiable information we shall first take reasonable steps to verify your identity before granting you access or otherwise taking any action. This is important to safeguard your information."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"Other matters"),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"21. Use of website by children"),i.a.createElement(B.a,null,"We do not sell products or provide services for purchase by children, nor do we market to children."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"22. Encryption of data sent between us"),i.a.createElement(B.a,null,"We use Secure Sockets Layer (SSL) certificates to verify our identity to your browser and to encrypt any data you give us. Whenever information is transferred between us, you can check that it is done so using SSL by looking for a closed padlock symbol or another trust mark in your browser\u2019s URL bar or toolbar."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"23. How you can complain"),i.a.createElement(B.a,null,"If you are not happy with our privacy policy or if you have any complaint then you should tell us. If a dispute is not settled, then we hope you will agree to attempt to resolve it by engaging in good faith with us in the process of mediation or arbitration."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"24. Retention period for personal data"),i.a.createElement(B.a,null,"Except as otherwise mentioned in this privacy notice, we keep your personal information only for as long as required by us: to provide you with the services you have requested; to comply with other law, including for the period demanded by our tax authorities; to support a claim or defence in court."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"25. Compliance with the law"),i.a.createElement(B.a,null,"Our privacy policy has been compiled so as to comply with the law of every country or legal jurisdiction in which we aim to do business. If you think it fails to satisfy the law of your jurisdiction, we should like to hear from you. However, ultimately it is your choice as to whether you wish to use our website."),i.a.createElement("br",null),i.a.createElement(B.a,{variant:"h5"},"26. Review of this privacy policy"),i.a.createElement(B.a,null,"We may update this privacy notice from time to time as necessary. The terms that apply to you are those posted here on our website on the day you use our website. We advise you to print a copy for your records. If you have any question regarding our privacy policy, please contact us."),i.a.createElement("br",null))}const dl=Object(z.a)(e=>({paper:{width:"100%",marginBottom:e.spacing(2)}}));function ml(e){const t=dl();return i.a.createElement(O.a,{elevation:0,className:t.paper},i.a.createElement(B.a,null,"Welcome to Land Diary (\u201cthe App\u201d). By accessing or using Land Diary, you agree to comply with and be bound by the following Terms and Conditions. Please read them carefully before using the App. If you do not agree to these terms, do not use the App.",i.a.createElement("br",null),i.a.createElement("br",null),"1. Acceptance of Terms By accessing or using Land Diary, you confirm that you have read, understood, and agree to these Terms and Conditions, as well as our Privacy Policy. We may update these Terms from time to time, and it is your responsibility to review them periodically.",i.a.createElement("br",null),i.a.createElement("br",null),"2. Use of the App - Eligibility: You must be at least 18 years old or have the consent of a legal guardian to use Land Diary.",i.a.createElement("br",null)," - Account Registration: You may be required to create an account to access certain features of the App. You agree to provide accurate and up-to-date information and keep your account credentials secure.",i.a.createElement("br",null),"- Permitted Use: You agree to use Land Diary solely for lawful purposes and in accordance with these Terms. You must not use the App to violate any local, national, or international laws.",i.a.createElement("br",null),i.a.createElement("br",null),"3. User Content",i.a.createElement("br",null),' - Ownership: You retain ownership of any content you upload or submit to Land Diary, including but not limited to text, images, and other data ("User Content").',i.a.createElement("br",null)," - License to Land Diary: By submitting User Content, you grant Land Diary a non-exclusive, royalty-free, worldwide license to use, display, and distribute your User Content for the purposes of operating and improving the App.",i.a.createElement("br",null)," - Prohibited Content: You agree not to post any content that is offensive, harmful, defamatory, or violates any laws. Land Diary reserves the right to remove any User Content that it deems inappropriate.",i.a.createElement("br",null),i.a.createElement("br",null),"4. Intellectual Property",i.a.createElement("br",null)," - All content, software, and materials available on Land Diary, excluding User Content, are the property of Land Diary or its licensors. This includes, but is not limited to, text, graphics, logos, and software.",i.a.createElement("br",null)," - You may not copy, distribute, modify, or create derivative works of any content from the App without prior written consent from Land Diary.",i.a.createElement("br",null),i.a.createElement("br",null),"5. Limitation of Liability",i.a.createElement("br",null)," - Land Diary and its affiliates are not liable for any damages, losses, or harm resulting from your use or inability to use the App.",i.a.createElement("br",null),' - The App is provided "as-is" and "as available," and we make no warranties, express or implied, regarding the App\u2019s functionality, accuracy, or reliability.',i.a.createElement("br",null),i.a.createElement("br",null),"6. Disclaimer",i.a.createElement("br",null)," - Land Diary does not guarantee the accuracy, completeness, or timeliness of information available on the App. The information provided is for general informational purposes and should not be relied upon as legal, financial, or professional advice.",i.a.createElement("br",null),i.a.createElement("br",null),"7. Termination",i.a.createElement("br",null)," - Land Diary reserves the right to suspend or terminate your access to the App at any time, with or without notice, for any reason, including violation of these Terms.",i.a.createElement("br",null),i.a.createElement("br",null),"8. Privacy",i.a.createElement("br",null)," - Our collection and use of personal information in connection with the App are described in our Privacy Policy. By using the App, you agree to the terms of our Privacy Policy.",i.a.createElement("br",null),i.a.createElement("br",null),"9. Governing Law",i.a.createElement("br",null)," - These Terms are governed by and construed in accordance with the laws of South Africa. Any disputes arising under or in connection with these Terms shall be subject to the exclusive jurisdiction of the courts of South Africa.",i.a.createElement("br",null),i.a.createElement("br",null),"10. Contact Us",i.a.createElement("br",null)," - For any questions about these Terms and Conditions, please contact us at info@landdiary.co.za.",i.a.createElement("br",null),i.a.createElement("br",null),i.a.createElement("strong",null,"Acknowledgment"),i.a.createElement("br",null),"By using Land Diary, you acknowledge that you have read, understood, and agree to be bound by these Terms and Conditions."))}const pl=[{name:"name",min:1,max:40},{name:"surname",min:1,max:40},{name:"email",min:1,max:150,type:"email"},{name:"password",min:8,max:100,type:"password"}],hl=[{name:"confirmationCode",min:1,max:20}];class gl extends n.Component{constructor(e){super(e),this.handleConfirmationSubmit=async e=>{e.preventDefault(),this.setState({isloading:!0});const{user:t}=this.state,{userHasAuthenticated:a,history:n,setSnack:i}=this.props;try{await o.b.confirmSignUp(null===t||void 0===t?void 0:t.email.toLowerCase(),t.confirmationCode);const e=await o.b.signIn(null===t||void 0===t?void 0:t.email,t.password);await Ta({userName:e.username,email:e.attributes.email,name:null===t||void 0===t?void 0:t.name,surname:t.surname,shortName:t.shortName,entityType:"entity",showDemo:this.state.demoChecked,newUser:!0}),a(!0),n.push("/settings")}catch(r){i({open:!0,variant:"error",messageText:r.response?(r.response.data.error.message?r.response.data.error.message:r.response.data.error)+" ":r.message}),this.setState({isloading:!1})}},this.showPassword=()=>{const{showPassword:e}=this.state;this.setState({showPassword:!e})},this.onDisplayPTanC=()=>{const{displayTanC:e}=this.state;this.setState({displayTanC:!e})},this.onDisplayDataPrivacy=()=>{const{displayPrivacy:e}=this.state;this.setState({displayPrivacy:!e})},this.handleToggle=e=>{const t={...this.state.user};t[e.target.id]=e.target.checked,this.setState({user:t,changed:!0})},this.handleChange=e=>{const t={...this.state.user};t[e.target.id]=e.target.value,this.setState({user:t,changed:!0})},this.handleSubmit=async e=>{e.preventDefault();const{user:t}=this.state;this.setState({isloading:!0});try{const e=await o.b.signUp({username:null===t||void 0===t?void 0:t.email.toLowerCase(),password:t.password});this.setState({newUser:e})}catch(a){this.props.setSnack({open:!0,variant:"error",messageText:a.response?(a.response.data.error.message?a.response.data.error.message:a.response.data.error)+" ":a.message})}this.setState({isloading:!1})},this.handleBlur=e=>this.validateField(e.target.id,pl),this.handleBlurConfo=e=>this.validateField(e.target.id,hl),this.state={isloading:!1,user:{email:"",password:"",confirmPassword:"",confirmationCode:"",name:"",surname:"",tAnCAccepted:!1,privacyAccepted:!1,demoChecked:!1},newUser:null,errors:{count:0},displayTanC:!1,displayPrivacy:!1,showPassword:!1}}validateField(e,t){const{user:a}=this.state,n=jn(e,a,t),i={...this.state.errors};i[e]=n.msg,this.setState({errors:i})}renderConfirmationForm(e){const{user:t,errors:a,isloading:n}=this.state,r=$n(t,hl);return i.a.createElement("form",{onSubmit:this.handleConfirmationSubmit},i.a.createElement(Jr.a,{component:"main",maxWidth:"xs"},i.a.createElement(B.a,{gutterBottom:!0,color:"primary"},"An email containing your confirmation code was sent to the email address provided. Please enter that code below."),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"confirmationCode",label:"Confirmation Code",name:"confirmationCode",onBlur:this.handleBlurConfo,value:t.confirmationCode,onChange:this.handleChange,error:!!a.confirmationCode||void 0,helperText:a.confirmationCode}),i.a.createElement("br",null),i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!r,isloading:n,text:"Verify",loadingText:"Verifying\u2026"})))}renderForm(e){const{user:t,isloading:a,errors:n,displayTanC:r,displayPrivacy:l,showPassword:s,demoChecked:o}=this.state,c=!window.matchMedia("(min-width: 850px)").matches;let d=$n(t,pl);d=t.password===t.confirmPassword&&d;return i.a.createElement("form",{onSubmit:this.handleSubmit},i.a.createElement(Jr.a,{component:"main",maxWidth:"xs"},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",type:"text",label:"Name",name:"name",autoFocus:!0,value:null===t||void 0===t?void 0:t.name,onChange:this.handleChange,onBlur:this.handleBlurConfo,error:!!n.name||void 0,helperText:n.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"surname",type:"text",label:"Surname",name:"surname",value:t.surname,onChange:this.handleChange,onBlur:this.handleBlurConfo,error:!!n.surname||void 0,helperText:n.surname})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"shortName",type:"text",label:"Entity Name",name:"shortName",autoFocus:!0,value:null===t||void 0===t?void 0:t.shortName,onChange:this.handleChange,onBlur:this.handleBlurConfo,error:!!n.shortName||void 0,helperText:n.shortName})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"email",type:"email",inputProps:{autocapitalise:"none"},label:"Email Address",name:"email",autoComplete:"email",value:null===t||void 0===t?void 0:t.email,onChange:this.handleChange,onBlur:this.handleBlur,error:!!n.email||void 0,helperText:n.email})),i.a.createElement(g.a,null,i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:o,onChange:e=>{this.setState({demoChecked:e.target.checked})},name:"demo-farm",id:"demo-farm"}),label:"Include Demo Farm"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,name:"password",label:"Password",id:"password",autoComplete:"current-password",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},s?i.a.createElement(nl.a,null):i.a.createElement(tl.a,null))),type:s?"text":"password"},value:t.password,onChange:this.handleChange,onBlur:this.handleBlur,error:!!n.password||void 0,helperText:n.password})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,name:"confirmPassword",label:"Confirm Password",type:"password",id:"confirmPassword",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},s?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:s?"text":"password"},value:t.confirmPassword,onChange:this.handleChange,onBlur:this.handleBlur,error:!!n.confirmPassword||void 0,helperText:n.confirmPassword})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(sl,{message:i.a.createElement(ml,null),onChecked:this.handleToggle,checked:t.tAnCAccepted,linkCaption:"View and accept Terms and Conditions",policyCaption:"Terms and Conditions",onDisplayPolicy:this.onDisplayPTanC,displayPolicy:r,handleCancel:this.onDisplayPTanC,id:"tAnCAccepted"})),!c&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,null,"We are committed to protecting your privacy and the confidentiality of your personal information. Our policy is not just an exercise in complying with the law, but a continuation of our respect for you and your personal information.")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(sl,{message:i.a.createElement(cl,null),onChecked:this.handleToggle,checked:t.privacyAccepted,linkCaption:"View and accept Privacy Policy",policyCaption:"Data Privacy",onDisplayPolicy:this.onDisplayDataPrivacy,displayPolicy:l,handleCancel:this.onDisplayDataPrivacy,id:"privacyAccepted"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!d||!t.tAnCAccepted||!t.privacyAccepted,isloading:a,text:"Sign up",loadingText:"Signing up\u2026"})))))}render(){const{classes:e}=this.props,{newUser:t}=this.state;return i.a.createElement("div",{className:"Signup"},null===t?this.renderForm(e):this.renderConfirmationForm(e))}}var ul=Object(v.a)(e=>({paper:{marginTop:e.spacing(8),display:"flex",flexDirection:"column",alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},submit:{margin:e.spacing(1)}}))(gl);class bl extends n.Component{constructor(e){super(e),this.handleChange=e=>{this.setState({[e.target.id]:e.target.value})},this.showPassword=()=>{const{showPassword:e}=this.state;this.setState({showPassword:!e})},this.handleSendCodeClick=async e=>{e.preventDefault(),this.setState({isSendingCode:!0});try{await o.b.forgotPassword(this.state.email.toLowerCase()),this.setState({codeSent:!0})}catch(t){alert(t.message),this.setState({isSendingCode:!1})}},this.handleConfirmClick=async e=>{e.preventDefault(),this.setState({isConfirming:!0});try{await o.b.forgotPasswordSubmit(this.state.email,this.state.code,this.state.password),this.setState({confirmed:!0})}catch(t){alert(t.message),this.setState({isConfirming:!1})}},this.state={code:"",email:"",password:"",codeSent:!1,confirmed:!1,confirmPassword:"",isConfirming:!1,isSendingCode:!1,isNotValid:!1,error:"",showPassword:!1}}validateCodeForm(){return this.state.email.length>0}validateResetForm(){if(this.state.code.length<=0)return!1;let e=!0,t="";return this.state.password.length<8||!this.state.password.match(/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$/)?(t="Password guidance. Minimum length 8, must contain uppercase, lowercase and special characters",e=!0):(t="",e=!1),{isNotValid:!e&&this.state.code.length>0&&this.state.password.length>0&&this.state.password===this.state.confirmPassword,error:t}}renderRequestCodeForm(e){return i.a.createElement("form",{onSubmit:this.handleSendCodeClick},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"email",label:"Email Address",name:"email",autoComplete:"email",autoFocus:!0,value:this.state.email,onChange:this.handleChange}),i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!this.validateCodeForm(),isloading:this.state.isSendingCode,text:"Send Confirmation",loadingText:"Sending\u2026"}))}renderConfirmationForm(e){const t=this.validateResetForm(),{showPassword:a}=this.state;return i.a.createElement("form",{onSubmit:this.handleConfirmClick},i.a.createElement(B.a,{gutterBottom:!0,color:"secondary"},"An email containing your confirmation code was sent to the address provided. Please enter that code below."),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"code",label:"Confirmation Code",name:"code",autoFocus:!0,value:this.state.code,onChange:this.handleChange}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,name:"password",label:"Password",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},a?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:a?"text":"password"},id:"password",value:this.state.password,onChange:this.handleChange}),i.a.createElement(B.a,{variant:"subtitle2"},t.error),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,name:"confirmPassword",label:"Confirm Password",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},i.a.createElement(E.a,{onClick:this.showPassword},a?i.a.createElement(tl.a,null):i.a.createElement(nl.a,null))),type:a?"text":"password"},id:"confirmPassword",value:this.state.confirmPassword,onChange:this.handleChange}),i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!t.isNotValid,isloading:this.state.isConfirming,text:"Confirm",loadingText:"Confirm\u2026"}))}renderSuccessMessage(){return i.a.createElement("div",{className:"success"},i.a.createElement("p",null,"Your password has been reset."),i.a.createElement("p",null,i.a.createElement(s.b,{to:"/login"},"Click here to login with your new credentials.")))}render(){const{classes:e}=this.props;return i.a.createElement("div",{className:"ResetPassword"},this.state.codeSent?this.state.confirmed?this.renderSuccessMessage():this.renderConfirmationForm(e):this.renderRequestCodeForm(e))}}var vl=Object(v.a)(e=>({paper:{marginTop:e.spacing(8),display:"flex",flexDirection:"column",alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},submit:{margin:e.spacing(1)}}))(bl);class yl extends n.Component{constructor(e){super(e),this.handleChange=e=>{this.setState({[e.target.id]:e.target.value})},this.handleChangeClick=async e=>{e.preventDefault(),this.setState({isChanging:!0});try{const e=await o.b.currentAuthenticatedUser();await o.b.changePassword(e,this.state.oldPassword,this.state.password),this.props.history.push("/")}catch(t){alert(t.message),this.setState({isChanging:!1})}},this.state={password:"",oldPassword:"",isChanging:!1,confirmPassword:""}}validateForm(){return this.state.oldPassword.length>0&&this.state.password.length>0&&this.state.password===this.state.confirmPassword}render(){const{classes:e}=this.props;return i.a.createElement("form",{onSubmit:this.handleChangeClick},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"password",fullWidth:!0,id:"oldPassword",label:"Old Password",name:"oldPassword",autoFocus:!0,value:this.state.oldPassword,onChange:this.handleChange}),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"password",fullWidth:!0,id:"password",label:"Old Password",name:"password",value:this.state.password,onChange:this.handleChange}),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"password",fullWidth:!0,id:"confirmPassword",label:"Confirm Password",name:"confirmPassword",autoFocus:!0,value:this.state.confirmPassword,onChange:this.handleChange}),i.a.createElement(Mt,{type:"submit",variant:"contained",color:"primary",className:e.submit,disabled:!this.validateForm(),isloading:this.state.isChanging,text:"Change",loadingText:"Changing\u2026"}))}}var fl=Object(v.a)(e=>({paper:{marginTop:e.spacing(8),display:"flex",flexDirection:"column",alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},submit:{margin:e.spacing(1)}}))(yl),El=a(1757);const Sl=[{name:"name",min:1,max:250},{name:"entityType",min:2,max:100},{name:"shortName",min:1,max:25},{name:"address1",min:1,max:100},{name:"address2",min:1,max:100},{name:"country",min:1,max:100},{name:"province",min:1,max:100},{name:"pCode",min:1,max:40},{name:"contactNum",min:1,max:40},{name:"email",min:1,max:40}];class Cl extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id),this.fileUploaded=async e=>{if(!e.serverId)return void console.log("received undefined key");const{farm:t}=this.state,a={...t};a.logoKey=e.serverId,a.logoFileType=e.fileType;const n=await this.getLogoUrl(a.logoKey,a.logoFileType);this.setState({logoURL:n,changed:!0,farm:a})},this.mapFileUploaded=async e=>{if(!e.serverId)return void console.log("received undefined key");const{farm:t}=this.state,a={...t};a.farmKml=e.serverId,a.farmKmlFileType=e.fileType;const n=await this.getLogoUrl(t.farmKml,t.farmKmlFileType);this.setState({farmMapKml:n,changed:!0,farm:a})},this.getLogoUrl=async(e,t)=>{const{getFromGlobalState:a}=this.props;return Fa({activeTenant:a("activeSite"),type:"files",path:e,contentType:t})},this.handleLatGeoChange=e=>{const{farm:t}=this.state,a={...t};a.geoLocation||(a.geoLocation={lat:null,lng:null}),a.geoLocation.lat=parseFloat(e.target.value),isNaN(a.geoLocation.lat)&&(a.geoLocation.lat=null),this.setState({farm:a,changed:!0})},this.handleLngGeoChange=e=>{const{farm:t}=this.state,a={...t};a.geoLocation||(a.geoLocation={lat:null,lng:null}),a.geoLocation.lng=parseFloat(e.target.value),isNaN(a.geoLocation.lng)&&(a.geoLocation.lng=null),this.setState({farm:a,changed:!0})},this.getCurrentLocation=()=>{this.setState({locationLoading:!0}),navigator.geolocation.getCurrentPosition(e=>{const t={lat:e.coords.latitude,lng:e.coords.longitude,accuracy:e.coords.accuracy,altitude:e.coords.altitude,altAcc:e.coords.altitudeAccuracy},{farm:a}=this.state,n={...a};n.geoLocation=t,this.setState({farm:n,changed:!0,locationLoading:!1})},e=>{this.setState({locationLoading:!1}),alert(e.message)},{enableHighAccuracy:!0,timeout:1e5,maximumAge:0})},this.handleChange=e=>{const{farm:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({farm:a,changed:!0})},this.handleRadioChange=(e,t)=>{const{farm:a}=this.state,n={...a};n[t]=e.target.value,this.setState({farm:n,changed:!0})},this.handleCountryChange=e=>{const{farm:t}=this.state,a={...t};a.country!==e.target.value&&a.province&&(a.province=""),a[e.target.id]=e.target.value;const n=V.filter(t=>t.countryName===e.target.value),i=n.length>0?n[0].regions:[];this.setState({farm:a,changed:!0,regions:i})},this.onMarkerComplete=e=>{const{farm:t}=this.state,a={...t};a.geoLocation={lat:e.position.lat(),lng:e.position.lng()},this.setState({farm:a,changed:!0})};const{farm:t,handleUpdate:a}=this.props;this.handleUpdate=a.bind(this),this.onMarkerComplete=this.onMarkerComplete.bind(this),this.mapFileUploaded=this.mapFileUploaded.bind(this),this.fileUploaded=this.fileUploaded.bind(this),this.state={farm:t,errors:{count:0},changed:!1,locationLoading:!1,regions:[],logoChanged:!1,logoURL:null,copyEntity:!1,untouched:{}}}async componentDidMount(){const{isNew:e}=this.props,{farm:t}=this.state;if(e)this.setState({farm:{entityType:"farm"}});else{const e={...t};if(t.country){const a=V.filter(e=>e.countryName===t.country),n=a.length>0?a[0].regions:[];this.setState({farm:e,regions:n})}if(t.logoKey){const e=await this.getLogoUrl(t.logoKey,t.logoFileType),a=await this.getLogoUrl(t.farmKml,t.farmKmlFileType);this.setState({logoURL:e,farmMapKml:a})}e.entityType||(e.entityType="farm",this.setState({farm:e}))}}validateField(e){const{farm:t,errors:a}=this.state,n=jn(e,t,Sl),i={...a};a[e]=n.msg,this.setState({errors:i})}render(){var e,t;const{classes:a,open:n,isNew:r,setClose:l,getFromGlobalState:s}=this.props,{farm:o,errors:c,regions:d,farmMapKml:m,isUploadingFile:p,logoChanged:h,changed:u,locationLoading:b,logoURL:v}=this.state,y=$n(o,Sl);let f=16;o.geoLocation||(f=2);const E=o.geoLocation&&o.geoLocation.lat&&o.geoLocation.lng?ee(o.geoLocation):{lat:-30.664413,lng:23.758869},S=o.geoLocation?[{position:E,sk:o.key,clickable:!0}]:[],C="farm"===o.entityType?"Farm":"Entity";const x=s("siteList").find(e=>e.tenantId===o.farmId);return i.a.createElement(Ia,{open:n,dialogObject:o,setClose:l,isNew:r,handleUpdateDialogObject:this.handleUpdate,skPrimary:"init_setting_",dynamoType:"farm",valid:!p&&y&&!h,changed:u,newTitle:"Farm Details",title:o.name,getFromGlobalState:s},i.a.createElement(g.a,{container:!0,className:a.root,spacing:1,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:a.formControlRadio},i.a.createElement(kn.a,{shrink:!0,component:"legend",required:!0},"Entity or farm"),i.a.createElement(xn.a,{"aria-label":"entityType",name:"entityType",id:"entityType",className:a.group,value:o?o.entityType:"",onChange:e=>this.handleRadioChange(e,"entityType")},i.a.createElement(Fe.a,{value:"entity",control:i.a.createElement(Cn.a,null),label:"Entity"}),i.a.createElement(Fe.a,{value:"farm",control:i.a.createElement(Cn.a,null),label:"Farm"}),c.entityType&&i.a.createElement(En.a,{className:a.helperText},c.entityType)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(qn,{message:"farm"===o.entityType?"Find the center of the farm on the map and place a pin or select find my location if you are on the farm. You can also enter the latitude and longitude if you have them.":"Find the physical location of the entity office on the map and place a pin or select find my location if you are at the entity office. You can also enter the latitude and longitude if you have them"})),!this.props.isEntity&&i.a.createElement(g.a,{style:{marginTop:10},item:!0,xs:11,sm:11,md:11,lg:11,xl:11},i.a.createElement(kn.a,{shrink:!0,component:"legend",required:!0},"Copy Farm Details From Entity ",(null===x||void 0===x||null===(e=x.parentFarm)||void 0===e?void 0:e.name)||(null===x||void 0===x||null===(t=x.parentFarm)||void 0===t?void 0:t.shortName)),i.a.createElement(ai.a,{checked:this.state.copyEntity,name:"copyEntity",InputLabelProps:{shrink:!0},value:this.state.copyEntity,onChange:e=>{if(this.state.copyEntity)this.setState({farm:this.state.untouched});else{var t,a,n,i,r,l,s,c,d,m,p,h,g,u;const e=V.filter(e=>e.countryName===x.parentFarm.country);console.log(e);const y=e.length>0?e[0].regions:[];var b,v;if(this.setState({untouched:o,farm:{...o,geoLocation:null===x||void 0===x||null===(t=x.parentFarm)||void 0===t?void 0:t.geoLocation,geoLocationLat:null===x||void 0===x||null===(a=x.parentFarm)||void 0===a?void 0:a.geoLocationLat,geoLocationLn:null===x||void 0===x||null===(n=x.parentFarm)||void 0===n?void 0:n.geoLocationLn,puc:null===x||void 0===x||null===(i=x.parentFarm)||void 0===i?void 0:i.puc,gapnum:null===x||void 0===x||null===(r=x.parentFarm)||void 0===r?void 0:r.gapnum,vatNo:null===x||void 0===x||null===(l=x.parentFarm)||void 0===l?void 0:l.vatNo,address1:null===x||void 0===x||null===(s=x.parentFarm)||void 0===s?void 0:s.address1,address2:null===x||void 0===x||null===(c=x.parentFarm)||void 0===c?void 0:c.address2,country:null===x||void 0===x||null===(d=x.parentFarm)||void 0===d?void 0:d.country,province:null===x||void 0===x||null===(m=x.parentFarm)||void 0===m?void 0:m.province,pCode:null===x||void 0===x||null===(p=x.parentFarm)||void 0===p?void 0:p.pCode,contactNum:null===x||void 0===x||null===(h=x.parentFarm)||void 0===h?void 0:h.contactNum,email:null===x||void 0===x||null===(g=x.parentFarm)||void 0===g?void 0:g.email},regions:y}),null===x||void 0===x||null===(u=x.parentFarm)||void 0===u?void 0:u.logoKey)this.getLogoUrl(null===x||void 0===x||null===(b=x.parentFarm)||void 0===b?void 0:b.logoKey,null===x||void 0===x||null===(v=x.parentFarm)||void 0===v?void 0:v.logoFileType)}this.setState({copyEntity:!this.state.copyEntity})}})),i.a.createElement(g.a,{item:!0,xs:11,sm:11,md:11,lg:11,xl:11},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,InputLabelProps:{shrink:!!o.geoLocation},id:"geoLocation",label:"Find my location",name:"geoLocation",disabled:!0,value:o.geoLocation&&o.geoLocation.lat&&o.geoLocation.lng?`${o.geoLocation.lat.toFixed(7)} ${o.geoLocation.lng.toFixed(7)}`:"",onChange:this.handleGeoChange,onBlur:this.handleBlur,error:!!c.geoLocation||void 0,helperText:c.geoLocation})),i.a.createElement(g.a,{item:!0,xs:1,sm:1,md:1,lg:1,xl:1},i.a.createElement(la,{onClick:this.getCurrentLocation,success:!0,icon:i.a.createElement(kr.a,null),loading:b})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"number",InputLabelProps:{shrink:!!o.geoLocation},id:"geoLocationLat",label:"Manual Entry Lat",name:"geoLocationLat",value:o.geoLocation&&o.geoLocation.lat?o.geoLocation.lat:"",onChange:this.handleLatGeoChange,onBlur:this.handleBlur,error:!!c.geoLocation||void 0,helperText:c.geoLocation})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"number",InputLabelProps:{shrink:!!o.geoLocation},id:"geoLocationLng",label:"Manual Entry Lng",name:"geoLocationLng",value:o.geoLocation&&o.geoLocation.lng?o.geoLocation.lng:"",onChange:this.handleLngGeoChange,onBlur:this.handleBlur,error:!!c.geoLocation||void 0,helperText:c.geoLocation})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Wn,{center:E,zoom:f,markers:S,mode:"marker",kmlLayerSrc:m,onMarkerComplete:this.onMarkerComplete})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:C+" Name",name:"name",InputLabelProps:{shrink:!0},value:o.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.name||void 0,helperText:c.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"shortName",label:C+" Short Name",name:"shortName",value:o.shortName,InputLabelProps:{shrink:!0},onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.shortName||void 0,helperText:c.shortName})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"puc",label:"Production Unit Code (PUC)",name:"puc",value:o.puc,InputLabelProps:{shrink:!0},onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.puc||void 0,helperText:c.puc})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"gapnum",label:"GLOBALG.A.P. Number",name:"gapnum",InputLabelProps:{shrink:!0},value:o.gapnum,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.gapnum||void 0,helperText:c.gapnum})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"vatNo",label:"VAT number",name:"vatNo",InputLabelProps:{shrink:!0},value:o.vatNo,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.vatNo||void 0,helperText:c.vatNo})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"address1",label:C+" Physical Address Line 1",name:"address1",InputLabelProps:{shrink:!0},value:o.address1,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.address1||void 0,helperText:c.address1})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"address2",label:C+" Physical Address Line 2",name:"address2",value:o.address2,InputLabelProps:{shrink:!0},onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.address2||void 0,helperText:c.address2})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"country"},"Country"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,margin:"normal",required:!0,displayEmpty:!0,value:o.country,InputLabelProps:{shrink:!0},onChange:this.handleCountryChange,onBlur:this.handleBlur,error:!!c.country||void 0,inputProps:{name:"country",id:"country"}},i.a.createElement("option",{"aria-label":"empty",value:""}),V&&V.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.countryName},e.countryName)))),c.country&&i.a.createElement(En.a,{className:a.helperText},c.country))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:a.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"Province"},"Province"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,margin:"normal",value:o.province,InputLabelProps:{shrink:!0},disabled:!o.province&&d.length<1,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.province||void 0,inputProps:{name:"province",id:"province"}},i.a.createElement("option",{"aria-label":"empty",value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.name},e.name)))),c.province&&i.a.createElement(En.a,{className:a.helperText},c.province))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,id:"pCode",label:"Postal Code",InputLabelProps:{shrink:!0},name:"pCode",value:o.pCode,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.pCode||void 0,helperText:c.pCode})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"contactNum",label:C+" Contact Number",name:"contactNum",value:o.contactNum,InputLabelProps:{shrink:!0},onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.contactNum||void 0,helperText:c.contactNum})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"email",label:C+" Email",name:"email",value:o.email,InputLabelProps:{shrink:!0},onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.email||void 0,helperText:c.email})),i.a.createElement(bn.a,{shrink:!0,htmlFor:"logo"},C+" Logo"),o.logoKey&&o.logoKey&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",null,i.a.createElement("br",null),i.a.createElement("img",{alt:"Logo for the farm",id:"logo",src:v,style:{maxWidth:"150px"}}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(nr,{activeTenant:s("activeSite"),generateThumbnail:!1,generatePreview:!1,maxFileSize:"350KB",onFileUploaded:this.fileUploaded,folder:"images/logo/",getFromGlobalState:s,allowMultiple:!1,forceName:!0,fileName:"farmLogo",allowFileTypeValidation:!0,acceptedFileTypes:["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"]}))))}}var xl=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},formControlRadio:{marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Cl);class kl extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({farmDialogOpen:!0})},this.handleBlur=()=>{},this.getLogoUrl=async(e,t)=>{const{getFromGlobalState:a}=this.props;return Fa({activeTenant:a("activeSite"),type:"files",path:e,contentType:t})},this.handleUpdate=async e=>{const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("farm").findIndex(t=>t.sk===e.sk);if(-1===n){const n=t("farm");n[0]=e;const i=await this.getLogoUrl(e.logoKey,e.logoFileType);this.setState({logoURL:i}),a({farm:n})}else{const i=t("farm");i[n]=e;const r=await this.getLogoUrl(e.logoKey,e.logoFileType);this.setState({logoURL:r}),a({farm:i})}},this.handleUpdate=this.handleUpdate.bind(this),this.setClose=this.setClose.bind(this),this.handleClickShowFarm=this.handleClickShowFarm.bind(this),this.onCloseInfoWindow=this.onCloseInfoWindow.bind(this),this.onSelectFarmMarker=this.onSelectFarmMarker.bind(this),this.onMapClick=this.onMapClick.bind(this);const{initialState:t}=this.props;this.state={farm:t,selectedFarm:null,isNew:!1,farmDialogOpen:!1,logoURL:"",farmMarkerSelected:!1}}async componentDidMount(){const{farm:e}=this.state;if(e[0]){const t=await this.getLogoUrl(e[0].logoKey,e[0].logoFileType);this.setState({logoURL:t})}}handleClickAdd(){this.setState({farmDialogOpen:!0,isNew:!0,selectedFarm:{}})}handleClickEdit(){this.setState({farmDialogOpen:!0,isNew:!0})}handleClickShowFarm(){const{getFromGlobalState:e}=this.props,t=e("farm");t[0]?this.setState({selectedFarm:t[0],farmDialogOpen:"true",isNew:!1}):(t[0]={},this.setState({selectedFarm:t[0],farmDialogOpen:"true",isNew:!0}))}onSelectFarmMarker(){this.setState({farmMarkerSelected:!0})}onCloseMarker(){this.setState({farmMarkerSelected:!1})}onCloseInfoWindow(){this.setState({farmMarkerSelected:!1})}onMapClick(){this.setState({farmMarkerSelected:!1})}setClose(){this.setState({farmDialogOpen:!1})}getFarmInfo(e){return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{variant:"h6"},e.name),i.a.createElement(B.a,{variant:"subtitle2"},` Short name: ${e.shortName} ha`),i.a.createElement(B.a,{variant:"subtitle2"}," Production Unit Code (PUC): "+e.puc),i.a.createElement(B.a,{variant:"subtitle2"}," GLOBALG.A.P. Number: "+e.gapnum),e.vatNo&&i.a.createElement(B.a,{variant:"subtitle2"}," VAT Number: "+e.vatNo),i.a.createElement(El.a,{href:"#",variant:"h6",onClick:this.mapEditFarm.bind(this,e.sk)},"Edit"))}mapEditFarm(){const{getFromGlobalState:e}=this.props,t=e("farm");t[0]?this.setState({selectedFarm:t[0],farmDialogOpen:"true",isNew:!1}):(t[0]={},this.setState({selectedFarm:t[0],farmDialogOpen:"true",isNew:!0}))}render(){const{classes:e,initialState:t,activeSite:a,getFromGlobalState:n,isEntity:r}=this.props,{farmMarkerSelected:l,farmDialogOpen:s,isNew:o,selectedFarm:c,logoURL:d}=this.state,m=t,p=n("blocks"),h=m[0]&&m[0].geoLocation?ee(m[0].geoLocation):{lat:-30.664413,lng:23.758869},u=m[0]&&m[0].geoLocation?16:2;let b="Farm";m[0]&&m[0].entityType&&(b="farm"===m[0].entityType?"Farm":"Entity");const v=m[0]&&m[0].geoLocation?[{position:h,sk:m[0].key,clickable:!0}]:[],y=l?{label:m[0].name,position:h,content:this.getFarmInfo(m[0])}:void 0,f=[];for(const i of p)if(i.paths){let e=i.color,t=1;f.push({label:i.number,sk:i.sk,paths:i.paths,color:i.color,strokeColor:e,strokeWeight:t})}return i.a.createElement(O.a,{elevation:0,className:e.maninSection},s&&i.a.createElement(xl,{handleUpdate:this.handleUpdate,open:s,setClose:this.setClose,isEntity:r,isNew:o,farm:c,activeSite:a,getFromGlobalState:n}),i.a.createElement(B.a,{variant:"subtitle1"},b+" Details",i.a.createElement(I.a,{placement:"top",title:"Edit"},i.a.createElement(E.a,{"aria-label":"Edit",color:"primary",className:e.menuButton,onClick:this.handleClickShowFarm},i.a.createElement(A.a,null)))),m&&m.map(t=>i.a.createElement(O.a,{elevation:0,className:e.parentSection,key:m.sk},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},t.logoKey&&t.logoKey&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},"Logo")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement("div",null,i.a.createElement("br",null),i.a.createElement("img",{alt:"logo",id:"logo",src:d,style:{maxWidth:"150px"}})))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},b+" Name")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.name)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},b+" Short Name")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.shortName)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},"Production Unit Code (PUC)")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.puc)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"}," GLOBALG.A.P. Number")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.gapnum)),t.vatNo&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"}," VAT Number")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.vatNo))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},b+" Physical Address")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.address1),i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.address2),i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.country),i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.province),i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.pCode)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},b+" Contact Number")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.contactNum)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(B.a,{variant:"subtitle2"},b+" Email")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(B.a,{variant:"subtitle1",style:{marginLeft:"10px"}},t.email))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Wn,{center:h,markers:v,polygons:f,infoWindow:y,onCloseInfoWindow:this.onCloseInfoWindow,zoom:u,onClick:this.onMapClick,onSelectMarker:this.onSelectFarmMarker})))))}}var wl=Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(kl);const Tl=[{name:"cultivarType",min:1,max:80},{name:"cultivar",min:1,max:80},{name:"rootStockType",min:1,max:80},{name:"rootStock",min:1,max:80}];class Dl extends n.Component{constructor(e){super(e),this.onCropTypeChange=async(e,t=!0)=>{let{selectedCropType:a,crop:n,variety:i}=this.state;if(a===e.target.value)return!0;const r={...n};a=e.target.value,r.cropType=a,r.genCropSK="";const l={...i};l.cropType="",l.cultivarType="",l.rootStockType="",l.rootStock="",l.cultivar="",this.setState({selectedCropType:a,isLoading:!0,crops:[],cultivars:[],cultivarTypes:[],rootStockTypes:[],rootStockNames:[],variety:l});const{getFromGlobalState:s,setGlobalState:o,setSnack:c}=this.props,d=await La(s,o,c,a);this.setState({changed:t,isLoading:!1,crops:d.crops,crop:r})},this.onCropChange=async(e,t=!0)=>{let{selectedCrop:a,selectedCropType:n,crop:i,variety:r}=this.state;const{getFromGlobalState:l}=this.props;a=e.target.value;const s={...i},o=l("genCrops")[n].find(e=>e.sk===a),c=o?o.name:"";s.genCropSK=a,s.name=c;const d={...r};d.cropName=a,d.cropType=n,d.rootStockType="",d.rootStock="",d.cultivar="",d.cultivarType="";const m=l("cropsDetail")[n].filter(e=>e.cropName===a),p=m&&[...new Set(m.map(e=>e.cultivarType))];this.setState({changed:t,selectedCrop:a,cultivarTypes:p,cultivars:[],rootStockTypes:[],rootStockNames:[],crop:s,variety:d,thisCropDetails:m})},this.onCultivarTypeChange=async(e,t=!0)=>{const{selectedCrop:a,selectedCropType:n,variety:i}=this.state,{getFromGlobalState:r}=this.props,l={...i};l.cultivarType=e.target.value,l.rootStockType="",l.rootStock="",l.cultivar="";const s=r("cropsDetail")[n].filter(e=>e.cropName===a),o=s.filter(e=>e.cultivarType===l.cultivarType),c=o&&[...new Set(o.map(e=>e.cultivar))];this.setState({changed:t,selectedCrop:a,cultivars:c,rootStockTypes:[],rootStockNames:[],variety:l,thisCropDetails:s})},this.onCultivarNameChange=async(e,t=!0)=>{const{selectedCrop:a,selectedCropType:n,variety:i}=this.state,{getFromGlobalState:r}=this.props,l={...i};l.cultivar=e.target.value,l.rootStockType="",l.rootStock="";const s=r("cropsDetail")[n].filter(e=>e.cropName===a),o=s.filter(e=>e.cultivarType===l.cultivarType).filter(e=>e.cultivar===l.cultivar),c=o&&[...new Set(o.map(e=>e.rootStockType))];this.setState({changed:t,selectedCrop:a,rootStockTypes:c,rootStockNames:[],variety:l,thisCropDetails:s})},this.onRootStockTypeChange=async(e,t=!0)=>{const{selectedCrop:a,selectedCropType:n,crop:i,variety:r,cultivars:l}=this.state,{getFromGlobalState:s}=this.props,o={...r};o.rootStockType=e.target.value,o.rootStock="";const c=s("cropsDetail")[n].filter(e=>e.cropName===a),d=c.filter(e=>e.cultivarType===o.cultivarType).filter(e=>e.cultivar===o.cultivar).filter(e=>e.rootStockType===o.rootStockType),m=d&&[...new Set(d.map(e=>e.rootStock))];this.setState({changed:t,selectedCrop:a,rootStockNames:m,variety:o,thisCropDetails:c})},this.findCropDetail=()=>{const{crop:e,variety:t,thisCropDetails:a}=this.state,{getFromGlobalState:n}=this.props,i={},r=a.filter(e=>e.cultivarType===t.cultivarType).filter(e=>e.cultivar===t.cultivar).filter(e=>e.rootStockType===t.rootStockType).find(e=>e.rootStock===t.rootStock);if(r){const t=[];let a={};const l=n("crops"),s=l.findIndex(t=>t.sk===e.genCropSK);-1===s?(a={...e},t.push({...a}),a.varieties=[],i.crop=a):(a={...l[s]},a.varieties||(a.varieties=[]),i.crop=a);if(-1===a.varieties.findIndex(e=>e.sk===r.sk)){const e={};e.genVarietySK=r.sk,e.sk=`${a.sk}_setchild_${Rt.a.v1()}`,e.type="gen_varieties",t.push(e),a.varieties.push(r),i.variety={...e},i.crop=a}return{retVal:i,batchInserts:t}}return{retVal:null,batchInserts:[],error:!0,errorMsg:"Could not find_"+JSON.stringify(t)}},this.onChange=(e,t=!0)=>{const{variety:a}=this.state,n={...a};n[e.target.id]=e.target.value,this.setState({variety:n,changed:t})},this.handleBlur=e=>this.validateField(e.target.id,Tl),this.handleChange=e=>{const t={...this.state.crop};t[e.target.id]=e.target.value,this.setState({crop:t,changed:!0})},this.handleUpdate=async()=>{},this.handleDeletePreExecute=async(e,t)=>{const{getFromGlobalState:a,setGlobalState:n,setSnack:i}=this.props;try{const t=e.variety.sk,i=e.crop.sk,r=[...a("genVarieties")],l=[...a("myGenCrops")],s=r.findIndex(e=>e.genVarietySK===t),o=l.findIndex(e=>e.genCropSK===i),c=a("activeSite");await wa({sk:r[s].sk,archiveName:"trash",type:"gen_varieties",activeTenant:c});const d=[...a("crops")],m=d.findIndex(e=>e.sk===i);if(-1!==m){const e=d[m].varieties.findIndex(e=>e.sk===t);-1!==e&&(d[m].varieties.splice(e,1),r.splice(s,1),0===d[m].varieties.length&&(await wa({sk:l[o].sk,archiveName:"trash",type:"gen_crops",activeTenant:c}),d.splice(m,1),l.splice(o,1))),n({crops:d,myGenCrops:l,genVarieties:r})}return{status:!0}}catch(r){return i({open:!0,variant:"error",messageText:Pa(r)}),{status:!1}}},this.handleDelete=async()=>{},this.handlePreExecute=async(e,t)=>{if(t)return{status:!0};const{getFromGlobalState:a,setGlobalState:n}=this.props,i=this.findCropDetail();try{if(i.error)return this.props.setSnack({open:!0,variant:"error",messageText:i.errorMsg}),{status:!1};if(!i||0===i.batchInserts.length)return{status:!1,errorMSG:"This crop already exists on your farm"};const e={items:i.batchInserts};e.activeTenant=this.props.getFromGlobalState("activeSite"),e.type="batchupload";const t=await fa(this.props.getFromGlobalState("currentUser").username,"calls",ua(e,!0),this.props.getFromGlobalState("activeSite"));if(t.status&&i.retVal.crop){const e=[...a("crops")],t=e.findIndex(e=>e.sk===i.retVal.crop.sk);-1===t?e.push(i.retVal.crop):e[t]=i.retVal.crop,n({crops:e})}return t}catch(r){this.props.setSnack({open:!0,variant:"error",messageText:Pa(r)})}},this.state={isLoading:!1,isNew:this.props.isNew,crop:{},variety:{},errors:{count:0},changed:!1,selectedCropType:"",selectedCrop:"",crops:[],thisCropDetails:[],cultivarTypes:[],cultivars:[],rootStockTypes:[],rootStockNames:[],updateObj:null,cropTypes:[]}}async componentDidMount(){const{getFromGlobalState:e}=this.props,t=e("cropTypesSetting"),a=t&&t.filter(e=>!0===e.enabled);if(this.props.isNew){const e={};e.sk="init_setting_"+Rt.a.v1(),e.type="gen_crops";const t={};this.setState({crop:e,variety:t,cropTypes:a})}else{this.setState({isLoading:!1});const{crop:t,variety:a}=this.props,n={...a},i=e("cropTypesSetting"),r=i&&i.filter(e=>!0===e.enabled),l=t.cropType?t.cropType:t.sk.substring(0,t.sk.indexOf("_setchild_")),s=r.find(e=>e.sk===l);await this.onCropTypeChange({target:{value:s.sk}},!1),await this.onCropChange({target:{value:t.sk}},!1),await this.onCultivarTypeChange({target:{value:n.cultivarType}},!1),await this.onCultivarNameChange({target:{value:n.cultivar}},!1),await this.onRootStockTypeChange({target:{value:n.rootStockType}},!1),this.onChange({target:{value:n.rootStock,id:"rootStock"}},!1),this.setState({cropTypes:r,crop:t,variety:n}),this.setState({isLoading:!1})}}validateField(e,t){const a=jn(e,this.state.variety,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{open:e,isNew:t,setClose:a,getFromGlobalState:n,classes:r}=this.props,{crop:l,errors:s,variety:o,selectedCropType:c,crops:d,cultivarTypes:m,cultivars:p,rootStockTypes:h,rootStockNames:u,isLoading:b,cropTypes:v}=this.state,y=$n(o,Tl);return i.a.createElement(Ia,{open:e,dialogObject:{variety:o,crop:l},setClose:a,allowDelete:!b,isNew:t,handleDeletePreExecute:!0,handleDeletePreExecuteOnly:!0,handleDeletePreExecute:this.handleDeletePreExecute.bind(this),handleDeleteDialogObject:this.handleDelete.bind(this),handleUpdateDialogObject:this.handleUpdate.bind(this),skPrimary:"init_setting_",dynamoType:"crops",changed:this.state.changed,valid:y,noServerInteraction:!0,preExecuteOnly:!0,handlePreExecute:this.handlePreExecute.bind(this),newTitle:"New Crop",title:l.name,getFromGlobalState:n},i.a.createElement(N,{isloading:b},i.a.createElement(g.a,{container:!0,className:r.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Crop type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,disabled:v&&0===v.length,displayEmpty:!0,value:c,onChange:this.onCropTypeChange,inputProps:{name:"cropType",id:"cropType"}},i.a.createElement("option",{value:""}),v&&v.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Crops"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:d&&0===d.length,value:l.genCropSK,onChange:this.onCropChange,inputProps:{name:"crop",id:"crop"}},i.a.createElement("option",{value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Cultivar type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:m&&0===m.length,value:o.cultivarType,onChange:this.onCultivarTypeChange,inputProps:{name:"cultivarType",id:"cultivarType"}},i.a.createElement("option",{value:""}),m&&m.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Cultivar name"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:p&&0===p.length,value:o.cultivar,onChange:this.onCultivarNameChange,inputProps:{name:"cultivar",id:"cultivar"}},i.a.createElement("option",{value:""}),p&&p.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Rootstock type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:h&&0===h.length,value:o.rootStockType,onChange:this.onRootStockTypeChange,inputProps:{name:"rootStockType",id:"rootStockType"}},i.a.createElement("option",{value:""}),h&&h.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:r.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Rootstock name"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:u&&0===u.length,value:o.rootStock,onChange:this.onChange,inputProps:{name:"rootStock",id:"rootStock"}},i.a.createElement("option",{value:""}),u&&u.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))))))}}var Pl=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Dl);const Fl=[{name:"cultivar",min:1,max:40}];class Nl extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Fl),this.handleChange=e=>{let t={...this.state.variety};t[e.target.id]=e.target.value,this.setState({variety:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,variety:{},errors:{count:0},varieties:[],changed:!1}}componentDidMount(){this.props.isNew?this.setState({variety:{}}):this.setState({variety:this.props.variety})}validateField(e,t){let a=jn(e,this.state.variety,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,parentSK:l,parent:s,getFromGlobalState:o}=this.props,{variety:c,errors:d}=this.state,m=$n(c,Fl);return i.a.createElement(Ia,{open:t,dialogObject:c,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_setchild_",dynamoType:"varieties",valid:m,disableActions:c.isGeneral,changed:this.state.changed,newTitle:"New Cultivar",title:c.cultivar?c.cultivar:"",subTitle:s?s.name:"",parentKey:l,getFromGlobalState:o},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"cultivar",label:"Cultivar",name:"cultivar",value:c.cultivar,onChange:this.handleChange,onBlur:this.handleBlur,error:!!d.cultivar||void 0,helperText:d.cultivar}))}}var Bl=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Nl);const Ll=[{id:"cropType",numeric:!1,disablePadding:!0,label:"Crop type"},{id:"name",numeric:!1,disablePadding:!1,label:"Crop"},{id:"cultivarType",numeric:!1,disablePadding:!1,label:"Cultivar type"},{id:"variety",numeric:!1,disablePadding:!1,label:"Cultivar name"},{id:"rootStockType",numeric:!1,disablePadding:!1,label:"Rootstock type"},{id:"rootStock",numeric:!1,disablePadding:!1,label:"Rootstock"}],Al=[{id:"cropType",combine:[{id:"cropType",opacity:1},{id:"name",opacity:.6},{id:"varietyCombo",opacity:.4}],numeric:!1,disablePadding:!0,label:"Crop",maxWidth:"100px"},{id:"rootStock",numeric:!1,disablePadding:!1,label:"Rootstock"}];class Ol extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({cropDialogOpen:!0})},this.handleBlur=()=>{},this.handleClickAddNewVariety=(e,t)=>{t.stopPropagation(),this.setState({varietyDialogOpen:!0,isNew:!0,selectedCropSK:e.sk,selectedCrop:e,selectedVariety:{}})},this.handleClickShowVariety=(e,t)=>{const{getFromGlobalState:a}=this.props,n=a("crops").find(t=>t.sk===e),i=n.varieties.find(e=>e.sk===t);this.setState({selectedCrop:n,selectedVariety:i,selectedCropSK:n.sk}),this.setState({varietyDialogOpen:!0,isNew:!1})},this.setClose=this.setClose.bind(this),this.setCloseVariety=this.setCloseVariety.bind(this),this.handleClickShowCrop=this.handleClickShowCrop.bind(this),this.handleClickAdd=this.handleClickAdd.bind(this),this.handleUpdateVariety=this.handleUpdateVariety.bind(this),this.handleUpdate=this.handleUpdate.bind(this),this.state={selectedCrop:null,selectedVariety:null,selectedCropOb:null,isNew:!1,cropDialogOpen:!1,varietyDialogOpen:!1}}handleClickAdd(){this.setState({cropDialogOpen:!0,isNew:!0,selectedCrop:{}})}handleClickShowCrop(e,t,a){const{getFromGlobalState:n}=this.props;if(t){if(a){const e=n("crops").find(e=>e.sk===t),i=e.varieties.find(e=>e.sk===a);this.setState({selectedCropOb:e,selectedCrop:t,selectedVariety:i,selectedCropSK:e.sk}),this.setState({cropDialogOpen:!0,isNew:!1})}}else{const e=n("crops").find(e=>e.sk===a);this.setState({selectedCrop:e,selectedCropSK:a,cropDialogOpen:"true",isNew:!1})}}handleClickEdit(){this.setState({cropDialogOpen:!0,isNew:!0})}handleUpdate(e){const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("crops").findIndex(t=>t.sk===e.sk);if(-1===n){const n=t("crops");n.push(e),a({crops:n})}else{const i=t("crops");i[n]=e,a({crops:i})}}handleUpdateVariety(e,t){const{getFromGlobalState:a,setGlobalState:n}=this.props,i=a("crops").findIndex(e=>e.sk===t);if(-1===i)return void alert("impossible - we don't have this crop!");const r=a("crops"),{varieties:l}=r[i];l||(r[i].varieties=[]);const s=r?r[i].varieties.findIndex(t=>t.sk===e.sk):-1;-1===s?(r[i].varieties.push(e),n({crops:r})):(r[i].varieties[s]=e,n({crops:r}))}setClose(){this.setState({cropDialogOpen:!1})}setCloseVariety(){this.setState({varietyDialogOpen:!1})}generateRows(e){const t=[];if(!e)return t;const{getFromGlobalState:a}=this.props,n=a("cropTypesSetting");return n||0!==n.length?(e.forEach(e=>{const a=e.cropType?e.cropType:e.sk.substring(0,e.sk.indexOf("_setchild_")),i=n.find(e=>e.sk===a),r=i?i.name:"";e.varieties&&e.varieties.forEach(a=>{const n=`${a.cultivarType} ${a.cultivar} ${a.rootStockType}`;t.push({parentSK:e.sk,sk:a.sk,varietyCombo:n,cropType:r,name:e.name,cultivarType:a.cultivarType,rootStockType:a.rootStockType,rootStock:a.rootStock,variety:a.cultivar})})}),t):t}render(){const{classes:e,getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props,{selectedCropOb:r,selectedVariety:l,cropDialogOpen:s,isNew:o,varietyDialogOpen:c,selectedCropSK:d,selectedCrop:m}=this.state,p=t("crops"),h=t("isMobile"),g=this.generateRows(p),u=h?Al:Ll,b=t("userDetail");return i.a.createElement(O.a,{elevation:0,className:e.mainSection},s&&i.a.createElement(Pl,{handleUpdate:this.handleUpdate,open:s,setClose:this.setClose,isNew:o,getFromGlobalState:t,setGlobalState:a,setSnack:n,crop:r,variety:l}),c&&i.a.createElement(Bl,{handleUpdate:this.handleUpdateVariety,open:c,setClose:this.setCloseVariety,isNew:o,variety:l,getFromGlobalState:t,parentSK:d,parent:m}),i.a.createElement(Me,{heading:"Crops",displayToolbar:!0,hideHeading:!0,id:"cropTable",noPagination:!0,rows:g,headCells:u,handleSelect:this.handleClickShowCrop,handleAddItem:b&&b.rights&&!b.rights.readOnly?this.handleClickAdd:null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,padFirstCol:"5px",clean:!0,dense:!0,parent:!0,ancestorsInRow:!0,parentSK:"parentSK",maxHeight:"350px",selectedRow:l?l.sk:""}))}}var Il=Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Ol),Gl=a(1775),Rl=a(438),Ul=a.n(Rl);const Ml=Object(z.a)(e=>({root:{display:"flex",alignItems:"center",maxWidth:300},icon:{marginRight:e.spacing(1)}}));function Wl(e){const t=Ml(),a=t=>{const{onInputChange:a}=e;a&&a(t)},{options:n,label:r}=e;return i.a.createElement("div",{className:t.root},i.a.createElement(Gl.a,{options:n,fullWidth:!0,getOptionLabel:e=>e.label?e.label:"",onChange:(t,a)=>{const{onChange:n}=e;n&&n(a)},renderInput:e=>i.a.createElement(zt.a,Object.assign({},e,{label:r,fullWidth:!0,onChange:a}))}),i.a.createElement(Ul.a,{className:t.icon}))}Wl.defaultProps={label:"Search"};var zl=Wl;class Kl extends n.Component{constructor(e){super(e),this.handleNameBlur=e=>{const{chemical:t,errors:a}=this.state,{ppps:n,requiredFields:i}=this.props,r=jn(e.target.id,t,i);if(r.isValid&&n){-1!==n.filter(e=>e.sk!==t.sk).findIndex(t=>t.name===e.target.value)?(r.isValid=!1,r.msg="Name already exists"):(r.isValid=!0,r.msg="")}const l={...a};l[e.target.id]=r.msg,this.setState({errors:l})},this.handleInputChange=e=>{const{getFromGlobalState:t,setSnack:a,ppps:n}=this.props,i=t("activeSite");e.target.value.length>0?this.setState({searchString:e.target.value,isSearching:!0},()=>{xa(i,"startswith","genPPPs",encodeURIComponent(this.state.searchString)).then(e=>{const t=e.filter(e=>!e.isDisabled&&!n.find(t=>t.loadedFromSettingSK&&t.loadedFromSettingSK===e.sk));this.setState({searchedPPPS:t,isSearching:!1})}).catch(e=>{a({open:!0,variant:"error",messageText:Pa(e)})})}):this.setState({searchedPPPS:[{sk:"",name:"Type the first letter to search"}]})},this.handleGenPPPChange=e=>{const{searchedPPPS:t}=this.state;if(e&&e.value){const a=t.find(t=>t.sk===e.value),n={...a};delete n.sk,delete n.isGeneral,n.loadedFromSettingSK=a.sk,this.setState({chemical:n,selectedGenPPP:a})}},this.handleBlur=e=>{const{requiredFields:t}=this.props;this.validateField(e.target.id,t)},this.handleChange=e=>{const t={...this.state.chemical};t[e.target.id]=e.target.value,this.setState({chemical:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.chemical};a[e]=t.target.value,this.setState({chemical:a,changed:!0})},this.handleCheckChange=e=>{const{chemical:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({chemical:a,changed:!0})},this.handleToggle=e=>{const t=this.state.chemical.allowedVarieties.indexOf(e),a={...this.state.chemical};-1===t?a.allowedVarieties.push(e):a.allowedVarieties.splice(t,1),this.setState({chemical:a,changed:!0})},this.getGenPPPsOptions=e=>e.map(e=>{const t={};return t.value=e.sk,t.key=e.sk,t.label=e.name,t}),this.getOptions=e=>{const{searchString:t,isSearching:a}=this.state;return 0===t.length?[{value:"",label:"Type to search",key:"type"}]:a?[{value:"",label:"Searching...",key:"searching"}]:a||0!==e.length?e:[{value:"",label:"No results",key:"searching"}]},this.state={chemical:null,errors:{count:0},changed:!1,searchString:"",searchedPPPS:[],isSearching:!1,selectedGenPPP:null}}componentDidMount(){if(this.props.isNew)this.setState({chemical:{chemcrops:[]}});else{const{chemical:e}=this.props;e.chemcrops||(e.chemcrops=[]),this.setState({chemical:e})}}validateField(e){const{requiredFields:t}=this.props,a=jn(e,this.state.chemical,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,getFromGlobalState:l,autoSearch:s,dynamoType:o,skPrimary:c,requiredFields:d}=this.props,{chemical:m,errors:p,searchedPPPS:h,selectedGenPPP:u,isSearching:b}=this.state,v=h&&h.length?this.getGenPPPsOptions(h):[],y=u||m&&m.loadedFromSettingSK,f=$n(m,d)&&(!p.name||""===p.name);return m?i.a.createElement(Ia,{open:t,dialogObject:m,setClose:n,isNew:a,changed:this.state.changed,handleUpdateDialogObject:r.bind(this),skPrimary:c,dynamoType:o,valid:f,newTitle:"New Plant Protection",title:m&&m.name?m.name:"",getFromGlobalState:l},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:m.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),s&&a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zl,{options:this.getOptions(v),onInputChange:this.handleInputChange,onChange:this.handleGenPPPChange,label:b?"Searching...":"Search for Plant Protection Product"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Trade Name",name:"name",disabled:y,InputLabelProps:{shrink:!0},value:m&&m.name,onChange:this.handleChange,onBlur:this.handleNameBlur,error:!!p.name||void 0,helperText:p.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"registrationNumber",label:"Registration Number",name:"registrationNumber",disabled:y,InputLabelProps:{shrink:!0},value:m&&m.registrationNumber,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.registrationNumber||void 0,helperText:p.registrationNumber})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"registrationHolder",label:"Registration Holder",name:"registrationHolder",disabled:y,InputLabelProps:{shrink:!0},value:m&&m.registrationHolder,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.registrationHolder||void 0,helperText:p.registrationHolder})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,multiline:!0,fullWidth:!0,id:"aIngredient",label:"Active Ingredient",disabled:y,InputLabelProps:{shrink:!0},name:"aIngredient",value:m.aIngredient,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.aIngredient||void 0,helperText:p.aIngredient})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"supplier",label:"Supplier",name:"supplier",value:m.supplier,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.supplier||void 0,helperText:p.supplier})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"advisor",label:"Advisor Name and Surname",name:"advisor",value:m.advisor,onChange:this.handleChange,onBlur:this.handleBlur,error:!!p.advisor||void 0,helperText:p.advisor})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{required:!0},"Dilution unit"),i.a.createElement(xn.a,{"aria-label":"unit",name:"unit",id:"unit",className:e.group,value:null===m||void 0===m?void 0:m.unit,onChange:this.handleRadioChange.bind(this,"unit")},i.a.createElement(Fe.a,{value:"kg",control:i.a.createElement(Cn.a,null),label:"kg (granular)"}),i.a.createElement(Fe.a,{value:"liter",control:i.a.createElement(Cn.a,null),label:"liter (liquid)"}),(null===p||void 0===p?void 0:p.unit)&&i.a.createElement(En.a,{className:e.helperText},null===p||void 0===p?void 0:p.unit)))))):null}}Kl.defaultProps={dynamoType:"chemicals",skPrimary:"init_setting_",autoSearch:!1,searchedPPPS:[],requiredFields:[{name:"name",min:1,max:40},{name:"aIngredient",min:1,max:1e3},{name:"registrationNumber",min:1,max:40},{name:"registrationHolder",min:1,max:40}]};var Hl=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(Kl);const ql=[{name:"crop",min:1,max:100}];class Vl extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,ql),this.handleRadioChange=(e,t)=>{const a={...this.state.chemCrop};a[e]=t.target.value,this.setState({chemCrop:a,changed:!0})},this.handleReentryOverride=(e,t)=>{const a={...this.state.chemCrop},n=a.targets.findIndex(e=>e.sk===t);-1!==n&&(Object.hasOwn(a.targets[n],"reentryOverride")?a.targets[n].reentryOverride=!a.targets[n].reentryOverride:a.targets[n].reentryOverride=e.target.checked),this.setState({chemCrop:a,changed:!0})},this.handleToggle=(e,t,a)=>{const n={...this.state.chemCrop};n.targets||(n.targets=[]);const i=n.targets.findIndex(t=>t.sk===e);-1===i?n.targets.push({sk:e}):n.targets.splice(i,1),this.setState({chemCrop:n,changed:!0})},this.handleTargetChange=(e,t)=>{const a={...this.state.chemCrop};a.targets||(a.targets=[]);const n=a.targets.findIndex(e=>e.sk===t);-1!==n&&(a.targets[n][e.target.id]=e.target.value),this.setState({chemCrop:a,changed:!0})},this.handleChange=e=>{const t={...this.state.chemCrop};t[e.target.id]=e.target.value,this.setState({chemCrop:t,changed:!0})},this.handleCheckChange=e=>{const{chemCrop:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({chemCrop:a,changed:!0})},this.handleExpand=e=>{const{expandedTarget:t}=this.state;t!==e?this.setState({expandedTarget:e}):this.setState({expandedTarget:""})},this.state={isloading:!1,isNew:this.props.isNew,chemCrop:{},errors:{count:0},varieties:[],changed:!1,expandedTarget:""}}componentDidMount(){this.props.isNew?this.setState({chemCrop:{reentryOverride:!1}}):this.setState({chemCrop:this.props.chemCrop})}validateField(e,t){const a=jn(e,this.state.chemCrop,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,parent:l,metaData:s,getFromGlobalState:o}=this.props,{chemCrop:c,errors:d,expandedTarget:m}=this.state,p=s.filteredCrops,h=$n(c,ql);return i.a.createElement(Ia,{open:t,dialogObject:c,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_setchild_",dynamoType:"chemcrops",valid:h,changed:this.state.changed,newTitle:"New Crop",subTitle:""+l.name,title:!a&&c.crop?ae(c.crop,p,"name"):"",parentKey:l.sk,getFromGlobalState:o},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:c.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Crop"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,value:c.crop,onChange:this.handleChange,onBlur:this.handleBlur,error:!!d.crop||void 0,inputProps:{name:"crop",id:"crop"}},i.a.createElement("option",{value:""}),p&&p.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),d.crop&&i.a.createElement(En.a,{className:e.helperText},d.crop)))))}}var jl=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(Vl);const $l=[{name:"targetType",min:1,max:100},{name:"target",min:1,max:100},{name:"phi",min:1,max:100},{name:"dosage",min:1,max:100},{name:"dosageUnit",min:1,max:100},{name:"reentry",min:0,max:1e3,type:"number",condition:{name:"reentryOverride",value:!1}}];class Yl extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,$l),this.handleRadioChange=(e,t)=>{const a={...this.state.chemCropTarget};a[e]=t.target.value,this.setState({chemCrop:a,changed:!0})},this.handleChange=e=>{const t={...this.state.chemCropTarget};t[e.target.id]=e.target.value,this.setState({chemCropTarget:t,changed:!0})},this.handleCheckboxChange=e=>{const t={...this.state.chemCropTarget};t[e.target.id]=e.target.checked,this.setState({chemCropTarget:t,changed:!0})},this.filterByCrop=(e,t)=>{if(!e)return[];let a=e.filter(e=>"Yes"===e.cropSpecific&&e.observableOnSk===t);return a=a.concat(e.filter(e=>"No"===e.cropSpecific)),a},this.state={isloading:!1,isNew:this.props.isNew,chemCropTarget:{},errors:{count:0},changed:!1,expandedTarget:""}}componentDidMount(){this.props.isNew?this.setState({chemCropTarget:{reentryOverride:!1}}):this.setState({chemCropTarget:this.props.chemCropTarget})}validateField(e,t){const a=jn(e,this.state.chemCropTarget,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,chemical:n,setClose:r,handleUpdate:l,parent:s,metaData:o,getFromGlobalState:c,crop:d,alreadySet:m}=this.props,{chemCropTarget:p,errors:h}=this.state,u=function(e,t){if(!e)return null;const a=[],n=t("targetsTypesSetting");for(let i=0;ie.targetType===t);l&&l.length&&a.push({name:t,sk:r,targetsList:l})}return a}(st(o.monitorings,c),c),b=p.targetType?u.find(e=>e.sk===p.targetType).targetsList:[],v=this.filterByCrop(b,d),y=a?v.filter(e=>!m.find(t=>t.targetSK===e.sk)&&"Yes"!==e.isDisabled):v,f=ae(n.sk,c("chemicals")),E=$n(p,$l);return i.a.createElement(Ia,{open:t,dialogObject:p,setClose:r,isNew:a,handleUpdateDialogObject:l.bind(this),skPrimary:"_setchild_",dynamoType:"chemcropsTargets",valid:E,changed:this.state.changed,newTitle:"New Target",subTitle:f,title:!a&&ae(p.target,b),parentKey:s.sk,getFromGlobalState:c},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Target type"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,value:p.targetType,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.targetType||void 0,inputProps:{name:"targetType",id:"targetType"}},i.a.createElement("option",{value:""}),u&&u.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),h.targetType&&i.a.createElement(En.a,{className:e.helperText},h.targetType))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Target"),i.a.createElement(Sn.a,{native:!0,required:!0,disabled:!p.targetType,displayEmpty:!0,value:p.target,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.target||void 0,inputProps:{name:"target",id:"target"}},i.a.createElement("option",{value:""}),y&&y.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),h.target&&i.a.createElement(En.a,{className:e.helperText},h.target))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",disabled:p.reentryOverride,type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"days"),min:"0.00001",step:"any"},id:"reentry",label:"Re-entry Period",InputLabelProps:{shrink:!0},name:"reentry",value:p.reentry,onChange:e=>this.handleChange(e),onBlur:this.handleBlur})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"reentryOverride",label:"or deposit dry",labelPlacement:"end",control:i.a.createElement(xe.a,{color:"secondary",name:"reentryOverride",id:"reentryOverride",checked:p.reentryOverride,onClick:e=>this.handleCheckboxChange(e)})})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",id:"phi",label:"Pre-harvest interval (PHI)",name:"phi",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},"days"),min:"0.00001",step:"any"},InputLabelProps:{shrink:!0},value:p.phi,onChange:e=>this.handleChange(e)})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,id:"dosage",label:"Dosage",name:"valperUnit",type:"number",value:p.dosage,onChange:e=>this.handleChange(e),InputLabelProps:{shrink:!0}})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cdosagerop"},"Dosage Unit"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,value:p.dosageUnit,onChange:e=>this.handleChange(e),onBlur:this.handleBlur,error:!!h.dosageUnit||void 0,inputProps:{name:"dosageUnit",id:"dosageUnit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"ml/ha"},"ml/ha"),i.a.createElement("option",{value:"L/ha"},"L/ha"),i.a.createElement("option",{value:"g/ha"},"g/ha"),i.a.createElement("option",{value:"kg/ha"},"kg/ha"),i.a.createElement("option",{value:"/ha"},"/ha"),i.a.createElement("option",{value:"/cluster"},"/cluster"),i.a.createElement("option",{value:"/trap"},"/trap"),i.a.createElement("option",{value:"g/L"},"g/L"),i.a.createElement("option",{value:"g/100L"},"g/100L"),i.a.createElement("option",{value:"ml/100L"},"ml/100L"),i.a.createElement("option",{value:"L/100L"},"L/100L"),i.a.createElement("option",{value:"/m2"},"/m2"),i.a.createElement("option",{value:"ml/plant"},"ml/plant"),i.a.createElement("option",{value:"g/plant"},"g/plant")),h.dosageUnit&&i.a.createElement(En.a,{className:e.helperText},h.dosageUnit)))))}}var _l=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(Yl);const Zl=[{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"},{id:"name",numeric:!1,disablePadding:!0,label:"Name"}],Jl=[{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"},{id:"name",numeric:!1,disablePadding:!0,label:"Name"}],Ql=[{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"},{id:"name",numeric:!1,disablePadding:!0,label:"Name"}];class Xl extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({chemicalDetailOpen:!0,isNew:!1})},this.handleBlur=e=>{},this.handleClickAddNewChemicalCrop=e=>{this.setState({chemicalCropDialogOpen:!0,isNew:!0,selectedChemicalSK:e,selectedChemicalCrop:null,selectedChemicalCropTarget:null})},this.handleClickAddNewChemicalCropTarget=()=>{this.setState({chemicalCropTargetDialogOpen:!0,isNew:!0,selectedChemicalCropTarget:{}})},this.handleClickShowChemicalCrop=(e,t,a)=>{this.setState({selectedChemicalCropTarget:null,chemicalCropDialogOpen:!0,isNew:!1})},this.handleSelectChemicalCrop=(e,t,a)=>{const{selectedChemical:n}=this.state,i=n.chemcrops.find(e=>e.sk===a);this.setState({selectedChemicalCrop:i})},this.handleClickShowChemicalCropTarget=(e,t,a)=>{this.setState({chemicalCropTargetDialogOpen:!0,isNew:!1})},this.handleSelectChemicalCropTarget=(e,t,a)=>{const{selectedChemicalCrop:n}=this.state,i=n.targets.find(e=>e.sk===a);this.setState({selectedChemicalCropTarget:i})},this.handleClickShowChemical=this.handleClickShowChemical.bind(this),this.handleClickAddChemical=this.handleClickAddChemical.bind(this),this.handleClickSelectChemical=this.handleClickSelectChemical.bind(this),this.state={expandedSetting:"",selectedChemical:null,selectedChemicalCrop:null,modalObject:null,isNew:!1,chemicalDetailOpen:!1,chemicalCropDialogOpen:!1,errors:{},openModal:"",chemicalCropTargetDialogOpen:!1,selectedChemicalCropTarget:null}}handleClickAddChemical(){this.setState({chemicalDetailOpen:!0,isNew:!0,selectedChemical:null,selectedChemicalCrop:null,selectedChemicalCropTarget:null})}handleClickShowChemical(e,t,a){this.setState({chemicalDetailOpen:"true",isNew:!1})}handleClickSelectChemical(e,t,a){const n=this.props.getFromGlobalState("chemicals").find(e=>e.sk===a);this.setState({selectedChemical:n,selectedChemicalCrop:null,selectedChemicalCropTarget:null,isNew:!1})}handleClickEdit(){this.setState({chemicalDetailOpen:!0,isNew:!0})}setClose(){this.setState({chemicalDetailOpen:!1})}setCloseVariety(){this.setState({chemicalCropDialogOpen:!1})}setCloseChemicalCropTarget(){this.setState({chemicalCropTargetDialogOpen:!1})}handleUpdate(e){const t=this.props.getFromGlobalState("chemicals").findIndex(t=>t.sk===e.sk);if(-1===t){const t=this.props.getFromGlobalState("chemicals");t.push(e),this.props.setGlobalState({chemicals:t})}else{const a=this.props.getFromGlobalState("chemicals");a[t]=e,this.props.setGlobalState({chemicals:a})}this.setState({selectedChemicalCropTarget:null,selectedChemicalCrop:null,selectedChemical:e})}handleUpdateChemicalCropTarget(e){const{setGlobalState:t,getFromGlobalState:a}=this.props,{selectedChemicalCrop:n,selectedChemical:i}=this.state,r=a("chemicals"),l=r.find(e=>e.sk===i.sk).chemcrops.find(e=>e.sk===n.sk);l.targets||(l.targets=[]);const s=l.targets.findIndex(t=>e.sk===t.sk);-1===s?l.targets.push(e):l.targets[s]={...e},t({chemicals:r}),this.setState({selectedChemicalCropTarget:e})}handleUpdateChemicalCrop(e,t){const a=this.props.getFromGlobalState("chemicals").findIndex(e=>e.sk===t);if(-1===a)return void alert("impossible - we don't have this crop!");const n=this.props.getFromGlobalState("chemicals");n[a].chemcrops||(n[a].chemcrops=[]);const i=n?n[a].chemcrops.findIndex(t=>t.sk===e.sk):-1;-1===i?(n[a].chemcrops.push(e),this.props.setGlobalState({chemicals:n,chemicalCropDialogOpen:!1})):(n[a].chemcrops[i]={...e},this.props.setGlobalState({chemicals:n,chemicalCropDialogOpen:!1})),this.setState({selectedChemicalCropTarget:null,selectedChemicalCrop:e})}getCropsNotAddedYet(e,t,a,n){if(!t)return[];t.chemcrops||(t.chemcrops=[]);const i=t.chemcrops.map(e=>e.crop),r=e.filter(e=>!i.includes(e.sk));if(!a){const t=e.filter(e=>e.sk===n.crop);t&&r.push(t[0])}return r}render(){const{classes:e,initialState:t,getFromGlobalState:a}=this.props,{selectedChemical:n,selectedChemicalCrop:r,chemicalCropDialogOpen:l,chemicalDetailOpen:s,selectedChemicalCropTarget:o,chemicalCropTargetDialogOpen:c}=this.state,d=t,m=Zl,p=function(e){if(!e)return[];const t=[];for(let a=0;a{const t={};return t.sk=e.sk,t.name=e.targetDetail.name,t.targetSK=e.targetDetail.sk,t}):[]}(t("monitorings"));for(let i=0;e.targets&&i({root:{flexGrow:1},aligner:{},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Xl);const ts=[{name:"name",min:3,max:1e3},{name:"unit",min:1,max:1e3},{name:"nitrogenP",min:0,max:1e3,type:"number"},{name:"nitrogenG",min:0,max:1e3,type:"number"},{name:"phosphorusP",min:0,max:1e3,type:"number"},{name:"phosphorusG",min:0,max:1e3,type:"number"},{name:"potassiumP",min:0,max:1e3,type:"number"},{name:"potassiumG",min:0,max:1e3,type:"number"},{name:"caP",min:0,max:1e3,type:"number"},{name:"caG",min:0,max:1e3,type:"number"},{name:"mgP",min:0,max:1e3,type:"number"},{name:"mgG",min:0,max:1e3,type:"number"},{name:"sP",min:0,max:1e3,type:"number"},{name:"sG",min:0,max:1e3,type:"number"},{name:"bP",min:0,max:1e3,type:"number"},{name:"bG",min:0,max:1e3,type:"number"},{name:"feP",min:0,max:1e3,type:"number"},{name:"feG",min:0,max:1e3,type:"number"},{name:"mnP",min:0,max:1e3,type:"number"},{name:"mnG",min:0,max:1e3,type:"number"},{name:"znP",min:0,max:1e3,type:"number"},{name:"znG",min:0,max:1e3,type:"number"},{name:"cuP",min:0,max:1e3,type:"number"},{name:"cuG",min:0,max:1e3,type:"number"},{name:"moP",min:0,max:1e3,type:"number"},{name:"moG",min:0,max:1e3,type:"number"}];class as extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,ts),this.handleInputChange=e=>{const{getFromGlobalState:t,setSnack:a,fertilisers:n}=this.props,i=t("activeSite");e.target.value.length>0?this.setState({searchString:e.target.value,isSearching:!0},()=>{xa(i,"startswith","genFertilisers",encodeURIComponent(this.state.searchString)).then(e=>{const t=e.filter(e=>!e.isDisabled&&!n.find(t=>t.loadedFromSettingSK&&t.loadedFromSettingSK===e.sk));this.setState({searchedFertilisers:t,isSearching:!1})}).catch(e=>{a({open:!0,variant:"error",messageText:Pa(e)})})}):this.setState({searchedFertilisers:[{sk:"",name:"Type the first letter to search"}]})},this.handleNameBlur=e=>{const{fertiliser:t,errors:a}=this.state,{fertilisers:n}=this.props,i=jn(e.target.id,t,ts);if(i.isValid&&n){-1!==n.filter(e=>e.sk!==t.sk).findIndex(t=>t.name===e.target.value)?(i.isValid=!1,i.msg="Name already exists"):(i.isValid=!0,i.msg="")}const r={...a};r[e.target.id]=i.msg,this.setState({errors:r})},this.handleChange=e=>{const t={...this.state.fertiliser};t[e.target.id]=e.target.value,this.setState({fertiliser:t,changed:!0})},this.handleGenFertChange=e=>{const{searchedFertilisers:t}=this.state;if(console.log("event value",e),e&&e.value){const a=t.find(t=>t.sk===e.value),n={...a};delete n.sk,delete n.isGeneral,n.loadedFromSettingSK=a.sk,this.setState({fertiliser:n,selectedGenFertiliser:a})}},this.handleCheckChange=e=>{const{fertiliser:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({fertiliser:a,changed:!0})},this.handleChangeP=e=>{const t={...this.state.fertiliser};t[e.target.id]=e.target.value&&e.target.value.length&&e.target.value;t[e.target.id.replace("P","G")]=parseFloat(1e3*e.target.value/100).toFixed(2),this.setState({fertiliser:t,changed:!0})},this.handleChangeG=e=>{const t={...this.state.fertiliser};t[e.target.id]=e.target.value&&e.target.value.length&&e.target.value;t[e.target.id.replace("G","P")]=parseFloat(e.target.value/1e3*100).toFixed(2),this.setState({fertiliser:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.fertiliser};a[e]=t.target.value,this.setState({fertiliser:a,changed:!0})},this.handleToggle=(e,t,a)=>{const n=this.state.fertiliser.allowedVarieties.indexOf(e),i={...this.state.fertiliser};-1===n?i.allowedVarieties.push(e):i.allowedVarieties.splice(n,1),this.setState({fertiliser:i,changed:!0})},this.getGenFertsOptions=e=>e.map(e=>{const t={};return t.value=e.sk,t.key=e.sk,t.label=e.name,t}),this.renderElement=(e,t,a,n)=>i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:`${a}${n}`,label:"G"===n?(null===t||void 0===t?void 0:t.unit)?"kg"===(null===t||void 0===t?void 0:t.unit)?" Ca g/kg":" Ca g/L":" Ca g":"%",name:`${a}${n}`,InputLabelProps:{shrink:!0},InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},(null===t||void 0===t?void 0:t.unit)?"kg"===(null===t||void 0===t?void 0:t.unit)?" g/kg":" g/L":" g"),min:"0.00001",step:"any"},value:t[`${a}${n}`],onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!e[`${a}${n}`]||void 0,helperText:e[`${a}${n}`]})),this.getOptionLabel=(e,t)=>(console.log("optionLabeloption",e,"value",t),e.label?e.label:""),this.getOptionValue=e=>e.value,this.getOptionSelected=(e,t)=>(console.log("optionSelectedoption",e,"value",t),e.value===t),this.getOptions=e=>{const{searchString:t,isSearching:a}=this.state;return 0===t.length?[{value:"",label:"Type to search",key:"type"}]:a?[{value:"",label:"Searching...",key:"searching"}]:a||0!==e.length?e:[{value:"",label:"No results",key:"searching"}]},this.state={isloading:!1,isNew:this.props.isNew,fertiliser:this.props.fertiliser,errors:{count:0},changed:!1,searchedFertilisers:[],selectedGenFertiliser:null,searchString:"",isSearching:!1}}componentDidMount(){}validateField(e){const{fertiliser:t,errors:a}=this.state,n=jn(e,t,ts),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,getFromGlobalState:l,dynamoType:s,skPrimary:o,autoSearch:c}=this.props,{fertiliser:d,errors:m,searchedFertilisers:p,selectedGenFertiliser:h,isSearching:u}=this.state,b=$n(d,ts)&&(!m.name||""===m.name),v=this.getGenFertsOptions(p),y=h||d&&d.loadedFromSettingSK;return i.a.createElement(Ia,{open:t,dialogObject:d,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:o,dynamoType:s,valid:b,changed:this.state.changed,newTitle:"New Fertiliser",title:d.name,getFromGlobalState:l},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-end"},!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:d.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},c&&i.a.createElement(zl,{options:this.getOptions(v),onInputChange:this.handleInputChange,onChange:this.handleGenFertChange,label:u?"Searching...":"Search for fertiliser"}),i.a.createElement(zt.a,{margin:"normal",required:!0,disabled:y,fullWidth:!0,InputLabelProps:{shrink:!0},id:"name",label:"Trade Name",name:"name",value:d.name,onChange:this.handleChange,onBlur:this.handleNameBlur,error:!!m.name||void 0,helperText:m.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{required:!0},"State"),i.a.createElement(xn.a,{"aria-label":"unit",name:"unit",id:"unit",disabled:y,className:e.group,value:(null===d||void 0===d?void 0:d.unit)||"",onChange:this.handleRadioChange.bind(this,"unit")},i.a.createElement(Fe.a,{value:"kg",control:i.a.createElement(Cn.a,null),label:"kg (granular)"}),i.a.createElement(Fe.a,{value:"liter",control:i.a.createElement(Cn.a,null),label:"litre (liquid)"}),m.unit&&i.a.createElement(En.a,{className:e.helperText},null===m||void 0===m?void 0:m.unit)))),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"nitrogenP",label:"Nitrogen (N) %",name:"nitrogenP",disabled:y,InputLabelProps:{shrink:!0},value:d.nitrogenP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.nitrogenP||void 0,helperText:m.nitrogen})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"nitrogenG",step:"0.01",disabled:y,label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Nitrogen (N) g/kg":" Nitrogen (N) g/L":" Nitrogen (N) g",name:"nitrogenG",InputLabelProps:{shrink:!0},value:d.nitrogenG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.nitrogenG||void 0,helperText:m.nitrogen})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"phosphorusP",label:"Phosphorus (P) %",step:"0.01",name:"phosphorusP",disabled:y,InputLabelProps:{shrink:!0},value:d.phosphorusP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.phosphorusP||void 0,helperText:m.phosphorusP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"phosphorusG",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Phosphorus (P) g/kg":" Phosphorus (P) g/L":" Phosphorus (P) g",name:"phosphorusG",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.phosphorusG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.phosphorusG||void 0,helperText:m.phosphorusG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"potassiumP",label:"Potassium (K) %",step:"0.01",name:"potassiumP",disabled:y,InputLabelProps:{shrink:!0},value:d.potassiumP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.potassiumP||void 0,helperText:m.potassiumP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"potassiumG",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Potassium (K) g/kg":" Potassium (K) g/L":" Potassium (K) g",name:"potassiumG",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.potassiumG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.potassiumG||void 0,helperText:m.potassiumG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"caP",label:"Ca %",name:"caP",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.caP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.caP||void 0,helperText:m.caP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"caG",step:"0.01",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Ca g/kg":" Ca g/L":" Ca g",name:"caG",disabled:y,InputLabelProps:{shrink:!0},value:d.caG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.caG||void 0,helperText:m.caG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"mgP",label:"Mg %",step:"0.01",name:"mgP",disabled:y,InputLabelProps:{shrink:!0},value:d.mgP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.mgP||void 0,helperText:m.mgP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"mgG",step:"0.01",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Mg g/kg":" Mg g/L":" Mg g",name:"mgG",disabled:y,InputLabelProps:{shrink:!0},value:d.mgG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.mgG||void 0,helperText:m.mgG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"sP",label:"S %",step:"0.01",name:"sP",disabled:y,InputLabelProps:{shrink:!0},value:d.sP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.sP||void 0,helperText:m.sP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"sG",step:"0.01",disabled:y,label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" S g/kg":" S g/L":" S g",name:"sG",InputLabelProps:{shrink:!0},value:d.sG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.sG||void 0,helperText:m.sG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"bP",label:"B %",name:"bP",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.bP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.bP||void 0,helperText:m.bP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"bG",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" B g/kg":" B g/L":" B g",name:"bG",disabled:y,InputLabelProps:{shrink:!0},step:"0.01",value:d.bG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.bG||void 0,helperText:m.bG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"feP",label:"Fe %",step:"0.01",name:"feP",disabled:y,InputLabelProps:{shrink:!0},value:d.feP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.feP||void 0,helperText:m.feP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"feG",disabled:y,step:"0.01",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Fe g/kg":" Fe g/L":" Fe g",name:"feG",InputLabelProps:{shrink:!0},value:d.feG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.feG||void 0,helperText:m.feG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"mnP",label:"Mn %",step:"0.01",name:"mnP",disabled:y,InputLabelProps:{shrink:!0},value:d.mnP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.mnP||void 0,helperText:m.mnP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"mnG",disabled:y,step:"0.01",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Mn g/kg":" Mn g/L":" Mn g",name:"mnG",InputLabelProps:{shrink:!0},value:d.mnG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.mnG||void 0,helperText:m.mnG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"znP",label:"Zn %",name:"znP",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.znP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.znP||void 0,helperText:m.znP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"znG",disabled:y,label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Zn g/kg":" Zn g/L":" Zn g",name:"znG",step:"0.01",InputLabelProps:{shrink:!0},value:d.znG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.znG||void 0,helperText:m.znG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"cuP",label:"Cu %",name:"cuP",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:d.cuP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.cuP||void 0,helperText:m.cuP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"cuG",disabled:y,label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Cu g/kg":" Cu g/L":" Cu g",name:"cuG",InputLabelProps:{shrink:!0},step:"0.01",value:d.cuG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.cuG||void 0,helperText:m.cuG})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"moP",label:"Mo %",name:"moP",disabled:y,InputLabelProps:{shrink:!0},step:"0.01",value:d.moP,onChange:this.handleChangeP,onBlur:this.handleBlur,error:!!m.moP||void 0,helperText:m.moP})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"moG",label:(null===d||void 0===d?void 0:d.unit)?"kg"===(null===d||void 0===d?void 0:d.unit)?" Mo g/kg":" Mo g/L":" Mo g",name:"moG",step:"0.01",disabled:y,InputLabelProps:{shrink:!0},value:null===d||void 0===d?void 0:d.moG,onChange:this.handleChangeG,onBlur:this.handleBlur,error:!!m.moG||void 0,helperText:m.moG})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"supplier",label:"Supplier",name:"supplier",value:null===d||void 0===d?void 0:d.supplier,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.supplier||void 0,helperText:m.supplier})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"advisor",label:"Advisor Name and Surname",name:"advisor",value:null===d||void 0===d?void 0:d.advisor,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.advisor||void 0,helperText:m.advisor}))))}}as.defaultProps={dynamoType:"fertilisers",skPrimary:"init_setting_",autoSearch:!1,searchedFertilisers:[]};var ns=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},formControlA:{minWidth:220},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2),width:"100%"}}))(as);const is=[{name:"crop",min:1,max:100}];class rs extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,is),this.handleRadioChange=(e,t)=>{let a={...this.state.fertCrop};a[e]=t.target.value,this.setState({fertCrop:a,changed:!0})},this.handleChange=e=>{let t={...this.state.fertCrop};t[e.target.id]=e.target.value,this.setState({fertCrop:t,changed:!0})},this.handleAppMethodChange=e=>{let t={...this.state.fertCrop};switch(t.application={},e.target.value){case"handPlant":t.application.method="handPlant",t.application.methodText="Hand",t.application.dosage="kg",t.application.unit="plant";break;case"handHa":t.application.method="handHa",t.application.methodText="Hand",t.application.dosage="kg",t.application.unit="ha";break;case"fertilizerSpreader":t.application.method="fertilizerSpreader",t.application.methodText="Fertilizer Spreader",t.application.dosage="kg",t.application.unit="ha";break;case"fertigation":t.application.method="fertigation",t.application.methodText="Fertigation",t.application.dosage="l",t.application.unit="100l";break;case"drench":t.application.method="drench",t.application.methodText="Drench",t.application.dosage="ml",t.application.unit="l";break;case"foliarSpray":t.application.method="foliarSpray",t.application.methodText="Foliar Spray",t.application.dosage="l",t.application.unit="100l";break;case"arealSpray":t.application.method="arealSpray",t.application.methodText="Areal Spray",t.application.dosage="l",t.application.unit="100l";break;default:t.application={method:"none",dosage:"none",unit:"none"}}this.setState({fertCrop:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,fertCrop:{},errors:{count:0},varieties:[],changed:!1}}componentDidMount(){this.props.isNew?this.setState({fertCrop:{}}):this.setState({fertCrop:this.props.fertCrop})}validateField(e,t){let a=jn(e,this.state.fertCrop,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,parent:l,metaData:s,getFromGlobalState:o}=this.props,{fertCrop:c,errors:d}=this.state,m=s,p=$n(c,is);return i.a.createElement(Ia,{open:t,dialogObject:c,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_setchild_",dynamoType:"fertcrops",valid:p,changed:this.state.changed,newTitle:"New Crop",subTitle:""+l.name,title:a?"":ae(c.crop,m,"name"),parentKey:l.sk,getFromGlobalState:o},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Crop"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:c.crop,onChange:this.handleChange,onBlur:this.handleBlur,error:!!d.crop||void 0,inputProps:{name:"crop",id:"crop"}},i.a.createElement("option",{value:""}),m&&m.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),d.crop&&i.a.createElement(En.a,{className:e.helperText},d.crop)))))}}var ls=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},group:{margin:e.spacing(1,0)},formControlRadio:{marginTop:e.spacing(2)}}))(rs);const ss=[{id:"isDisabled",numeric:!1,disablePadding:!1,label:"Disabled",maxWidth:"80px"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"supplier",numeric:!1,disablePadding:!1,label:"Supplier"},{id:"unit",numeric:!1,disablePadding:!1,label:"Unit"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"}],os=[{id:"name",combine:[{id:"unit",opacity:1},{id:"supplier",opacity:.6}],numeric:!1,disablePadding:!0,label:"Name",maxWidth:"100px"},{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"}],cs={nitrogenP:"N",phosphorusP:"P",potassiumP:"K",caP:"Ca",mgP:"Mg",sP:"S",bP:"B",feP:"Fe",mnP:"Mn",znP:"Zn",cuP:"Cu",moP:"Mo"};class ds extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({fertiliserDetailOpen:!0})},this.handleBlur=e=>{},this.handleClickAddNewFertiliserCrop=(e,t)=>{this.setState({fertiliserCropDetailOpen:!0,isNew:!0,selectedFertiliserSK:e,selectedFertiliser:t,selectedFertiliserCrop:{}})},this.handleClickShowFertiliserCrop=(e,t)=>{const a=this.props.getFromGlobalState("fertilisers").find(t=>t.sk===e),n=a.fertcrops.find(e=>e.sk===t);this.setState({selectedFertiliserCrop:n,selectedFertiliser:a,selectedFertiliserSK:a.sk}),this.setState({fertiliserCropDetailOpen:!0,isNew:!1})},this.getFertiliserRows=e=>{if(!e||!e.length)return[];return e.map(e=>{const t={...e};return t.isDisabled=t.isDisabled?"Yes":"No",t.description="",Object.keys(cs).forEach(e=>{cs[e]&&t[e]&&(t.description+=`${cs[e]}:${parseFloat(t[e]).toFixed(2)} `)}),t})},this.handleClickShowFertiliser=this.handleClickShowFertiliser.bind(this),this.handleClickAdd=this.handleClickAdd.bind(this),this.state={expandedSetting:"",selectedFertiliser:null,selectedFertiliserCrop:null,modalObject:null,isNew:!1,fertiliserDetailOpen:!1,fertiliserCropDetailOpen:!1,errors:{},openModal:""}}handleClickAdd(){this.setState({fertiliserDetailOpen:!0,isNew:!0,pricePerUnit:0,selectedFertiliser:{nitrogenP:0,phosphorusP:0,potassiumP:0,caP:0,mgP:0,sP:0,bP:0,feP:0,mnP:0,znP:0,cuP:0,moP:0,nitrogenG:0,phosphorusG:0,potassiumG:0,caG:0,mgG:0,sG:0,bG:0,feG:0,mnG:0,znG:0,cuG:0,moG:0}})}handleClickShowFertiliser(e,t,a){const n=this.props.getFromGlobalState("fertilisers").find(e=>e.sk===a);this.setState({selectedFertiliser:n,selectedFertiliserSK:a,fertiliserDetailOpen:"true",isNew:!1})}handleClickEdit(){this.setState({fertiliserDetailOpen:!0,isNew:!0})}setClose(){this.setState({fertiliserDetailOpen:!1})}setCloseVariety(){this.setState({fertiliserCropDetailOpen:!1})}handleUpdate(e){const t=this.props.getFromGlobalState("fertilisers").findIndex(t=>t.sk===e.sk);if(-1===t){const t=this.props.getFromGlobalState("fertilisers");t.push(e),this.props.setGlobalState({fertilisers:t})}else{const a=this.props.getFromGlobalState("fertilisers");a[t]=e,this.props.setGlobalState({fertilisers:a})}}handleUpdateFertiliserCrop(e,t){const a=this.props.getFromGlobalState("fertilisers").findIndex(e=>e.sk===t);if(-1===a)return void alert("impossible - we don't have this fertiliser!");const n=this.props.getFromGlobalState("fertilisers");n[a].fertcrops||(n[a].fertcrops=[]);const i=n?n[a].fertcrops.findIndex(t=>t.sk===e.sk):-1;-1===i?(n[a].fertcrops.push(e),this.props.setGlobalState({fertilisers:n})):(n[a].fertcrops[i]=e,this.props.setGlobalState({fertilisers:n}))}getCropsNotAddedYet(e,t,a,n){if(!t)return[];if(!t.fertcrops)return[];const i=t.fertcrops.map(e=>e.crop),r=e.filter(e=>!i.includes(e.sk));if(!a){const t=e.filter(e=>e.sk===n.crop);t&&r.push(t[0])}return r}render(){const{classes:e,initialState:t,setSnack:a,isMobile:n,getFromGlobalState:r}=this.props,{selectedFertiliser:l}=this.state,s=t,o=this.getFertiliserRows(s),c=r("userDetail");return i.a.createElement(O.a,{elevation:0,className:e.mainSection},this.state.fertiliserDetailOpen&&i.a.createElement(ns,{handleUpdate:this.handleUpdate.bind(this),open:this.state.fertiliserDetailOpen,setClose:this.setClose.bind(this),isNew:this.state.isNew,getFromGlobalState:this.props.getFromGlobalState,fertiliser:this.state.selectedFertiliser,autoSearch:!0,setSnack:a,fertilisers:s}),this.state.fertiliserCropDetailOpen&&i.a.createElement(ls,{handleUpdate:this.handleUpdateFertiliserCrop.bind(this),open:this.state.fertiliserCropDetailOpen,setClose:this.setCloseVariety.bind(this),isNew:this.state.isNew,fertCrop:this.state.selectedFertiliserCrop,parentSK:this.state.selectedFertiliserSK,parent:this.state.selectedFertiliser,getFromGlobalState:this.props.getFromGlobalState,metaData:this.getCropsNotAddedYet(this.props.metaData,this.state.selectedFertiliser,this.state.isNew,this.state.selectedFertiliserCrop)}),i.a.createElement(Me,{heading:"Fertilisers",displayToolbar:!0,hideHeading:!0,id:"fertilisersTable",noPagination:!0,rows:o,headCells:n?os:ss,handleSelect:this.handleClickShowFertiliser,handleAddItem:c&&c.rights&&!c.rights.readOnly?this.handleClickAdd:null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0,dense:!0,maxHeight:"350px",selectedRow:l?l.sk:""}))}}var ms=Object(v.a)(e=>({root:{flexGrow:1},aligner:{},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(ds),ps=a(1759),hs=a(1760),gs=a(1761);function us(e){const{classes:t,activeStep:a,steps:n,handleNext:r,handleBack:l,handleReset:s,handleFinish:o,stepValid:c,minHeight:d,minWidth:m,isMobile:p,stepsContent:h,isLoadingStep:g,children:u,replaceFinish:b}=e;return i.a.createElement("div",{className:t.root},i.a.createElement(ps.a,{activeStep:a,alternativeLabel:!0,style:{paddingBottom:"0px",paddingTop:"8px"}},n.map(e=>i.a.createElement(hs.a,{disabled:e.disabled,key:e.label},i.a.createElement(gs.a,null,e.label)))),i.a.createElement("div",null,a===n.length?i.a.createElement("div",null,i.a.createElement(B.a,{className:t.instructions},"All steps completed"),i.a.createElement(Ct.a,{onClick:s},"Reset")):i.a.createElement("div",null,i.a.createElement(O.a,{elevation:0,className:t.paper,style:p?{}:{minHeight:d,minWidth:m}},i.a.createElement(N,{isloading:g},u&&u.length>a&&u[a])),i.a.createElement("div",null,i.a.createElement(Ct.a,{disabled:0===a,onClick:l,className:t.backButton},"Back"),a!==n.length-1&&b&&i.a.createElement(Ct.a,{disabled:!c,variant:"contained",color:"primary",onClick:a===n.length-1?o:r},a===n.length-1?"Finish":"Next")))))}us.defaultProps={activeStep:0,minHeight:"250px",minWidth:"300px",isMobile:!1,isLoadingStep:!1,replaceFinish:!1};var bs=Object(v.a)(e=>({root:{width:"100%"},backButton:{marginRight:e.spacing(1)},instructions:{marginTop:e.spacing(1),marginBottom:e.spacing(1)},paper:{marginTop:e.spacing(1),marginBottom:e.spacing(1),padding:e.spacing(1),alignItems:"center"}}))(us),vs=a(1762);const ys=[{value:"Trap"},{value:"Fruit"},{value:"Flower"},{value:"Leaf"},{value:"New Leaf (Flush)"},{value:"Raceme"},{value:"Branch"},{value:"Tree"},{value:"Planting"}],fs=[{value:"Trap"},{value:"Fruit"},{value:"Flower"},{value:"Leaf"},{value:"Branch"},{value:"Tree"},{value:"% of Trees"},{value:"Planting"},{value:"Hectares"},{value:"Block"}],Es=[{value:"m"},{value:"mm"},{value:"mm/day"},{value:"Degrees Celcius"},{value:"mS/cm"},{value:"uS/cm"},{value:"Liter"},{value:"kg"},{value:"kPa"},{value:"g"},{value:"%"},{value:"mg/kg"}],Ss=[{month:1,member:"jan",label:"Jan",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:2,member:"feb",label:"Feb",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:3,member:"mar",label:"Mar",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:4,member:"apr",label:"Apr",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:5,member:"may",label:"May",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:6,member:"jun",label:"Jun",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:7,member:"jul",label:"Jul",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:8,member:"aug",label:"Aug",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:9,member:"sep",label:"Sep",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:10,member:"oct",label:"Oct",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:11,member:"nov",label:"Nov",thresholdLow:null,thesholdMedium:null,thesholdHigh:null},{month:12,member:"dec",label:"Dec",thresholdLow:null,thesholdMedium:null,thesholdHigh:null}];function Cs(e){const{classes:t,stage:a,errors:n,getFromGlobalState:r,obsIdx:l,stageIdx:s,targetType:o,handleDeleteStage:c,handleRadioChange:d,handleArrayChange:m,handleBlur:p,handleDeleteImage:h,fileUploaded:u,handleVariableTChange:b,imageUrls:v,isGeneral:y,setId:f,disableUpload:S,disableDelete:C,disableElevation:x,selectionMode:k,cropSpecific:w,isLoading:T,selectedCropType:D}=e,F=r("targetsTypesSetting"),L=o?F.find(e=>e.sk===o):null,A=L?L.name:"",I=A&&"Other"!==A?ys:Es,G=r("targetDetail"),R=F.find(e=>"Phenology"===e.name),U=G&&R&&G[R.sk]?G[R.sk]:[],M=U&&U[D],W=!w,z=fs;return a?i.a.createElement(N,{isloading:T},i.a.createElement(O.a,{elevation:x?0:1,className:t.paper},i.a.createElement(g.a,{container:!0,className:t.root2,spacing:1,alignItems:"flex-end"},!W&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",null,i.a.createElement(B.a,null,"Stage "+(s+1)),!C&&i.a.createElement(E.a,{onClick:e=>c(e,l,s)},i.a.createElement(ei.a,{color:"secondary"})))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"priority"},"Priority"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,displayEmpty:!0,disabled:k,value:a.priority,onChange:e=>m(e,l,s),onBlur:p,error:!!n.priority||void 0,inputProps:{name:"priority",id:"priority"}},i.a.createElement("option",{"aria-label":"empty",value:""}),i.a.createElement("option",{value:"Primary"},"Primary"),i.a.createElement("option",{value:"Secondary"},"Secondary")),n.priority&&i.a.createElement(En.a,{className:t.helperText},n.priority))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"priority"},"Phenology"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,displayEmpty:!0,disabled:k,value:a.phenology,onChange:e=>m(e,l,s),onBlur:p,error:!!n.phenology||void 0,inputProps:{name:"phenology",id:"phenology"}},i.a.createElement("option",{"aria-label":"empty",value:""}),M&&M.map(e=>i.a.createElement("option",{value:e.sk},e.name))),n.priority&&i.a.createElement(En.a,{className:t.helperText},n.priority))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:t.formControlRadio},i.a.createElement(kn.a,{required:!0},"Type"),i.a.createElement(xn.a,{"aria-label":"monitorType",name:"monitorType",id:"monitorType",className:t.group,disabled:k,value:a.monitorType,onChange:e=>d(e,l,s,"monitorType")},i.a.createElement(Fe.a,{value:"Fixed",control:i.a.createElement(Cn.a,{disabled:k}),label:"Fixed"}),i.a.createElement(Fe.a,{value:"Field",control:i.a.createElement(Cn.a,{disabled:k}),label:"Field"}),n.monitorType&&i.a.createElement(En.a,{className:t.helperText},n.monitorType)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,disabled:k,id:"stageDescription",label:"Description",name:"stageDescription",value:a.stageDescription,onChange:e=>m(e,l,s),onBlur:p,error:!!n.stageDescription||void 0,helperText:n.stageDescription})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{className:t.root},i.a.createElement(Wi.a,{className:t.imageList,cols:a&&a.images&&a.images.length>1?2.5:1},a&&a.images&&a.images.map((e,a)=>i.a.createElement(zi.a,{key:e.Key,style:{minWidth:"120px",height:"200px"}},v&&v[e.Key]?i.a.createElement("img",{key:e.Key,style:{objectFit:"cover",height:"100%"},alt:"target",src:v[e.Key]}):i.a.createElement("div",{style:{width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center"}},i.a.createElement(P.a,{color:"secondary"})),i.a.createElement(vs.a,{title:e.name,classes:{root:t.titleBar,title:t.title},actionIcon:C?void 0:i.a.createElement(E.a,{onClick:t=>h(t,l,s,e.Key),"aria-label":"star "+e.name},i.a.createElement(ei.a,{className:t.title}))}))))),!S&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(nr,{activeTenant:r("activeSite"),generateThumbnail:!0,generatePreview:!0,onFileUploaded:e=>u(e,l,s,a),folder:`generalSettings/targets/${A}/`,allowImageResize:!0,imageResizeTargetWidth:300,imageResizeTargetHeight:300,allowMultiple:!0,isGeneral:y,setId:f,imageTransformVariantsIncludeOriginal:!1,getFromGlobalState:r}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"procedure",multiline:!0,disabled:k,rowsMax:"4",label:"Monitoring procedure",name:"procedure",value:a.procedure,onChange:e=>m(e,l,s),onBlur:p,error:!!n.procedure||void 0,helperText:n.procedure})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Observation Type"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,displayEmpty:!0,disabled:k,value:a.unitNum,onChange:e=>m(e,l,s),onBlur:p,error:!!n.unitNum||void 0,inputProps:{name:"unitNum",id:"unitNum"}},i.a.createElement("option",{"aria-label":"empty",value:""}),i.a.createElement("option",{value:"Number"},"Number"),i.a.createElement("option",{value:"Percentage"},"Percentage"),i.a.createElement("option",{value:"Present"},"Present / Absent"),i.a.createElement("option",{value:"Scale"},"Scale")),n.unitNum&&i.a.createElement(En.a,{className:t.helperText},n.unitNum))),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",id:"quantityOfUnit",label:"Observations",disabled:k,name:"quantityOfUnit",value:a.quantityOfUnit,onChange:e=>m(e,l,s),onBlur:p,error:!!n.quantityOfUnit||void 0,helperText:n.quantityOfUnit})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unit"},"Unit"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,disabled:k,value:null===a||void 0===a?void 0:a.unit,onChange:e=>m(e,l,s),onBlur:p,error:!!(null===n||void 0===n?void 0:n.unit)||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{"aria-label":"empty",value:""}),I&&I.map(e=>i.a.createElement("option",{value:e.value},e.value))),(null===n||void 0===n?void 0:n.unit)&&i.a.createElement(En.a,{className:t.helperText},null===n||void 0===n?void 0:n.unit))),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",disabled:k,id:"quantityOfUnit2",label:"Points",name:"quantityOfUnit2",value:a.quantityOfUnit2,onChange:e=>m(e,l,s),onBlur:p,error:!!n.quantityOfUnit2||void 0,helperText:n.quantityOfUnit2})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unit"},"Point description"),i.a.createElement(Sn.a,{native:!0,required:!0,disabled:k,displayEmpty:!0,value:a.unit2,onChange:e=>m(e,l,s),onBlur:p,error:!!n.unit||void 0,inputProps:{name:"unit2",id:"unit2"}},i.a.createElement("option",{"aria-label":"empty",value:""}),z&&z.map(e=>i.a.createElement("option",{value:e.value},e.value))),n.unit2&&i.a.createElement(En.a,{className:t.helperText},n.unit2))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"frequency"},"Observation frequency"),i.a.createElement(Sn.a,{native:!0,style:{minWidth:"200px"},required:!0,fullWidth:!0,disabled:k,displayEmpty:!0,value:a.frequency,onChange:e=>m(e,l,s),onBlur:p,error:!!n.unit||void 0,inputProps:{name:"frequency",id:"frequency"}},i.a.createElement("option",{"aria-label":"empty",value:""}),i.a.createElement("option",{value:"Second"},"Second"),i.a.createElement("option",{value:"Minute"},"Minute"),i.a.createElement("option",{value:"Hourly"},"Hourly"),i.a.createElement("option",{value:"Daily"},"Daily"),i.a.createElement("option",{value:"Weekly"},"Weekly"),i.a.createElement("option",{value:"Monthly"},"Monthly"),i.a.createElement("option",{value:"Quarterly"},"Quarterly"),i.a.createElement("option",{value:"Annually"},"Annually")),n.frequency&&i.a.createElement(En.a,{className:t.helperText},n.frequency))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:t.formControlRadio},i.a.createElement(kn.a,{required:!0},"Threshold"),i.a.createElement(xn.a,{"aria-label":"threshold",name:"threshold",id:"threshold",disabled:k,className:t.group,value:a.threshold,onChange:e=>d(e,l,s,"threshold")},i.a.createElement(Fe.a,{value:"Yes",control:i.a.createElement(Cn.a,{disabled:k}),label:"Yes"}),i.a.createElement(Fe.a,{value:"No",control:i.a.createElement(Cn.a,{disabled:k}),label:"No"}),n.threshold&&i.a.createElement(En.a,{className:t.helperText},n.threshold)))),a.threshold&&"Yes"===a.threshold&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:t.formControlRadio},i.a.createElement(kn.a,{required:!0},"Constant Threshold"),i.a.createElement(xn.a,{"aria-label":"thresholdConstant",name:"thresholdConstant",id:"thresholdConstant",className:t.group,disabled:k,value:a.thresholdConstant,onChange:e=>d(e,l,s,"thresholdConstant")},i.a.createElement(Fe.a,{value:"Yes",control:i.a.createElement(Cn.a,{disabled:k}),label:"Yes"}),i.a.createElement(Fe.a,{value:"No",control:i.a.createElement(Cn.a,{disabled:k}),label:"No"}),n.thresholdConstant&&i.a.createElement(En.a,{className:t.helperText},n.thresholdConstant)))),a.threshold&&"Yes"===a.threshold&&a.thresholdConstant&&"Yes"===a.thresholdConstant&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(kn.a,{required:!0},"Thresholds")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"thresholdLow",label:"Low",name:"thresholdLow",value:a.thresholdLow,onChange:e=>m(e,l,s),onBlur:p,error:!!n.thresholdLow||void 0,helperText:n.thresholdLow})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"thresholdMedium",label:"Medium",name:"thresholdMedium",value:a.thresholdMedium,onChange:e=>m(e,l,s),onBlur:p,error:!!n.thresholdMedium||void 0,helperText:n.thresholdMedium})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"thresholdHigh",label:"High",name:"thresholdHigh",value:a.thresholdHigh,onChange:e=>m(e,l,s),onBlur:p,error:!!n.thresholdHigh||void 0,helperText:n.thresholdHigh}))),a.thresholdConstant&&"No"===a.thresholdConstant&&Ss.map((e,t)=>i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:3,sm:3,md:3,lg:3,xl:3},i.a.createElement(kn.a,{required:!0},e.label)),i.a.createElement(g.a,{item:!0,xs:3,sm:3,md:3,lg:3,xl:3},i.a.createElement(zt.a,{margin:"dense",fullWidth:!0,id:a.member+"Low",label:0===t?"Low":void 0,name:a.member+"Low",value:a.variableThreshold&&a.variableThreshold[e.member]&&a.variableThreshold[e.member].low?a.variableThreshold[e.member].low:void 0,onChange:t=>b(t,l,s,e.member,"low"),onBlur:p,error:!!(n.variableThreshold&&a.variableThreshold[e.member]&&n.variableThreshold[e.member].low)||void 0,helperText:n.variableThreshold?n.variableThreshold[e.member]:void 0})),i.a.createElement(g.a,{item:!0,xs:3,sm:3,md:3,lg:3,xl:3},i.a.createElement(zt.a,{margin:"dense",fullWidth:!0,id:e.member+"Med",label:0===t?"Medium":void 0,name:e.member+"Med",value:a.variableThreshold&&a.variableThreshold[e.member]&&a.variableThreshold[e.member].med?a.variableThreshold[e.member].med:void 0,onChange:t=>b(t,l,s,e.member,"med"),onBlur:p,error:!!(n.variableThreshold&&a.variableThreshold[e.member]&&n.variableThreshold[e.member].med)||void 0,helperText:n.variableThreshold?n.variableThreshold[e.member]:void 0})),i.a.createElement(g.a,{item:!0,xs:3,sm:3,md:3,lg:3,xl:3},i.a.createElement(zt.a,{margin:"dense",fullWidth:!0,id:e.member+"High",label:0===t?"High":void 0,name:e.member+"High",value:a.variableThreshold&&a.variableThreshold[e.member]&&a.variableThreshold[e.member].high?a.variableThreshold[e.member].high:void 0,onChange:t=>b(t,l,s,e.member,"high"),onBlur:p,error:!!(n.variableThreshold&&a.variableThreshold[e.member]&&n.variableThreshold[e.member].high)||void 0,helperText:n.variableThreshold?n.variableThreshold[e.member]:void 0}))))))):null}Cs.defaultProps={imageUrls:[],isGeneral:!1,setId:"",disableUpload:!1,disableDelete:!1,disableElevation:!1,selectionMode:!1,cropSpecific:!1};var xs=Object(v.a)(e=>({progress:{margin:e.spacing(2)},root:{display:"flex",flexWrap:"wrap",justifyContent:"space-around",overflow:"hidden",backgroundColor:e.palette.background.paper},helperText:{color:"red"},formControl:{minWidth:120,marginTop:e.spacing(2),marginBottom:e.spacing(1)},paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),alignItems:"center",width:"100%"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"},imageList:{flexWrap:"nowrap",transform:"translateZ(0)"},title:{color:"white"},titleBar:{background:"linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, rgba(0,0,0,0) 100%)"}}))(Cs);const ks=[{name:"monitorType",min:1,max:40},{name:"targetType",min:1,max:40}],ws=[[{name:"targetType",min:1,max:120},{name:"cropSpecific",min:1,max:120}],[{name:"crop",min:1,max:120}],[{name:"target",min:1,max:120}],[]];function Ts(e){const{monitoring:t,handleChange:a,targetsTypesSetting:n,errors:r,classes:l,isNew:s}=e;return i.a.createElement(g.a,{container:!0,className:l.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:l.formControlRadio},i.a.createElement(kn.a,{required:!0},"Type"),i.a.createElement(xn.a,{"aria-label":"targetType",name:"targetType",id:"targetType",disabled:!s,className:l.group,value:t.targetType,onChange:a},n&&n.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Fe.a,{key:e.sk,value:e.sk,control:i.a.createElement(Cn.a,{disabled:!s,id:"targetType"}),label:e.name}))),r.targetType&&i.a.createElement(En.a,{className:l.helperText},r.targetType)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:l.formControlRadio},i.a.createElement(kn.a,{required:!0},"Crop Specific"),i.a.createElement(xn.a,{"aria-label":"cropSpecific",name:"cropSpecific",id:"cropSpecific",className:l.group,disabled:s,value:t.cropSpecific,onChange:a},i.a.createElement(Fe.a,{value:"Yes",control:i.a.createElement(Cn.a,{disabled:!s,id:"cropSpecific"}),label:"Yes"}),i.a.createElement(Fe.a,{value:"No",control:i.a.createElement(Cn.a,{disabled:!s,id:"cropSpecific"}),label:"No"}),r.cropSpecific&&i.a.createElement(En.a,{className:l.helperText},r.cropSpecific)))))}function Ds(e){const{monitoring:t,handleObervableChange:a,crops:n,errors:r,classes:l,handleBlur:s,isNew:o}=e;return i.a.createElement(g.a,{container:!0,className:l.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:l.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"crop"},"Obervable on"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,disabled:!o,value:t.crop,onChange:a,onBlur:s,error:!!r.crop||void 0,inputProps:{name:"crop",id:"crop"}},i.a.createElement("option",{"aria-label":"empty",value:""}),n&&n.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.crop&&i.a.createElement(En.a,{className:l.helperText},r.crop)))))}function Ps(e){const{monitoring:t,targetDetails:a,handleObervableChange:n,errors:r,classes:l,handleBlur:s,isNew:o,rows:c}=e,d=(c||[]).map(e=>({targetSK:null===e||void 0===e?void 0:e.targetSK,observableOnSk:null===e||void 0===e?void 0:e.observableOnSk}));console.log("targetDetails, rows",a,c);const m=null===t||void 0===t?void 0:t.crop,p=(a||[]).filter(e=>{const t={observableOnSk:m,targetSK:e.sk};var a;if(!(a=t,d.some(e=>Object.keys(a).every(t=>e[t]===a[t]))))return e});return i.a.createElement(g.a,{container:!0,className:l.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:l.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"target"},"Targets"),i.a.createElement(Sn.a,{native:!0,required:!0,displayEmpty:!0,disabled:!o,value:t.target,onChange:n,onBlur:s,error:!!r.target||void 0,inputProps:{name:"target",id:"target"}},i.a.createElement("option",{"aria-label":"empty",value:""}),p.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),r.target&&i.a.createElement(En.a,{className:l.helperText},r.target))))}function Fs(e){const{monitoring:t,handleRadioChange:a,handleArrayChange:n,expandedStage:r,handleStageExpand:l,handleVariableTChange:s,getFromGlobalState:o,imageUrls:c,errors:d,classes:m,handleBlur:p,targetOther:h,handleInclude:u}=e,b=t.targetDetail;return i.a.createElement(g.a,{container:!0,className:m.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(qn,{message:"Select the stages you want to monitor. You can adjust the thresholds for your farm."})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},"Yes"===t.cropSpecific&&b&&b.observableOn.map((e,t)=>e&&e.stages&&e.stages.map((e,g)=>i.a.createElement(cr,{headingComponent:i.a.createElement(i.a.Fragment,null,i.a.createElement(xe.a,{edge:"start",checked:!!e.selected&&e.selected,tabIndex:-1,disableRipple:!0,id:e.sk,onClick:e=>u(e,t,g),inputProps:{"aria-labelledby":e.sk}}),i.a.createElement(B.a,{className:m.heading},h?`${e.monitorType} : ${e.stageDescription}`:"Stage "+(g+1))),expanded:r,type:e.sk,handleExpand:t=>l(e)},i.a.createElement(xs,{classes:m,stage:e,cropSpecific:"Yes"===b.cropSpecific,errors:d,getFromGlobalState:o,obsIdx:t,stageIdx:g,targetType:b.targetType,handleRadioChange:a,handleArrayChange:n,handleBlur:p,handleVariableTChange:s,imageUrls:c,isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",disableUpload:!0,disableElevation:!0,disableDelete:!0,selectionMode:!0})))),"No"===t.cropSpecific&&i.a.createElement(xs,{classes:m,stage:b.nonCropDetail,disableElevation:!0,errors:d,getFromGlobalState:o,cropSpecific:"Yes"===b.cropSpecific,targetType:b.targetType,handleRadioChange:a,handleArrayChange:n,handleBlur:p,handleVariableTChange:s,imageUrls:c,isGeneral:!0,disableUpload:!0,disableDelete:!0,selectionMode:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3"})))}class Ns extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,ks),this.handleChange=e=>{const{monitoring:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({monitoring:a,changed:!0})},this.handleCheckChange=e=>{const{monitoring:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({monitoring:a,changed:!0})},this.handleInclude=(e,t,a)=>{const{monitoring:n}=this.state,i={...n};if("Yes"===i.cropSpecific){const e=!i.targetDetail.observableOn[t].stages[a].selected||!i.targetDetail.observableOn[t].stages[a].selected;i.targetDetail.observableOn[t].stages[a].selected=e}else{const e=!!i.targetDetail.nonCropDetail.selected&&!i.targetDetail.nonCropDetail.selected;i.targetDetail.nonCropDetail.selected=e}this.setState({monitoring:i,changed:!0}),e.preventDefault(),e.stopPropagation(),e.persist()},this.handleRadioChange=(e,t,a,n)=>{const{monitoring:i}=this.state,r={...i};"Yes"===r.cropSpecific?r.targetDetail.observableOn[t].stages[a][n]=e.target.value:r.targetDetail.nonCropDetail[n]=e.target.value,this.setState({monitoring:i,changed:!0})},this.handleObervableChange=async e=>{const{monitoring:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({monitoring:a,changed:!0})},this.handleTargetChange=async e=>{const{monitoring:t,targetDetails:a}=this.state,n={...t};n[e.target.id]=e.target.value;const i=a.find(t=>t.sk===e.target.value);i&&(i.isGeneral=!1),n.targetDetail={...i},this.setState({monitoring:n,changed:!0})},this.handleVariableTChange=(e,t,a,n,i)=>{const{monitoring:r}=this.state,l={...r};"Yes"===r.cropSpecific?(l.targetDetail.observableOn[t].stages[a].variableThreshold||(l.targetDetail.observableOn[t].stages[a].variableThreshold={}),l.targetDetail.observableOn[t].stages[a].variableThreshold[n]||(l.targetDetail.observableOn[t].stages[a].variableThreshold[n]={}),l.targetDetail.observableOn[t].stages[a].variableThreshold[n][i]||(l.targetDetail.observableOn[t].stages[a].variableThreshold[n][i]={}),l.targetDetail.observableOn[t].stages[a].variableThreshold[n][i]=e.target.value):(l.targetDetail.nonCropDetail.variableThreshold||(l.targetDetail.nonCropDetail.variableThreshold={}),l.targetDetail.nonCropDetail.variableThreshold[n]||(l.targetDetail.nonCropDetail.variableThreshold[n]={}),l.targetDetail.nonCropDetail.variableThreshold[n][i]||(l.targetDetail.nonCropDetail.variableThreshold[n][i]={}),l.targetDetail.nonCropDetail.variableThreshold[n][i]=e.target.value),this.setState({monitoring:l,changed:!0})},this.handleToggle=e=>{const{monitoring:t}=this.state,a=t.allowedCrops.indexOf(e),n={...t};-1===a?n.allowedCrops.push(e):n.allowedCrops.splice(a,1),this.setState({monitoring:n,changed:!0})},this.initWizard=async()=>{this.setState({isLoadingStep:!0}),await this.getStepContent(0),this.setState({activeStep:0,isLoadingStep:!1})},this.handleNext=async()=>{const{activeStep:e,monitoring:t}=this.state;let a;a=0===e&&"No"===t.cropSpecific?e+2:e+1,this.setState({isLoadingStep:!0}),await this.getStepContent(a),this.setState({activeStep:a,isLoadingStep:!1})},this.handleBack=async()=>{const{activeStep:e,monitoring:t}=this.state;let a;a=2===e&&"No"===t.cropSpecific?e-2:e-1,this.setState({isLoadingStep:!0}),await this.getStepContent(a),this.setState({activeStep:a,isLoadingStep:!1})},this.handleReset=()=>{this.setState({activeStep:0})},this.handleFinish=()=>{},this.filterTargets=(e,t)=>t.filter(t=>t.cropSpecific===e.cropSpecific),this.getStepContent=async e=>{const{monitoring:t}=this.state,{getFromGlobalState:a,setSnack:n,setGlobalState:i}=this.props;switch(e){case 2:{let e=[];e="Yes"===t.cropSpecific?await Ba(a,i,n,t.targetType,t.crop):await async function(e,t,a,n){if(!n)return null;const i=e("targetDetailNonCrop");if(i&&i[n])return i[n];try{const a=e("activeSite"),r=await xa(a,n.concat("_"),"cropSpecific","No"),l={...i};return l[n]||(l[n]={}),l[n]=r,t({targetDetailNonCrop:l}),l[n]}catch(r){return a({open:!0,variant:"error",messageText:Pa(r)}),!1}}(a,i,n,t.targetType);const r=this.filterTargets(t,e);r.sort((e,t)=>e.name>t.name?1:-1),this.setState({targetDetails:r});break}case 3:if("No"===t.cropSpecific){const{imageUrls:e}=this.state,a=await this.getNonCropSpecificUrls(t,e);this.setState({imageUrls:a})}break;default:return"Unknown stepIndex"}},this.handleArrayChange=(e,t,a)=>{const{monitoring:n}=this.state,i={...n};"Yes"===i.cropSpecific?i.targetDetail.observableOn[t].stages[a][e.target.id]=e.target.value:i.targetDetail.nonCropDetail[e.target.id]=e.target.value,this.setState({monitoring:n,changed:!0})},this.handleStageExpand=async e=>{if(!e)return;const{expandedStage:t,imageUrls:a}=this.state;if(t!==e.sk){const t=e.sk;this.setState({expandedStage:t});const n=e.images&&await this.getUrls(e.images,a);this.setState({imageUrls:n})}else this.setState({expandedStage:""})},this.getNonCropSpecificUrls=async(e,t)=>{const{getFromGlobalState:a}=this.props,n=a("activeSite"),i={...t};if(e.targetDetail.nonCropDetail&&e.targetDetail.nonCropDetail.images)for(const r of e.targetDetail.nonCropDetail.images)if(!i[r.Key]){const e={activeTenant:n,type:"files",setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",path:r.Key,contentType:r.fileType,isGeneral:!0,collectionName:"targets/pests"};i[r.Key]=await Fa(e)}return i},this.getUrls=async(e,t)=>{if(!e)return t;const{getFromGlobalState:a}=this.props,n=a("activeSite"),i={...t};return await Promise.all(e.map(async e=>{if(!i[e.Key]){const t={activeTenant:n,type:"files",setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",path:e.Key,contentType:e.fileType,isGeneral:!0,collectionName:"targets/pests"};i[e.Key]=await Fa(t)}})),i};const{handleUpdate:t,rows:a}=this.props;this.handleUpdate=t.bind(this),this.state={monitoring:null,errors:{count:0},changed:!1,activeStep:0,isLoadingStep:!1,targetDetails:[],includedTargets:[],expandedStage:"",imageUrls:{},steps:[{label:"Type"},{label:"Crops"},{label:"Target"},{label:"Stages"}],rows:a}}async componentDidMount(){const{isNew:e,monitoring:t}=this.props;if(e)await this.initWizard(),this.setState({monitoring:{}});else{const e={...t};await this.initWizard(),this.setState({monitoring:e,activeStep:3})}}validateField(e){const{monitoring:t,errors:a}=this.state,n=jn(e,t,ks),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,isNew:a,setClose:n,metaData:r,getFromGlobalState:l}=this.props,s=r,{monitoring:o,errors:c,changed:d,activeStep:m,isLoadingStep:p,targetDetails:h,expandedStage:u,imageUrls:b,steps:v,includedTargets:y}=this.state,f=$n(o,ws[m]),E=a?f&&m===v.length-1:f;if(!o)return null;const S=l("targetsTypesSetting"),C=S.find(e=>"Other"===e.name).sk,x=l("isMobile");return i.a.createElement(Ia,{open:t,dialogObject:o,setClose:n,isNew:a,handleUpdateDialogObject:this.handleUpdate,skPrimary:"init_setting_",dynamoType:"monitorings",valid:E,changed:d,newTitle:"New Monitoring",title:o&&o.targetDetail&&o.targetDetail.labelName?o.targetDetail.labelName:"New Monitoring",getFromGlobalState:l},i.a.createElement(i.a.Fragment,null,!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:o.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),i.a.createElement(bs,{steps:v,activeStep:m,handleNext:this.handleNext,handleBack:this.handleBack,handleReset:this.handleReset,handleFinish:this.handleFinish,stepValid:f,minHeight:"250px",minWidth:"550px",replaceFinish:!0,isMobile:x,isLoadingStep:p},i.a.createElement(Ts,{errors:c,monitoring:o,handleChange:this.handleChange,targetsTypesSetting:S,classes:e,isNew:a}),i.a.createElement(Ds,{errors:c,monitoring:o,crops:s,handleObervableChange:this.handleObervableChange,targetOther:C,handleBlur:this.handleBlur,classes:e,isNew:a}),i.a.createElement(Ps,{monitoring:o,targetDetails:h,handleObervableChange:this.handleTargetChange,errors:c,classes:e,handleBlur:this.handleBlur,isNew:a,rows:this.state.rows}),i.a.createElement(Fs,{monitoring:o,targetDetails:h,handleRadioChange:this.handleRadioChange,handleArrayChange:this.handleArrayChange,expandedStage:u,handleStageExpand:this.handleStageExpand,handleVariableTChange:this.handleVariableTChange,getFromGlobalState:l,imageUrls:b,errors:c,classes:e,handleBlur:this.handleBlur,targetOther:C,isNew:a,handleInclude:this.handleInclude,includedTargets:y}))))}}Ns.defaultProps={isNew:!1,open:!1};var Bs=Object(v.a)(e=>({avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(1)},heading:{display:"inline"},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(1)}}))(Ns);const Ls=[{name:"name",min:1,max:40}];class As extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Ls),this.handleChange=e=>{let t={...this.state.station};t[e.target.id]=e.target.value,this.setState({station:t,changed:!0})},this.getCurrentLocation=()=>{this.setState({locationLoading:!0,locationLoaded:!1}),navigator.geolocation.getCurrentPosition(e=>{const t={lat:parseFloat(e.coords.latitude.toFixed(7)),lng:parseFloat(e.coords.longitude.toFixed(7))};let a={...this.state.station};a.geoLocation=t,this.setState({station:a,changed:!0,locationLoading:!1,locationLoaded:!0})},e=>{e.code===e.PERMISSION_DENIED&&this.setState({locationLoading:!1,locationLoaded:!1})},{enableHighAccuracy:!0,timeout:1e5,maximumAge:0})},this.state={isloading:!1,isNew:this.props.isNew,station:{},errors:{count:0},changed:!1,locationLoading:!1,locationLoaded:!1}}componentDidMount(){this.props.isNew?this.setState({station:{}}):this.setState({station:this.props.station})}validateField(e,t){let a=jn(e,this.state.station,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,parentSK:l,parent:s,getFromGlobalState:o,type:c}=this.props,{station:d,errors:m}=this.state,p=$n(d,Ls);return i.a.createElement(Ia,{open:t,dialogObject:d,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_setchild_",dynamoType:c,valid:p,changed:this.state.changed,newTitle:"New Station",title:d.name?d.name:"",subTitle:s?s.name:"",parentKey:l,getFromGlobalState:o},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Station Name",name:"name",value:d.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.variety||void 0,helperText:m.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"notes",label:"Notes",name:"notes",multiline:!0,rowsMax:"4",value:d.notes,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.notes||void 0,helperText:m.notes})),i.a.createElement(g.a,{item:!0,xs:11,sm:11,md:11,lg:11,xl:11},i.a.createElement(vn.a,{fullWidth:!0,className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"geoLocation"},"Geolocation"),i.a.createElement(zt.a,{margin:"normal",style:{minWidth:"200px"},id:"geoLocation",name:"geoLocation",value:d.geoLocation?`lat:${d.geoLocation.lat} lng:${d.geoLocation.lng}`:"",onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.geoLocation||void 0,helperText:m.geoLocation}))),i.a.createElement(g.a,{item:!0,xs:1,sm:1,md:1,lg:1,xl:1},i.a.createElement(la,{onClick:this.getCurrentLocation,success:!0,icon:i.a.createElement(kr.a,null),loading:this.state.locationLoading}))))}}var Os=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(As);const Is=[{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"},{id:"targetType",numeric:!1,disablePadding:!0,label:"Target type"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"stages",numeric:!1,disablePadding:!1,label:"Stages"},{id:"stagesDescrip",numeric:!1,disablePadding:!1,label:"Stage Descriptions"},{id:"cropSpecific",numeric:!1,disablePadding:!1,label:"Crop specific"},{id:"observableOn",numeric:!1,disablePadding:!1,label:"Crop"}],Gs=[{id:"targetType",combine:[{id:"targetType",opacity:1},{id:"name",opacity:.8},{id:"mobileDescription",opacity:.6}],numeric:!1,disablePadding:!0,label:"Target",maxWidth:"100px"},{id:"observableOn",numeric:!1,disablePadding:!1,label:"Crop"}];class Rs extends n.Component{constructor(e){super(e),this.handleShowMonitoring=(e,t,a)=>{const{getFromGlobalState:n}=this.props,i=n("monitorings").find(e=>e.sk===a);this.setState({selectedMonitoring:i,selectedMonitoringSK:a,monitoringDialogOpen:"true",isNew:!1})},this.handleBlur=()=>{},this.handleSettingExpand=e=>{const{expandedSetting:t}=this.state;t!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.handleClickAddNewStation=e=>{this.setState({stationDialogOpen:!0,isNew:!0,selectedMonitoringSK:e.sk,selectedMonitoring:e,selectedStation:{}})},this.handleClickShowStation=(e,t)=>{const{getFromGlobalState:a}=this.props,n=a("monitorings").find(t=>t.sk===e),i=n.monitorStations.find(e=>e.sk===t);this.setState({selectedMonitoring:n,selectedStation:i,selectedMonitoringSK:n.sk}),this.setState({stationDialogOpen:!0,isNew:!1})},this.handleUpdate=this.handleUpdate.bind(this),this.setClose=this.setClose.bind(this),this.handleUpdateSite=this.handleUpdateSite.bind(this),this.setCloseStation=this.setCloseStation.bind(this),this.handleClickAdd=this.handleClickAdd.bind(this),this.handleShowMonitoring=this.handleShowMonitoring.bind(this),this.state={expandedSetting:"",stationDialogOpen:!1,selectedMonitoring:null,selectedStation:null,selectedMonitoringSK:"",isNew:!1,monitoringDialogOpen:!1}}handleClickAdd(){this.setState({monitoringDialogOpen:!0,isNew:!0,selectedMonitoring:{}})}handleCkickShowMonitoring(e){const{getFromGlobalState:t}=this.props,a=t("monitorings").find(t=>t.sk===e);this.setState({selectedMonitoring:a,selectedMonitoringSK:e,monitoringDialogOpen:"true",isNew:!1})}handleClickEdit(){this.setState({monitoringDialogOpen:!0,isNew:!0})}handleUpdateSite(e,t){const{getFromGlobalState:a,setGlobalState:n}=this.props,i=a("monitorings").findIndex(e=>e.sk===t);if(-1===i)return void alert("impossible - we don't have this monitoring!");const r=a("monitorings");r[i].monitorStations||(r[i].monitorStations=[]);const l=r?r[i].monitorStations.findIndex(t=>t.sk===e.sk):-1;-1===l?(r[i].monitorStations.push(e),n({monitorings:r})):(r[i].monitorStations[l]=e,n({monitorings:r}))}handleUpdate(e){const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("monitorings").findIndex(t=>t.sk===e.sk),i=t("monitorings");-1===n?(i.push(e),a({monitorings:i})):(i[n]=e,a({monitorings:i}))}setClose(){this.setState({monitoringDialogOpen:!1})}setCloseStation(){this.setState({stationDialogOpen:!1})}render(){const{classes:e,initialState:t,getFromGlobalState:a,setGlobalState:n,setSnack:r}=this.props,l=t,{monitoringDialogOpen:s,isNew:o,selectedMonitoring:c,stationDialogOpen:d,selectedStation:m,selectedMonitoringSK:p}=this.state,h=a("isMobile")?Gs:Is,g=st(l,a),u=a("userDetail");return console.log(l),i.a.createElement(O.a,{elevation:0,className:e.mainSection},s&&i.a.createElement(Bs,{handleUpdate:this.handleUpdate,open:s,setClose:this.setClose,isNew:o,monitoring:c,getFromGlobalState:a,setGlobalState:n,setSnack:r,metaData:a("crops"),rows:g}),d&&i.a.createElement(Os,{handleUpdate:this.handleUpdateSite,open:d,type:"monitorStations",setClose:this.setCloseStation,isNew:o,station:m,getFromGlobalState:a,parentSK:p,parent:c}),i.a.createElement(Me,{displayToolbar:!0,id:"monitoringTable",heading:"",noPagination:!0,dense:!0,rows:g,headCells:h,handleSelect:this.handleShowMonitoring,handleAddItem:u&&u.rights&&!u.rights.readOnly?this.handleClickAdd:null,actionType:"actionType",rowKeyName:"sk",clean:!0,maxHeight:"350px",selectedRow:p}))}}var Us=Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},margin:{margin:e.spacing(1)},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Rs);class Ms extends n.Component{constructor(e){super(e),this.handleBlur=e=>{const{requiredFields:t}=this.props;this.validateField(e.target.id,t)},this.handleChange=e=>{const t={...this.state.combination};t[e.target.id]=e.target.value,this.setState({combination:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.combination};a[e]=t.target.value,this.setState({combination:a,changed:!0})},this.handleCheckChange=e=>{const{combination:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({combination:a,changed:!0})},this.state={combination:null,errors:{count:0},changed:!1}}componentDidMount(){const{isNew:e,combinationType:t}=this.props;if(e)this.setState({combination:{combinationProducts:[],combinationType:t,isDisabled:!1}});else{const{combination:e}=this.props;e.combinationProducts||(e.combinationProducts=[]),this.setState({combination:e})}}validateField(e){const{requiredFields:t}=this.props,{combination:a,errors:n}=this.state,i=jn(e,a,t),r={...this.state.errors};r[e]=i.msg,this.setState({errors:r})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,getFromGlobalState:l,requiredFields:s}=this.props,{combination:o,errors:c,changed:d}=this.state;if(!o)return null;const m=$n(o,s);return i.a.createElement(Ia,{open:t,dialogObject:o,setClose:n,isNew:a,changed:d,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"combinations",valid:m,newTitle:"New Combination",title:o&&o.name?o.name:"",getFromGlobalState:l},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:o.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",InputLabelProps:{shrink:!0},value:o&&o.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.name||void 0,helperText:c.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"description",label:"Description",name:"description",InputLabelProps:{shrink:!0},value:o&&o.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.name||void 0,helperText:c.name}))))}}Ms.defaultProps={requiredFields:[{name:"name",min:1,max:40}]};var Ws=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(Ms);const zs=Object(z.a)(e=>({root:{width:"100%",backgroundColor:e.palette.background.paper,maxHeight:"300px",overflowY:"auto"},rootLoad:{display:"flex","& > * + *":{marginLeft:e.spacing(2)}},nested:{paddingLeft:e.spacing(4)}}));function Ks(e){const{data:t,handleToggle:a,checkedItems:n,arrayName:r,planting:l,loading:s,hideCheck:o,onSelectAll:c,allSelected:d}=e,m=zs();return i.a.createElement(i.a.Fragment,null,s&&i.a.createElement("div",{className:m.rootLoad}," ",i.a.createElement(P.a,{color:"secondary"})," "),c&&i.a.createElement(Fe.a,{value:"top",style:{float:"right"},control:i.a.createElement(xe.a,{checked:d,onChange:c,disableRipple:!0,inputProps:{"aria-labelledby":"SelectAll"}}),label:"Select All",labelPlacement:"start"}),i.a.createElement(tn.a,{className:m.root},t&&t.map(e=>{const t="checkbox-list-label-"+e.sk;return i.a.createElement(en.a,{className:m.nested,disableRipple:!0,disabled:e.disabled,key:e.sk,role:void 0,dense:!0,button:!0,onClick:a&&a.bind(this,e.sk,r,l)},!o&&!e.disabled&&i.a.createElement(ji.a,null,i.a.createElement(xe.a,{edge:"start",checked:n&&-1!==n.indexOf(e.sk),tabIndex:-1,disableRipple:!0,disabled:!!e.disabled,inputProps:{"aria-labelledby":t}})),i.a.createElement(ti.a,{id:t,primary:""+e.name}))})))}Ks.defaultProps={onSelectAll:null,allSelected:!1};class Hs extends n.Component{constructor(e){super(e),this.handleBlur=e=>{const{requiredFields:t}=this.props;this.validateField(e.target.id,t)},this.handleChangePPP=e=>{const t=this.props.getFromGlobalState("chemicals").find(t=>t.sk===e.target.value);this.setState({selectedChemical:t,selectedChemicalCrop:null,selectedChemicalCropTarget:null,isNew:!1})},this.handleChangeType=e=>{this.setState({selectedType:e.target.value,changed:!0,selectedChemical:null,selectedChemicalCrop:null,selectedChemicalCropTarget:null,selectedFertiliser:null})},this.handleChange=e=>{const{combination:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({combination:a,changed:!0})},this.handleSelectChemicalCrop=e=>{const{selectedChemical:t}=this.state,a=t.chemcrops.find(t=>t.sk===e.target.value);this.setState({selectedChemicalCrop:a,selectedChemicalCropTarget:null})},this.handleChangeFert=e=>{const t=this.props.getFromGlobalState("fertilisers").find(t=>t.sk===e.target.value);this.setState({selectedFertiliser:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.combination};a[e]=t.target.value,this.setState({combination:a,changed:!0})},this.handleCheckChange=e=>{const{combination:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({combination:a,changed:!0})},this.handleSelectChemicalCropTarget=e=>{const{selectedChemicalCrop:t}=this.state,a=t.targets.find(t=>t.sk===e.target.value);this.setState({selectedChemicalCropTarget:a})},this.generateCropRows=(e,t)=>{if(!e)return[];const a=[],n=t("crops");for(let i=0;e&&e.chemcrops&&i{if(!e)return[];return e.map(e=>{const t={};return t.sk=e.sk,t.name=e.targetDetail.name,t.targetSK=e.targetDetail.sk,t})},this.handleToggle=(e,t,a)=>{this.setState({selectedCombinationProduct:e})},this.handleAddPPP=e=>{const{selectedChemical:t,selectedChemicalCrop:a,selectedChemicalCropTarget:n}=this.state,i={...e};i.combinationProducts||(i.combinationProducts=[]);-1===i.combinationProducts.findIndex(e=>e.sk===t.sk)&&(i.combinationProducts.push({type:"chemical",sk:t.sk.concat(a.sk).concat(n.sk),selectedChemical:t,selectedChemicalCrop:a,selectedChemicalCropTarget:n,chemicalSK:t.sk,cropSK:a.sk,targetSK:n.sk}),this.setState({combination:i,changed:!0,selectedChemical:null,selectedChemicalCrop:null,selectedChemicalCropTarget:null}))},this.handleAddFert=e=>{const{selectedFertiliser:t}=this.state,a={...e};a.combinationProducts||(a.combinationProducts=[]);-1===a.combinationProducts.findIndex(e=>e.sk===t.sk)&&(a.combinationProducts.push({type:"fertiliser",sk:t.sk,selectedFertiliser:t}),this.setState({combination:a,changed:!0,selectedFertiliser:null}))},this.getListData=()=>{const{combination:e}=this.state,{getFromGlobalState:t,fertilisers:a}=this.props;t("crops");return e&&e.combinationProducts&&e.combinationProducts.map(e=>{if("fertiliser"===e.type){const t={};return t.type=e.type,t.sk=e.sk,t.typeText="Fertiliser",t.name=ae(e.sk,a),t}{const a=e.selectedChemicalCrop?this.generateCropTargetRows(e.selectedChemicalCrop,t):[],n=(e.selectedChemical?this.generateCropRows(e.selectedChemical,t):[]).find(t=>t.sk===e.cropSK),i=a.find(t=>t.sk===e.targetSK),r={};return r.sk=e.sk,r.type=e.type,r.typeText="PPP",r.name=`${ae(e.sk,t("chemicals"))}, ${n.name}, ${i.name}`,r}})},this.generateCropTargetRows=(e,t)=>{if(!e)return[];const a=[],n=this.generateReasonLis(t("monitorings"));for(let i=0;e.targets&&ii.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Crop"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:v?v.sk:"",onChange:this.handleSelectChemicalCrop.bind(this),inputProps:{name:"selectedCrop",id:"selectedCrop"}},i.a.createElement("option",{value:""}),S&&S.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Target"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:y?y.sk:"",onChange:this.handleSelectChemicalCropTarget.bind(this),inputProps:{name:"selectedChemicalCropTarget",id:"selectedChemicalCropTarget"}},i.a.createElement("option",{value:""}),C&&C.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))))),p&&"fertiliser"===p&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Fertiliser"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:m?m.sk:"",onChange:this.handleChangeFert.bind(this),inputProps:{name:"seletedFertiliser",id:"seletedFertiliser"}},i.a.createElement("option",{value:""}),c&&c.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))))))}}Hs.defaultProps={requiredFields:[{name:"name",min:1,max:40}]};var qs=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},formControlRadio:{marginTop:e.spacing(2)},group:{flexDirection:"row"}}))(Hs);const Vs=[{id:"name",numeric:!1,disablePadding:!0,label:"Name"}],js=[{id:"isDisabledText",numeric:!1,disablePadding:!0,label:"Disabled"},{id:"name",numeric:!1,disablePadding:!0,label:"Name"},{id:"description",numeric:!1,disablePadding:!0,label:"Description"}],$s=[{id:"typeText",numeric:!1,disablePadding:!0,label:"Type"},{id:"name",numeric:!1,disablePadding:!0,label:"Name"},{id:"crop",numeric:!1,disablePadding:!0,label:"Crop"},{id:"target",numeric:!1,disablePadding:!0,label:"Target"}];class Ys extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({chemicalDetailOpen:!0,isNew:!1})},this.handleBlur=e=>{},this.handleClickAddNewChemicalCrop=e=>{this.setState({chemicalCropDialogOpen:!0,isNew:!0,selectedChemicalSK:e,selectedChemicalCrop:null,selectedChemicalCropTarget:null})},this.handleClickAddNewChemicalCropTarget=()=>{this.setState({chemicalCropTargetDialogOpen:!0,isNew:!0,selectedChemicalCropTarget:{}})},this.handleSelectCombinationType=(e,t,a)=>{this.setState({selectedCombinationType:a,selectedCombination:null,selectedCombinationTarget:null})},this.handelClickAddNewCombination=()=>{this.setState({combinationDialogOpen:!0,isNew:!0,selectedCombinationTarget:null})},this.handleClickAddNewCombinationProduct=()=>{this.setState({combinationProductDialogOpen:!0,isNew:!1})},this.handleClickSelectCombinationType=e=>{this.setState({selectedCombinationType:e,selectedCombination:null,selectedCombinationTarget:null})},this.handleSelectCombination=(e,t,a)=>{const{getFromGlobalState:n}=this.props,i=n("combinations").find(e=>e.sk===a);console.log("selectedCombination",i),this.setState({selectedCombination:i,selectedCombinationTarget:null})},this.handleSelectCombinationTarget=(e,t,a)=>{const{selectedCombination:n}=this.state,i=n.combinationProducts.find(e=>e.sk===a);this.setState({selectedCombinationTarget:i,combinationProductDialogOpen:!0,isNewComboEntry:!1})},this.handleClickShowCombination=(e,t,a)=>{this.setState({selectedCombinationTarget:null,combinationDialogOpen:!0,isNew:!1})},this.handleSelectChemicalCrop=(e,t,a)=>{const{selectedChemical:n}=this.state,i=n.chemcrops.find(e=>e.sk===a);this.setState({selectedChemicalCrop:i})},this.handleClickShowChemicalCropTarget=(e,t,a)=>{this.setState({chemicalCropTargetDialogOpen:!0,isNew:!1})},this.handleSelectChemicalCropTarget=(e,t,a)=>{const{selectedChemicalCrop:n}=this.state,i=n.targets.find(e=>e.sk===a);this.setState({selectedChemicalCropTarget:i})},this.getListData=e=>{const{getFromGlobalState:t}=this.props,a=t("fertilisers");return e&&e.combinationProducts&&this.removeDuplicates(e.combinationProducts).map(e=>{if("fertiliser"===e.type){const t={};return t.sk=e.sk,t.typeText="Fertiliser",t.type=e.type,t.name=ae(e.sk,a),t}{const a=e.selectedChemicalCrop?function(e,t){if(!e)return[];const a=[],n=function(e){return e?e.map(e=>{const t={};return t.sk=e.sk,t.name=e.targetDetail.name,t.targetSK=e.targetDetail.sk,t}):[]}(t("monitorings"));for(let i=0;e.targets&&it.sk===e.cropSK),i=a.find(t=>t.sk===e.targetSK),r={};return r.sk=e.sk,r.type=e.type,r.typeText="PPP",r.name=ae(e.chemicalSK,t("chemicals")),r.crop=n.name,r.target=i.name,r}})},this.handleClickShowChemical=this.handleClickShowChemical.bind(this),this.handleClickAddChemical=this.handleClickAddChemical.bind(this),this.handleClickSelectChemical=this.handleClickSelectChemical.bind(this),this.handleClickAddCombinationType=this.handleClickAddCombinationType.bind(this),this.handleClickSelectCombinationType=this.handleClickSelectCombinationType.bind(this),this.state={expandedSetting:"",selectedChemical:null,selectedChemicalCrop:null,modalObject:null,isNew:!1,chemicalDetailOpen:!1,chemicalCropDialogOpen:!1,errors:{},openModal:"",chemicalCropTargetDialogOpen:!1,selectedChemicalCropTarget:null,combinationTypeOpen:!1,combinationProductDialogOpen:!1,selectedCombinationType:null,selectedCombination:null,selectedCombinationTarget:null,isNewComboEntry:!1}}handleClickAddChemical(){this.setState({chemicalDetailOpen:!0,isNew:!0,selectedChemical:null,selectedChemicalCrop:null,selectedChemicalCropTarget:null})}handleClickAddCombinationType(){this.setState({combinationTypeOpen:!0,isNew:!0,selectedCombinationType:null,selectedCombination:null,selectedCombinationTarget:null})}handleClickShowChemical(e,t,a){this.setState({chemicalDetailOpen:"true",isNew:!1})}handleClickSelectChemical(e,t,a){const n=this.props.getFromGlobalState("chemicals").find(e=>e.sk===a);this.setState({selectedChemical:n,selectedChemicalCrop:null,selectedChemicalCropTarget:null,isNew:!1})}handleClickEdit(){this.setState({chemicalDetailOpen:!0,isNew:!0})}setClose(){this.setState({combinationDialogOpen:!1,combinationProductDialogOpen:!1,selectedCombinationTarget:null})}setCloseVariety(){this.setState({chemicalCropDialogOpen:!1})}setCloseChemicalCropTarget(){this.setState({chemicalCropTargetDialogOpen:!1})}handleUpdate(e){const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("combinations"),i=n.findIndex(t=>t.sk===e.sk);-1===i?n.push(e):n[i]=e,a({combinations:n}),this.setState({selectedCombinationTarget:null,selectedCombination:e})}handleUpdateChemicalCropTarget(e){const{setGlobalState:t,getFromGlobalState:a}=this.props,{selectedChemicalCrop:n,selectedChemical:i}=this.state,r=a("chemicals"),l=r.find(e=>e.sk===i.sk).chemcrops.find(e=>e.sk===n.sk);l.targets||(l.targets=[]);const s=l.targets.findIndex(t=>e.sk===t.sk);-1===s?l.targets.push(e):l.targets[s]={...e},t({chemicals:r}),this.setState({selectedChemicalCropTarget:e})}handleUpdateChemicalCrop(e,t){const a=this.props.getFromGlobalState("chemicals").findIndex(e=>e.sk===t);if(-1===a)return void alert("impossible - we don't have this crop!");const n=this.props.getFromGlobalState("chemicals");n[a].chemcrops||(n[a].chemcrops=[]);const i=n?n[a].chemcrops.findIndex(t=>t.sk===e.sk):-1;-1===i?(n[a].chemcrops.push(e),this.props.setGlobalState({chemicals:n,chemicalCropDialogOpen:!1})):(n[a].chemcrops[i]={...e},this.props.setGlobalState({chemicals:n,chemicalCropDialogOpen:!1})),this.setState({selectedChemicalCropTarget:null,selectedChemicalCrop:e})}removeDuplicates(e){const t=new Set,a=[];return e.forEach(e=>{const n=JSON.stringify({selectedChemical:null===e||void 0===e?void 0:e.selectedChemical,selectedChemicalCrop:null===e||void 0===e?void 0:e.selectedChemicalCrop,selectedChemicalCropTarget:null===e||void 0===e?void 0:e.selectedChemicalCropTarget});t.has(n)||(t.add(n),a.push(e))}),a}getCropsNotAddedYet(e,t,a,n){if(!t)return[];if(!t.chemcrops)return[];const i=t.chemcrops.map(e=>e.crop),r=e.filter(e=>!i.includes(e.sk));if(!a){const t=e.filter(e=>e.sk===n.crop);t&&r.push(t[0])}return r}render(){const{classes:e,initialState:t,getFromGlobalState:a}=this.props,{selectedCombinationType:n,combinationDialogOpen:r,selectedCombination:l,isNew:s,selectedChemical:o,selectedChemicalCrop:c,chemicalCropDialogOpen:d,chemicalDetailOpen:m,selectedChemicalCropTarget:p,chemicalCropTargetDialogOpen:h,combinationProductDialogOpen:u}=this.state,b=a("userDetail");let v=a("combinations");v||(v=[]),v=n?v.filter(e=>e.combinationType===n):[],v=v.map(e=>{const t={...e};return t.isDisabledText=t.isDisabled?"Yes":"No",t});let y=[];l&&(y=this.getListData(l));const f=a("chemicals"),E=a("fertilisers");return i.a.createElement(O.a,{elevation:0,className:e.mainSection},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},r&&i.a.createElement(Ws,{handleUpdate:this.handleUpdate.bind(this),open:r,setClose:this.setClose.bind(this),isNew:s,combinationType:n,combination:l,getFromGlobalState:a}),u&&i.a.createElement(qs,{handleUpdate:this.handleUpdate.bind(this),open:u,setClose:this.setClose.bind(this),isNew:s,combinationType:n,combination:l,getFromGlobalState:a,chemicals:f,fertilisers:E,isNewComboEntry:this.state.isNewComboEntry,selectedCombinationTarget:this.state.selectedCombinationTarget}),this.state.chemicalCropDialogOpen&&i.a.createElement(jl,{handleUpdate:this.handleUpdateChemicalCrop.bind(this),open:d,setClose:this.setCloseVariety.bind(this),isNew:this.state.isNew,chemCrop:c,parent:o,getFromGlobalState:a,metaData:{filteredCrops:this.getCropsNotAddedYet(this.props.metaData,this.state.selectedChemical,this.state.isNew,this.state.selectedChemicalCrop),monitorings:a("monitorings")}}),h&&i.a.createElement(_l,{handleUpdate:this.handleUpdateChemicalCropTarget.bind(this),open:h,setClose:this.setCloseChemicalCropTarget.bind(this),isNew:this.state.isNew,chemCropTarget:p,chemical:o,parent:c,getFromGlobalState:a,crop:c?c.crop:null,metaData:{monitorings:a("monitorings")},alreadySet:[]}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(Me,{heading:"Type",displayToolbar:!0,id:"combinationTypes",noPagination:!0,rows:[{name:"Plant Protection"},{name:"Fertiliser"}],headCells:Vs,handleSelect:this.handleSelectCombinationType,actionType:"actionType",rowKeyName:"name",disablePadFirstCol:!0,clean:!0,dense:!0,handleEditItem:this.handleClickShowChemical,maxHeight:"350px",selectedRow:n})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(Me,{heading:"Combination",displayToolbar:!0,id:"combinationTable",noPagination:!0,rows:v,headCells:js,handleSelect:this.handleSelectCombination,handleAddItem:b&&b.rights&&!b.rights.readOnly?this.handelClickAddNewCombination:null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0,dense:!0,showEditButton:!0,editDisabled:!l,disableAdd:!n,handleEditItem:this.handleClickShowCombination,parent:o,maxHeight:"350px",selectedRow:l?l.sk:""})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(Me,{heading:"Products",displayToolbar:!0,id:"combinationTargets",noPagination:!0,rows:y,headCells:$s,handleSelect:this.handleSelectCombinationTarget,handleAddItem:b&&b.rights&&!b.rights.readOnly?this.handleClickAddNewCombinationProduct:null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0,dense:!0,showEditButton:!0,disableAdd:!l,editDisabled:!p,handleEditItem:this.handleClickShowChemicalCropTarget,parent:c,maxHeight:"350px",selectedRow:p?p.sk:""}))))}}var _s=Object(v.a)(e=>({root:{flexGrow:1},aligner:{},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Ys);class Zs extends n.Component{constructor(e){super(e),this.state={}}render(){const{classes:e,open:t,isNew:a,setClose:n,getFromGlobalState:r,details:l,handleClose:s,farm:o}=this.props;return console.log(o),i.a.createElement(yt.a,{open:t,onClose:s,"aria-labelledby":"form-dialog-title"},i.a.createElement(St.a,{id:"form-dialog-title"},null===o||void 0===o?void 0:o.name),i.a.createElement(Et.a,null,i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",InputLabelProps:{shrink:!0},disabled:!0,value:null===o||void 0===o?void 0:o.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"shortName",label:"Short Name",name:"shortName",value:null===o||void 0===o?void 0:o.shortName,InputLabelProps:{shrink:!0},disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Production Unit Code (PUC)",InputLabelProps:{shrink:!0},value:null===o||void 0===o?void 0:o.puc,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"GLOBALG.A.P. Number",InputLabelProps:{shrink:!0},value:null===o||void 0===o?void 0:o.gapnum,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"VAT number",InputLabelProps:{shrink:!0},name:"Country",value:null===o||void 0===o?void 0:o.vatNo,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Physical Address Line 1",InputLabelProps:{shrink:!0},name:"Country",value:null===o||void 0===o?void 0:o.address1,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Physical Address Line 2",InputLabelProps:{shrink:!0},name:"Country",value:null===o||void 0===o?void 0:o.address2,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Country",InputLabelProps:{shrink:!0},name:"Country",value:null===o||void 0===o?void 0:o.country,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Province",InputLabelProps:{shrink:!0},name:"Province",value:null===o||void 0===o?void 0:o.province,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,label:"Postal Code",InputLabelProps:{shrink:!0},name:"pCode",value:null===o||void 0===o?void 0:o.pCode,disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"contactNum",label:"Contact Number",name:"contactNum",value:null===o||void 0===o?void 0:o.contactNum,InputLabelProps:{shrink:!0},disabled:!0})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"email",label:"Email",name:"email",value:null===o||void 0===o?void 0:o.email,InputLabelProps:{shrink:!0},disabled:!0})))))}}var Js=Zs;const Qs=({children:e,settingDialog:t,handleUpdate:a,open:n,setClose:r,isNew:l,selectedSetting:s,metaData:o,getFromGlobalState:c,setGlobalState:d})=>i.a.cloneElement(t,{handleUpdate:a,open:n,setClose:r,isNew:l,selectedSetting:s,metaData:o,getFromGlobalState:c,setGlobalState:d});class Xs extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({settingDialogOpen:!0})},this.handleBlur=()=>{},this.handleUpdate=async e=>{const{getFromGlobalState:t,settingName:a,setGlobalState:n}=this.props,i=t(a).findIndex(t=>t.sk===e.sk);if(-1===i){const i=t(a);i.push(e),n({[a]:i})}else{const r=t(a);r[i]=e,n({[a]:r})}if("farms"===a){n({siteList:await Ea()})}},this.state={selectedSetting:null,isNew:!1,settingDialogOpen:!1,openDetails:!1}}handleClickAdd(){this.setState({settingDialogOpen:!0,isNew:!0,selectedSetting:{}})}handleClickShowSetting(e,t,a){const{getFromGlobalState:n,settingName:i}=this.props,r=n(i).find(e=>e.sk===a);this.setState({selectedSetting:r,settingDialogOpen:"true",isNew:!1})}handleClickEdit(){this.setState({settingDialogOpen:!0,isNew:!0})}setClose(){this.setState({settingDialogOpen:!1})}render(){const{classes:e,settingDialog:t,userAvatar:a,settingHeading:n,headCells:r,initialState:l,getFromGlobalState:s,farm:o,Extract:c}=this.props,{settingDialogOpen:d}=this.state,m=l,p=s("userDetail");return i.a.createElement(O.a,{elevation:0,className:e.mainSection},d&&i.a.createElement(Qs,{settingDialog:t,metaData:this.props.metaDataName?this.props.getFromGlobalState(this.props.metaDataName):void 0,handleUpdate:this.handleUpdate.bind(this),open:this.state.settingDialogOpen,setClose:this.setClose.bind(this),isNew:this.state.isNew,selectedSetting:this.state.selectedSetting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState}),this.props.showDetails&&i.a.createElement(Ct.a,{onClick:e=>{this.setState({openDetails:!this.state.openDetails})},variant:"contained",color:"secondary",style:{float:"left"}},"View Details"),i.a.createElement(Js,{classes:!0,farm:o,open:this.state.openDetails,handleClose:()=>{this.setState({openDetails:!1})}}),i.a.createElement(Me,{Extract:c,userAvatar:a,displayToolbar:!0,id:n,heading:"",noPagination:!0,rows:m,headCells:r,handleSelect:this.handleClickShowSetting.bind(this),handleAddItem:p&&p.rights&&!p.rights.readOnly?this.handleClickAdd.bind(this):null,rowKeyName:"sk",clean:!0,maxHeight:"350px",selectedRow:this.state.selectedSetting}))}}Xs.defaultProps={displayLabelPrim:"name"};var eo=Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Xs);const to=[{name:"name",min:1,max:40},{name:"capacity",min:1,max:40},{name:"allowedChemicals",min:1,max:40}];class ao extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,to),this.handleChange=e=>{let t={...this.state.chemEquipment};t[e.target.id]=e.target.value,this.setState({chemEquipment:t,changed:!0})},this.handleToggle=(e,t,a)=>{const n=this.state.chemEquipment.allowedChemicals.indexOf(e),i={...this.state.chemEquipment};-1===n?i.allowedChemicals.push(e):i.allowedChemicals.splice(n,1),this.setState({chemEquipment:i})},this.state={isloading:!1,isNew:this.props.isNew,chemEquipment:this.props.selectedSetting,errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({chemEquipment:{allowedChemicals:[]}});else{let e=this.props.selectedSetting;e.allowedChemicals||(e.allowedChemicals=[]),this.setState({chemEquipment:e})}}validateField(e,t){let a=jn(e,this.state.chemEquipment,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,metaData:l,getFromGlobalState:s}=this.props,{chemEquipment:o,errors:c}=this.state,d=$n(o,to);return i.a.createElement(Ia,{open:t,dialogObject:o,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"chemequips",valid:d,changed:this.state.changed,newTitle:"Equipment",title:o.name,getFromGlobalState:s},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Equipment Name",name:"name",autoFocus:!0,value:o.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.chemEquipment||void 0,helperText:c.name}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"capacity",label:"Capacity in Liters",name:"capacity",type:"number",inputProps:{min:"0.00001",step:"any"},value:o.capacity,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.capacity||void 0,helperText:c.capacity}),i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(B.a,{variant:"subtitle1"}," Can be used for *"),i.a.createElement(Ks,{data:l,onBlur:this.handleBlur,checkedItems:o.allowedChemicals,handleToggle:this.handleToggle}),i.a.createElement(En.a,{className:e.helperText},c.allowedChemicals),c.allowedChemicals&&i.a.createElement(En.a,{className:e.helperText},c.allowedChemicals)))}}var no=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(ao);const io=[{name:"consumer",min:1,max:200}];class ro extends n.Component{constructor(e){super(e),this.handleCheckChange=e=>{const{apiKey:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({apiKey:a,changed:!0})},this.handleBlur=e=>this.validateField(e.target.id,io),this.handleChange=e=>{const t={...this.state.apiKey};t[e.target.id]=e.target.value,this.setState({apiKey:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,apiKey:this.props.selectedSetting,errors:{count:0},changed:!1,activeSite:""}}componentDidMount(){const e=this.props.getFromGlobalState("activeSite");this.setState({activeSite:e})}validateField(e,t){const a=jn(e,this.state.apiKey,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,getFromGlobalState:l}=this.props,{apiKey:s,errors:o,activeSite:c}=this.state,d=$n(s,io);return i.a.createElement(Ia,{open:t,dialogObject:s,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"apiKeys",valid:d,changed:this.state.changed,newTitle:"New API Key",title:s.consumer,getFromGlobalState:l},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},!a&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:s.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"consumer",label:"Consumer Name",name:"consumer",autoFocus:!0,value:s.consumer,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.apiKey||void 0,helperText:o.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",disabled:!0,fullWidth:!0,id:"activeTenant",label:"Farm ID",name:"activeTenant",autoFocus:!0,value:c,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.apiKey||void 0,helperText:o.apiKey})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",disabled:!0,fullWidth:!0,id:"apiKey",label:"API Key",name:"apiKey",autoFocus:!0,value:s.apiKey,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.apiKey||void 0,helperText:o.apiKey}))))}}var lo=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(ro);const so=[{name:"name",min:1,max:40},{name:"capacity",min:1,max:40}];class oo extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,so),this.handleChange=e=>{const t={...this.state.harvestingEquipment};t[e.target.id]=e.target.value,this.setState({harvestingEquipment:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,harvestingEquipment:{},errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({harvestingEquipment:{}});else{const e=this.props.selectedSetting;this.setState({harvestingEquipment:e})}}validateField(e,t){const a=jn(e,this.state.harvestingEquipment,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{open:e,isNew:t,setClose:a,handleUpdate:n,getFromGlobalState:r}=this.props,{harvestingEquipment:l,errors:s}=this.state,o=$n(l,so);return i.a.createElement(Ia,{open:e,dialogObject:l,setClose:a,isNew:t,handleUpdateDialogObject:n.bind(this),skPrimary:"init_setting_",dynamoType:"harvestequips",valid:o,changed:this.state.changed,newTitle:"New Harvesting Equipment",title:l.name,getFromGlobalState:r},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:l.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.name||void 0,helperText:s.name}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"capacity",label:"Capacity in Kg",name:"capacity",type:"number",inputProps:{min:"0.00001",step:"any"},value:l.capacity,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.capacity||void 0,helperText:s.capacity}))}}var co=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(oo);const mo=[{name:"name",min:1,max:40}];class po extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,mo),this.handleChange=e=>{const t={...this.state.cluster};t[e.target.id]=e.target.value,this.setState({cluster:t,changed:!0})},this.handleClickAdd=()=>{const e={...this.state.cluster};e.list||(e.list=[]),e.list.push({sk:Rt.a.v1(),name:""}),this.setState({cluster:e,changed:!0})},this.handleClickDelete=e=>{const t={...this.state.cluster};if(!t.list)return;const a=t.list.findIndex(t=>t.sk===e);-1!==a&&t.list.splice(a,1),this.setState({cluster:t,changed:!0})},this.handleArrayChange=e=>{const t={...this.state.cluster};if(!t.list)return;const a=t.list.find(t=>t.sk===e.target.id);a&&(a.name=e.target.value),this.setState({cluster:t,changed:!0})},this.handleClickDelete=this.handleClickDelete.bind(this),this.state={isloading:!1,cluster:{},errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({harvestingEquipment:{}});else{const e=this.props.selectedSetting;this.setState({cluster:e})}}validateField(e,t){const a=jn(e,this.state.cluster,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,getFromGlobalState:l}=this.props,{cluster:s,errors:o}=this.state,c=$n(s,mo);return i.a.createElement(Ia,{open:t,dialogObject:s,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"clusters",valid:c,changed:this.state.changed,newTitle:"New cluster group",title:s.name,getFromGlobalState:l},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Cluster group name",name:"name",autoFocus:!0,value:s.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.name||void 0,helperText:o.name}),i.a.createElement(B.a,{variant:"subtitle1"},"Add Cluster",i.a.createElement(I.a,{placement:"top",title:"Add"},i.a.createElement(E.a,{"aria-label":"Add",color:"secondary",className:e.menuButton,onClick:this.handleClickAdd.bind(this)},i.a.createElement(C.a,null)))),i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(B.a,{variant:"subtitle1"}," Clusters"),i.a.createElement(tn.a,{component:"nav","aria-label":"main mailbox folders"},s&&s.list&&s.list.map(t=>i.a.createElement(en.a,{button:!0},i.a.createElement(zt.a,{onChange:this.handleArrayChange,value:t.name,id:t.sk,name:t.sk}),i.a.createElement(I.a,{placement:"top",title:"Delete"},i.a.createElement(E.a,{"aria-label":"Delete",color:"secondary",className:e.menuButton,id:t.id,inputProps:{name:t.sk,id:t.sk},onClick:e=>this.handleClickDelete(t.sk)},i.a.createElement(ei.a,null))))))))}}var ho=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2),maxHeight:300,minHeight:300,overflowY:"auto"},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(po);const go=[{name:"name",min:1,max:100},{name:"surname",min:1,max:100},{name:"roles",min:1,max:1e3},{name:"team",min:1,max:100,condition:{name:"teamLeader",value:!0}}];class uo extends n.Component{constructor(e){super(e),this.handleDelete=e=>{const t={...this.state.operator},a=t&&t.roles.findIndex(t=>t===e);-1!==a&&t.roles.splice(a,1),this.setState({operator:t,changed:!0})},this.onSelectAll=()=>{const{operator:e,roles:t}=this.state,a={...e};a.allSelected?(a.allSelected=!1,a.roles=[]):(a.allSelected=!0,a.roles=[],a.roles=t.map(e=>e.sk)),this.setState({operator:a,changed:!0})},this.handleToggle=e=>{const{operator:t}=this.state,a={...t};a.roles||(a.roles=[]);const n=t&&t.roles.findIndex(t=>t===e);-1===n?a.roles.push(e):a.roles.splice(n,1),this.setState({operator:a,changed:!0})},this.handleBlur=e=>this.validateField(e.target.id,go),this.handleChange=e=>{const{operator:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({operator:a,changed:!0})},this.handleCheckChange=e=>{const{operator:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({operator:a,changed:!0})},this.onDisable=()=>{const{operator:e}=this.state,t={...e};t.disabled?t.disabled=!1:t.disabled=!0,this.setState({operator:t,changed:!0})};const{handleUpdate:t}=this.props;this.handleUpdate=t.bind(this),this.state={operator:{},errors:{count:0},changed:!1}}componentDidMount(){const{isNew:e,selectedSetting:t,roles:a}=this.props;if(e)this.setState({operator:{enabled:!0,roles:[],allSelected:!1},roles:a});else{const e=t;this.setState({operator:e,roles:a})}}validateField(e){const{operator:t,errors:a}=this.state,n=jn(e,t,go),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,isNew:a,setClose:n,getFromGlobalState:r}=this.props,{operator:l,errors:s,changed:o,roles:c}=this.state,d=$n(l,go);return i.a.createElement(Ia,{open:t,dialogObject:l,setClose:n,isNew:a,handleUpdateDialogObject:this.handleUpdate,skPrimary:"init_setting_",dynamoType:"operators",valid:d,changed:o,onDisable:this.onDisable,newTitle:"New member",title:l.name,getFromGlobalState:r},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:l.enabled,id:"enabled",onChange:this.handleCheckChange,value:"enabled",color:"secondary"}),label:"Enabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:l.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.name||void 0,helperText:s.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"surname",label:"Surname",name:"surname",value:l.surname,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.surname||void 0,helperText:s.surname})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"idNo",label:"ID",name:"idNo",value:l.idNo,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.idNo||void 0,helperText:s.idNo})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"clockNo",label:"Clock number",name:"clockNo",value:l.clockNo,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.clockNo||void 0,helperText:s.clockNo})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"team",label:"Team",name:"team",value:l.team,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.team||void 0,helperText:s.team})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:l.teamLeader,id:"teamLeader",onChange:this.handleCheckChange,value:"teamLeader",color:"secondary"}),label:"Team Leader"})),i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:8,lg:8,xl:8},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(B.a,{variant:"subtitle1"},"Allowed tasks"),i.a.createElement(Ks,{data:c,checkedItems:l.roles,handleToggle:this.handleToggle,arrayName:"blank",onSelectAll:this.onSelectAll,allSelected:c&&l.roles&&c.length===l.roles.length})))))}}var bo=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},margin:{margin:e.spacing(1)},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(uo);const vo=[{name:"name",min:1,max:100},{name:"description",min:1,max:300}];class yo extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,vo),this.handleChange=e=>{const t={...this.state.agronomistActs};t[e.target.id]=e.target.value,this.setState({agronomistActs:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,agronomistActs:{},errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({agronomistActs:{}});else{const e=this.props.selectedSetting;this.setState({agronomistActs:e})}}validateField(e,t){const a=jn(e,this.state.agronomistActs,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{open:e,isNew:t,setClose:a,handleUpdate:n,getFromGlobalState:r}=this.props,{agronomistActs:l,errors:s}=this.state,o=$n(l,vo);return i.a.createElement(Ia,{open:e,dialogObject:l,setClose:a,isNew:t,handleUpdateDialogObject:n.bind(this),skPrimary:"init_setting_",dynamoType:"agronomistActs",valid:o,changed:this.state.changed,newTitle:"New Activity",title:l.name,getFromGlobalState:r},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:l.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.name||void 0,helperText:s.name}),i.a.createElement(zt.a,{margin:"normal",multiline:!0,rowsMax:"4",fullWidth:!0,id:"description",label:"Description",name:"description",value:l.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.description||void 0,helperText:s.description}))}}var fo=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(yo);const Eo=[{name:"name",min:1,max:40},{name:"surname",min:1,max:40},{name:"email",min:1,max:40},{name:"rights",min:2,max:400,type:"object"}];class So extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Eo),this.handleChange=e=>{const t={...this.state.user};t[e.target.id]=e.target.value,this.setState({user:t,changed:!0})},this.handleToggleActivities=e=>t=>{const a={...this.state.user};if(a.rights||(a.rights={}),a.rights.allowedActivities||(a.rights.allowedActivities=[],a.rights.createActivities=!0),t.target.checked)a.rights.allowedActivities.push(e);else{const t=a.rights.allowedActivities.indexOf(e);t>-1&&a.rights.allowedActivities.splice(t,1),0===a.rights.allowedActivities.length&&(a.rights.createActivities=!1)}this.setState({user:a,changed:!0})},this.handleToggle=e=>t=>{const a={...this.state.user};a.rights||(a.rights={}),a.rights[e]=t.target.checked,"administrator"===e&&(a.rights.manageInventory=a.rights.administrator,a.rights.createActivities=a.rights.administrator,a.rights.readOnly=!1,a.rights.changeSettings=a.rights.administrator,a.rights.viewDashboard=a.rights.administrator,a.rights.industryView=!1,t.target.checked?(a.rights.allowedActivities=[],a.rights.allowedActivities.push("fertilisings"),a.rights.allowedActivities.push("sprayings"),a.rights.allowedActivities.push("waterings"),a.rights.allowedActivities.push("harvestings"),a.rights.allowedActivities.push("pestings"),a.rights.allowedActivities.push("activities")):a.rights.allowedActivities=[]),"industryView"===e&&(a.rights.manageInventory=!1,a.rights.createActivities=!1,a.rights.readOnly=!1,a.rights.changeSettings=!1),"viewDashboard"===e&&(a.rights.viewDashboard=t.target.checked),"createActivities"===e&&(a.rights.allowedActivities&&(a.rights.allowedActivities=[]),t.target.checked?(a.rights.allowedActivities.push("fertilisings"),a.rights.allowedActivities.push("sprayings"),a.rights.allowedActivities.push("waterings"),a.rights.allowedActivities.push("harvestings"),a.rights.allowedActivities.push("pestings"),a.rights.allowedActivities.push("activities")):a.rights.allowedActivities=[]),"readOnly"===e&&(a.rights.administrator=!1,a.rights.industryView=!1),this.setState({user:a,changed:!0})},this.handleEnableToggle=e=>t=>{const a={...this.state.user};a[e]=t.target.checked,this.setState({user:a,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,user:{rights:{administrator:!1,manageInventory:!1,createActivities:!1,allowedActivities:[],changeSettings:!1,readOnly:!0,viewDashboard:!1,industryView:!1},enabled:!0},errors:{count:0},changed:!1}}componentDidMount(){if(!this.props.isNew){const{user:e}=this.props;this.setState({user:e})}}validateField(e,t){const a=jn(e,this.state.user,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleSubmitAddExistingUser:r,handleUpdate:l,allowDelete:s,handleDeletePreExecute:o,handleDeleteDialogObject:c,handlePreExecute:d,getFromGlobalState:m}=this.props,{user:p,errors:h}=this.state,g=p.type&&("SentSharedInvite"===p.type||"SentInvite"===p.type),u=$n(p,Eo),b=m("userDetail").sk!==p.sk;return i.a.createElement(Ia,{open:t,dialogObject:p,setClose:n,setSnack:this.props.setSnack,isNew:a,handleUpdateDialogObject:l.bind(this),handlePreExecute:d.bind(this),skPrimary:"init_user_",dynamoType:"users",valid:!g&&u,deleteLabel:"Are you sure you want to remove this user ?",changed:this.state.changed,newTitle:"New User",title:null===p||void 0===p?void 0:p.name,getFromGlobalState:m,rejectedUser:p.rejected,handleSubmitAddExistingUser:r,allowDelete:s&&c&&b,handleDeletePreExecute:o,handleDeleteDialogObject:c?c.bind(this):void 0},g&&i.a.createElement(qn,{message:"Invitiations can not be edited once sent. You can edit the user post acceptance or you can delete the invitation."}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",disabled:g,autoFocus:!0,value:null===p||void 0===p?void 0:p.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.name||void 0,helperText:h.name}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"surname",label:"Surname",disabled:g,name:"surname",value:p.surname,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.surname||void 0,helperText:h.surname}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"email",label:"eMail",disabled:g||!a||void 0,name:"email",type:"email",inputProps:{autocapitalise:"none"},value:null===p||void 0===p?void 0:p.email,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.email||void 0,helperText:h.email}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"group",label:"Group",name:"group",value:null===p||void 0===p?void 0:p.group,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.group||void 0,helperText:h.group}),i.a.createElement(vn.a,{fullWidth:!0,component:"fieldset",disabled:g,className:e.formControl},i.a.createElement(kn.a,{component:"legend"},"Access rights"),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.readOnly,disabled:!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"readOnly",onChange:this.handleToggle("readOnly"),value:"readOnly",color:"secondary"}),label:"Read-only"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.administrator,name:"administrator",onChange:this.handleToggle("administrator"),value:"administrator",color:"secondary"}),label:"Administrator (change everything)"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.changeSettings,disabled:!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"changeSettings",onChange:this.handleToggle("changeSettings"),value:"changeSettings",color:"secondary"}),label:"Settings and documents"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.viewDashboard,disabled:!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"viewDashboard",onChange:this.handleToggle("viewDashboard"),value:"viewDashboard",color:"secondary"}),label:"Dashboard and reports"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.manageInventory,disabled:!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"manageInventory",onChange:this.handleToggle("manageInventory"),value:"manageInventory",color:"secondary"}),label:"Inventory"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.createActivities,disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"createActivities",onChange:this.handleToggle("createActivities"),value:"createActivities",color:"secondary"}),label:"Records"}),p.rights&&p.rights.createActivities&&i.a.createElement("div",{style:{marginLeft:"24px"}},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("fertilisings"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"fertilisings",onChange:this.handleToggleActivities("fertilisings"),value:"fertilisings",color:"secondary"}),label:"Fertiliser"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("sprayings"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"sprayings",onChange:this.handleToggleActivities("sprayings"),value:"sprayings",color:"secondary"}),label:"Plant Protection"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("waterings"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"waterings",onChange:this.handleToggleActivities("waterings"),value:"waterings",color:"secondary"}),label:"Irrigation"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("harvestings"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"harvestings",onChange:this.handleToggleActivities("harvestings"),value:"harvestings",color:"secondary"}),label:"Harvest"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("pestings"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"pestings",onChange:this.handleToggleActivities("pestings"),value:"pestings",color:"secondary"}),label:"Monitoring"}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.allowedActivities&&p.rights.allowedActivities.includes("activities"),disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"activities",onChange:this.handleToggleActivities("activities"),value:"activities",color:"secondary"}),label:"Agronomic Activities"})),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:p.rights&&p.rights.industryView,disabled:g||!(!p.rights||!p.rights.administrator||!0!==p.rights.administrator)||void 0,name:"industryView",onChange:this.handleToggle("industryView"),value:"industryView",color:"secondary"}),label:"Industry view"})),i.a.createElement(vn.a,{component:"fieldset",className:e.formControl},!p.shared&&i.a.createElement(kn.a,{component:"legend"},"Platform Status"),p.shared&&i.a.createElement(kn.a,{component:"legend"},"Farm Status"),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:!g&&p.enabled,disabled:g,id:"enabled",onChange:this.handleEnableToggle("enabled"),value:"enabled",color:"secondary"}),label:"Enabled"})))}}var Co=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{marginTop:e.spacing(3)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(So);class xo extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({userDialogOpen:!0})},this.componentDidMount=()=>{console.log(this.props.initialState);const e=!window.matchMedia("(min-width: 850px)").matches;let t={...this.state};t=e?[{id:"name",combine:[{id:"name",opacity:1},{id:"email",opacity:.6}],numeric:!1,disablePadding:!0,label:"Users"}]:[{id:"enabledText",numeric:!1,disablePadding:!1,label:"Enabled",maxWidth:"70px"},{id:"name",combine:[{id:"name",opacity:1},{id:"email",opacity:.6}],numeric:!1,disablePadding:!0,label:"Users"},{id:"group",numeric:!1,disablePadding:!1,label:"Group",maxWidth:"70px"}];const a=e;this.setState({headCells:t,clean:a})},this.handleBlur=e=>{},this.handleCloseModal=()=>{this.setState({confirmExistingUserAdd:!1})},this.handleDeleteDialogObject=e=>{const t=this.props.getFromGlobalState("users"),a=t.findIndex(t=>t.sk===e.sk);-1!==a&&t.splice(a,1),this.props.setGlobalState({users:t}),console.log("deleting user now",t)},this.handleUserDelete=async(e,t)=>{try{const{setGlobalState:t,getFromGlobalState:n}=this.props;if("SentSharedInvite"===e.type||e.rejected){this.setState({isSubmitting:!0}),await(a={type:"users",activeTenant:n("activeSite"),sk:e.sk,email:e.email},console.log("api post from storage"),o.a.del("farms","/sharedUserInviteDelete",{body:a}));const i=n("sentSharedInvites"),r=i.findIndex(t=>t.sk===e.sk);return-1!==r&&(i.splice(r,1),t({sentSharedInvites:i})),this.setState({isSubmitting:!1,success:!0}),e.rejected&&this.handleDeleteDialogObject(e),!1}if("SentInvite"===e.type){this.setState({isSubmitting:!0}),await function(e){return console.log("api post from storage"),o.a.del("farms","/userInviteDelete",{body:e})}({type:"users",activeTenant:n("activeSite"),sk:e.sk,email:e.email});const a=n("sentInvites"),i=a.findIndex(t=>t.sk===e.sk);return-1!==i&&(a.splice(i,1),t({sentInvites:a})),this.setState({isSubmitting:!1,success:!0}),!1}return!!e.shared||(this.setState({isSubmitting:!0}),await function(e){return console.log("api post from Storage"),o.a.post("farms","/deleteUser",{body:e})}({type:"users",activeTenant:n("activeSite"),sk:e.sk}),this.setState({isSubmitting:!1,success:!0}),!1)}catch(n){throw this.setState({success:!1,isSubmitting:!1,messageText:n.response?`${n.response.data.error}, api src: ${n.response.data.src} `:n.message}),n}var a},this.handleSubmitAddExistingUser=async e=>{try{const a=e&&(null===e||void 0===e?void 0:e.rejected)?{...null===e||void 0===e?void 0:e.rejected}:this.state.sharedUser;if(!a)return!1;this.setState({isLoadingShared:!0}),delete a.rejected,await(t=a,console.log("api post from storage"),o.a.post("farms","/sharedUserInvite",{body:t}));const n=this.props.getFromGlobalState("sentSharedInvites");a.type="SentSharedInvite",n.push(a),this.props.setGlobalState({sentSharedInvites:n}),this.setState({isLoadingShared:!1,userDialogOpen:!1,confirmExistingUserAdd:!1}),this.props.setSnack({open:!0,variant:"info",autoHideDuration:2e3,messageText:"User invitation sent."})}catch(a){return this.setState({isLoadingShared:!1,userDialogOpen:!1,confirmExistingUserAdd:!1}),this.props.setSnack({open:!0,variant:"error",messageText:a.response?`${a.response.data.error.message?a.response.data.error.message:a.response.data.error}, api src: ${a.response.data.src} `:a.message}),!1}var t},this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.state={expandedSetting:"",selectedUser:null,selectedVariety:null,modalObject:null,isNew:!1,userDialogOpen:!1,varietyDialogOpen:!1,errors:{},openModal:"",confirmExistingUserAdd:!1,sharedUser:null,isLoadingShared:!1,selectedTab:0,headCells:[]}}handleClickAdd(){this.setState({userDialogOpen:!0,isNew:!0,selectedUser:{}})}handleClickShowUser(e,t,a,n,i,r){let l=this.props.getFromGlobalState("users").find(e=>e.sk===a);l||(l=this.props.getFromGlobalState("sentInvites").find(e=>e.sk===a)),l||(l=this.props.getFromGlobalState("sentSharedInvites").find(e=>e.sk===a)),this.setState({selectedUser:l,selectedUserSK:a,userDialogOpen:"true",isNew:!1})}handleClickEdit(){this.setState({userDialogOpen:!0,isNew:!0})}setClose(){this.state.confirmExistingUserAdd||this.setState({userDialogOpen:!1})}setCloseVariety(){this.setState({varietyDialogOpen:!1})}hasEnableToggled(e){return{toggled:this.props.getFromGlobalState("users").find(t=>t.sk===e.sk).enabled!==e.enabled,enabled:e.enabled}}async handlePreExecute(e){const t=this.props.getFromGlobalState("activeSite");if(this.state.isNew)try{const t=await Da(e);return this.setState({isloading:!1}),e.userName=t.Username,this.props.setSnack({open:!0,variant:"info",autoHideDuration:4e3,messageText:"User invitation sent. You can view the user post acceptance."}),!1}catch(i){if(this.setState({isloading:!1}),i.response&&i.response.data&&i.response.data.error){if("UsernameExistsException"===i.response.data.error.code)return e.activeTenant=t,e.shared=!0,this.setState({confirmExistingUserAdd:!0,sharedUser:e}),!1;throw i}throw i}const a=this.hasEnableToggled(e);if(e.shared)return!0;if(!a.toggled)return!0;try{return a.enabled?await(n={sk:e.sk,type:"users",activeTenant:t},console.log("api post from Storage"),o.a.post("farms","/enableUser",{body:n})):await function(e){return console.log("api post from Storage"),o.a.post("farms","/disableUser",{body:e})}({sk:e.sk,type:"users",activeTenant:t}),this.setState({isloading:!1}),!0}catch(i){throw this.setState({isloading:!1}),i}var n}async handleUpdate(e){const t=this.props.getFromGlobalState("users").findIndex(t=>t.sk===e.sk);if(!e.shared)if(-1===t){const t=this.props.getFromGlobalState("sentInvites");e.type="SentInvite",t.push(e),this.props.setGlobalState({sentInvites:t})}else{const a=this.props.getFromGlobalState("users");a[t]=e,this.props.setGlobalState({users:a})}}render(){const{classes:e,initialState:t,allowDelete:a,handleDelete:n,getFromGlobalState:r}=this.props,{isLoadingShared:l,headCells:s,clean:o}=this.state,c=t,d=this.props.getFromGlobalState("sentInvites"),m=this.props.getFromGlobalState("sentSharedInvites"),p=r("userDetail");console.log(p);let h=c.filter(e=>!e.rejected&&!e.shared).map((e,t)=>{const a={...e};return a.name=`${a.name} ${a.surname}`,a.enabledText=a.enabled?"Yes":"No",a});const g=d?d.map((e,t)=>{const a={...e};return a.name=`${a.name} ${a.surname}`,a.surname=a.surname?a.surname:"No surname",a.enabledText="Pending",a}):[];h=h.concat(g);const u=c.filter(e=>e.rejected&&!e.shared).map((e,t)=>{const a={...e};return a.name=`${a.name} ${a.surname}`,a.enabledText=a.enabled?"Yes":"No",a});let b=c.filter(e=>!e.rejected&&e.shared).map((e,t)=>{const a={...e};return a.name=`${a.name} ${a.surname}`,a.enabledText=a.enabled?"Yes":"No",a});const v=m?m.map((e,t)=>{const a={...e};return a.name=" ",a.name=`${a.name} ${a.surname}`,a.surname=a.surname?a.surname:"No surname",a.enabledText="Pending",a}):[];return b=b.concat(v),i.a.createElement(O.a,{elevation:0,className:e.mainSection},this.state.userDialogOpen&&i.a.createElement(Co,{handleUpdate:this.handleUpdate.bind(this),open:this.state.userDialogOpen,setClose:this.setClose.bind(this),isNew:this.state.isNew,setSnack:this.props.setSnack,user:this.state.selectedUser,getFromGlobalState:this.props.getFromGlobalState,handlePreExecute:this.handlePreExecute.bind(this),handleDeletePreExecute:this.handleUserDelete.bind(this),handleSubmitAddExistingUser:this.handleSubmitAddExistingUser,allowDelete:"sentInvites"!==this.state.selectedUser.type,handleDeleteDialogObject:this.handleDeleteDialogObject?this.handleDeleteDialogObject.bind(this):void 0}),i.a.createElement(Mi,{value:this.state.selectedTab,handleChange:this.handleTabChange},i.a.createElement(Me,{userAvatar:!0,heading:"My users",displayToolbar:!0,hideHeading:!0,id:"userTable",noPagination:!0,rows:h,headCells:s,handleSelect:this.handleClickShowUser.bind(this),handleAddItem:p&&p.rights&&!p.rights.readOnly?this.handleClickAdd.bind(this):null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,padFirstCol:"5px",clean:!0,maxHeight:"350px",selectedRow:this.state.selectedUserSK}),i.a.createElement(Me,{userAvatar:!0,displayToolbar:!0,hideHeading:!0,id:"userTableShared",heading:"Shared Users",noPagination:!0,rows:b,maxHeight:"350px",headCells:s,handleSelect:this.handleClickShowUser.bind(this),actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,padFirstCol:"5px",clean:!0,selectedRow:this.state.selectedUserSK}),i.a.createElement(Me,{userAvatar:!0,hideHeading:!0,displayToolbar:!0,id:"userTableRejected",heading:"Rejected User Invitations",noPagination:!0,rows:u,headCells:s,handleSelect:this.handleClickShowUser.bind(this),actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,padFirstCol:"5px",clean:!0,maxHeight:"350px",selectedRow:this.state.selectedUserSK})),this.state.confirmExistingUserAdd&&i.a.createElement(Wt,{open:this.state.confirmExistingUserAdd,loading:l,title:"Shared User",actionText:"Add",message:"The user with this email address already has a profile on Land Diary. Do you want to invite the user to this farm? The access rights you have selected will apply.",handleConfirm:this.handleSubmitAddExistingUser.bind(this),handleCancel:this.handleCloseModal}))}}var ko=Object(v.a)(e=>({root:{flexGrow:1},aligner:{},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(xo);class wo extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({blockDialogOpen:!0})},this.handleBlur=()=>{},this.genIndex=e=>{const t=e;let a=0;for(let n=0;n{const{blockColors:n}=this.state;let i="#FFFFFF";if(t.color)if(n[t.sk]&&n[t.sk][a.sk])i=n[t.sk]&&n[t.sk][a.sk];else{const e=n.count+1;i=function(){let e,t=0;for(const a in le)Math.random()<1/++t&&(e=a);return e}();const r={...n};r[t.sk]||(r[t.sk]={}),r[t.sk][a.sk]||(r[t.sk][a.sk]={}),r[t.sk][a.sk]=i,r.count=e,this.setState({blockColors:r})}return i},this.mapBlockDetailsUploaded=async e=>{const{getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props;try{const i=[],r=t("activeSite"),l=re(await ie(e.file)),s=this.validateBlockDetails(l);let o=!1,c="";if(s.error)return n({open:!0,variant:"error",messageText:s.messageText}),null;const d=[...t("blocks")],m=[...t("crops")];if(!d||!d.length)return n({open:!0,variant:"error",messageText:"No blocks found. first upload your blocks using a google earth KML file or map the blocks directly."}),null;n({open:!0,variant:"info",messageText:`Creating ${l.length} blocks.`});const p=t("cropTypesSetting");for(const e of l){if(""===e.Block)continue;const t=d.find(t=>t.number===e.Block);if(!t){n({open:!0,variant:"error",messageText:`Block ${e.Block} not found on the map. Please upload this block.`});continue}t.soilType=e.Soil_Type,t.slope=e.Slope,t.irrigated="Dry land"!==e.Irrigation?"irrigated":"dryland",t.volumePerHour=e.Irrigation_rate_l_p_h,t.irrigationSystem=e.Irrigation,t.flowunit=e.Plant_or_ha?e.Plant_or_ha.toLowerCase():void 0;const a=await this.createPlantings(e,t,p);if(a.error||!a.planting){o=!0,c=a.messageText;break}t.plantings||(t.plantings=[]);const l=t.plantings.findIndex(e=>e.name===a.planting.name),s={...a.planting};s.activeTenant=r,-1===l?(s.sk=t.sk.concat("_planting_").concat(Rt.a.v1()),t.plantings.push(s),i.push(s)):(s.sk=t.plantings[l].sk,t.plantings[l]=s,i.push(s)),t.size||(t.size=0),t.size=parseFloat(t.sizeMap),t.activeTenant=r,t.color=this.getBlockColor(t,a.crop,a.cropDetail),t.type="blocks";const{plantings:h,...g}=t,u=i.findIndex(e=>e.sk===t.sk);-1===u?i.push(g):i[u]=g;if(-1===m.findIndex(e=>e.sk===a.crop.sk)){const e={};m.push(a.crop),e.genCropSK=a.crop.sk,e.type="gen_crops",e.sk="init_setting_"+Rt.a.v1(),i.push(e)}const b=m.find(e=>e.sk===a.crop.sk);b.varieties||(b.varieties=[]);if(-1===b.varieties.findIndex(e=>e.sk===a.cropDetail.sk)){b.varieties.push(a.cropDetail);const e={type:"gen_varieties"};e.genVarietySK=a.cropDetail.sk,e.sk=`${b.sk}_setchild_${Rt.a.v1()}`,i.push(e)}}if(o){n({open:!0,variant:"error",messageText:c+". Please rectify the data. Your data has not been saved"})}else{const e=i.map(e=>e.sk),r=i.reduce((e,t)=>(e[t.sk]=++e[t.sk]||0,e),{});console.log(i.filter(e=>r[e.sk]));new Set(i.map(e=>e.sk)).size,i.length;const l=e.some((t,a)=>e.indexOf(t)!==a);console.log(l);const s={items:i};s.activeTenant=t("activeSite"),s.type="batchupload",await fa(t("currentUser").username,"calls",ua(s,!0),this.props.getFromGlobalState("activeSite")),a({crops:m}),a({blocks:d}),n({open:!0,variant:"info",messageText:d.length+" blocks created."})}}catch(i){console.log(i),n({open:!0,variant:"error",messageText:Pa(i)})}},this.mapFileUploaded=async e=>{if(!e.serverId)return console.log("received undefined key"),null;const{setSnack:t}=this.props,a=await ie(e.file),n=await async function(e){const t=(new DOMParser).parseFromString(e,"text/xml"),a=[],n=[],i=[];if("kml"!==t.documentElement.nodeName)throw"error while parsing";for(const r of t.getElementsByTagName("Placemark")){if(!r.getElementsByTagName("name")||!r.getElementsByTagName("name")[0]){i.push("Blocks found without a name. Please provide a name for each block");continue}const e=r.getElementsByTagName("name")[0].childNodes[0].nodeValue.trim(),t=r.getElementsByTagName("Polygon"),l=r.getElementsByTagName("Point");for(const n of t){const t=n.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue.trim().split(" "),i=[];for(const e of t){const t=e.split(",");i.push({lat:parseFloat(t[1]),lng:parseFloat(t[0])})}a.push({name:e,googlePolygonsPaths:i})}for(const a of l){const t=a.getElementsByTagName("coordinates")[0].childNodes[0].nodeValue.trim().split(",");n.push({name:e,coord:{lat:parseFloat(t[1]),lng:parseFloat(t[0])}})}}return{markers:n,polygons:a,errors:i}}(a);n.errors&&n.errors.length&&t({open:!0,variant:"error",messageText:"At least one block without a name found. Please correct and upload again."}),this.insertBlocks(n),this.setState({changed:!0})},this.calculateHectarage=e=>{const t=e=>e*Math.PI/180,a=e.reduce((e,a,n,i)=>{if(n===i.length-1)return e;const r=i[n+1],l=t(a.lat),s=t(a.lng),o=t(r.lat);return e+(t(r.lng)-s)*(2+Math.sin(l)+Math.sin(o))},0);return(Math.abs(6371e3*a*6371e3/2)/1e4).toFixed(2)},this.insertBlocks=e=>{try{const{setGlobalState:t,getFromGlobalState:a}=this.props,n=[...a("blocks")];if(!e||!e.polygons)return null;for(const i of e.polygons){const e=new window.google.maps.Polygon({paths:i.googlePolygonsPaths}),t=window.google.maps.geometry.spherical.computeArea(e.getPath()),a={};a.sizeMap=t/1e4,a.sizeMap=a.sizeMap.toFixed(4),a.number=i.name,a.paths=i.googlePolygonsPaths,a.size=this.calculateHectarage(i.googlePolygonsPaths),a.color="#d3d3d3",a.strokeColor="#FFFFFF",a.sk="init_block_"+Rt.a.v1();const r=n.findIndex(e=>e.number===i.name);-1===r?n.push({...a}):n[r]=a}t({blocks:n}),this.setState({mapUploading:!1})}catch(t){alert(t)}},this.validateBlockDetails=e=>{const t={error:!1,messageText:""};e||(t.error=!0,t.messageText="No block details");const a=e.filter((e,t,a)=>a.findIndex(t=>t.Block===e.Block)===t);if(a.length===e.length)return t;for(const n of a){if(1!==e.filter(e=>e.Block===n.Block&&e.Planting===n.Planting).length){t.error=!0,t.messageText=`Block ${n.Block} contains duplicate planting names: ${n.Planting} in column Planting. Please make them distinct if you have more than one planting in this block.`;break}}return t},this.createCrop=async(e,t)=>{const a=t.findIndex(t=>t.sk===e.sk);if(-1!==a)return t[a];Rt.a.v1()},this.createPlantings=async(e,t,a)=>{if(!t||!e)return;const{getFromGlobalState:n,setGlobalState:i,setSnack:r}=this.props,l={},s=a.find(t=>t.name===e.Crop_type);if(!s)return{error:!0,messageText:`Crop type ${e.Crop_type} for block ${t.number} and plating ${e.name} not found in crop type database. Please confirm crop type name for planting ${e.Planting}`};const o=await La(n,i,r,s.sk),c=o.crops.find(t=>t.name===e.Crop_name);if(!c)return{error:!0,messageText:`Crop name ${e.Crop_name} not found in crops database. Please confirm crop for block ${t.number} and planting ${e.Planting}`};const d=o.cropsDetail.find(t=>t.cultivarType===e.Cultivar_type&&t.cultivar===e.Cultivar_name&&t.rootStockType===e.Rootstock_type&&t.rootStock===e.Rootstock_name);return d?(l.cropType=s.sk,l.crop=c.sk,l.name=e.Planting,e.Size_hectares&&parseFloat(e.Size_hectares.replace(",","."))>0&&(l.size=parseFloat(e.Size_hectares.replace(",","."))),l.date=function(e){const t=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/,a=/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;if(t.test(e)){const[a,n,i,r]=e.match(t).map(Number),l=`${r}-${String(i).padStart(2,"0")}-${String(n).padStart(2,"0")}`,s=new Date(l);if(!isNaN(s.getTime()))return s.toISOString().substr(0,10)}if(a.test(e)){const[t,n,i,r]=e.match(a).map(Number),l=`${r}-${String(n).padStart(2,"0")}-${String(i).padStart(2,"0")}`,s=new Date(l);if(!isNaN(s.getTime()))return s.toISOString().substr(0,10)}throw new Error("Invalid Date")}(e.Plant_Date),l.variety=d.sk,l.plantSpacing=parseFloat(e.Spacing_Inter_plant_in_m.replace(",",".")),isNaN(l.plantSpacing)?{error:!0,messageText:`Spacing_Inter_plant_in_m required for block ${t.number} planting ${e.Planting}. Names are case sensitive.`}:(l.plantDensity=parseFloat(e.Spacing_Intra_row_in_m.replace(",",".")),isNaN(l.plantDensity)?{error:!0,messageText:`Spacing_Inter_plant_in_m required for block ${t.number} planting ${e.Planting}. Names are case sensitive.`}:(l.totalPlants=parseFloat(e.Total_Plants.replace(",",".")),isNaN(l.totalPlants)?l.totalPlants=Qe(l.plantSpacing,l.plantDensity,l.size?l.size:t.sizeMap):l.totalPlantsOverride=!0,l.totalPlantsPerHa=parseFloat(e.Plants_ha.replace(",",".")),isNaN(l.totalPlantsPerHa)&&(l.totalPlantsPerHa=l.totalPlants/(l.size?l.size:t.sizeMap)),l.type="plantings",l.irrigated=t.irrigated,l.volumePerHour=t.volumePerHour,l.irrigationSystem=t.irrigationSystem,l.flowunit=t.flowunit,{planting:l,crop:c,cropDetail:d}))):{error:!0,messageText:`Crop name ${e.Crop_name}, cultivar type ${e.Cultivar_type}, cultivar name ${e.Cultivar_name}, rootstock type ${e.Rootstock_type}, rootstock name ${e.Rootstock_name} not found in crops database. Please confirm these details for block ${t.number} planting ${e.Planting}. Names are case sensitive.`}},this.state={selectedBlock:null,isNew:!1,blockDialogOpen:!1,selectedMapBlock:"",infoWindowPosition:null,mapUploading:!1,blockColors:{count:0},error:{},userLocation:null}}componentDidMount(){navigator.geolocation?navigator.geolocation.getCurrentPosition(e=>{const{latitude:t,longitude:a}=e.coords;this.setState({userLocation:{lat:t,lng:a}})},e=>{console.error("Error fetching user location:",e),this.setState({userLocation:null})}):(console.error("Geolocation is not supported by this browser."),this.setState({userLocation:null}))}handleClickAdd(){this.setState({blockDialogOpen:!0,isNew:!0,selectedBlock:{}})}handleClickShowBlock(e,t,a){const{getFromGlobalState:n}=this.props,i=n("blocks").find(e=>e.sk===a);this.setState({selectedBlock:i,selectedBlockSK:a,blockDialogOpen:"true",isNew:!1})}handleClickEdit(){this.setState({blockDialogOpen:!0,isNew:!0})}setClose(){this.setState({blockDialogOpen:!1})}handleUpdateBlocks(e){const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("blocks").findIndex(t=>t.sk===e.sk);if(-1===n){const n=t("blocks");n.push(e),a({blocks:n})}else{const i=t("blocks");i[n]=e,a({blocks:i})}}handleDeleteBlock(e){const{getFromGlobalState:t,setGlobalState:a}=this.props,n=t("blocks"),i=n.findIndex(t=>t.sk===e.sk);-1!==i?(n.splice(i,1),a({blocks:n})):alert("impossible - we don't have this block!")}onMapBlockClick(e,t){this.setState({selectedMapBlock:e,infoWindowPosition:{lat:t.latLng.lat(),lng:t.latLng.lng()}})}onCloseInfoWindow(){this.setState({selectedMapBlock:"",infoWindowPosition:null})}onMapClick(){this.setState({selectedMapBlock:"",infoWindowPosition:null})}onCloseMarker(){this.setState({selectedMarker:""})}onFileUploadStart(){this.setState({mapUploading:!0})}getColorIcon(e){return e||(e="grey"),i.a.createElement("div",{style:{height:"15px",width:"15px",backgroundColor:e}})}getBlockInfo(e){return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{variant:"h6"},e.number),i.a.createElement(B.a,{variant:"subtitle2"},` Size: ${e.size} ha`),i.a.createElement(B.a,{variant:"subtitle2"}," Soil Type: "+e.soilType),i.a.createElement(B.a,{variant:"subtitle2"}," Slope: "+e.slope),i.a.createElement(B.a,{variant:"subtitle2"}," Irrigation: "+("irrigated"===e.irrigated?"Irrigated":"Dry Land")),i.a.createElement(El.a,{href:"#",variant:"h6",onClick:this.mapEditBlock.bind(this,e.sk)},"Edit"))}mapEditBlock(e){const{getFromGlobalState:t}=this.props,a=t("blocks").find(t=>t.sk===e);this.setState({selectedBlock:a,selectedBlockSK:e,blockDialogOpen:"true",isNew:!1})}render(){const{classes:e,farm:t,getFromGlobalState:a}=this.props,{infoWindowPosition:n,mapUploading:r}=this.state,l=a("userDetail"),s=a("blocks");if(!t[0])return null;if(!s)return null;const o=s.map(e=>{const t={...e};return t.label=`${t.slope} slope, ${t.soilType} soil, ${e.irrigated?"irrigated"===e.irrigated?e.volumePerHour+"l/hour":"Dry land":e.volumePerHour+"l/hour"}`,t.color=this.getColorIcon(t.color),t}),c=[];let d=null;for(const i of s)if(i.paths){let e=i.color,t=1;i.sk===this.state.selectedMapBlock&&(d={label:i.number,position:n,content:this.getBlockInfo(i)},e="black",t=3),c.push({label:i.number,sk:i.sk,paths:i.paths,color:i.color,strokeColor:e,strokeWeight:t})}const m=ee(t[0].geoLocation)?ee(t[0].geoLocation):this.state.userLocation;return i.a.createElement(O.a,{elevation:0,className:e.mainSection},this.state.blockDialogOpen&&i.a.createElement(Zn,{handleUpdateBlocks:this.handleUpdateBlocks.bind(this),handleDeleteBlock:this.handleDeleteBlock.bind(this),allowDelete:!0,open:this.state.blockDialogOpen,setClose:this.setClose.bind(this),isNew:this.state.isNew,block:this.state.selectedBlock,otherBlockPolygons:c,metaData:this.props.getFromGlobalState("irrigations"),farm:this.props.getFromGlobalState("farm"),getFromGlobalState:this.props.getFromGlobalState,userLocation:this.state.userLocation}),i.a.createElement(qn,{message:"You can add your blocks by selecting the add block button below. You will be able to\r map your blocks. You can also import a KML file from google earth if you have already mapped them. Please ensure that the block name is used for the polygon name. The block details can be imported using a csv template."}),i.a.createElement(N,{isloading:r,style:{width:"100%",height:"500px"}},i.a.createElement(Wn,{center:m,polygons:c,onPolygonClick:this.onMapBlockClick.bind(this),onCloseInfoWindow:this.onCloseInfoWindow.bind(this),infoWindow:d,onClick:this.onMapClick.bind(this)})),i.a.createElement(bn.a,{shrink:!0,htmlFor:"kmlUploader"},"Import KML file"),i.a.createElement(nr,{activeTenant:this.props.getFromGlobalState("activeSite"),generateThumbnail:!1,id:"kmlUploader2",generatePreview:!1,onFileUploaded:this.mapFileUploaded.bind(this),folder:"maps/",getFromGlobalState:this.props.getFromGlobalState,allowMultiple:!1,forceName:!0,fileName:"farmKml.kml",error:this.state.error,acceptedFileTypes:["application/vnd.google-earth.kml+xml","text/xml","kml"]}),i.a.createElement(bn.a,{shrink:!0,htmlFor:"csvUploader"},"Import Block details using a .csv file"),i.a.createElement(nr,{activeTenant:this.props.getFromGlobalState("activeSite"),generateThumbnail:!1,id:"csvUploader",generatePreview:!1,onFileUploaded:this.mapBlockDetailsUploaded.bind(this),folder:"blockdetails/",getFromGlobalState:this.props.getFromGlobalState,allowMultiple:!1,forceName:!0,fileName:"blockdetails.csv",allowFileTypeValidation:!0,acceptedFileTypes:["text/csv","application/vnd.ms-excel"]}),i.a.createElement(Me,{displayToolbar:!0,id:"blockTable",heading:"",noPagination:!0,rows:o,headCells:[{id:"color",numeric:!0,label:"",disablePadding:!0,maxWidth:"10px"},{id:"number",combine:[{id:"number",opacity:1},{id:"label",opacity:.6}],numeric:!1,disablePadding:!1,label:"Number"},{id:"size",numeric:!0,disablePadding:!1,label:"Size (ha)"}],handleSelect:this.handleClickShowBlock.bind(this),handleAddItem:l&&l.rights&&!l.rights.readOnly?this.handleClickAdd.bind(this):null,actionType:"actionType",rowKeyName:"sk",clean:!0,maxHeight:"350px",selectedRow:this.state.selectedinventoryItemSK}))}}var To=Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},formControl:{width:"100%",minWidth:120,marginTop:e.spacing(2)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(wo);const Do=[{name:"name",min:1,max:25}];class Po extends n.Component{constructor(e){super(e),this.handleToggle=(e,t)=>{const{farms:a}=this.state,n={...a},i=n.settingsToCopy[t]?n.settingsToCopy[t].indexOf(e):-1;-1===i?(n.settingsToCopy[t]||(n.settingsToCopy[t]=[]),n.settingsToCopy[t].push(e)):n.settingsToCopy[t].splice(i,1),this.setState({farms:n,changed:!0})},this.handleBlur=e=>this.validateField(e.target.id,Do),this.handleChange=e=>{const{farms:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({farms:a,changed:!0})},this.handleCheckChange=e=>{const{farms:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({farms:a,changed:!0})},this.state={isNew:this.props.isNew,farms:{},errors:{count:0},changed:!1}}componentDidMount(){const{isNew:e,getFromGlobalState:t,selectedSetting:a}=this.props;if(e){const e=t("farm")&&t("farm")[0]?t("farm")[0].sk:"";this.props.parentFarm?this.setState({farms:{parentFarm:this.props.parentFarm,settingsToCopy:{},entityType:"farm"}}):this.setState({farms:{parentFarm:e,settingsToCopy:{},entityType:"farm"}})}else{const e=a;this.setState({farms:e})}}async handlePreExecute(e){const{isNew:t}=this.state,{getFromGlobalState:a}=this.props;try{let m;var n,i;if(e.isNew=t,e.activeTenant=a("activeSite"),m=await(d=e,console.log("api post from Storage"),o.a.post("farms","/addSite",{body:d},{Headers:{"Content-type":"application/json"}})),t)e.newTenant=null===(n=m.newTenant)||void 0===n||null===(i=n.item)||void 0===i?void 0:i.tenantId;const p=a("siteList"),h=p.findIndex(e=>{var t,a,n;return e.tenantId===(null===(t=m)||void 0===t||null===(a=t.newTenant)||void 0===a||null===(n=a.item)||void 0===n?void 0:n.tenantId)});var r,l,s,c;if(-1===h)p.push(null===(r=m)||void 0===r||null===(l=r.newTenant)||void 0===l?void 0:l.item);else p[h]=null===(s=m)||void 0===s||null===(c=s.newTenant)||void 0===c?void 0:c.item;this.props.setGlobalState({siteList:p})}catch(m){throw m}var d;return!0}validateField(e,t){const a=jn(e,this.state.farms,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{open:e,isNew:t,setClose:a,handleUpdate:n,getFromGlobalState:r}=this.props,{farms:l,errors:s}=this.state,o=$n(l,Do);console.log(l);const c=window.location.pathname.includes("admin");return i.a.createElement(Ia,{open:e,dialogObject:l,setClose:a,isNew:t,handleUpdateDialogObject:n.bind(this),skPrimary:"init_setting_",dynamoType:"farms",valid:o,parentKey:l.parentFarm,changed:this.state.changed,newTitle:l.parentSk,title:l.name,getFromGlobalState:r,handlePreExecute:this.handlePreExecute.bind(this)},i.a.createElement(g.a,{container:!0,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Short Name",name:"name",autoFocus:!0,value:l.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.name||void 0,helperText:s.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"description",label:"Description",name:"description",value:l.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.description||void 0,helperText:s.description})),c&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"discount",label:"Discount",name:"discount",value:l.discount,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.description||void 0,helperText:s.description})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:l.isDisabled,id:"isDisabled",onChange:this.handleCheckChange,value:"isDisabled",color:"secondary"}),label:"Disabled"}))))}}var Fo=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Po);const No=[{name:"name",min:1,max:100}];class Bo extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,No),this.handleChange=e=>{const t={...this.state.facility};t[e.target.id]=e.target.value,this.setState({facility:t,changed:!0})},this.state={isloading:!1,facility:{},errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({facility:{}});else{const e=this.props.selectedSetting;this.setState({facility:e})}}validateField(e,t){const a=jn(e,this.state.facility,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,metaData:l,getFromGlobalState:s}=this.props,{facility:o,errors:c}=this.state,d=$n(o,No);return i.a.createElement(Ia,{open:t,dialogObject:o,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"facilities",valid:d,changed:this.state.changed,newTitle:"New facility",title:o.name,getFromGlobalState:s},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:o.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.name||void 0,helperText:c.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"discription",label:"Discription",name:"discription",value:o.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.discription||void 0,helperText:c.discription}))))}}Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},margin:{margin:e.spacing(1)},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Bo);const Lo=[{name:"productProcessor",min:1,max:200},{name:"enabled",min:1,max:100}];class Ao extends n.Component{constructor(e){super(e),this.handleDelete=e=>{const t={...this.state.operator},a=t&&t.roles.findIndex(t=>t===e);-1!==a&&t.roles.splice(a,1),this.setState({operator:t,changed:!0})},this.onSelectAll=()=>{const{operator:e,roles:t}=this.state,a={...e};a.allSelected?(a.allSelected=!1,a.roles=[]):(a.allSelected=!0,a.roles=[],a.roles=t.map(e=>e.sk)),this.setState({operator:a,changed:!0})},this.handleToggle=e=>{const{operator:t}=this.state,a={...t};a.roles||(a.roles=[]);const n=t&&t.roles.findIndex(t=>t===e);-1===n?a.roles.push(e):a.roles.splice(n,1),this.setState({operator:a,changed:!0})},this.handleBlur=e=>this.validateField(e.target.id,Lo),this.handleChange=e=>{const{operator:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({operator:a,changed:!0})},this.handleCountryChange=e=>{const{allProductProcessors:t,selectedCrop:a,selectedProvince:n}=this.state,i=e.target.value;let r=[...t];i&&(r=r.filter(e=>e.country===i)),r=a?this.filterCropChange(r,i,n,{target:{value:a}}):r.filter(e=>!e.processingCrops),this.setState({selectedCountry:i,productProcessors:r,selectedProvince:"",selectedProductProcessor:"",changed:!0})},this.handleProvinceChange=e=>{const{allProductProcessors:t,selectedCountry:a,selectedCrop:n}=this.state,i=e.target.value;let r=[...t];a&&(r=r.filter(e=>e.country===a)),i&&(r=r.filter(e=>e.province===i)),r=n?this.filterCropChange(r,a,i,{target:{value:n}}):r.filter(e=>!e.processingCrops),this.setState({selectedProvince:i,productProcessors:r,changed:!0})},this.filterCropChange=(e,t,a,n)=>{const i=n.target.value;let r=[...e],l=[];if(t&&(r=r.filter(e=>e.country===t)),a&&(r=r.filter(e=>e.province===a)),i){r=r.filter(e=>e.processingCrops);for(let e=0;e!e.processingCrops);return l},this.handleCropChange=e=>{const{allProductProcessors:t,selectedCountry:a,selectedProvince:n}=this.state,i=this.filterCropChange(t,a,n,e),r=e.target.value;this.setState({selectedCrop:r,productProcessors:i,selectedProductProcessor:"",changed:!0})},this.handleProcessorChange=e=>{const{myProductProcessor:t}=this.state,a={...t},n=e.target.value;a.productProcessor=n,this.setState({selectedProductProcessor:n,myProductProcessor:a,changed:!0})},this.handleProcessorTypeChange=async e=>{const{selectedProcessorType:t}=this.state,a=e.target.value,{getFromGlobalState:n,setSnack:i,setGlobalState:r}=this.props;if(t!==a)try{this.setState({isLoading:!0});const e=n("activeSite"),t=await xa(e,a.concat("_")),i=t?[...new Set(t.map(e=>e.country))]:[],l=t?[...new Set(t.map(e=>e.province))]:[],s=t.filter(e=>!e.processingCrops),o=[...n("productProcessors")];for(let a=0;ae.sk===t[a].sk)&&o.push(t[a])}r({productProcessors:o}),this.setState({selectedProcessorType:a,allProductProcessors:t,productProcessors:s,isLoading:!1,countries:i,provinces:l,selectedCountry:"",selectedProvince:"",changed:!0})}catch(l){i({open:!0,variant:"error",messageText:Pa(l)}),this.setState({isLoading:!1})}},this.handleCheckChange=e=>{const{myProductProcessor:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({myProductProcessor:a,changed:!0})},this.onDisable=()=>{const{myProductProcessor:e}=this.state,t={...e};t.disabled?t.disabled=!1:t.disabled=!0,this.setState({myProductProcessor:t,changed:!0})};const{handleUpdate:t}=this.props;this.handleUpdate=t.bind(this),this.state={selectedProcessorType:"",myProductProcessor:{},isLoading:!1,productProcessors:[],allProductProcessors:[],errors:{count:0},changed:!1,countries:[],provinces:[],selectedCountry:"",selectedProvince:"",selectedCrop:"",selectedProductProcessor:"",processorName:"",processorTypeName:"",isNew:!1}}componentDidMount(){const{isNew:e,selectedSetting:t,getFromGlobalState:a}=this.props;if(e)this.setState({isNew:e,myProductProcessor:{enabled:!0}});else{const n=t,i=a("productProcessors").find(e=>e.sk===n.productProcessor),r=i.sk.substring(0,i.sk.indexOf("_setchild_")),l=a("productProcessorTypes"),s=l?l.find(e=>e.sk===r).name:"",{countries:o,provinces:c,productProcessors:d}=this.state,m=[...o];m.push(i.country);const p=[...c];p.push(i.province);const h=[...d];h.push(i),this.setState({isNew:e,myProductProcessor:n,selectedProcessorType:r,selectedCountry:i.country,selectedProvince:i.province,processorName:i.name,processorTypeName:s,selectedProductProcessor:n.productProcessor,countries:m,provinces:p,productProcessors:h})}}validateField(e){const{myProductProcessor:t,errors:a}=this.state,n=jn(e,t,Lo),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,setClose:a,getFromGlobalState:n}=this.props,{isNew:r,selectedProcessorType:l,errors:s,changed:o,myProductProcessor:c,productProcessors:d,countries:m,provinces:p,allProductProcessors:h,selectedCountry:u,selectedProvince:b,selectedCrop:v,selectedProductProcessor:y,processorName:f,processorTypeName:E}=this.state,S=n("productProcessorTypes"),C=n("crops"),x=$n(c,Lo);return i.a.createElement(Ia,{open:t,dialogObject:c,setClose:a,isNew:r,handleUpdateDialogObject:this.handleUpdate,skPrimary:"init_setting_",dynamoType:"myProductProcessors",valid:x,changed:o,onDisable:this.onDisable,newTitle:"New processor",title:c.name,getFromGlobalState:n,allowDelete:!0},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:c.enabled,id:"enabled",onChange:this.handleCheckChange,value:"enabled",color:"secondary"}),label:"Enabled"})),i.a.createElement(i.a.Fragment,null," ",i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Processor Type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,disabled:!r,displayEmpty:!0,value:l,onChange:this.handleProcessorTypeChange,onBlur:this.handleBlur,inputProps:{name:"productProcessorType",id:"productProcessorType"}},i.a.createElement("option",{value:""}),S&&S.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Country"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,disabled:0===h.length,displayEmpty:!0,value:u,onChange:this.handleCountryChange,onBlur:this.handleBlur,inputProps:{name:"selectedCountry",id:"selectedCountry"}},i.a.createElement("option",{value:""}),m&&m.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Province"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:0===h.length,value:b,onChange:this.handleProvinceChange,onBlur:this.handleBlur,inputProps:{name:"selectedProvince",id:"selectedProvince"}},i.a.createElement("option",{value:""}),p&&p.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e},e)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Crop"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:0===h.length,value:c.selectedCrop,onChange:this.handleCropChange,onBlur:this.handleBlur,inputProps:{name:"selectedCrop",id:"selectedCrop"}},i.a.createElement("option",{value:""},"Not crop specific"),C&&C.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Processors"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,disabled:0===h.length,value:y,onChange:this.handleProcessorChange,onBlur:this.handleBlur,inputProps:{name:"selectedProductProcessor",id:"selectedProductProcessor"}},i.a.createElement("option",{value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))))),!1,i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:8,lg:8,xl:8})))}}Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},margin:{margin:e.spacing(1)},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Ao);const Oo=Ua.f.create({body:{paddingTop:35,paddingBottom:55,paddingHorizontal:35},sectionRight:{marginBottom:10,paddingBottom:10,textAlign:"right",width:"60%"},sectionLeft:{marginBottom:10,paddingBottom:10,width:"40%"},section:{display:"flex",flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"},sectionNoPadLeft:{margin:10,padding:10,marginLeft:0,paddingLeft:0},textHeader:{fontSize:24,paddingBottom:10},textSubHeader:{fontSize:14},textOpac:{fontSize:10,opacity:.6},text:{fontSize:10},table:{display:"table",width:"auto",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderRightWidth:0,borderBottomWidth:0},tableRow:{margin:"auto",flexDirection:"row"},tableCol1Header:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableColHeader:{borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol1:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol:{borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCellHeader:{margin:3,fontSize:10,fontWeight:500},tableCell:{margin:3,fontSize:8},tableCellStrong:{margin:3,fontSize:8,fontWeight:"bold"},pageNumber:{position:"absolute",fontSize:12,bottom:30,left:0,right:0,textAlign:"right",color:"grey",paddingRight:20,marginRight:20},logoText:{position:"absolute",fontSize:10,bottom:30,left:20,textAlign:"left",textDecoration:"none"},logo:{width:30,height:30,paddingLeft:2},farmLogo:{maxWidth:"150px"}}),Io=e=>i.a.createElement(Ua.h,{style:Oo.table},i.a.createElement(Ua.h,{fixed:!0,style:Oo.tableRow},e.data.headCells&&e.data.headCells.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Oo.tableColHeader,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:Oo.tableCellHeader},t.label))))),e.data.rows&&e.data.rows.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:Oo.tableRow},e.data.headCells&&e.data.headCells.map(a=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Oo.tableCol,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:t.strong?Oo.tableCellStrong:Oo.tableCell},$(a,t[a.id],e.data.locale))))))))),Go=e=>i.a.createElement(Ua.h,{wrap:!1,style:Oo.section},e.logoURL&&i.a.createElement(Ua.h,{style:Oo.sectionLeft},i.a.createElement(Ua.b,{cache:!0,style:Oo.farmLogo,src:e.logoURL})),!e.logoURL&&i.a.createElement(Ua.h,{style:Oo.sectionLeft}),i.a.createElement(Ua.h,{style:Oo.sectionRight},i.a.createElement(Ua.g,{style:Oo.textHeader},e.farm.name),e.farm.gapnum&&i.a.createElement(Ua.g,{style:Oo.textOpac},"GLOBAL.G.A.P: "+e.farm.gapnum),e.farm.puc&&i.a.createElement(Ua.g,{style:Oo.textOpac},"Production Unit Code (PUC): "+e.farm.puc),e.farm.vatNo&&i.a.createElement(Ua.g,{style:Oo.textOpac},"VAT Number: "+e.farm.vatNo),i.a.createElement(Ua.g,{style:Oo.textOpac},"Tel: "+e.farm.contactNum),i.a.createElement(Ua.g,{style:Oo.textOpac},"email: "+e.farm.email),e.farm.geoLocation&&i.a.createElement(Ua.g,{style:Oo.textOpac},"Geolocation: "+(e.farm.geoLocation.lat&&e.farm.geoLocation.lng?`Lat: ${e.farm.geoLocation.lat.toFixed(7)} Lng: ${e.farm.geoLocation.lng.toFixed(7)}`:e.farm.geoLocation)),i.a.createElement(Ua.g,{style:Oo.textOpac},"Address: "+e.farm.address1),i.a.createElement(Ua.g,{style:Oo.textOpac},""+e.farm.address2),i.a.createElement(Ua.g,{style:Oo.textOpac},""+e.farm.country),i.a.createElement(Ua.g,{style:Oo.textOpac},""+e.farm.province),i.a.createElement(Ua.g,{style:Oo.textOpac},""+e.farm.pCode))),Ro=e=>i.a.createElement(Ua.a,null,i.a.createElement(Ua.e,{size:"A4",style:Oo.body,orientation:"landscape"},i.a.createElement(Go,e),i.a.createElement(Ua.h,{style:[Oo.sectionNoPadLeft,{paddingBottom:0,paddingTop:0,marginTop:0,marginBottom:0}]},i.a.createElement(Ua.g,{style:Oo.textSubHeader},"Record Type: "+e.recordTypeLabel),i.a.createElement(Ua.g,{style:Oo.textOpac},"Report Date: "+_()),e.startDate&&e.endDate&&i.a.createElement(Ua.g,{style:Oo.textOpac},`Report range: From: ${e.startDate} To: ${e.endDate}`)),i.a.createElement(Ua.h,{style:Oo.sectionNoPadLeft},i.a.createElement(Ua.g,{style:Oo.textSubHeader},e.data.title)),i.a.createElement(Io,e),i.a.createElement(Ua.g,{style:Oo.pageNumber,render:({pageNumber:e,totalPages:t})=>`Page: ${e} / ${t}`,fixed:!0}),i.a.createElement(Ua.h,{wrap:!1,style:Oo.logoText},i.a.createElement(Ua.c,{style:{textDecoration:"none"},wrap:!1,src:"landdiary.com"},i.a.createElement(Ua.g,{wrap:!1,style:{borderRadius:3,paddingLeft:"3px",paddingBottom:"2px"}},i.a.createElement(Ua.b,{style:Oo.logo,src:Ka.a})," ")))));class Uo extends n.Component{constructor(e){super(e),this.getLogoUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0},logoURL:void 0}}async componentDidMount(){if(this.props.farm&&this.props.farm.logoKey){const e=await this.getLogoUrl(this.props.farm.logoKey,this.props.farm.logoFileType);this.setState({logoURL:e})}}render(){const{recordType:e,farm:t,getFromGlobalState:a,blocks:n,startDate:r,endDate:l,onDownloaded:s,recordTypeLabel:o,averagedReport:c}=this.props,d=tt(e,n,a,void 0,void 0,void 0,r,l,null,null);d.headCells&&(d.headCells=d.headCells.filter(e=>"icon"!==e.type));const{logoURL:m}=this.state;return t.logoKey&&!m?i.a.createElement("div",{style:{color:"inherit",float:"right",marginLeft:"auto"}},i.a.createElement(la,{key:"pdf",onClick:s,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:!0,disabled:!0})):i.a.createElement(Ua.d,{document:i.a.createElement(Ro,{data:d,recordType:e,recordTypeLabel:o,farm:t,startDate:r,endDate:l,logoURL:m}),fileName:`${t.name} ${d.title} ${_()}`,style:{color:"inherit",float:"right",marginLeft:"auto"}},({blob:e,url:t,loading:a,error:n})=>i.a.createElement(la,{key:"pdf",onClick:s,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:a,disabled:a}))}}var Mo=Object(v.a)(Oo)(Uo);class Wo extends n.Component{constructor(e){super(e),this.state={csvData:[],loading:!1,title:""}}componentDidMount(){const{recordType:e,getFromGlobalState:t,blocks:a,startDate:n,endDate:i,averagedReport:r}=this.props;this.setState({loading:!0});const l=tt(e,a,t,void 0,void 0,void 0,n,i,null,null);l.headCells&&(l.headCells=l.headCells.filter(e=>"icon"!==e.type));const s=[];s.push(l.headCells.map(e=>e.label));for(let o=0;o({id:e,label:e,type:""}));s=s.filter(e=>"icon"!==e.type);const o=[];o.push(s.map(e=>e.label)),l.transactions.forEach(e=>{const t=s.map(t=>e[t.id]||"");o.push(t)}),this.setState({csvData:o,loading:!1,title:"Transaction Records"})}render(){const{recordType:e,getFromGlobalState:t,blocks:a,startDate:n,endDate:r,onDownloaded:l,farm:s}=this.props,{csvData:o,loading:c,title:d}=this.state;return i.a.createElement(_a.CSVLink,{data:o,filename:`${d} ${_()}`},i.a.createElement(la,{key:"csv",onClick:l,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:c,disabled:c}))}}var Ho=Ko;const qo=Ua.f.create({body:{paddingTop:35,paddingBottom:55,paddingHorizontal:35},sectionRight:{marginBottom:10,paddingBottom:10,textAlign:"right",width:"60%"},sectionLeft:{marginBottom:10,paddingBottom:10,width:"40%"},section:{display:"flex",flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"},sectionNoPadLeft:{margin:10,padding:10,marginLeft:0,paddingLeft:0},textHeader:{fontSize:24,paddingBottom:10},textSubHeader:{fontSize:14},textOpac:{fontSize:10,opacity:.6},text:{fontSize:10},table:{display:"table",width:"auto",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderRightWidth:0,borderBottomWidth:0},tableRow:{margin:"auto",flexDirection:"row"},tableCol1Header:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableColHeader:{borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol1:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol:{borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCellHeader:{margin:3,fontSize:10,fontWeight:500},tableCell:{margin:3,fontSize:8},tableCellStrong:{margin:3,fontSize:8,fontWeight:"bold"},pageNumber:{position:"absolute",fontSize:12,bottom:30,left:0,right:0,textAlign:"right",color:"grey",paddingRight:20,marginRight:20},logoText:{position:"absolute",fontSize:10,bottom:30,left:20,textAlign:"left",textDecoration:"none"},logo:{width:30,height:30,paddingLeft:2},farmLogo:{maxWidth:"150px"}}),Vo=e=>i.a.createElement(Ua.h,{style:qo.table},i.a.createElement(Ua.h,{fixed:!0,style:qo.tableRow},e.data.headCells&&e.data.headCells.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[qo.tableColHeader,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:qo.tableCellHeader},t.label))))),e.data.transactions&&e.data.transactions.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:qo.tableRow},e.data.headCells&&e.data.headCells.map(a=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[qo.tableCol,{width:100/e.data.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:t.strong?qo.tableCellStrong:qo.tableCell},$(a,t[a.id],e.data.locale))))))))),jo=e=>i.a.createElement(Ua.h,{wrap:!1,style:qo.section},e.logoURL&&i.a.createElement(Ua.h,{style:qo.sectionLeft},i.a.createElement(Ua.b,{cache:!0,style:qo.farmLogo,src:e.logoURL})),!e.logoURL&&i.a.createElement(Ua.h,{style:qo.sectionLeft}),i.a.createElement(Ua.h,{style:qo.sectionRight},i.a.createElement(Ua.g,{style:qo.textHeader},e.farm.name),e.farm.gapnum&&i.a.createElement(Ua.g,{style:qo.textOpac},"GLOBAL.G.A.P: "+e.farm.gapnum),e.farm.puc&&i.a.createElement(Ua.g,{style:qo.textOpac},"Production Unit Code (PUC): "+e.farm.puc),e.farm.vatNo&&i.a.createElement(Ua.g,{style:qo.textOpac},"VAT Number: "+e.farm.vatNo),i.a.createElement(Ua.g,{style:qo.textOpac},"Tel: "+e.farm.contactNum),i.a.createElement(Ua.g,{style:qo.textOpac},"email: "+e.farm.email),e.farm.geoLocation&&i.a.createElement(Ua.g,{style:qo.textOpac},"Geolocation: "+(e.farm.geoLocation.lat&&e.farm.geoLocation.lng?`Lat: ${e.farm.geoLocation.lat.toFixed(7)} Lng: ${e.farm.geoLocation.lng.toFixed(7)}`:e.farm.geoLocation)),i.a.createElement(Ua.g,{style:qo.textOpac},"Address: "+e.farm.address1),i.a.createElement(Ua.g,{style:qo.textOpac},""+e.farm.address2),i.a.createElement(Ua.g,{style:qo.textOpac},""+e.farm.country),i.a.createElement(Ua.g,{style:qo.textOpac},""+e.farm.province),i.a.createElement(Ua.g,{style:qo.textOpac},""+e.farm.pCode))),$o=e=>i.a.createElement(Ua.a,null,i.a.createElement(Ua.e,{size:"A4",style:qo.body,orientation:"landscape"},i.a.createElement(jo,e),i.a.createElement(Ua.h,{style:[qo.sectionNoPadLeft,{paddingBottom:0,paddingTop:0,marginTop:0,marginBottom:0}]},i.a.createElement(Ua.g,{style:qo.textSubHeader},"Record Type: Transaction Records"),i.a.createElement(Ua.g,{style:qo.textOpac},"Report Date: "+_()),e.startDate&&e.endDate&&i.a.createElement(Ua.g,{style:qo.textOpac},`Report range: From: ${e.startDate} To: ${e.endDate}`)),i.a.createElement(Ua.h,{style:qo.sectionNoPadLeft},i.a.createElement(Ua.g,{style:qo.textSubHeader},"Transactions")),i.a.createElement(Vo,e),i.a.createElement(Ua.g,{style:qo.pageNumber,render:({pageNumber:e,totalPages:t})=>`Page: ${e} / ${t}`,fixed:!0}),i.a.createElement(Ua.h,{wrap:!1,style:qo.logoText},i.a.createElement(Ua.c,{style:{textDecoration:"none"},wrap:!1,src:"landdiary.com"},i.a.createElement(Ua.g,{wrap:!1,style:{borderRadius:3,paddingLeft:"3px",paddingBottom:"2px"}},i.a.createElement(Ua.b,{style:qo.logo,src:Ka.a})," ")))));class Yo extends n.Component{constructor(e){super(e),this.getLogoUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0},logoURL:void 0}}async componentDidMount(){if(this.props.farm&&this.props.farm.logoKey){const e=await this.getLogoUrl(this.props.farm.logoKey,this.props.farm.logoFileType);this.setState({logoURL:e})}}render(){var e;const{recordType:t,farm:a,getFromGlobalState:n,blocks:r,startDate:l,endDate:s,onDownloaded:o,recordTypeLabel:c}=this.props,d=et(n,l,s);let m=null===d||void 0===d||null===(e=d.headCells)||void 0===e?void 0:e.map(e=>({id:e,label:e,type:""}));m=m.filter(e=>"icon"!==e.type),d.headCells&&(d.headCells=m),console.log("data",d);const{logoURL:p}=this.state;return a.logoKey&&!p?i.a.createElement("div",{style:{color:"inherit",float:"right",marginLeft:"auto"}},i.a.createElement(la,{key:"pdf",onClick:o,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:!0,disabled:!0})):i.a.createElement(Ua.d,{document:i.a.createElement($o,{data:d,recordType:t,recordTypeLabel:c,farm:a,startDate:l,endDate:s,logoURL:p}),fileName:"Transactions "+_(),style:{color:"inherit",float:"right",marginLeft:"auto"}},({blob:e,url:t,loading:a,error:n})=>i.a.createElement(la,{key:"pdf",onClick:o,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:a,disabled:a}))}}var _o=Object(v.a)(qo)(Yo);var Zo=function(e){var t,a;const{sub:r,setSnack:l,setGlobalState:s}=e,[o,c]=Object(n.useState)(!1);return console.log(e),i.a.createElement("div",null,i.a.createElement(u.a,null,i.a.createElement(y.a,{titleTypographyProps:{fontSize:12},style:{backgroundColor:"#0e4553",color:"#fff",fontSize:12}}),i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},"Cancelled"==r.status?"---":"R"+(null===(t=r.totalPrice)||void 0===t?void 0:t.toFixed(2))+"p/m"),o?i.a.createElement(F,null):"Cancelled"==r.status?i.a.createElement(i.a.Fragment,null,i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},r.status),i.a.createElement("p",{style:{fontSize:12,textAlign:"center"}},"Subscription Status"),i.a.createElement("p",{style:{fontSize:12,textAlign:"center"}},"Active Until ",function(e){const t=new Date(e),a=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0");return`${String(t.getDate()).padStart(2,"0")}-${n}-${a}`}(r.nextSubscription))):i.a.createElement(b.a,null,i.a.createElement(zt.a,{type:"text",fullWidth:!0,label:"Primary Card",value:"*************"+((null===r||void 0===r?void 0:r.subscriptionMaskedCreditCardNumber)?null===r||void 0===r||null===(a=r.subscriptionMaskedCreditCardNumber)||void 0===a?void 0:a.slice(-4):"********42321")}),i.a.createElement(zt.a,{style:{marginTop:20},type:"text",label:"Expiry",value:"032026"})),!o&&("Active"==r.status||"True"==r.status)&&i.a.createElement(f.a,null,i.a.createElement(Ct.a,{style:{width:"100%"},onClick:async()=>{try{c(!0),await Sa({...r,status:"False"}),c(!1),l({open:!0,variant:"info",messageText:"Subscription successfully cancelled"}),r.status="Cancelled",s({subscription:[{...r}]})}catch(e){c(!1),l({open:!0,variant:"error",messageText:"Failed to Cancel Subsciption"})}},variant:"contained",color:"primary"},"Cancel Subscription")),!o&&"Cancelled"==r.status&&i.a.createElement(f.a,null,i.a.createElement(Ct.a,{style:{width:"100%"},onClick:async()=>{try{c(!0),await Sa({...r,status:"Active"}),c(!1),l({open:!0,variant:"info",messageText:"Subscription successfully reactivated"}),r.status="Active",s({subscription:[{...r}]})}catch(e){c(!1),l({open:!0,variant:"error",messageText:"Failed to Activate Subsciption"})}},variant:"contained",color:"primary"},"Activate Subscription"))))};const Jo=[{name:"Harvest",sk:"harvestings"},{name:"Irrigate",sk:"waterings"},{name:"Fertilise",sk:"fertilisings"},{name:"Monitor",sk:"pestings"},{name:"Agronomic Activities",sk:"activities"},{name:"Plant Protection",sk:"sprayings"}];class Qo extends n.Component{constructor(e){super(e),this.updateGlobalState=(e,t)=>{const a={...this.props.getFromGlobalState("settings")};a[t]=e,this.props.setGlobalState({settings:a})},this.setReportStartDate=e=>{this.setState({reportStartDate:e.target.value})},this.setReportEndDate=e=>{this.setState({reportEndDate:e.target.value})},this.handleSubmit=async(e,t)=>{t.preventDefault(),this.setState({isSubmitting:!0}),this.setState({messageText:""});try{e.sk||(e.sk="init_set_crops_"+Rt.a.v1(),e.type="settings",e.version=0);const t=e.version?e.version:0;e.version=t+1;let a={};e.activeTenant=this.props.getFromGlobalState("activeSite"),a=await ya(this.props.getFromGlobalState("currentUser").username,"calls",ua(e),this.props.getFromGlobalState("activeSite")),a.status&&(e.cached=a.cached),this.setState({isSubmitting:!1}),this.setState({success:!0}),this.updateGlobalState(e,"set_crops"),this.props.setClose()}catch(a){this.setState({success:!1,isSubmitting:!1,messageText:a.response?`${a.response.data.error.message}, api src: ${a.response.data.src} `:a.message})}},this.handleChange=(e,t)=>{const a={...this.props.getFromGlobalState("settings")};a[e][t.target.id]=t.target.value,this.props.setGlobalState({settings:a})},this.handleAddChange=(e,t,a)=>{const n={...this.props.getFromGlobalState("settings")};n[t]||(n[t]=[]),n[t].push(e),this.props.setGlobalState({settings:n})},this.roleString=e=>{if(!e)return"";let t=Jo.filter(t=>e.includes(t.sk));return t=t.map(e=>e.name),function(e){if(!e)return"";const t=e.length;let a,n="";for(a=0;a{const n={...this.props.getFromGlobalState("settings")},i=n[e].findIndex(e=>e.sk===t);-1!==i&&(n[e][i][a.target.id]=a.target.value,this.props.setGlobalState({settings:n}))},this.comparer=e=>t=>0===e.filter(e=>e.tenantId===t.farmId).length,this.filterSites=(e,t)=>{if(console.log("sites","farms",e,t,this.props.getFromGlobalState("allfarms")),!t)return[];return t.filter(t=>e.some(e=>(null===e||void 0===e?void 0:e.tenantId)===(null===t||void 0===t?void 0:t.newTenant)))},this.handleBlur=e=>{},this.handleSettingExpand=e=>{this.state.expandedSetting!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.handleTogglePDF=e=>{this.setState({pdf:e})},this.handleToggleCSV=e=>{this.setState({csv:e})},this.handleToggleDateRangeDialog=(e,t)=>{this.setState({dateRangeDialogOpen:e},()=>{this.handleTogglePDF(t)})},this.handleToggleDateRangeDialogCSV=(e,t)=>{this.setState({dateRangeDialogOpen:e},()=>{this.handleToggleCSV(t)})},this.handleCancelGeneratePDF=()=>{this.setState({activityPDF:null,pdf:!1,dateRangeDialogOpen:!1,reportLoading:!1,reportType:""})},this.handleCancelGenerateCSV=()=>{this.setState({activityCSV:null,csv:!1,dateRangeDialogOpen:!1,reportLoading:!1,reportType:""})},this.handleGeneratePDF=()=>{this.setState({reportLoading:!0},()=>{this.handleToggleDateRangeDialog(!1,!0)})},this.handleGenerateCSV=()=>{this.setState({reportLoading:!0},()=>{this.handleToggleDateRangeDialogCSV(!1,!0)})},this.state={expandedSetting:"",errors:{},clean:!1,pdf:!1,csv:!1,pdf:!1,csv:!1,activityPDF:null,activityCSV:null,dateRangeDialogOpen:!1,reportStartDate:"",reportEndDate:(new Date).toISOString().substr(0,10),reportType:""}}async componentDidMount(){if(!this.props.isAuthenticated)return;const e=!window.matchMedia("(min-width: 850px)").matches;this.setState({clean:e})}formatToCCYYMMDD(e){const t=new Date(e),a=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0");return`${String(t.getDate()).padStart(2,"0")}-${n}-${a}`}getPDFLogic(e,t,a,n,r,l,s,o,c){return t&&t.type===n.type&&e?!this.state.dateRangeDialogOpen&&e?i.a.createElement(_o,{startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,getFromGlobalState:a,blocks:o,recordTypeLabel:n.label,recordType:n.type,onDownloaded:r,color:"secondary",className:l.pdfButton,farm:a("farm")[0]}):void 0:i.a.createElement(I.a,{title:"Generate PDF report"},i.a.createElement(E.a,{edge:"start",className:l.menuButton,color:"primary",onClick:c,"aria-label":"close"},i.a.createElement(Pt.a,null)))}getCSVLogic(e,t,a,n,r,l,s,o,c){return t&&t.type===n.type&&e?!this.state.dateRangeDialogOpen&&e?i.a.createElement(Ho,{startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,getFromGlobalState:a,blocks:o,recordTypeLabel:n.label,recordType:n.type,onDownloaded:r,color:"secondary",className:l.pdfButton,farm:s}):void 0:i.a.createElement(E.a,{edge:"start",className:l.menuButton,color:"primary",onClick:c,"aria-label":"close"},i.a.createElement(I.a,{title:"Generate CSV report"},i.a.createElement(Nt.a,null)))}getReportIcons(e,t,a,n,r,l,s,o,c,d,m,p,h){return i.a.createElement("div",{style:{display:"flex",flexDirection:"row"}},this.getCSVLogic(e,a,r,l,o,c,d,m,p),this.getPDFLogic(t,n,r,l,s,c,d,m,h))}onDownloadedPDF(e){e.stopPropagation(),this.setState({activityPDF:null,pdf:!1,reportLoading:!1,reportType:""})}onDownloadedCSV(e){e.stopPropagation(),this.setState({activityCSV:null,csv:!1,reportLoading:!1,reportType:""})}onReportRecordPDF(e,t){t.stopPropagation(),this.setState({activityPDF:e,dateRangeDialogOpen:!0,reportLoading:!1,reportType:"pdf"})}onReportRecordCSV(e,t){t.stopPropagation(),this.setState({activityCSV:e,dateRangeDialogOpen:!0,reportLoading:!1,reportType:"csv"})}render(){var e,t;const{classes:a,getFromGlobalState:n,sync:r,blocks:l}=this.props,{expandedSetting:s,errors:o,clean:c}=this.state,d=n("farm");let m=n("siteList");m=m.sort((e,t)=>(""+e.shortName).localeCompare(t.shortName,void 0,{numeric:!0}));let p=this.props.getFromGlobalState("farms");p=p.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!0}));1===m.length&&m[0].isNewAccount;const h=!!(d&&d[0]&&d[0].entityType&&"entity"===d[0].entityType),u=n("subscription"),b=u&&u[0],v=u&&this.formatToCCYYMMDD(null===b||void 0===b?void 0:b.nextSubscription);console.log(b);const y={};return i.a.createElement(N,{isloading:this.state.isloading},i.a.createElement(O.a,{elevation:0,className:a.paper},i.a.createElement(cr,{heading:h?"Entity Details":"Farm Detail",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(wl,{initialState:d,handleChange:this.handleChange,handleBlur:this.handleBlur,errors:o,isEntity:h,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState})),!h&&i.a.createElement(i.a.Fragment,null," ",i.a.createElement(cr,{heading:"Blocks",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(To,{clean:c,initialState:this.props.getFromGlobalState("blocks"),farm:this.props.getFromGlobalState("farm"),handleChange:this.handleChange,handleBlur:this.handleBlur,errors:o,setSnack:this.props.setSnack,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState})),i.a.createElement(cr,{heading:"Clusters",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("clusters"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(ho,null),settingName:"clusters",settingHeading:"Add",headCells:[{id:"name",numeric:!1,disablePadding:!1,label:"Group"},{}]})),i.a.createElement(cr,{heading:"Crops",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(Il,{handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,setSnack:this.props.setSnack})),i.a.createElement(cr,{heading:"Monitoring",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(Us,{initialState:this.props.getFromGlobalState("monitorings"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,setSnack:this.props.setSnack})),i.a.createElement(cr,{heading:"Plant Protection Products",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(es,{initialState:this.props.getFromGlobalState("chemicals"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,metaData:this.props.getFromGlobalState("crops"),sync:this.props.sync,activeSite:this.props.activeSite})),i.a.createElement(cr,{heading:"Fertilisers",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(ms,{initialState:this.props.getFromGlobalState("fertilisers"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,metaData:this.props.getFromGlobalState("crops"),setSnack:this.props.setSnack,isMobile:this.props.isMobile})),i.a.createElement(cr,{heading:"Combinations",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(_s,{initialState:this.props.getFromGlobalState("combinations"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,metaData:{fertilisers:this.props.getFromGlobalState("fertilisers"),chemicals:this.props.getFromGlobalState("chemicals")},setSnack:this.props.setSnack,isMobile:this.props.isMobile})),i.a.createElement(cr,{heading:"Equipment",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("chemequips"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(no,null),settingName:"chemequips",settingHeading:"Add",metaDataName:"chemicals",headCells:[{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"capacity",numeric:!0,disablePadding:!1,label:"Capacity in liter"}]})),i.a.createElement(cr,{heading:"Harvesting",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("harvestequips"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(co,null),settingName:"harvestequips",settingHeading:"Add",headCells:[{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"capacity",numeric:!0,disablePadding:!1,label:"Capacity in Kg"}]})),i.a.createElement(cr,{heading:"Agronomic activities",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("agronomistActs"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(fo,null),settingName:"agronomistActs",settingHeading:"Add",displayLabelPrim:"name",displayLabelSec:"description",headCells:[{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"}]})),i.a.createElement(cr,{heading:"Workforce",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("operators").map(e=>{const t={...e};return t.name=`${t.name} ${t.surname}`,t.rolesString=this.roleString(t.roles),t.enabled=t.enabled?"Yes":"No",t.leader=t.teamLeader?"Yes":"No",t}),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(bo,{roles:Jo}),settingName:"operators",settingHeading:"Add",displayLabelPrim:"name",userAvatar:!0,displayLabelSec:"surname",headCells:c?[{id:"name",numeric:!1,disablePadding:!1,label:"Name"}]:[{id:"enabled",numeric:!1,disablePadding:!1,label:"Enabled"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"leader",numeric:!1,disablePadding:!1,label:"Leader"},{id:"clockNo",numeric:!1,disablePadding:!1,label:"Clock No"},{id:"idNo",numeric:!1,disablePadding:!1,label:"ID"},{id:"team",numeric:!1,disablePadding:!1,label:"Team"},{id:"rolesString",numeric:!1,disablePadding:!1,label:"Role"}]}))),h&&i.a.createElement(cr,{heading:h?"Farms":"Additional Sites",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.filterSites(m,p).map(e=>{const t={...e};return t.isDisabled=e.isDisabled?"Yes":"No",t}),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(Fo,null),settingName:"farms",settingHeading:"Add",displayLabelPrim:"name",displayLabelSec:"description",headCells:[{id:"isDisabled",numeric:!1,disablePadding:!1,label:"Disabled"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"}]})),i.a.createElement(cr,{heading:"Users",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(ko,{initialState:this.props.getFromGlobalState("users"),handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,setSnack:this.props.setSnack})),i.a.createElement(cr,{heading:"API Keys",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:this.props.getFromGlobalState("apiKeys").map(e=>{const t={...e};return t.enabled=t.isDisabled?"Yes":"No",t}),isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(lo,null),settingName:"apiKeys",settingHeading:"Add",metaDataName:"apiKeys",headCells:[{id:"enabled",numeric:!1,disablePadding:!1,label:"Disabled"},{id:"consumer",numeric:!1,disablePadding:!1,label:"Consumer"},{id:"apiKey",numeric:!1,disablePadding:!1,label:"Key"}]})),h&&i.a.createElement(cr,{heading:"Subscription",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{lg:4,style:{textAlign:"center"}},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},"Active"),i.a.createElement("p",{style:{fontSize:12}},"Subscription Status")),i.a.createElement(g.a,{lg:4,style:{textAlign:"center"}},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},v),i.a.createElement("p",{style:{fontSize:12}},"Next Payment Date")),i.a.createElement(g.a,{lg:4},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},"R",null===(e=b.totalPrice||0)||void 0===e?void 0:e.toFixed(2)),i.a.createElement("p",{style:{textAlign:"center",fontSize:12}},"Total Billing Amount")),i.a.createElement(g.a,{lg:12},i.a.createElement(eo,{initialState:null===(t=this.props.getFromGlobalState("transactions")||[])||void 0===t?void 0:t.map(e=>{const t={...e};return t.enabled=t.isDisabled?"Yes":"No",t}),isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,Extract:this.getReportIcons(this.state.csv,this.state.pdf,this.state.activityCSV,this.state.activityPDF,n,y,this.onDownloadedPDF.bind(this),this.onDownloadedCSV.bind(this),a,d,l,this.onReportRecordCSV.bind(this,y),this.onReportRecordPDF.bind(this,y)),settingDialog:i.a.createElement(i.a.Fragment,null),settingName:"transactions",settingHeading:"transactions",metaDataName:"transactions",headCells:[{id:"description",numeric:!1,disablePadding:!1,label:"Description"},{id:"billingDate",numeric:!1,disablePadding:!1,label:"Billing Date"},{id:"status",numeric:!1,disablePadding:!1,label:"Status"},{id:"amount",numeric:!1,disablePadding:!1,label:"Amount"}]}))),this.state.dateRangeDialogOpen&&i.a.createElement(Kt,{open:this.state.dateRangeDialogOpen,loading:this.state.reportLoading,title:"Report Date Range",handleConfirm:"pdf"===this.state.reportType?this.handleGeneratePDF:this.handleGenerateCSV,handleCancel:"csv"===this.state.reportType?this.handleCancelGeneratePDF:this.handleCancelGenerateCSV,startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,handleSetStartDate:this.setReportStartDate,handleSetEndDate:this.setReportEndDate})),h&&i.a.createElement(cr,{heading:"Manage Billing",expanded:s,handleExpand:this.handleSettingExpand},i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(Zo,Object.assign({sub:b},this.props)))))))}}var Xo=Object(v.a)(e=>({root:{flexGrow:1},headingDropper:{display:"inherit",marginRight:"auto",marginBottom:"15px"},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},header:{[e.breakpoints.up("sm")]:{display:"none"}},paper:{flexGrow:1,display:"flex",flexDirection:"column",backgroundColor:"inherit",marginBottom:e.spacing(10)},section:{},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Qo),ec=a(1763);class tc extends n.Component{constructor(e){super(e),this.onAccept=async(e,t)=>{try{const n={email:e,tenant:t};this.setState({isloading:!0});await(a=n,console.log("api post from storage"),o.a.post("farms","/sharedUserAdd",{body:a}));const i=this.props.getFromGlobalState("invites"),r=i.findIndex(a=>a.email===e&&a.tenantId===t);-1!==r&&i.splice(r,1),this.setState({isloading:!1});const l=(await Ea()).filter(e=>!e.isDisabled||!0!==e.isDisabled);this.props.setGlobalState({siteList:l}),this.props.setGlobalState({invites:i}),this.props.setSnack({open:!0,variant:"info",autoHideDuration:2e3,messageText:"Invitation accepted."})}catch(n){return this.setState({isloading:!1,userDialogOpen:!1}),this.props.setSnack({open:!0,variant:"error",messageText:n.response?`${n.response.data.error.message?n.response.data.error.message:n.response.data.error}, api src: ${n.response.data.src} `:n.message}),!1}var a},this.onReject=async(e,t)=>{try{const n={email:e,tenant:t};this.setState({isloading:!0});await(a=n,console.log("api post from storage"),o.a.post("farms","/sharedUserReject",{body:a}));const i=this.props.getFromGlobalState("invites"),r=i.findIndex(a=>a.email===e&&a.tenantId===t);-1!==r&&i.splice(r,1),this.setState({isloading:!1}),this.props.setGlobalState({invites:i}),this.props.setSnack({open:!0,variant:"info",autoHideDuration:2e3,messageText:"Invitation rejected."})}catch(n){return this.setState({isloading:!1,userDialogOpen:!1}),this.props.setSnack({open:!0,variant:"error",messageText:n.response?`${n.response.data.error.message?n.response.data.error.message:n.response.data.error}, api src: ${n.response.data.src} `:n.message}),!1}var a},this.handleExpandActivity=e=>{let t=this.state.selectedActivity;t&&t.type===t.type?this.setState({selectedActivity:null}):this.setState({selectedActivity:e})},this.state={openDialog:"",isNew:!1,isloading:!1}}componentDidMount(){}renderMessages(e,t,a){return e.map(e=>i.a.createElement(g.a,{key:e.sk,style:{padding:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(u.a,{className:t.root},i.a.createElement(ec.a,null,i.a.createElement(b.a,null,i.a.createElement(B.a,{gutterBottom:!0,variant:"h6",component:"h2"},"Invitation from "+(e.farm?e.farm:e.shortName)),i.a.createElement(B.a,{gutterBottom:!0,variant:"body2",component:"p"},"Sent on: "+new Date(parseInt(e.createdAt))),i.a.createElement(B.a,{variant:"body2",color:"textSecondary",component:"p"},`You have been granted access to ${e.farm?e.farm:e.shortName} by ${e.invitedByName} ${e.invitedBySurname}. You will be able to access this farm on Land Diary by selecting the short name "${e.shortName}". You can accept or reject this invitation below.`))),i.a.createElement(f.a,null,i.a.createElement(Mt,{onClick:this.onAccept.bind(this,e.email,e.tenantId),variant:"contained",color:"primary",className:t.submit,disabled:a,isloading:a,text:"Accept",loadingText:"Accepting ..."}),i.a.createElement(Mt,{onClick:this.onReject.bind(this,e.email,e.tenantId),variant:"contained",color:"secondary",className:t.submit,disabled:a,isloading:a,text:"Reject",loadingText:"Rejecting ..."})))))}render(){const{classes:e,getFromGlobalState:t}=this.props,a=t("invites");return console.log("report loading....",this.state.reportLoading),i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{className:e.searchBar,key:"search",style:{padding:"3px",marginBottom:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12})),i.a.createElement(N,{isloading:this.state.isLoading},i.a.createElement(g.a,{container:!0,className:e.root2,spacing:2,alignItems:"flex-start"},a&&this.renderMessages(a,e),0===a.length&&i.a.createElement("p",null,"You currently have no active invites. Please contact an admin to send you an invitation and gain access to the farms."))))}}var ac=Object(v.a)(e=>({root:{flexGrow:1},root2:{flexGrow:1,marginTop:"5px"},submit:{margin:e.spacing(1)},iconContainer:{textAlign:"center",width:"60px"},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},fab:{margin:e.spacing(1)},fabFloat:{margin:e.spacing(1),top:"auto",right:20,bottom:80,left:"auto",position:"fixed"},submit:{margin:e.spacing(3,0,2)},list:{width:"100%",maxWidth:360,backgroundColor:e.palette.background.paper},heading:{[e.breakpoints.up("sm")]:{display:"none"}},searchBar:{[e.breakpoints.up("sm")]:{}},nested:{paddingLeft:e.spacing(4)},cardHeader:{paddingBottom:"6px"},cached:{fontSize:15,color:e.palette.secondary.main},syncError:{fontSize:15,color:"red"},card:{minWidth:275},bullet:{display:"inline-block",margin:"0 2px",transform:"scale(0.8)"},title:{fontSize:14},pos:{marginBottom:12}}))(tc);const nc=[{name:"name",min:1,max:100}];class ic extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,nc),this.handleChange=e=>{let t={...this.state.folder};t[e.target.id]=e.target.value,this.setState({folder:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,folder:{name:""},errors:{count:0},changed:!1,isloading:!1}}componentDidMount(){if(!this.props.isNew){let e=this.props.folder;this.setState({folder:e})}}validateField(e,t){let a=jn(e,this.state.folder,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,metaData:l,getFromGlobalState:s,handlePreExecute:o,parent:c}=this.props,{folder:d,errors:m}=this.state,p=$n(d,nc);return a&&(d.path=c?`${c.path}${d.name}/`:d.name+"/",d.parentSK=c?c.sk:null),i.a.createElement(Ia,{open:t,dialogObject:d,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"init_setting_",dynamoType:"folders",parentKey:c?c.sk:null,valid:p,changed:this.state.changed,newTitle:"New Folder",title:d&&d.name?d.name:"",getFromGlobalState:s,handlePreExecute:o},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:d.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.name||void 0,helperText:m.name}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"description",label:"Description",name:"description",value:d.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!m.description||void 0,helperText:m.description}),i.a.createElement("br",null))}}ic.defaultProps={parent:null};var rc,lc,sc,oc,cc,dc,mc,pc,hc,gc,uc,bc,vc,yc,fc,Ec=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(ic);function Sc(){return(Sc=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Sc({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#F15642"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M101.744,303.152c0-4.224,3.328-8.832,8.688-8.832h29.552c16.64,0,31.616,11.136,31.616,32.48 c0,20.224-14.976,31.488-31.616,31.488h-21.36v16.896c0,5.632-3.584,8.816-8.192,8.816c-4.224,0-8.688-3.184-8.688-8.816V303.152z M118.624,310.432v31.872h21.36c8.576,0,15.36-7.568,15.36-15.504c0-8.944-6.784-16.368-15.36-16.368H118.624z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M196.656,384c-4.224,0-8.832-2.304-8.832-7.92v-72.672c0-4.592,4.608-7.936,8.832-7.936h29.296 c58.464,0,57.184,88.528,1.152,88.528H196.656z M204.72,311.088V368.4h21.232c34.544,0,36.08-57.312,0-57.312H204.72z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M303.872,312.112v20.336h32.624c4.608,0,9.216,4.608,9.216,9.072c0,4.224-4.608,7.68-9.216,7.68 h-32.624v26.864c0,4.48-3.184,7.92-7.664,7.92c-5.632,0-9.072-3.44-9.072-7.92v-72.672c0-4.592,3.456-7.936,9.072-7.936h44.912 c5.632,0,8.96,3.344,8.96,7.936c0,4.096-3.328,8.704-8.96,8.704h-37.248V312.112z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),rc||(rc=i.a.createElement("g",null)),lc||(lc=i.a.createElement("g",null)),sc||(sc=i.a.createElement("g",null)),oc||(oc=i.a.createElement("g",null)),cc||(cc=i.a.createElement("g",null)),dc||(dc=i.a.createElement("g",null)),mc||(mc=i.a.createElement("g",null)),pc||(pc=i.a.createElement("g",null)),hc||(hc=i.a.createElement("g",null)),gc||(gc=i.a.createElement("g",null)),uc||(uc=i.a.createElement("g",null)),bc||(bc=i.a.createElement("g",null)),vc||(vc=i.a.createElement("g",null)),yc||(yc=i.a.createElement("g",null)),fc||(fc=i.a.createElement("g",null)))},xc=i.a.forwardRef((e,t)=>i.a.createElement(Cc,Sc({svgRef:t},e)));var kc,wc,Tc,Dc,Pc,Fc,Nc,Bc,Lc,Ac,Oc,Ic,Gc,Rc,Uc;a.p;function Mc(){return(Mc=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Mc({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#50BEE8"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M141.968,303.152c0-10.752,16.896-10.752,16.896,0v50.528c0,20.096-9.6,32.256-31.728,32.256 c-10.88,0-19.952-2.96-27.888-13.184c-6.528-7.808,5.76-19.056,12.416-10.88c5.376,6.656,11.136,8.192,16.752,7.936 c7.152-0.256,13.44-3.472,13.568-16.128v-50.528H141.968z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M181.344,303.152c0-4.224,3.328-8.832,8.704-8.832H219.6c16.64,0,31.616,11.136,31.616,32.48 c0,20.224-14.976,31.488-31.616,31.488h-21.36v16.896c0,5.632-3.584,8.816-8.192,8.816c-4.224,0-8.704-3.184-8.704-8.816 L181.344,303.152L181.344,303.152z M198.24,310.432v31.872h21.36c8.576,0,15.36-7.568,15.36-15.504 c0-8.944-6.784-16.368-15.36-16.368H198.24z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M342.576,374.16c-9.088,7.552-20.224,10.752-31.472,10.752c-26.88,0-45.936-15.344-45.936-45.808 c0-25.824,20.096-45.904,47.072-45.904c10.112,0,21.232,3.44,29.168,11.248c7.792,7.664-3.456,19.056-11.12,12.288 c-4.736-4.608-11.392-8.064-18.048-8.064c-15.472,0-30.432,12.4-30.432,30.432c0,18.944,12.528,30.464,29.296,30.464 c7.792,0,14.448-2.32,19.184-5.76V348.08h-19.184c-11.392,0-10.24-15.616,0-15.616h25.584c4.736,0,9.072,3.584,9.072,7.552v27.248 C345.76,369.568,344.752,371.712,342.576,374.16z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),kc||(kc=i.a.createElement("g",null)),wc||(wc=i.a.createElement("g",null)),Tc||(Tc=i.a.createElement("g",null)),Dc||(Dc=i.a.createElement("g",null)),Pc||(Pc=i.a.createElement("g",null)),Fc||(Fc=i.a.createElement("g",null)),Nc||(Nc=i.a.createElement("g",null)),Bc||(Bc=i.a.createElement("g",null)),Lc||(Lc=i.a.createElement("g",null)),Ac||(Ac=i.a.createElement("g",null)),Oc||(Oc=i.a.createElement("g",null)),Ic||(Ic=i.a.createElement("g",null)),Gc||(Gc=i.a.createElement("g",null)),Rc||(Rc=i.a.createElement("g",null)),Uc||(Uc=i.a.createElement("g",null)))},zc=i.a.forwardRef((e,t)=>i.a.createElement(Wc,Mc({svgRef:t},e)));var Kc,Hc,qc,Vc,jc,$c,Yc,_c,Zc,Jc,Qc,Xc,ed,td,ad;a.p;function nd(){return(nd=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",nd({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#50BEE8"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M92.576,384c-4.224,0-8.832-2.32-8.832-7.936v-72.656c0-4.608,4.608-7.936,8.832-7.936h29.296 c58.464,0,57.168,88.528,1.136,88.528H92.576z M100.64,311.072v57.312h21.232c34.544,0,36.064-57.312,0-57.312H100.64z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M228,385.28c-23.664,1.024-48.24-14.72-48.24-46.064c0-31.472,24.56-46.944,48.24-46.944 c22.384,1.136,45.792,16.624,45.792,46.944C273.792,369.552,250.384,385.28,228,385.28z M226.592,308.912 c-14.336,0-29.936,10.112-29.936,30.32c0,20.096,15.616,30.336,29.936,30.336c14.72,0,30.448-10.24,30.448-30.336 C257.04,319.008,241.312,308.912,226.592,308.912z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M288.848,339.088c0-24.688,15.488-45.92,44.912-45.92c11.136,0,19.968,3.328,29.296,11.392 c3.456,3.184,3.84,8.816,0.384,12.4c-3.456,3.056-8.704,2.688-11.776-0.384c-5.232-5.504-10.608-7.024-17.904-7.024 c-19.696,0-29.152,13.952-29.152,29.552c0,15.872,9.328,30.448,29.152,30.448c7.296,0,14.08-2.96,19.968-8.192 c3.952-3.072,9.456-1.552,11.76,1.536c2.048,2.816,3.056,7.552-1.408,12.016c-8.96,8.336-19.696,10-30.336,10 C302.8,384.912,288.848,363.776,288.848,339.088z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Kc||(Kc=i.a.createElement("g",null)),Hc||(Hc=i.a.createElement("g",null)),qc||(qc=i.a.createElement("g",null)),Vc||(Vc=i.a.createElement("g",null)),jc||(jc=i.a.createElement("g",null)),$c||($c=i.a.createElement("g",null)),Yc||(Yc=i.a.createElement("g",null)),_c||(_c=i.a.createElement("g",null)),Zc||(Zc=i.a.createElement("g",null)),Jc||(Jc=i.a.createElement("g",null)),Qc||(Qc=i.a.createElement("g",null)),Xc||(Xc=i.a.createElement("g",null)),ed||(ed=i.a.createElement("g",null)),td||(td=i.a.createElement("g",null)),ad||(ad=i.a.createElement("g",null)))},rd=i.a.forwardRef((e,t)=>i.a.createElement(id,nd({svgRef:t},e)));var ld,sd,od,cd,dd,md,pd,hd,gd,ud,bd,vd,yd,fd,Ed;a.p;function Sd(){return(Sd=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Sd({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#A066AA"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M199.84,374.16c-9.088,7.536-20.224,10.752-31.472,10.752c-26.88,0-45.936-15.36-45.936-45.808 c0-25.84,20.096-45.92,47.072-45.92c10.112,0,21.232,3.456,29.168,11.264c7.808,7.664-3.456,19.056-11.12,12.288 c-4.736-4.624-11.392-8.064-18.048-8.064c-15.472,0-30.432,12.4-30.432,30.432c0,18.944,12.528,30.448,29.296,30.448 c7.792,0,14.448-2.304,19.184-5.76V348.08h-19.184c-11.392,0-10.24-15.632,0-15.632h25.584c4.736,0,9.072,3.6,9.072,7.568v27.248 C203.024,369.552,202.016,371.712,199.84,374.16z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M224.944,303.152c0-10.496,16.896-10.88,16.896,0v73.024c0,10.624-16.896,10.88-16.896,0V303.152z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M281.12,312.096v20.336h32.608c4.608,0,9.216,4.608,9.216,9.088c0,4.224-4.608,7.664-9.216,7.664 H281.12v26.864c0,4.48-3.2,7.936-7.68,7.936c-5.632,0-9.072-3.456-9.072-7.936v-72.656c0-4.608,3.456-7.936,9.072-7.936h44.912 c5.632,0,8.96,3.328,8.96,7.936c0,4.096-3.328,8.688-8.96,8.688H281.12V312.096z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),ld||(ld=i.a.createElement("g",null)),sd||(sd=i.a.createElement("g",null)),od||(od=i.a.createElement("g",null)),cd||(cd=i.a.createElement("g",null)),dd||(dd=i.a.createElement("g",null)),md||(md=i.a.createElement("g",null)),pd||(pd=i.a.createElement("g",null)),hd||(hd=i.a.createElement("g",null)),gd||(gd=i.a.createElement("g",null)),ud||(ud=i.a.createElement("g",null)),bd||(bd=i.a.createElement("g",null)),vd||(vd=i.a.createElement("g",null)),yd||(yd=i.a.createElement("g",null)),fd||(fd=i.a.createElement("g",null)),Ed||(Ed=i.a.createElement("g",null)))},xd=i.a.forwardRef((e,t)=>i.a.createElement(Cd,Sd({svgRef:t},e)));var kd,wd,Td,Dd,Pd,Fd,Nd,Bd,Ld,Ad,Od,Id,Gd,Rd,Ud;a.p;function Md(){return(Md=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Md({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.616,14.4,32,32,32h320c17.6,0,32-14.384,32-32V128L352,0H128z "}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#50BEE8"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M117.184,327.84v47.344c0,5.632-4.592,8.832-9.216,8.832c-4.096,0-7.664-3.2-7.664-8.832v-72.032 c0-6.64,5.632-8.832,7.664-8.832c3.712,0,5.888,2.192,8.064,4.608l28.16,38l29.152-39.408c4.24-5.248,14.592-3.2,14.592,5.632 v72.032c0,5.632-3.6,8.832-7.68,8.832c-4.592,0-8.192-3.2-8.192-8.832V327.84l-21.232,26.88c-4.592,5.632-10.352,5.632-14.576,0 L117.184,327.84z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M210.288,303.152c0-4.224,3.328-8.832,8.704-8.832h29.552c16.64,0,31.616,11.136,31.616,32.496 c0,20.224-14.976,31.472-31.616,31.472h-21.36v16.896c0,5.632-3.584,8.832-8.192,8.832c-4.224,0-8.704-3.2-8.704-8.832V303.152z M227.168,310.448v31.856h21.36c8.576,0,15.36-7.552,15.36-15.488c0-8.96-6.784-16.368-15.36-16.368L227.168,310.448 L227.168,310.448z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M322.064,311.472h-21.872c-10.736,0-10.096-15.984,0-15.984h39.152c7.792,0,11.376,8.96,5.632,14.72 l-21.232,19.824c15.616-1.152,27.888,10.48,27.888,24.816c0,15.728-11.136,29.168-34.544,29.168 c-10.24,0-20.336-4.224-26.224-13.44c-6.144-9.072,7.024-17.776,13.936-8.832c3.328,4.352,8.704,6.528,14.448,6.528 c7.808,0,15.488-3.328,15.488-13.44c0-13.296-16.256-11.248-25.072-10.352c-10.752,2.048-13.936-9.6-7.664-14.448L322.064,311.472z "})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),kd||(kd=i.a.createElement("g",null)),wd||(wd=i.a.createElement("g",null)),Td||(Td=i.a.createElement("g",null)),Dd||(Dd=i.a.createElement("g",null)),Pd||(Pd=i.a.createElement("g",null)),Fd||(Fd=i.a.createElement("g",null)),Nd||(Nd=i.a.createElement("g",null)),Bd||(Bd=i.a.createElement("g",null)),Ld||(Ld=i.a.createElement("g",null)),Ad||(Ad=i.a.createElement("g",null)),Od||(Od=i.a.createElement("g",null)),Id||(Id=i.a.createElement("g",null)),Gd||(Gd=i.a.createElement("g",null)),Rd||(Rd=i.a.createElement("g",null)),Ud||(Ud=i.a.createElement("g",null)))},zd=i.a.forwardRef((e,t)=>i.a.createElement(Wd,Md({svgRef:t},e)));var Kd,Hd,qd,Vd,jd,$d,Yd,_d,Zd,Jd,Qd,Xd,em,tm,am;a.p;function nm(){return(nm=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",nm({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#84BD5A"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M144.336,326.192l22.256-27.888c6.656-8.704,19.584,2.416,12.288,10.736 c-7.664,9.088-15.728,18.944-23.408,29.04l26.096,32.496c7.04,9.6-7.024,18.8-13.936,9.328l-23.552-30.192l-23.152,30.848 c-6.528,9.328-20.992-1.152-13.696-9.856l25.712-32.624c-8.064-10.112-15.872-19.952-23.664-29.04 c-8.048-9.6,6.912-19.44,12.8-10.464L144.336,326.192z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M197.36,303.152c0-4.224,3.584-7.808,8.064-7.808c4.096,0,7.552,3.6,7.552,7.808v64.096h34.8 c12.528,0,12.8,16.752,0,16.752H205.44c-4.48,0-8.064-3.184-8.064-7.792v-73.056H197.36z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M272.032,314.672c2.944-24.832,40.416-29.296,58.08-15.728c8.704,7.024-0.512,18.16-8.192,12.528 c-9.472-6-30.96-8.816-33.648,4.464c-3.456,20.992,52.192,8.976,51.296,43.008c-0.896,32.496-47.968,33.248-65.632,18.672 c-4.24-3.456-4.096-9.072-1.792-12.544c3.328-3.312,7.024-4.464,11.392-0.88c10.48,7.152,37.488,12.528,39.392-5.648 C321.28,339.632,268.064,351.008,272.032,314.672z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Kd||(Kd=i.a.createElement("g",null)),Hd||(Hd=i.a.createElement("g",null)),qd||(qd=i.a.createElement("g",null)),Vd||(Vd=i.a.createElement("g",null)),jd||(jd=i.a.createElement("g",null)),$d||($d=i.a.createElement("g",null)),Yd||(Yd=i.a.createElement("g",null)),_d||(_d=i.a.createElement("g",null)),Zd||(Zd=i.a.createElement("g",null)),Jd||(Jd=i.a.createElement("g",null)),Qd||(Qd=i.a.createElement("g",null)),Xd||(Xd=i.a.createElement("g",null)),em||(em=i.a.createElement("g",null)),tm||(tm=i.a.createElement("g",null)),am||(am=i.a.createElement("g",null)))},rm=i.a.forwardRef((e,t)=>i.a.createElement(im,nm({svgRef:t},e)));var lm,sm,om,cm,dm,mm,pm,hm,gm,um,bm,vm,ym,fm,Em;a.p;function Sm(){return(Sm=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Sm({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#A066AA"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M92.816,303.152c0-4.224,3.312-8.848,8.688-8.848h29.568c16.624,0,31.6,11.136,31.6,32.496 c0,20.224-14.976,31.472-31.6,31.472H109.68v16.896c0,5.648-3.552,8.832-8.176,8.832c-4.224,0-8.688-3.184-8.688-8.832 C92.816,375.168,92.816,303.152,92.816,303.152z M109.68,310.432v31.856h21.376c8.56,0,15.344-7.552,15.344-15.488 c0-8.96-6.784-16.368-15.344-16.368L109.68,310.432L109.68,310.432z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M178.976,304.432c0-4.624,1.024-9.088,7.68-9.088c4.592,0,5.632,1.152,9.072,4.464l42.336,52.976 v-49.632c0-4.224,3.696-8.848,8.064-8.848c4.608,0,9.072,4.624,9.072,8.848v72.016c0,5.648-3.456,7.792-6.784,8.832 c-4.464,0-6.656-1.024-10.352-4.464l-42.336-53.744v49.392c0,5.648-3.456,8.832-8.064,8.832s-8.704-3.184-8.704-8.832v-70.752 H178.976z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M351.44,374.16c-9.088,7.536-20.224,10.752-31.472,10.752c-26.88,0-45.936-15.36-45.936-45.808 c0-25.84,20.096-45.92,47.072-45.92c10.112,0,21.232,3.456,29.168,11.264c7.808,7.664-3.456,19.056-11.12,12.288 c-4.736-4.624-11.392-8.064-18.048-8.064c-15.472,0-30.432,12.4-30.432,30.432c0,18.944,12.528,30.448,29.296,30.448 c7.792,0,14.448-2.304,19.184-5.76V348.08h-19.184c-11.392,0-10.24-15.632,0-15.632h25.584c4.736,0,9.072,3.6,9.072,7.568v27.248 C354.624,369.552,353.616,371.712,351.44,374.16z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),lm||(lm=i.a.createElement("g",null)),sm||(sm=i.a.createElement("g",null)),om||(om=i.a.createElement("g",null)),cm||(cm=i.a.createElement("g",null)),dm||(dm=i.a.createElement("g",null)),mm||(mm=i.a.createElement("g",null)),pm||(pm=i.a.createElement("g",null)),hm||(hm=i.a.createElement("g",null)),gm||(gm=i.a.createElement("g",null)),um||(um=i.a.createElement("g",null)),bm||(bm=i.a.createElement("g",null)),vm||(vm=i.a.createElement("g",null)),ym||(ym=i.a.createElement("g",null)),fm||(fm=i.a.createElement("g",null)),Em||(Em=i.a.createElement("g",null)))},xm=i.a.forwardRef((e,t)=>i.a.createElement(Cm,Sm({svgRef:t},e)));var km,wm,Tm,Dm,Pm,Fm,Nm,Bm,Lm,Am,Om,Im,Gm,Rm,Um;a.p;function Mm(){return(Mm=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Mm({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#F15642"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M105.456,303.152c0-4.224,3.328-8.832,8.688-8.832h29.552c16.64,0,31.616,11.136,31.616,32.48 c0,20.224-14.976,31.488-31.616,31.488h-21.36v16.896c0,5.632-3.568,8.816-8.176,8.816c-4.224,0-8.688-3.184-8.688-8.816v-72.032 H105.456z M122.336,310.432v31.872h21.36c8.576,0,15.36-7.568,15.36-15.504c0-8.944-6.784-16.368-15.36-16.368H122.336z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M191.616,303.152c0-4.224,3.328-8.832,8.704-8.832h29.552c16.64,0,31.616,11.136,31.616,32.48 c0,20.224-14.976,31.488-31.616,31.488h-21.36v16.896c0,5.632-3.584,8.816-8.192,8.816c-4.224,0-8.704-3.184-8.704-8.816V303.152z M208.496,310.432v31.872h21.36c8.576,0,15.36-7.568,15.36-15.504c0-8.944-6.784-16.368-15.36-16.368H208.496z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M301.68,311.472h-22.368c-11.136,0-11.136-16.368,0-16.368h60.496c11.392,0,11.392,16.368,0,16.368 h-21.232v64.608c0,11.12-16.896,11.392-16.896,0V311.472z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),km||(km=i.a.createElement("g",null)),wm||(wm=i.a.createElement("g",null)),Tm||(Tm=i.a.createElement("g",null)),Dm||(Dm=i.a.createElement("g",null)),Pm||(Pm=i.a.createElement("g",null)),Fm||(Fm=i.a.createElement("g",null)),Nm||(Nm=i.a.createElement("g",null)),Bm||(Bm=i.a.createElement("g",null)),Lm||(Lm=i.a.createElement("g",null)),Am||(Am=i.a.createElement("g",null)),Om||(Om=i.a.createElement("g",null)),Im||(Im=i.a.createElement("g",null)),Gm||(Gm=i.a.createElement("g",null)),Rm||(Rm=i.a.createElement("g",null)),Um||(Um=i.a.createElement("g",null)))},zm=i.a.forwardRef((e,t)=>i.a.createElement(Wm,Mm({svgRef:t},e)));var Km,Hm,qm,Vm,jm,$m,Ym,_m,Zm,Jm,Qm,Xm,ep,tp,ap;a.p;function np(){return(np=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",np({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#84BD5A"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M132.64,384c-8.064,0-11.264-7.792-6.656-13.296l45.552-60.512h-37.76 c-11.12,0-10.224-15.712,0-15.712h51.568c9.712,0,12.528,9.184,5.632,16.624l-43.632,56.656h41.584 c10.24,0,11.52,16.256-1.008,16.256h-55.28V384z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M212.048,303.152c0-10.496,16.896-10.88,16.896,0v73.04c0,10.608-16.896,10.88-16.896,0V303.152z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M251.616,303.152c0-4.224,3.328-8.832,8.704-8.832h29.552c16.64,0,31.616,11.136,31.616,32.48 c0,20.224-14.976,31.488-31.616,31.488h-21.36v16.896c0,5.632-3.584,8.816-8.192,8.816c-4.224,0-8.704-3.184-8.704-8.816 L251.616,303.152L251.616,303.152z M268.496,310.432v31.872h21.36c8.576,0,15.36-7.568,15.36-15.504 c0-8.944-6.784-16.368-15.36-16.368H268.496z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Km||(Km=i.a.createElement("g",null)),Hm||(Hm=i.a.createElement("g",null)),qm||(qm=i.a.createElement("g",null)),Vm||(Vm=i.a.createElement("g",null)),jm||(jm=i.a.createElement("g",null)),$m||($m=i.a.createElement("g",null)),Ym||(Ym=i.a.createElement("g",null)),_m||(_m=i.a.createElement("g",null)),Zm||(Zm=i.a.createElement("g",null)),Jm||(Jm=i.a.createElement("g",null)),Qm||(Qm=i.a.createElement("g",null)),Xm||(Xm=i.a.createElement("g",null)),ep||(ep=i.a.createElement("g",null)),tp||(tp=i.a.createElement("g",null)),ap||(ap=i.a.createElement("g",null)))},rp=i.a.forwardRef((e,t)=>i.a.createElement(ip,np({svgRef:t},e)));var lp,sp,op,cp,dp,mp,pp,hp,gp,up,bp,vp,yp,fp,Ep;a.p;function Sp(){return(Sp=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Sp({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#F7B84E"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M164.224,384c-4.096-2.32-6.656-6.912-4.096-12.288l36.704-71.76c3.456-6.784,12.672-7.04,15.872,0 l36.064,71.76c5.248,9.968-10.24,17.904-14.832,7.936l-5.648-11.264h-47.2l-5.504,11.264C173.552,384,168.816,384.912,164.224,384z M219.216,351.504l-14.448-31.6l-15.728,31.6H219.216z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M264.048,303.152c0-10.496,16.896-10.88,16.896,0v73.024c0,10.624-16.896,10.88-16.896,0V303.152z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),lp||(lp=i.a.createElement("g",null)),sp||(sp=i.a.createElement("g",null)),op||(op=i.a.createElement("g",null)),cp||(cp=i.a.createElement("g",null)),dp||(dp=i.a.createElement("g",null)),mp||(mp=i.a.createElement("g",null)),pp||(pp=i.a.createElement("g",null)),hp||(hp=i.a.createElement("g",null)),gp||(gp=i.a.createElement("g",null)),up||(up=i.a.createElement("g",null)),bp||(bp=i.a.createElement("g",null)),vp||(vp=i.a.createElement("g",null)),yp||(yp=i.a.createElement("g",null)),fp||(fp=i.a.createElement("g",null)),Ep||(Ep=i.a.createElement("g",null)))},xp=i.a.forwardRef((e,t)=>i.a.createElement(Cp,Sp({svgRef:t},e)));var kp,wp,Tp,Dp,Pp,Fp,Np,Bp;a.p;function Lp(){return(Lp=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Lp({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,kp||(kp=i.a.createElement("style",{type:"text/css"},"\r\n\t.st0{fill:#E2E5E7;}\r\n\t.st1{fill:#B0B7BD;}\r\n\t.st2{fill:#CAD1D8;}\r\n\t.st3{fill:#4979CE;}\r\n\t.st4{fill:#FFFFFF;}\r\n")),wp||(wp=i.a.createElement("path",{className:"st0",d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"})),Tp||(Tp=i.a.createElement("path",{className:"st1",d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"})),Dp||(Dp=i.a.createElement("polygon",{className:"st2",points:"480,224 384,128 480,128 "})),Pp||(Pp=i.a.createElement("path",{className:"st3",d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16V416z"})),Fp||(Fp=i.a.createElement("g",null,i.a.createElement("path",{className:"st4",d:"M106.9,327.8v47.3c0,5.6-4.6,8.8-9.2,8.8c-4.1,0-7.7-3.2-7.7-8.8v-72c0-6.7,5.6-8.8,7.7-8.8 c3.7,0,5.9,2.2,8.1,4.6l28.1,38l29.2-39.4c4.2-5.2,14.6-3.2,14.6,5.6v72c0,5.6-3.6,8.8-7.7,8.8c-4.6,0-8.2-3.2-8.2-8.8v-47.3 l-21.2,26.9c-4.6,5.6-10.4,5.6-14.6,0L106.9,327.8z"}))),Np||(Np=i.a.createElement("path",{className:"st2",d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"})),Bp||(Bp=i.a.createElement("g",null,i.a.createElement("path",{className:"st4",d:"M236.6,349.1H220v26.4c0,3.8-0.9,6.6-2.6,8.6c-1.7,1.9-3.9,2.9-6.5,2.9c-2.7,0-4.9-1-6.6-2.9 c-1.7-1.9-2.5-4.8-2.5-8.5v-71.8c0-4.2,0.9-7.1,2.7-8.9c1.8-1.8,4.7-2.7,8.7-2.7h23.2c6.9,0,12.1,0.6,15.8,1.7 c3.7,1.1,6.8,2.8,9.5,5.3c2.7,2.5,4.7,5.5,6.1,9c1.4,3.6,2.1,7.6,2.1,12c0,9.5-2.8,16.7-8.4,21.6S247.6,349.1,236.6,349.1z M232.2,306.4H220v28.5h12.2c4.3,0,7.8-0.5,10.7-1.4c2.9-0.9,5-2.5,6.5-4.6c1.5-2.1,2.3-4.9,2.3-8.3c0-4.1-1.2-7.5-3.5-10 C245.6,307.7,240.2,306.4,232.2,306.4z"}),i.a.createElement("path",{className:"st4",d:"M319,377.3v-11.8h-30.5c-3.9,0-6.7-0.9-8.7-2.7c-1.9-1.8-2.9-4.3-2.9-7.4c0-0.8,0.1-1.6,0.4-2.4 c0.3-0.8,0.7-1.7,1.3-2.6c0.6-0.9,1.2-1.8,1.8-2.6c0.6-0.8,1.4-1.9,2.3-3.1l32.3-45.1c2.1-3,3.8-5.1,5.2-6.5s3-2,4.9-2 c6.2,0,9.2,3.7,9.2,11.1v49.2h2.6c3.1,0,5.6,0.4,7.5,1.3c1.9,0.9,2.8,2.8,2.8,5.8c0,2.5-0.8,4.2-2.3,5.4c-1.5,1.1-3.9,1.7-6.9,1.7 h-3.7v11.8c0,3.3-0.7,5.7-2.1,7.3c-1.4,1.6-3.2,2.4-5.5,2.4c-2.3,0-4.1-0.8-5.5-2.4C319.7,382.9,319,380.5,319,377.3z M292.8,351.2 H319v-36.9L292.8,351.2z"}))))},Op=i.a.forwardRef((e,t)=>i.a.createElement(Ap,Lp({svgRef:t},e)));var Ip,Gp,Rp,Up,Mp,Wp,zp,Kp,Hp,qp,Vp,jp,$p,Yp,_p;a.p;function Zp(){return(Zp=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Zp({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#50BEE8"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M96.928,327.84v47.328c0,5.648-4.608,8.832-9.216,8.832c-4.096,0-7.68-3.184-7.68-8.832v-72.016 c0-6.656,5.632-8.848,7.68-8.848c3.696,0,5.872,2.192,8.064,4.624l28.128,37.984l29.168-39.408c4.24-5.232,14.592-3.2,14.592,5.648 v72.016c0,5.648-3.568,8.832-7.664,8.832c-4.608,0-8.192-3.184-8.192-8.832V327.84l-21.248,26.864 c-4.592,5.648-10.352,5.648-14.576,0L96.928,327.84z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M234.096,385.28c-23.664,1.024-48.24-14.72-48.24-46.064c0-31.472,24.56-46.944,48.24-46.944 c22.384,1.136,45.792,16.624,45.792,46.944C279.888,369.552,256.48,385.28,234.096,385.28z M232.688,308.912 c-14.336,0-29.936,10.112-29.936,30.32c0,20.096,15.616,30.336,29.936,30.336c14.72,0,30.448-10.24,30.448-30.336 C263.136,319.008,247.408,308.912,232.688,308.912z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M323.664,378.256l-33.776-70.752c-4.992-10.112,10.112-18.416,15.728-7.808l11.392,25.712 l14.704,33.776l14.448-33.776l11.392-25.712c5.12-9.712,19.952-3.584,15.616,7.04l-32.624,71.52 C337.6,386.32,328.512,388.224,323.664,378.256z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Ip||(Ip=i.a.createElement("g",null)),Gp||(Gp=i.a.createElement("g",null)),Rp||(Rp=i.a.createElement("g",null)),Up||(Up=i.a.createElement("g",null)),Mp||(Mp=i.a.createElement("g",null)),Wp||(Wp=i.a.createElement("g",null)),zp||(zp=i.a.createElement("g",null)),Kp||(Kp=i.a.createElement("g",null)),Hp||(Hp=i.a.createElement("g",null)),qp||(qp=i.a.createElement("g",null)),Vp||(Vp=i.a.createElement("g",null)),jp||(jp=i.a.createElement("g",null)),$p||($p=i.a.createElement("g",null)),Yp||(Yp=i.a.createElement("g",null)),_p||(_p=i.a.createElement("g",null)))},Qp=i.a.forwardRef((e,t)=>i.a.createElement(Jp,Zp({svgRef:t},e)));var Xp,eh,th,ah,nh,ih,rh,lh,sh,oh,ch,dh,mh,ph,hh;a.p;function gh(){return(gh=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",gh({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#576D7E"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M132.784,311.472H110.4c-11.136,0-11.136-16.368,0-16.368h60.512c11.392,0,11.392,16.368,0,16.368 h-21.248v64.592c0,11.12-16.896,11.392-16.896,0v-64.592H132.784z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M224.416,326.176l22.272-27.888c6.656-8.688,19.568,2.432,12.288,10.752 c-7.68,9.088-15.728,18.944-23.424,29.024l26.112,32.496c7.024,9.6-7.04,18.816-13.952,9.344l-23.536-30.192l-23.152,30.832 c-6.528,9.328-20.992-1.152-13.68-9.856l25.696-32.624c-8.048-10.096-15.856-19.936-23.664-29.024 c-8.064-9.6,6.912-19.44,12.784-10.48L224.416,326.176z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M298.288,311.472H275.92c-11.136,0-11.136-16.368,0-16.368h60.496c11.392,0,11.392,16.368,0,16.368 h-21.232v64.592c0,11.12-16.896,11.392-16.896,0V311.472z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Xp||(Xp=i.a.createElement("g",null)),eh||(eh=i.a.createElement("g",null)),th||(th=i.a.createElement("g",null)),ah||(ah=i.a.createElement("g",null)),nh||(nh=i.a.createElement("g",null)),ih||(ih=i.a.createElement("g",null)),rh||(rh=i.a.createElement("g",null)),lh||(lh=i.a.createElement("g",null)),sh||(sh=i.a.createElement("g",null)),oh||(oh=i.a.createElement("g",null)),ch||(ch=i.a.createElement("g",null)),dh||(dh=i.a.createElement("g",null)),mh||(mh=i.a.createElement("g",null)),ph||(ph=i.a.createElement("g",null)),hh||(hh=i.a.createElement("g",null)))},bh=i.a.forwardRef((e,t)=>i.a.createElement(uh,gh({svgRef:t},e)));var vh,yh,fh,Eh,Sh,Ch,xh,kh,wh,Th,Dh,Ph,Fh,Nh,Bh;a.p;function Lh(){return(Lh=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Lh({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#84BD5A"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M99.968,384c-4.608,0-7.808-3.456-7.808-7.936v-72.656c0-4.608,3.2-7.936,7.808-7.936h35.952 c16.768,0,25.84,11.392,25.84,24.432c0,5.744-1.664,11.392-7.024,16.128c10.096,3.968,14.576,11.76,14.576,21.232 c-0.016,14.704-10,26.736-29.184,26.736H99.968z M135.904,311.072h-26.992v19.056h26.992c5.504,0,8.96-3.456,8.96-10.24 C144.864,315.68,141.408,311.072,135.904,311.072z M108.912,368.384h31.216c14.848,0,14.848-22.64,0-22.64 c-9.712,0-21.104,0-31.216,0V368.384z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M201.456,327.84v47.328c0,5.648-4.608,8.832-9.2,8.832c-4.096,0-7.68-3.184-7.68-8.832v-72.016 c0-6.656,5.648-8.848,7.68-8.848c3.696,0,5.872,2.192,8.048,4.624l28.16,37.984l29.152-39.408c4.24-5.232,14.592-3.2,14.592,5.648 v72.016c0,5.648-3.584,8.832-7.664,8.832c-4.608,0-8.192-3.184-8.192-8.832V327.84l-21.248,26.864 c-4.592,5.648-10.352,5.648-14.576,0L201.456,327.84z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M290.176,303.152c0-4.224,3.328-8.848,8.704-8.848h29.552c16.64,0,31.616,11.136,31.616,32.496 c0,20.224-14.976,31.472-31.616,31.472h-21.36v16.896c0,5.648-3.584,8.832-8.192,8.832c-4.224,0-8.704-3.184-8.704-8.832 L290.176,303.152L290.176,303.152z M307.056,310.432v31.856h21.36c8.576,0,15.36-7.552,15.36-15.488 c0-8.96-6.784-16.368-15.36-16.368L307.056,310.432L307.056,310.432z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),vh||(vh=i.a.createElement("g",null)),yh||(yh=i.a.createElement("g",null)),fh||(fh=i.a.createElement("g",null)),Eh||(Eh=i.a.createElement("g",null)),Sh||(Sh=i.a.createElement("g",null)),Ch||(Ch=i.a.createElement("g",null)),xh||(xh=i.a.createElement("g",null)),kh||(kh=i.a.createElement("g",null)),wh||(wh=i.a.createElement("g",null)),Th||(Th=i.a.createElement("g",null)),Dh||(Dh=i.a.createElement("g",null)),Ph||(Ph=i.a.createElement("g",null)),Fh||(Fh=i.a.createElement("g",null)),Nh||(Nh=i.a.createElement("g",null)),Bh||(Bh=i.a.createElement("g",null)))},Oh=i.a.forwardRef((e,t)=>i.a.createElement(Ah,Lh({svgRef:t},e)));var Ih,Gh,Rh,Uh,Mh,Wh,zh,Kh,Hh,qh,Vh,jh,$h,Yh,_h;a.p;function Zh(){return(Zh=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Zh({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#A066AA"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M107.136,327.84v47.328c0,5.648-4.608,8.832-9.216,8.832c-4.096,0-7.664-3.184-7.664-8.832v-72.016 c0-6.656,5.632-8.848,7.664-8.848c3.712,0,5.888,2.192,8.064,4.624l28.144,37.984l29.168-39.408 c4.224-5.232,14.576-3.2,14.576,5.648v72.016c0,5.648-3.568,8.832-7.664,8.832c-4.608,0-8.192-3.184-8.192-8.832V327.84 l-21.232,26.864c-4.608,5.648-10.352,5.648-14.592,0L107.136,327.84z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M200.624,303.152c0-10.496,16.896-10.88,16.896,0v73.024c0,10.624-16.896,10.88-16.896,0V303.152z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M248.96,384c-4.224,0-8.832-2.32-8.832-7.936v-72.656c0-4.608,4.608-7.936,8.832-7.936h29.296 c58.464,0,57.184,88.528,1.152,88.528H248.96z M257.008,311.072v57.312h21.232c34.544,0,36.08-57.312,0-57.312H257.008z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M339.952,303.152c0-10.496,16.896-10.88,16.896,0v73.024c0,10.624-16.896,10.88-16.896,0V303.152z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Ih||(Ih=i.a.createElement("g",null)),Gh||(Gh=i.a.createElement("g",null)),Rh||(Rh=i.a.createElement("g",null)),Uh||(Uh=i.a.createElement("g",null)),Mh||(Mh=i.a.createElement("g",null)),Wh||(Wh=i.a.createElement("g",null)),zh||(zh=i.a.createElement("g",null)),Kh||(Kh=i.a.createElement("g",null)),Hh||(Hh=i.a.createElement("g",null)),qh||(qh=i.a.createElement("g",null)),Vh||(Vh=i.a.createElement("g",null)),jh||(jh=i.a.createElement("g",null)),$h||($h=i.a.createElement("g",null)),Yh||(Yh=i.a.createElement("g",null)),_h||(_h=i.a.createElement("g",null)))},Qh=i.a.forwardRef((e,t)=>i.a.createElement(Jh,Zh({svgRef:t},e)));var Xh,eg,tg,ag,ng,ig,rg,lg,sg,og,cg,dg,mg,pg,hg;a.p;function gg(){return(gg=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",gg({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#F7B84E"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M149.696,303.152c0-4.224,3.328-8.848,8.704-8.848h29.552c16.64,0,31.616,11.136,31.616,32.496 c0,20.224-14.976,31.472-31.616,31.472h-21.36v16.896c0,5.648-3.584,8.832-8.192,8.832c-4.224,0-8.704-3.184-8.704-8.832V303.152z M166.592,310.432v31.856h21.36c8.576,0,15.36-7.552,15.36-15.488c0-8.96-6.784-16.368-15.36-16.368L166.592,310.432 L166.592,310.432z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M234.032,314.656c2.944-24.816,40.416-29.28,58.08-15.712c8.704,7.024-0.512,18.16-8.192,12.528 c-9.472-6.016-30.96-8.832-33.648,4.464c-3.456,20.992,52.192,8.976,51.296,42.992c-0.896,32.496-47.968,33.264-65.632,18.672 c-4.24-3.44-4.096-9.056-1.792-12.528c3.328-3.312,7.024-4.464,11.392-0.896c10.48,7.168,37.488,12.544,39.392-5.648 C283.28,339.616,230.064,351.008,234.032,314.656z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Xh||(Xh=i.a.createElement("g",null)),eg||(eg=i.a.createElement("g",null)),tg||(tg=i.a.createElement("g",null)),ag||(ag=i.a.createElement("g",null)),ng||(ng=i.a.createElement("g",null)),ig||(ig=i.a.createElement("g",null)),rg||(rg=i.a.createElement("g",null)),lg||(lg=i.a.createElement("g",null)),sg||(sg=i.a.createElement("g",null)),og||(og=i.a.createElement("g",null)),cg||(cg=i.a.createElement("g",null)),dg||(dg=i.a.createElement("g",null)),mg||(mg=i.a.createElement("g",null)),pg||(pg=i.a.createElement("g",null)),hg||(hg=i.a.createElement("g",null)))},bg=i.a.forwardRef((e,t)=>i.a.createElement(ug,gg({svgRef:t},e)));var vg,yg,fg,Eg,Sg,Cg,xg,kg,wg,Tg,Dg,Pg,Fg,Ng,Bg;a.p;function Lg(){return(Lg=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Lg({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#F7B84E"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M96.816,314.656c2.944-24.816,40.416-29.28,58.08-15.712c8.704,7.024-0.512,18.16-8.192,12.528 c-9.472-6.016-30.96-8.832-33.648,4.464c-3.456,20.992,52.192,8.976,51.312,42.992c-0.896,32.496-47.984,33.264-65.648,18.672 c-4.224-3.44-4.096-9.056-1.792-12.528c3.328-3.312,7.04-4.464,11.392-0.896c10.48,7.168,37.488,12.544,39.392-5.648 C146.064,339.616,92.848,351.008,96.816,314.656z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M209.12,378.256l-33.776-70.752c-4.992-10.112,10.112-18.416,15.728-7.808l11.392,25.712 l14.704,33.776l14.448-33.776l11.392-25.712c5.12-9.712,19.952-3.584,15.616,7.04L226,378.256 C223.056,386.32,213.984,388.224,209.12,378.256z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M345.76,374.16c-9.088,7.536-20.224,10.752-31.472,10.752c-26.88,0-45.936-15.36-45.936-45.808 c0-25.84,20.096-45.92,47.072-45.92c10.112,0,21.232,3.456,29.168,11.264c7.792,7.664-3.456,19.056-11.12,12.288 c-4.736-4.624-11.392-8.064-18.048-8.064c-15.472,0-30.432,12.4-30.432,30.432c0,18.944,12.528,30.448,29.296,30.448 c7.792,0,14.448-2.304,19.184-5.76V348.08h-19.184c-11.392,0-10.24-15.632,0-15.632h25.584c4.736,0,9.072,3.6,9.072,7.568v27.248 C348.96,369.552,347.936,371.712,345.76,374.16z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),vg||(vg=i.a.createElement("g",null)),yg||(yg=i.a.createElement("g",null)),fg||(fg=i.a.createElement("g",null)),Eg||(Eg=i.a.createElement("g",null)),Sg||(Sg=i.a.createElement("g",null)),Cg||(Cg=i.a.createElement("g",null)),xg||(xg=i.a.createElement("g",null)),kg||(kg=i.a.createElement("g",null)),wg||(wg=i.a.createElement("g",null)),Tg||(Tg=i.a.createElement("g",null)),Dg||(Dg=i.a.createElement("g",null)),Pg||(Pg=i.a.createElement("g",null)),Fg||(Fg=i.a.createElement("g",null)),Ng||(Ng=i.a.createElement("g",null)),Bg||(Bg=i.a.createElement("g",null)))},Og=i.a.forwardRef((e,t)=>i.a.createElement(Ag,Lg({svgRef:t},e)));var Ig,Gg,Rg,Ug,Mg,Wg,zg,Kg,Hg,qg,Vg,jg,$g,Yg,_g;a.p;function Zg(){return(Zg=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Zg({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#A066AA"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M155.824,311.472H133.44c-11.12,0-11.12-16.368,0-16.368h60.512c11.376,0,11.376,16.368,0,16.368 H172.72v64.592c0,11.12-16.896,11.392-16.896,0C155.824,376.064,155.824,311.472,155.824,311.472z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M217.536,303.152c0-10.496,16.896-10.88,16.896,0v73.024c0,10.624-16.896,10.88-16.896,0V303.152z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M273.712,312.096v20.336h32.608c4.608,0,9.216,4.608,9.216,9.088c0,4.224-4.608,7.664-9.216,7.664 h-32.608v26.864c0,4.48-3.2,7.936-7.68,7.936c-5.632,0-9.072-3.456-9.072-7.936v-72.656c0-4.608,3.456-7.936,9.072-7.936h44.912 c5.632,0,8.96,3.328,8.96,7.936c0,4.096-3.328,8.688-8.96,8.688h-37.232V312.096z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Ig||(Ig=i.a.createElement("g",null)),Gg||(Gg=i.a.createElement("g",null)),Rg||(Rg=i.a.createElement("g",null)),Ug||(Ug=i.a.createElement("g",null)),Mg||(Mg=i.a.createElement("g",null)),Wg||(Wg=i.a.createElement("g",null)),zg||(zg=i.a.createElement("g",null)),Kg||(Kg=i.a.createElement("g",null)),Hg||(Hg=i.a.createElement("g",null)),qg||(qg=i.a.createElement("g",null)),Vg||(Vg=i.a.createElement("g",null)),jg||(jg=i.a.createElement("g",null)),$g||($g=i.a.createElement("g",null)),Yg||(Yg=i.a.createElement("g",null)),_g||(_g=i.a.createElement("g",null)))},Qg=i.a.forwardRef((e,t)=>i.a.createElement(Jg,Zg({svgRef:t},e)));var Xg,eu,tu,au,nu,iu,ru,lu,su,ou,cu,du,mu,pu,hu;a.p;function gu(){return(gu=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",gu({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#84BD5A"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M153.216,353.44l19.056-52.72c3.824-10.336,19.312-5.504,15.472,5.632l-25.328,68.72 c-2.304,7.28-4.464,9.472-8.832,9.472c-4.592,0-6.016-2.832-8.56-7.44l-22.256-50.544l-21.232,49.776 c-2.32,5.36-4.464,8.432-9.088,8.432c-4.464,0-6.784-3.072-8.816-8.704l-24.816-69.728c-3.84-11.504,12.4-15.712,15.712-5.632 l18.944,52.72l22.656-52.72c3.056-7.792,11.12-8.192,14.432-0.368L153.216,353.44z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M219.744,327.84v47.344c0,5.632-4.608,8.816-9.2,8.816c-4.096,0-7.68-3.184-7.68-8.816v-72.032 c0-6.656,5.648-8.832,7.68-8.832c3.696,0,5.872,2.176,8.048,4.608l28.16,38l29.152-39.408c4.24-5.248,14.592-3.2,14.592,5.632 v72.032c0,5.632-3.6,8.816-7.68,8.816c-4.592,0-8.192-3.184-8.192-8.816V327.84l-21.232,26.88c-4.592,5.632-10.352,5.632-14.576,0 L219.744,327.84z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M339.776,378.256L306,307.504c-4.992-10.096,10.112-18.4,15.728-7.792l11.392,25.696l14.704,33.776 l14.448-33.776l11.392-25.696c5.12-9.728,19.952-3.584,15.616,7.04l-32.624,71.504C353.712,386.32,344.64,388.224,339.776,378.256z "})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),Xg||(Xg=i.a.createElement("g",null)),eu||(eu=i.a.createElement("g",null)),tu||(tu=i.a.createElement("g",null)),au||(au=i.a.createElement("g",null)),nu||(nu=i.a.createElement("g",null)),iu||(iu=i.a.createElement("g",null)),ru||(ru=i.a.createElement("g",null)),lu||(lu=i.a.createElement("g",null)),su||(su=i.a.createElement("g",null)),ou||(ou=i.a.createElement("g",null)),cu||(cu=i.a.createElement("g",null)),du||(du=i.a.createElement("g",null)),mu||(mu=i.a.createElement("g",null)),pu||(pu=i.a.createElement("g",null)),hu||(hu=i.a.createElement("g",null)))},bu=i.a.forwardRef((e,t)=>i.a.createElement(uu,gu({svgRef:t},e)));var vu,yu,fu,Eu,Su,Cu,xu,ku,wu,Tu,Du,Pu,Fu,Nu,Bu;a.p;function Lu(){return(Lu=Object.assign||function(e){for(var t=1;t{let{svgRef:t,title:a,...n}=e;return i.a.createElement("svg",Lu({id:"Layer_1",x:"0px",y:"0px",viewBox:"0 0 512 512",style:{enableBackground:"new 0 0 512 512"},xmlSpace:"preserve",ref:t},n),a?i.a.createElement("title",null,a):null,i.a.createElement("path",{style:{fill:"#E2E5E7"},d:"M128,0c-17.6,0-32,14.4-32,32v448c0,17.6,14.4,32,32,32h320c17.6,0,32-14.4,32-32V128L352,0H128z"}),i.a.createElement("path",{style:{fill:"#B0B7BD"},d:"M384,128h96L352,0v96C352,113.6,366.4,128,384,128z"}),i.a.createElement("polygon",{style:{fill:"#CAD1D8"},points:"480,224 384,128 480,128 "}),i.a.createElement("path",{style:{fill:"#50BEE8"},d:"M416,416c0,8.8-7.2,16-16,16H48c-8.8,0-16-7.2-16-16V256c0-8.8,7.2-16,16-16h352c8.8,0,16,7.2,16,16 V416z"}),i.a.createElement("g",null,i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M100,303.152c0-4.224,3.328-8.848,8.688-8.848h29.552c16.64,0,31.616,11.136,31.616,32.496 c0,20.224-14.976,31.472-31.616,31.472h-21.36v16.896c0,5.648-3.584,8.832-8.192,8.832c-4.224,0-8.688-3.184-8.688-8.832V303.152z M116.88,310.432v31.856h21.36c8.576,0,15.36-7.552,15.36-15.488c0-8.96-6.784-16.368-15.36-16.368L116.88,310.432L116.88,310.432z "}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M184.32,314.656c2.944-24.816,40.416-29.28,58.08-15.712c8.704,7.024-0.512,18.16-8.192,12.528 c-9.472-6.016-30.96-8.832-33.648,4.464c-3.456,20.992,52.192,8.976,51.296,42.992c-0.896,32.496-47.968,33.264-65.632,18.672 c-4.24-3.44-4.096-9.056-1.792-12.528c3.328-3.312,7.024-4.464,11.392-0.896c10.48,7.168,37.488,12.544,39.392-5.648 C233.568,339.616,180.336,351.008,184.32,314.656z"}),i.a.createElement("path",{style:{fill:"#FFFFFF"},d:"M278.24,384c-4.224,0-8.832-2.32-8.832-7.936v-72.656c0-4.608,4.608-7.936,8.832-7.936h29.296 C366,295.472,364.72,384,308.688,384H278.24z M286.304,311.072v57.312h21.232c34.544,0,36.08-57.312,0-57.312H286.304z"})),i.a.createElement("path",{style:{fill:"#CAD1D8"},d:"M400,432H96v16h304c8.8,0,16-7.2,16-16v-16C416,424.8,408.8,432,400,432z"}),vu||(vu=i.a.createElement("g",null)),yu||(yu=i.a.createElement("g",null)),fu||(fu=i.a.createElement("g",null)),Eu||(Eu=i.a.createElement("g",null)),Su||(Su=i.a.createElement("g",null)),Cu||(Cu=i.a.createElement("g",null)),xu||(xu=i.a.createElement("g",null)),ku||(ku=i.a.createElement("g",null)),wu||(wu=i.a.createElement("g",null)),Tu||(Tu=i.a.createElement("g",null)),Du||(Du=i.a.createElement("g",null)),Pu||(Pu=i.a.createElement("g",null)),Fu||(Fu=i.a.createElement("g",null)),Nu||(Nu=i.a.createElement("g",null)),Bu||(Bu=i.a.createElement("g",null)))},Ou=i.a.forwardRef((e,t)=>i.a.createElement(Au,Lu({svgRef:t},e)));a.p;var Iu=a(834),Gu=a.n(Iu),Ru=a(835),Uu=a.n(Ru);const Mu=Object(z.a)(e=>({small:{width:"32px",height:"32px"},medium:{width:"135px",height:"180px"}}));function Wu(e){const{contentType:t,size:a}=e;return function(e,t,a){switch(e.toLowerCase()){case"pdf":return i.a.createElement(xc,{className:a[t]});case"jpg":return i.a.createElement(zc,{className:a[t]});case"doc":case"docx":return i.a.createElement(rd,{className:a[t]});case"gif":return i.a.createElement(xd,{className:a[t]});case"mp3":return i.a.createElement(zd,{className:a[t]});case"xls":case"xlsx":return i.a.createElement(rm,{className:a[t]});case"png":return i.a.createElement(xm,{className:a[t]});case"ppt":case"pptx":return i.a.createElement(zm,{className:a[t]});case"zip":return i.a.createElement(rp,{className:a[t]});case"ai":return i.a.createElement(xp,{className:a[t]});case"mp4":return i.a.createElement(Op,{className:a[t]});case"mov":return i.a.createElement(Qp,{className:a[t]});case"txt":return i.a.createElement(bh,{className:a[t]});case"bmp":return i.a.createElement(Oh,{className:a[t]});case"midi":return i.a.createElement(Qh,{className:a[t]});case"ps":return i.a.createElement(bg,{className:a[t]});case"svg":return i.a.createElement(Og,{className:a[t]});case"tif":return i.a.createElement(Qg,{className:a[t]});case"wmv":return i.a.createElement(bu,{className:a[t]});case"psd":return i.a.createElement(Ou,{className:a[t]});case"folder":return i.a.createElement(Gu.a,{fill:"#cec177",color:"secondary",className:a[t]});default:return i.a.createElement(Uu.a,{fill:"#cec177",color:"secondary",className:a[t]})}}(t,a,Mu())}Wu.defaultProps={size:"medium"};const zu=[{name:"descrName",min:1,max:200}];class Ku extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,zu),this.handleChange=e=>{let t={...this.state.file};t[e.target.id]=e.target.value,this.setState({file:t,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,file:{descrName:""},errors:{count:0},changed:!1,isloading:!1}}componentDidMount(){const{isNew:e,file:t}=this.props;e||this.setState({file:t})}validateField(e,t){let a=jn(e,this.state.file,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,metaData:l,getFromGlobalState:s,handlePreExecute:o,handleDeletePreExecute:c,parent:d,handleDeleteDialogObject:m,allowDelete:p}=this.props,{file:h,errors:g}=this.state,u=$n(h,zu);return i.a.createElement(Ia,{open:t,dialogObject:h,setClose:n,isNew:a,allowDelete:!0,handleDeletePreExecute:c,handleUpdateDialogObject:r.bind(this),handleDeleteDialogObject:m,skPrimary:"init_setting_",dynamoType:"files",parentKey:d?d.sk:null,valid:u,changed:this.state.changed,newTitle:"",title:h&&h.descrName?h.descrName:"",getFromGlobalState:s},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"descrName",label:"Name",name:"descrName",autoFocus:!0,value:h.descrName?h.descrName:h.filenameWithoutExtension,onChange:this.handleChange,onBlur:this.handleBlur,error:!!g.descrName||void 0,helperText:g.descrName}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"description",label:"Description",name:"description",value:h.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!g.description||void 0,helperText:g.description}),i.a.createElement("br",null))}}Ku.defaultProps={parent:null};var Hu=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Ku);class qu extends n.Component{constructor(e){super(e),this.handleAddFolder=e=>{if(e){const t=this.props.getFromGlobalState("folders"),a=t.findIndex(t=>t.sk===e);if(-1===a)return alert("impossible folder not found"),null;this.setState({addFolderDialogOpen:!0,isNew:!0,selectedParent:t[a]})}else this.setState({addFolderDialogOpen:!0,isNew:!0,selectedParent:null})},this.setClose=()=>{this.setState({addFolderDialogOpen:!1,selectedFolder:null,selectedParent:null})},this.setCloseFileDialog=()=>{this.setState({fileDialogOpen:!1})},this.handleUpdate=e=>{const t=this.props.getFromGlobalState("folders"),a=t.findIndex(t=>t.sk===e.sk);-1===a?t.push(e):t[a]=e,this.props.setGlobalState({folders:t})},this.handleFileUpdate=e=>{const t=this.props.getFromGlobalState("files"),a=t.findIndex(e=>e.sk===this.state.selectedFile.sk);-1===a?t.push(e):t[a]=e,this.props.setGlobalState({files:t})},this.handleFolderExpand=e=>{this.state.expandedFolder!==e?this.setState({expandedFolder:e}):this.setState({expandedFolder:""})},this.handleSectionExpand=e=>{this.state.expandedSection!==e?this.setState({expandedSection:e}):this.setState({expandedSection:""})},this.getIcon=e=>i.a.createElement(Wu,{size:"small",contentType:e}," "),this.handleDownload=async(e,t,a)=>{e.preventDefault(),e.stopPropagation(),e.persist(),this.setState({urlLoading:!0,selectedDownloadKey:t});const n=this.props.getFromGlobalState("files").find(e=>e.Key===t);n||alert("impossible file not in state");const i={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:t,tenant:a,files:!0,contentType:"application/octet-stream"};try{const e=await Fa(i);return this.link.href=e,this.link.download=n.filename,this.setState({urlLoading:!1,selectedDownloadKey:""}),this.link.click(),!0}catch(r){this.props.setSnack({open:!0,variant:"error",messageText:Pa(r)})}},this.handleClick=e=>{e.stopPropagation()},this.isLoading=e=>e===this.state.selectedDownloadKey,this.getDownloadLink=(e,t,a,n)=>i.a.createElement("a",{href:"",style:{color:"inherit"},ref:e=>this.link=e,onClick:e=>this.handleClick(e),download:e},i.a.createElement(I.a,{title:"Download"},i.a.createElement(la,{onClick:e=>this.handleDownload(e,t,n),color:"inherit",success:!0,icon:i.a.createElement(Wa.a,null),loading:this.state.urlLoading&&this.isLoading(t)}))),this.handleEditFolder=(e,t)=>{t.stopPropagation(),this.setState({addFolderDialogOpen:!0,isNew:!1,selectedFolder:e})},this.getFolderAction=e=>i.a.createElement(E.a,{style:{padding:"0px",float:"right"},"aria-label":"Edit",className:this.props.classes.menuButton,onClick:this.handleEditFolder.bind(this,e)},i.a.createElement(A.a,null)),this.renderFolder=(e,t)=>{const{isMobile:a}=this.state;let n=!1;e.name===this.state.expandedFolder&&(n=!0);let r=[];n&&(r=this.props.getFromGlobalState("folders"),r||(r=[]),r=r.filter(t=>t.path.startsWith(e.path)&&t.parentSK),r||(r=[]));const l=this.props.getFromGlobalState("userDetail");return i.a.createElement(cr,{heading:e.name,key:e.sk,detailHeading:a?void 0:e.description,action:this.getFolderAction(e),expanded:this.state.expandedFolder,handleExpand:this.handleFolderExpand},i.a.createElement(g.a,{container:!0,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Te.a,{variant:"extended",size:"medium",style:{float:"right",marginLeft:"auto",color:"black",backgroundColor:"transparent"},color:"primary","aria-label":"add",disabled:l&&l.rights&&l.rights.readOnly,className:this.props.classes.margin,onClick:this.handleAddFolder.bind(this,e.sk)},i.a.createElement(C.a,{className:this.props.classes.extendedIcon}),"Section")),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},n&&r.map(e=>i.a.createElement(i.a.Fragment,null,this.renderSection(e,t))))))},this.renderSection=(e,t)=>{const{isMobile:a}=this.state;let n=[];if(e.name===this.state.expandedSection){this.props.getFromGlobalState("files");const t=this.props.getFromGlobalState("files").filter(t=>t.Key.startsWith(e.path));n=t&&t.map(e=>{const t={...e};return t.uploaded=new Date(t.createdAt).toLocaleDateString(),t.sizeString=this.getSizeString(t.fileSize),t.descrName=t.descrName?t.descrName:t.filenameWithoutExtension,t.icon=this.getIcon(e.fileExtension),console.log("obbbbbb",t),t.downloadLink=this.getDownloadLink(t.filename,t.Key,t.fileType,t.farmId),t})}n=n&&n.sort((e,t)=>(""+e.descrName).localeCompare(t.descrName,void 0,{numeric:!0}));const{headCells:r}=this.state;return i.a.createElement(i.a.Fragment,null,i.a.createElement(cr,{heading:e.name,key:e.sk,disablePadding:!0,style:{margingLeft:"10px"},detailHeading:a?void 0:e.description,action:this.getFolderAction(e),expanded:this.state.expandedSection,handleExpand:this.handleSectionExpand},i.a.createElement(g.a,{container:!0,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Me,{heading:"Files",hideHeading:!0,id:"fileTable",noPagination:!0,rows:n,headCells:r,handleSelect:this.handleClickShowFile.bind(this),rowKeyName:"sk",disablePadFirstCol:!0,padFirstCol:"5px",clean:!0,dense:!0,maxHeight:"350px",selectedRow:this.state.selectedFile})),i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},t&&i.a.createElement(B.a,null,"Maximum storage of 1GB reached"),!t&&i.a.createElement(nr,{activeTenant:this.props.getFromGlobalState("activeSite"),generateThumbnail:!1,generatePreview:!1,onFileUploaded:this.fileUploaded.bind(this),folder:e.path,getFromGlobalState:this.props.getFromGlobalState})))))},this.state={addFolderDialogOpen:!1,expandedFolder:"",expandedSection:"",selectedFolder:null,selectedParent:null,isNew:!1,headCells:[],selectedFile:null,fileDialogOpen:!1,link:null,urlLoading:!1,selectedDownloadKey:"",isMobile:!1}}async componentDidMount(){if(!this.props.isAuthenticated)return;const e=!window.matchMedia("(min-width: 850px)").matches;let t={...this.state};t=e?[{id:"icon",numeric:!1,disablePadding:!1,label:"",maxWidth:"20px"},{id:"descrName",combine:[{id:"descrName",opacity:1},{id:"filename",opacity:.6},{id:"sizeString",opacity:.4}],numeric:!1,disablePadding:!1,label:"Name",maxWidth:"100px"},{id:"downloadLink",numeric:!1,disablePadding:!1,label:""}]:[{id:"icon",numeric:!1,disablePadding:!0,label:"",maxWidth:"20px"},{id:"descrName",combine:[{id:"descrName",opacity:1},{id:"filename",opacity:.6},{id:"sizeString",opacity:.4}],numeric:!1,disablePadding:!1,label:"Name"},{id:"uploaded",numeric:!1,disablePadding:!1,label:"Modified"},{id:"downloadLink",numeric:!1,disablePadding:!1,label:""}];const a=e;this.setState({headCells:t,clean:a,isMobile:e})}handleDeleteFileUpdate(e){const t=this.props.getFromGlobalState("files"),a=t.findIndex(t=>t.sk===e.sk);-1!==a&&(t.splice(a,1),this.props.setGlobalState({files:t}))}async handleFileDeletePreExecute(e){try{const a={activeTenant:this.props.getFromGlobalState("activeSite"),Key:e.Key,type:"files"};return!!(await(t=a,console.log("api post from storage"),o.a.post("farms","/deleteFile",{body:t}))).status}catch(a){return this.props.setSnack({open:!0,variant:"error",messageText:Pa(a)}),!1}var t}async handlePreExecute(e){const t=this.props.getFromGlobalState("activeSite");if(e.activeTenant=t,!this.state.isNew)return!0;try{await(a=e,console.log("api post from Storage"),o.a.post("farms","/bucket",{body:a}));return this.setState({isloading:!1}),!1}catch(n){throw n}var a}getSizeString(e){return e<1e3?e.toLocaleString()+" bytes":e<1e6?(e/1e3).toLocaleString()+" KB":(e/1e6).toLocaleString()+" MB"}async fileUploaded(e){try{if(!e.serverId)return void console.log("received undefined key");const a=e.serverId,n={};n.sk="init_"+a,n.lastModified=e.file.lastModified,n.Key=a,n.lastModifiedDate=e.file.lastModifiedDate?e.file.lastModifiedDate:new Date(e.file.lastModified),n.fileExtension=e.fileExtension,n.filename=e.filename,n.filenameWithoutExtension=e.filenameWithoutExtension,n.fileSize=e.fileSize,n.fileType=e.fileType,n.createdAt=(new Date).valueOf(),n.version=1,n.type="files",n.activeTenant=this.props.getFromGlobalState("activeSite");await(t=n,console.log("api post from Storage"),o.a.post("farms","/farms",{body:t}));const i=this.props.getFromGlobalState("files"),r=i.findIndex(e=>e.Key===a);-1===r?i.push(n):i[r]=n,this.props.setGlobalState({files:i})}catch(a){console.log("Error from dialog",a),this.props.setSnack({open:!0,variant:"error",messageText:Pa(a)})}var t}handleClickShowFile(e,t,a,n,i,r){const l=this.props.getFromGlobalState("files").find(e=>e.sk===a);this.setState({selectedFile:l,fileDialogOpen:"true",isNew:!1})}render(){const{classes:e,getFromGlobalState:t}=this.props,{addFolderDialogOpen:a,expandedFolder:n,folder:r,fileDialogOpen:l,isNew:s}=this.state;let o=this.props.getFromGlobalState("folders");if(o=o&&o.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!0})),console.log("folders",o),!o)return null;const c=t("userDetail");o=o.filter(e=>!e.parentSK);let d=this.props.getFromGlobalState("files").reduce((e,t)=>e+parseFloat(t.fileSize),0);d=(d/1e6).toFixed(2);const m=d>1e3,p=m?100:Math.round(100*d/1e3),h=d+" MB out of 1GB used.";return i.a.createElement(N,{isloading:this.state.isloading},i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement("div",{style:{float:"right",marginLeft:"auto"}},i.a.createElement(I.a,{title:"Add Folder"},i.a.createElement(Te.a,{variant:"extended",size:"medium",color:"primary",disabled:c&&c.rights&&c.rights.readOnly,"aria-label":"add",className:e.margin,onClick:this.handleAddFolder.bind(this,null)},i.a.createElement(C.a,{className:e.extendedIcon}),"Folder"))),i.a.createElement("div",null,o&&o.map((e,t)=>this.renderFolder(e,m))),a&&i.a.createElement(Ec,{handleUpdate:this.handleUpdate,handlePreExecute:s?this.handlePreExecute.bind(this):void 0,parent:this.state.selectedParent,open:!0,folder:s?void 0:this.state.selectedFolder,isNew:s,setClose:this.setClose,getFromGlobalState:this.props.getFromGlobalState}),l&&i.a.createElement(Hu,{handleUpdate:this.handleFileUpdate,handleDeletePreExecute:this.handleFileDeletePreExecute.bind(this),handleDeleteDialogObject:this.handleDeleteFileUpdate.bind(this),allowDelete:!0,open:!0,file:s?void 0:this.state.selectedFile,isNew:s,setClose:this.setCloseFileDialog,getFromGlobalState:this.props.getFromGlobalState}),i.a.createElement("div",{style:{margin:"10px",width:"100%",textAlign:"center"}},i.a.createElement("div",{style:{display:"inline-block"}},i.a.createElement(I.a,{title:h},i.a.createElement(Ai.a,{variant:"progress",backgroundColor:"inherit",steps:100,nextButton:i.a.createElement(B.a,{style:{margin:"5px"},variant:"subtitle1"},"1GB"),backButton:i.a.createElement(B.a,{style:{margin:"5px"},variant:"subtitle1"},d+"MB"),position:"static",activeStep:p,className:e.stepper}))))))}}var Vu=Object(v.a)(e=>({root:{flexGrow:1},paper:{flexGrow:1,display:"flex",flexDirection:"column",backgroundColor:"inherit",marginBottom:e.spacing(10)},heading:{[e.breakpoints.up("sm")]:{display:"none"}},extendedIcon:{marginRight:e.spacing(1)},margin:{margin:e.spacing(1)},section:{},stepper:{width:200,flexGrow:1,backgroundColor:"inherit",progress:{color:"red",backgroundColor:"red"}}}))(qu),ju=a(1764);class $u extends n.Component{constructor(e){super(e),this.state={}}async componentDidMount(){}render(){const{classes:e,reload:t,location:{pathname:a}}=this.props;return i.a.createElement(N,{isloading:this.state.isloading},i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(B.a,{component:"h1",variant:"h5"},"Under Construction "+a),i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(O.a,{elevation:0,className:e.section},i.a.createElement(ju.a,{variant:"middle"}))))))}}var Yu=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},section:{margin:e.spacing(2,4)}}))($u);const _u=Object(z.a)(e=>({root:{width:"180px","& > *":{padding:e.spacing(1)}},paper:{marginBottom:e.spacing(2),padding:e.spacing(1)},formControl:{minWidth:120,marginTop:e.spacing(2)}}));function Zu(e){const t=_u(),{metaData:a,handleChange:n,selectedData:r,expandedFilter:l,handleExpand:s,handleToggle:o,filters:c,handleSaveFilter:d,activeFilter:m,handleFilterChange:p}=e;return a&&r?i.a.createElement("div",null,i.a.createElement(vn.a,{className:t.formControl},i.a.createElement("div",{style:{width:"100%"}},i.a.createElement(Sn.a,{native:!0,required:!0,value:m,onChange:p,inputProps:{name:"filter",id:"filter"}},i.a.createElement("option",{key:"",value:""}),c&&c.map(e=>i.a.createElement("option",{key:e.sk,value:e.sk},e.name))),i.a.createElement(I.a,{title:"Add"},i.a.createElement(E.a,{size:"medium",color:"secondary","aria-label":"add",onClick:d},i.a.createElement(C.a,null))))),i.a.createElement(cr,{heading:"Date",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.startDate&&r.endDate?1:0}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement("div",null,i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"startDate",label:"Start Date",name:"startDate",InputLabelProps:{shrink:!0},value:r.startDate,onChange:n}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,disabled:!r.startDate,minDate:r.startDate,type:"date",id:"endDate",label:"End Date",name:"endDate",inputProps:{min:r.startDate},InputLabelProps:{shrink:!0},value:r.endDate,onChange:n}))),a.userGroups.length>0&&i.a.createElement(cr,{heading:"User groups",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.userGroups.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.userGroups,checkedItems:r&&r.userGroups,handleToggle:o,arrayName:"userGroups"})),a.users.length>0&&i.a.createElement(cr,{heading:"Users",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.users.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.users,checkedItems:r&&r.users,handleToggle:o,arrayName:"users"})),i.a.createElement(cr,{heading:"Crops",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.crops.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.crops,checkedItems:r&&r.crops,handleToggle:o,arrayName:"crops"})),a.clusters&&i.a.createElement(cr,{heading:"Clusters",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.clusters.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.clusters,checkedItems:r&&r.clusters,handleToggle:o,arrayName:"clusters"})),i.a.createElement(cr,{heading:"Blocks",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.blocks.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.blocks,checkedItems:r&&r.blocks,handleToggle:o,arrayName:"blocks"})),i.a.createElement(cr,{heading:"Plantings",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.plantings.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.plantings,checkedItems:r&&r.plantings,handleToggle:o,arrayName:"plantings"})),i.a.createElement(cr,{heading:"Record Types",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.recordTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.recordTypes,checkedItems:r&&r.recordTypes,handleToggle:o,arrayName:"recordTypes"})),a.monitorTypes.length>0&&i.a.createElement(cr,{heading:"Monitor Types",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.monitorTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.monitorTypes,checkedItems:r&&r.monitorTypes,handleToggle:o,arrayName:"monitorTypes"})),a.targetTypes.length>0&&-1!==r.recordTypes.findIndex(e=>"pestings"===e)&&i.a.createElement(cr,{heading:"Target Types",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.targetTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.targetTypes,checkedItems:r&&r.targetTypes,handleToggle:o,arrayName:"targetTypes"})),a.targetTypes.length>0&&-1!==r.recordTypes.findIndex(e=>"pestings"===e)&&a.targets.length>0&&i.a.createElement(cr,{heading:"Targets",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.targets.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.targets,checkedItems:r&&r.targets,handleToggle:o,arrayName:"targets"})),a.targetTypes.length>0&&-1!==r.recordTypes.findIndex(e=>"pestings"===e)&&a.targets.length&&a.stages.length>0&&i.a.createElement(cr,{heading:"Stages",expanded:l,handleExpand:s,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:r&&r.stages.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:a.stages,checkedItems:r&&r.stages,handleToggle:o,arrayName:"stages"}))):null}const Ju=[{name:"name",min:1,max:40}];class Qu extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Ju),this.handleChange=e=>{const t={...this.state.filter};t[e.target.id]=e.target.value,this.setState({filter:t,changed:!0})},this.handleCheckChange=e=>{const t={...this.state.filter};t[e.target.id]=e.target.checked,this.setState({filter:t,changed:!0})},this.handleSaveAsNew=e=>{const t={...this.state.filter};t[e.target.id]=e.target.checked,t.name="",t.default=!1,this.setState({filter:t,changed:!0,isNew:!0})},this.state={isNew:this.props.isNew,filter:{},errors:{count:0},changed:!1}}componentDidMount(){const{filter:e}=this.props;this.setState({filter:e})}validateField(e){const t=jn(e,this.state.filter,Ju),a={...this.state.errors};a[e]=t.msg,this.setState({errors:a})}render(){const{open:e,setClose:t,handleUpdate:a,getFromGlobalState:n}=this.props,{filter:r,errors:l,changed:s,isNew:o}=this.state,c=$n(r,Ju);return r?i.a.createElement(Ia,{open:e,dialogObject:r,setClose:t,isNew:o,handleUpdateDialogObject:a.bind(this),skPrimary:"init_setting_",dynamoType:"filters",valid:c,changed:s,newTitle:"New Filter",title:"Filter",getFromGlobalState:n},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:r.saveAsNew,id:"saveAsNew",onChange:this.handleSaveAsNew,color:"secondary"}),label:"Save as New"}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Filter",name:"name",autoFocus:!0,value:r.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!l.name||void 0,helperText:l.name}),i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:r.default,id:"default",onChange:this.handleCheckChange,color:"secondary"}),label:"Default"})):null}}var Xu=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(Qu);const eb=Object(z.a)(e=>({root:{"& > *":{marginTop:e.spacing(1),padding:e.spacing(1)}},table:{},col1:{width:"80px"}}));function tb(e){const t=eb(),{data:a}=e;return a&&a.payload?i.a.createElement("div",{className:t.root},i.a.createElement(Ne.a,{component:O.a,style:{marginBottom:"30px"}},i.a.createElement(be.a,{className:t.table,size:"small","aria-label":"a dense table"},i.a.createElement(ve.a,null,i.a.createElement(Se.a,{key:"date"},i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Date"),i.a.createElement(ye.a,{component:"th",scope:"row"},new Date(a.payload.date).toLocaleDateString()),i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Block"),i.a.createElement(ye.a,{component:"th",scope:"row"},a.payload.blockName)),i.a.createElement(Se.a,{key:"block"},i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Target"),i.a.createElement(ye.a,{component:"th",scope:"row"},a.payload.observationData.targetName),i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Stage"),i.a.createElement(ye.a,{component:"th",scope:"row"},a.payload.observationData.stageDescription)),i.a.createElement(Se.a,{key:"target"},i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Average"),i.a.createElement(ye.a,{component:"th",scope:"row"},a.payload.observationData.average),i.a.createElement(ye.a,{className:t.col1,component:"th",scope:"row"},"Threshold"),i.a.createElement(ye.a,{component:"th",scope:"row"},a.payload.observationData.threshold?`Low: ${a.payload.observationData.threshold.low} Med: ${a.payload.observationData.threshold.med} High: ${a.payload.observationData.threshold.high} `:"None")))))):null}class ab extends n.Component{constructor(e){super(e),this.getBlockPaths=(e,t)=>{const a=[];for(let n=0;e&&nt.sk===e.observation.monitoringSK);let r;r=e.observation.cropSpecific?n.observableOn[0].stages.find(t=>t.sk===e.observation.stageSK):n.nonCropDetail;const l=this.getMonitoringInfo(n,r,e.observationData),s={label:n.name,position:{lat:t.latLng.lat(),lng:t.latLng.lng()},content:l};this.setState({keepBounds:!0,selectedStage:e.observation.stageSK,infoWindow:s,infoWindowPosition:{lat:t.latLng.lat(),lng:t.latLng.lng()}})}}getMonitoringInfo(e,t,a){return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{variant:"h6"},e.name),i.a.createElement(B.a,{variant:"subtitle2"}," Stage: "+t.stageDescription),i.a.createElement(B.a,{style:{color:a.color},variant:"h6"}," Average: "+a.average.toFixed(2)),i.a.createElement(B.a,{variant:"subtitle2"}," Priority: "+t.priority),i.a.createElement(B.a,{variant:"subtitle2"}," Date: "+a.date),a.threshold&&i.a.createElement(B.a,{variant:"subtitle2"},` Threshold: Low ${a.threshold.low} Med ${a.threshold.med} High ${a.threshold.high}`),i.a.createElement(B.a,{variant:"subtitle2"}," Recommended points: "+t.quantityOfUnit),i.a.createElement(B.a,{variant:"subtitle2"}," Monitored points: "+a.actualObservations))}onMapBlockClick(e,t){const{selectedBlock:a}=this.state,{getFromGlobalState:n,blocks:i}=this.props;if(i&&a!==e){const a=this.getBlockPaths(i,e),n=i&&i.find(t=>t.sk===e),r={label:n.number,position:{lat:t.latLng.lat(),lng:t.latLng.lng()},content:this.getBlockInfo(n)};this.setState({blockPaths:a,selectedBlock:e,infoWindow:r,infoWindowPosition:{lat:t.latLng.lat(),lng:t.latLng.lng()}})}}getBlockInfo(e){return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{variant:"h6"},e.number),i.a.createElement(B.a,{variant:"subtitle2"},` Size: ${e.size} ha`),i.a.createElement(B.a,{variant:"subtitle2"}," Soil Type: "+e.soilType),i.a.createElement(B.a,{variant:"subtitle2"}," Slope: "+e.slope),i.a.createElement(B.a,{variant:"subtitle2"}," Irrigation: "+("irrigated"===e.irrigated?"Irrigated":"Dry Land")))}render(){const{classes:e}=this.props,{blockPaths:t,circles:a,isLoading:n,infoWindow:r,selectedBlock:l,infoWindowPosition:s,keepBounds:o}=this.state;return i.a.createElement(N,{isloading:n,style:{width:"100%",height:"500px"}},t&&t.length&&i.a.createElement(Wn,{polygons:t,onPolygonClick:this.onMapBlockClick,onCircleClick:this.onMapCircleClick,onCloseInfoWindow:this.onCloseInfoWindow,infoWindow:r,onClick:this.onMapClick,circles:a,keepBounds:o}))}}var nb=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(ab),ib=a(31);const rb=e=>new Date(e).toLocaleDateString();function lb(e){return`hsl(${137.508*e},50%,75%)`}const sb=(e,t,a)=>new Date(e).toLocaleDateString();class ob extends n.PureComponent{render(){const{title:e,data:t,keys:a,dataKey:n,height:r,name:l,handleClick:s,Ylabel:o,procedure:c}=this.props,d=a.filter(e=>!e.includes("Block")),m=a.filter(e=>e.includes("Block"));let p=0;m.map(e=>{t.map(t=>{t[e]>=p&&(p=parseInt(t[e])+2)})});const h=t.map(e=>(d.map(t=>{e[t]&&(e[t]=p)}),e));return i.a.createElement(O.a,{elevation:0,style:{borderRadius:"4px",overflow:"hidden",marginTop:20}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),c&&i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{style:{textAlign:"center",fontSize:12},variant:"button",gutterBottom:!0},"procedure: ",c)),i.a.createElement(ib.k,{key:l+" 3",width:"100%",height:r,style:{cursor:"pointer"}},i.a.createElement(ib.e,{width:"100%",height:r,data:h,name:l,key:l+" 1",margin:{top:20,right:20,left:10,bottom:5}},i.a.createElement(ib.c,{strokeDasharray:"3 3"}),i.a.createElement(ib.o,{dataKey:n,type:"number",domain:["dataMin","dataMax"],tickFormatter:rb}),i.a.createElement(ib.p,{label:{value:o,angle:-90,position:"insideLeft"}}),i.a.createElement(ib.n,{labelFormatter:sb}),i.a.createElement(ib.f,{wrapperStyle:{fontSize:"12px"}}),a&&a.length&&a.map((e,t)=>!e.includes("Block")&&i.a.createElement(ib.a,{name:e,key:`${l}-line-${e}-i`,dataKey:e,fill:lb(t+1),barSize:5})),a&&a.length&&a.map((e,t)=>e.includes("Block")&&i.a.createElement(ib.g,{connectNulls:!0,type:"monotone",activeDot:{onClick:s,r:8},name:e,dot:{r:6},key:`${l}-line-${e}-i`,dataKey:e,stroke:lb(t+1),strokeWidth:2})))))}}ob.defaultProps={height:400};class cb extends n.Component{constructor(e){super(e),this.handleMonitorTypeExpand=e=>{const{expandedMonitorType:t}=this.state;t!==e?this.setState({expandedMonitorType:e}):this.setState({expandedMonitorType:""})},this.handleMonitorTypeExpandInner=e=>{const{expandedMonitorTypeInner:t}=this.state;t!==e?this.setState({expandedMonitorTypeInner:e}):this.setState({expandedMonitorTypeInner:""})},this.distinctPush=(e,t)=>{-1===e.findIndex(e=>e===t)&&e.push(t)},this.renderCharts=e=>{const{handleMonitoringClick:t}=this.props;return Object.keys(e).map(a=>{const n=this.findUnitValue(e[a],"unit"),r="Average "+(n?"(per"+n+")":""),l=this.findUnitValue(e[a],"procedure");return i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(ob,{dataKey:"date",key:a,title:a,height:300,name:a,handleClick:t,keys:e[a].dataKeys,Ylabel:r,procedure:l,data:e[a].data.sort((e,t)=>e.date-t.date)}))})},this.formatData=(e,t,a)=>{const n={};if(!e||!e.targetTypes)return null;for(let s=0;se.targetDetail&&e.targetDetail.type===o);console.log(c),n[o]||(n[o]={});for(let e=0;ee.targets.map(e=>e.name).includes(p));this.distinctPush(n[o][s.observationData.targetName][s.observationData.stageDescription].dataKeys,m),h.map(e=>{this.distinctPush(n[o][s.observationData.targetName][s.observationData.stageDescription].dataKeys,e.product)}),n[o][s.observationData.targetName][s.observationData.stageDescription].data||(n[o][s.observationData.targetName][s.observationData.stageDescription].data=[]);const g={date:new Date(s.observationData.date).getTime()};g[m]=null===(l=s.observationData.average)||void 0===l?void 0:l.toFixed(1),g.blockName=m,g.observationData=s.observationData,n[o][s.observationData.targetName][s.observationData.stageDescription].data.push(g),h.map(e=>{const t={[e.product]:e.volume,date:new Date(e.date).getTime(),pest:e},a=n[o][s.observationData.targetName][s.observationData.stageDescription].data;this.addUnique(a,t)})}}return n},this.state={graphData:{},expandedMonitorType:"",expandedMonitorTypeInner:""}}componentDidMount(){const{data:e,chemicals:t,getFromGlobalState:a}=this.props,n=a("targetsTypesSetting"),i=this.formatData(e,t,n);i&&this.setState({graphData:i})}componentDidUpdate(e){const{data:t,chemicals:a,getFromGlobalState:n}=this.props,i=n("targetsTypesSetting");if(t!==e.data){const e=this.formatData(t,a,i);this.setState({graphData:e})}}findUnitValue(e,t){return function e(a){if(a&&"object"===typeof a){if(a.hasOwnProperty(t))return a[t];for(const t in a)if(a.hasOwnProperty(t)){const n=e(a[t]);if(n)return n}}return null}(e)}aggregateChemicalData(e,t,a){const n=[],i=e=>{const t=(this.props.getFromGlobalState("monitorings")||[]).find(t=>t.sk===e);return t?t.targetDetail.name:"Unknown"};return e&&e.forEach(e=>{const{product:r,volume:l,date:s,reasons:o}=e,c=t.find(e=>e.sk===r);c&&o&&o.forEach(e=>{if(e.applied){const t=(e=>{const t=(a||[]).find(t=>t.sk===e);return t?t.name:"Unknown"})(e.targetType);let r=n.find(e=>e.product===c.name&&e.date===s&&e.targetType===t);r||(r={product:c.name,date:s,volume:0,targets:[],targetType:t},n.push(r)),r.volume+=l;r.targets.some(t=>t.target===e.target)||r.targets.push({name:i(e.target),targetType:e.targetType})}})}),n}createUniqueId(e){var t,a,n;const i=null===(t=e.pest)||void 0===t?void 0:t.targets.map(e=>`${e.name}:${e.targetType}`).sort().join("|");return`${null===(a=e.pest)||void 0===a?void 0:a.product}:${e.date}:${null===(n=e.pest)||void 0===n?void 0:n.volume}:${i}`}addUnique(e,t){const a=new Set(e.map(e=>this.createUniqueId(e))),n=this.createUniqueId(t);return!a.has(n)&&(e.push(t),!0)}addAveragesToObservationData(e){const t={};e&&e.forEach(e=>{const a=e.observationData,n=a.block,i=a.planting,r=a.targetName,l=a.stageDescription,s=new Date(a.date).toISOString().split("T")[0],o=`${n}_${i}_${r}_${l}_${s}`;t[o]||(t[o]={totalObservations:0,observationCount:0,pestType:r,block:n,date:s,originalItem:e}),t[o].totalObservations+=a.value,t[o].observationCount+=1});return Object.values(t).map(e=>{const t=e.totalObservations/e.observationCount;return{...e.originalItem,observationData:{...e.originalItem.observationData,average:t,totalObservations:e.totalObservations,observationCount:e.observationCount,date:e.date}}})}render(){const{classes:e}=this.props,{graphData:t,expandedMonitorType:a,expandedMonitorTypeInner:n}=this.state;return i.a.createElement(O.a,{elevation:1,style:{marginTop:"10px",maxHeight:"80vh",minHeight:"400px",overflowY:"auto",backgroundClip:"inherit"}},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},t&&Object.keys(t).map(e=>i.a.createElement(cr,{heading:e,overwriteDisplay:!0,expanded:a,handleExpand:this.handleMonitorTypeExpand},Object.keys(t[e]).map(a=>i.a.createElement("div",{style:{width:"100%",marginBottom:"5px"}},i.a.createElement(cr,{heading:a,overwriteDisplay:!0,expanded:n,handleExpand:this.handleMonitorTypeExpandInner},i.a.createElement("div",{style:{width:"100%"}},n===a&&this.renderCharts(t[e][a])))))))))}}var db=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(cb);class mb extends n.PureComponent{render(){const{title:e,data:t,keys:a,dataKey:n,height:r,name:l}=this.props,s=a&&a.length&&function(e,t){return q()({hue:e,count:t})}("#3f51b5",a.length);return i.a.createElement(O.a,{style:{borderRadius:"4px",overflow:"hidden"}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),i.a.createElement(ib.k,{key:l,width:"100%",height:r,style:{cursor:"pointer"}},i.a.createElement(ib.b,{width:"100%",height:r,data:t,key:`${l}-${e}`,margin:{top:20,right:20,left:10,bottom:5}},i.a.createElement(ib.c,{strokeDasharray:"3 3"}),i.a.createElement(ib.o,{dataKey:n,tick:{fontSize:"12px"}}),i.a.createElement(ib.p,null),i.a.createElement(ib.n,null),i.a.createElement(ib.f,{wrapperStyle:{fontSize:"12px"}}),a&&a.length&&a.map((e,t)=>i.a.createElement(ib.a,{stackId:"a",key:`${l}-${t}`,dataKey:e,fill:s[t]})))))}}mb.defaultProps={height:400};const pb={nPerHa:{name:"N",type:"Macro"},pPerHa:{name:"P",type:"Macro"},kPerHa:{name:"K",type:"Macro"},caPerHa:{name:"Ca",type:"Macro"},mgPerHa:{name:"Mg",type:"Macro"},sPerHa:{name:"S",type:"Macro"},znPerHa:{name:"Zn",type:"Micro"},bPerHa:{name:"B",type:"Micro"},fePerHa:{name:"Fe",type:"Micro"},mnPerHA:{name:"Mn",type:"Micro"},cuPerHa:{name:"Cu",type:"Micro"},moPerHa:{name:"Mo",type:"Micro"}};class hb extends n.Component{constructor(e){super(e),this.handleMonitorTypeExpand=e=>{const{expandedMonitorType:t}=this.state;t!==e?this.setState({expandedMonitorType:e}):this.setState({expandedMonitorType:""})},this.handleMonitorTypeExpandInner=e=>{const{expandedMonitorTypeInner:t}=this.state;t!==e?this.setState({expandedMonitorTypeInner:e}):this.setState({expandedMonitorTypeInner:""})},this.distinctPush=(e,t)=>{-1===e.findIndex(e=>e===t)&&e.push(t)},this.renderCharts=(e,t)=>{const{handleMonitoringClick:a}=this.props;console.log(e,t);return e&&e.data?i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(mb,{dataKey:"name",key:"fertChart",title:"Nutrients kg/ha",height:400,name:"Fetilisers",handleClick:a,keys:e.dataKeys,data:e.data.filter(e=>e.type===t)})):null},this.formatData=e=>{const t={data:[],dataKeys:e.distinctFertilisers};if(!e||!e.distinctFertilisers)return null;for(let a=0;ae.product&&e.product===a).reduce((e,t)=>e+parseFloat(t[n]?t[n]:0),0);0!==i&&(r[a]=parseFloat(i.toFixed(3)))}t.data.push(r)}return t},this.formatDataOld=e=>{const t={};if(!e||!e.distinctFertilisers)return null;for(let a=0;ae.product&&e.product===n);t[n]||(t[n]={});for(let e=0;e({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(hb);function ub(){let e;do{e="#"+Math.floor(16777215*Math.random()).toString(16),e=7===e.length?e:"#"+e.slice(1).padStart(6,"0")}while(bb(e));return e}function bb(e){const t=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),n=parseInt(e.slice(5,7),16);return t>240&&a>240&&n>240}const vb=function(e){const t=[];for(;t.lengthi.a.createElement(O.a,{elevation:1,style:{marginTop:"10px",maxHeight:"80vh",minHeight:"400px",overflowY:"auto",backgroundClip:"inherit"}},i.a.createElement(g.a,{container:!0,spacing:1,alignItems:"flex-start"},(()=>{const t=[...new Set(e.flatMap(e=>Object.keys(e).filter(e=>e.startsWith("totalLiters_")).map(e=>e.replace("totalLiters_",""))))];return i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},"Liters/Week")),i.a.createElement(ib.k,{key:"Irrigation 3",width:"100%",height:400,style:{cursor:"pointer"}},i.a.createElement(ib.h,{width:500,height:400,data:e,margin:{top:5,right:30,left:20,bottom:5}},i.a.createElement(ib.c,{strokeDasharray:"3 3"}),i.a.createElement(ib.o,{dataKey:"week"}),i.a.createElement(ib.p,null),i.a.createElement(ib.n,{label:"Week Ending"}),i.a.createElement(ib.f,null),t.map((e,t)=>i.a.createElement(ib.g,{key:e,name:e,type:"monotone",dataKey:"totalLiters_"+e,stroke:vb[t],activeDot:{r:8}})))))})())),fb=a(1771);Object(fb.a)().base(Math.E);function Eb(){let e;do{e="#"+Math.floor(16777215*Math.random()).toString(16),e=7===e.length?e:"#"+e.slice(1).padStart(6,"0")}while(Sb(e));return e}function Sb(e){const t=parseInt(e.slice(1,3),16),a=parseInt(e.slice(3,5),16),n=parseInt(e.slice(5,7),16);return t>240&&a>240&&n>240}const Cb=function(e){const t=[];for(;t.lengthi.a.createElement(O.a,{elevation:1,style:{marginTop:"10px",maxHeight:"80vh",minHeight:"400px",overflowY:"auto",backgroundClip:"inherit"}},i.a.createElement(g.a,{container:!0,spacing:1,alignItems:"flex-start"},(e=>{const t=[...new Set(e.flatMap(e=>Object.keys(e).filter(e=>e.startsWith("totalKgs_")).map(e=>e.replace("totalKgs_",""))))];return i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},"Total Kgs/Week")),i.a.createElement(ib.k,{width:"100%",height:400,style:{cursor:"pointer"}},i.a.createElement(ib.b,{data:e,margin:{top:5,right:30,left:20,bottom:5}},i.a.createElement(ib.c,{strokeDasharray:"3 3"}),i.a.createElement(ib.o,{dataKey:"week"}),i.a.createElement(ib.p,null),i.a.createElement(ib.n,null),i.a.createElement(ib.f,null),t.map((e,t)=>i.a.createElement(ib.a,{key:e,type:"monotone",dataKey:"totalKgs_"+e,fill:Cb[t],name:e})))))})(e)));class kb extends n.Component{constructor(e){super(e),this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.state={monitoringData:[],fertilisingData:[],selectedTab:0,isLoading:!1,selectedStage:"",irrigationData:[],harvestingData:[],chemicals:[]}}componentDidMount(){const{getFromGlobalState:e,blocks:t}=this.props;this.setState({isLoading:!0});const a=e("chemicals"),n=pt(t,e("monitorings"),e("targetsTypesSetting")),i=mt(t,e("fertilisers")),r=dt(t),l=ct(t);this.setState({isLoading:!1,monitoringData:n,fertilisingData:i,irrigationData:r,harvestingData:l,chemicals:a})}componentDidUpdate(e){const{getFromGlobalState:t,activeSite:a,blocks:n}=this.props;if(a!==e.activeSite||n!==e.blocks){const e=pt(n,t("monitorings"),t("targetsTypesSetting")),a=mt(n,t("fertilisers")),i=dt(n),r=ct(n);this.setState({isLoading:!1,infoWindow:null,monitoringData:e,fertilisingData:a,irrigationData:i,harvestingData:r})}}getMonitoringInfo(e,t,a){return i.a.createElement(i.a.Fragment,null,i.a.createElement(B.a,{variant:"h6"},e.name),i.a.createElement(B.a,{variant:"subtitle2"}," Stage: "+t.stageDescription),i.a.createElement(B.a,{style:{color:a.color},variant:"h6"}," Average: "+a.value.toFixed(2)),i.a.createElement(B.a,{variant:"subtitle2"}," Priority: "+t.priority),i.a.createElement(B.a,{variant:"subtitle2"}," Date: "+a.date),a.threshold&&i.a.createElement(B.a,{variant:"subtitle2"}," Threshold Value: "+a.thresholdValue.toFixed(2)),a.threshold&&i.a.createElement(B.a,{variant:"subtitle2"},` Threshold: Low ${a.threshold.low} Med ${a.threshold.med} High ${a.threshold.high}`),i.a.createElement(B.a,{variant:"subtitle2"}," Recommended points: "+t.quantityOfUnit),i.a.createElement(B.a,{variant:"subtitle2"}," Monitored points: "+a.actualObservations))}render(){const{classes:e,handleMonitoringClick:t,handleFertilisingClick:a,handlePPPClick:n,getFromGlobalState:r}=this.props,{monitoringData:l,selectedTab:s,fertilisingData:o,irrigationData:c,harvestingData:d,chemicals:m}=this.state;return i.a.createElement(Mi,{value:s,handleChange:this.handleTabChange},i.a.createElement(db,{heading:"Monitoring",data:l,handleMonitoringClick:t,chemicals:m,getFromGlobalState:r}),i.a.createElement(gb,{heading:"Fertilising",data:o,handleFertilsingClick:a}),i.a.createElement(yb,{heading:"Irrigation",data:c}),i.a.createElement(xb,{heading:"Harvesting",data:d}))}}var wb=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(kb);class Tb extends n.Component{constructor(e){super(e),this.distinctPush=(e,t)=>{-1===e.findIndex(e=>e.sk===t.sk)&&e.push(t)},this.generateMetaDataAndFilter=(e,t,a)=>{const{metaData:n}=this.state,{getFromGlobalState:i}=this.props,r={...t},l=(i("monitorings"),i("targetsTypesSetting"),i("crops")),s={...n,crops:l},o=[];let c=[...e];console.log(a,l),a&&("clusters"===a&&(s.blocks=[],s.plantings=[],r.blocks=[],r.plantings=[]),"blocks"===a&&(s.plantings=[],r.plantings=[]),"userGroups"===a&&(s.monitorTypes=[],r.monitorTypes=[],s.targetTypes=[],r.targetTypes=[],s.stages=[],r.stages=[],s.users=[],r.users=[],r.recordTypes=[],s.recordTypes=[],r.targets=[],s.targets=[]),"recordTypes"===a&&(s.monitorTypes=[],r.monitorTypes=[],s.targetTypes=[],r.targetTypes=[],s.stages=[],r.stages=[]),"targetTypes"===a&&(s.targets=[],r.targets=[]),"targets"===a&&(s.stages=[],r.stages=[])),r.blocks.length&&(c=e.filter(e=>-1!==r.blocks.indexOf(e.sk)));for(let d=0;c&&d"pestings"===e)){const e=this.filterTargetTypes(c,i("monitorings"),i("targetsTypesSetting"));for(let t=0;e&&t{const a=t.map(e=>e.sk).indexOf(e.sk);a>-1&&this.distinctPush(s.clusters,{name:t[a].name,sk:e.sk})})}if("clusters"===a){(t.clusters||[]).map(e=>{((null===c||void 0===c?void 0:c.clusters)||[]).map(e=>e.sk).includes(e)&&(l=!0)})}}l&&(o.push(e),this.distinctPush(s.blocks,{name:e.number,sk:e.sk}))}return s.users=t.userGroups.length>0?s.users.filter(e=>t.userGroups.some(t=>t===e.group)):s.users,console.log("filtered-data",o),{filteredData:o,metaData:s,selectedData:r}},this.filterStages=(e,t,a,n)=>{const i=[];for(let r=0;re===i.stageSK)&&n.observations.push(i):n.observations.push(i)}n.observations.length>0&&i.push(n)}return i},this.fiterTargetFin=(e,t,a,n)=>{const i=[],r=[];for(let l=0;le===i.targetDetailSK)){s.observations.push(i);const e=a.find(e=>i.monitoringSK===e.sk);if("Yes"===e.cropSpecific){const t=e.targetDetail.observableOn[0].stages.find(e=>e.sk===i.stageSK);this.distinctPush(r,{sk:t.sk,name:t.stageDescription})}}}else s.observations.push(i)}s.observations.length>0&&i.push(s)}return{filteredPestings:i,stages:r}},this.filterTargets=(e,t,a,n)=>{const i=[],r=[];for(let l=0;ll.monitoringSK===e.sk);if(c){const e=(n||[]).find(e=>e.sk===c.targetType);t.targetTypes.length?-1!==t.targetTypes.findIndex(t=>t===e.sk)&&(o.observations.push(l),this.distinctPush(r,{sk:c.targetDetail.sk,name:c.targetDetail.name})):(o.observations.push(l),this.distinctPush(r,{sk:c.targetDetail.sk,name:c.targetDetail.name}))}else console.log("LD error: monitoring not found monitoringSK",l.monitoringSK);o.observations.length>0&&i.push(o)}}return{filteredPestings:i,targets:r}},this.filterTargetTypes=(e,t,a)=>{const n=[];for(let i=0;ii.monitoringSK===e.sk);if(l){const e=null===a||void 0===a?void 0:a.find(e=>e.sk===l.targetType);this.distinctPush(n,{sk:e.sk,name:e.name})}else console.log("LD error: monitoring not found monitoringSK",i.monitoringSK)}}return n},this.filterMonitorings=(e,t,a)=>{const n=a.crop,i=[];for(let r=0;re.monitorType===t);if(a.length>0){const t={...e[r]};t.targetDetail.observableOn[0].stages=[...a],i.push(t)}}}else if(e[r].targetDetail.nonCropDetail.monitorType===t){const t={...e[r]};i.push(t)}return i},this.filterUsers=(e,t)=>{let a=!1;const n={},i=se;return Object.keys(i).forEach(i=>{if(t[i]&&t[i].length){const r=t[i].filter(t=>e.users.some(e=>e===t.createdByDetail.email));r.length?(n[i]=r,a=!0):n[i]=[]}else n[i]=[]}),{hasRecords:a,foundRecords:n}},this.filterUserGroups=(e,t,a)=>{let n=!1;const i={},r={},l=[],s=[],o=se,c=a.map(e=>{const t={...e};return t.group||(t.group="Unassisgned"),t}).filter(t=>e.userGroups.some(e=>e===t.group));return Object.keys(o).forEach(e=>{if(t[e]&&t[e].length){const o=t[e].filter(e=>c.some(t=>t.email===e.createdByDetail.email));if(o.length){i[e]=o,n=!0;for(let e=0;ee.email===t.createdByDetail.email),n=(null===e||void 0===e?void 0:e.group)?null===e||void 0===e?void 0:e.group:"Unassisgned";this.distinctPush(l,{sk:n,name:n}),this.distinctPush(s,{sk:null===e||void 0===e?void 0:e.email,name:`${null===e||void 0===e?void 0:e.name} ${e.surname}`,group:n}),r[t.createdBy]=e}}}else i[e]=[]}else i[e]=[]}),{hasRecords:n,foundRecords:i,userGroups:l,usersMeta:s}},this.filterRecordTypes=(e,t)=>{const a={};if(e.recordTypes.length){for(let i=0;i{const n=[],i=[],r=[],l={};let s=!1;const o={},c=se;return Object.keys(c).forEach(c=>{if(t[c]&&t[c].length){const d=t[c].filter(t=>t.date>=e.startDate&&t.date<=e.endDate);if(d.length){this.distinctPush(n,{sk:c,name:se[c]}),o[c]=d,s=!0;for(let e=0;ee.email===t.createdByDetail.email),n=(null===e||void 0===e?void 0:e.group)?null===e||void 0===e?void 0:e.group:"Unassisgned";this.distinctPush(i,{sk:n,name:n}),this.distinctPush(r,{sk:null===e||void 0===e?void 0:e.email,name:`${null===e||void 0===e?void 0:e.name} ${null===e||void 0===e?void 0:e.surname}`,group:n}),l[t.createdBy]=e}}}else o[c]=[]}else o[c]=[]}),{hasRecords:s,foundRecordTypes:n,foundRecords:o,userGroups:i,usersMeta:r}},this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.handleChange=e=>{const{selectedData:t}=this.state,{getFromGlobalState:a}=this.props,n={...t};if(n[e.target.id]!==e.target.value){n[e.target.id]=e.target.value;const t=a("blocks"),i=this.generateMetaDataAndFilter(t,n,"dateRange");this.setState({filteredData:i.filteredData,metaData:i.metaData,selectedData:i.selectedData})}},this.handleExpand=e=>{const{expandedFilter:t}=this.state;t!==e?this.setState({expandedFilter:e}):this.setState({expandedFilter:""})},this.handleSaveFilter=e=>{this.setState({filterSaveDialogOpen:!0})},this.closeFilterSaveDialog=()=>{this.setState({filterSaveDialogOpen:!1})},this.handleFilterChange=e=>{const{activeFilter:t,selectedData:a}=this.state;let n={...a};const{getFromGlobalState:i}=this.props;if(e.target.value!==t){const t=i("filters").find(t=>t.sk===e.target.value);t&&(n={...t});const a=i("blocks"),r=this.generateMetaDataAndFilter(a,n,"");this.setState({filteredData:r.filteredData,metaData:r.metaData,selectedData:r.selectedData,activeFilter:e.target.value})}},this.handleFilterUpdate=e=>{const{getFromGlobalState:t,setGlobalState:a}=this.props,n=[...t("filters")],i=n.findIndex(t=>t.sk===e.sk);-1===i?n.push(e):n[i]=e,a({filters:n})},this.handleMonitoringClick=(e,t)=>{this.setState({selectedMonitoring:e})},this.handleFertilisingClick=(e,t)=>{},this.handleFilterToggle=(e,t)=>{const{selectedData:a}=this.state,{getFromGlobalState:n}=this.props,i={...a},r=i[t].indexOf(e);-1===r?i[t].push(e):i[t].splice(r,1);const l=n("blocks"),s=this.generateMetaDataAndFilter(l,i,t);this.setState({filteredData:s.filteredData,metaData:s.metaData,selectedData:s.selectedData})},this.state={selectedTab:0,expandedFilter:"",filterSaveDialogOpen:!1,selectedMonitoring:null,activeFilter:"",filteredMetaData:{},selectedData:{startDate:null,endDate:null,crops:[],clusters:[],blocks:[],plantings:[],recordTypes:[],monitorTypes:[],targetTypes:[],targets:[],stages:[],userGroups:[],users:[],cultivars:[]},flatItems:[],metaData:{clusters:[],blocks:[],crops:[],plantings:[],monitorTypes:[],recordTypes:[],targetTypes:[],stages:[],targets:[],userGroups:[],users:[]},filteredData:[]}}componentDidMount(){const{selectedData:e}=this.state,{getFromGlobalState:t}=this.props;let a={...e};const n=t("filters");if(n.length){const e=n.find(e=>!0===e.default);e&&(a={...e})}const i=new Date;a.endDate=i.toISOString().substr(0,10);const r=new Date;r.setDate(r.getDate()-7),a.startDate=r.toISOString().substr(0,10);const l=t("blocks"),s=this.generateMetaDataAndFilter(l,a);this.setState({filteredData:s.filteredData,metaData:s.metaData,selectedData:a,activeFilter:a.sk?a.sk:""})}render(){const{classes:e,getFromGlobalState:t}=this.props,{selectedTab:a,expandedFilter:n,selectedData:r,metaData:l,filteredData:s,filterSaveDialogOpen:o,activeFilter:c,selectedMonitoring:d}=this.state,m=t("activeSite");return i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:2,lg:2,xl:2},i.a.createElement(Zu,{metaData:l,expandedFilter:n,handleExpand:this.handleExpand,selectedData:r,handleChange:this.handleChange,handleToggle:this.handleFilterToggle,handleSaveFilter:this.handleSaveFilter,handleFilterChange:this.handleFilterChange,filters:t("filters"),activeFilter:c})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:10,lg:10,xl:10},i.a.createElement(Mi,{value:a,handleChange:this.handleTabChange},i.a.createElement(nb,{heading:"Map",activeSite:m,getFromGlobalState:t,blocks:s}),i.a.createElement(wb,{heading:"Data",activeSite:m,getFromGlobalState:t,blocks:s,handleMonitoringClick:this.handleMonitoringClick,handleFertilisingClick:this.handleFertilisingClick})),d&&i.a.createElement(tb,{data:d})),o&&i.a.createElement(Xu,{filter:r,open:o,setClose:this.closeFilterSaveDialog,isNew:""===c,handleUpdate:this.handleFilterUpdate,getFromGlobalState:t}))}}var Db=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(Tb);const Pb=[{name:"product",min:1,max:100},{name:"inout",min:1,max:10},{name:"amount",min:1,max:1e6,type:"number"},{name:"reason",min:1,max:100},{name:"date",min:1,max:100}];class Fb extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Pb),this.handleChange=e=>{const t={...this.state.inventoryItem};t[e.target.id]=e.target.value,this.setState({inventoryItem:t,changed:!0})},this.handleRadioChange=(e,t)=>{const a={...this.state.inventoryItem};a[e]=t.target.value,this.setState({inventoryItem:a,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,inventoryItem:this.props.inventoryItem||{},errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew){const e=new Date;this.setState({inventoryItem:{entryType:"adjustment",date:e.toISOString().substr(0,10)}})}else{const{inventoryItem:e}=this.props;this.setState({inventoryItem:e})}}validateField(e,t){const a=jn(e,this.state.inventoryItem,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,newTitle:r,handleUpdate:l,metaData:s,product:o,dynamoType:c,activityName:d,handleDelete:m,allowDelete:p,getFromGlobalState:h}=this.props,{inventoryItem:u={},errors:b}=this.state,v=$n(u,Pb);u.product=null===o||void 0===o?void 0:o.sk,u.price&&u.amount&&(u.pricePerUnit=u.price/u.amount);let y=null,f=null,E=null,S=null;return u.entryType&&"application"===u.entryType&&(u.inout=u.inout?u.inout:"out",u.block&&(y=s.blocks.find(e=>e.sk===u.block),y&&(u.reason=u.reason?u.reason:"Application: "+y.number,u.planting&&(f=y.plantings.find(e=>e.sk===u.planting),f[d]&&(E=f[d].filter(e=>e.product===o.sk&&(!a||!1===e.completed)),u.activity&&(S=E.find(e=>e.sk===u.activity),u.amount=a?S.calculatedProduct:u.amount)))))),i.a.createElement(Ia,{open:t,dialogObject:u,setClose:n,isNew:a,handleUpdateDialogObject:l.bind(this),handleDeleteDialogObject:m.bind(this),allowDelete:p,disableDelete:S&&S.completed,skPrimary:"init_inventory_",dynamoType:c,valid:v,changed:this.state.changed,newTitle:r||"New Entry",title:r||"New Entry",getFromGlobalState:h},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},u.entryType&&"adjustment"===u.entryType&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{component:"label",required:!0},"Inventory In / Out"),i.a.createElement(xn.a,{"aria-label":"Direction",name:"inout",id:"inout",className:e.group,value:u.inout,onChange:this.handleRadioChange.bind(this,"inout")},i.a.createElement(Fe.a,{value:"in",control:i.a.createElement(Cn.a,null),label:"in"}),i.a.createElement(Fe.a,{value:"out",control:i.a.createElement(Cn.a,null),label:"out"}),b.inout&&i.a.createElement(En.a,{className:e.helperText},b.inout)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"amount",label:"Amount in "+(o&&(null===o||void 0===o?void 0:o.unit)),name:"amount",value:u.amount,onChange:this.handleChange,onBlur:this.handleBlur,error:!!b.amount||void 0,helperText:b.amount})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"reason"},"Reason"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:u.reason,onChange:this.handleChange.bind(this),onBlur:this.handleBlur.bind(this),error:!!b.reason||void 0,inputProps:{name:"reason",id:"reason"}},i.a.createElement("option",{value:""}),u.inout&&"in"===u.inout&&i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:"New Stock"},"New Stock"),i.a.createElement("option",{value:"Stock Return"},"Stock Return")),u.inout&&"out"===u.inout&&i.a.createElement(i.a.Fragment,null," ",i.a.createElement("option",{value:"Chemical Application"},"Application"),i.a.createElement("option",{value:"Stock Return to supplier"},"Stock Return to supplier"),i.a.createElement("option",{value:"Stock Exired"},"Stock Expired")),i.a.createElement("option",{value:"Stock Adjustment"},"Stock Adjustment")),b.reason&&i.a.createElement(En.a,{className:e.helperText},b.reason)))),!a&&u.entryType&&"application"===u.entryType&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,null,`Block ${ae(u.block,s.blocks,"number")}, ${ae(f.crop,s.crops)}, ${S.date}, ${o.name}`),i.a.createElement(B.a,null,"Application: "+(S.completed?"Completed":"Busy"))),u.activity&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"amount",label:"Amount in "+(o&&(null===o||void 0===o?void 0:o.unit)),name:"amount",disabled:S&&S.completed,value:u.amount,onChange:this.handleChange,onBlur:this.handleBlur,error:!!b.amount||void 0,helperText:b.amount}))),u.inout&&u.amount&&"in"===u.inout&&"New Stock"===u.reason&&i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"price",label:"Total price",name:"price",disabled:S&&S.completed,value:u.price,onChange:this.handleChange,onBlur:this.handleBlur,error:!!b.amount||void 0,helperText:b.amount})),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,id:"pricePerUnit",inputProps:{readOnly:!0},InputLabelProps:{shrink:!0},label:"Price per "+(o&&(null===o||void 0===o?void 0:o.unit)),name:"pricePerUnit",value:u.pricePerUnit&&u.pricePerUnit.toLocaleString("en-ZA",{style:"currency",currency:"ZAR"})}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"comment",label:"Comment",name:"comment",value:u.comment,disabled:S&&S.completed,onChange:this.handleChange,onBlur:this.handleBlur,error:!!b.comment||void 0,helperText:b.comment})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",disabled:S&&S.completed,InputLabelProps:{shrink:!0},value:u.date,onChange:this.handleChange.bind(this),onBlur:this.handleBlur,error:!!b.date||void 0,helperText:b.date}))))}}var Nb=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:"120px",marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)}}))(Fb);const Bb=[{name:"product",min:1,max:100},{name:"inout",min:1,max:10},{name:"amount",min:0,max:1e9,type:"number"},{name:"unit",min:1,max:20},{name:"reason",min:1,max:100},{name:"date",min:1,max:100}];class Lb extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,Bb),this.handleChange=e=>{const t={...this.state.inventoryRequest};t[e.target.id]=e.target.value,this.setState({inventoryRequest:t,changed:!0})},this.handleRadioChange=(e,t)=>{let a={...this.state.inventoryRequest};a[e]=t.target.value,this.setState({inventoryRequest:a,changed:!0})},this.handleToggle=e=>t=>{let a={...this.state.inventoryRequest};a[e]=t.target.checked,this.setState({inventoryRequest:a,changed:!0})},this.setAmountMax=()=>{const{inventoryRequest:e}=this.state;if(e.totalAmount&&e.applicationTotal){Bb.find(e=>"amount"===e.name).max=e.totalAmount-e.applicationTotal}},this.state={isloading:!1,isNew:this.props.isNew,inventoryRequest:this.props.inventoryRequest,errors:{count:0},changed:!1}}componentDidMount(){if(this.props.isNew)this.setState({inventoryRequest:this.props.inventoryRequest});else{let e=this.props.inventoryRequest;this.setState({inventoryRequest:e})}this.setAmountMax()}validateField(e){const{inventoryRequest:t,errors:a}=this.state,n=jn(e,t,Bb),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{open:e,isNew:t,setClose:a,handleUpdate:n,dynamoType:r,getFromGlobalState:l}=this.props,{inventoryRequest:s,changed:o,errors:c}=this.state,d=$n(s,Bb);return i.a.createElement(Ia,{open:e,dialogObject:s,setClose:a,isNew:t,handleUpdateDialogObject:n.bind(this),skPrimary:"_inventory_",dynamoType:r,valid:d,changed:o,newTitle:"New Entry",title:"Inventory Request",parentKey:s.activity,getFromGlobalState:l},i.a.createElement(zt.a,{margin:"normal",readOnly:!0,fullWidth:!0,type:"number",inputProps:{step:"0.001"},id:"amount",label:"Total Amount for application in "+(null===s||void 0===s?void 0:s.unit),name:"amount",disabled:!0,value:s.totalAmount,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.totalAmount||void 0,helperText:c.totalAmount}),i.a.createElement(zt.a,{margin:"normal",readOnly:!0,fullWidth:!0,type:"number",id:"applicationTotal",label:"Already taken from inventory",name:"amount",disabled:!0,value:s.applicationTotal,error:!!c.applicationTotal||void 0,helperText:c.applicationTotal}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"reason",readOnly:!0,label:"Application",name:"reason",value:s.reason,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.reason||void 0,helperText:c.reason}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"comment",label:"Comment",name:"comment",value:s.comment,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.comment||void 0,helperText:c.comment}),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"amount",label:"Amount to take from inventory",name:"amount",type:"number",inputProps:{min:"0.00001",step:"any"},value:s.amount,onChange:this.handleChange,onBlur:this.handleBlur,error:!!c.amount||void 0,helperText:c.amount}),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:s.date,onChange:this.handleChange.bind(this),onBlur:this.handleBlur,error:!!c.date||void 0,helperText:c.date}))}}var Ab=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)}}))(Lb);const Ob=Ua.f.create({body:{paddingTop:35,paddingBottom:55,paddingHorizontal:35},sectionRight:{marginBottom:10,paddingBottom:10,textAlign:"right",width:"60%"},sectionLeft:{marginBottom:10,paddingBottom:10,width:"40%"},section:{display:"flex",flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"},sectionNoPadLeft:{margin:10,padding:10,marginLeft:0,paddingLeft:0},textHeader:{fontSize:24,paddingBottom:10},textSubHeader:{fontSize:14},textOpac:{fontSize:10,opacity:.6},text:{fontSize:10},table:{display:"table",width:"auto",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderRightWidth:0,borderBottomWidth:0},tableRow:{margin:"auto",flexDirection:"row"},tableCol1Header:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableColHeader:{borderStyle:"solid",borderColor:"#bfbfbf",borderBottomColor:"#000",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol1:{width:"40%",borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCol:{borderStyle:"solid",borderColor:"#bfbfbf",borderWidth:1,borderLeftWidth:0,borderTopWidth:0},tableCellHeader:{margin:3,fontSize:10,fontWeight:500},tableCell:{margin:3,fontSize:8},tableCellStrong:{margin:3,fontSize:8,fontWeight:"bold"},pageNumber:{position:"absolute",fontSize:12,bottom:30,left:0,right:0,textAlign:"right",color:"grey",paddingRight:20,marginRight:20},logoText:{position:"absolute",fontSize:10,bottom:30,left:20,textAlign:"left",textDecoration:"none"},logo:{width:30,height:30,paddingLeft:2},farmLogo:{maxWidth:"150px"}}),Ib=e=>i.a.createElement(Ua.h,{style:Ob.table},i.a.createElement(Ua.h,{fixed:!0,style:Ob.tableRow},e.headCells&&e.headCells.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Ob.tableColHeader,{width:100/e.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:Ob.tableCellHeader},t.label))))),e.rows&&e.rows.map(t=>i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:Ob.tableRow},e.headCells&&e.headCells.map(a=>{var n;return i.a.createElement(i.a.Fragment,null,i.a.createElement(Ua.h,{style:[Ob.tableCol,{width:100/e.headCells.length+" %"}]},i.a.createElement(Ua.g,{style:t.strong?Ob.tableCellStrong:Ob.tableCell},$(a,t[a.id],null===(n=e.data)||void 0===n?void 0:n.locale))))})))));const Gb=e=>i.a.createElement(Ua.h,{wrap:!1,style:Ob.section},e.logoURL&&i.a.createElement(Ua.h,{style:Ob.sectionLeft},i.a.createElement(Ua.b,{cache:!0,style:Ob.farmLogo,src:e.logoURL})),!e.logoURL&&i.a.createElement(Ua.h,{style:Ob.sectionLeft}),i.a.createElement(Ua.h,{style:Ob.sectionRight},i.a.createElement(Ua.g,{style:Ob.textHeader},e.farm.name),e.farm.gapnum&&i.a.createElement(Ua.g,{style:Ob.textOpac},"GLOBAL.G.A.P: "+e.farm.gapnum),e.farm.puc&&i.a.createElement(Ua.g,{style:Ob.textOpac},"Production Unit Code (PUC): "+e.farm.puc),e.farm.vatNo&&i.a.createElement(Ua.g,{style:Ob.textOpac},"VAT Number: "+e.farm.vatNo),i.a.createElement(Ua.g,{style:Ob.textOpac},"Tel: "+e.farm.contactNum),i.a.createElement(Ua.g,{style:Ob.textOpac},"email: "+e.farm.email),e.farm.geoLocation&&i.a.createElement(Ua.g,{style:Ob.textOpac},"Geolocation: "+(e.farm.geoLocation.lat&&e.farm.geoLocation.lng?`Lat: ${e.farm.geoLocation.lat.toFixed(7)} Lng: ${e.farm.geoLocation.lng.toFixed(7)}`:e.farm.geoLocation)),i.a.createElement(Ua.g,{style:Ob.textOpac},"Address: "+e.farm.address1),i.a.createElement(Ua.g,{style:Ob.textOpac},""+e.farm.address2),i.a.createElement(Ua.g,{style:Ob.textOpac},""+e.farm.country),i.a.createElement(Ua.g,{style:Ob.textOpac},""+e.farm.province),i.a.createElement(Ua.g,{style:Ob.textOpac},""+e.farm.pCode))),Rb=e=>i.a.createElement(Ua.a,null,i.a.createElement(Ua.e,{size:"A4",style:Ob.body,orientation:"landscape"},i.a.createElement(Gb,e),i.a.createElement(Ua.h,{style:[Ob.sectionNoPadLeft,{paddingBottom:0,paddingTop:0,marginTop:0,marginBottom:0}]},i.a.createElement(Ua.g,{style:Ob.textSubHeader},"Product: "+e.product.name),i.a.createElement(Ua.g,{style:Ob.textOpac},"Report Date: "+_()),e.startDate&&e.endDate&&i.a.createElement(Ua.g,{style:Ob.textOpac},`Report range: From: ${e.startDate} To: ${e.endDate}`)),i.a.createElement(Ua.h,{style:Ob.sectionNoPadLeft},i.a.createElement(Ua.g,{style:Ob.textSubHeader},"inv_chemical"===e.inventoryName?"Chemical Inventory Records":"Fertiliser Inventory Records")),i.a.createElement(Ib,e),i.a.createElement(Ua.g,{style:Ob.pageNumber,render:({pageNumber:e,totalPages:t})=>`Page: ${e} / ${t}`,fixed:!0}),i.a.createElement(Ua.h,{wrap:!1,style:Ob.logoText},i.a.createElement(Ua.c,{style:{textDecoration:"none"},wrap:!1,src:"landdiary.com"},i.a.createElement(Ua.g,{wrap:!1,style:{borderRadius:3,paddingLeft:"3px",paddingBottom:"2px"}},i.a.createElement(Ua.b,{style:Ob.logo,src:Ka.a})," ")))));class Ub extends n.Component{constructor(e){super(e),this.getLogoUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t};return await Fa(a)},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0}}}async componentDidMount(){if(this.props.farm&&this.props.farm.logoKey){let e=await this.getLogoUrl(this.props.farm.logoKey,this.props.farm.logoFileType);this.setState({logoURL:e})}}render(){const{farm:e,rows:t,headCells:a,product:n,inventoryName:r,onDownloaded:l,startDate:s,endDate:o}=this.props,{logoURL:c}=this.state;return e.logoKey&&!c?i.a.createElement("div",{style:{color:"inherit",float:"right",marginLeft:"auto"}},i.a.createElement(la,{key:"pdf",onClick:l,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:!0,disabled:!0})):i.a.createElement(Ua.d,{document:i.a.createElement(Rb,{inventoryName:r,rows:t,farm:e,headCells:a,product:n,startDate:s,endDate:o,logoURL:c}),fileName:`${e.name} ${n.name} ${_()}`,style:{color:"inherit",float:"right",marginLeft:"auto"}},({blob:e,url:t,loading:a,error:n})=>i.a.createElement(la,{key:"pdf",onClick:l,success:!0,icon:i.a.createElement(Wa.a,null),color:"inherit",loading:a,disabled:a}))}}var Mb=Object(v.a)(Ob)(Ub);class Wb extends n.Component{constructor(e){super(e),this.state={csvData:[],loading:!1,title:""}}componentDidMount(){const{recordType:e,getFromGlobalState:t,planting:a,startDate:n,endDate:i,block:r,data:l}=this.props;this.setState({loading:!0}),l.headCells&&(l.headCells=l.headCells.filter(e=>"icon"!==e.type));const s=[];s.push(l.headCells.map(e=>e.label));for(let o=0;o{this.setState({inventoryItemDialogOpen:!0})},this.generatePDF=(e,t)=>{this.setState({pdf:!0,startDate:e,endDate:t})},this.generateCSV=(e,t)=>{this.setState({csv:!0,startDate:e,endDate:t})},this.onDownloaded=()=>{this.setState({pdf:!1,csv:!0})},this.getSelectedItem=e=>{const{selectedInventoryItem:t}=this.state,a={},n=new Date,i=t;a.block=i.blockSK,a.planting=i.plantingSK,a.product=i.product,a.inout="out",a.totalAmount=i.amount,a.unit=null===i||void 0===i?void 0:i.unit,a.entryType="application",a.reason=`Block:${i.blockNumber} ${i.cropName} ${i.varietyName}`,a.activity=i.activitySK,a.recordType=i.recordType,a.date=n.toISOString().substr(0,10);let r=0;const l=function(e,t,a,n,i,r){const l=function(e,t,a,n,i){const r=i("blocks"),l=r.findIndex(t=>t.sk===e);if(-1===l)return{status:!1,error:"Block not found",record:void 0};const{plantings:s}=r[l],o=r[l].plantings.findIndex(e=>e.sk===t);if(-1===o)return{status:!1,error:"Planting not found",record:void 0};const c=s[o][a]?s[o][a].findIndex(e=>e.sk===n):-1;return-1===c?{status:!1,error:"Record not found",record:void 0}:{status:!0,record:s[o][a][c],error:""}}(e,t,a,i,r);if(!l.status)return l;let s=0;const o=r(n),c=o&&o.filter(e=>e.sk.startsWith(i));return s=c&&c.reduce((e,t)=>e+parseFloat(t.amount),0),{status:!0,value:s,error:""}}(i.blockSK,i.plantingSK,i.recordType,e,i.activitySK,this.props.getFromGlobalState);return l&&(r=l.value),a.applicationTotal=r,a},this.sortProductByType=(e,t,a)=>{const n=e&&e.filter(e=>e.product===t);return console.log(a,"products --- >",n),n.map(e=>({...e,inout:"out",amount:"sprayings"===a?e.volume:parseFloat(e.total),comment:"Application on "+e.cropName,reason:"Application"}))},this.calculateChemicalDosage=(e,t)=>Array.isArray(e)&&0!==e.length?e.map(e=>{let a=0;if(!e.reasons||!Array.isArray(e.reasons)||!e.reasons.length)return{productSK:e.sk,amount:0,unit:e.unit||"",inout:e.inout||"in"};const n=t("blocks").map(e=>e.plantings).flat().filter(e=>e).find(t=>t.sk===e.plantingSK);let i=0,r=0;n&&(i=Qe(n.plantSpacing,n.plantDensity,n.size),r=parseFloat(n.size)||0),e.reasons.forEach(t=>{if(!t.dosage||!t.dosageUnit)return;const n=parseFloat(t.dosage)||0,l=t.dosageUnit,s=parseFloat(e.volume)||0;switch(l){case"ml/plant":case"g/plant":a+=n*i/1e3;break;case"ml/ha":a+=n*r/1e3;break;case"L/ha":a+=n*r;break;case"g/ha":a+=n*r/1e3;break;case"kg/ha":case"/ha":a+=n*r;break;case"/m2":a+=n*(1e4*r);break;case"g/L":a+=n*s/1e3;break;case"g/100L":case"ml/100L":a+=n*s/100/1e3;break;case"L/100L":a+=n*s/100}});const l="out"===e.inout?-1*a:a;return{...e,actionType:"Entry",productSK:e.sk,productName:e.productName||e.tradeName,amount:l.toFixed(2),unit:e.unit||"",inout:e.inout||"in"}}):[],this.getProductItems=(e,t,a)=>{var n,i;const{inventoryItems:r,inventoryRequests:l}=this.state;let s=this.getInventoryForProduct(e,r);const o=tt(this.props.activityName,this.props.metaData.blocks,this.props.getFromGlobalState,!0,!0,100,void 0,void 0,!0,!0),c=this.sortProductByType(o.rows,e.sk,this.props.activityName),d=parseFloat(e.minStock);console.log("sortedProducts",c);const m=null===(n=this.props.getFromGlobalState("blocks").map(e=>e.plantings))||void 0===n||null===(i=n.find(t=>t.sk===(null===e||void 0===e?void 0:e.plantingSK)))||void 0===i?void 0:i[0],p=Qe(m.plantSpacing,m.plantDensity,m.size);console.log(m.plantSpacing,m.plantDensity,m.size,"totalPlants",p);c.map(e=>{const t={...e};return"g"===e.qtyUnit&&(t.amount=t.amount/1e3),t});let h=this.calculateChemicalDosage(c,this.props.getFromGlobalState).concat(s);const g=(u=0,e=>u+=parseFloat(e.amount));var u;const b=h.map(g);h=h.map((e,t)=>{const a={...e};return a.balance=b[t],a});const v=h.reduce((e,t)=>e+parseFloat(t.amount),0),y=v>1.1?"green":1.1===v?"amber":"red";h=h&&h.sort((e,t)=>new Date(t.date)-new Date(e.date));const f=h.length,E=h.slice(0,Kb),{unit:S}=e;let C=[],x=[];return x=[{id:"date",combine:[{id:"date",opacity:1},{id:"reason",opacity:.6}],numeric:!1,disablePadding:!1,label:"Date"},{id:"amount",combine:[{id:"amount",opacity:1}],numeric:!0,disablePadding:!1,label:`(${S})`}],C=[{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"blockNumber",numeric:!1,disablePadding:!1,label:"Block",minWidth:"80px"},{id:"plantingName",numeric:!1,disablePadding:!1,label:"Planting",minWidth:"80px"},{id:"reason",numeric:!1,disablePadding:!1,label:"Reason",minWidth:"70px"},{id:"comment",numeric:!1,disablePadding:!1,label:"Comment",minWidth:"70px"},{id:"amount",numeric:!0,disablePadding:!1,label:`Total (${S})`},{id:"balance",numeric:!0,disablePadding:!1,label:`Balance (${S})`}],{count:f,mostRecent:E,rows:h,headCells:C,headCellsClean:x,total:v,unit:S,minStock:d,status:{status:y,message:""}}},this.state={expandedProduct:null,selectedProduct:null,inventoryItems:null,inventoryRequests:[],selectedInventoryItem:null,selectedChemicalCrop:null,expandedContent:null,modalObject:null,isNew:!1,inventoryItemDialogOpen:!1,chemicalCropDialogOpen:!1,inventoryRequestDialogOpen:!1,errors:{},openModal:"",showAllDialogOpen:!1,showReportDialogOpen:!1,clean:!0,pdf:!1,startDate:void 0,endDate:void 0,csv:!1,applications:[]}}componentDidMount(){const{initialState:e}=this.props;this.setState({inventoryItems:e})}handleClickAdd(e){this.setState({selectedAction:"Entry",inventoryItemDialogOpen:!0,selectedProduct:e,isNew:!0,selectedInventoryItem:{}})}handleClickShowInventoryItem(e,t,a,n){if("Entry"===n){const e=this.props.getFromGlobalState(this.props.inventoryName).find(e=>e.sk===a);this.setState({selectedAction:n,selectedProduct:t,selectedInventoryItem:e,selectedinventoryItemSK:a,inventoryItemDialogOpen:"true",isNew:!1})}else if("Request"===n){const e=this.state.inventoryRequests.find(e=>e.activitySK===a);this.setState({selectedAction:n,selectedInventory:e.inventoryName,selectedProduct:t,selectedInventoryItem:e,selectedInventoryRequestSK:a,inventoryRequestDialogOpen:"true",isNew:!0})}}setClose(){"Request"===this.state.selectedAction?this.setState({inventoryRequestDialogOpen:!1}):this.setState({inventoryItemDialogOpen:!1})}setCloseShowAll(){this.setState({showAllDialogOpen:!1})}setCloseReport(){this.setState({showReportDialogOpen:!1,clean:!0})}handleUpdate(e){const{getFromGlobalState:t,inventoryName:a,setGlobalState:n}=this.props,i=t(a).findIndex(t=>t.sk===e.sk);if(-1===i){const i=t(a);i.push(e),n({[a]:i})}else{const r=t(a);r[i]=e,n({[a]:r})}}handleDelete(e){const{getFromGlobalState:t,inventoryName:a,setGlobalState:n}=this.props,i=t(a).findIndex(t=>t.sk===e.sk);if(-1===i)alert("impossible deleting an item we dont have");else{const e=t(a);e.splice(i,1),n({[a]:e})}this.setState({pdf:!1})}handleExpand(e){const{expandedProduct:t}=this.state;t&&e.sk===t.sk?this.setState({expandedProduct:null,pdf:!1}):this.setState({expandedProduct:e,pdf:!1})}async handlePreExecute(e){const{getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props,{block:i,planting:r,activity:l,recordType:s,type:o,sk:c}=e;let d={};const m=t("blocks"),p=m.findIndex(e=>e.sk===i);if(-1===p)return alert("impossible - we don't have this block!"),!1;const{plantings:h}=m[p],g=m[p].plantings.findIndex(e=>e.sk===r),u=h[g][s]?h[g][s].findIndex(e=>e.sk===l):-1;if(-1===u)return alert(" impossible we don't have this activity"),!1;d={...m[p].plantings[g][s][u]},d[o]||(d[o]=[]),d[o].push(c);try{const e=d.version?d.version:0;d.version=e+1;let n={};return d.activeTenant=this.props.getFromGlobalState("activeSite"),n=await ya(this.props.getFromGlobalState("currentUser").username,"calls",ua(d),t("activeSite")),n.status&&(d.cached=n.cached),m[p].plantings[g][s][u]=d,a({blocks:m}),!0}catch(b){return n({open:!0,variant:"error",message:b.response?`${b.response.data.error.message?b.response.data.error.message:b.response.data.error}, api src: ${b.response.data.src} `:b.message}),!1}}handleClickShowAll(){this.setState({showAllDialogOpen:!0})}handleClickShowReport(){this.setState({showReportDialogOpen:!0,clean:!1})}getInventoryForProduct(e,t){if(!t)return[];if(!e)return[];return t.filter(t=>t.product===e.sk)}render(){const{classes:e,inventoryName:t,metaData:a,activityName:n,getFromGlobalState:r}=this.props,{inventoryItemDialogOpen:l,isNew:s,selectedInventoryItem:o,selectedProduct:c,inventoryRequestDialogOpen:d,selectedInventory:m,showAllDialogOpen:p,expandedProduct:h,pdf:u,csv:b,clean:v,selectedinventoryItemSK:y,showReportDialogOpen:E,startDate:S,endDate:C}=this.state,x=r("farm")[0],k=r("userDetail");function w(e,t){return e.slice().sort((e,a)=>new Date(e[t])-new Date(a[t]))}return i.a.createElement(O.a,{elevation:0,className:e.mainSection},"inv_chemical"===t&&l&&i.a.createElement(Nb,{handleUpdate:this.handleUpdate.bind(this),handleDelete:this.handleDelete.bind(this),allowDelete:!0,open:l,setClose:this.setClose.bind(this),isNew:s,inventoryItem:o,product:c,dynamoType:"inv_chemical",newTitle:c.name,activityName:"sprayings",getFromGlobalState:this.props.getFromGlobalState,metaData:{blocks:r("blocks"),crops:r("crops")}}),"inv_fertiliser"===t&&l&&i.a.createElement(Nb,{handleUpdate:this.handleUpdate.bind(this),handleDelete:this.handleDelete.bind(this),allowDelete:!0,open:l,setClose:this.setClose.bind(this),isNew:s,newTitle:c.name,inventoryItem:o,product:c,dynamoType:"inv_fertiliser",activityName:"fertilisings",getFromGlobalState:this.props.getFromGlobalState,metaData:{blocks:r("blocks"),crops:r("crops")}}),d&&i.a.createElement(Ab,{handleUpdate:this.handleUpdate.bind(this),open:d,setClose:this.setClose.bind(this),isNew:s,product:c,dynamoType:m,getFromGlobalState:this.props.getFromGlobalState,inventoryRequest:this.getSelectedItem(m)}),i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},a&&a.products&&a.products.map((a,n)=>{const l=this.getProductItems(a),s=w(l.mostRecent,"date");return console.log("productItems.rows",l.rows),i.a.createElement(i.a.Fragment,null,p&&a.sk===h.sk&&i.a.createElement(Ra,{open:p&&a.sk===h.sk,setClose:this.setCloseShowAll.bind(this),isNew:!1,getFromGlobalState:r,title:""+a.name},i.a.createElement(Me,{displayToolbar:!0,id:"reportTable",noPagination:!0,rows:l.rows,headCells:v?l.headCellsClean:l.headCells,handleSelect:this.handleClickShowInventoryItem.bind(this),handleAddItem:k&&k.rights&&!k.rights.readOnly?this.handleClickAdd.bind(this,a):null,parent:a,actionType:"actionType",rowKeyName:"sk",orderByProperty:"date",orderType:"asc",clean:!0,selectedRow:y})),E&&a.sk===h.sk&&i.a.createElement(Ra,{open:E&&a.sk===h.sk,setClose:this.setCloseReport.bind(this),isNew:!1,title:a.name+" report",getFromGlobalState:r,onGeneratePDF:this.generatePDF.bind(this),onGenerateCSV:this.generateCSV.bind(this),pdfRequested:u,csvRequested:b,reportCSV:i.a.createElement(zb,{onDownloaded:this.onDownloaded,data:{headCells:l.headCells,title:a.name,rows:S&&C?w(l.rows,"date").filter(e=>e.date>=S&&e.date<=C):w(l.rows,"date")},color:"secondary",className:e.pdfButton,startDate:S,endDate:C,farm:x}),reportPDF:i.a.createElement(Mb,{onDownloaded:this.onDownloaded,inventoryName:t,product:a,color:"secondary",className:e.pdfButton,farm:x,headCells:l.headCells,startDate:S,endDate:C,rows:S&&C?w(l.rows,"date").filter(e=>e.date>=S&&e.date<=C):w(l.rows,"date"),getFromGlobalState:r})},i.a.createElement(Me,{displayToolbar:!0,heading:"",orderByProperty:"date",orderType:"asc",rows:l.rows,headCells:v?l.headCellsClean:l.headCells,parent:a,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0})),i.a.createElement(g.a,{key:a.sk,style:{padding:"3px"},item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(D,{title:a.name.toUpperCase(),expanded:!(!this.state.expandedProduct||this.state.expandedProduct.sk!==a.sk)||void 0,ariaLabel:"Product",handleExpandClick:this.handleExpand.bind(this,a),avatar:i.a.createElement(ge,{status:l.status,hideIfGreen:!1,size:"medium"}),elevation:1,expandedContent:i.a.createElement(i.a.Fragment,null,i.a.createElement(Me,{displayToolbar:!0,heading:"Most Recent",noPagination:!0,hideHeader:!0,rows:s,headCells:this.state.clean?l.headCellsClean:l.headCells,handleSelect:this.handleClickShowInventoryItem.bind(this),handleAddItem:k&&k.rights&&!k.rights.readOnly?this.handleClickAdd.bind(this,a):null,dense:!0,parent:a,actionType:"actionType",rowKeyName:"sk",orderByProperty:"date",orderType:"asc",clean:!0,selectedRow:this.state.selectedinventoryItemSK}),i.a.createElement(f.a,null,i.a.createElement(Ct.a,{size:"small",onClick:this.handleClickShowReport.bind(this),color:"secondary",className:e.buttonLeft},"Report"),i.a.createElement(Ct.a,{size:"small",onClick:this.handleClickShowAll.bind(this),color:"secondary",className:e.buttonRight},"Show All")))},i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-end"},i.a.createElement(g.a,{item:!0,xs:5,sm:5,md:5,lg:5,xl:5},i.a.createElement(B.a,null,"Stock Level:")),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(B.a,{variant:"subtitle2",className:e["text"+l.status.status]},`${l.total.toLocaleString()} ${null===l||void 0===l?void 0:l.unit}`," ")),i.a.createElement(g.a,{item:!0,xs:1,sm:1,md:1,lg:1,xl:1}),i.a.createElement(g.a,{item:!0,xs:1,sm:1,md:1,lg:1,xl:1}),i.a.createElement(g.a,{item:!0,xs:1,sm:1,md:1,lg:1,xl:1})))))})))}}var qb=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"},aligner:{},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap",backgroundColor:"inherit"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},buttonRight:{margin:e.spacing(1),float:"right",marginLeft:"auto"},buttonLeft:{margin:e.spacing(1),float:"left",marginRight:"auto"},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},statusBar:{display:"flex",flexDirection:"row"},colorSecondary:{backgroundColor:"#e0e0e0"},red:{backgroundColor:ze.a[500]},amber:{backgroundColor:me.a[500]},green:{backgroundColor:K.a[500]},textred:{color:ze.a[500]},textamber:{color:me.a[500]},textgreen:{color:K.a[500]},badgeChild:{padding:e.spacing(0,.5),margin:"1px"},badge:{},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(Hb);const{RECENTS_LEN:Vb}=We;class jb extends n.Component{constructor(e){super(e),this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.onDownloaded=()=>{this.setState({pdf:!1,csv:!0})},this.sortProductByType=(e,t,a)=>(e&&e).map(e=>({...e,inout:"out",amount:"sprayings"===a?e.volume:parseFloat(e.total),comment:"Application on "+e.cropName,reason:"Application"})),this.getProductItems=(e,t,a)=>{const{inventoryItems:n,inventoryRequests:i}=this.state;let r=n;const l=tt(this.state.activityType,this.props.getFromGlobalState("blocks"),this.props.getFromGlobalState,!0,!0,100,void 0,void 0,!0,!0),s=this.sortProductByType(l.rows,null===e||void 0===e?void 0:e.sk,this.props.activityName),o=parseFloat(null===e||void 0===e?void 0:e.minStock);let c=s.concat(r).map(e=>{const t={...e};return"out"===t.inout&&(t.amount=-1*t.amount),t.actionType="Entry",t});const d=(m=0,e=>m+=parseFloat(e.amount));var m;const p=c.map(d);c=c.map((e,t)=>{const a={...e};return a.balance=p[t],a});const h=c.reduce((e,t)=>e+parseFloat(t.amount),0),g=h>1.1*o?"green":h>o&&h<=1.1*o?"amber":"red";c=c&&c.sort((e,t)=>new Date(t.date)-new Date(e.date));const u=c.length,b=c.slice(0,Vb),v=null===e||void 0===e?void 0:e.unit;let y=[],f=[];return f=[{id:"date",combine:[{id:"date",opacity:1},{id:"reason",opacity:.6}],numeric:!1,disablePadding:!1,label:"Date"},{id:"amount",combine:[{id:"amount",opacity:1}],numeric:!0,disablePadding:!1,label:`(${v})`}],y=[{id:"date",numeric:!1,disablePadding:!1,label:"Date",minWidth:"80px"},{id:"blockNumber",numeric:!1,disablePadding:!1,label:"Block",minWidth:"80px"},{id:"plantingName",numeric:!1,disablePadding:!1,label:"Planting",minWidth:"80px"},{id:"reason",numeric:!1,disablePadding:!1,label:"Reason",minWidth:"70px"},{id:"comment",numeric:!1,disablePadding:!1,label:"Comment",minWidth:"70px"},{id:"amount",numeric:!0,disablePadding:!1,label:`Total (${v})`},{id:"balance",numeric:!0,disablePadding:!1,label:`Balance (${v})`}],{count:u,mostRecent:b,rows:c,headCells:y,headCellsClean:f,total:h,unit:v,minStock:o,status:{status:g,message:""}}},this.state={selectedTab:0,expandedProduct:null,selectedProduct:null,inventoryItems:null,inventoryRequests:[],selectedInventoryItem:null,selectedChemicalCrop:null,expandedContent:null,modalObject:null,isNew:!1,inventoryItemDialogOpen:!1,chemicalCropDialogOpen:!1,inventoryRequestDialogOpen:!1,errors:{},openModal:"",showAllDialogOpen:!1,showReportDialogOpen:!1,clean:!0,pdf:!1,startDate:void 0,endDate:void 0,csv:!1,applications:[]}}async componentDidMount(){if(!this.props.isAuthenticated)return;this.props.getFromGlobalState("inv_chemical")}createData(e,t,a,n,i,r){return{sk:e,name:t,calories:a,fat:n,carbs:i,protein:r}}blockReportPDF(){this.setState({pdf:!0})}blockReportCSV(){this.setState({csv:!0})}render(){const{classes:e,getFromGlobalState:t,setGlobalState:a}=this.props,{inventoryItemDialogOpen:n,isNew:r,selectedInventoryItem:l,selectedProduct:s,inventoryRequestDialogOpen:o,selectedInventory:c,showAllDialogOpen:d,expandedProduct:m,pdf:p,csv:h,clean:u,selectedinventoryItemSK:b,showReportDialogOpen:v,startDate:y,endDate:f}=this.state,E=this.getProductItems(),S=t("farm")[0];t("userDetail");function C(e,t){return e.slice().sort((e,a)=>new Date(e[t])-new Date(a[t]))}return i.a.createElement(N,{isloading:this.state.isloading},i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(g.a,{className:e.searchBar,key:"search",style:{padding:"3px",marginBottom:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(O.a,null," ",i.a.createElement(Mr,{pdfRequested:p,csvRequested:h,onBlockReportPDF:this.blockReportPDF.bind(this),onBlockReportCSV:this.blockReportCSV.bind(this),getFromGlobalState:t,reportCSV:i.a.createElement(zb,{onDownloaded:this.onDownloaded,data:{headCells:E.headCells,title:"Inventory Records",rows:y&&f?C(E.rows,"date").filter(e=>e.date>=y&&e.date<=f):C(E.rows,"date")},color:"secondary",className:e.pdfButton,startDate:y,endDate:f,farm:S})}))),this.state.dateRangeDialogOpen&&i.a.createElement(Kt,{open:this.state.dateRangeDialogOpen,loading:this.state.reportLoading,title:"Report Date Range",handleConfirm:"pdf"===this.state.reportType?this.handleGeneratePDF:this.handleGenerateCSV,handleCancel:"csv"===this.state.reportType?this.handleCancelGeneratePDF:this.handleCancelGenerateCSV,startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,handleSetStartDate:this.setReportStartDate,handleSetEndDate:this.setReportEndDate}),i.a.createElement(Mi,{value:this.state.selectedTab,handleChange:this.handleTabChange},i.a.createElement(qb,{heading:"Plant Protection",inventoryName:"inv_chemical",getFromGlobalState:t,setGlobalState:a,initialState:this.props.getFromGlobalState("inv_chemical"),metaData:{products:this.props.getFromGlobalState("chemicals"),blocks:this.props.getFromGlobalState("blocks"),crops:this.props.getFromGlobalState("crops")},activityName:"sprayings"}),i.a.createElement(qb,{heading:"Fertiliser",inventoryName:"inv_fertiliser",getFromGlobalState:t,setGlobalState:a,initialState:this.props.getFromGlobalState("inv_fertiliser"),metaData:{products:this.props.getFromGlobalState("fertilisers"),blocks:this.props.getFromGlobalState("blocks"),crops:this.props.getFromGlobalState("crops")},activityName:"fertilisings"}))))}}var $b=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(2),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(jb),Yb=a(221);class _b extends n.Component{constructor(e){super(e),this.processCSV=(e,t=",")=>{const a=e.slice(0,e.indexOf("\n")).split(t),n=e.slice(e.indexOf("\n")+1).split("\n").map(e=>{const n=e.split(t);return a.reduce((e,t,a)=>(e[t]=n[a].replace("\r",""),e),{})});console.log("new arr",n)},this.readFile=async e=>{const t=e.target.files[0],a=new FileReader;a.readAsText(t),a.onload=async function(){const e=a.result,t=e.slice(0,e.indexOf("\n")).split(";"),n=e.slice(e.indexOf("\n")+1).split("\n").map(e=>{const a=e.split(";");return t.reduce((e,t,n)=>(e[t.replace("\r","")]=a[n].replace("\r",""),e),{})});for(const a of n){const e=a.parentSK.concat("_setchild_").concat(Rt.a.v1()),t={setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",sk:e,name:a.cropName,activeTenant:"aeba4040-1dc4-11ec-9f88-e121604a510b",isGeneral:!0,type:"cropsSetting"},n=Rt.a.v1(),r={setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",sk:e.concat("_setchild_").concat(n),version:1,cropName:e,activeTenant:"aeba4040-1dc4-11ec-9f88-e121604a510b",createdAt:1632947910323,createdBy:"us-east-1:4f16bd35-3bd9-483f-b8e0-b43e64bc295e",isGeneral:!0,cropType:a.parentSK,type:"cropsDetail"};try{if((await ya("67d106c9-0f9e-4811-9aaa-6b814ccf7263","calls",ua(t),t.activeTenant)).status){t.uploaded=!0;(await ya("67d106c9-0f9e-4811-9aaa-6b814ccf7263","calls",ua(r),r.activeTenant)).status&&(r.uploaded=!0)}else t.uploaded=!1;console.log(t.sk,"uploaded",t.uploaded),console.log(r.sk,"uploaded",r.uploaded)}catch(i){return this.props.setSnack({open:!0,variant:"error",messageText:Pa(i)}),!1}}console.log("inserts done")},a.onerror=function(){console.log(a.error)}},this.handleSubmit=async(e,t)=>{try{return!1}catch(a){alert(a)}},this.state={}}async componentDidMount(){const{getFromGlobalState:e}=this.props,t=e("currentUser").username;this.setState({currentUser:t})}toCsv(e){return e.reduce((e,t)=>(e+=t.join(","),e+="\r\n",encodeURIComponent(e)),"")}createCropData(e){}render(){const{classes:e,reload:t}=this.props;return i.a.createElement(N,{isloading:this.state.isloading},i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(B.a,{component:"h1",variant:"h5"},`Version ${Yb.buildMajor}.${Yb.buildMinor}.${Yb.buildRevision}`),i.a.createElement(E.a,{"aria-label":"Edit",color:"primary",className:e.menuButton,onClick:t},i.a.createElement(Rr.a,null)),i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{style:{padding:"10px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(O.a,{elevation:0,className:e.section},i.a.createElement(Ct.a,{text:"maintain",color:"inherit",onClick:this.handleSubmit}," Maintains"),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"file",id:"number",name:"number",style:{minWidth:"200px"},onChange:this.readFile.bind(this)}),i.a.createElement(ju.a,{variant:"middle"}))))))}}var Zb=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},section:{margin:e.spacing(2,4)}}))(_b);var Jb=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,firstFormValid:r,onApplyAll:l,handleBlur:s,handleCommonBlur:o,handleCommonChange:c,block:d,planting:m,metaData:p,selectedBlocks:h,handleSwitchChange:v,handleBatchChange:y}=e;let f=!0;return(e=>{for(var t of e){if(!t.record)continue;if(!t.record.duration)continue;let e=t.blockOB,a=t.plantingOB;const n=e.flowunit;let i;"hectare"===n?i=parseFloat(t.record.duration)*parseFloat(e.volumePerHour)*parseFloat(a.size?a.size:e.size):"plant"===n&&(i=t.record.duration*e.volumePerHour*a.totalPlants),t.record.actualLiters=i}})(h),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},h&&h.map(e=>i.a.createElement(u.a,{style:{width:"100%",marginBottom:"15px"}},i.a.createElement(b.a,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:t.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:y.bind(this,e.planting,e.block),onBlur:s.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].date)||void 0,helperText:n[e.planting]&&n[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(bn.a,{shrink:!0,htmlFor:"duration"},"Duration (hours)"),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},fullWidth:!0,id:"duration",name:"duration",value:e.record.duration,onChange:y.bind(this,e.planting,e.block),onBlur:s.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].duration)||void 0,helperText:n[e.planting]&&n[e.planting].duration})),i.a.createElement(g.a,{item:!0,xs:7,sm:7,md:9,lg:9,xl:9}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{fullWidth:!0,className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"actualLiters"},"Applied Liters"),i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",inputProps:{min:"0.00001",step:"any"},fullWidth:!0,id:"actualLiters",name:"actualLiters",value:e.record.actualLiters,onChange:y.bind(this,e.planting,e.block),onBlur:s.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].actualLiters)||void 0,helperText:n[e.planting]&&n[e.planting].actualLiters})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:y.bind(this,e.planting,e.block),operators:p.operators,title:"Operator",value:e.record.operator,team:e.record.team,onBlur:s.bind(this,e.planting),error:n[e.planting]&&n[e.planting].operator})),f&&i.a.createElement(g.a,{style:{marginTop:"20px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ct.a,{variant:"contained",color:"primary",className:t.submit,onClick:l.bind(this,e.planting,e.block,e.record),disabled:r},"Apply to All")),f=!1)))))}));const Qb=(e,t,a)=>{const n=a[a.map(e=>e.name).indexOf(t)].sk;return e.filter(e=>e.targetType===n)},Xb=({selectedBlock:e,handleBatchChange:t,handleBlur:a,errors:n,classes:r,handleBatchCheckChange:l,metaData:s,handleLocationBatchChange:o,expandedSetting:c,handleSettingExpand:d,handlePestingsMonitored:m,onApplyAll:p,firstFormValid:h,index:v,selectedBlocks:y})=>{var f,E;const S=s.monitorings.find(t=>t.sk===e.record.pest);S&&!e.record.numPointsScoutedOverride&&(e.record.numPointsScouted=S.quantityOfUnit);const C=(null===e||void 0===e||null===(f=e.record)||void 0===f?void 0:f.target)||"";return console.log("record we want",e.record),i.a.createElement(u.a,{style:{width:"100%",marginBottom:"15px"},key:v},i.a.createElement(b.a,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:r.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:t.bind(void 0,e.planting,e.block),onBlur:a.bind(void 0,e.planting),error:!(!n[e.planting]||!n[e.planting].date)||void 0,helperText:n[e.planting]&&n[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Tr,{onChange:o.bind(void 0,e.planting,e.block),value:null===e||void 0===e||null===(E=e.record)||void 0===E?void 0:E.geoLocation,id:"geoLocation",required:!0,name:"geoLocation"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12,style:{marginBottom:10}},i.a.createElement(vn.a,{component:"fieldset",className:r.formControl},i.a.createElement(kn.a,{required:!0},"Target"),i.a.createElement(xn.a,{"aria-label":"target",name:"target",id:"target",className:r.group,value:C,onChange:t.bind(void 0,e.planting,e.block)},i.a.createElement(Fe.a,{value:"Pest",control:i.a.createElement(Cn.a,{id:"target"}),label:"Pest"}),i.a.createElement(Fe.a,{value:"Disease",control:i.a.createElement(Cn.a,{id:"target"}),label:"Disease"}),i.a.createElement(Fe.a,{value:"Beneficial",control:i.a.createElement(Cn.a,{id:"target"}),label:"Beneficial"}),i.a.createElement(Fe.a,{value:"Other",control:i.a.createElement(Cn.a,{id:"target"}),label:"Other"}),i.a.createElement(Fe.a,{value:"Phenology",control:i.a.createElement(Cn.a,{id:"target"}),label:"Phenology"}),n[e.planting]&&n[e.planting].target&&i.a.createElement(En.a,{className:r.helperText},n[e.planting].target)))),((e,t,a,n,i,r,l)=>{var s;const o=t.plantingOB.crop;let c=[];if(!a)return c;const d=null===(s=l[l.map(e=>e.name).indexOf(a)])||void 0===s?void 0:s.sk;if("Other"===a)return c=e.filter(e=>{var t,a;return(null===(t=e.targetDetail)||void 0===t||null===(a=t.nonCropDetail)||void 0===a?void 0:a.monitorType)===n&&e.targetType===d}),c;{e.forEach((function(e){var t;i.findIndex(e=>e.sk===o);const a=i[i.map(e=>e.sk).indexOf(o)].name;(null===(t=e.targetDetail)||void 0===t?void 0:t.observableOn.map(e=>e.name)).includes(a)&&c.push(e)}));const t=Qb(c,a,l);return console.log("pestsAllowed",t),t}})(s.monitorings,e,e.record.target,"Field",s.crops,s.pests,s.targetTypes).map((t,l)=>{var s,o,p,h,u,b,y,f,E,x,k,w,T,D,P,F;return i.a.createElement(cr,{heading:t.targetDetail.name,key:t.targetDetail.sk,overwriteDisplay:!0,expanded:c,handleExpand:d},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},"Yes"===t.cropSpecific&&t.targetDetail.observableOn[0].stages.map((s,o)=>{var c,d,p,h,u,b,v,y,f,E,x,k,w,T,D,P,F,N,B,L,A;return i.a.createElement(i.a.Fragment,null,i.a.createElement(bn.a,{shrink:!0,htmlFor:"pest",style:{marginBottom:10}},s.stageDescription),"Number"===s.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",step:!0,required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"0.01"},id:"units",label:"Other"!==(null===S||void 0===S?void 0:S.target)?"Number observed":(null===(c=S.selectedPest)||void 0===c||null===(d=c.targetDetail)||void 0===d||null===(p=d.nonCropDetail)||void 0===p?void 0:p.unit)+" observed",name:"units",value:null!==(h=null===(u=e.record)||void 0===u||null===(b=u.stages)||void 0===b||null===(v=b[C])||void 0===v||null===(y=v[l])||void 0===y?void 0:y[o])&&void 0!==h?h:"",onChange:a=>m(e.planting,a,s.sk,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,o,e.record.target,l),onBlur:a.bind(void 0,e.planting),error:!(!n[e.planting]||!(null===(f=n[e.planting])||void 0===f?void 0:f.units))||void 0,helperText:n.units})),"Percentage"===s.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"0.01"},id:"units",label:"Percentage",name:"units",value:null!==(E=null===(x=e.record)||void 0===x||null===(k=x.stages)||void 0===k||null===(w=k[C])||void 0===w||null===(T=w[l])||void 0===T?void 0:T[o])&&void 0!==E?E:"",onChange:a=>m(e.planting,e.block,a,s.sk,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,o,e.record.target,l),onBlur:a.bind(void 0,e.planting),error:!(!n[e.planting]||!(null===(D=n[e.planting])||void 0===D?void 0:D.units))||void 0,helperText:n.units})),"Present"===s.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:r.formControlRadio},i.a.createElement(kn.a,{required:!0},"Present"),i.a.createElement(xn.a,{"aria-label":"units",name:"units",id:"units",className:r.group,value:null!==(P=null===(F=e.record)||void 0===F||null===(N=F.stages)||void 0===N||null===(B=N[C])||void 0===B||null===(L=B[l])||void 0===L||null===(A=L[o])||void 0===A?void 0:A.toString())&&void 0!==P?P:"",onChange:a=>m(e.planting,a,s.sk,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,o,e.record.target,l)},i.a.createElement(Fe.a,{value:"1",control:i.a.createElement(Cn.a,{id:"units"}),label:"Yes"}),i.a.createElement(Fe.a,{value:"0",control:i.a.createElement(Cn.a,{id:"units"}),label:"No"}),n[e.planting]&&n[e.planting].units&&i.a.createElement(En.a,{className:r.helperText},n[e.planting].units)))))}),"No"===t.cropSpecific&&"Number"===t.targetDetail.nonCropDetail.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"0.01"},id:"units",label:`$${null===S||void 0===S?void 0:S.unit} observed`,name:"units",value:null!==(s=null===(o=e.record)||void 0===o||null===(p=o.stages)||void 0===p||null===(h=p[C])||void 0===h||null===(u=h[l])||void 0===u?void 0:u[v])&&void 0!==s?s:"",onChange:a=>m(e.planting,a,void 0,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,v,e.record.target,l),onBlur:a.bind(void 0,e.planting),error:!(!n[e.planting]||!n[e.planting].units)||void 0,helperText:n.units})),"No"===t.cropSpecific&&"Percentage"===t.targetDetail.nonCropDetail.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"0.01"},id:"units",label:"Percentage",name:"units",value:null!==(b=null===(y=e.record)||void 0===y||null===(f=y.stages)||void 0===f||null===(E=f[C])||void 0===E||null===(x=E[l])||void 0===x?void 0:x[v])&&void 0!==b?b:"",onChange:a=>m(e.planting,a,void 0,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,v,e.record.target,l),onBlur:a.bind(void 0,e.planting),error:!(!n[e.planting]||!n[e.planting].units)||void 0,helperText:n.units}))," ","No"===t.cropSpecific&&"Present"===t.targetDetail.nonCropDetail.unitNum&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:r.formControlRadio},i.a.createElement(kn.a,{required:!0},"Present"),i.a.createElement(xn.a,{"aria-label":"units",name:"units",id:"units",className:r.group,value:null!==(k=null===(w=e.record)||void 0===w||null===(T=w.stages)||void 0===T||null===(D=T[C])||void 0===D||null===(P=D[l])||void 0===P||null===(F=P[v])||void 0===F?void 0:F.toString())&&void 0!==k?k:"",onChange:a=>m(e.planting,a,void 0,t.sk,t.targetDetail.sk,t.cropSpecific,t.targetDetail.observableOn[0].sk,v,e.record.target,l)},i.a.createElement(Fe.a,{value:"1",control:i.a.createElement(Cn.a,{id:"units"}),label:"Yes"}),i.a.createElement(Fe.a,{value:"0",control:i.a.createElement(Cn.a,{id:"units"}),label:"No"}),n[e.planting]&&n[e.planting].units&&i.a.createElement(En.a,{className:r.helperText},n[e.planting].units))))))}),0===v&&y.length>1&&i.a.createElement(g.a,{style:{marginTop:"20px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ct.a,{variant:"contained",color:"primary",className:r.submit,onClick:p.bind(void 0,e.planting,e.block,e.record),disabled:h},"Apply to All"))))};var ev=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},group:{flexDirection:"row"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{firstFormValid:t,onApplyAll:a,classes:r,errors:l,handleBlur:s,metaData:o,selectedBlocks:c,handleBatchChange:d,handleBatchCheckChange:m,handleLocationBatchChange:p,handlePestingsMonitored:h}=e,[u,b]=Object(n.useState)({expandedSetting:""});if(!o.monitorings)return null;const v=e=>{const{expandedSetting:t}=u;b(t!==e?{expandedSetting:e}:{expandedSetting:""})};return i.a.createElement(g.a,{container:!0,className:r.root,spacing:1,alignItems:"flex-start"},c&&c.map((e,n)=>i.a.createElement(Xb,{selectedBlock:e,handleBatchChange:d,handleBlur:s,errors:l,classes:r,handleBatchCheckChange:m,metaData:o,handleLocationBatchChange:p,expandedSetting:u.expandedSetting,handleSettingExpand:v,handlePestingsMonitored:h,onApplyAll:a,firstFormValid:t,index:n,selectedBlocks:c})))}));var tv=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,errors:a,handleBlur:n,firstFormValid:r,onApplyAll:l,metaData:s,selectedBlocks:o,handleBatchChange:c}=e,d=s.agronomistActs;let m=!0;return i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},o&&o.map(e=>i.a.createElement(u.a,{style:{width:"100%",marginBottom:"15px"}},i.a.createElement(b.a,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:t.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:c.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].date)||void 0,helperText:a[e.planting]&&a[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"activities"},"Activity"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:e.record.activity,onChange:c.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].activity)||void 0,inputProps:{name:"activity",id:"activity"}},i.a.createElement("option",{value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),a[e.planting]&&a[e.planting].activity&&i.a.createElement(En.a,{className:t.helperText},a[e.planting].activity))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12}),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:c.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),operators:s.operators,title:"Operator",value:e.record.operator,team:e.record.team,error:a[e.planting]&&a[e.planting].operator})),m&&i.a.createElement(g.a,{style:{marginTop:"20px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ct.a,{variant:"contained",color:"primary",className:t.submit,onClick:l.bind(this,e.planting,e.block,e.record),disabled:r},"Apply to All")),m=!1))))}));var av=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,record:a,errors:n,handleBlur:r,handleChange:l,metaData:s,selectedBlocks:o,handleBatchChange:c,overrideHarvestTotal:d,handleCommonBlur:m,handleCommonChange:p}=e,h=s;return a.harvestTotal=((e,t)=>{if(!e)return 0;for(var a of t)if(!a.record.totalHarvestOverride){if(a.record.totalHarvestOverride=!1,!a.record.harvestUnits)continue;let t=e.find(e=>e.sk===a.record.harvestEquip);if(!t)return;a.record.harvestTotal=a.record.harvestUnits*t.capacity}})(h,o),i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},o&&o.map(e=>i.a.createElement(u.a,{style:{width:"100%",marginBottom:"15px"}},i.a.createElement(b.a,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:t.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:c.bind(this,e.planting,e.block),onBlur:r.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].date)||void 0,helperText:n[e.planting]&&n[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"harvestEquip"},"Harvest Unit"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:e.record.harvestEquip,onChange:c.bind(this,e.planting,e.block),onBlur:r.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].harvestEquip)||void 0,inputProps:{name:"harvestEquip",id:"harvestEquip"}},i.a.createElement("option",{value:""}),h&&h.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),n[e.planting]&&n[e.planting].harvestEquip&&i.a.createElement(En.a,{className:t.helperText},n[e.planting].harvestEquip))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"harvestUnits",label:"Total Units",name:"harvestUnits",value:e.record.harvestUnits,onChange:c.bind(this,e.planting,e.block),onBlur:r.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].harvestUnits)||void 0,helperText:n[e.planting]&&n[e.planting].harvestUnits})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"harvestTotal"},"Total harvest in Kg"),i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",inputProps:{min:"0.00001",step:"any"},id:"harvestTotal",name:"harvestTotal",disabled:!e.record.totalHarvestOverride,value:e.record.harvestTotal,onChange:c.bind(this,e.planting,e.block),onBlur:r.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].harvestTotal)||void 0,helperText:n[e.planting]&&n[e.planting].harvestTotal})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"harvestOverride",control:i.a.createElement(Cn.a,{color:"secondary",name:"totalHarvestOverride",checked:e.record.totalHarvestOverride,id:"totalHarvestOverride",onClick:d.bind(this,e.planting,e.block)}),label:"Override"}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"text",id:"deliveryNote",label:"Delivery Note",name:"deliveryNote",value:e.record.deliveryNote,onChange:c.bind(this,e.planting,e.block),onBlur:r.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].deliveryNote)||void 0,helperText:n[e.planting]&&n[e.planting].deliveryNote})),i.a.createElement(g.a,{item:!0,xs:4,sm:4,md:8,lg:8,xl:8})))))}));const nv=(e,t)=>(e.fertcrops||[]).find(e=>e.crop===t.crop),iv=(e,t,a)=>{if(!e)return;const n=a&&a.find(t=>t.sk===e);return n&&nv(n,t)},rv=(e,t)=>{if(!e)return;return t.find(t=>t.sk===e)};var lv=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)},paper:{margin:e.spacing(2),padding:e.spacing(2)},tooltip:{backgroundColor:"white"}}))((function(e){const{classes:t,record:a,errors:n,getFromGlobalState:r,handleBlur:l,onApplyAll:s,handleChange:o,overrideTotalBatch:c,firstFormValid:d,metaData:m,planting:p,block:h,handleSwitchChange:v,selectedBlocks:y,handleBatchChange:f,handleCommonBlur:E,handleCommonChange:S}=e,C=r("combinations").filter(e=>"Fertiliser"===e.combinationType),x=m.fertilisers.filter(e=>!e.isDisabled).concat(C);let k;const w=m.fertilisers.concat(C);((e,t)=>{for(var a of e){if(!a.record)continue;if(!a.record.unit)continue;if(!t)continue;const e=a.record;if(e.unit){let n,i;if(e.product){n=iv(e.product,a.plantingOB,t);const r=rv(e.product,t);i=null===r||void 0===r?void 0:r.unit}"plant"===e.unit?e.totalUnit="kg"===i?"g":"ml":e.totalUnit="kg"===i?"kg":"l"}e.volume&&!e.totalOverride&&("plant"===e.unit?e.total=e.volume*a.plantingOB.totalPlants:"ha"===e.unit?e.total=e.volume*a.plantingOB.size:e.total=e.volume)}})(y,w),k=iv(y,w);let T=!0;return i.a.createElement(i.a.Fragment,null,y&&y.map(e=>{var r;const o=C.find(t=>{var a;return t.sk===(null===e||void 0===e||null===(a=e.record)||void 0===a?void 0:a.product)})||null,d=!!o;var p;d&&(e.record.combinations=(null===e||void 0===e||null===(p=e.record)||void 0===p?void 0:p.combinations)||[]);return i.a.createElement(u.a,{full:!0,style:{width:"100%",marginBottom:"15px"}},i.a.createElement(b.a,null,i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:t.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].date)||void 0,helperText:n[e.planting]&&n[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:4,lg:4,xl:4},i.a.createElement(zt.a,{margin:"normal",type:"time",id:"endTime",label:"End Time",name:"endTime",InputLabelProps:{shrink:!0},value:e.record.endTime,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].endTime)||void 0,helperText:n[e.planting]&&n[e.planting].endTime})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Fertiliser"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,value:e.record.product,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].product)||void 0,inputProps:{name:"product",id:"product"}},i.a.createElement("option",{value:""}),x&&x.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),d?null===o||void 0===o||null===(r=o.combinationProducts)||void 0===r?void 0:r.map((a,r)=>{var s,o,c,d,p,h,u,b,v,y,E,S,C,x,k,w;return i.a.createElement(g.a,{item:!0,style:{marginTop:20},container:!0,className:t.root,spacing:1,alignItems:"flex-end",key:r},"chemical"===a.type?i.a.createElement(g.a,{style:{border:"1px solid #eee",padding:5},container:!0},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===a||void 0===a||null===(s=a.selectedChemical)||void 0===s?void 0:s.name," (Chemical)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,value:null===e||void 0===e||null===(o=e.record)||void 0===o||null===(c=o.combinations[r])||void 0===c?void 0:c.chemrigs,onChange:t=>{var n,i;const l={...e.record};l.product=null===a||void 0===a||null===(n=a.selectedChemical)||void 0===n?void 0:n.sk,l.type="sprayings",l.chemrigs=t.target.value;const s=(null===e||void 0===e||null===(i=e.record)||void 0===i?void 0:i.combinations)||[];s.splice(r,1,l),e.record.combinations=s},onBlur:l.bind(this,e.planting),inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),m.chemequips&&m.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",disabled:!(null===(d=e.record)||void 0===d||null===(p=d.combinations[r])||void 0===p?void 0:p.chemrigs),inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",name:"numRigs",InputLabelProps:{shrink:!0},value:null===e||void 0===e||null===(h=e.record)||void 0===h||null===(u=h.combinations[r])||void 0===u?void 0:u.numRigs,onChange:t=>{var a;const n=(null===e||void 0===e||null===(a=e.record)||void 0===a?void 0:a.combinations[r])||{};n.numRigs=t.target.value;const i=m.chemequips.find(e=>e.sk===n.chemrigs);n.volume=parseFloat(null===i||void 0===i?void 0:i.capacity)*t.target.value;const s=(null===e||void 0===e?void 0:e.record.combinations)||[];s.splice(r,1,n),e.record.combinations=s,l.bind(this,e.planting)},onBlur:l.bind(this,e.planting)})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",InputLabelProps:{shrink:!0},disabled:!0,inputProps:{min:"0.00001",step:"any"},fullWidth:!0,id:"volume",label:"Total volume in liters",name:"volume",value:null===e||void 0===e||null===(b=e.record)||void 0===b||null===(v=b.combinations[r])||void 0===v?void 0:v.volume}))):i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-end",style:{border:"1px solid #eee",padding:5}},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===a||void 0===a||null===(y=a.selectedFertiliser)||void 0===y?void 0:y.name," (fertiliser)"),i.a.createElement("hr",null),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:null===e||void 0===e||null===(E=e.record)||void 0===E||null===(S=E.combinations[r])||void 0===S?void 0:S.unit,onChange:t=>{var n,i;const l=(null===e||void 0===e||null===(n=e.record)||void 0===n?void 0:n.combinations[r])||{...null===e||void 0===e?void 0:e.record};delete l.combinations,l.product=null===a||void 0===a||null===(i=a.selectedFertiliser)||void 0===i?void 0:i.sk,l.type="fertilisings",l.unit=t.target.value,t.target.value&&("plant"===t.target.value?l.totalUnit="kg"===(null===a||void 0===a?void 0:a.selectedFertiliser.unit)?"g":"ml":l.totalUnit="kg"===(null===a||void 0===a?void 0:a.selectedFertiliser.unit)?"kg":"l");const s=(null===e||void 0===e?void 0:e.record.combinations)||[];s.splice(r,1,l),e.record.combinations=s},onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].unit)||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),n.unit&&i.a.createElement(En.a,{className:t.helperText},n.unit)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},e.record.totalUnit?e.record.totalUnit:""),min:"0.00001",step:"any"},InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"volume",label:"Applied quantity",name:"volume",value:null===e||void 0===e||null===(C=e.record)||void 0===C||null===(x=C.combinations[r])||void 0===x?void 0:x.volume,onChange:t=>{const a=e.record.combinations[r]||{};var n;if(a.volume=t.target.value,t.target.value)if("plant"===a.unit)a.total=parseFloat(t.target.value)*(null===e||void 0===e||null===(n=e.blockOB)||void 0===n?void 0:n.plantings[0].totalPlants);else if("ha"===a.unit){var i;a.total=parseFloat(t.target.value)*(null===e||void 0===e||null===(i=e.blockOB)||void 0===i?void 0:i.plantings[0].size)}else a.total=parseFloat(t.target.value);const l=e.record.combinations||[];l.splice(r,1,a),e.record.combinations=l},onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].volume)||void 0,helperText:n[e.planting]&&n[e.planting].volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"total",label:"Total "+(e.record.totalUnit?e.record.totalUnit:""),name:"total",value:null===e||void 0===e||null===(k=e.record)||void 0===k||null===(w=k.combinations[r])||void 0===w?void 0:w.total,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),error:!(!n[e.planting]||!n[e.planting].volume)||void 0,helperText:n.total}))))}):i.a.createElement(i.a.Fragment,null,i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,displayEmpty:!0,value:e.record.unit,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"cluster"},"Cluster"),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),n.unit&&i.a.createElement(En.a,{className:t.helperText},n.unit))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},a.totalUnit?a.totalUnit:""),min:"0.00001",step:"any"},InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"volume",label:"Applied quantity",name:"volume",value:e.record.volume,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting)})))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(Fe.a,{value:"totalOverride",control:i.a.createElement(Cn.a,{color:"secondary",name:"totalOverride",checked:e.record.totalOverride,id:"totalOverride",onClick:c.bind(this,e.planting,e.block)}),label:"Override"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting),operators:m.operators,title:"Operator",value:e.record.operator,team:e.record.team})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"notes",label:"Notes",name:"notes",multiline:!0,rowsMax:"4",value:e.record.notes,onChange:f.bind(this,e.planting,e.block),onBlur:l.bind(this,e.planting)})),T&&i.a.createElement(g.a,{style:{marginTop:"20px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ct.a,{variant:"contained",color:"primary",className:t.submit,onClick:s.bind(this,e.planting,e.block,e.record)},"Apply to All")),T=!1)))}))}));const sv=(e,t)=>{if(void 0===e)return;if(void 0===t)return;if(void 0===e.chemcrops)return;return e.chemcrops.find(e=>e.crop===t.crop)},ov=(e,t,a)=>{if(!t)return[];const n=a("monitorings"),i=e.find(e=>e.sk===t);let r={};r="combinations"===i.type?i.combinationProducts.flatMap(e=>{var t;return null===e||void 0===e||null===(t=e.selectedChemicalCrop)||void 0===t?void 0:t.targets}):i.chemcrops[0].targets;return n.filter(e=>{var t;return null===(t=r)||void 0===t?void 0:t.some(t=>t.target===e.sk)})};var cv=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)},paper:{margin:e.spacing(2),padding:e.spacing(2)},tooltip:{backgroundColor:"white",color:"black",fontSize:"12px",boxShadow:"0px 1px 3px 0px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 2px 1px -1px rgba(0,0,0,0.12)"}}))((function(e){const{classes:t,errors:a,handleBlur:n,expandedTarget:r,getFromGlobalState:l,firstFormValid:s,handleExpand:o,onApplyAll:c,metaData:d,selectedBlocks:m,handleBatchChange:p,handleBatchApplied:h,handleBatchToggleReasons:v}=e,y=((e,t,a)=>{const n={};if(t){for(const i of t){const t=i.plantingOB.crop,r=[];e.forEach(e=>{if(e.chemcrops){-1!==e.chemcrops.findIndex(e=>e.crop===t)&&r.push(e)}});const l=a("combinations").filter(e=>"Plant Protection"===e.combinationType);n[i.planting]=[...r,...l]}return n}})(d.chemicals,m,l),f=l("combinations").filter(e=>"Plant Protection"===e.combinationType);((e,t)=>{for(var a of e)if(a.record&&a.record.chemrigs&&a.record.numRigs&&a.record.chemrigs&&a.record.numRigs){const e=t.chemequips.find(e=>e.sk===a.record.chemrigs);a.record.volume=e.capacity*a.record.numRigs}})(m,d),((e,t,a)=>{if(t)for(var n of e){var i;if(!n.record.product||!n.record.endDate||!n.record.date)continue;const e=a("combinations").filter(e=>"Plant Protection"===e.combinationType),r=t.concat(e).find(e=>e.sk===n.record.product),l=sv(r,n.plantingOB);if(!l)return;const s=(null===(i=(l.targets||[]).map(e=>e.phi))||void 0===i?void 0:i.length)>0&&l.targets.map(e=>e.phi)[0];n.record.phiLapse=J(n.record.date,n.record.time,s)}})(m,d.chemicals,l);let E=!0;return i.a.createElement(i.a.Fragment,null,m&&m.map(e=>{var m;const S=f.find(t=>{var a;return t.sk===(null===e||void 0===e||null===(a=e.record)||void 0===a?void 0:a.product)})||null,C=!!S;var x;C&&(e.record.combinations=(null===e||void 0===e||null===(x=e.record)||void 0===x?void 0:x.combinations)||[]);return i.a.createElement(u.a,{style:{width:"100%",marginBottom:"15px"}},i.a.createElement(b.a,null,i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{variant:"h6",color:"inherit",noWrap:!0,className:t.location},e.label)),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:8,lg:8,xl:8},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"date",id:"date",label:"Date",name:"date",InputLabelProps:{shrink:!0},value:e.record.date,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].date)||void 0,helperText:a[e.planting]&&a[e.planting].date})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:8,xl:8},i.a.createElement(zt.a,{margin:"normal",type:"time",id:"endTime",label:"End Time",name:"endTime",InputLabelProps:{shrink:!0},value:e.record.endTime,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].endTime)||void 0,helperText:a[e.planting]&&a[e.planting].endTime})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Plant Protection"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:e.record.product,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].product)||void 0,inputProps:{name:"product",id:"product"}},i.a.createElement("option",{value:""}),y[e.planting]&&y[e.planting].map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),a[e.planting]&&a[e.planting].product&&i.a.createElement(En.a,{className:t.helperText},a[e.planting].product))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(bn.a,{shrink:!0,htmlFor:"reasons"},"Reasons"),i.a.createElement(Sr,{metaData:{monitorings:e.record.product?ov(y[e.planting],e.record.product,l):[]},onBlur:n.bind(this,e.planting),checkedItems:e.record.reasons,handleToggle:v,getFromGlobalState:l,handleExpand:o,expandedTarget:r,planting:e.planting,readOnly:!0,pickApplied:!0,handleApplied:h,arrayName:"reasons"}),i.a.createElement(En.a,{className:t.helperText},a.reasons),a[e.planting]&&a[e.planting].reasons&&i.a.createElement(En.a,{className:t.helperText},a[e.planting].reasons)),C?null===S||void 0===S||null===(m=S.combinationProducts)||void 0===m?void 0:m.map((r,l)=>{var s,o,c,m,h,u,b,v,y,f,E,S,C,x,k,w;return i.a.createElement(g.a,{item:!0,style:{marginTop:20},container:!0,className:t.root,spacing:1,alignItems:"flex-end",key:l},"chemical"===r.type?i.a.createElement(g.a,{style:{border:"1px solid #eee",padding:5},container:!0},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===r||void 0===r||null===(s=r.selectedChemical)||void 0===s?void 0:s.name," (Chemical)"),i.a.createElement("hr",null),i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:null===e||void 0===e||null===(o=e.record)||void 0===o||null===(c=o.combinations[l])||void 0===c?void 0:c.chemrigs,onChange:t=>{var a,n;const i={...e.record};i.product=null===r||void 0===r||null===(a=r.selectedChemical)||void 0===a?void 0:a.sk,i.type="sprayings",i.chemrigs=t.target.value;const s=(null===e||void 0===e||null===(n=e.record)||void 0===n?void 0:n.combinations)||[];s.splice(l,1,i),e.record.combinations=s},onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].chemrigs)||void 0,inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),d.chemequips&&d.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),a[e.planting]&&a[e.planting].chemrigs&&i.a.createElement(En.a,{className:t.helperText},a[e.planting].chemrigs))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",type:"number",disabled:!(null===(m=e.record)||void 0===m||null===(h=m.combinations[l])||void 0===h?void 0:h.chemrigs),inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",value:null===e||void 0===e||null===(u=e.record)||void 0===u||null===(b=u.combinations[l])||void 0===b?void 0:b.numRigs,name:"numRigs",InputLabelProps:{shrink:!0},onChange:t=>{var a;const n=(null===e||void 0===e||null===(a=e.record)||void 0===a?void 0:a.combinations[l])||{};n.numRigs=t.target.value;const i=d.chemequips.find(e=>e.sk===n.chemrigs);n.volume=parseFloat(null===i||void 0===i?void 0:i.capacity)*t.target.value;const r=(null===e||void 0===e?void 0:e.record.combinations)||[];r.splice(l,1,n),e.record.combinations=r},onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].numRigs)||void 0,helperText:a[e.planting]&&a[e.planting].numRigs})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},disabled:!0,inputProps:{min:"0.00001",step:"any"},fullWidth:!0,id:"volume",label:"Total volume in liters",name:"volume",value:null===e||void 0===e||null===(v=e.record)||void 0===v||null===(y=v.combinations[l])||void 0===y?void 0:y.volume,error:!(!a[e.planting]||!a[e.planting].volume)||void 0,helperText:a[e.planting]&&a[e.planting].volume}))):i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-end",style:{border:"1px solid #eee",padding:5}},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("label",{style:{marginTop:20}},null===r||void 0===r||null===(f=r.selectedFertiliser)||void 0===f?void 0:f.name," (fertiliser)"),i.a.createElement("hr",null),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"product"},"Application per"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:null===e||void 0===e||null===(E=e.record)||void 0===E||null===(S=E.combinations[l])||void 0===S?void 0:S.unit,onChange:t=>{var a,n;const i=(null===e||void 0===e||null===(a=e.record)||void 0===a?void 0:a.combinations[l])||{...null===e||void 0===e?void 0:e.record};delete i.combinations,i.product=null===r||void 0===r||null===(n=r.selectedFertiliser)||void 0===n?void 0:n.sk,i.type="fertilisings",i.unit=t.target.value,t.target.value&&("plant"===t.target.value?i.totalUnit="kg"===(null===r||void 0===r?void 0:r.selectedFertiliser.unit)?"g":"ml":i.totalUnit="kg"===(null===r||void 0===r?void 0:r.selectedFertiliser.unit)?"kg":"l");const s=(null===e||void 0===e?void 0:e.record.combinations)||[];s.splice(l,1,i),e.record.combinations=s},onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].unit)||void 0,inputProps:{name:"unit",id:"unit"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"planting"},"Planting"),i.a.createElement("option",{value:"plant"},"Plant"),i.a.createElement("option",{value:"ha"},"ha")),a.unit&&i.a.createElement(En.a,{className:t.helperText},a.unit)))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputProps:{endAdornment:i.a.createElement(ri.a,{position:"end"},e.record.totalUnit?e.record.totalUnit:""),min:"0.00001",step:"any"},InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"volume",label:"Applied quantity",name:"volume",value:null===e||void 0===e||null===(C=e.record)||void 0===C||null===(x=C.combinations[l])||void 0===x?void 0:x.volume,onChange:t=>{const a=e.record.combinations[l]||{};var n;if(a.volume=t.target.value,t.target.value)if("plant"===a.unit)a.total=parseFloat(t.target.value)*(null===e||void 0===e||null===(n=e.blockOB)||void 0===n?void 0:n.plantings[0].totalPlants);else if("ha"===a.unit){var i;a.total=parseFloat(t.target.value)*(null===e||void 0===e||null===(i=e.blockOB)||void 0===i?void 0:i.plantings[0].size)}else a.total=parseFloat(t.target.value);const r=e.record.combinations||[];r.splice(l,1,a),e.record.combinations=r},onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].volume)||void 0,helperText:a[e.planting]&&a[e.planting].volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"total",label:"Total "+(e.record.totalUnit?e.record.totalUnit:""),name:"total",value:null===e||void 0===e||null===(k=e.record)||void 0===k||null===(w=k.combinations[l])||void 0===w?void 0:w.total,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].volume)||void 0,helperText:a.total}))))}):i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"chemrigs"},"Equipment"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:e.record.chemrigs,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].chemrigs)||void 0,inputProps:{name:"chemrigs",id:"chemrigs"}},i.a.createElement("option",{value:""}),d.chemequips&&d.chemequips.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),a[e.planting]&&a[e.planting].chemrigs&&i.a.createElement(En.a,{className:t.helperText},a[e.planting].chemrigs))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",disabled:!e.record.chemrigs,inputProps:{min:"0.00001",step:"any"},id:"numRigs",shrink:!0,label:"Total number applied",name:"numRigs",InputLabelProps:{shrink:!0},value:e.record.numRigs,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].numRigs)||void 0,helperText:a[e.planting]&&a[e.planting].numRigs})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,type:"number",InputLabelProps:{shrink:!0},disabled:!0,inputProps:{min:"0.00001",step:"any"},fullWidth:!0,id:"volume",label:"Total volume in liters",name:"volume",value:e.record.volume,error:!(!a[e.planting]||!a[e.planting].volume)||void 0,helperText:a[e.planting]&&a[e.planting].volume})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,type:"number",InputLabelProps:{shrink:!0,min:"0.00001",step:"any"},id:"volume",label:"Total Volume Applied [Liters]",name:"volume",value:e.record.volume,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].volume)||void 0,helperText:a[e.planting]&&a[e.planting].volume}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"weather"},"Weather"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,value:e.record.weather,onChange:p.bind(this,e.planting,e.block),inputProps:{name:"weather",id:"weather"}},i.a.createElement("option",{value:""}),i.a.createElement("option",{value:"Sunny"},"Sunny"),i.a.createElement("option",{value:"Cloudy"},"Cloudy"),i.a.createElement("option",{value:"Night"},"Night")))),i.a.createElement(g.a,{item:!0,xs:6,sm:6,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"phiLapse"},"Withholding period end"),i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"phiLapse",name:"phiLapse",readOnly:!0,value:e.record.phiLapse,onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].phiLapse)||void 0,helperText:a[e.planting]&&a[e.planting].phiLapse}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(si,{onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),operators:d.operators,title:"Operator",value:e.record.operator,team:e.record.team,error:a[e.planting]&&a[e.planting].operator})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",fullWidth:!0,id:"notes",label:"Notes",name:"notes",multiline:!0,InputLabelProps:{shrink:!0},rowsMax:"4",value:e.record.notes,onChange:p.bind(this,e.planting,e.block),onBlur:n.bind(this,e.planting),error:!(!a[e.planting]||!a[e.planting].notes)||void 0,helperText:a[e.planting]&&a[e.planting].notes})),E&&i.a.createElement(g.a,{style:{marginTop:"20px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Ct.a,{variant:"contained",color:"primary",className:t.submit,onClick:c.bind(this,e.planting,e.block,e.record),disabled:s},"Apply to All")),E=!1)))}))}));class dv extends n.Component{constructor(e){super(e),this.handleBlur=(e,t)=>this.validateField(t.target.id,this.props.requiredFields,e),this.onApplyAll=(e,t,a,n)=>{const i=[...this.state.selectedBlocks];for(const r of i)r.record={...a};this.setState({selectedBlocks:i,changed:!0})},this.handleCommonBlur=e=>{const t={isValid:!0};return this.state.selectedBlocks.forEach(a=>{t.isValid=t.isValid&&jn(e.target.id,a.record,this.props.requiredFields).isValid}),t},this.overrideCalculatedVolume=e=>{const t={...this.state.record};t.calculatedVolumeOverride=!t.calculatedVolumeOverride,this.setState({record:t,changed:!0})},this.overrideCalculatedProduct=e=>{const t={...this.state.record};t.calculatedProductOverride=!t.calculatedProductOverride,this.setState({record:t,changed:!0})},this.handleChange=e=>{const t={...this.state.record};t[e.target.id]=e.target.value,this.setState({record:t,changed:!0})},this.handleBatchApplied=(e,t,a,n)=>{const i=[...this.state.selectedBlocks].find(e=>e.planting===n);if(i){const{record:n}=i,r={...n};r[a]||(r[a]=[]);const l=r[a].findIndex(e=>e.target===t);if(-1!==l){for(let e=0;e{const n=[...this.state.selectedBlocks],i=n.find(e=>e.planting===a);if(i){const{record:a}=i,{getFromGlobalState:n}=this.props,r=a;r[t]||(r[t]=[]);const l=r[t].findIndex(t=>t.target===e);for(let e=0;e"Plant Protection"===e.combinationType),s=n("chemicals").concat(l).find(e=>e.sk===a.product),o=("combinations"===s.type?s.combinationProducts.map(e=>e.selectedChemicalCrop).find(e=>e.crop===i.plantingOB.crop):s.chemcrops.find(e=>e.crop===i.plantingOB.crop)).targets.find(t=>t.target===e);o.applied=!0,r[t].push(o)}else r[t].splice(l,1)}this.setState({selectedBlocks:n,changed:!0})},this.handleBatchChange=(e,t,a)=>{const n=[...this.state.selectedBlocks],i=n.find(t=>t.planting===e);console.log("isCombination",t),i&&(i.record[a.target.id]=a.target.value),this.setState({selectedBlocks:n,changed:!0})},this.handlePestingsMonitored=(e,t,a,n,i,r,l,s,o,c)=>{const d=[...this.state.selectedBlocks],m=d.find(t=>t.planting===e);if(console.log(t),m){const e=parseFloat(t.target.value);if(isNaN(e)){var p,h,g;(null===(p=m.record.stages)||void 0===p||null===(h=p[o])||void 0===h?void 0:h[c])&&delete m.record.stages[o][c][s];const e=null===(g=m.record.observations)||void 0===g?void 0:g.findIndex(e=>e.stageSK===a&&e.monitoringSK===n);return-1!==e&&m.record.observations.splice(e,1),void this.setState({selectedBlocks:d,changed:!0})}m.record.geoLocations=m.record.geoLocations?[...m.record.geoLocations]:[],m.record.geoLocations.splice(0,1,m.record.geoLocation),m.record.stages=m.record.stages||[],m.record.stages[o]=m.record.stages[o]||[],m.record.stages[o][c]=m.record.stages[o][c]||[],m.record.stages[o][c].lengthe.stageSK===a&&e.monitoringSK===n);-1!==b?m.record.observations[b].entries.splice(0,1,[e]):m.record.observations.push(u)}this.setState({selectedBlocks:d,changed:!0})},this.overrideTotalBatch=(e,t,a)=>{const n=[...this.state.selectedBlocks],i=n.find(t=>t.planting===e);i&&(i.record[a.target.id]=!i.record[a.target.id]),this.setState({selectedBlocks:n,changed:!0})},this.handleLocationBatchChange=(e,t,a)=>{const n=[...this.state.selectedBlocks],i=n.find(t=>t.planting===e);i&&(i.record.geoLocation=a),this.setState({selectedBlocks:n,changed:!0})},this.handleBatchCheckChange=(e,t,a)=>{const n=[...this.state.selectedBlocks],i=n.find(t=>t.planting===e);i&&(i.record[a.target.id]=a.target.checked),this.setState({selectedBlocks:n,changed:!0})},this.overrideHarvestTotal=(e,t,a)=>{const n=[...this.state.selectedBlocks],i={...this.state.errors},r=n.find(t=>t.planting===e);r&&(r.record[a.target.id]=!r.record[a.target.id]),r.record[a.target.id]&&(i.harvestEquip=void 0,i.harvestUnits=void 0),this.setState({errors:i,selectedBlocks:n,changed:!0})},this.handleCommonChange=e=>{const t=[...this.state.selectedBlocks],{record:a}=this.state;t&&t.forEach(t=>{t.record[e.target.id]=e.target.value}),a[e.target.id]=e.target.value,this.setState({selectedBlocks:t,changed:!0,record:a})},this.handleSwitchChange=e=>t=>{const a={...this.state.record};a[e]=t.target.checked,this.setState({record:a,changed:!0})},this.handleComplexChange=(e,t,a)=>{const n={...this.state.record};n[a.target.id]=a.target.value,n[t]=a.target.value*this.props.inputData[e],this.setState({record:n,changed:!0})},this.handleExpand=e=>{const{expandedTarget:t}=this.state;t!==e?this.setState({expandedTarget:e}):this.setState({expandedTarget:""})},this.handleToggleChemrigs=(e,t,a)=>{const n=[...this.state.selectedBlocks],i=n.find(e=>e.planting===a);if(i){i.record[t]||(i.record[t]=[]);const a=i.record[t].indexOf(e);-1===a?i.record[t].push(e):i.record[t].splice(a,1)}this.setState({selectedBlocks:n,changed:!0})},this.state={isloading:!1,isNew:this.props.isNew,record:{},errors:{count:0},changed:!1,selectedBlocks:[],expandedTarget:""}}componentDidMount(){if(this.props.isNew){const e=new Date,t={...this.state.record};t.date=e.toISOString().substr(0,10);const a=`${e.getHours()}:${e.getMinutes()}`;t.time=a;const n=this.props.selectedBlocks;n&&n.forEach(a=>{a.record.date=e.toISOString().substr(0,10),"fertilisings"!==this.props.recordType&&"sprayings"!==this.props.recordType||(a.record.endDate=e.toISOString().substr(0,10),a.record.endTime=Z(),a.record.time=Z(),a.record.date=e.toISOString().substr(0,10),t.endDate=e.toISOString().substr(0,10))}),this.setState({selectedBlocks:n,changed:!1,record:t})}}validateField(e,t,a){const n=jn(e,this.state.selectedBlocks.find(e=>e.planting===a).record,t),i={...this.state.errors};i[a]={},i[a][e]=n.msg,this.setState({errors:i})}updateParent(e,t){const a={...this.state.record};a[e]=t,this.setState({record:a})}render(){const{open:e,isNew:t,setClose:a,handleUpdateRecord:n,allowDelete:r,handleDeleteRecord:l,requiredFields:s,recordType:o,title:c,newTitle:d,plantingSK:m,getFromGlobalState:p,selectedBlocks:h}=this.props,{record:g,errors:u,expandedTarget:b}=this.state,v=h&&h[0]&&$n(h[0].record,s);return i.a.createElement(Ia,{open:e,dialogObject:{items:this.state.selectedBlocks},setClose:a,isNew:t,handleUpdateDialogObject:n.bind(this),skPrimary:"_record_",dynamoType:o,valid:!0,changed:this.state.changed,getFromGlobalState:p,newTitle:d,title:c,batchInserting:!0,lastUpdatedBy:{createdByEmail:(null===g||void 0===g?void 0:g.createdByEmail)?null===g||void 0===g?void 0:g.createdByEmail:"",createdAt:null===g||void 0===g?void 0:g.createdAt},subTitle:"New Batch Record",parentKey:m,plantingKey:m,allowDelete:r&&l,handleDeleteDialogObject:l?l.bind(this):void 0},"waterings"===o&&i.a.createElement(Jb,{record:g,errors:u,getFromGlobalState:p,onApplyAll:this.onApplyAll.bind(this),selectedBlocks:h,handleCommonChange:this.handleCommonChange.bind(this),handleBatchChange:this.handleBatchChange.bind(this),handleBlur:this.handleBlur.bind(this),handleCommonBlur:this.handleCommonBlur.bind(this),metaData:{operators:p("operators").filter(e=>-1!==e.roles.indexOf("waterings"))},updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange,firstFormValid:!v}),"pestings"===o&&i.a.createElement(ev,{record:g,errors:u,selectedBlocks:h,handlePestingsMonitored:this.handlePestingsMonitored.bind(this),handleBatchCheckChange:this.handleBatchCheckChange.bind(this),handleLocationBatchChange:this.handleLocationBatchChange.bind(this),handleCommonChange:this.handleCommonChange.bind(this),handleBatchChange:this.handleBatchChange.bind(this),getFromGlobalState:p,handleBlur:this.handleBlur.bind(this),handleCommonBlur:this.handleCommonBlur.bind(this),metaData:{monitorings:p("monitorings"),operators:p("operators").filter(e=>-1!==e.roles.indexOf("pestings")),crops:p("crops"),pests:p("pests"),targetTypes:p("targetsTypesSetting")},updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange,firstFormValid:!v,onApplyAll:this.onApplyAll.bind(this)}),"activities"===o&&i.a.createElement(tv,{record:g,errors:u,selectedBlocks:h,handleCommonChange:this.handleCommonChange.bind(this),onApplyAll:this.onApplyAll.bind(this),handleBatchChange:this.handleBatchChange.bind(this),getFromGlobalState:p,handleBlur:this.handleBlur.bind(this),handleCommonBlur:this.handleCommonBlur.bind(this),metaData:{agronomistActs:p("agronomistActs"),operators:p("operators").filter(e=>-1!==e.roles.indexOf("activities"))},updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange,firstFormValid:!v}),"harvestings"===o&&i.a.createElement(av,{record:g,errors:u,selectedBlocks:h,handleCommonChange:this.handleCommonChange.bind(this),handleBatchChange:this.handleBatchChange.bind(this),overrideHarvestTotal:this.overrideHarvestTotal.bind(this),handleBlur:this.handleBlur.bind(this),getFromGlobalState:p,handleCommonBlur:this.handleCommonBlur.bind(this),metaData:p("harvestequips"),updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange}),"fertilisings"===o&&i.a.createElement(lv,{record:g,errors:u,onApplyAll:this.onApplyAll.bind(this),selectedBlocks:h,getFromGlobalState:p,handleCommonChange:this.handleCommonChange.bind(this),handleBatchChange:this.handleBatchChange.bind(this),overrideTotalBatch:this.overrideTotalBatch.bind(this),handleBlur:this.handleBlur.bind(this),handleCommonBlur:this.handleCommonBlur.bind(this),metaData:{fertilisers:p("fertilisers"),operators:p("operators").filter(e=>-1!==e.roles.indexOf("fertilisings")),inventory:p("inv_fertiliser")},updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange,firstFormValid:!v}),"sprayings"===o&&i.a.createElement(cv,{record:g,errors:u,onApplyAll:this.onApplyAll.bind(this),getFromGlobalState:p,selectedBlocks:h,handleBatchToggleReasons:this.handleBatchToggleReasons.bind(this),handleBatchApplied:this.handleBatchApplied.bind(this),handleExpand:this.handleExpand.bind(this),handleCommonChange:this.handleCommonChange.bind(this),handleBatchChange:this.handleBatchChange.bind(this),handleBlur:this.handleBlur.bind(this),handleCommonBlur:this.handleCommonBlur.bind(this),expandedTarget:b,metaData:{chemicals:p("chemicals"),chemequips:p("chemequips"),pests:p("pests"),operators:p("operators").filter(e=>-1!==e.roles.indexOf("sprayings")),inventory:p("inv_chemical")},updateParent:this.updateParent.bind(this),handleSwitchChange:this.handleSwitchChange,handleToggle:this.handleToggleChemrigs,firstFormValid:!v}))}}var mv=Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:220,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(dv);var pv=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:120,marginTop:e.spacing(2)}}))((function(e){const{classes:t,errors:a,blocks:r,checkedItems:l,crops:s,handleToggle:o}=e;return i.a.createElement(tn.a,{className:t.root},r&&r.map(e=>i.a.createElement(n.Fragment,{key:e.sk},i.a.createElement(B.a,{key:e.sk,variant:"subtitle1"},"Block "+e.number),e&&e.plantings&&function(e,t,a,n,r,l,s){return i.a.createElement(tn.a,{className:e.root},t&&t.map(t=>{const o="checkbox-list-label-"+t.sk,c=`Block ${s.number} ${((e,t)=>{const a=e.find(e=>e.sk===t);let n="";return a&&(n=a.name),n})(n,t.crop)} - ${((e,t,a)=>{const n=e.find(e=>e.sk===t);let i="";if(n){const e=n.varieties.find(e=>e.sk===a);e&&(i=e.cultivar)}return i})(n,t.crop,t.variety)} - ${t.name?t.name:""}`;return i.a.createElement(en.a,{className:e.nested,disableRipple:!0,key:t.sk,role:void 0,dense:!0,button:!0,onClick:l.bind(this,t.sk,a,c,s,t)},i.a.createElement(ji.a,null,i.a.createElement(xe.a,{edge:"start",checked:-1!==r.findIndex(e=>e.planting===t.sk),tabIndex:-1,disableRipple:!0,inputProps:{"aria-labelledby":o}})),i.a.createElement(ti.a,{id:o,primary:c}))}))}(t,e.plantings,e.sk,s,l,o,e))))}));var hv=Object(v.a)(e=>({progress:{margin:e.spacing(2)},center:{display:"flex",justifyContent:"center"},formControl:{minWidth:150,marginTop:e.spacing(2)},formControlC:{minWidth:150,margin:e.spacing(1)}}))((function(e){const{classes:t,blocks:a,allSelected:n,onSelectAll:r,selectedBlocks:l,metaData:s,handleToggle:o,clusters:c,selectedCluster:d,selectedClusterGroup:m,handleClusterChange:p,handleClusterGroupChange:h}=e;return i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},c&&c.length&&i.a.createElement(i.a.Fragment,null,i.a.createElement(vn.a,{className:t.formControlC},i.a.createElement(bn.a,{shrink:!0,htmlFor:"assignedTo"},"Cluster groups"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:m,onChange:h,inputProps:{name:"cluster",id:"cluster"}},i.a.createElement("option",{value:""}),c&&c.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{key:e.sk,value:e.sk},e.name))))),i.a.createElement(vn.a,{className:t.formControlC},i.a.createElement(bn.a,{shrink:!0,htmlFor:"assignedTo"},"Cluster"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:d,onChange:p,inputProps:{name:"cluster",id:"cluster"}},i.a.createElement("option",{value:""}),m&&c.find(e=>e.sk===m).list.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{key:e.sk,value:e.sk},e.name)))))),i.a.createElement(Fe.a,{value:"start",style:{float:"right"},control:i.a.createElement(xe.a,{checked:n,onChange:r,disableRipple:!0,inputProps:{"aria-labelledby":"SelectAll"}}),label:"Select All",labelPlacement:"start"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(pv,{blocks:a,crops:s&&s.crops?s.crops:[],checkedItems:l,handleToggle:o})))}));const{RECENTS_LEN:gv}=We;const uv=[{type:"fertilisings",label:"Fertiliser",icon:function(e){return i.a.createElement(rn.a,{color:"secondary",style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M10.5,3C8,3 6,5 6,7.5C6,8.11 6.13,8.71 6.37,9.27C5.5,10.12 5,11.28 5,12.5C5,15 7,17 9.5,17C10,17 10.5,16.89 11,16.72V21H13V15.77C13.5,15.91 14,16 14.5,16A5.5,5.5 0 0,0 20,10.5A5.5,5.5 0 0,0 14.5,5C14.41,5 14.33,5 14.24,5C13.41,3.76 12,3 10.5,3M10.5,5C11.82,5 12.91,6.03 13,7.35C13.46,7.12 14,7 14.5,7A3.5,3.5 0 0,1 18,10.5A3.5,3.5 0 0,1 14.5,14C13.54,14 12.63,13.61 11.96,12.91C11.76,14.12 10.72,15 9.5,15A2.5,2.5 0 0,1 7,12.5C7,11.12 7.8,10.54 9,9.79C8.2,8.76 8,8.16 8,7.5A2.5,2.5 0 0,1 10.5,5Z"}),">")},requiredFields:[{name:"product",min:4,max:200},{name:"operator",min:1,max:200},{name:"date",min:1,max:40},{name:"endTime",min:1,max:40}]},{type:"sprayings",label:"Plant Protection",icon:function(e){return i.a.createElement(rn.a,{color:"secondary",style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M3,3H21V5A2,2 0 0,0 19,7V19A2,2 0 0,1 17,21H7A2,2 0 0,1 5,19V7A2,2 0 0,0 3,5V3M7,5V7H12V8H7V9H10V10H7V11H10V12H7V13H12V14H7V15H10V16H7V19H17V5H7Z"}),">")},requiredFields:[{name:"product",min:1,max:100},{name:"date",min:1,max:40},{name:"reasons",min:1,max:40,type:"array"},{name:"operator",min:1,max:200},{name:"weather",min:1,max:40}]},{type:"waterings",label:"Irrigation",icon:function(){return i.a.createElement(nn.a,{color:"secondary"})},requiredFields:[{name:"date",min:1,max:40},{name:"duration",min:1,max:40},{name:"operator",min:1,max:200},{name:"actualLiters",min:0,max:1e13,type:"number"}]},{type:"harvestings",label:"Harvest",icon:function(){return i.a.createElement(rn.a,{color:"secondary",style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M23,4.1V2.3L21.2,2.1C21.1,2.1 20.5,2 19.5,2C15.4,2 12.4,3.2 10.7,5.3C9.4,4.5 7.6,4 5.5,4C4.5,4 3.8,4.1 3.8,4.1L1.9,4.4L2,6.1C2.1,9.1 3.6,14.8 8.8,14.8C8.9,14.8 8.9,14.8 9,14.8V18.2C5.2,18.7 2,20 2,20V22H22V20C22,20 18.8,18.7 15,18.2V15C21.3,14.9 23,7.8 23,4.1M12,18C11.7,18 11.3,18 11,18V12.4C11,12.4 10.8,9 8,9C8,9 9.5,9.8 9.9,12.7C9.5,12.8 9.1,12.8 8.8,12.8C4.2,12.8 4,6.1 4,6.1C4,6.1 4.6,6 5.5,6C7.4,6 10.5,6.4 11.4,9.1C11.9,4.6 17,4 19.5,4C20.4,4 21,4.1 21,4.1C21,4.1 21,13.1 14.7,13.1C14.5,13.1 14.2,13.1 14,13.1C14,11.1 16,8.1 16,8.1C13,9.1 13,13 13,13V18C12.7,18 12.3,18 12,18Z"}),">")},requiredFields:[{name:"harvestEquip",min:1,max:100,condition:{name:"totalHarvestOverride",value:!1}},{name:"harvestUnits",min:1,max:40,condition:{name:"totalHarvestOverride",value:!1}},{name:"harvestTotal",min:1,max:40},{name:"date",min:1,max:40}]},{type:"pestings",label:"Monitoring",showSummary:!0,icon:function(){return i.a.createElement(rn.a,{color:"secondary",style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M20,8H17.19C16.74,7.2 16.12,6.5 15.37,6L17,4.41L15.59,3L13.42,5.17C12.96,5.06 12.5,5 12,5C11.5,5 11.05,5.06 10.59,5.17L8.41,3L7,4.41L8.62,6C7.87,6.5 7.26,7.21 6.81,8H4V10H6.09C6.03,10.33 6,10.66 6,11V12H4V14H6V15C6,15.34 6.03,15.67 6.09,16H4V18H6.81C8.47,20.87 12.14,21.84 15,20.18C15.91,19.66 16.67,18.9 17.19,18H20V16H17.91C17.97,15.67 18,15.34 18,15V14H20V12H18V11C18,10.66 17.97,10.33 17.91,10H20V8M16,15A4,4 0 0,1 12,19A4,4 0 0,1 8,15V11A4,4 0 0,1 12,7A4,4 0 0,1 16,11V15M14,10V12H10V10H14M10,14H14V16H10V14Z"}),">")},requiredFields:[{name:"date",min:1,max:40},{name:"observations",min:1,max:40}]},{type:"activities",label:"Agronomic Activity",icon:function(){return i.a.createElement(rn.a,{color:"secondary",style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M19.5,12c0.93,0,1.78,0.28,2.5,0.76V8c0-1.1-0.9-2-2-2h-6.29l-1.06-1.06l1.41-1.41l-0.71-0.71L9.82,6.35l0.71,0.71 l1.41-1.41L13,6.71V9c0,1.1-0.9,2-2,2h-0.54c0.95,1.06,1.54,2.46,1.54,4c0,0.34-0.04,0.67-0.09,1h3.14 C15.3,13.75,17.19,12,19.5,12z"}),i.a.createElement("path",{d:"M19.5,13c-1.93,0-3.5,1.57-3.5,3.5s1.57,3.5,3.5,3.5s3.5-1.57,3.5-3.5S21.43,13,19.5,13z M19.5,18 c-0.83,0-1.5-0.67-1.5-1.5s0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5S20.33,18,19.5,18z"}),i.a.createElement("path",{d:"M4,9h5c0-1.1-0.9-2-2-2H4C3.45,7,3,7.45,3,8C3,8.55,3.45,9,4,9z"}),i.a.createElement("path",{d:"M9.83,13.82l-0.18-0.47L10.58,13c-0.46-1.06-1.28-1.91-2.31-2.43l-0.4,0.89l-0.46-0.21l0.4-0.9C7.26,10.13,6.64,10,6,10 c-0.53,0-1.04,0.11-1.52,0.26l0.34,0.91l-0.47,0.18L4,10.42c-1.06,0.46-1.91,1.28-2.43,2.31l0.89,0.4l-0.21,0.46l-0.9-0.4 C1.13,13.74,1,14.36,1,15c0,0.53,0.11,1.04,0.26,1.52l0.91-0.34l0.18,0.47L1.42,17c0.46,1.06,1.28,1.91,2.31,2.43l0.4-0.89 l0.46,0.21l-0.4,0.9C4.74,19.87,5.36,20,6,20c0.53,0,1.04-0.11,1.52-0.26l-0.34-0.91l0.47-0.18L8,19.58 c1.06-0.46,1.91-1.28,2.43-2.31l-0.89-0.4l0.21-0.46l0.9,0.4C10.87,16.26,11,15.64,11,15c0-0.53-0.11-1.04-0.26-1.52L9.83,13.82z M7.15,17.77c-1.53,0.63-3.29-0.09-3.92-1.62c-0.63-1.53,0.09-3.29,1.62-3.92c1.53-0.63,3.29,0.09,3.92,1.62 C9.41,15.38,8.68,17.14,7.15,17.77z"}),">")},requiredFields:[{name:"activity",min:1,max:100},{name:"operator",min:1,max:200},{name:"date",min:1,max:40}]}];class bv extends n.Component{constructor(e){super(e),this.handleClusterGroupChange=e=>{const{selectedClusterGroup:t}=this.state;e.target.value!==t&&this.setState({selectedClusterGroup:e.target.value})},this.handleClusterChange=e=>{const{selectedCluster:t}=this.state;e.target.value!==t&&this.setState({selectedCluster:e.target.value})},this.handleToggle=(e,t,a,n,i)=>{const r=[...this.state.selectedBlocks];let l=this.state.allSelected;const s=r&&r.findIndex(t=>t.planting===e);-1===s?r.push({blockOB:n,plantingOB:i,block:t,planting:e,label:a,record:{}}):(r.splice(s,1),l=!1),this.setState({selectedBlocks:r,changed:!0,allSelected:l})},this.nameLookup=(e,t)=>{let a=e.find(e=>e.sk===t),n="";return a&&(n=a.name),n},this.varietyLookup=(e,t,a)=>{let n=e.find(e=>e.sk===t),i="";if(n){let e=n.varieties.find(e=>e.sk===a);e&&(i=e.cultivar)}return i},this.onSelectAll=e=>{let t=[...this.state.selectedBlocks];const{selectedCluster:a,allSelected:n,selectedClusterGroup:i}=this.state;let r=n;const l=this.props.getFromGlobalState("crops");if(r)r=!1,t=[];else{let e=this.props.getFromGlobalState("blocks");for(var s of("waterings"===this.state.selectedActivity.type&&(e=e.filter(e=>"irrigated"===e.irrigated)),e))if(s.plantings)for(var o of s.plantings){const e=!!o.clusters&&o.clusters.find(e=>e.sk===i),n=!!e&&e.items.find(e=>e===a);if(""!==i&&""!==a&&!n)continue;const r=`Block ${s.number} ${this.nameLookup(l,o.crop)} - ${this.varietyLookup(l,o.crop,o.variety)}`;t.push({blockOB:s,plantingOB:o,block:s.sk,planting:o.sk,label:r,record:{}})}r=!0}this.setState({allSelected:r,selectedBlocks:t,changed:!0})},this.handleExpandActivity=(e,t)=>{let a=this.state.selectedActivity;if(a&&a.type===a.type)this.setState({selectedActivity:null,data:null});else{const{getFromGlobalState:a}=this.props,{showSummaryByPlanting:n,clean:i}=this.state,r=tt(e.type,t,a,i,!0,gv,void 0,void 0,!0,!0);this.setState({selectedActivity:e,data:r})}},this.handleChange=e=>{let t={...this.state.selectedPest};t=e.target.value,this.setState({selectedPest:t})},this.handleClickShowTableRecord=(e,t,a,n,i,r)=>{const{showSummaryByPlanting:l}=this.state;if(l)this.setState({recordShowMessage:!0});else{let e=this.props.getFromGlobalState("blocks").find(e=>e.sk===i),n=null===e||void 0===e?void 0:e.plantings.find(e=>e.sk===t),l=n[r].find(e=>e.sk===a);this.setState({selectedBlock:e,selectedPlanting:n,selectedBlockSK:null===e||void 0===e?void 0:e.sk,selectedPlantingSK:null===n||void 0===n?void 0:n.sk,selectedRecord:l,selectedRecordSK:null===l||void 0===l?void 0:l.sk}),this.setState({openDialog:r,isNew:!1})}},this.setSnackClose=()=>{this.setState({recordShowMessage:!1})},this.handleShowDetail=(e,t,a)=>{let n=this.state.showDetail;n=a.target.checked;const{getFromGlobalState:i}=this.props,{clean:r,showSummaryByPlanting:l}=this.state,s=tt(e.type,t,i,!n,!0,gv,void 0,void 0,!0,!0);this.setState({data:{headCells:[],rows:[],title:"",mostRecent:[]},showDetail:n,clean:!n},()=>{this.setState({data:s})})},this.handleShowSummaryByPlanting=(e,t,a)=>{let n=this.state.showSummaryByPlanting;n=a.target.checked;const{getFromGlobalState:i}=this.props,{clean:r}=this.state,l=tt(e.type,t,i,r,!0,gv,void 0,void 0,!0,!0);this.setState({data:{headCells:[],rows:[],title:"",mostRecent:[]},showSummaryByPlanting:n},()=>{this.setState({data:l})})},this.onAddRecord=e=>{this.setState({openDialog:this.state.selectedActivity.type,isNew:!0,blockSelector:!0,selectedBlocks:[],selectedCluster:""})},this.handleCancelGeneratePDF=()=>{this.setState({activityPDF:null,pdf:!1,dateRangeDialogOpen:!1,reportLoading:!1,reportType:""})},this.handleCancelGenerateCSV=()=>{this.setState({activityCSV:null,csv:!1,dateRangeDialogOpen:!1,reportLoading:!1,reportType:""})},this.handleTogglePDF=e=>{this.setState({pdf:e})},this.handleToggleCSV=e=>{this.setState({csv:e})},this.handleToggleLoading=e=>{this.setState({reportLoading:e},()=>{this.handleTogglePDF(!0)})},this.handleToggleDateRangeDialog=(e,t)=>{this.setState({dateRangeDialogOpen:e},()=>{this.handleTogglePDF(t)})},this.handleToggleDateRangeDialogCSV=(e,t)=>{this.setState({dateRangeDialogOpen:e},()=>{this.handleToggleCSV(t)})},this.handleGeneratePDF=()=>{this.setState({reportLoading:!0},()=>{this.handleToggleDateRangeDialog(!1,!0)})},this.handleGenerateCSV=()=>{this.setState({reportLoading:!0},()=>{this.handleToggleDateRangeDialogCSV(!1,!0)})},this.setReportStartDate=e=>{this.setState({reportStartDate:e.target.value})},this.setAveraged=e=>{this.setState({averagedReport:e.target.checked})},this.setReportEndDate=e=>{this.setState({reportEndDate:e.target.value})},this.state={blocks:[],openDialog:"",isNew:!1,selectedBlock:null,selectedBlockSK:"",selectedRecordSK:"",selectedPlantingSK:"",selectedActivity:null,selectedRecord:null,showDetail:!1,showSummaryByPlanting:!0,clean:!0,blockSelector:!1,selectedBlocks:[],allSelected:!1,pdf:!1,csv:!1,activityPDF:null,activityCSV:null,dateRangeDialogOpen:!1,reportStartDate:"",averagedReport:!1,reportEndDate:(new Date).toISOString().substr(0,10),reportLoading:!1,selectedCluster:"",selectedClusterGroup:"",reportType:"",recordShowMessage:!1,data:null}}componentDidMount(){!window.matchMedia("(min-width: 850px)").matches||this.setState({showDetail:!0,showSummaryByPlanting:!0,clean:!1})}handleUpdateBatchRecord(e,t){!function(e,t,a,n){const i=a("blocks");for(const r of e.items){const e=i.findIndex(e=>e.sk===r.block);if(-1===e)return void alert("impossible - we don't have this block!");const{plantings:t}=i[e],a=i[e].plantings.findIndex(e=>e.sk===r.planting);i[e].plantings[a][r.record.type]||(i[e].plantings[a][r.record.type]=[]),i[e].plantings[a][r.record.type].push(r.record)}n({blocks:i})}(e,0,this.props.getFromGlobalState,this.props.setGlobalState,this.state.selectedBlockSK,this.state.selectedPlantingSK)}handleUpdateRecord(e,t){ba(e,0,this.props.getFromGlobalState,this.props.setGlobalState,this.state.selectedBlockSK,this.state.selectedPlantingSK)}handleBlockSelection(e,t){this.setState({blockSelector:!1})}setClose(){this.setState({openDialog:"",selectedRecord:null,selectedBlock:null,selectedPlanting:null,selectedBlockSK:"",selectedPlantingSK:"",selectedRecordSK:""})}closeBlockSelector(){this.setState({openDialog:"",blockSelector:!1,allSelected:!1})}handleDeleteRecord(e,t){const{getFromGlobalState:a,setGlobalState:n}=this.props,{selectedBlockSK:i,selectedPlantingSK:r}=this.state,l=a("blocks"),s=l.findIndex(e=>e.sk===i);if(-1===s)return void alert("impossible - we don't have this block!");const{plantings:o}=l[s],c=l[s].plantings.findIndex(e=>e.sk===r),d=o[c][e.type]?o[c][e.type].findIndex(t=>t.sk===e.sk):-1;if(-1===d)alert("impossible deleting a record that doesn't exist");else{if("fertilisings"===e.type||"sprayings"===e.type){const t=a("inv_chemical"),i=a("inv_fertiliser");if(t){const a=t.filter(t=>t.sk.startsWith(e.sk));a.length>0&&(a.forEach(e=>t.splice(t.indexOf(e),1)),n({inv_chemical:t}))}if(i){const t=i.filter(t=>t.sk.startsWith(e.sk));t.length>0&&(t.forEach(e=>i.splice(i.indexOf(e),1)),n({inv_fertiliser:i}))}}l[s].plantings[c][e.type].splice(d,1),n({blocks:l})}}onDownloadedPDF(e){e.stopPropagation(),this.setState({activityPDF:null,pdf:!1,reportLoading:!1,reportType:""})}onDownloadedCSV(e){e.stopPropagation(),this.setState({activityCSV:null,csv:!1,reportLoading:!1,reportType:""})}onReportRecordPDF(e,t){t.stopPropagation(),this.setState({activityPDF:e,dateRangeDialogOpen:!0,reportLoading:!1,reportType:"pdf"})}onReportRecordCSV(e,t){t.stopPropagation(),this.setState({activityCSV:e,dateRangeDialogOpen:!0,reportLoading:!1,reportType:"csv"})}getPDFLogic(e,t,a,n,r,l,s,o,c){return t&&t.type===n.type&&e?!this.state.dateRangeDialogOpen&&e&&t&&t.type===n.type?i.a.createElement(Mo,{startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,averagedReport:this.state.averagedReport,getFromGlobalState:a,blocks:o,recordTypeLabel:n.label,recordType:n.type,onDownloaded:r,color:"secondary",className:l.pdfButton,farm:s}):void 0:i.a.createElement(I.a,{title:"Generate PDF report"},i.a.createElement(E.a,{edge:"start",className:l.menuButton,color:"primary",onClick:c,"aria-label":"close"},i.a.createElement(Pt.a,null)))}getCSVLogic(e,t,a,n,r,l,s,o,c){return t&&t.type===n.type&&e?!this.state.dateRangeDialogOpen&&e&&t&&t.type===n.type?i.a.createElement(zo,{startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,averagedReport:this.state.averagedReport,getFromGlobalState:a,blocks:o,recordTypeLabel:n.label,recordType:n.type,onDownloaded:r,color:"secondary",className:l.pdfButton,farm:s}):void 0:i.a.createElement(E.a,{edge:"start",className:l.menuButton,color:"primary",onClick:c,"aria-label":"close"},i.a.createElement(I.a,{title:"Generate CSV report"},i.a.createElement(Nt.a,null)))}getReportIcons(e,t,a,n,r,l,s,o,c,d,m,p,h){return i.a.createElement("div",{style:{display:"flex",flexDirection:"row"}},this.getCSVLogic(e,a,r,l,o,c,d,m,p),this.getPDFLogic(t,n,r,l,s,c,d,m,h))}renderActivities(e,t,a,n,r,l){return uv.map(n=>{var s;return i.a.createElement(ca,{role:l&&l.rights&&l.rights.allowedActivities?"allowedActivities":"noAccess",isAdministrator:!0,perform:(null===l||void 0===l?void 0:l.rights)&&(null===l||void 0===l||null===(s=l.rights)||void 0===s?void 0:s.allowedActivities)&&l.rights.allowedActivities.includes(n.type)?n.type:"noAccess",yes:()=>i.a.createElement(g.a,{key:n.type,style:{padding:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(D,{expanded:!(!this.state.selectedActivity||this.state.selectedActivity.type!==n.type)||void 0,disableContentPadding:!0,title:n.label,ariaLabel:n.label,action:l&&l.rights&&l.rights.viewDashboard||l.rights.administrator?this.getReportIcons(this.state.csv,this.state.pdf,this.state.activityCSV,this.state.activityPDF,a,n,this.onDownloadedPDF.bind(this),this.onDownloadedCSV.bind(this),r,t,e,this.onReportRecordCSV.bind(this,n),this.onReportRecordPDF.bind(this,n)):null,avatar:i.a.createElement("div",{className:r.iconContainer},i.a.createElement(E.a,{className:r.button,style:{border:this.state.selectedActivity&&this.state.selectedActivity.type===n.type?"3px solid #63c7c8":void 0},size:"large"},n.icon())),handleExpandClick:this.handleExpandActivity.bind(this,n,e),expandedContent:this.state.selectedActivity&&this.state.selectedActivity.type&&this.state.selectedActivity.type===n.type&&i.a.createElement(Ve,{displayToolbar:!0,noPagination:!1,dense:!0,showAll:!0,recordType:this.state.selectedActivity.type,blocks:e,type:this.state.selectedActivity.type,handleSelect:this.handleClickShowTableRecord,getFromGlobalState:this.props.getFromGlobalState,handleAddItem:this.onAddRecord,clean:this.state.clean,handleShowDetail:this.handleShowDetail.bind(this,n,e),showDetail:this.state.showDetail,handleShowSummary:this.handleShowSummaryByPlanting&&n.showSummary?this.handleShowSummaryByPlanting.bind(this,n,e):void 0,showSummary:this.state.showSummaryByPlanting,data:this.state.data})})),no:()=>null})})}extractClusters(e){let t=[];if(!e)return t;const a=e.length;let n=0;for(;ne===i)&&t.push(e[n].plantings[a].cluster)}a+=1}}n+=1}return t=t&&t.sort((e,t)=>(""+e.number).localeCompare(t.number,void 0,{numeric:!0})),t}filterByCluster(e,t,a){let n=[];if(!e)return n;if(""===t||""===a)return e;const i=e.length;let r=0;for(;re.sk===t);if(s){s.items.find(e=>e===a)&&(l=!0)}if(l){let t=n.find(t=>t.sk===e[r].sk);t||(t={...e[r]},t.plantings=[],n.push(t));const a={...e[r].plantings[i]};t.plantings.push(a)}i+=1}}r+=1}return n}renderBlockSelector(e){let t=e("blocks");"waterings"===this.state.selectedActivity.type&&(t=t.filter(e=>"irrigated"===e.irrigated));const a=e("clusters");let n=this.filterByCluster(t,this.state.selectedClusterGroup,this.state.selectedCluster);return n=n&&n.sort((e,t)=>(""+e.number).localeCompare(t.number,void 0,{numeric:!0})),i.a.createElement(Ia,{open:this.state.blockSelector,dialogObject:void 0,setClose:this.closeBlockSelector.bind(this),isNew:this.state.isNew,handleUpdateDialogObject:this.handleBlockSelection.bind(this),skPrimary:"",dynamoType:void 0,valid:this.state.selectedBlocks.length>0,changed:this.state.changed,getFromGlobalState:this.props.getFromGlobalState,newTitle:"Select plantings",title:"Select plantings",subTitle:"",parentKey:"",plantingKey:"",noServerInteraction:!0,allowDelete:!1,handleDeleteDialogObject:void 0},this.state.blockSelector&&i.a.createElement(hv,{record:void 0,errors:void 0,clusters:a,handleClusterChange:this.handleClusterChange,handleClusterGroupChange:this.handleClusterGroupChange,selectedCluster:this.state.selectedCluster,selectedClusterGroup:this.state.selectedClusterGroup,handleToggle:this.handleToggle.bind(this),metaData:{crops:e("crops")},blocks:n,selectedBlocks:this.state.selectedBlocks,onSelectAll:this.onSelectAll,allSelected:this.state.allSelected}))}render(){const{classes:e,getFromGlobalState:t}=this.props,{reportType:a,recordShowMessage:n}=this.state,r=t("userDetail");return i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(i.a.Fragment,null,n&&i.a.createElement(ia,{open:!this.state.success,setClose:this.setSnackClose.bind(this),messageText:"To view the record details first uncheck the Averaged checkbox",variant:"info"})),i.a.createElement(g.a,{container:!0,className:e.root,spacing:2,alignItems:"flex-start"},i.a.createElement(g.a,{className:e.searchBar,key:"search",style:{padding:"3px",marginBottom:"3px"},item:!0,xs:12,sm:12,md:12,lg:12,xl:12})),i.a.createElement(N,{isloading:this.state.isLoading},i.a.createElement(g.a,{container:!0,className:e.root2,spacing:2,alignItems:"flex-start"},this.renderActivities(this.props.getFromGlobalState("blocks"),this.props.getFromGlobalState("farm")[0],this.props.getFromGlobalState,this.state.pdf,e,r),this.state.selectedActivity&&this.state.selectedActivity.type&&""!==this.state.openDialog&&!this.state.isNew&&i.a.createElement(Br,{handleUpdateRecord:this.handleUpdateRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:this.state.openDialog===this.state.selectedActivity.type,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,blockSK:this.state.selectedBlockSK,block:this.state.selectedBlock,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:this.state.selectedActivity.type,newTitle:" New "+uv.find(e=>e.type===this.state.selectedActivity.type).label,title:uv.find(e=>e.type===this.state.selectedActivity.type).label,getFromGlobalState:this.props.getFromGlobalState,requiredFields:uv.find(e=>e.type===this.state.selectedActivity.type).requiredFields}),!this.state.blockSelector&&this.state.selectedActivity&&this.state.selectedActivity.type&&""!==this.state.openDialog&&this.state.isNew&&i.a.createElement(mv,{handleUpdateRecord:this.handleUpdateBatchRecord.bind(this),handleDeleteRecord:this.handleDeleteRecord.bind(this),allowDelete:!0,open:this.state.openDialog===this.state.selectedActivity.type,setClose:this.setClose.bind(this),isNew:this.state.isNew,record:this.state.selectedRecord,selectedBlocks:this.state.selectedBlocks,blockSK:this.state.selectedBlockSK,plantingSK:this.state.selectedPlantingSK,planting:this.state.selectedPlanting,recordType:this.state.selectedActivity.type,newTitle:" New "+uv.find(e=>e.type===this.state.selectedActivity.type).label,title:uv.find(e=>e.type===this.state.selectedActivity.type).label,getFromGlobalState:this.props.getFromGlobalState,requiredFields:uv.find(e=>e.type===this.state.selectedActivity.type).requiredFields}),this.state.blockSelector&&this.renderBlockSelector(t),this.state.dateRangeDialogOpen&&i.a.createElement(Kt,{open:this.state.dateRangeDialogOpen,loading:this.state.reportLoading,title:"Report Date Range",handleConfirm:"pdf"===a?this.handleGeneratePDF:this.handleGenerateCSV,handleCancel:"csv"===a?this.handleCancelGeneratePDF:this.handleCancelGenerateCSV,startDate:this.state.reportStartDate,endDate:this.state.reportEndDate,averaged:this.state.activityCSV?this.state.activityCSV.showSummary:!!this.state.activityPDF&&this.state.activityPDF.showSummary,averagedChecked:this.state.averagedReport,handleSetAveraged:this.setAveraged,handleSetStartDate:this.setReportStartDate,handleSetEndDate:this.setReportEndDate}))))}}var vv=Object(v.a)(e=>({root:{flexGrow:1},root2:{flexGrow:1,marginTop:"5px"},iconContainer:{textAlign:"center",width:"60px"},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{width:"100%",marginTop:e.spacing(1)},fab:{margin:e.spacing(1)},fabFloat:{margin:e.spacing(1),top:"auto",right:20,bottom:80,left:"auto",position:"fixed"},submit:{margin:e.spacing(3,0,2)},list:{width:"100%",maxWidth:360,backgroundColor:e.palette.background.paper},heading:{[e.breakpoints.up("sm")]:{display:"none"}},searchBar:{[e.breakpoints.up("sm")]:{}},nested:{paddingLeft:e.spacing(4)},cardHeader:{paddingBottom:"6px"},cached:{fontSize:15,color:e.palette.secondary.main},syncError:{fontSize:15,color:"red"}}))(bv);class yv extends n.Component{constructor(e){super(e),this.sortEntities=e=>{const t=[],a=[],n={sk:"non_entity_related",entityType:"entity",name:"Z-Non Entity Related",shortName:"Z-Non Entity Related",farms:[],amount:0};return e.forEach(e=>{"entity"===e.entityType?t.push(e):"farm"===e.entityType&&(e.amount=((e=0,t=0,a=0)=>{const n=(850+12*e+50*Math.max(0,t-6))*(1-a/100);return Math.max(0,n)})(e.plantings,e.users,e.discount||0),a.push(e))}),a.sort((e,t)=>{const a=e.shortName||e.name||"",n=t.shortName||t.name||"";return a.localeCompare(n)}),t.forEach(e=>{e.farms=a.filter(t=>(null===t||void 0===t?void 0:t.parentFarm)===(null===e||void 0===e?void 0:e.sk)),e.amount=e.farms.reduce((e,t)=>e+(t.isDisabled?0:t.amount),0),e.farms.length>0&&e.farms.push({sk:"total",entityType:"farm",name:"Total",shortName:"Total",amount:e.amount})}),a.forEach(e=>{(null===e||void 0===e?void 0:e.parentFarm)||(n.farms.push(e),n.amount+=e.isDisabled?0:e.amount)}),n.farms.length>0&&(n.farms.push({sk:"total",entityType:"farm",name:"Total",shortName:"Total",amount:n.amount}),t.push(n)),t},this.farms=async()=>{const e=await o.a.get("farms","/listFarms"),t=this.removeDuplicates(this.sortEntities(e));console.log("sortedEntities",t),this.props.setGlobalState({farmList:e.filter(e=>"farm"===e.entityType)}),this.setState({entities:t,originalEntities:e})},this.updateGlobalState=(e,t)=>{const a={...this.props.getFromGlobalState("settings")};a[t]=e,this.props.setGlobalState({settings:a})},this.handleSubmit=async(e,t)=>{t.preventDefault(),console.log("look at these->",e,t),this.setState({isSubmitting:!0}),this.setState({messageText:""}),console.log("submiting now");try{e.sk||(e.sk="init_set_crops_"+Rt.a.v1(),e.type="settings",e.version=0);const t=e.version?e.version:0;e.version=t+1;let a={};e.activeTenant=this.props.getFromGlobalState("activeSite"),a=await ya(this.props.getFromGlobalState("currentUser").username,"calls",ua(e),this.props.getFromGlobalState("activeSite")),a.status&&(e.cached=a.cached),this.setState({isSubmitting:!1}),this.setState({success:!0}),this.updateGlobalState(e,"set_crops"),this.farms(),this.props.setClose()}catch(a){this.setState({success:!1,isSubmitting:!1,messageText:a.response?`${a.response.data.error.message}, api src: ${a.response.data.src} `:a.message})}},this.handleSettingExpand=e=>{this.state.expandedSetting!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.handleChange=e=>{const t=e.target.value;if(t){const e=this.searchForFarmOrEntity(this.state.originalEntities,t);this.setState({entities:e})}else{const e=this.sortEntities(this.state.originalEntities);this.setState({entities:e})}},this.state={expandedSetting:"",entities:[]}}searchForFarmOrEntity(e,t){const a=[],n=[],i=[],r={sk:"non_entity_related",entityType:"entity",name:"Non Entity Related",shortName:"Non Entity Related",farms:[]};return e.forEach(e=>{"entity"===e.entityType?a.push(e):"farm"===e.entityType&&n.push(e)}),a.forEach(e=>{(e.shortName||e.name||"").toLowerCase().includes(t.toLowerCase())&&(e.farms=n.filter(t=>(null===t||void 0===t?void 0:t.parentFarm)===(null===e||void 0===e?void 0:e.sk)),i.push(e))}),0===i.length&&n.forEach(e=>{if((e.shortName||e.name||"").toLowerCase().includes(t.toLowerCase())){const t=a.find(t=>(null===t||void 0===t?void 0:t.sk)===(null===e||void 0===e?void 0:e.parentFarm));t?(t.farms=[e],i.push(t)):r.farms.push(e)}}),r.farms.length>0&&i.push(r),this.removeDuplicates(i)}removeDuplicates(e){const t=new Map;return e.filter(e=>!t.has(e.name)&&(t.set(e.name,!0),!0))}componentDidMount(){this.farms()}render(){const{classes:e}=this.props,{expandedSetting:t,entities:a}=this.state;return i.a.createElement(O.a,{elevation:0,style:{marginTop:20,padding:10},className:e.mainSection},i.a.createElement(zt.a,{margin:"normal",id:"name",label:"Search....",name:"name",autoFocus:!0,disabled:0==a.length,onChange:this.handleChange}),a.map(e=>i.a.createElement(cr,{heading:e.name||e.shortName,expanded:t,handleExpand:this.handleSettingExpand},i.a.createElement(eo,{initialState:e.farms.map(e=>{const t={...e};return t.isDisabled=e.isDisabled?"Yes":"No",t}),farm:e,handleSubmit:this.handleSubmit,isSubmitting:this.state.isSubmitting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState,settingDialog:i.a.createElement(Fo,{parentFarm:e.sk}),showDetails:!0,settingName:"farmList",settingHeading:"Add",displayLabelPrim:"name",displayLabelSec:"description",headCells:[{id:"isDisabled",numeric:!1,disablePadding:!1,label:"Disabled"},{id:"farmId",numeric:!1,disablePadding:!1,label:"Farm ID"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"},{id:"plantings",numeric:!1,disablePadding:!1,label:"Plantings"},{id:"users",numeric:!1,disablePadding:!1,label:"Users"},{id:"amount",numeric:!1,disablePadding:!1,label:"Subscription"}]}))))}}var fv=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"}}))(yv),Ev=a(567),Sv=a.n(Ev),Cv=a(443),xv=a.n(Cv),kv=a(851),wv=a.n(kv),Tv=a(850),Dv=a.n(Tv),Pv=a(584),Fv=a.n(Pv),Nv=a(583),Bv=a.n(Nv),Lv=a(848),Av=a.n(Lv),Ov=a(849),Iv=a.n(Ov),Gv=a(852),Rv=a.n(Gv),Uv=a(847),Mv=a.n(Uv),Wv=a(853),zv=a.n(Wv);const Kv={Add:Object(n.forwardRef)((e,t)=>i.a.createElement(xv.a,Object.assign({},e,{ref:t}))),Check:Object(n.forwardRef)((e,t)=>i.a.createElement(At.a,Object.assign({},e,{ref:t}))),Clear:Object(n.forwardRef)((e,t)=>i.a.createElement(Bv.a,Object.assign({},e,{ref:t}))),Delete:Object(n.forwardRef)((e,t)=>i.a.createElement(It.a,Object.assign({},e,{ref:t}))),DetailPanel:Object(n.forwardRef)((e,t)=>i.a.createElement(Fv.a,Object.assign({},e,{ref:t}))),Edit:Object(n.forwardRef)((e,t)=>i.a.createElement(A.a,Object.assign({},e,{ref:t}))),Export:Object(n.forwardRef)((e,t)=>i.a.createElement(Mv.a,Object.assign({},e,{ref:t}))),Filter:Object(n.forwardRef)((e,t)=>i.a.createElement(vr.a,Object.assign({},e,{ref:t}))),FirstPage:Object(n.forwardRef)((e,t)=>i.a.createElement(Av.a,Object.assign({},e,{ref:t}))),LastPage:Object(n.forwardRef)((e,t)=>i.a.createElement(Iv.a,Object.assign({},e,{ref:t}))),NextPage:Object(n.forwardRef)((e,t)=>i.a.createElement(Fv.a,Object.assign({},e,{ref:t}))),PreviousPage:Object(n.forwardRef)((e,t)=>i.a.createElement(Dv.a,Object.assign({},e,{ref:t}))),ResetSearch:Object(n.forwardRef)((e,t)=>i.a.createElement(Bv.a,Object.assign({},e,{ref:t}))),Search:Object(n.forwardRef)((e,t)=>i.a.createElement(Ul.a,Object.assign({},e,{ref:t}))),SortArrow:Object(n.forwardRef)((e,t)=>i.a.createElement(wv.a,Object.assign({},e,{ref:t}))),ThirdStateCheck:Object(n.forwardRef)((e,t)=>i.a.createElement(Rv.a,Object.assign({},e,{ref:t}))),ViewColumn:Object(n.forwardRef)((e,t)=>i.a.createElement(zv.a,Object.assign({},e,{ref:t})))};var Hv=Object(v.a)(e=>({submit:{margin:e.spacing(1)}}),{withTheme:!0})((function(e){const{title:t,rows:a,headCells:n,onRowAdd:r,onRowUpdate:l,onRowDelete:s,isLoading:o,actions:c}=e;return i.a.createElement(Sv.a,{title:t,icons:Kv,actions:c||void 0,elevation:0,columns:n,data:a,components:{Container:e=>i.a.createElement(O.a,Object.assign({},e,{elevation:0}))},isLoading:o,options:{filtering:!0,sorting:!0,maxBodyHeight:400,pageSize:20,emptyRowsWhenPaging:!1,pageSizeOptions:[20,40,80,200],addRowPosition:"first",draggable:!1,rowStyle:{fontSize:"0.875rem",fontFamily:"Roboto",fontWeight:400}},editable:r&&l&&{onRowAdd:async e=>{await r(e)},onRowUpdate:async(e,t)=>{await l(e,t)},onRowDelete:async e=>{await s(e)}}})}));class qv extends n.Component{constructor(e){super(e),this.onRowUpdate=async e=>{const{getFromGlobalState:t,setSnack:a,setGlobalState:n}=this.props,{selectedCropType:i}=this.state,r=t("cropsDetail");try{const l={...e};l.version+=1,l.activeTenant=t("activeSite");const s=await ya(t("currentUser").username,"calls",ua(l),l.activeTenant);s.status&&(l.cached=s.cached);const o=[...r[i]],c=o.findIndex(e=>e.sk===l.sk);if(-1===c)return a({open:!0,variant:"error",messageText:"row not found in local cache - please refresh"}),!1;o[c]=l;const d={...r};return d[i]=o,n({cropsDetail:d}),!0}catch(l){return a({open:!0,variant:"error",messageText:Pa(l)}),!1}},this.onRowDelete=async e=>{const{getFromGlobalState:t,setSnack:a,setGlobalState:n}=this.props,{selectedCropType:i}=this.state,r=t("cropsDetail");try{const l={...e};l.activeTenant=t("activeSite");if(!(await ka(l)).status)return a({open:!0,variant:"error",messageText:"failed to delete - please refresh"}),!1;const s=[...r[i]],o=s.findIndex(e=>e.sk===l.sk);if(-1===o)return a({open:!0,variant:"error",messageText:"row not found in local cache - please refresh"}),!1;s.splice(o,1);const c={...r};return c[i]=s,n({cropsDetail:c}),!0}catch(l){return a({open:!0,variant:"error",messageText:Pa(l)}),!1}},this.onRowAdd=async e=>{const{getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props,i=t("cropsDetail"),{selectedCropType:r}=this.state;try{const n={...e};n.setId="a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",n.sk=e.cropName.concat("_setChild_").concat(Rt.a.v1()),n.isGeneral=!0,n.type="cropsDetail",n.version=1,n.activeTenant=t("activeSite");const l=await ya(t("currentUser").username,"calls",ua(n),n.activeTenant);l.status&&(n.cached=l.cached);const s=[...i[r]];s.push(n);const o={...i};return o[r]=s,a({cropsDetail:o}),!0}catch(l){return n({open:!0,variant:"error",messageText:Pa(l)}),!1}},this.handleEnableToggle=async()=>{const{selectedCropType:e}=this.state,{getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props,i=t("cropTypesSetting"),r={...i.find(t=>t.sk===e)};r.hasOwnProperty("enabled")?r.enabled=!r.enabled:r.enabled=!0;try{r.version||(r.version=0),r.version+=1,r.activeTenant=t("activeSite"),this.setState({isSubmitting:!0});const n=await ya(t("currentUser").username,"calls",ua(r),r.activeTenant);if(n.status){r.cached=n.cached;const t=[...i],l=t.findIndex(t=>t.sk===e);-1!==l&&(t[l]=r,this.setState({isSubmitting:!1}),a({cropTypes:t}))}}catch(l){return n({open:!0,variant:"error",messageText:Pa(l)}),!1}},this.onCropTypeChange=async e=>{let{selectedCropType:t}=this.state;const{columns:a,getCropDetails:n,setAdminState:i}=this.props;if(t===e.target.value)return!0;t=e.target.value,this.setState({selectedCropType:t,isloadingTable:!0});const r=await n(t);if(r&&r.crops&&r.crops.length){let e={...a};e=this.getHeader(r.crops).sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})),i({columns:e})}this.setState({isloadingTable:!1})},this.getHeader=e=>{if(!e)return[];const t={};e.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!1})).forEach(e=>{t[e.sk]=e.name});return[{title:"Crop name",field:"cropName",validate:e=>""===e.cropName?"Crop name cannot be empty":"",lookup:t},{title:"Cultivar type",field:"cultivarType",width:100},{title:"Cultivar name",field:"cultivar",validate:e=>""===e.cultivar?"Cultivar name cannot be empty":""},{title:"Rootstock type",field:"rootStockType"},{title:"Rootstock",field:"rootStock"}]},this.state={isloading:!1,isloadingTable:!1,selectedCropType:null,filters:{},isSubmitting:!1}}componentDidMount(){const{isAuthenticated:e}=this.props}render(){const{classes:e,rows:t,columns:a,getFromGlobalState:n}=this.props,{isloadingTable:r,selectedCropType:l,isloading:s,filters:o,isSubmitting:c}=this.state,d=n("cropTypesSetting"),m=d.find(e=>e.sk===l),p=m&&m.enabled;return i.a.createElement(N,{isloading:s},i.a.createElement(O.a,{elevation:0,style:{marginLeft:"4px"},className:e.paper},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Crop Type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:l,onChange:this.onCropTypeChange,inputProps:{name:"cropType",id:"cropType"}},i.a.createElement("option",{value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))),l&&i.a.createElement("div",{style:{margin:"10px"}},i.a.createElement(Mt,{onClick:this.handleEnableToggle,variant:"contained",color:"primary",className:e.submit,disabled:c,isloading:c,text:p?"Disable":"Enable",loadingText:p?"Disabling...":"Enabling..."})),i.a.createElement(Hv,{headCells:a,title:"",rows:t&&t[l]?t[l]:[],onRowAdd:l&&this.onRowAdd,onRowUpdate:this.onRowUpdate,onRowDelete:this.onRowDelete,isLoading:r,filters:o})))}}var Vv=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"},paper:{marginLeft:"4px",marginTop:"10px"},formControl:{minWidth:120,marginTop:e.spacing(2),marginLeft:"4px"},submit:{margin:e.spacing(1)}}))(qv);const jv=[{name:"name",min:1,max:80},{name:"targetType",min:1,max:80},{name:"image",min:1,max:5e3},{name:"observableOn",min:1,max:5e3}];class $v extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,jv),this.handleChange=e=>{const t={...this.state.target};t[e.target.id]=e.target.value,this.setState({target:t,changed:!0})},this.handleSettingExpand=async(e,t)=>{const{getFromGlobalState:a,setGlobalState:n,setSnack:i}=this.props;if(this.state.expnandedObservable!==e){this.setState({isLoading:!0}),this.setState({expnandedObservable:e});const{imageUrls:r}=this.state.imageUrls,l=await this.getUrls(t.stages,r),s=a("targetsTypesSetting").find(e=>"Phenology"===e.name);await Ba(a,n,i,s.sk,t.sk),this.setState({imageUrls:l,isLoading:!1})}else this.setState({expnandedObservable:""})},this.handleArrayChange=(e,t,a)=>{const n={...this.state.target};"Yes"===n.cropSpecific?n.observableOn[t].stages[a][e.target.id]=e.target.value:n.nonCropDetail[e.target.id]=e.target.value,this.setState({target:n,changed:!0})},this.handleDeleteStage=(e,t,a)=>{const n={...this.state.target};n.observableOn[t].stages[a]&&(n.observableOn[t].stages.splice(a,1),this.setState({target:n,changed:!0}))},this.handleDeleteObservable=(e,t)=>{const a={...this.state.target};a.observableOn[t]&&(a.observableOn.splice(t,1),this.setState({target:a,changed:!0}))},this.handleDeleteImage=(e,t,a,n)=>{const i={...this.state.target};if("Yes"===i.cropSpecific&&i.observableOn[t].stages[a].images){const e=i.observableOn[t].stages[a].images.findIndex(e=>e.Key===n);-1!==e&&(i.observableOn[t].stages[a].images.splice(e,1),this.setState({target:i,changed:!0}))}else if(i.nonCropDetail.images){const e=i.nonCropDetail.images.findIndex(e=>e.Key===n);-1!==e&&(i.target.nonCropDetail.images.splice(e,1),this.setState({target:i,changed:!0}))}},this.handleVariableTChange=(e,t,a,n,i)=>{const r={...this.state.target};r.cropSpecific?(r.observableOn[t].stages[a].variableThreshold||(r.observableOn[t].stages[a].variableThreshold={}),r.observableOn[t].stages[a].variableThreshold[n]||(r.observableOn[t].stages[a].variableThreshold[n]={}),r.observableOn[t].stages[a].variableThreshold[n][i]||(r.observableOn[t].stages[a].variableThreshold[n][i]={}),r.observableOn[t].stages[a].variableThreshold[n][i]=e.target.value):(r.nonCropDetail.variableThreshold||(r.nonCropDetail.variableThreshold={}),r.nonCropDetail.variableThreshold[n]||(r.nonCropDetail.variableThreshold[n]={}),r.nonCropDetail.variableThreshold[n][i]||(r.nonCropDetail.variableThreshold[n][i]={}),r.nonCropDetail.variableThreshold[n][i]=e.target.value),this.setState({target:r,changed:!0})},this.handleRadioChange=(e,t,a,n)=>{const i={...this.state.target};"Yes"===i.cropSpecific?i.observableOn[t].stages[a][n]=e.target.value:i.nonCropDetail[n]=e.target.value,this.setState({target:i,changed:!0})},this.handleToggle=(e,t,a)=>{const n=this.state.target.observableOn.findIndex(t=>t.sk===e),i={...this.state.target},{crops:r}=this.props.data;if(-1===n){const t=r&&r.find(t=>t.sk===e);t.stages=[{sk:Rt.a.v1()}],i.observableOn.push(t)}else i.observableOn.splice(n,1);this.setState({target:i,changed:!0})},this.getFilteredCrops=(e,t)=>{if(!e)return t.crops?t.crops:[];if(!t.crops)return[];if(!e.observableOn)return t.crops;let a=[];return a=t.crops.filter(t=>!e.observableOn.find(e=>e.sk===t.sk)),a},this.fileUploaded=async(e,t,a,n)=>{const{getFromGlobalState:i,setSnack:r}=this.props,l=i("activeSite");try{if(!e.serverId)return void console.log("received undefined key");const n=e.serverId,i={};i.sk="init_"+n,i.lastModified=e.file.lastModified,i.Key=n,i.lastModifiedDate=e.file.lastModifiedDate?e.file.lastModifiedDate:new Date(e.file.lastModified),i.fileExtension=e.fileExtension,i.filename=e.filename,i.filenameWithoutExtension=e.filenameWithoutExtension,i.fileSize=e.fileSize,i.fileType=e.fileType,i.createdAt=(new Date).valueOf(),i.version=1,i.type="files";const r={...this.state.target},s={...this.state.imageUrls};if("Yes"===r.cropSpecific){r.observableOn[t].stages||(r.observableOn[t].stages=[]),r.observableOn[t].stages[a].images||(r.observableOn[t].stages[a].images=[]);const e=r.observableOn[t].stages[a].images.findIndex(e=>e.Key===i.Key);-1===e?r.observableOn[t].stages[a].images.push(i):r.observableOn[t].stages[a].images[e]=i}else{r.nonCropDetail.images||(r.nonCropDetail.images=[]);const e=r.nonCropDetail.images.findIndex(e=>e.Key===i.Key);-1===e?r.nonCropDetail.images.push(i):r.nonCropDetail.images[e]=i}const o={activeTenant:l,type:"files",setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",path:i.Key,contentType:i.fileType,isGeneral:!0};s[i.Key]=await Fa(o),console.log("imageURLS",JSON.stringify(s)),this.setState({target:r,imageUrls:s,changed:!0})}catch(s){console.log("Error from dialog",s),r({open:!0,variant:"error",messageText:Pa(s)})}},this.handleDelete=e=>{const t={...this.state.target},a=t&&t.observableOn.findIndex(t=>t.sk===e);-1!==a&&t.observableOn.splice(a,1),this.setState({target:t,changed:!0})},this.renderNonCropSpecific=e=>{const{classes:t,target:a,isOther:n,errors:r,imageUrls:l,getFromGlobalState:s}=e;return a.nonCropDetail||(a.nonCropDetail={}),i.a.createElement(xs,{classes:t,stage:a.nonCropDetail,disableElevation:n,errors:r,getFromGlobalState:s,cropSpecific:"Yes"===a.cropSpecific,targetType:a.targetType,handleRadioChange:this.handleRadioChange,handleArrayChange:this.handleArrayChange,handleBlur:this.handleBlur,handleDeleteImage:this.handleDeleteImage,fileUploaded:this.fileUploaded,handleVariableTChange:this.handleVariableTChange,imageUrls:l,isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3"})},this.renderCropSpecific=e=>{const{errors:t,selectedCropType:a,onCropTypeChange:n,data:r,classes:l,target:s,filteredCrops:o,loading:c,expnandedObservable:d,isOther:m,getFromGlobalState:p,imageUrls:h,isLoading:u}=e;return i.a.createElement(i.a.Fragment,null,i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,null,"Observable on")),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:l.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Crop Type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:a,onChange:n,inputProps:{name:"cropType",id:"cropType"}},i.a.createElement("option",{value:""}),r&&r.cropTypes&&r.cropTypes.filter(e=>e.enabled).map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:l.formControl},i.a.createElement(B.a,null,"Available crops"),i.a.createElement(Ks,{data:o,onBlur:this.handleBlur,checkedItems:s.observableOn,handleToggle:this.handleToggle,loading:c,hideCheck:!0,childCollectionMember:"cropsSetting"}),i.a.createElement(En.a,{className:l.helperText},t.observableOn),t.observableOn&&i.a.createElement(En.a,{className:l.helperText},t.observableOn))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},s&&s.observableOn.map((e,a)=>i.a.createElement(cr,{heading:e.name,expanded:d,action:i.a.createElement(E.a,{onClick:e=>this.handleDeleteObservable(e,a)},i.a.createElement(ei.a,{color:"secondary"})),handleExpand:t=>this.handleSettingExpand(e.name,e)},i.a.createElement("div",{style:{width:"100%"}},e.stages&&e.stages.map((n,r)=>i.a.createElement(xs,{classes:l,stage:n,cropSpecific:"Yes"===s.cropSpecific,disableElevation:m,errors:t,getFromGlobalState:p,obsIdx:a,stageIdx:r,targetType:s.targetType,handleDeleteStage:this.handleDeleteStage,handleRadioChange:this.handleRadioChange,handleArrayChange:this.handleArrayChange,handleBlur:this.handleBlur,handleDeleteImage:this.handleDeleteImage,fileUploaded:this.fileUploaded,handleVariableTChange:this.handleVariableTChange,imageUrls:h,isGeneral:!0,isLoading:u,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",selectedCropType:e.sk})),!m&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement("div",{style:{width:"100%",float:"right",marginLeft:"auto"}},i.a.createElement(I.a,{title:"Add Stage"},i.a.createElement(Te.a,{variant:"extended",size:"medium",color:"primary","aria-label":"add",className:l.margin,onClick:e=>this.handleAddStage(a)},i.a.createElement(C.a,{className:l.extendedIcon}),"Stage")))))))))},this.getNonCropSpecificUrls=async(e,t)=>{const{getFromGlobalState:a}=this.props,n=a("activeSite"),i={...t};if(e.nonCropDetail&&e.nonCropDetail.images)for(const r of e.nonCropDetail.images)if(!i[r.Key]){const e={activeTenant:n,type:"files",setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",path:r.Key,contentType:r.fileType,isGeneral:!0,collectionName:"targets/pests"};i[r.Key]=await Fa(e)}return i},this.getUrls=async(e,t)=>{if(!e)return null;const{getFromGlobalState:a}=this.props,n=a("activeSite"),i={...t};for(const r of e)if(r.images)for(const e of r.images)if(!i[e.Key]){const t={activeTenant:n,type:"files",setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",path:e.Key,contentType:e.fileType,isGeneral:!0,collectionName:"targets/pests"};i[e.Key]=await Fa(t)}return i},this.handleAddStage=e=>{const t={...this.state.target};t.observableOn[e].stages.push({sk:Rt.a.v1()}),this.setState({target:t})},this.state={isloading:!1,isNew:this.props.isNew,target:this.props.target,errors:{count:0},changed:!1,imageUrl:null,imageUrls:{},isLoading:!1,expnandedObservable:null}}async componentDidMount(){const{targetType:e,target:t,isNew:a}=this.props;if(a)this.setState({target:{observableOn:[],targetType:e,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",isGeneral:!0,imageID:Rt.a.v1()}});else if(t.cropSpecific&&!t.observableOn&&(t.observableOn=[]),"No"===t.cropSpecific){const{imageUrls:e}=this.state,a=await this.getNonCropSpecificUrls(t,e);this.setState({target:t,imageUrls:a})}}validateField(e,t){const a=jn(e,this.state.target,t),n={...this.state.errors};n[e]=a.msg,this.setState({errors:n})}render(){const{classes:e,open:t,isNew:a,setClose:n,handleUpdate:r,data:l,getFromGlobalState:s,targetType:o,onCropTypeChange:c,selectedCropType:d,loading:m}=this.props,{target:p,errors:h,expnandedObservable:u,imageUrls:b,isLoading:v}=this.state,y=($n(p,jv),this.getFilteredCrops(p,l)),f=s("targetsTypesSetting"),E=o?f.find(e=>e.sk===o):null,S="Other"===(E?E.name:"");return p?i.a.createElement(Ia,{open:t,dialogObject:p,setClose:n,isNew:a,handleUpdateDialogObject:r.bind(this),skPrimary:"_setchild_",dynamoType:"targetDetail",valid:!0,parentKey:o,changed:this.state.changed,newTitle:"New Target",title:p.name,getFromGlobalState:s},i.a.createElement(g.a,{container:!0,className:e.root2,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",value:p.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.name||void 0,helperText:h.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"labelName",label:"Label Name",name:"labelName",value:p.labelName,onChange:this.handleChange,onBlur:this.handleBlur,error:!!h.labelName||void 0,helperText:h.labelName})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{component:"fieldset",className:e.formControlRadio},i.a.createElement(kn.a,{required:!0},"Crop Specific"),i.a.createElement(xn.a,{"aria-label":"threshold",name:"cropSpecific",id:"cropSpecific",className:e.group,value:p.cropSpecific,onChange:this.handleChange},i.a.createElement(Fe.a,{value:"Yes",control:i.a.createElement(Cn.a,{id:"cropSpecific"}),label:"Yes"}),i.a.createElement(Fe.a,{value:"No",control:i.a.createElement(Cn.a,{id:"cropSpecific"}),label:"No"}),h.cropSpecific&&i.a.createElement(En.a,{className:e.helperText},h.cropSpecific)))),p.cropSpecific&&"Yes"===p.cropSpecific&&this.renderCropSpecific({errors:h,selectedCropType:d,onCropTypeChange:c,data:l,classes:e,target:p,filteredCrops:y,loading:m,expnandedObservable:u,isOther:S,getFromGlobalState:s,imageUrls:b,isLoading:v}),p.cropSpecific&&"No"===p.cropSpecific&&this.renderNonCropSpecific({classes:e,target:p,isOther:S,errors:h,imageUrls:b,getFromGlobalState:s}))):null}}var Yv=Object(v.a)(e=>({imageList:{flexWrap:"nowrap",transform:"translateZ(0)"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},margin:{margin:e.spacing(1)},extendedIcon:{marginRight:e.spacing(1)},helperText:{color:"red"},group:{flexDirection:"row"},formControlRadio:{marginTop:e.spacing(2)}}),{withTheme:!0})($v);class _v extends n.Component{constructor(e){super(e),this.onRowDelete=async(e,t)=>{const{getFromGlobalState:a,setSnack:n,setAdminState:i,getAdminState:r}=this.props,l={...r("targetsDetail")};try{const e={...t};e.activeTenant=a("activeSite"),this.setState({loadingTargets:!0});const r=this.getHeader();if(!(await ka(e)).status)return n({open:!0,variant:"error",messageText:"failed to delete - please refresh"}),!1;const s=l[e.targetType].findIndex(t=>t.sk===e.sk);return-1===s?(n({open:!0,variant:"error",messageText:"row not found in local cache - please refresh"}),!1):(l[e.targetType].splice(s,1),i({targetsDetail:l}),this.setState({loadingTargets:!1,columns:r}),!0)}catch(s){return n({open:!0,variant:"error",messageText:Pa(s)}),!1}},this.onRowAdd=()=>{this.setState({isNew:!0,targetsDialogOpen:!0})},this.onHandleUpdate=e=>{const{getAdminState:t,setAdminState:a}=this.props,n={...t("targetsDetail")},i=this.getHeader(),r=n[e.targetType].findIndex(t=>t.sk===e.sk);-1===r?n[e.targetType].push(e):n[e.targetType][r]=e,a({targetsDetail:n}),this.setState({columns:i})},this.onRowEdit=(e,t)=>{const{rows:a}=this.props,n=a.find(e=>e.sk===t.sk);this.setState({isNew:!1,targetsDialogOpen:!0,selectedTarget:n})},this.setClose=()=>{this.setState({isNew:!1,targetsDialogOpen:!1})},this.onRowAdd2=async e=>{const{getFromGlobalState:t,setSnack:a}=this.props,{cropsDetail:n}=this.state;try{const a={...e};a.setId="a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",a.sk=e.cropName.concat("_setChild_").concat(Rt.a.v1()),a.isGeneral=!0,a.type="cropsDetail",a.version=1,a.activeTenant=t("activeSite");const i=await ya(t("currentUser").username,"calls",ua(a),a.activeTenant);i.status&&(a.cached=i.cached);const r=[...n];return r.push(a),this.setState({cropsDetail:r}),!0}catch(i){return a({open:!0,variant:"error",messageText:Pa(i)}),!1}},this.onTargetTypeChange=async e=>{let{selectedTargetsType:t,targetsDetail:a}=this.state;const{getTargetDetails:n}=this.props;if(t===e.target.value)return!0;t=e.target.value,this.setState({selectedTargetsType:t,loadingTargets:!0});const i=await n(t);if(i&&i.targetsDetail&&i.targetsDetail.length){let e=[...a];e=i.targetsDetail,this.setState({targetsDetail:e,selectedTargetsType:t})}this.setState({loadingTargets:!1})},this.onCropTypeChange=async e=>{let{selectedCropType:t,crops:a}=this.state;const{getCropDetails:n}=this.props;if(t===e.target.value)return!0;t=e.target.value,this.setState({selectedCropType:t,crops:[],loadingCrops:!0});const i=await n(t);if(i&&i.crops&&i.crops.length){let e=[...a];e=i.crops,this.setState({crops:e,loadingCrops:!1})}},this.getTargetUrl=async(e,t)=>{const a={activeTenant:this.props.getFromGlobalState("activeSite"),type:"files",path:e,contentType:t},n=await Fa(a);return i.a.createElement("img",{src:n,style:{width:50,borderRadius:"50%"}})},this.stringifyTargets=e=>{let t="";return e.forEach((a,n)=>{t=t.concat(a.name),n!==e.length-1&&(t=t.concat(", "))}),t},this.getHeader=()=>[{title:"Target name",field:"name",validate:e=>""===e.name?"Crop name cannot be empty":""},{title:"Observable On",field:"observableOnString",render:e=>e&&e.observableOn&&this.stringifyTargets(e.observableOn)}],this.state={isloading:!1,selectedTargetsType:"",isNew:!1,targetsDialogOpen:!1,selectedTarget:null,cropsDetail:[],selectedCropType:null,crops:[],columns:[],loadingCrops:!1,targetsDetail:[],loadingTargets:!1}}componentDidMount(){const{isAuthenticated:e,getFromGlobalState:t}=this.props;if(!e)return;let a=t("activeSite");""!==a&&a||(a="default");const n=this.getHeader();this.setState({columns:n})}render(){const{classes:e,data:t,getFromGlobalState:a,onTargetTypeChange:n,rows:r,selectedTargetsType:l,setGlobalState:s,setSnack:o}=this.props,c=a("targetsTypesSetting"),{crops:d,loadingTargets:m,loadingCrops:p,selectedTarget:h,isloading:g,columns:u,targetsDialogOpen:b,isNew:v}=this.state,y=l?[{icon:()=>i.a.createElement(xv.a,null),tooltip:"Add Row",isFreeAction:!0,onClick:(e,t)=>{this.onRowAdd(e,t)}},{icon:()=>i.a.createElement(A.a,null),tooltip:"Edit Target",onClick:(e,t)=>{this.onRowEdit(e,t)}},{icon:()=>i.a.createElement(ei.a,null),tooltip:"Delete Target",onClick:(e,t)=>{this.onRowDelete(e,t)}}]:void 0;return i.a.createElement(N,{isloading:g},i.a.createElement(O.a,{elevation:0,style:{marginLeft:"4px"},className:e.paper},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"cropType"},"Target Type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:l,onChange:n,inputProps:{name:"cropType",id:"cropType"}},i.a.createElement("option",{value:""}),c&&c.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name))))),i.a.createElement(Hv,{headCells:u,title:"",rows:r&&r.length?r:[],isLoading:m,actions:y}),b&&i.a.createElement(Yv,{isNew:v,handleUpdate:this.onHandleUpdate,setClose:this.setClose,open:b,target:h,loading:p,targetType:l,data:{crops:d,cropTypes:t.cropTypes},onCropTypeChange:this.onCropTypeChange,getFromGlobalState:a,setGlobalState:s,setSnack:o})))}}var Zv=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"},paper:{marginLeft:"4px",marginTop:"10px"},formControl:{minWidth:120,marginTop:e.spacing(2),marginLeft:"4px"}}))(_v),Jv=a(444),Qv=a.n(Jv);const Xv=[{id:"isDisabled",numeric:!1,disablePadding:!1,label:"Disabled",maxWidth:"80px"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"supplier",numeric:!1,disablePadding:!1,label:"Supplier"},{id:"unit",numeric:!1,disablePadding:!1,label:"Unit"},{id:"price",numeric:!1,disablePadding:!1,label:"Unit Price"},{id:"description",numeric:!1,disablePadding:!1,label:"Description"}],ey=[{id:"name",combine:[{id:"unit",opacity:1},{id:"supplier",opacity:.6}],numeric:!1,disablePadding:!0,label:"Name",maxWidth:"100px"},{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"}],ty={nitrogenP:"N",phosphorusP:"P",potassiumP:"K",caP:"Ca",mgP:"Mg",sP:"S",bP:"B",feP:"Fe",mnP:"Mn",znP:"Zn",cuP:"Cu",moP:"Mo"};class ay extends n.Component{constructor(e){super(e),this.handleClickShowFertiliser=(e,t,a)=>{const{fertilisers:n}=this.props,i=n.find(e=>e.sk===a);i&&this.setState({selectedFertiliser:i,fertiliserDialogOpen:!0})},this.validateFile=e=>{const{setSnack:t}=this.props,a=e.map(e=>e.name),n=a.filter((e,t)=>a.indexOf(e)!==t);return!n.length||(t({open:!0,variant:"error",messageText:"The following fertilisers are duplicated: "+n.join(", ")}),!1)},this.loadFertiliser=async e=>{const{getFromGlobalState:t,getAdminState:a}=this.props,{setSnack:n}=this.props;this.setState({isloading:!0});const i=a("genFertilisers"),r=e.map(e=>{const t=e,a=i.findIndex(t=>t.name===e.name);if(-1===a){const e="init_";t.sk=e.concat(Rt.a.v1()),t.version=1}else t.version=i[a].version+1,t.sk=i[a].sk;return t.type="genFertilisers",t.setId="a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",t.isGeneral=!0,t.isDisabled=!1,t.unit=(null===e||void 0===e?void 0:e.unit)&&"granular"===(null===e||void 0===e?void 0:e.unit)?"kg":"liter",Object.keys(ty).forEach(e=>{if(t[e]){t[e]=parseFloat(t[e]);const a=e.replace("P","G");t[a]=1e3*t[e]/100}}),t});try{n({open:!0,variant:"info",messageText:`Uploading ${r.length} fertilisers.`});const e={items:r};e.activeTenant=t("activeSite"),e.type="batchupload";if((await fa(t("currentUser").username,"calls",ua(e,!0),t("activeSite"))).status){for(let e=0;e{const{setSnack:t,getFromGlobalState:a}=this.props,n={activeTenant:a("activeSite"),type:"files",path:e.Key,contentType:"application/octet-stream"};try{const e=await Fa(n),t=await Ca(e),a=await t.blob(),i=new FileReader;i.onload=async e=>{const t=re(e.target.result);this.validateFile(t)&&await this.loadFertiliser(t)},i.readAsText(a)}catch(i){t({open:!0,variant:"error",messageText:Pa(i)})}},this.getFertiliserRows=e=>{if(!e||!e.length)return[];return e.map(e=>{const t={...e};return t.isDisabled=t.isDisabled?"Yes":"No",t.description="",Object.keys(ty).forEach(e=>{t.description+=`${ty[e]}:${t[e]} `}),t})},this.handleSelectFile=async e=>{const{value:t}=e.target,{getFromGlobalState:a}=this.props,n=a("files").find(e=>e.sk===t);this.setState({selectedFile:n})},this.handleUploadFile=async()=>{const{selectedFile:e}=this.state;this.setState({isloading:!0}),await this.handleParseAndLoad(e),this.setState({isloading:!1})},this.setClose=this.setClose.bind(this),this.handleUpdate=this.handleUpdate.bind(this),this.handleClickShowFertiliser=this.handleClickShowFertiliser.bind(this),this.handleClickAdd=this.handleClickAdd.bind(this),this.handleSelectFile=this.handleSelectFile.bind(this),this.state={isloading:!1,selectedFile:null,fertiliserDialogOpen:!1,isNew:!1}}async componentDidMount(){const{isAuthenticated:e,getFertiliserDetails:t}=this.props;e&&(this.setState({isloading:!0}),await t(),this.setState({isloading:!1}))}handleClickAdd(){this.setState({fertiliserDialogOpen:!0,isNew:!0,selectedFertiliser:{isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",nitrogenP:0,phosphorusP:0,potassiumP:0,caP:0,mgP:0,sP:0,bP:0,feP:0,mnP:0,znP:0,cuP:0,moP:0,nitrogenG:0,phosphorusG:0,potassiumG:0,caG:0,mgG:0,sG:0,bG:0,feG:0,mnG:0,znG:0,cuG:0,moG:0}})}handleUpdate(e){const{getAdminState:t,setAdminState:a}=this.props,n=t("genFertilisers"),i=n.findIndex(t=>t.sk===e.sk),r=[...n];-1===i?r.push(e):r[i]=e,a({genFertilisers:r})}setClose(){this.setState({fertiliserDialogOpen:!1,isNew:!1})}render(){const{classes:e,getFromGlobalState:t,fertilisers:a,isMobile:n}=this.props,{isloading:r,selectedFile:l,fertiliserDialogOpen:s,selectedFertiliser:o,isNew:c}=this.state,d=t("files"),m=this.getFertiliserRows(a),p=d.filter(e=>e.Key.includes("Settings/Fertilisers"));return i.a.createElement(O.a,{elevation:0,className:e.paper},s&&i.a.createElement(ns,{handleUpdate:this.handleUpdate,open:s,setClose:this.setClose,isNew:c,getFromGlobalState:t,fertiliser:o,dynamoType:"genFertilisers",fertilisers:m}),i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,null,"Select file to upload"),i.a.createElement(Sn.a,{native:!0,required:!0,value:l&&l.sk,onChange:this.handleSelectFile,inputProps:{name:"selectedFile",id:"selectedFile"}},i.a.createElement("option",{key:"",value:""}),p&&p.map(e=>i.a.createElement("option",{key:e.sk,value:e.sk},e.filename)))),i.a.createElement(I.a,{title:"Upload"},i.a.createElement(Te.a,{variant:"extended",disabled:!l||r,size:"medium",color:"primary","aria-label":"add",className:e.margin,onClick:this.handleUploadFile},i.a.createElement(Qv.a,{className:e.extendedIcon}),"Upload")),i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(N,{isloading:r},i.a.createElement(bn.a,null,(m&&m.length)+" fertilisers "),i.a.createElement(Me,{heading:"Fertilisers",displayToolbar:!0,hideHeading:!0,id:"fertilisersTable",noPagination:!0,rows:m,headCells:n?ey:Xv,handleSelect:this.handleClickShowFertiliser,handleAddItem:this.handleClickAdd,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0,dense:!0,maxHeight:"350px",selectedRow:o?o.sk:""}))))}}var ny=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"},paper:{margin:e.spacing(1)},formControl:{minWidth:120,marginTop:e.spacing(2),marginLeft:"4px"},mainSection:{width:"100%",flexWrap:"wrap"},margin:{margin:e.spacing(1)},extendedIcon:{paddingRight:e.spacing(1)},submit:{margin:e.spacing(1)}}))(ay);const iy=[{id:"isDisabled",numeric:!1,disablePadding:!1,label:"Disabled",maxWidth:"80px"},{id:"name",numeric:!1,disablePadding:!1,label:"Name"},{id:"registrationNumber",numeric:!1,disablePadding:!1,label:"Reg Num"},{id:"registrationHolder",numeric:!1,disablePadding:!1,label:"Reg Holder"},{id:"aIngredient",numeric:!1,disablePadding:!1,label:"Active Ingredient",minWidth:"200px"}],ry=["name","registrationNumber","registrationHolder","aIngredient"],ly=[{id:"name",combine:[{id:"registrationNumber",opacity:1},{id:"registrationHolder",opacity:.6}],numeric:!1,disablePadding:!0,label:"Name",maxWidth:"100px"},{id:"isDisabled",numeric:!1,disablePadding:!0,label:"Disabled"}];class sy extends n.Component{constructor(e){super(e),this.handleClickShowPPP=(e,t,a)=>{const{ppps:n}=this.props,i=n.find(e=>e.sk===a);i&&this.setState({selectedPPP:i,pppDialogOpen:!0})},this.validateFile=e=>{const{setSnack:t}=this.props;if(e.filter(e=>ry.some(t=>!e[t])).length)return t({open:!0,variant:"error",messageText:"The PPPs are missing required columns: 'name', 'registrationNumber', 'registrationHolder', 'aIngredient'"}),!1;const a=e.map(e=>e.name),n=a.filter((e,t)=>a.indexOf(e.trim())!==t);return!n.length||(t({open:!0,variant:"error",messageText:`The following PPPs are duplicated: ${n.join(", ")}. Please remove them and upload again.`}),!1)},this.loadPPP=async e=>{const{getFromGlobalState:t,getAdminState:a}=this.props,{setSnack:n}=this.props;this.setState({isloading:!0});const i=a("genPPPs"),r=e.map(e=>{const t=e,a=i.findIndex(t=>t.name===e.name);if(-1===a){const e="init_";t.sk=e.concat(Rt.a.v1()),t.version=1}else t.version=i[a].version+1,t.sk=i[a].sk;return t.type="genPPPs",t.setId="a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",t.isGeneral=!0,t.isDisabled=!1,t.name=e.name.trim(),t.registrationNumber=e.registrationNumber.trim(),t.registrationHolder=e.registrationHolder.trim(),t.aIngredient=e.aIngredient.trim(),t});try{n({open:!0,variant:"info",messageText:`Uploading ${r.length} PPPs.`});const e={items:r};e.activeTenant=t("activeSite"),e.type="batchupload";if((await fa(t("currentUser").username,"calls",ua(e,!0),t("activeSite"))).status){for(let e=0;e{const{setSnack:t,getFromGlobalState:a}=this.props,n={activeTenant:a("activeSite"),type:"files",path:e.Key,contentType:"application/octet-stream"};try{const e=await Fa(n),t=await Ca(e),a=await t.blob(),i=new FileReader;i.onload=async e=>{const t=function(e){if(!e)return null;const t=e,a=t&&t.slice(0,t.indexOf("\n")),n=a&&-1!==a.indexOf(",")?",":";",i=/;(?=(?:[^"]*"[^"]*")*[^"]*$)/,r=t.slice(0,t.indexOf("\n")).split(n);return t.slice(t.indexOf("\n")+1).split("\n").map(e=>{const t=e.split(i);return r.reduce((e,a,n)=>{let i=t[n]?t[n].trim().replace("\r",""):"";return/^["\u201c]/.test(i)&&/["\u201c]$/.test(i)&&(i=i.slice(1,-1).replace(/""/g,'"')),e[a.replace("\r","")]=i,e},{})})}(e.target.result);this.validateFile(t)&&await this.loadPPP(t)},i.readAsText(a)}catch(i){t({open:!0,variant:"error",messageText:Pa(i)})}},this.getPPPRows=e=>{if(!e||!e.length)return[];return e.map(e=>{const t={...e};return t.isDisabled=t.isDisabled?"Yes":"No",t})},this.handleSelectFile=async e=>{const{value:t}=e.target,{getFromGlobalState:a}=this.props,n=a("files").find(e=>e.sk===t);this.setState({selectedFile:n})},this.handleUploadFile=async()=>{const{selectedFile:e}=this.state;this.setState({isloading:!0}),await this.handleParseAndLoad(e),this.setState({isloading:!1})},this.setClose=this.setClose.bind(this),this.handleUpdate=this.handleUpdate.bind(this),this.handleClickShowPPP=this.handleClickShowPPP.bind(this),this.handleClickAdd=this.handleClickAdd.bind(this),this.handleSelectFile=this.handleSelectFile.bind(this),this.state={isloading:!1,selectedFile:null,pppDialogOpen:!1,isNew:!1,selectedPPP:null}}async componentDidMount(){const{isAuthenticated:e,getPPPDetails:t}=this.props;e&&(this.setState({isloading:!0}),await t(),this.setState({isloading:!1}))}handleClickAdd(){this.setState({isNew:!0,selectedPPP:{isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3",isDisabled:!1,type:"genPPPs"}})}handleUpdate(e){const{getAdminState:t,setAdminState:a}=this.props,n=t("genPPPs"),i=n.findIndex(t=>t.sk===e.sk),r=[...n];-1===i?r.push(e):r[i]=e,a({genPPPs:r})}setClose(){this.setState({pppDialogOpen:!1,isNew:!1})}render(){const{classes:e,getFromGlobalState:t,ppps:a,isMobile:n}=this.props,{isloading:r,selectedFile:l,pppDialogOpen:s,selectedPPP:o,isNew:c}=this.state,d=t("files"),m=t("userDetail"),p=this.getPPPRows(a),h=d.filter(e=>e.Key.includes("Settings/Plant protection products"));return i.a.createElement(O.a,{elevation:0,className:e.paper},s&&i.a.createElement(Hl,{handleUpdate:this.handleUpdate,open:s,setClose:this.setClose,isNew:c,getFromGlobalState:t,chemical:o,dynamoType:"genPPPs",ppps:p}),i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,null,"Select file to upload"),i.a.createElement(Sn.a,{native:!0,required:!0,value:l&&l.sk,onChange:this.handleSelectFile,inputProps:{name:"selectedFile",id:"selectedFile"}},i.a.createElement("option",{key:"",value:""}),h&&h.map(e=>i.a.createElement("option",{key:e.sk,value:e.sk},e.filename)))),i.a.createElement(I.a,{title:"Upload"},i.a.createElement(Te.a,{variant:"extended",disabled:!l||r,size:"medium",color:"primary","aria-label":"add",className:e.margin,onClick:this.handleUploadFile},i.a.createElement(Qv.a,{className:e.extendedIcon}),"Upload")),i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(N,{isloading:r},i.a.createElement(bn.a,null,(p&&p.length)+" PPPs "),i.a.createElement(Me,{heading:"PPPs",displayToolbar:!0,hideHeading:!0,id:"pppTable",noPagination:!0,rows:p,headCells:n?ly:iy,handleSelect:this.handleClickShowPPP,handleAddItem:m&&m.rights&&!m.rights.readOnly?this.handleClickAdd:null,actionType:"actionType",rowKeyName:"sk",disablePadFirstCol:!0,clean:!0,dense:!0,maxHeight:"350px",selectedRow:o?o.sk:""}))))}}var oy=Object(v.a)(e=>({root:{flexGrow:1,marginTop:"5px",backgroundColor:"inherit"},paper:{margin:e.spacing(1)},formControl:{minWidth:120,marginTop:e.spacing(2),marginLeft:"4px"},mainSection:{width:"100%",flexWrap:"wrap"},margin:{margin:e.spacing(1)},extendedIcon:{paddingRight:e.spacing(1)},submit:{margin:e.spacing(1)}}))(sy),cy=a(785);const dy=Object(z.a)(e=>({root:{display:"flex",justifyContent:"center",flexWrap:"wrap",listStyle:"none",padding:e.spacing(.5),margin:0},chip:{margin:e.spacing(.5)}}));function my(e){const{chipData:t,handleDelete:a}=e,n=dy();return t?i.a.createElement(O.a,{component:"ul",elevation:0,className:n.root},t.map(e=>i.a.createElement("li",{key:e},i.a.createElement(cy.a,{color:"primary",label:e.name,variant:"outlined",onDelete:a.bind(this,e.sk),className:n.chip})))):null}const py=[{name:"name",min:1,max:200},{name:"productProcessorType",min:1,max:200},{name:"country",min:1,max:100},{name:"province",min:1,max:100}];class hy extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,py),this.handleChange=e=>{const{productProcessor:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({productProcessor:a,changed:!0})},this.handleCropTypeChange=async e=>{const{getFromGlobalState:t}=this.props,{productProcessor:a}=this.state,n=e.target.value,i=t("cropsSetting"),r={};r[n]=i.filter(e=>e.sk.startsWith(n)),a.processingCrops&&a.processingCrops[n]&&(r[n]=r[n].filter(e=>!a.processingCrops[n].includes(e.sk))),this.setState({selectedCropType:n,changed:!0,localGenCrops:r})},this.handleToggle=e=>{const t=e.substring(0,e.indexOf("_setchild_")),{productProcessor:a,localGenCrops:n}=this.state,{getFromGlobalState:i}=this.props,r={...a},l={...n};r.processingCrops||(r.processingCrops={}),r.processingCrops[t]||(r.processingCrops[t]=[]);const s=r.processingCrops[t].findIndex(t=>t===e);if(-1===s){r.processingCrops[t].push(e);const a=l[t].length?l[t].findIndex(t=>t.sk===e):-1;-1!==a&&l[t].splice(a,1)}else{r.processingCrops[t].splice(s,1),0===r.processingCrops[t].length&&delete r.processingCrops[t],0===Object.keys(r.processingCrops).length&&(r.processingCrops=null);if(-1===(l[t]&&l[t].length?l[t].findIndex(t=>t.sk===e):-1)){const a=i("cropsSetting").find(t=>t.sk===e);l[t]||(l[t]=[]),l[t].push(a)}}this.setState({productProcessor:r,localGenCrops:l,changed:!0})},this.handleCheckChange=e=>{const{productProcessor:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({productProcessor:a,changed:!0})},this.handleCountryChange=e=>{const{productProcessor:t}=this.state,a={...t};a.country!==e.target.value&&a.province&&(a.province=""),a[e.target.id]=e.target.value;const n=V.filter(t=>t.countryName===e.target.value),i=n.length>0?n[0].regions:[];this.setState({productProcessor:a,changed:!0,regions:i})};const{handleUpdate:t}=this.props;this.handleUpdate=t.bind(this),this.state={productProcessor:{},errors:{count:0},changed:!1,regions:[],processedCrops:[],selectedCropType:"",localGenCrops:{}}}async componentDidMount(){const{isNew:e,selectedSetting:t}=this.props;if(e)this.setState({productProcessor:{enabled:!0,isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3"}});else{const e=t;if(e.country){const t=V.filter(t=>t.countryName===e.country),a=t.length>0?t[0].regions:[];this.setState({productProcessor:e,regions:a})}else this.setState({productProcessor:e})}}validateField(e){const{productProcessor:t,errors:a}=this.state,n=jn(e,t,py),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,isNew:a,setClose:n,metaData:r,getFromGlobalState:l}=this.props,{productProcessor:s,errors:o,changed:c,regions:d,selectedCropType:m,localGenCrops:p}=this.state,h=$n(s,py),u=a?r&&r.filter(e=>e.enabled):r,b=l("cropTypesSetting").filter(e=>e.enabled);return i.a.createElement(Ia,{open:t,dialogObject:s,setClose:n,isNew:a,handleUpdateDialogObject:this.handleUpdate,skPrimary:"_setchild_",dynamoType:"productProcessors",valid:h,changed:c,newTitle:"New Pocessor",parentKey:s.productProcessorType,title:s.name,getFromGlobalState:l},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:s.enabled,id:"enabled",onChange:this.handleCheckChange,value:"enabled",color:"secondary"}),label:"Enabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Processor Type"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:s.productProcessorType,onChange:this.handleChange,onBlur:this.handleBlur,inputProps:{name:"productProcessorType",id:"productProcessorType"}},i.a.createElement("option",{value:""}),u&&u.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),o.productProcessorType&&i.a.createElement(En.a,{className:e.helperText},o.productProcessorType))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"country"},"Country"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,margin:"normal",required:!0,displayEmpty:!0,value:s.country,onChange:this.handleCountryChange,onBlur:this.handleBlur,error:!!o.country||void 0,inputProps:{name:"country",id:"country"}},i.a.createElement("option",{"aria-label":"empty",value:""}),V&&V.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.countryName},e.countryName)))),o.country&&i.a.createElement(En.a,{className:e.helperText},o.country))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{fullWidth:!0,className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"Province"},"Province"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,margin:"normal",value:s.province,disabled:!s.province&&d.length<1,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.province||void 0,inputProps:{name:"province",id:"province"}},i.a.createElement("option",{"aria-label":"empty",value:""}),d&&d.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.name},e.name)))),o.province&&i.a.createElement(En.a,{className:e.helperText},o.province))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",value:s.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.name||void 0,helperText:o.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(bn.a,{shrink:!0,htmlFor:"unitNum"},"Crop Types"),i.a.createElement(Sn.a,{native:!0,fullWidth:!0,required:!0,displayEmpty:!0,value:m,onChange:this.handleCropTypeChange,onBlur:this.handleBlur,inputProps:{name:"cropTypes",id:"cropTypes"}},i.a.createElement("option",{value:""}),b&&b.map(e=>i.a.createElement(i.a.Fragment,null,i.a.createElement("option",{value:e.sk},e.name)))),o.productProcessorType&&i.a.createElement(En.a,{className:e.helperText},o.productProcessorType))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(B.a,null,"Available Crops"),i.a.createElement(Ks,{data:p[m],hideCheck:!0,checkedItems:s.processingCrops?s.processingCrops[m]:[],handleToggle:this.handleToggle,arrayName:"processedCrops"}))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:6,lg:6,xl:6},i.a.createElement(B.a,null,"Slected Crops"),s.processingCrops&&Object.keys(s.processingCrops).map(t=>i.a.createElement(i.a.Fragment,null,s.processingCrops[t].length>0&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(vn.a,{className:e.formControl},i.a.createElement(B.a,null,b.find(e=>e.sk===t).name),i.a.createElement(my,{onBlur:this.handleBlur,name:t,id:t,chipData:s.processingCrops&&s.processingCrops[t]?s.processingCrops[t].map(e=>{const t={};t.sk=e;const a=l("cropsSetting");return t.name=a?l("cropsSetting").find(t=>t.sk===e).name:"",t}):[],handleDelete:this.handleToggle}),i.a.createElement(En.a,{className:e.helperText},o.observableOn),o.processingCrops&&i.a.createElement(En.a,{className:e.helperText},o.processingCrops)))))),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"description",label:"Description",name:"description",value:s.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!o.discription||void 0,helperText:o.discription}))))}}Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},margin:{margin:e.spacing(1)},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(hy);const gy=[{name:"name",min:1,max:200}];class uy extends n.Component{constructor(e){super(e),this.handleBlur=e=>this.validateField(e.target.id,gy),this.handleChange=e=>{const{productProcessorType:t}=this.state,a={...t};a[e.target.id]=e.target.value,this.setState({productProcessorType:a,changed:!0})},this.handleCheckChange=e=>{const{productProcessorType:t}=this.state,a={...t};a[e.target.id]=e.target.checked,this.setState({productProcessorType:a,changed:!0})};const{handleUpdate:t}=this.props;this.handleUpdate=t.bind(this),this.state={productProcessorType:{},errors:{count:0},changed:!1}}componentDidMount(){const{isNew:e,selectedSetting:t}=this.props;if(e)this.setState({productProcessorType:{enabled:!0,isGeneral:!0,setId:"a9d3f4b0-696b-4eb9-a9d7-48828697d1a3"}});else{const e=t;this.setState({productProcessorType:e})}}validateField(e){const{productProcessorType:t,errors:a}=this.state,n=jn(e,t,gy),i={...a};i[e]=n.msg,this.setState({errors:i})}render(){const{classes:e,open:t,isNew:a,setClose:n,getFromGlobalState:r}=this.props,{productProcessorType:l,errors:s,changed:o}=this.state,c=$n(l,gy);return i.a.createElement(Ia,{open:t,dialogObject:l,setClose:n,isNew:a,handleUpdateDialogObject:this.handleUpdate,skPrimary:"init_",dynamoType:"productProcessorTypes",valid:c,changed:o,newTitle:"New Pocessor Type",title:l.name,getFromGlobalState:r},i.a.createElement(g.a,{container:!0,className:e.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(Fe.a,{control:i.a.createElement(xe.a,{checked:l.enabled,id:"enabled",onChange:this.handleCheckChange,value:"enabled",color:"secondary"}),label:"Enabled"})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"name",label:"Name",name:"name",autoFocus:!0,value:l.name,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.name||void 0,helperText:s.name})),i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(zt.a,{margin:"normal",required:!0,fullWidth:!0,id:"description",label:"Description",name:"description",value:l.description,onChange:this.handleChange,onBlur:this.handleBlur,error:!!s.discription||void 0,helperText:s.discription}))))}}Object(v.a)(e=>({paper:{marginTop:e.spacing(3),marginBottom:e.spacing(3),padding:e.spacing(2),alignItems:"center"},avatar:{margin:e.spacing(1),backgroundColor:e.palette.secondary.main},margin:{margin:e.spacing(1)},form:{display:"flex",flexWrap:"wrap"},formControl:{minWidth:120,marginTop:e.spacing(2)},submit:{margin:e.spacing(1)},title:{marginLeft:e.spacing(2),flex:1},helperText:{color:"red"}}))(uy);const by=({children:e,settingDialog:t,handleUpdate:a,open:n,setClose:r,isNew:l,selectedSetting:s,metaData:o,getFromGlobalState:c,setGlobalState:d})=>i.a.cloneElement(t,{handleUpdate:a,open:n,setClose:r,isNew:l,selectedSetting:s,metaData:o,getFromGlobalState:c,setGlobalState:d});class vy extends n.Component{constructor(e){super(e),this.handleClickShow=()=>{this.setState({settingDialogOpen:!0})},this.handleBlur=()=>{},this.handleUpdate=async e=>{const{getFromGlobalState:t,settingName:a,setGlobalState:n}=this.props,i=t(a).findIndex(t=>t.sk===e.sk);if(-1===i){t(a).push(e),n({setting:e})}else{const r=t(a);r[i]=e,n({[a]:r})}if("farms"===a){const e=await Ea();console.log("farms-disabled",e);n({siteList:e.filter(e=>!e.isDisabled||!0!==e.isDisabled)})}},this.state={selectedSetting:null,isNew:!1,settingDialogOpen:!1}}handleClickAdd(){this.setState({settingDialogOpen:!0,isNew:!0,selectedSetting:{}})}handleClickShowSetting(e,t,a){const{getFromGlobalState:n,settingName:i}=this.props,r=n(i).find(e=>e.sk===a);this.setState({selectedSetting:r,settingDialogOpen:"true",isNew:!1})}handleClickEdit(){this.setState({settingDialogOpen:!0,isNew:!0})}setClose(){this.setState({settingDialogOpen:!1})}render(){const{classes:e,settingDialog:t,userAvatar:a,settingHeading:n,headCells:r,initialState:l}=this.props,{settingDialogOpen:s}=this.state,o=l;return i.a.createElement(O.a,{elevation:0,className:e.mainSection},s&&i.a.createElement(by,{settingDialog:t,metaData:this.props.metaDataName?this.props.getFromGlobalState(this.props.metaDataName):void 0,handleUpdate:this.handleUpdate.bind(this),open:this.state.settingDialogOpen,setClose:this.setClose.bind(this),isNew:this.state.isNew,selectedSetting:this.state.selectedSetting,setGlobalState:this.props.setGlobalState,getFromGlobalState:this.props.getFromGlobalState}),i.a.createElement(Me,{userAvatar:a,displayToolbar:!0,id:n,heading:this.props.heading,noPagination:!0,rows:o,headCells:r,handleSelect:this.handleClickShowSetting.bind(this),handleAddItem:this.handleClickAdd.bind(this),rowKeyName:"sk",clean:!0,maxHeight:"350px",selectedRow:this.state.selectedSetting}))}}vy.defaultProps={displayLabelPrim:"name"};Object(v.a)(e=>({root:{flexGrow:1},paperDropperBody:{display:"flex",margin:e.spacing(2)},heading:{marginTop:"4px",cursor:"pointer"},submit:{margin:e.spacing(1)},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10)},mainSection:{width:"100%",flexWrap:"wrap"},parentSection:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(2)}},childSection:{marginLeft:e.spacing(5)},childSectionChildren:{[e.breakpoints.up("sm")]:{marginLeft:e.spacing(6)},[e.breakpoints.down("sm")]:{marginLeft:e.spacing(4)}},expand:{transform:"rotate(0deg)",padding:"4px",marginLeft:"auto",transition:e.transitions.create("transform",{duration:e.transitions.duration.shortest})},expandOpen:{transform:"rotate(180deg)"}}))(vy);class yy extends n.Component{constructor(e){super(e),this.setAdminState=e=>{this.setState(e)},this.handleSettingExpand=e=>{const{expandedSetting:t}=this.state;t!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.getAdminState=e=>this.state[e],this.getTargetDetails=async e=>{const t=e.target.value;this.setState({isloadingTable:!0,selectedTargetsType:t});const{getFromGlobalState:a,setSnack:n}=this.props,{targetsDetail:i}=this.state;if(i&&i[t]&&i[t].length)return void this.setState({isloadingTable:!1});let r=a("activeSite");""!==r&&r||(r="default");try{const e=(await xa(r,t.concat("_"))).filter(e=>"targetDetail"===e.type),a={...i};a[t]=e,this.setState({targetsDetail:a,isloadingTable:!1})}catch(l){return n({open:!0,variant:"error",messageText:Pa(l)}),this.setState({isloadingTable:!1}),!1}},this.getCropDetailsLocal=async e=>{this.setState({isloadingTable:!0});const{getFromGlobalState:t,setGlobalState:a,setSnack:n}=this.props,i=await La(t,a,n,e);return this.setState({isloadingTable:!0}),i},this.getFertiliserDetailsLocal=async()=>{this.setState({isloadingTable:!0});const{getFromGlobalState:e,setGlobalState:t,setSnack:a}=this.props,n=await async function(e,t,a){try{const a=e("activeSite"),n=e("genFertilisers");if(n&&n.length)return n;const i=[...await xa(a,null,"genFertilisers")];return t({genFertilisers:i}),i}catch(n){return a({open:!0,variant:"error",messageText:Pa(n)}),!1}}(e,t,a);return this.setState({genFertilisers:n,isloadingTable:!1}),n},this.getPPPDetailsLocal=async()=>{this.setState({isloadingTable:!0});const{getFromGlobalState:e,setGlobalState:t,setSnack:a}=this.props,n=await async function(e,t,a){try{const a=e("activeSite"),n=e("genPPPs");if(n&&n.length)return n;const i=[...await xa(a,null,"genPPPs")];return t({genPPPS:i}),i}catch(n){return a({open:!0,variant:"error",messageText:Pa(n)}),!1}}(e,t,a);return this.setState({genPPPs:n,isloadingTable:!1}),n},this.handleTabChange=(e,t)=>{t!==this.state.selectedTab&&this.setState({selectedTab:t})},this.state={selectedTab:2,isloading:!1,isloadingTable:!1,crops:{},cropsDetail:{},selectedCropType:null,columns:[],targetsDetail:{},selectedTargetsType:null,isSubmitting:!1,expandedSetting:"",fertiliserColumns:[],genFertilisers:[],genPPPs:[]}}componentDidMount(){if(!this.props.isAuthenticated)return;const{getFromGlobalState:e,setGlobalState:t,setSnack:a}=this.props;this.setState({isloading:!0}),this.setState({isloading:!1}),console.log("farm",e("farm"))}render(){const{classes:e,reload:t,isAuthenticated:a,getFromGlobalState:n,setGlobalState:r,setSnack:l,isMobile:s}=this.props,{selectedTab:o,columns:c,fertiliserColumns:d,targetsDetail:m,genFertilisers:p,genPPPs:h,selectedTargetsType:g,isSubmitting:u,expandedSetting:b}=this.state,v=n("cropTypesSetting"),y=n("genCrops"),f=n("cropsDetail");return i.a.createElement(O.a,{elevation:0,className:e.paper},i.a.createElement(Mi,{value:o,handleChange:this.handleTabChange,selectedTab:o},i.a.createElement(fv,{heading:"Farms",getFromGlobalState:n,setGlobalState:r,setSnack:l,isAuthenticated:!0,setAdminState:this.setAdminState,getAdminState:this.getAdminState,getCropDetails:this.getCropDetailsLocal}),i.a.createElement(Vv,{heading:"Crops",getFromGlobalState:n,setGlobalState:r,setSnack:l,isAuthenticated:!0,data:{cropTypes:v,crops:y},rows:f,setAdminState:this.setAdminState,getAdminState:this.getAdminState,getCropDetails:this.getCropDetailsLocal,columns:c}),i.a.createElement(Zv,{heading:"Targets",data:{cropTypes:v,crops:y},getFromGlobalState:n,setGlobalState:r,setSnack:l,rows:g?m[g]:{},getCropDetails:this.getCropDetailsLocal,isAuthenticated:!0,getTargetDetails:this.getTargetDetails,setAdminState:this.setAdminState,getAdminState:this.getAdminState,onTargetTypeChange:this.getTargetDetails,selectedTargetsType:g}),i.a.createElement(ny,{heading:"Fertiliser",getFromGlobalState:n,setGlobalState:r,setSnack:l,isAuthenticated:!0,data:{cropTypes:v,crops:y},setAdminState:this.setAdminState,getAdminState:this.getAdminState,fertilisers:p,getFertiliserDetails:this.getFertiliserDetailsLocal,columns:d}),i.a.createElement(oy,{heading:"PPP",getFromGlobalState:n,setGlobalState:r,setSnack:l,isAuthenticated:!0,setAdminState:this.setAdminState,getAdminState:this.getAdminState,ppps:h,getPPPDetails:this.getPPPDetailsLocal}),i.a.createElement(O.a,{heading:"Other",elevation:0,style:{marginLeft:"4px"},className:e.paper2})))}}var fy=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(2),backgroundColor:"inherit"},paper2:{marginLeft:"4px",marginTop:"10px"},section:{margin:e.spacing(2,4)}}))(yy);const Ey=Object(z.a)(e=>({root:{minWidth:"100px",maxWidth:"100px",maxHeight:"80px",margin:"8px",float:"left",color:e.palette.primary.main},cardHeader:{textAlign:"center",padding:"4px"},cardContnet:{textAlign:"center",padding:"4px"}}));function Sy(e){const t=Ey(),{stat:a,header:n,subHeader:r,icon:l}=e;return i.a.createElement(u.a,{className:t.root},i.a.createElement(y.a,{className:t.cardHeader,title:n,subheader:r,titleTypographyProps:{variant:"subtitle2"},subheaderTypographyProps:{variant:"body2"}}),i.a.createElement(b.a,{className:t.cardContnet},i.a.createElement(B.a,{variant:"h6"},a)))}const Cy=Object(z.a)(e=>({root:{marginTop:e.spacing(2)},paper:{borderRadius:"8px",height:"100%",transition:"box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",boxShadow:"0px 1px 1px rgb(100 116 139 / 6%), 0px 1px 2px rgb(100 116 139 / 10%)",overflow:"hidden"},cardContnet:{paddingBottom:"32px"}}));function xy(e){const t=Cy(),{stat:a,header:n,icon:r,message:l,maxWidth:s}=e;return i.a.createElement(O.a,{className:t.root,style:s?{maxWidth:s}:void 0},i.a.createElement(u.a,null,i.a.createElement(b.a,{className:t.cardContnet},i.a.createElement(g.a,{container:!0,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:8,lg:6,xl:8},i.a.createElement("div",{style:{paddingLeft:"24px",paddingTop:"24px"}},i.a.createElement(B.a,{variant:"button"},n),i.a.createElement(B.a,{variant:"h4"},a),l&&i.a.createElement(B.a,{variant:"body2"},l))),i.a.createElement(g.a,{item:!0,xs:2,sm:2,md:2,lg:2,xl:2}),i.a.createElement(g.a,{item:!0,xs:2,sm:2,md:2,lg:4,xl:2},i.a.createElement("div",{style:{paddingLeft:"24px",paddingTop:"24px"}},r&&i.a.createElement(de.a,{style:{width:"56px",height:"56px",float:"right",backgroundColor:"#0e4553"}},r)))),!1)))}const ky=Object(z.a)(e=>({root:{width:"180px","& > *":{padding:e.spacing(1)}},paper:{marginBottom:e.spacing(2),padding:e.spacing(1)},formControl:{minWidth:120,marginTop:e.spacing(2)}}));function wy(e){ky();const{metaData:t,handleToggle:a,selectedData:n,expandedSetting:r,handleExpand:l}=e;return i.a.createElement("div",null,i.a.createElement(cr,{heading:"Country",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.countries.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.countries,checkedItems:n.countries,handleToggle:a,arrayName:"countries"})),i.a.createElement(cr,{heading:"Province",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.provinces.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.provinces,checkedItems:n.provinces,handleToggle:a,arrayName:"provinces"})),i.a.createElement(cr,{heading:"Crop Type",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.cropTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.cropTypes,checkedItems:n.cropTypes,handleToggle:a,arrayName:"cropTypes"})),i.a.createElement(cr,{heading:"Crop",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.crops.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.crops,checkedItems:n.crops,handleToggle:a,arrayName:"crops"})),i.a.createElement(cr,{heading:"Cultivar type",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.cultivarTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.cultivarTypes,checkedItems:n.cultivarTypes,handleToggle:a,arrayName:"cultivarTypes"})),i.a.createElement(cr,{heading:"Cultivar",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.cultivars.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.cultivars,checkedItems:n.cultivars,handleToggle:a,arrayName:"cultivars"})),i.a.createElement(cr,{heading:"Rootstock type",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.rootStockTypes.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.rootStockTypes,checkedItems:n.rootStockTypes,handleToggle:a,arrayName:"rootStockTypes"})),i.a.createElement(cr,{heading:"Rootstock",expanded:r,handleExpand:l,detailComponent:i.a.createElement(di.a,{color:"secondary",badgeContent:n.rootStocks.length}),expandIcon:i.a.createElement(vr.a,null)},i.a.createElement(Ks,{data:t.rootStocks,checkedItems:n.rootStocks,handleToggle:a,arrayName:"rootStocks"})))}class Ty extends n.PureComponent{render(){const{title:e,data:t,keys:a,dataKey:n,height:r,name:l}=this.props;return i.a.createElement(O.a,{style:{borderRadius:"4px",overflow:"hidden"}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),i.a.createElement(ib.k,{key:l+" 3",width:"100%",height:r,style:{cursor:"pointer"}},i.a.createElement(ib.b,{width:"100%",height:r,data:t,name:l,key:l+" 1",margin:{top:20,right:20,left:10,bottom:5}},i.a.createElement(ib.c,{strokeDasharray:"3 3"}),i.a.createElement(ib.o,{dataKey:n}),i.a.createElement(ib.p,null),i.a.createElement(ib.n,null),i.a.createElement(ib.f,{wrapperStyle:{fontSize:"12px"}}),a&&a.length&&a.map((e,t)=>i.a.createElement(ib.a,{name:e,key:`${l}-bar-${e}`,label:!0,dataKey:e,fill:Y(j("#0e4553",-.4*t),80)})))))}}Ty.defaultProps={height:400};class Dy extends n.PureComponent{render(){const{title:e,data:t,keys:a,dataKey:n,color:r,showLedgend:l,showLabel:s,height:o,cx:c,cy:d,innerRadius:m,outerRadius:p,legendAlign:h,legendLayout:g,legendVerticalAlign:u,addMargin:b}=this.props,v=b?"16px":void 0;return i.a.createElement(O.a,{style:{borderRadius:"4px",overflow:"hidden",marginTop:v}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),i.a.createElement(ib.k,{width:"100%",height:o,style:{cursor:"pointer"}},i.a.createElement(ib.j,{width:"100%",height:"100%"},i.a.createElement(ib.i,{data:t,cx:c,cy:d,innerRadius:m,outerRadius:p,fill:"#8884d8",paddingAngle:3,dataKey:n,label:s},t&&t.length&&t.map((e,t)=>i.a.createElement(ib.d,{key:"cell-"+t,fill:Y(j("#0e4553",-.4*t),70)}))),l&&i.a.createElement(ib.f,{wrapperStyle:{fontSize:"12px"},layout:g,verticalAlign:u,align:h}),i.a.createElement(ib.n,null))))}}Dy.defaultProps={height:150,cx:70,cy:65,innerRadius:20,outerRadius:40,legendLayout:"vertical",legendVerticalAlign:"middle",legendAlign:"right",addMargin:!1};class Py extends n.PureComponent{constructor(...e){super(...e),this.renderTooltip=e=>{const{active:t,payload:a}=e;if(t&&a&&a.length){const e=a[0]&&a[0].payload;return i.a.createElement("div",{style:{backgroundColor:"#fff",border:"1px solid #999",margin:0,padding:10}},i.a.createElement("p",null,i.a.createElement("span",null,"range: "),e.name),i.a.createElement("p",null,e["Area in Ha"],i.a.createElement("span",null," Ha")))}return null}}render(){const{title:e,data:t,dataKeyX:a,dataKeyY:n,dataKeyZ:r,height:l,name:s,yLabel:o}=this.props,c=((e,t)=>[0,e&&Math.max(Math.max.apply(null,e.map(e=>e[t])))])(t,r),d=[c[0],c[1]];return i.a.createElement(O.a,{style:{borderRadius:"4px",overflow:"hidden"}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),i.a.createElement(ib.k,{key:s,width:"100%",height:l,style:{cursor:"pointer"}},i.a.createElement(ib.m,{width:"100%",height:60,margin:{top:30,right:20,bottom:10,left:10}},i.a.createElement(ib.o,{type:"category",dataKey:a,interval:0,name:a,tickLine:{transform:"translate(0, -6)"},label:!0}),i.a.createElement(ib.p,{type:"number",dataKey:n,name:n,height:10,width:80,tick:!1,tickLine:!1,axisLine:!1,label:{value:o,position:"insideRight"}}),i.a.createElement(ib.q,{label:!0,type:"number",dataKey:r,domain:c,range:d}),i.a.createElement(ib.n,{cursor:{strokeDasharray:"3 3"},wrapperStyle:{zIndex:100},content:this.renderTooltip}),i.a.createElement(ib.l,{data:t,fill:"#0e4553"}))))}}Py.defaultProps={height:400};class Fy extends n.PureComponent{render(){const{title:e,data:t,keys:a,dataKey:n,color:r,showLedgend:l,showLabel:s,height:o,cx:c,cy:d,innerRadius:m,outerRadius:p,innerRadiusOuter:h,outerRadiusOuter:g,legendAlign:u,legendLayout:b,legendVerticalAlign:v,addMargin:y,dataKeyOuter:f,dataOuter:E}=this.props,S=y?"16px":void 0;return i.a.createElement(O.a,{style:{borderRadius:"4px",overflow:"hidden",marginTop:S}},e&&i.a.createElement(i.a.Fragment,null,i.a.createElement("div",{style:{width:"100%",justifyContent:"center",display:"inline-flex",paddingTop:"5px"}},i.a.createElement(B.a,{variant:"button",gutterBottom:!0},e))),i.a.createElement(ib.k,{width:"100%",height:o,style:{cursor:"pointer"}},i.a.createElement(ib.j,{width:"100%",height:"100%"},i.a.createElement(ib.i,{data:t,cx:c,cy:d,innerRadius:m,outerRadius:p,fill:"#0e4553",paddingAngle:3,dataKey:n,label:s}),l&&i.a.createElement(ib.f,{wrapperStyle:{fontSize:"12px"},layout:b,verticalAlign:v,align:u}),i.a.createElement(ib.i,{data:E,dataKey:f,cx:c,cy:d,innerRadius:h,outerRadius:g,fill:Y(j("#0e4553",6*-.4),80),label:!0}),i.a.createElement(ib.n,null))))}}function Ny(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M19.5,12c0.93,0,1.78,0.28,2.5,0.76V8c0-1.1-0.9-2-2-2h-6.29l-1.06-1.06l1.41-1.41l-0.71-0.71L9.82,6.35l0.71,0.71 l1.41-1.41L13,6.71V9c0,1.1-0.9,2-2,2h-0.54c0.95,1.06,1.54,2.46,1.54,4c0,0.34-0.04,0.67-0.09,1h3.14 C15.3,13.75,17.19,12,19.5,12z"}),i.a.createElement("path",{d:"M19.5,13c-1.93,0-3.5,1.57-3.5,3.5s1.57,3.5,3.5,3.5s3.5-1.57,3.5-3.5S21.43,13,19.5,13z M19.5,18 c-0.83,0-1.5-0.67-1.5-1.5s0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5S20.33,18,19.5,18z"}),i.a.createElement("path",{d:"M4,9h5c0-1.1-0.9-2-2-2H4C3.45,7,3,7.45,3,8C3,8.55,3.45,9,4,9z"}),i.a.createElement("path",{d:"M9.83,13.82l-0.18-0.47L10.58,13c-0.46-1.06-1.28-1.91-2.31-2.43l-0.4,0.89l-0.46-0.21l0.4-0.9C7.26,10.13,6.64,10,6,10 c-0.53,0-1.04,0.11-1.52,0.26l0.34,0.91l-0.47,0.18L4,10.42c-1.06,0.46-1.91,1.28-2.43,2.31l0.89,0.4l-0.21,0.46l-0.9-0.4 C1.13,13.74,1,14.36,1,15c0,0.53,0.11,1.04,0.26,1.52l0.91-0.34l0.18,0.47L1.42,17c0.46,1.06,1.28,1.91,2.31,2.43l0.4-0.89 l0.46,0.21l-0.4,0.9C4.74,19.87,5.36,20,6,20c0.53,0,1.04-0.11,1.52-0.26l-0.34-0.91l0.47-0.18L8,19.58 c1.06-0.46,1.91-1.28,2.43-2.31l-0.89-0.4l0.21-0.46l0.9,0.4C10.87,16.26,11,15.64,11,15c0-0.53-0.11-1.04-0.26-1.52L9.83,13.82z M7.15,17.77c-1.53,0.63-3.29-0.09-3.92-1.62c-0.63-1.53,0.09-3.29,1.62-3.92c1.53-0.63,3.29,0.09,3.92,1.62 C9.41,15.38,8.68,17.14,7.15,17.77z"}),">")}function By(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M17.9,17.39C17.64,16.59 16.89,16 16,16H15V13C15,12.45 14.55,12 14,12H8V10H10C10.55,10 11,9.55 11,9V7H13C14.1,7 15,6.1 15,5V4.59C17.93,5.77 20,8.64 20,12C20,14.08 19.2,15.97 17.9,17.39M11,19.93C7.05,19.44 4,16.08 4,12C4,11.38 4.08,10.78 4.21,10.21L9,15V16C9,17.1 9.9,18 11,18M12,2C6.48,2 2,6.48 2,12C2,17.52 6.48,22 12,22C17.52,22 22,17.52 22,12C22,6.48 17.52,2 12,2Z"}),">")}function Ly(e){return i.a.createElement(rn.a,{color:e.color,style:{fontSize:"x-large"},viewBox:"0 0 24 24"},i.a.createElement("path",{d:"M16 12L9 2L2 12H3.86L0 18H7V22H11V18H18L14.14 12H16M20.14 12H22L15 2L12.61 5.41L17.92 13H15.97L19.19 18H24L20.14 12M13 19H17V22H13V19Z"}),">")}Fy.defaultProps={height:130,cx:"50%",cy:"50%",innerRadius:20,outerRadius:40,innerRadiusOuter:70,outerRadiusOuter:90,legendLayout:"vertical",legendVerticalAlign:"middle",legendAlign:"right",addMargin:!1};class Ay extends n.Component{constructor(e){super(e),this.distinctPush=(e,t)=>{-1===e.findIndex(e=>e.sk===t.sk)&&e.push(t)},this.handleExpand=e=>{const{expandedSetting:t}=this.state;t!==e?this.setState({expandedSetting:e}):this.setState({expandedSetting:""})},this.getPaths=e=>{if(!e)return null;const t=[],a=e.length;for(let n=0;n{for(let t=0;t{const{getFromGlobalState:a,setGlobalState:n}=this.props,{selectedGraphTab:i}=this.state,r=a("census"),l=a("metaData"),s={...a("selectedData")},o={...l},c=s[t].indexOf(e);switch(-1===c?s[t].push(e):s[t].splice(c,1),t){case"countries":case"provinces":{const e=V.filter(e=>-1!==s.countries.indexOf(e.countryName));let t=[];for(let a=0;a{const t={};return t.name=e.name,t.sk=e.name,t}))}o.provinces=t,n({metaData:o});break}case"irrigationTypes":break;case"cropTypes":case"crops":case"cultivarTypes":case"cultivars":case"rootStockTypes":case"rootStocks":break;default:}const d=this.filterItems(r.Items,s),m=this.getPaths(d.filteredItems),p=Xe(d.filteredItems);"cropTypes"!==t&&(o.cropTypes=[...new Set(p.map(e=>e.cropTypeName))],o.cropTypes=o.cropTypes.map(e=>({name:e,sk:e}))),"crops"!==t&&(o.crops=[...new Set(p.map(e=>e.cropName))],o.crops=o.crops.map(e=>({name:e,sk:e}))),"cultivarTypes"!==t&&(o.cultivarTypes=[...new Set(p.map(e=>e.cultivarType))],o.cultivarTypes=o.cultivarTypes.map(e=>({name:e,sk:e}))),"cultivars"!==t&&(o.cultivars=[...new Set(p.map(e=>e.cultivar))],o.cultivars=o.cultivars.map(e=>({name:e,sk:e}))),"rootStockTypes"!==t&&(o.rootStockTypes=[...new Set(p.map(e=>e.rootStockType))],o.rootStockTypes=o.rootStockTypes.map(e=>({name:e,sk:e}))),"rootStocks"!==t&&(o.rootStocks=[...new Set(p.map(e=>e.rootStock))],o.rootStocks=o.rootStocks.map(e=>({name:e,sk:e}))),"irrigationTypes"!==t&&(o.irrigationTypes=[...new Set(p.map(e=>e.irrigationSystem))],o.irrigationTypes=o.irrigationTypes.map(e=>({name:e,sk:e})));const h=this.generateGraphData(i,p);this.props.setGlobalState({filteredMetaData:o,selectedData:s,filteredStats:d.stats}),this.setState({blockPaths:m,flatItems:p,graphData:h})},this.handleFilterToggle=(e,t)=>{const{getFromGlobalState:a,setGlobalState:n}=this.props,{selectedGraphTab:i}=this.state,r=a("census"),l=a("metaData"),s=a("selectedData"),o={...s},c={...l},d=o[t].indexOf(e);switch(-1===d?o[t].push(e):o[t].splice(d,1),t){case"countries":case"provinces":{const e=V.filter(e=>-1!==o.countries.indexOf(e.countryName));let t=[];for(let a=0;a{const t={};return t.name=e.name,t.sk=e.name,t}))}c.provinces=t,n({metaData:c});break}case"irrigationTypes":break;case"cropTypes":case"crops":case"cultivarTypes":case"cultivars":case"rootStockTypes":case"rootStocks":{s.cropTypes.length&&(c.crops=c.crops.filter(e=>-1!==s.cropTypes.indexOf(e.cropType)));let e=[...c.crops];s.crops.length&&(e=c.crops.filter(e=>-1!==s.crops.indexOf(e.sk)));let t=[];for(let a=0;at.sk.startsWith(e[a].sk)));if(c.varieties=[...t],c.cultivars=[],c.cultivarTypes=[],c.rootStocks=[],c.rootStockTypes=[],this.injectVarieties(c,l),s.cultivarTypes.length){c.varieties=c.varieties.filter(e=>-1!==o.cultivarTypes.indexOf(e.cultivarType)),c.cultivars=[],c.rootStocks=[],c.rootStockTypes=[];for(let e=0;e-1!==o.cultivars.indexOf(e.cultivar)),c.rootStocks=[],c.rootStockTypes=[];for(let e=0;e-1!==o.rootStockTypes.indexOf(e.rootStockType)),c.rootStocks=[];for(let e=0;e{const{getFromGlobalState:e}=this.props,t=e("selectedData");return t.rootStockTypes.length?{groupBy:["rootStockType","rootStock"],title:"Tree Density by Rootstock/Ha"}:t.cultivars.length?{groupBy:["cultivar","rootStockType"],title:"Tree Density by Rootstock Type/Ha"}:t.cultivarTypes.length?{groupBy:["cultivarType","cultivar"],title:"Tree Density by Cultivar/Ha"}:t.crops.length?{groupBy:["cropName","cultivarType"],title:"Tree Density by Cultivar Type/Ha"}:t.cropTypes.length?{groupBy:["cropTypeName","cropName"],title:"Tree Density/Ha"}:t.provinces.length?{groupBy:["province","cropTypeName"],title:"Tree Density by Crop Type/Ha"}:t.countries.length?{groupBy:["country","province"],title:"Tree Density/Ha"}:{groupBy:["cropTypeName","cropName"],title:"Tree Density by Crop Type/Ha"}},this.generateGraphData=(e,t)=>{let a={};const{getFromGlobalState:n}=this.props;n("allStats"),n("selectedData");switch(e){case 0:{a.country=_e(t,"country","size","Area in Ha","Country",!1),a.country.total=a.country.data.reduce((e,t)=>e+parseFloat(t["Area in Ha"]),0),a.province=_e(t,"province","size","Area","Province",!0),a.cropType=_e(t,"cropTypeName","size","Area in Ha","Crop type",!0),a.crop=_e(t,"cropName","size","Area in Ha","Crop",!0),a.cultivarType=_e(t,"cultivarType","size","Area in Ha","Crop",!0),a.cultivarType2=Ye(t,["cultivarType","rootStockType"],"size","Cultivar",!0),a.cultivarType.outerData=[],a.cultivarType2.data.forEach(e=>{Object.keys(e).forEach(t=>{"name"!==t&&a.cultivarType.outerData.push({name:t,value:e[t]})})}),a.cultivar=Ye(t,["cultivar","rootStock"],"size","Cultivar",!0);const e=this.getSelectedGroup();a.plantingDensity=Ye(t,e.groupBy,"totalPlants","Density by Cultivar type",!0,"size","divide"),a.plantingDensity.title=e.title,a.plantAge=_e(t,"ageBucket","size","Area in Ha","Age",!0),a.plantAge.title="Tree age",a.plantAge.data=a.plantAge.data.sort((e,t)=>(""+e.name).localeCompare(t.name,void 0,{numeric:!0})),a.plantAge.data=a.plantAge.data.map(e=>{const t={...e};return t.index=1,t}),a.irrigationType=_e(t,"irrigationSystem","size","Area in Ha","Age",!0),a.irrigationType.title="Irrigation",a.rootStockType=_e(t,"rootStockType","size","Area in Ha","Age",!0),a.rootStockType.title="Rootstock Type",a.rootStock=_e(t,"rootStock","size","Area in Ha","Age",!0),a.rootStock.title="Rootstock";break}case 1:a.province=_e(t,"province","size","Area in Ha","Province",!0);break;case 2:a=_e(t,"cropTypeName","size","Area in Ha","Crop type",!0);break;case 3:a=_e(t,"cropName","size","Area in Ha","Crop",!0);break;case 4:a=Ye(t,["cropName","cultivarType"],"size","Cultivar Type",!0);break;case 5:a=Ye(t,["cultivarType","cultivar"],"size","Cultivar",!0);break;case 6:a=Ye(t,["cultivar","rootStockType"],"size","Rootstock Type",!0);break;case 7:a=Ye(t,["rootStockType","Rootstock"],"size","Rootstock",!0)}return a},this.filterItems=(e,t)=>{const{getFromGlobalState:a}=this.props;let n=t;if(n||(n=a("selectedData")),!e)return null;const i={farms:0,size:0,sizeByCrop:{},plantings:0,trees:0,set:!1};let r=[...e];const l=[];n&&(n.countries.length&&(r=r.filter(e=>-1!==n.countries.indexOf(e.farm.address.country))),n.regions.length&&(r=r.selectedData(e=>-1!==n.regions.indexOf(e.farm.address.region))),n.provinces.length&&(r=r.filter(e=>-1!==n.provinces.indexOf(e.farm.address.province))));for(let s=0;s-1!==n.cropTypes.indexOf(e.crop.cropType))),n.crops.length&&(a=a.filter(e=>-1!==n.crops.indexOf(e.crop.id))),n.cultivarTypes.length&&(a=a.filter(e=>-1!==n.cultivarTypes.indexOf(e.variety.cultivarType))),n.cultivars.length&&(a=a.filter(e=>-1!==n.cultivars.indexOf(e.variety.cultivar))),n.rootStockTypes.length&&(a=a.filter(e=>-1!==n.rootStockTypes.indexOf(e.variety.rootStockType))),n.rootStocks.length&&(a=a.filter(e=>-1!==n.rootStocks.indexOf(e.variety.rootStock))),n.irrigationTypes.length&&(a=a.filter(e=>-1!==n.irrigationTypes.indexOf(e.irrigationSystem))))}if(a.length){const n={...r[s].blocks[t]};n.plantings=a;let l=a.reduce((e,t)=>e+parseFloat(t.size),0);isNaN(l)&&(l=parseFloat(r[s].blocks[t].sizeMap)),i.size+=l;for(let e=0;ee+parseFloat(t.totalPlants?t.totalPlants:Qe(t.plantSpacing,t.plantDensity,t.size)),0);isNaN(o)&&(o=0),i.trees+=o,i.plantings+=a.length,e.push(n)}else console.log("plantings 0")}if(e.length){const t={farm:{},blocks:[]};t.farm={...r[s].farm},t.blocks=[...e],l.push(t)}else console.log("no blocks")}return i.farms=l.length,{filteredItems:l,stats:i}},this.handleTabChange=(e,t)=>{const{selectedTab:a}=this.state;t!==a&&this.setState({selectedTab:t})},this.handleGraphTabChange=(e,t)=>{const{selectedGraphTab:a,flatItems:n}=this.state;if(t!==a){const e=this.generateGraphData(t,n);this.setState({selectedGraphTab:t,graphData:e})}},this.calcTotalSelectedCrop=(e,t)=>{let a=t.size;if(e.crops&&e.crops.length){a=0;for(let n=0;n{const t={};return t.name=e.countryName,t.sk=e.countryName,t});const s=n.cropTypes?Object.getOwnPropertyNames(n.cropTypes):[];for(let t=0;t({root:{flexGrow:1},paper:{marginBottom:e.spacing(1),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(Ay);class Iy extends n.Component{constructor(e){super(e),this.locationError=e=>{const{setSnack:t}=this.props;t({open:!0,variant:"error",messageText:" Failed to find location "+e.message})},this.locationFound=e=>{const{isMobile:t,block:a,getFromGlobalState:n}=this.props,i=e.coords,r=n("blocks"),l=Nn(r,i.latitude,i.longitude),s=this.getBlockPaths(r,l);this.setState({currentLocation:i,blockPaths:s,foundBlock:l})},this.onUserMoved=()=>{const{userMoved:e}=this.state;e||this.setState({userMoved:!0})},this.recenter=()=>{const{userMoved:e}=this.state;e&&this.setState({userMoved:!1})},this.getBlockPaths=(e,t)=>{const a=[];for(let n=0;nt.sk===e),r={label:n.number,position:{lat:t.latLng.lat(),lng:t.latLng.lng()},content:this.getBlockInfo(n)};this.setState({blockPaths:a,selectedBlock:e,infoWindow:r,infoWindowPosition:{lat:t.latLng.lat(),lng:t.latLng.lng()}})}}onMapClick(){this.onCloseInfoWindow()}onCloseInfoWindow(){const{getFromGlobalState:e}=this.props,t=e("blocks"),a=this.getBlockPaths(t,"");this.setState({blockPaths:a,foundBlock:"",infoWindowPosition:null,infoWindow:null})}render(){const{online:e,classes:t}=this.props,{currentLocation:a,foundBlock:n,blockPaths:r,infoWindow:l,userMoved:s}=this.state,o=a&&window.google&&window.google.maps?[{position:{lat:a.latitude,lng:a.longitude},icon:{path:a&&window.google&&window.google.maps?window.google.maps.SymbolPath.CIRCLE:void 0,scale:a.accuracy>3?a.accuracy:3,fillColor:"red",fillOpacity:.2,strokeColor:"red",strokeWeight:2}}]:[],c=a?n?"You are in block: "+n.number:"You do not appear to be in a block":null;return i.a.createElement(g.a,{container:!0,className:t.root,spacing:1,alignItems:"flex-start"},i.a.createElement(g.a,{item:!0,xs:8,sm:8,md:8,lg:8,xl:8},i.a.createElement(B.a,{style:{margin:"5px"},variant:"subtitle1"},""+(a&&a?`Accuracy: ${a.accuracy.toFixed(2)} m`:"Locating..."),i.a.createElement(Li.a,{style:a?a&&a.accuracy<10?{color:"green",paddingLeft:"8px"}:{color:"orange",paddingLeft:"8px"}:{color:"red",paddingLeft:"8px"}}))),c&&i.a.createElement(g.a,{item:!0,xs:12,sm:12,md:12,lg:12,xl:12},i.a.createElement(B.a,{style:{margin:"5px"},variant:"subtitle1"},c)),e&&i.a.createElement(Wn,{center:a?{lat:a.latitude,lng:a.longitude}:void 0,polygons:r,markers:o,style:{height:"400px",width:"100%"},onPolygonClick:this.onMapBlockClick,onCloseInfoWindow:this.onCloseInfoWindow,infoWindow:l,onClick:this.onMapClick,keepBounds:s}))}}var Gy=Object(v.a)(e=>({root:{flexGrow:1},paper:{display:"flex",flexDirection:"column",marginBottom:e.spacing(10),backgroundColor:"inherit"},heading:{[e.breakpoints.up("sm")]:{display:"none"}},section:{margin:e.spacing(2,4)}}))(Iy),Ry=a(154);var Uy=e=>{const t=e.getFromGlobalState("subscription"),a=(null===t||void 0===t?void 0:t[0])&&(e=>{if(!e)return!1;const t=new Date;return(new Date(e.nextSubscription)-t)/864e5>-15})(t[0]),n=(null===t||void 0===t?void 0:t[0])||{};return e.getFromGlobalState("synchronising")?i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Checking Subscription Status",subheader:"........",subheaderTypographyProps:{color:"#fff",fontSize:9},style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement(F,null),i.a.createElement("p",null,"Hold on, while we verify your subscription status"))))):i.a.createElement("div",{style:{paddingTop:40}},t&&!n.nextSubscription?i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Activate Free Trial",style:{backgroundColor:"#0e4553",color:"#fff"},subheaderTypographyProps:{color:"#fff"},subheader:"Access 1 Month Free Trial"}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},i.a.createElement("sup",null,"R"),"10"),i.a.createElement("strong",null,i.a.createElement("p",null,"Pay R10 Today ")),"Full Access",i.a.createElement("br",null),"1 Month Free Trial",i.a.createElement("br",null),"Cancel anytime",i.a.createElement("br",null),"Unlimited users",i.a.createElement("br",null),i.a.createElement("strong",null,i.a.createElement("p",null,"Access to all Modules:")),"Monitoring",i.a.createElement("br",null),"Harvesting",i.a.createElement("br",null),"Horticultural activities",i.a.createElement("br",null),"Plant protection",i.a.createElement("br",null),"Fertiliser",i.a.createElement("br",null)),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"row",justifyContent:"center"}},i.a.createElement(Ry.Link,{to:"activate-trial"},i.a.createElement(Ct.a,{variant:"contained",color:"primary"},"Activate Free Trial"))))),n.totalPrice>0&&i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Start With Launch Pricing",subheader:"Launch Pricing",subheaderTypographyProps:{color:"#fff"},style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},i.a.createElement("sup",null,"R"),n.totalPrice),i.a.createElement("strong",null,i.a.createElement("p",null,"Base fee for your entity per month")),"R850 per month per farm",i.a.createElement("br",null),"R12.00 per month per planting",i.a.createElement("br",null),"R50 per additional user",i.a.createElement("br",null),"Includes 6 users, 2 devices per user",i.a.createElement("br",null),i.a.createElement("strong",null,i.a.createElement("p",null,"Modules Included in base fee:")),"Monitoring",i.a.createElement("br",null),"Harvesting",i.a.createElement("br",null),"Horticultural activities",i.a.createElement("br",null),"Plant protection",i.a.createElement("br",null),"Fertiliser",i.a.createElement("br",null)),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"row",justifyContent:"center"}},i.a.createElement(Ry.Link,{to:"activate-subscription"},i.a.createElement(Ct.a,{variant:"contained",color:"primary"},"Subscribe")))))):a?i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Your subscription is active",subheader:"Enjoy Land Diary!!",subheaderTypographyProps:{color:"#fff",fontSize:9},style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement("p",null,"You have full access to Land Diary and all its features")),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"row",justifyContent:"center"}},i.a.createElement(Ry.Link,{to:"records"},i.a.createElement(Ct.a,{variant:"contained",color:"primary"},"Browse Records")))))):i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Your subscription has expired",subheader:"Renew, subscription to gain full access",subheaderTypographyProps:{color:"#fff",fontSize:9},style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},i.a.createElement("sup",null,"R"),n.totalPrice),i.a.createElement("p",null,"Your trial period has expired,renew your subcription to gain full access")),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"row",justifyContent:"center"}},i.a.createElement(Ry.Link,{to:"renew-subscription"},i.a.createElement(Ct.a,{variant:"contained",color:"primary"},"Renew")))))))};var My=e=>{var t;const[a]=Object(n.useState)((()=>{const e=new Date,t=e.getMonth()+1,a=e.getFullYear()+(t>11?1:0);return new Date(a,t%12,1)})()),{history:r,userDetail:l,activeSite:s,setSnack:o,setGlobalState:c,getFromGlobalState:d}=e,m=e.getFromGlobalState("siteList").find(e=>e.tenantId===s),p=e.getFromGlobalState("subscription")[0];p.totalPrice=p.totalPrice>=1?p.totalPrice:850;const h="entity"===(null===m||void 0===m?void 0:m.entityType)?null===m||void 0===m?void 0:m.tenantId:null===m||void 0===m||null===(t=m.parentFarm)||void 0===t?void 0:t.activeTenant,v=`${(E=a).getFullYear()}-${String(E.getMonth()+1).padStart(2,"0")}-${String(E.getDate()).padStart(2,"0")}`;var E;const S="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),C=parseInt(function(e){const t=new Date,a=t.getFullYear(),n=t.getMonth(),i=new Date(a,n+1,0).getDate()-t.getDate();return parseInt(e/31*i)}(p.totalPrice));return i.a.createElement("div",{style:{paddingTop:40}},i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Setup Your Subscription",style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,{style:{textAlign:"center"}},i.a.createElement("p",{style:{margin:0,fontSize:12,marginTop:5,textAlign:"center"}},"Subscribe and enjoy full access to Land Diary's features. You will be charged R",C," today, which is subject to change based on the features you enable on land-diary."),i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},i.a.createElement("sup",null,"R"),C),i.a.createElement("h5",{style:{textAlign:"center"}},"Just a heads-up! Your next billing date will come up on: ",a.toDateString()," and your monthly charge will be R",p.totalPrice),i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,alignItems:"flex-start"},i.a.createElement("form",{style:{width:"100%",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"},name:"form",id:"sub-form",method:"POST",action:"https://paynow.netcash.co.za/site/paynow.aspx"},i.a.createElement("input",{type:"text",hidden:!0,name:"m1",value:"02586e4b-6f53-4bc1-8adb-98cdccabe091"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m2",value:"24ade73c-98cf-47b3-99be-cc7b867b3080"}),i.a.createElement("input",{type:"text",hidden:!0,name:"p2",value:S}),i.a.createElement("input",{type:"text",hidden:!0,name:"p3",value:"Land-diary subscription"}),i.a.createElement("input",{type:"text",hidden:!0,name:"p4",value:C}),i.a.createElement("input",{type:"text",hidden:!0,name:"Budget",value:"Y"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m4",value:h}),i.a.createElement("input",{type:"text",hidden:!0,name:"m5",value:l.userId}),i.a.createElement("input",{type:"text",hidden:!0,name:"m6",value:l.email}),i.a.createElement("input",{type:"text",hidden:!0,name:"m9",value:l.email}),i.a.createElement(zt.a,{fullWidth:!0,margin:"normal",required:!0,type:"text",label:"Contact Number",name:"m11",id:"m11",InputLabelProps:{shrink:!0}}),i.a.createElement("input",{type:"text",hidden:!0,name:"m14",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m16",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m17",value:"12"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m18",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m19",value:v}),i.a.createElement("input",{type:"text",hidden:!0,name:"m20",value:p.totalPrice}),i.a.createElement(Ct.a,{name:"submit",type:"submit",style:{marginTop:20,width:"40%"},variant:"contained",color:"primary"},"Subscribe")))),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"column",justifyContent:"center"}},i.a.createElement("p",{style:{margin:0,fontSize:12,marginTop:5}},"You'll be redirected to a secure payment gateway to complete subscription"))))))};const Wy=Object(z.a)({noBorder:{"& .MuiOutlinedInput-root":{"& fieldset":{border:"none"}}}});var zy=e=>{var t;const[a,r]=Object(n.useState)(!1),l=(Wy(),e=>{const t=e-new Date;if(t<=0)return{days:0,hours:0,minutes:0,seconds:0};return{days:Math.floor(t/864e5),hours:Math.floor(t/36e5%24),minutes:Math.floor(t/6e4%60),seconds:Math.floor(t/1e3%60)}}),[s]=Object(n.useState)((()=>{const e=new Date,t=new Date;t.setDate(e.getDate()+30);const a=t.getMonth()+1,n=t.getFullYear()+(a>11?1:0);return new Date(n,a%12,1)})()),[o,c]=Object(n.useState)(l(s));Object(n.useEffect)(()=>{const e=setInterval(()=>{c(l(s))},1e3);return()=>clearInterval(e)},[s]);const{history:d,userDetail:m,activeSite:p,setSnack:h,setGlobalState:v,getFromGlobalState:E}=e,S=e.getFromGlobalState("siteList").find(e=>e.tenantId===p),C="entity"===(null===S||void 0===S?void 0:S.entityType)?null===S||void 0===S?void 0:S.tenantId:null===S||void 0===S||null===(t=S.parentFarm)||void 0===t?void 0:t.activeTenant,x=`${(k=s).getFullYear()}-${String(k.getMonth()+1).padStart(2,"0")}-${String(k.getDate()).padStart(2,"0")}`;var k;const[w,T]=Object(n.useState)({m1:"02586e4b-6f53-4bc1-8adb-98cdccabe091",m2:"24ade73c-98cf-47b3-99be-cc7b867b3080",p2:C,p3:"Land Diary",p4:850,Budget:"Y",m4:m.email,m5:m.userId,m9:m.email,m14:1,m15:"6cb844d2-8000-4a5f-ac89-9160ea423213",m16:1,m17:12,m18:1,m19:x,m20:850}),D="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),P=e.getFromGlobalState("subscription")[0];return console.log(s,x,D),i.a.createElement("div",{style:{paddingTop:40}},i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,justifyContent:"space-evenly"},i.a.createElement(g.a,{item:!0,lg:4},i.a.createElement(u.a,null,i.a.createElement(y.a,{title:"Activate Free Trial",style:{backgroundColor:"#0e4553",color:"#fff"}}),i.a.createElement(b.a,null,i.a.createElement("p",{style:{margin:0,fontSize:12,marginTop:5,textAlign:"center"}},"Start your free trial today and enjoy full access to Land Diary's features. You will be charged R10.00 today. Then R",P.totalPrice||850," per month per farm, which is subject to change based on features you enable on landdiary."),i.a.createElement("h1",{style:{lineHeight:.8,color:"#39b54a",textAlign:"center",fontSize:35}},i.a.createElement("sup",null,"R"),"10"),i.a.createElement("h5",{style:{textAlign:"center"}},"Just a heads-up! Your next billing date will come up on: ",s.toDateString()),i.a.createElement(g.a,{container:!0,xs:12,sm:12,md:12,lg:12,xl:12,alignItems:"flex-start"},i.a.createElement("form",{style:{width:"100%",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"},name:"form",id:"sub-form",method:"POST",action:"https://paynow.netcash.co.za/site/paynow.aspx"},i.a.createElement("input",{type:"text",hidden:!0,name:"m1",value:"02586e4b-6f53-4bc1-8adb-98cdccabe091"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m2",value:"24ade73c-98cf-47b3-99be-cc7b867b3080"}),i.a.createElement("input",{type:"text",hidden:!0,name:"p2",value:D}),i.a.createElement("input",{type:"text",hidden:!0,name:"p3",value:"Land-diary subscription"}),i.a.createElement("input",{type:"text",hidden:!0,name:"p4",value:"10"}),i.a.createElement("input",{type:"text",hidden:!0,name:"Budget",value:"Y"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m4",value:C}),i.a.createElement("input",{type:"text",hidden:!0,name:"m5",value:m.userId}),i.a.createElement("input",{type:"text",hidden:!0,name:"m6",value:m.email}),i.a.createElement("input",{type:"text",hidden:!0,name:"m9",value:m.email}),i.a.createElement(zt.a,{fullWidth:!0,margin:"normal",required:!0,type:"text",label:"Contact Number",onChange:e=>{T({...w,[e.target.name]:e.target.value})},name:"m11",id:"m11",InputLabelProps:{shrink:!0}}),i.a.createElement("input",{type:"text",hidden:!0,name:"m14",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m16",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m17",value:"12"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m18",value:"1"}),i.a.createElement("input",{type:"text",hidden:!0,name:"m19",value:x}),i.a.createElement("input",{type:"text",hidden:!0,name:"m20",value:P.totalPrice||850}),i.a.createElement(Ct.a,{name:"submit",type:"submit",style:{marginTop:20,width:"40%"},variant:"contained",color:"primary"},"Subscribe")))),i.a.createElement(f.a,{style:{display:"flex",flexDirection:"column",justifyContent:"center"}},i.a.createElement("p",{style:{margin:0,fontSize:12,marginTop:5,textAlign:"center"}},"You'll be redirected to a secure payment gateway to complete subscription"))))))},Ky=a(854),Hy=a.n(Ky);var qy=e=>i.a.createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",backgroundColor:"#fff",height:"80vh"}},i.a.createElement("img",{src:Hy.a,alt:"land-diary",style:{}}),i.a.createElement("h2",null," All set up !"),i.a.createElement("p",null,"Your account has been activated, you can cancel your subscription anytime in settings."),i.a.createElement("p",{style:{margin:0,fontSize:12}},"Great news! You can now explore our help files and find everything you need to get the most out of Land Diary."),i.a.createElement(Ry.Link,{to:"documents",style:{marginTop:10}},i.a.createElement(Ct.a,{variant:"outlined"},"Help Files"))),Vy=a(855),jy=a.n(Vy);var $y=e=>i.a.createElement("div",{style:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",backgroundColor:"#fff",height:"80vh"}},i.a.createElement("img",{src:jy.a,height:"30%",alt:"land-diary",style:{}}),i.a.createElement("h2",null," Ops!! Something went wrong. "),i.a.createElement("p",null,"Your subscription failed to complete successfully"),i.a.createElement("p",{style:{margin:0,fontSize:12}},"Check your card details and maybe try again later."),i.a.createElement(Ry.Link,{to:"subscription",style:{marginTop:10}},i.a.createElement(Ct.a,{variant:"outlined"},"Back"))),Yy=({childProps:e})=>i.a.createElement(c.Switch,null,i.a.createElement(p,{path:"/",exact:!0,component:Zr,props:e})," ",i.a.createElement(p,{path:"/records",exact:!0,component:vv,props:e}),i.a.createElement(h,{path:"/login",exact:!0,component:rl,props:e}),i.a.createElement(h,{path:"/signup",exact:!0,component:ul,props:e}),i.a.createElement(h,{path:"/login/reset",exact:!0,component:vl,props:e}),i.a.createElement(h,{path:"/login/changePassword",exact:!0,component:fl,props:e}),i.a.createElement(m,{path:"/version",exact:!0,component:Zb,props:e}),i.a.createElement(p,{path:"/documents",exact:!0,component:Vu,props:e}),i.a.createElement(p,{path:"/subscription",exact:!0,component:Uy,props:e}),i.a.createElement(p,{path:"/activate-trial",exact:!0,component:zy,props:e}),i.a.createElement(p,{path:"/activate-subscription",exact:!0,component:My,props:e}),i.a.createElement(p,{path:"/subscription-success",exact:!0,component:qy,props:e}),i.a.createElement(p,{path:"/subscription-failed",exact:!0,component:$y,props:e}),i.a.createElement(p,{path:"/dashboard",exact:!0,component:Db,props:e}),i.a.createElement(p,{path:"/inventory",exact:!0,component:$b,props:e}),i.a.createElement(p,{path:"/messages",exact:!0,component:ac,props:e}),i.a.createElement(p,{path:"/settings",exact:!0,component:Xo,props:e}),i.a.createElement(p,{path:"/admin",exact:!0,component:fy,props:e}),i.a.createElement(p,{path:"/census",exact:!0,component:Oy,props:e}),i.a.createElement(p,{path:"/location",exact:!0,component:Gy,props:e}),i.a.createElement(m,{component:Yu,props:e}));var _y=Object(v.a)(e=>({modal:{display:"none",position:"fixed",zIndex:"10040 !important",paddingTop:"100px",left:0,top:0,width:"100%",height:"100%",overflow:"auto",backgroundColor:"rgba(0,0,0,0.4)"},modalContent:{backgroundColor:"#fefefe",margin:"auto",padding:"20px",border:"1px solid #888",width:"80%",borderRadius:"8px"},close:{color:"#aaaaaa",float:"right",fontSize:"28px",fontWeight:"bold",padding:"3px,"},button:{margin:e.spacing(1)},buttonParent:{display:"flex",alignItem:"center",justifyContent:"center"},labelParent:{display:"flex",alignItem:"center",justifyContent:"center"}}),{withTheme:!0})((function(e){const{classes:t}=e;return i.a.createElement("div",{id:"updateModal",className:t.modal},i.a.createElement("div",{className:t.modalContent},i.a.createElement("div",{className:t.labelParent},i.a.createElement("p",null,"Land Diary has been updated. Use the new version now?")),i.a.createElement("div",{className:t.buttonParent},i.a.createElement(Ct.a,{variant:"contained",color:"primary",id:"modalAccept",className:t.button},"Update now"),i.a.createElement(Ct.a,{variant:"contained",color:"secondary",id:"modalDismiss",className:t.button},"No, Later"))))})),Zy=a(445),Jy=a.n(Zy),Qy=a(857),Xy=a.n(Qy),ef=a(671),tf=a(858),af=a.n(tf),nf=a(856),rf=a.n(nf),lf=a(401);function sf(e){const[t,a]=i.a.useState(null),n=()=>{a(null)};return i.a.createElement("div",null,i.a.createElement(I.a,{key:"5a",title:e.userName+" click to logout"},i.a.createElement(Ct.a,{color:"inherit",onClick:e=>{a(e.currentTarget)}},i.a.createElement(Ae,{key:"6a",userKey:e.userKey,name:e.userName}))),i.a.createElement(lf.a,{id:"simple-menu",anchorEl:t,keepMounted:!0,open:Boolean(t),onClose:n},i.a.createElement(ef.a,{onClick:n},"Profile"),i.a.createElement(ef.a,{onClick:e.handleLogout},"Logout")))}class of extends i.a.Component{constructor(e){super(e),this.handleChange=async e=>{const{getFromGlobalState:t,refreshState:a,sync:n}=this.props,i=e.target.value,r=t("activeSite");e.target.value!==r&&(await a(i),await n(i))},this.goBack=this.goBack.bind(this)}pathToHeader(e){switch(e){case"/":return"Blocks";default:{const t=e.substring(1,e.lenth);return t.charAt(0).toUpperCase()+t.slice(1)}}}goBack(){const{history:e}=this.props;e.goBack()}render(){var e;const{classes:t,isAuthenticated:a,handleLogout:n,getFromGlobalState:r,online:l,handleDrawerToggle:o,location:{pathname:c},industryView:d}=this.props;let m=r("siteList");console.log("siteList",m),m=m.sort((e,t)=>(""+e.shortName).localeCompare(t.shortName,void 0,{numeric:!0})),m=m.filter(e=>!(null===e||void 0===e?void 0:e.isDisabled)||!0!==(null===e||void 0===e?void 0:e.isDisabled));const p=r("activeSite"),h=r("userDetail"),g=r("farm"),u=(g&&g[0]&&g[0].entityType&&g[0].entityType,h?h.sk:"none"),b=h?`${h.name} ${h.surname}`:"X X",v=r("users").find(e=>e.sk===u);return window.location.href.includes("settings")&&!(null===v||void 0===v||null===(e=v.rights)||void 0===e?void 0:e.changeSettings)&&(window.location.href="/"),i.a.createElement(kt.a,{position:"absolute",className:t.appBar},i.a.createElement(G.a,null,i.a.createElement(E.a,{color:"inherit","aria-label":"Open drawer",onClick:o,className:t.menuButton},i.a.createElement(Xy.a,null)),i.a.createElement("img",{style:{height:"50px",marginLeft:"30px"},src:rf.a,alt:"Logo"}),i.a.createElement(B.a,{key:"1a",variant:"overline",color:"inherit",noWrap:!0,className:t.title},`Version ${Yb.buildMajor}.${Yb.buildMinor}.${Yb.buildRevision}`),i.a.createElement(B.a,{key:"2a",variant:"h6",color:"inherit",noWrap:!0,className:t.location},this.pathToHeader(c)),!d&&i.a.createElement(i.a.Fragment,null,i.a.createElement(bn.a,{style:{color:"white"}},"Available farms"),i.a.createElement(vn.a,{className:t.formControl},i.a.createElement(Sn.a,{disableUnderline:!0,key:"3a",required:!0,value:p,onChange:this.handleChange,MenuProps:{classes:{paper:t.menuPaper}},inputProps:{name:"activeSite",id:"activeSite",classes:{nativeInput:t.selectP,select:t.selectP}}},m&&m.sort().map(e=>i.a.createElement("option",{key:null===e||void 0===e?void 0:e.sk,value:null===e||void 0===e?void 0:e.tenantId},"Main site"===(null===e||void 0===e?void 0:e.shortName)?null===e||void 0===e?void 0:e.shortName2:null===e||void 0===e?void 0:e.shortName," ","-",(null===e||void 0===e?void 0:e.entityType)?null===e||void 0===e?void 0:e.entityType.charAt(0).toUpperCase():"F"))))),l?i.a.createElement(af.a,{key:"4a",style:{color:"green",paddingRight:"15px"}}):i.a.createElement(W.a,{style:{paddingRight:"15px"},color:"error"}),a&&i.a.createElement(i.a.Fragment,null,!d&&i.a.createElement(ca,{key:"7a",role:h&&h.rights&&h.rights.changeSettings?"changeSettings":"noAccess",perform:"openSettingsPage",yes:()=>i.a.createElement(I.a,{key:"5b",title:"Access Settings"},i.a.createElement(E.a,{style:{color:"white"},disablegutters:!0,component:s.b,to:"/settings",selected:"/settings"===c},i.a.createElement(Jy.a,{color:"white"})))})),a&&i.a.createElement(sf,{userKey:u,userName:b,handleLogout:n}),!a&&i.a.createElement(i.a.Fragment,null,i.a.createElement(ef.a,{disabled:!0,key:"7a",component:s.b,to:"/signup"},"Sign Up"),i.a.createElement(ef.a,{key:"8a",component:s.b,to:"/login"},"Login"))))}}var cf=Object(v.a)(e=>({appBar:{zIndex:e.zIndex.drawer+1,position:"fixed",top:0,[e.breakpoints.down("xs")]:{display:"none"}},title:{minWidth:"90px",marginLeft:"30px"},location:{flexGrow:1,paddingLeft:"8px"},menuButton:{marginRight:20},formControl:{margin:e.spacing(1),backgroundColor:"white",borderRadius:"5px",minWidth:120,boxShadow:"none"},select:{"&:before":{borderColor:"white"},"&:after":{borderColor:"white"}},selected:{color:e.palette.secondary.main},icon:{fill:"white",color:"inherit"},input:{color:"white"},selectP:{paddingLeft:"8px"},item:{color:"inherit"},menuPaper:{maxHeight:250,paddingLeft:"8px",paddingRight:"8px",cursor:"pointer",overflowX:"scroll"}}),{withTheme:!0})(of),df=a(859),mf=a.n(df),pf=a(863),hf=a.n(pf),gf=a(860),uf=a.n(gf),bf=a(861),vf=a.n(bf),yf=a(446),ff=a.n(yf),Ef=a(862),Sf=a.n(Ef),Cf=a(1768),xf=a(1769);class kf extends i.a.Component{constructor(e){super(e),this.onOpenMenu=e=>{this.setState({anchorEl:e.currentTarget})},this.handleLocalLogout=()=>{const{handleLogout:e}=this.props;e(),this.handleClose()},this.handleClose=()=>{this.setState({anchorEl:null})},this.goBack=this.goBack.bind(this),this.state={anchorEl:null}}goBack(){const{history:e}=this.props;e.goBack()}render(){const{classes:e,history:t,userDetail:a,isAuthenticated:n,online:r,location:{pathname:l},getFromGlobalState:o}=this.props,c=o("farm"),d=o("siteList"),m=(1===d.length&&d[0].isNewAccount,!!(c&&c[0]&&c[0].entityType&&"entity"===c[0].entityType)),{anchorEl:p}=this.state,h=Boolean(p);return i.a.createElement(kt.a,{color:"primary",position:"absolute",className:e.appBar},i.a.createElement(G.a,{className:e.toolbar},n&&i.a.createElement(Cf.a,{classes:{root:e.bottomnav},value:l},!r&&i.a.createElement(W.a,{style:{position:"fixed",bottom:"auto",zIndex:"100",right:"3px",top:"0px",left:"auto"},color:"error"}),i.a.createElement(xf.a,{disabled:"/"===t.location.pathname,onClick:this.goBack,label:"Back",classes:{root:e.navAction},value:"/back",icon:i.a.createElement(mf.a,null)}),!m&&i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"Blocks",value:"/",component:s.b,to:"/",icon:i.a.createElement(uf.a,null)}),!m&&i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"Records",value:"/records",disabled:m,component:s.b,to:"/records",icon:i.a.createElement(ff.a,null)}),i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"Locate",value:"/location",component:s.b,to:"/location",icon:i.a.createElement(Li.a,null)}),!m&&i.a.createElement(ca,{role:a&&a.rights&&a.rights.viewDashboard?"viewDashboard":"noAccess",perform:"viewDashboard",isAdministrator:a&&a.rights&&a.rights.administrator,yes:()=>i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"Stats",value:"/dashboard",disabled:m,component:s.b,to:"/dashboard",icon:i.a.createElement(vf.a,null)}),no:()=>null}),!m&&i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"Inventory",value:"/inventory",disabled:m,component:s.b,to:"/inventory",icon:i.a.createElement(Sf.a,null)}),i.a.createElement(xf.a,{classes:{selected:e.selected,root:e.navAction},label:"More",value:"more",onClick:this.onOpenMenu,icon:i.a.createElement(hf.a,null)})),i.a.createElement(lf.a,{id:"long-menu",anchorEl:p,keepMounted:!0,open:h,anchorOrigin:{vertical:"bottom",horizontal:"center"},transformOrigin:{vertical:"top",horizontal:"center"},onClose:this.handleClose,PaperProps:{style:{width:200}}},i.a.createElement(ef.a,{component:s.b,to:"/version",onClick:this.handleClose},"About"),n&&i.a.createElement("div",null,i.a.createElement(ca,{role:a&&a.rights&&a.rights.changeSettings?"changeSettings":"noAccess",perform:"openDocumentsPage",yes:()=>i.a.createElement(ef.a,{component:s.b,to:"/documents",onClick:this.handleClose},"Documents")}),i.a.createElement(ca,{role:a&&a.rights&&a.rights.mangeInventory?"mangeInventory":"noAccess",perform:"openInventoryPage",yes:()=>i.a.createElement(ef.a,{disabled:!0,component:s.b,to:"/inventory",onClick:this.handleClose},"Inventory")}),i.a.createElement(ef.a,{component:s.b,to:"/messages",onClick:this.handleClose},"Messages")),n?i.a.createElement(i.a.Fragment,null," ",i.a.createElement(ju.a,null)," ",i.a.createElement(ca,{role:a&&a.rights&&a.rights.changeSettings?"changeSettings":"noAccess",perform:"openSettingsPage",yes:()=>i.a.createElement(ef.a,{component:s.b,to:"/settings",onClick:this.handleClose},"Settings")}),i.a.createElement(ef.a,{color:"inherit",onClick:this.handleLocalLogout,disabled:!r},"Logout")):i.a.createElement("div",null,i.a.createElement(ef.a,{disabled:!0,component:s.b,to:"/signup",onClick:this.handleClose},"Sign Up"),i.a.createElement(ef.a,{component:s.b,to:"/login",onClick:this.handleClose},"Login")),n&&a&&a.rights&&a.rights.ldadmin&&i.a.createElement(i.a.Fragment,null,i.a.createElement(ju.a,null),i.a.createElement(ef.a,{component:s.b,to:"/admin",onClick:this.handleClose},"Admin")))))}}var wf=Object(v.a)(e=>({appBar:{position:"fixed",top:"auto",bottom:0,[e.breakpoints.up("sm")]:{display:"none"}},bottomnav:{color:"inherit",backgroundColor:"inherit"},navAction:{color:"inherit",backgroundColor:"inherit",paddingLeft:"0px",paddingRight:"0px",minWidth:"65px"},toolbar:{color:"inherit",backgroundColor:"inherit",paddingLeft:"0px",paddingRight:"0px",justifyContent:"center"},icon:{color:"inherit"},button:{},buttonMore:{},selected:{color:e.palette.secondary.main+" !important"},disabled:{color:"#c2c2c2 !important"}}),{withTheme:!0})(kf),Tf=a(146),Df=a(864),Pf=a.n(Df),Ff=a(865),Nf=a.n(Ff),Bf=a(585),Lf=a.n(Bf),Af=a(868),Of=a.n(Af),If=a(867),Gf=a.n(If),Rf=a(586),Uf=a.n(Rf),Mf=a(866),Wf=a.n(Mf),zf=a(1707);const Kf=Object(v.a)(e=>({badge:{top:"30%",right:-15,color:e.palette.secondary.main,border:"1px solid "+e.palette.secondary.main}}))(di.a);class Hf extends i.a.Component{render(){const{classes:e,theme:t,mobileopen:a,handleDrawerToggle:n,userDetail:r,online:l,data:o,industryView:c,getFromGlobalState:d,location:{pathname:m},isAuthenticated:p,handleLogout:h}=this.props,g=d("farm"),u=d("siteList"),b=(1===u.length&&u[0].isNewAccount,!!(g&&g[0]&&g[0].entityType&&"entity"===g[0].entityType)),v=i.a.createElement("div",null,i.a.createElement(Bt.a,{xsDown:!0},i.a.createElement("div",{className:e.toolbar})),i.a.createElement(zf.a,{className:e.menuList},p&&!c&&i.a.createElement(i.a.Fragment,null," ",!b&&i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/",selected:"/"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Pf.a,{color:"inherit"})),"Blocks"),!b&&i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,onClick:n,to:"/records",selected:"/records"===m},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(ff.a,{color:"inherit"})),"Records"),i.a.createElement(ca,{role:r&&r.rights&&r.rights.viewDashboard?"viewDashboard":"noAccess",perform:"viewDashboard",isAdministrator:r&&r.rights&&r.rights.administrator,yes:()=>!b&&i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/dashboard",selected:"/dashboard"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Nf.a,{color:"inherit"})),"Dashboard")}),i.a.createElement(ca,{role:r&&r.rights&&r.rights.manageInventory?"manageInventory":"noAccess",perform:"openInventoryPage",yes:()=>!b&&i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/inventory",selected:"/inventory"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Lf.a,{color:"inherit"})),"Inventory")}),i.a.createElement(ca,{role:r&&r.rights&&r.rights.changeSettings?"changeSettings":"noAccess",perform:"openDocumentsPage",yes:()=>i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/documents",selected:"/documents"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Uf.a,{color:"inherit"})),"Documents")}),c&&!b&&i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/census",selected:"/census"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Uf.a,{color:"inherit"})),"Census"),i.a.createElement(ca,{role:r&&r.rights&&r.rights.changeSettings?"changeSettings":"noAccess",perform:"openSettingsPage",yes:()=>i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/settings",selected:"/settings"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Jy.a,{color:"inherit"})),"Settings")})),i.a.createElement(ju.a,null),p?i.a.createElement(i.a.Fragment,null,i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/messages",selected:"/messages"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Wf.a,{color:"inherit"})),i.a.createElement(Kf,{invisible:!o||!o.messages||o.messages.length<=0,color:"primary",badgeContent:o&&o.messages&&o.messages.length},"Messages")),i.a.createElement(ef.a,{classes:{selected:e.selected},onClick:h,disabled:!l},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Xr.a,{color:"inherit"})),"Logout")):i.a.createElement(i.a.Fragment,null,i.a.createElement(ef.a,{disabled:!0,component:s.b,to:"/signup"},i.a.createElement(ji.a,null,i.a.createElement(Gf.a,{color:"default"})),"Sign Up"),i.a.createElement(ef.a,{component:s.b,to:"/login",classes:{selected:e.selected}},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Of.a,{color:"inherit"})),"Login")),!c&&i.a.createElement(ef.a,{component:s.b,to:"/version",classes:{selected:e.selected},selected:"/version"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Kn.a,{color:"inherit"})),"About"),p&&r&&r.rights&&r.rights.ldadmin&&i.a.createElement(i.a.Fragment,null,i.a.createElement(ju.a,null),i.a.createElement(ef.a,{classes:{selected:e.selected},component:s.b,to:"/admin",selected:"/admin"===m,onClick:n},i.a.createElement(ji.a,{className:e.icon},i.a.createElement(Lf.a,{color:"inherit"})),"Admin"))));return i.a.createElement("nav",{className:e.drawer},i.a.createElement(Bt.a,{smUp:!0,implementation:"css"},i.a.createElement(Tf.a,{variant:"temporary",anchor:"rtl"===t.direction?"right":"left",open:a,onClose:n,classes:{paper:e.drawerPaper},onClick:n},v)),i.a.createElement(Bt.a,{xsDown:!0,implementation:"css"},i.a.createElement(Tf.a,{classes:{paper:e.drawerPaper},variant:"persistent",open:a},v)))}}var qf=Object(v.a)(e=>({drawer:{[e.breakpoints.up("sm")]:{width:240,flexShrink:0}},badgePadding:{},toolbar:e.mixins.toolbar,drawerPaper:{width:240,backgroundColor:e.palette.primary.main,color:"white"},menuList:{paddingTop:"30px",paddingBottom:"0px",color:"inherit"},selected:{color:e.palette.secondary.main},icon:{color:"inherit"}}),{withTheme:!0})(Hf);class Vf extends i.a.Component{constructor(e){super(e),this.setSnackClose=()=>{const{setSnack:e}=this.props;e({open:!1,messageText:" ",variant:"info"})},this.handleDrawerToggle=e=>{this.setState(e=>({mobileopen:!e.mobileopen})),e.stopPropagation()},this.handleDrawerClose=e=>{const{mobileopen:t}=this.state;t&&(this.setState(e=>({mobileopen:!e.mobileopen})),e.stopPropagation())},this.state={mobileopen:!1}}render(){const{classes:e,children:t,location:a,handleLogout:n,reload:r,history:l,snack:s,online:o,getFromGlobalState:c,setGlobalState:d,refreshState:m,sync:p,userDetail:h,industryView:g,isMobile:u}=this.props,{mobileopen:b}=this.state,v=c("isAuthenticated");return i.a.createElement("div",{className:e.root,onClick:this.handleDrawerClose},i.a.createElement(cf,{online:o,location:a,isAuthenticated:v,reload:r,isMobile:u,history:l,handleLogout:n,handleDrawerToggle:this.handleDrawerToggle,getFromGlobalState:c,setGlobalState:d,refreshState:m,industryView:g,sync:p}),i.a.createElement(wf,{online:o,location:a,isAuthenticated:v,reload:r,history:l,isMobile:u,handleLogout:n,getFromGlobalState:c,setGlobalState:d,refreshState:m,userDetail:h,sync:p}),i.a.createElement(qf,{online:o,handleDrawerToggle:this.handleDrawerToggle,mobileopen:b,location:a,className:e.drawer,isMobile:u,isAuthenticated:v,handleLogout:n,userDetail:h,industryView:g,getFromGlobalState:c,data:{messages:c("invites")}}),i.a.createElement("main",{className:e.content},i.a.createElement("div",{className:e.toolbarSpacer}),t,i.a.createElement(_y,null),i.a.createElement(ia,{open:s.open,setClose:this.setSnackClose,messageText:s.messageText,variant:s.variant,autoHideDuration:s.autoHideDuration?s.autoHideDuration:void 0})))}}var jf=Object(ln.a)(c.withRouter,Object(v.a)(e=>({root:{height:"100%",[e.breakpoints.up("sm")]:{display:"flex"}},toolbarSpacer:{minHeight:"56px",display:"block",[e.breakpoints.down("xs")]:{display:"none"}},content:{flexGrow:1,padding:e.spacing(3),marginBottom:e.spacing(12),overflow:"hidden",[e.breakpoints.up("sm")]:{transition:e.transitions.create("margin",{easing:e.transitions.easing.sharp,duration:e.transitions.duration.leavingScreen}),marginLeft:-240},backgroundColor:"inherit"},drawer:{[e.breakpoints.down("sm")]:{display:"none"}}})))(Vf),$f=a(232);var Yf=Object($f.b)({palette:{primary:{main:"#0e4553"},secondary:{main:"#63c7c8"}},typography:{useNextVariants:!0}});class _f extends i.a.Component{constructor(e){super(e),this.state={error:null,errorInfo:null}}componentDidCatch(e,t){this.setState({error:e,errorInfo:t})}render(){const{errorInfo:e,error:t}=this.state,{children:a}=this.props;return e?i.a.createElement("div",null,i.a.createElement("h2",null,"Something went wrong."),i.a.createElement("details",{style:{whiteSpace:"pre-wrap"}},t&&t.toString(),i.a.createElement("br",null),e.componentStack)):a}}a(1696);class Zf extends n.Component{constructor(e){super(e),this.connectionChange=e=>{const t=navigator.connection||navigator.mozConnection||navigator.webkitConnection,a=`effectiveType ${t.effectiveType} downlink ${t.downlink} rtt ${t.rtt}`;alert(a)},this.updateOnlineStatus=()=>{const e=!!navigator.onLine;this.setState({online:e})},this.sync=async e=>{if(this.state.isAuthenticated){this.setState({synchronising:!0});try{this.setSnack({open:!0,variant:"info",messageText:"Synchronising.."});const t=await Na(this.state.currentUser.username,"farms",e);let a=!1;if(t.records&&t.records.industryView){if(t.records.invites&&t.records.invites.status&&t.records.invites.result){const e=await ga(t.records.invites.result);this.setState({invites:e.invites})}a=!0}if(!a&&t.status){const a=await ga(t.records),n=a.users&&a.users.find(e=>(null===e||void 0===e?void 0:e.email)===this.state.tp.attributes.email);n||console.log("could not find user detail in activesite"),e&&""!==e&&"default"!==e||(e=a.activeSite),this.setState({loading:!1,allfarms:a.allFarms,blocks:a.blocks,crops:a.crops,farm:a.farm,chemicals:a.chemicals,fertilisers:a.fertilisers,pests:a.pests,monitorings:a.monitorings,monitoringsOther:a.monitoringsOther,irrigations:a.irrigations,chemequips:a.chemequips,harvestequips:a.harvestequips,clusters:a.clusters,packequips:a.packequips,operators:a.operators,agronomistActs:a.agronomistActs,inv_chemical:a.inv_chemical,inv_fertiliser:a.inv_fertiliser,users:a.users,invites:a.invites,sentInvites:a.sentInvites,sentSharedInvites:a.sentSharedInvites,folders:a.folders,files:a.files,farms:a.farms,siteList:a.siteList&&a.siteList.length>0?a.siteList:this.state.siteList,activeSite:""!==e?e:a.activeSite,userDetail:n,myGenCrops:a.myGenCrops,genVarieties:a.genVarieties,targetsTypesSetting:a.targetsTypesSetting,cropTypesSetting:a.cropTypesSetting,cropsSetting:a.cropsSetting,productProcessorTypes:a.productProcessorTypes,productProcessors:a.productProcessors,filters:a.filters,myProductProcessors:a.myProductProcessors,facilities:a.facilities,apiKeys:a.apiKeys,combinations:a.combinations,transactions:a.transactions,subscription:a.subscription}),t.message?this.setSnack({open:!0,variant:"warning",messageText:t.message,autoHideDuration:3e3}):(this.setSnack({open:!1,variant:"info",messageText:""}),this.setState({online:!0}))}else a?(this.setSnack({open:!0,variant:"info",autoHideDuration:2e3,messageText:"Loading data"}),this.setState({synchronising:!1})):(this.setSnack({open:!0,variant:"info",autoHideDuration:2e3,messageText:"Poor connection working offline"}),this.setState({online:!1}));this.setState({synchronising:!1,industryView:a})}catch(s){var t,a,n,i,r,l;this.setState({synchronising:!1});const e=s.response?((null===(t=s.response.data)||void 0===t||null===(a=t.error)||void 0===a?void 0:a.message)?null===(n=s.response.data)||void 0===n||null===(i=n.error)||void 0===i?void 0:i.message:null===(r=s.response)||void 0===r||null===(l=r.data)||void 0===l?void 0:l.error)+" ":null===s||void 0===s?void 0:s.message;this.setSnack({open:!0,variant:"error",messageText:e}),this.setState({synchronising:!1})}}},this.userHasAuthenticated=async e=>{this.setState({isAuthenticated:e,isAuthenticating:!1,isLoading:!0});var t=this.state.activeSite;const a=await this.refreshState(t);this.setState({isLoading:!1}),await this.sync(a)},this.setGlobalState=e=>{this.setState(e)},this.setSnack=e=>{if(""===e.variant){}this.setState({snack:e})},this.getFromGlobalState=e=>this.state[e],this.reload=()=>{window.location.reload(!0)},this.handleLogout=async e=>{const{online:t}=this.state;t&&(await o.b.signOut(),this.setState(this.baseState),this.userHasAuthenticated(!1),this.setState({isLoading:!1,isAuthenticating:!1}),this.props.history.push("/login"))},this.state={loading:!0,snack:{open:!1,variant:"info",messageText:""},farmList:[],error:!1,isAuthenticated:!1,isAuthenticating:!0,isLoading:!1,synchronising:!1,industryView:!1,blocks:[],transactions:[],crops:[],farm:[],chemicals:[],fertilisers:[],pests:[],irrigations:[],chemequips:[],harvestequips:[],clusters:[],packequips:[],operators:[],agronomistActs:[],inv_chemical:[],inv_fertiliser:[],users:[],online:!0,currentUser:{},siteList:[],activeSite:"",farms:[],tp:null,userDetail:null,monitorings:[],monitoringsOther:[],cropTypes:[],cropsDetail:[],genCrops:[],genTargets:[],myGenCrops:[],genVarieties:[],targetsTypesSetting:[],cropTypesSetting:[],genFertilisers:[],cropsSetting:[],productProcessorTypes:[],apiKeys:[],allfarms:[],productProcessors:[],myProductProcessors:[],combinations:[],filters:[],facilities:[],isMobile:!1,targetDetail:{},census:null,imageUrls:{},filteredMetaData:{countries:[],provinces:[],regions:[],cropTypes:[],crops:[],varieties:[],cultivarTypes:[],cultivars:[],rootStockTypes:[],rootStocks:[]},metaData:{countries:[],provinces:[],regions:[],cropTypes:[],crops:[],varieties:[],cultivarTypes:[],cultivars:[],rootStockTypes:[],rootStocks:[]},selectedData:{countries:[],regions:[],provinces:[],cropTypes:[],crops:[],cultivarTypes:[],cultivars:[],rootStockTypes:[],rootStocks:[],irrigationTypes:[]},allStats:{farms:0,size:0,plantings:0,trees:0,sizeByCrop:{},set:!1},filteredStats:{farms:0,size:0,plantings:0,trees:0,set:!1}},this.baseState=this.state}async currentIdentity(){const e="CognitoIdentityServiceProvider.6io74e3s3ok97to2pk8uj9abic",t=localStorage.getItem(e+".LastAuthUser");if(null==t)return null;const a=localStorage.getItem(`${e}.${t}.idToken`);if(null==a)throw Error("Failed to read IdToken from cache!");const n=JSON.parse(atob(a.split(".")[1]));if(n.exp+Number(localStorage.getItem(`${e}.${t}.clockDrift`)||0)(null===e||void 0===e?void 0:e.email)===this.state.tp.attributes.email);i||console.log("could not find user detail"),this.setState({blocks:n.blocks,crops:n.crops,farm:n.farm,chemicals:n.chemicals,fertilisers:n.fertilisers,pests:n.pests,monitorings:n.monitorings,monitoringsOther:n.monitoringsOther,irrigations:n.irrigations,chemequips:n.chemequips,harvestequips:n.harvestequips,clusters:n.clusters,packequips:n.packequips,operators:n.operators?n.operators:[],agronomistActs:n.agronomistActs?n.agronomistActs:[],inv_chemical:n.inv_chemical,inv_fertiliser:n.inv_fertiliser,users:n.users,invites:n.invites,folders:n.folders,files:n.files,sentInvites:n.sentInvites,sentSharedInvites:n.sentSharedInvites,activeSite:""!==e?e:n.activeSite,siteList:n.siteList,userDetail:i,myGenCrops:n.myGenCrops,genVarieties:n.genVarieties,targetsTypesSetting:n.targetsTypesSetting,cropTypesSetting:n.cropTypesSetting,cropsSetting:n.cropsSetting,facilities:n.facilities,productProcessorTypes:n.productProcessorTypes,productProcessors:n.productProcessors,filters:n.filters,myProductProcessors:n.myProductProcessors,activeSite:e,apiKeys:n.apiKeys,combinations:n.combinations,transactions:n.transactions,subscription:n.subscription}),console.timeEnd("timer")}catch(t){this.setSnack({open:!0,variant:"error",messageText:t.response?(t.response.data.error.message?t.response.data.error.message:t.response.data.error)+" ":t.message})}return e}async refreshIndustryView(){const{isAuthenticated:e}=this.state}render(){const e=this.getFromGlobalState("farm"),t=(this.getFromGlobalState("siteList").length,!!(e&&e[0]&&e[0].entityType&&"entity"===e[0].entityType)),a={isAuthenticated:this.state.isAuthenticated,userHasAuthenticated:this.userHasAuthenticated,setUserFarmId:this.setUserFarmId,setGlobalState:this.setGlobalState,getFromGlobalState:this.getFromGlobalState,farmId:this.state.farmId,reload:this.reload,refreshState:this.refreshState.bind(this),sync:this.sync.bind(this),setSnack:this.setSnack,snack:this.state.snack,isEntity:t,online:this.state.online,activeSite:this.state.activeSite,userDetail:this.state.userDetail,isMobile:this.state.isMobile,industryView:this.state.industryView};return i.a.createElement(_f,null,i.a.createElement(d.a,{theme:Yf},i.a.createElement(N,{isloading:this.state.isLoading||this.state.isAuthenticating},!(this.state.isAuthenticating||this.state.isLoading)&&i.a.createElement(jf,{industryView:a.industryView,isMobile:a.isMobile,isAuthenticated:a.isAuthenticated,userDetail:a.userDetail,sync:a.sync,refreshState:a.refreshState,online:a.online,reload:this.reload,setGlobalState:this.setGlobalState,getFromGlobalState:this.getFromGlobalState,snack:a.snack,setSnack:a.setSnack,handleLogout:this.handleLogout},i.a.createElement(Yy,{childProps:a})))))}}var Jf=Object(c.withRouter)(Zf);const Qf=Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));function Xf(e,t){navigator.serviceWorker.register(e).then(e=>{e.onupdatefound=()=>{const a=e.installing;null!=a&&(a.onstatechange=()=>{if("activated"===a.state&&(document.getElementById("updateModal").style.display="none",window.location.reload()),"installed"===a.state)if(navigator.serviceWorker.controller){var n=document.getElementById("updateModal");n.style.display="block";var i=document.getElementById("modalAccept"),r=document.getElementById("modalDismiss");i.addEventListener("click",(function(){a.postMessage({type:"SKIP_WAITING"})})),r.addEventListener("click",(function(){n.style.display="none"})),console.log("New content is available and will be used when all tabs for this page are closed. See https://bit.ly/CRA-PWA.V67.0017"),t&&t.onUpdate&&t.onUpdate(e)}else console.log("Content is cached for offline use."),t&&t.onSuccess&&t.onSuccess(e)})}}).catch(e=>{console.error("Error during service worker registration:",e)})}var eE={REGION:"us-east-1",BUCKET:"dev-landdiary-attachmentsbucket"},tE={REGION:"us-east-1",URL:"https://y6b6vsydqb.execute-api.us-east-1.amazonaws.com/dev"},aE={REGION:"us-east-1",USER_POOL_ID:"us-east-1_PTcEgtyOT",APP_CLIENT_ID:"6io74e3s3ok97to2pk8uj9abic",IDENTITY_POOL_ID:"us-east-1:a92a9302-d01d-4020-affb-6fa37d28d67b"};o.d.configure({Auth:{mandatorySignIn:!0,region:aE.REGION,userPoolId:aE.USER_POOL_ID,identityPoolId:aE.IDENTITY_POOL_ID,userPoolWebClientId:aE.APP_CLIENT_ID},Storage:{region:eE.REGION,bucket:eE.BUCKET,identityPoolId:aE.IDENTITY_POOL_ID},API:{endpoints:[{name:"farms",endpoint:tE.URL,region:tE.REGION}]}}),l.a.render(i.a.createElement(s.a,null,i.a.createElement(Jf,null)),document.getElementById("root")),function(e){if("serviceWorker"in navigator){if(new URL("",window.location.href).origin!==window.location.origin)return;window.addEventListener("load",()=>{const t="/service-worker.js";Qf?(!function(e,t){fetch(e).then(a=>{const n=a.headers.get("content-type");404===a.status||null!=n&&-1===n.indexOf("javascript")?navigator.serviceWorker.ready.then(e=>{e.unregister().then(()=>{window.location.reload()})}):Xf(e,t)}).catch(()=>{console.log("No internet connection found. App is running in offline mode.")})}(t,e),navigator.serviceWorker.ready.then(()=>{console.log("This web app is being served cache-first by a service worker. To learn more, visit https://bit.ly/CRA-PWAV67.0017")})):Xf(t,e)})}}()},174:function(e,t){e.exports="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUsAAAElCAYAAABtScC0AAAACXBIWXMAAAsSAAALEgHS3X78AAAgAElEQVR4nO2dXW8c13nHz5FISmocU/GtUZBq4QI1ipJOgzRA0nLVuElQFCCFoFctytUn0OqqwKK7XO42i6BFIQooetEbLe+DmPwEJq+aoihEXvSiL4DIBjaaxHBEJFXa2PIpDvUMNVztzJw558zMefn/jIVleWd3ZnbmP8/74UIIBgAAIBvO+U2IJQAAFMA5P7iCkwQAANlwzieMsTWIJQAAZEBCuSn/L8QSAABmkBZKyRxOEgAAvEQmcxhjUijX038PsQQAAIKE8oAxtjJ9TuCGAwDAC6FcZYydzBJKBrEEAIBzoWwzxh4zxhazTgfEEgAQLefF5i8SOY+KzgFilgCAKCG3e5Lldk8DyxIAEB2c8w653UpCyWBZAgBigrLde7Ijp+xhw7IEAEQB53yDst2lhZLBsgQAhE5WkXlZYFkCAIIlZU0aCSWDZQkACBFb1mQaWJYAgKCgTLcVazINLEsAQBBQ3eSObgKnCIglAMBryOWW1uRWlccBsQQAeAslcKQ1uVT1MUAsAQDewTlfJpG0GpfMA2IJgCLD0VhaMU/7ve4BzlkzpFzuTt6EoCpANhwAdWQC4f3haHwwHI1bOG/1Qi73EcUmaxVKBrEEQIs1iGZ9yCy3XIqWMfZeHbHJLCCWAOgD0ayQ1KzJx1WVA5UBYgmAORBNy3DOB1RYvlnrF+cAsQTAHhBNQ+TyDpzzk6biknlALAGwTyKae8PReBnntxjOeYviko8qjkseM8be0dkQYglAdcgawCfD0XgC0ZyNrJfknMthvO/XEJd8yBhrCSGOdDaGWAJQPZsQzcuQSMrkzZMaCstPGWO3hRAdIcRT3Q+BWAJQH9GL5pRI1pG8kdbkqhDCuJEAYglA/UQnmg2I5LENazINxBKA5gheNKlWclCjSJ4xxu4LIaxYk2kglgA0T1o0b4bye6SG8FY6Oi3FLmNsWQixU8WHQywBcAcpmifD0Xjgs2hSe6LMOD+oqVbyUJYDCSHatlzuWUAsAXCLRbLEvBRNcrlle+JKDV+XZLm1y4HKALEEwE28Ek2KTR7U5HJLkbwrhFi2HZfMA2IJgNs4L5q09s1JDUXlaZGcVPxdrwCxBMAPnBRN2ctNbneVsUmZ4d6mesnaRTIBYgmAXzgjmiSUjyr8ikQkpSU5qDJ5owLEEgA/SYtmu+4jqFgonRLJBIglAH4jRfPRcDSuTTQrFEonRTIBYglAGCzVIZq0Dk4VQrlLMUnnRDIBYglAtTwka+mspvNcmWhS1tt2gkWK5C0qKD+x/NlWgVgCUC1y6VxZqL3ss2jSErQTi1lvb0QyAWIJQA30e13fRXNgqSvn0DeRTIBYAlAjjojmRpkN5ZIPjLF7ht9/RgXlLd9EMgFiCUADNCya75VcVM10is8xLefQWEG5DSCWADRISjRXKY5XF0orUVKZkIn7fWyy7o1LQCwBcIB+r3vS73WlMN1yTDQHBp+dCKWTpUBlgVgC4BAuiSZZlbrL0gYllAxiCYCbuCCab7zxRkfzM2T8tdJBvE0AsQTAYZoSzWfPnq19/PHHurHKQQgxymkglgB4QN2i+eGHH+hueljVGjhNA7EEwCPqEs3/+Pd/093UJCHkNBBLADykStH85JNP2A9+8I86mx7WucxD3UAsAfCYKkTzo49+ortpkO53AsQSgACwKZpPf/pTnc3OhBB7IV9LEEsAAmJKNPd1juzk5InOZkELJYNYAhAmJJpyYMZtmvSjzA9/+F865yTYWGUCxBKAgOn3ugf9XrdVRjQ/+ECrbAhiCQDwH1XRfPbsmdax+jp2rQwQSwAiokg0nz37n9In49atX/t5DGcQYglAhOi451m89tprn8ZwBiGWAESMTdEMnbnYTwAA4IVoypFqf/pnf/5dxthfhHxKOOfLOtvBsgQAXPC/v/jFf0dwNnTE8hBiCQCIDdW1hy4BsQQAxIaOWB5ALAEA0cA5v0nT4MtyArEEAMREqTXTUxxBLAEAMdHWOFY5UQliCQCIA855S9MFP5+oBLEEAMSC7pIX50NCIJYAgOChNdB1rEoGyxIAEAXUsaO75MV+sv45xBIAEDrSMlzUPMZJ8geIJQAgWDjnUuxWNI/vNL2uEMQSABAkJJSbBsd2KSEEsQQABIXs0rEglNKqnKT/AiPaAADBwDlfpTijruud8ErxOixLAEAQcM47VBNpKpQyA/7KAmywLAEAXkM1lDK+uGThOM6yWiIhlgAAL6H2xYklkUzYSOoqp4EbDgDwCimSnHPpJr9vWSjvz3K/E2BZAgC8gCzJgUHbYh67QojcLh+IJQDAaSoWSUZCWTi6DWIJAHAS6umeVCiSTFUoGWKWAADXkCJJReVPXBFKBrEEALjClEiadN+osF1GKBnccABA05C7PahBIFlSR5kekKEKxBIA0Ai00qLsutmq6fuPqY7yRGdjuOEAgNrhnEtL8qRGoZRu96quUDJYlgCAOuGcb9DUcpvF5HkcktutLZIJsCwBAJUjpwFR1817NQnlKWPsjhCiZUMoGcQSAFAlNFtSWpKPKy4DSpAieVcIsayTxMkDbjgAoBJqdrmlSA6mB/baBGIJALAKZbmlaK3XcGZlKVCnSpFMgFgCAKxB1uTEYDVFVc7Iat3JGqlmG4glAMCYGq3J2kUyAWIJADDiRz/60XXG2FHFscnGRDIBYgkAMOLHPz4XyyqFcpeSN1ZKgHSBWAIAXOWQRDJzenmdQCwBAK5xShluq3WSpkAsAQCu0HhcMg908ABQLVvD0XgyHI2XcZ5z2WeMyUEXAxeFkkEsAagFOafxCURzJtLlvi2E0B6dVhcQSwDqA6L5kjMam7bsSgKnCIglAPUTu2heuNwO7IsyEEsAmiM20UzGpjnvcs8CYglA88Qgmg/JmnSqHKgMEEsA3CFE0ZTr3rwjhOi4muVWBWIJgHuEIprJujdHDuyLMRBLANTZoxa8uvBVNBNr0qsEThEQSwAU6fe6R/1etyXrAhsSzcFwNL7p+O8VlDWZhgsh3NkbADxiOBpL4RzUtLZMwkVLYL/XtR4D/Pa3/6Tz/e9/74HGpse0imJwIpkAyxIATfq97kEDluYirbV94oqlefubX5cC3gpZKBnEEgBzYhXNz3/+dba2/nV2483XPvI9060CxBIAS0yJ5mlN57UR0fzt33mHvfNHX2bPb9TxbW4AsQTAMiSaMnt914Joyu1vMca+wBi7TzHLWdQmml999/fZ62+9wT7jceU7kOABoGKGo3GbEkE6Sy9s93vdixKc4Wi8yhh7rLCdViIoL8Ej3e4vv/sVJn6FswvVEIy9/rnX/nPvH773lup3+AosSwAqpt/rTgwszUsWoixfojVpirBqab755pvs9/54jV17/Qa7Pned3Uhe89fZwtWFz2K4hiCWANSEpmhuzBC6SYk9NhbN33z7bfa73/wqu/G5G+zG/DV2Xb7mFi5e1+avQSwBAPYpKZpL5E6n0bEStUTzD77xLlv92hfZtYVrbGHuxeuafM1fv3jFYlkiZglAwyjGNA9Toinfu2K41zNjmumY5bvf/EP2q7+xxBKJ4JwxkQ5WEjeuX//Xv/+bv/ut0K8jWJYANIy0NOX4MpnMycl2yy6h9+hlKpQsZWkekVhf4hvf+hb79bffYgvnbvYCuzY3zxauzp//+8Vr4eK1MAfLEgBQM+Qed+i1WOO3y3DA4Pjo8c0PP/zgwZe+9uWMt4lX/nTt2rXjv/2rv16ta0ebAmIJgIM0JZo/+9nPfv5L8X+vXbl69fy/+QxxnObawsLj7w7HXwz9OoJYAuAwTYim1IRPnv+SffL8UybEZQ97lloszM//y3cGwy+5fSbNgVgC4AGNiCYT7NPnz9nzzz598V8ZUjE/P//Pw34/y28PBoglAB7RlHv+/LPn7DPxfKZgzs3N/dOg95dfCf06QjYcAI+QZT7U/rhMi4DVwtUrV9nc1Xk2f3Xu/M/p1xV+BUXpAAA3IdHs0JANlfZHY7j8h19JBPLixRmHWAIA3Kbf6570e912naLJzgvU+cVLTGeBAgViCUAANCWaBMQSAOAXDYtm0EAsAQgQiKZ9IJYABAxE0x4QSwAiICWada95HgwQSwAioqGVKIMAYglAhEA0ywOxBCBiIJrqQCwBABBNBSCWAIALIJrZQCwBAK8wJZpll+8NEoglACATEk3dNc+DAmIJAChEc83zoIBYAgCUiVk0IZYAgNJMieZJDGcQy0oAAIACsCwBAEABiCUAACgAsQQAAAWucM4HnHNR8GrFcjI55zsK52PVgf1sKexnp+n9nEZlvw0++0DhnOi+jujz9+ieacd0XwDG5nAOXsI5l2sytxXe2lF8X9M8kDe4EOLIg311nZXU/q0nf5ALdjHGjhljB8lLCPE09pMVInDDL7OhuHD9BgmrD+x5tK++IoX0HmPsPcbYT8n69OFhCkoAsbyMqtu66IllKVlijE0c2I+YkJbnI875U3LZ8bAKAIglQXHIFaU3v8C5eGAO6y7GLyNAPlS3ZNE2RNN/IJYvKSsmS54F+B+4kJiKlEQ0ZZJoI/aT4SsQy5eJnU2NTX2LSyF+2SwyJPIe53yC38E/kA1/ga7obUr3SgjhS29sEr+M1bo5k9ZdifevVbQf8sG8KpNAqFTwB4jlC0zieVJoBzZ3pmLWSeB92mdbHAkhtEInnHM5NCL9ahmKqYyPy7rNFgTTD6IXS4o7Lhl8hG9iKdmi+ssDB/bFC8h7eMWDoOtng15lr6NFCKY/IGZZbFXuF/z/JU9r6hC/tIB84AghOkIIaW3e0Vi3JhFMJN8cJ2qxJNdqveBtAwXB9FEs5U2658B+BIMQYo/c/LLr1iSCuRz7OXSZ2C3LIpE7JfeoqKh7zdMLXe53jLHLSiFrU14P2yW+Bw8vx4FY5rPDyGKgTGoevhZ9b2EgRDVQEu22wrWTsCIHuXh4qFEQrVhSnLEoIJ9+0hdZl20HY4Cqlg3ilxVBSbRWCcG8h4eXm8RsWRZZlftT9ZNFT/xF1+oXybJRSTjABawQCuWUEUxYlw4SpVhSfLGoRu6SJUnCeVywjYuueFvxJkX8skJKCuYKpha5R6yWZZGonVKccpqiJ/6KayUgJPKqNx7ilxVCgqn6W+DB5RjRiaXigN8sl9TLRA8J/0PFtyN+WSH0WxSVojGP63eDJUbLUmXA70wLkiZgF8X2Nh0Vm4FCGIEhflkLqqERiKVDxCiWRZbfYcFgDJVBuk5c5GnRJqFH/NIB6LdQOb++1u8GSVRiqTjgN1cMqRSkqDvDFVf8UvyUYmaq+4b4ZYUIIXYUH1yYf+kIsVmWRUJxJoRQsRyLEj1Lrg55pePbVXw74pfVolIiBFfcEaIRS8UBv6pr1XjjimfQUexdRvyyWlSuoxU8sNwgJstSRbyUioEp5lRkna27Gm+i/Ve1fBG/rAjF2l02HU4BzRCTWJomdqbx2rqk+OV9xbdvYe2YylCx3BE7doAoxFJxwG+p5WI9S/TMhJIMqvHLCTKzlaAygBmWpQPEYlnaSuxMU7TNogeFxR3UXzaH4rR6xCwdIHixVBzwqyOUqts5LZYl6y8xQqwaijwUWJYOEINlaS2xMw3FOIta15wvLC5Zf3kP8UvrFMXKizrOQA1ALMsndqZRsS6dzyaXrL9E/BJER9BiqTjgV9cFP4cGIxS5URue1MohfglABqFblkVWpW5iZ5rCRI8PbWuIXwKQTbBiqTPg14AgXHGG+CUAmYRsWarc8FYsI4p5Fi3fsOTLYArELwF4lSDFUnHAr2liZxrvy4imQPyyPori2Sq/A6iYUC1LlQG/tlzwc8gaK4r1uToY+BUQv6yVorGBTwM7Xi8JVSxV1tixKpaEymd6s7444pfVo7hmk00PCGgyF9qJUxzwe1RR/PBI4T1tnxajkg8VOldF4+0YxS9bJLJADZXrEOfTAYITS0VLaF2hBbIqzgcDZ6we6SodarkreggtpgQTrqMaEEtPCMoNVxzw6wJeTb8uG7/EMq5q0PVaKJaKwzZAxYQWs/RFhJwdDJxFyTWvEb9UQyURqbJsLqiB0MTSm+SJZ/t6Tsn1x1F/WYzKwwdWpSMEI5aKA35dwsuFqIQQqL+0AF2vRR1mDOfQHUKyLH2z1HwYDJzFBuovjVGJ6+5bbpwABgQhlooDfl3EV+vyBPFLfeghqWJV4kHjEKGUDqncuLsNFPd2CgL4cjDwqo91iTJ+yTmX8ct7Cm8/j1+inOjiwa4igqfIgrtFLGIpR7HVbsXRjVFUytTxOX5JsTeV+ss9rFJ4zp7i5HPvEoCh470bTi5epQN+DVCxIHwZDJyFavwy+vXHOecThQcLoyEvSOw4Rggxy9pGsZWF3Oui0W2LvlqWrHz8civWxbdIKFUbJmBVOojXYqk44LfpjGJQwzVmUbL+8kG9e9cs0msoKZTb6K13E98tSxWRacoFP0dxdJs3g4GzKFF/GQ001OWghFAeCyHQKuoovotlkft36kjsJ7TBwFmoxi+DhqxJKXqPFWOUjM4bEmAO461YUq1arQN+DVCJmW763h5YMn4ZHCSSbZoStFXi+M6FEqVVbuOzZem8C56guEYPC0FoSsYvg0BWZFBcUv7Oj0q23SZCiTil43hZZ6k44Ne1VrGJQjLKq8HAWZSov/QOsv6XyWVepX+r1E3OAkLpEapi2W4oAXGQ0cXgjVWZQBPHdwpuLB8HA2exQe6orpBUwXLJWs/0Nb9seVDLqTxHEEp/UBXLJgfqXhJLKuAu6jV2JbEzzUShPbATwqQZadVTw8D7DuxOwlLJWGJVyBmVbcQo/cLHmKVKYsfVAQQq+7UWyhxI8gq2HdgVV5Bu9x0hxAaE0j98FEvvXPCEEomeYDo4qG5Q5ZhDRya9ltHG6C9eiaXigN9dx5/aSjWXnveLTxNr/eUZTbu6JZNesCb9xjfLUqW0xkmrMkGxo2dRIS7rDSQSMc20lJ1Md8mSbGOAbxh4I5aK4858mQEYfL/4NIHHL08paXOXrEg5o3QCSzIsfKqzVLEqfZksvaOQFV/xdTBwFjJ+WWLtGRc5pcLz5CV/myNYjnHAqX7M1ezrSXIhUiF6URzvyJenuWLd6knWjUgxzaJxZ86dD5X91vUOFK+RsjxFLSSQcCGEA7sBAABuE9q64QAAUAkQSwAAUABiCQAACkAsAQBAAYglAAAoALEEAAAFIJYAAKAAxBIAABSYG47G7Qo7eNKdGCf9XtfZtrDhaKy7nMOkyeMajsYdza6Vpve76uUzkpZEZvPaG47GNy307R/1e91GRrUZXC8JytfNcDRepm6tdMfWAR2/d33zfHv4nYOae3XPqKf2ore23+s2PvxiOBrrtjLdbmr/h6PxKi23qsN2v9dtbL0fg/NtwmlyzZnctMPRWArdusF+yHtgte6HFQnlA4OPOO73ukUttowMsE7BGkxy8MiOC/e+Kk0M0lgkcV5LpggNR2NGA2Llidvr97roxVXDxMIJYnG0kizRaz1ZXmI4Gh/SMh6TEsLZpoe97vpCizR5qrZ1rcjKM/29c4fZkNW9N2V8Haas/MTKTH6D9eFo/LDf63oxYasJy1KFUzrpO3U9fX2zLOnCNLlhJXcadAddHEqwS6JZ+HsOR+OWhfWF7vd73VomZQ1HY9P7PHdfycs5oOvxjCZr7cx6AKWEOxm5eNjvdZtYELEUriZ4lmiE2RP5I9OFCS6zYWHlRO/XKbeMvHnfl2423dCZkKCaro8+KPoeG5D7bSKUUszyhPImWcqLNPhYhhgGWZa6NID6va689u6QsK4NR2Onh3YzT7Lha3QBH9DTC7zAhuuyXsfN6iHSRTyi2Fsm5D4eGxzeYtUreVpwv88UHqoDik+er4MuxVDeq3TPpl/yIdQhcWXk1SSfvem6UeRT6ZAUzcfD0XgnOdmxQhdVXvC8DLAuZyOF7JGCxWN6/lYqrgyYGHog7bxQGInxvdR7E2vyZio3kbzWKcF0MCWYu7SN0zF0H+ss79FTP2Yr06bAQSzz2cwTTEpG3jf8jq0qrmcL7ve+Qkw7WVvpNOO90vK+Ta9tsj5XpoQx+fOay/e1r0XpS/R0iu5Gpydy0VpEZViK8TyWZJOEZyYUzzNd7tdqzM6C+32q+CBNxDJr/5/K+C69Bqn3XYgiWa5JOMNZV9znDp7ETYrtRq/ieCGWxTwosHrahsv92nbHbbjfKqVUyTlRrQjJCqEl28OyrJDYBLOKmrQ1JHqUyMwIk3Vkeh1accctuN8PS5TDFQnysnwI0Gsv5RVNu+yJMDt7HYbSGx6FYFJiZ6mijw9q6d2KWMvL2FLMbt/wq43ccQvu97HlIvElagDYSnU95ZYiuUpIgzQeRZD0qfKBAFdcjSIhaVO8TxdTd9zY/TbYdhanlNhJ16TO+o7EPXd2foRJu2NmbzGJVjo20aL/TtqdTIups5BJn2Ufm/SLqCCxM82itM77va7rxcG5HVNTll+L3LpVi6VWsjb1Zk7B9VPycky6e6Q7Xrrt14L7fV+j1fiQvnM1I255kuhEquRtMEMwk9/N2VbnSnrDZ5zwSyeRxLRFJ8zWRcxSPbcbCu/1jTrc5LbtrGzdTAnpxZ/JPU0GPJg+rFt5xeRyH4aj8XbSf67JpEyyw4L7resaJ22U7byYLiH//6OkuiB54NC+r6Q+z0kaccOlmMofhiaY3EoVpdpgPdD2yDrc5GATPdRiNyBL07TMp/D6ou8y6e4p646buN8qXTp538tof3PPC3ktSYgi/fBPjvPY5SE6jccsU32itywExxO8to6mGY7GGxUmdqYJehKRtGZoaIOJYKpafKblRErZcQvud26XTh60XWLsTFLddScUq5y+F9v09yfspWuehJecvvaaGNE2EzrpGxZm7rGk0NqD+JsqOk/9Y4oTlxXZjbyYXEDIc/qkysORVhJZhybXc647TuJkIjIqXTpFdCj0lTSLtOh+fmW/KExywF6G45LvtrEfleJcNpziJncMn8gsFAuJ3GKdQbMTTQt7MdCY7yXoZtb1ZJStOAvdPUXuuIn7rdqlkws9WFupVsaTvFI+KfB0TI9Tk4qcr8ZwxrJMI58wZGE+MviYJXrCeTOJOQPdiyh5SuskGTqhhTIyODKceK7KhuHsUemOv7KcA4VnTPZftUunELKiW3TdrFAp304ykT71Aa2ph82+zf2oEmfrLMmFNh1QEELtoM4x7FMs+EQzybCCcXj2ICEwvRYvPbxSMyR1KdOlowQlblcpJnlKD4f1VFH6Vkooj6kMbMOXkI/TRekWXBiv3UmDxE469qN7Q6GjJ5vSIaKpUWQ6rE0N8xgYWKq2u3QuQYN/l1OThtKvuzKZK0XVN6/PSTd8io7Bolyy0HrD9cBxDroX9N7Un3USDLEkenTQLW/pkBuqW9mQ9FenZ0jqUIvHlU7mhIDz7Y5Ud2XyRPay5pISOzrlILtpgTNIZMSQ6NE9Pq0HCP0uJud0kQq7TdzvbSwIqIcvveEmTfe+FqjbsCrz/k6FYGsuKSar2z2mLTYkVNu621MMUNcyPWxy+WPf8UIs6QLT7Yaw2U5ZJzqu0llGyEFXLJdC7IaykBwxCutY6O7RwaRLJ3qYZ1OHtGMfvmV2qUZNJ3g/8yYm9083lBHUDUZCeWDwED2z5MZuWKglLkOnrmWlQ8UnsTR5mvu2wJmuQOWFK3TP32YIC8TJGDAVQp8YehtW6k+zOlwqYj+gbrbG8CEbfg5NctHdvOVLVs4gsXOaZ/FQof+ZpsWqMlGmLlYVr4Pl1Hi2VYu99dbOgyyNozBHlYXxcL8t4Y1YEro3u0/oJnZUbuKJZslJxyGxNJ0bYMLDClzZtmF3TxHeFH27jm+T0oMueSB317S9MQ9dVyzIRE9JTqtwmy2UE+VhvUsnZkJaViIPXxI8G5oWxqGKxUNuuu6SB7G7cpX1L5OgPVR4axmOQx+3VzexiKUvCQpdF7yMxajrTm9GvALk3RosNNvlRF4Mp/CJWMTSeQyKpM9KZrpNqgpitC7v1pFJtjRsIwFdOhUQi1j6ELfR7tgpY0EYznGMSSzlQ+hOnSU3Frp7GLp0qsM3sQzSDaTEjm6QX+dmNunoCX4wMD1MVpsYwEJCpztpC2VCFeJb6VBd69DUjW5i51QzlrZHsUvdmktfpzgVIUVq4EAG+UCz1vYIXTrV4Y1laVi64nr8po7EzgXktusK3nqAiR7ZCvqOXMgMpTYgC5/ccJPyH2ezgqmF53UwiaeZbBuaq/cUCRFQhE9iqX2DOm4t6B7XvonLRefEx5rL3RnTt7cNJ+rfQ9E9KMKLmCW5fbrWV92jsJShxM6m5ubSHRYN7DZreKnhyayHH10jRwZtg3LN61XUJoIsfLEsTdYLcdm98tmddWrfLUzxWULHC8jDebEki8HkxnQ5c+vzomBrriV6LCxwB3ccZOKDZalb4pLgZLySbkrfS6FcFHvjJWdDmN8J7OO0WFpYRH7f4RhUrGuaVwq54yZdMHDHwUycFUvqlTZNIDjpghsmdlxikZbAcAoLa9zAHQev4KRYklAeGLrfpw6P0g+pTtHVYzENEcAdB5dwTizpiW4qlMzWWikV4XNiZxrnEj3MzoxIuOPgEk6JJS0o9b4FoTxzaBmES1AcNrQed1fFf2BQeM/gjoM0ToiljHsNR2MZmN+y9JEdJHZqpe2iy2ppRiTccXBOYx08FJds08Qdm5bWoauxSnJXq1zJrykW6Xd07rzTqqD7Buc9ccdDCp0ADWoRSxKJZVqS1vbSpGlcn+dnsm+mQ2FVWDbI0nccjhObrqAo3fE9TCSKGxOxbCvEc3Rm8pnQcXyen65Y7tY1/dqgWH6Fequday+V7vhwNJZi/sjgY9A7HjkmMcslEsO8V53sOlwqZJrYqfO4TGpTnXVV6dowaYVEdjxyQlmDRwql64kT3f3TnYaui0kVwYbjyZA2hWp0QS9PAzEAAAF0SURBVHY8YkIQS+eF0jCxU6u1TGEMXQts0WAtocqxMJmIITseL76LpQ8WJTN0TxuZGWmwrdNZY5pMZNIKCXc8UnwVyzNaz9mXmsVGpqEbsGfgrq544KqaXjdwxyPER7GUVkHL5WROGho0oT29u5q9ysdwQTPmeuG9pfW54Y5Hhk9iKS2d+/1e18nylBx0heOsiXWrU5gkejY9EJIdw1ZIuOOR4YNYnpEVsEzxJm+gxI5uCVWjljM9kEzExHXr0kYrJNzxiHBZLKW7fZdEcuBpMbBJssOFB4PJPjjfHmhhMhGDOx4Prq3ueEwW1Z7jnTiq6Foux44cvwwDPNDcVq4A2fKgRXBAv5NuXBm945HQpGV5RvV80sW+wxj7AsUjd0IQSsPEjhPhBvod9g0+wvlqBbjjQJW5GpaKPaEXo+966qi1oVuInRUeWDX4TJeWw5DCretm5g0Ftn2+tZGJtOFo/JB+M13aFhfH020M8Cnx6ReMsf8HPt9vYcSrSMwAAAAASUVORK5CYII="},221:function(e){e.exports=JSON.parse('{"buildMajor":1,"buildMinor":10,"buildRevision":6,"buildTag":"BETA"}')},484:function(e,t){},854:function(e,t,a){e.exports=a.p+"static/media/success.01ddc00b.gif"},855:function(e,t,a){e.exports=a.p+"static/media/not-found.303470ba.png"},856:function(e,t,a){e.exports=a.p+"static/media/logo.ab7af406.png"},901:function(e,t,a){e.exports=a(1698)},906:function(e,t,a){}},[[901,4,5]]]); //# sourceMappingURL=main.35586cd8.chunk.js.map