(this.webpackJsonpfront=this.webpackJsonpfront||[]).push([[0],{178:function(e,t,a){"use strict";a.r(t);a(78),a(79);var n=a(2),s=a(5),c=a(6),i=a(7),o=a(8),r=a(9),l=a(10),d=a.n(l),u=a(1),h=a.n(u);function m(){return sessionStorage.getItem("token")}function p(e){sessionStorage.setItem("token",e)}var b=a(25),j=a(12);function x(e){return JSON.parse(JSON.stringify(e))}function O(e){var t=new Date(e);return t=t.toLocaleDateString("en-GB",{timeZone:"UTC"})}function g(e){return(e=e.replace(" ","")).length>4&&(e="".concat(e.substr(0,4)," ").concat(e.substr(4,8))),e.length>9&&(e=e.substr(0,9)),e}function f(e){switch(e.length){case 1:return"0,000".concat(e);case 2:return"0,00".concat(e);case 3:return"0,0".concat(e);case 4:return"0,".concat(e);case 5:return"".concat(e.substring(0,1),",").concat(e.substring(1));case 6:return"".concat(e.substring(0,2),",").concat(e.substring(2));case 7:return"".concat(e.substring(0,3),",").concat(e.substring(3));case 8:return"".concat(e.substring(0,1),".").concat(e.substring(1,4),",").concat(e.substring(4));case 9:return"".concat(e.substring(0,2),".").concat(e.substring(2,5),",").concat(e.substring(5));case 10:return"".concat(e.substring(0,3),".").concat(e.substring(3,6),",").concat(e.substring(6));default:return""}}function v(e){switch(e.length){case 1:return"0,0".concat(e);case 2:return"0,".concat(e);case 3:return"".concat(e.substring(0,1),",").concat(e.substring(1));case 4:return"".concat(e.substring(0,2),",").concat(e.substring(2));case 5:return"".concat(e.substring(0,3),",").concat(e.substring(3));case 6:return"".concat(e.substring(0,1),".").concat(e.substring(1,4),",").concat(e.substring(4));case 7:return"".concat(e.substring(0,2),".").concat(e.substring(2,5),",").concat(e.substring(5));case 8:return"".concat(e.substring(0,3),".").concat(e.substring(3,6),",").concat(e.substring(6));default:return""}}function y(e){var t,a;return e=w(e),a=11,(e=(t=e).length>a?t.substring(0,a):t).replace(/(\d{3})(\d{3})(\d{3})(\d{2})/,"$1.$2.$3-$4")}function N(e){return(e=w(e)).length>=10?"(".concat(e.substring(0,2),") ").concat(e.substring(2,7),"-").concat(e.substring(7,11)):e}function w(e){return e.replace(/\D/g,"")}function C(e){return e.replace(/[.,;:()-\s]/g,"")}function S(e){return!isNaN(parseFloat(e))&&isFinite(e)}var k=a(13),T=a(0),_=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).positionClasses={top_left:"top-2 left-2",top_right:"top-2 right-2",bottom_left:"bottom-2 left-2",bottom_right:"bottom-2 right-2"},n.defaultClasses="w-72 h-24 fixed flex rounded-md shadow-md text-gray-100 ".concat(n.props.data.color),n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.setHiddenTimeout()}},{key:"setHiddenTimeout",value:function(){var e=this;null!==this.hiddenTimeout&&clearTimeout(this.hiddenTimeout),this.hiddenTimeout=setTimeout((function(){return e.props.data.click({displayToast:!1})}),5e3)}},{key:"render",value:function(){var e=this;return Object(T.jsxs)("div",{className:"".concat(this.defaultClasses," ").concat(this.positionClasses[this.props.data.position]),children:[Object(T.jsx)("div",{className:"w-1/4 flex justify-center items-center text-5xl",children:Object(T.jsx)(k.a,{icon:this.props.data.icon,className:""})}),Object(T.jsxs)("div",{className:"w-3/4",children:[Object(T.jsxs)("div",{className:"h-2/5 mt-2 flex justify-between items-end",children:[Object(T.jsx)("p",{className:"text-2xl font-medium",children:this.props.data.title}),Object(T.jsx)("button",{className:"text-xl font-medium mr-4 mb-2",onClick:function(){return e.props.data.click({displayToast:!1})},children:"X"})]}),Object(T.jsx)("div",{className:"h-3/5 mt-2",children:Object(T.jsx)("p",{children:this.props.data.text})})]})]})}}]),a}(h.a.Component),M=a(19),D=a.n(M);function q(e){return Object(T.jsxs)("button",{className:"bg-".concat(e.color," ").concat(e.width," ").concat(e.custom_style," h-10 mr-1 rounded-md duration-300 transform hover:scale-105 text-white"),onClick:e.click,type:e.type||"button",children:[Object(T.jsx)(k.a,{icon:e.icon,className:"text-xl mr-2"}),e.text]})}function F(e){return Object(T.jsx)("div",{className:"w-".concat(e.size," h-").concat(e.size," bg-").concat(e.color," ").concat(e.custom_style," flex justify-center items-center rounded-full cursor-pointer duration-300 transform hover:scale-105"),onClick:e.click,children:Object(T.jsx)(k.a,{icon:"".concat(e.icon),className:"text-xl text-white"})})}var I=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).getTechnicians=function(){d.a.get("".concat("https://sys.gwenergy.com.br/api","/equipments/get_technicians/"),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){n.setState({technicians:x(e.data)})})).catch((function(e){console.log(e)}))},n.generateDatalistOptions=function(){n.setState({options:n.state.technicians.map(n.valueToElement)})},n.valueToElement=function(e){return Object(T.jsx)("option",{value:e},e)},n.state={technicians:[],options:[]},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getTechnicians()}},{key:"componentDidUpdate",value:function(){this.state.technicians.length>0&&0===this.state.options.length&&this.generateDatalistOptions()}},{key:"render",value:function(){return Object(T.jsx)("datalist",{id:this.props.id,children:this.state.options})}}]),a}(h.a.Component),L=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).calcTotalValue=function(){var e=Number(C(i.state.OSToShow.labor_value)),t=Number(C(i.state.OSToShow.components_value));return String(e+t)},i.handleInputChange=function(e){var t=e.target,a=t.name,n=t.value;["incoming_freight","outgoing_freight"].includes(a)||(n=n.toUpperCase()),["labor_value","components_value"].includes(a)&&(n=String(Number(C(n))));var s=x(i.state.OSToShow);s[a]=n,i.setState({OSToShow:s})},i.handleItemsListChange=function(e){var t=e.target,a=t.id;i.itemsList[a]=t.value.toUpperCase(),i.updateItemsList()},i.addItemToList=function(){i.itemsList.push(""),i.updateItemsList()},i.removeItemFromList=function(){i.itemsList.pop(),i.updateItemsList()},i.updateItemsList=function(){var e=x(i.state.OSToShow);e.itens=i.itemsList.join(";"),i.setState({OSToShow:e})},i.startEditing=function(){i.setState({editingMode:!0})},i.cancelEdit=function(){i.setState({editingMode:!1}),i.restoreOriginalOSData()},i.restoreOriginalOSData=function(){i.setState({OSToShow:x(i.state.OSToShowCopy)})},i.saveEditing=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i.setState({editingMode:!1}),"0000-00-00"===(t=x(i.state.OSToShow)).arrival_date&&(t.arrival_date=null),"0000-00-00"===t.departure_date&&(t.departure_date=null),d.a.patch("".concat("https://sys.gwenergy.com.br/api","/service-orders/").concat(i.state.OSToShow.id,"/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0,OSToShow:x(e.data),OSToShowCopy:x(e.data)})})).catch((function(e){i.successfulUpdate=!1,i.restoreOriginalOSData(),i.setState({displayToast:!0})}));case 5:case"end":return e.stop()}}),e)}))),i.deleteOS=function(){d.a.delete("".concat("https://sys.gwenergy.com.br/api","/service-orders/").concat(i.state.OSToShow.id,"/"),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){window.location.reload()})).catch((function(e){console.log(e)}))},i.itemsList=[],i.state={editingMode:!1,displayToast:!1,OSToShow:x(e.OSToShow),OSToShowCopy:x(e.OSToShow)},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao atualizar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro atualizado!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"componentDidUpdate",value:function(){null!==this.state.OSToShow&&this.props.OSToShow.id!==this.state.OSToShow.id&&this.setState({OSToShow:this.props.OSToShow})}},{key:"genItemsList",value:function(){null!==this.state.OSToShow&&(this.itemsList=this.state.OSToShow.itens.split(";"))}},{key:"render",value:function(){var e=this,t="flex-col ml-3",a="w-full h-8 pl-2 border rounded-md",n="flex mt-3 mr-3 justify-evenly";return this.genItemsList(),this.state.OSToShow?Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{height:"fit-content",maxHeight:"720px",width:"650px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-3xl font-bold ml-3 mr-3 mb-5 mt-2",children:[Object(T.jsxs)("h2",{children:["OS-",this.state.OSToShow.id]}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsxs)("form",{className:"flex-col",children:[Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"arrival_date",children:"Data de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"date",name:"arrival_date",value:this.state.OSToShow.arrival_date,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"entry_NF",children:"NF de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"entry_NF",value:this.state.OSToShow.entry_NF,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_freight",children:"Frete de entrada"}),Object(T.jsxs)("select",{className:"".concat(a," ").concat(this.state.editingMode?"bg-white":"bg-gray-100"),name:"incoming_freight",value:this.state.OSToShow.incoming_freight,onChange:this.handleInputChange,disabled:!this.state.editingMode,children:[Object(T.jsx)("option",{value:"false",children:"N\xf3s"}),Object(T.jsx)("option",{value:"true",children:"Cliente"})]})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_shipping_company",children:"Transportadora de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"incoming_shipping_company",value:this.state.OSToShow.incoming_shipping_company,onChange:this.handleInputChange,disabled:!this.state.editingMode})]})}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"description",children:"Condi\xe7\xe3o do equipamento"}),Object(T.jsx)("textarea",{className:"w-full pl-2 border rounded-md ",name:"description",rows:"3",value:this.state.OSToShow.description,onChange:this.handleInputChange,disabled:!this.state.editingMode})]})}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",children:"Servi\xe7o"}),this.itemsList.map((function(t,a){return Object(T.jsxs)("div",{className:"flex-row w-full h-10 my-2 border rounded-md border-gray-300",children:[Object(T.jsx)("span",{className:"inline-flex h-full w-2/12 font-light justify-center items-center rounded-l-md bg-gray-200",children:"Item ".concat(a+1)}),Object(T.jsx)("input",{type:"text",id:a,value:t,onChange:e.handleItemsListChange,className:"h-full w-10/12 pl-3 align-top rounded-r-md",disabled:!e.state.editingMode},a)]},a)}))]})}),this.state.editingMode&&Object(T.jsx)("div",{className:"flex mt-2 mr-3 justify-evenly",children:Object(T.jsxs)("div",{className:"flex justify-center w-full",children:[Object(T.jsx)(F,{size:"12",color:"blue-500",icon:"plus",custom_style:"mr-5",click:this.addItemToList}),Object(T.jsx)(F,{size:"12",color:"red-500",icon:"minus",custom_style:"ml-5",click:this.removeItemFromList})]})}),Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"departure_date",children:"Data de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"date",name:"departure_date",value:this.state.OSToShow.departure_date||"",onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"outgoing_NF",children:"NF de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"outgoing_NF",value:this.state.OSToShow.outgoing_NF,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_freight",children:"Frete de sa\xedda"}),Object(T.jsxs)("select",{className:"".concat(a," ").concat(this.state.editingMode?"bg-white":"bg-gray-100"),name:"outgoing_freight",value:this.state.OSToShow.outgoing_freight,onChange:this.handleInputChange,disabled:!this.state.editingMode,children:[Object(T.jsx)("option",{value:"false",children:"N\xf3s"}),Object(T.jsx)("option",{value:"true",children:"Cliente"})]})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"outgoing_shipping_company",children:"Transportadora de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"outgoing_shipping_company",value:this.state.OSToShow.outgoing_shipping_company,onChange:this.handleInputChange,disabled:!this.state.editingMode})]})}),Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"components_value",children:"Componentes"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"components_value",value:v(this.state.OSToShow.components_value),onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"labor_value",children:"M\xe3o de obra"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"labor_value",value:v(this.state.OSToShow.labor_value),onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"total_value",children:"Valor total"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"total_value",value:v(this.calcTotalValue()),onChange:this.handleInputChange,disabled:!0})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"technician",children:"T\xe9cnico respons\xe1vel"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"technician",list:"technicians-list",value:this.state.OSToShow.technician,onChange:this.handleInputChange,disabled:!this.state.editingMode,autoComplete:"off"}),Object(T.jsx)(I,{field:"technician",id:"technicians-list"})]})})]}),this.state.editingMode&&Object(T.jsxs)("div",{className:"flex mt-5",children:[Object(T.jsx)("div",{className:"justify-start ml-3",children:Object(T.jsx)(q,{click:this.cancelEdit,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"})}),Object(T.jsx)("div",{className:"justify-end",children:Object(T.jsx)(q,{click:this.saveEditing,color:"green-500",width:"w-28",text:"Salvar",icon:"save"})})]}),!this.state.editingMode&&Object(T.jsxs)("div",{className:"flex justify-between ml-3 mt-5",children:[Object(T.jsx)(q,{click:this.startEditing,color:"yellow-500",width:"w-28",text:"Editar",icon:"edit"}),Object(T.jsx)(q,{click:this.deleteOS,color:"red-500",width:"w-28",text:"Deletar",icon:"trash",custom_style:"mr-4"})]})]},this.props.OSToShow):null}}]),a}(h.a.Component),E=a(21),R=a(76),U=a(77),A=a.n(U),z=function(){function e(t,a,n,s,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4;Object(c.a)(this,e),this.setCoords(t,a),this.setSerial(s),this.setName(n),this.setDate(i),this.setN(o)}return Object(i.a)(e,[{key:"setCoords",value:function(e,t){this.nameX1=Number(e),this.nameX2=Number(t),this.backupX1=e,this.backupX2=t}},{key:"setName",value:function(e){var t;this.name=e,t=this.name.split("-"),this.name1=t[0],this.name2=t[1]}},{key:"setSerial",value:function(e){this.serial=e}},{key:"setDate",value:function(e){var t=e.split("-");this.date=t[2]+"/"+t[1]+"/"+t[0]}},{key:"setN",value:function(e){this.N=e}},{key:"nameX1_R",value:function(){this.nameX1+=.5}},{key:"nameX1_L",value:function(){this.nameX1-=.5}},{key:"nameX2_R",value:function(){this.nameX2+=.5}},{key:"nameX2_L",value:function(){this.nameX2-=.5}},{key:"makeBarcode",value:function(e){var t=document.querySelector("#barcode");null!==t&&t.remove(),(t=document.createElement("template")).innerHTML='',t=t.content.firstChild,document.body.appendChild(t),A()("#barcode",e,{format:"CODE128",lineColor:"black",width:1,height:42,displayValue:!1}),this.canvas=document.getElementById("barcode")}},{key:"makePDF",value:function(){this.doc=new R.a("l","mm",[58,20]),this.doc.setFontSize(13);var e,t=Object(E.a)(this.serial);try{for(t.s();!(e=t.n()).done;){var a=e.value;this.makeBarcode(a);for(var n=0;n1&&n.setState({numberOfTags:e-1})},n.getCurrentNumberOfTags=function(){return n.state.numberOfTags},n.downloadTags=function(){n.tag=new z(n.equipmentsData[0].model.x1,n.equipmentsData[0].model.x2,n.equipmentsData[0].model.name,n.seriais,n.equipmentsData[0].manufacturing_date,n.getCurrentNumberOfTags()),n.tag.makePDF(),n.tag.downloadPDF()},n.state={numberOfTags:4},n}return Object(i.a)(a,[{key:"componentDidUpdate",value:function(){this.equipmentsData=this.props.equipmentsData,this.getSeriais()}},{key:"render",value:function(){var e=this,t="w-10 h-10 bg-tertiary hover:bg-gray-400";return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005"},content:{height:"250px",width:"520px",margin:"auto",border:"2px solid #000c"}},children:[Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Quantas etiquetas voc\xea deseja gerar?"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex justify-center h-10 mt-12 text-2xl font-bolder",children:Object(T.jsxs)("div",{className:"h-11 fit-content border-2 rounded border-gray-600",children:[Object(T.jsx)("button",{className:t,onClick:this.decrementNumberOfTags,children:"-"}),Object(T.jsx)("input",{type:"text",readOnly:!0,id:"tags_modal_input",className:"w-12 h-10 text-center bg-gray-100",value:this.state.numberOfTags}),Object(T.jsx)("button",{className:t,onClick:this.incrementNumberOfTags,children:"+"})]})}),Object(T.jsxs)("div",{className:"flex justify-end mt-10",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:function(){e.downloadTags(),e.props.afterDownloadMethod&&e.props.afterDownloadMethod()},color:"green-500",width:"w-28",text:"Gerar",icon:"cog"})]})]})}}]),a}(h.a.Component);function V(){var e=new Date,t=e.getFullYear(),a=e.getMonth()+1,n=e.getDate();return"".concat(t,"-").concat(a>9?a:"0"+a,"-").concat(n>9?n:"0"+n)}var H=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).calcTotalValue=function(){var e=Number(C(i.state.OS.labor_value)),t=Number(C(i.state.OS.components_value));return String(e+t)},i.handleInputChange=function(e){var t=e.target,a=t.name,n=t.value;["incoming_freight","outgoing_freight"].includes(a)||(n=n.toUpperCase()),["labor_value","components_value"].includes(a)&&(n=String(Number(C(n))));var s=x(i.state.OS);s[a]=n,i.setState({OS:s})},i.handleItemsListChange=function(e){var t=e.target,a=t.id;i.itemsList[a]=t.value.toUpperCase(),i.updateItemsList()},i.addItemToList=function(){i.itemsList.push(""),i.updateItemsList()},i.removeItemFromList=function(){i.itemsList.pop(),i.updateItemsList()},i.updateItemsList=function(){var e=x(i.state.OS);e.itens=i.itemsList.join(";"),i.setState({OS:e})},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.saveOS=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:""===(t=x(i.state.OS)).departure_date&&delete t.departure_date,d.a.post("".concat("https://sys.gwenergy.com.br/api","/service-orders/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0}),setTimeout(window.location.reload.bind(window.location),1e3)})).catch((function(e){i.successfulUpdate=!1,i.setState({displayToast:!0})}));case 3:case"end":return e.stop()}}),e)}))),i.itemsList=[],i.state={OS:{itens:"",entry_NFL:"0",technician:"",description:"",labor_value:"",outgoing_NF:"0",departure_date:"",components_value:"",serial:e.serial,outgoing_freight:!0,incoming_freight:!0,incoming_shipping_company:"",outgoing_shipping_company:"",arrival_date:V()},displayToast:!1},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao salvar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro salvo!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"genItemsList",value:function(){null!==this.state.OS&&(this.itemsList=this.state.OS.itens.split(";"))}},{key:"render",value:function(){var e=this,t="flex-col ml-3",a="w-full h-8 pl-2 border rounded-md",n="flex mt-3 mr-3 justify-evenly";return this.genItemsList(),Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{height:"fit-content",maxHeight:"720px",width:"650px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-3xl font-bold ml-3 mr-3 mb-5 mt-2",children:[Object(T.jsx)("h2",{children:"ORDEM DE SERVI\xc7O"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsxs)("form",{id:"form",autoComplete:"off",className:"flex-col",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"arrival_date",children:"Data de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"date",name:"arrival_date",value:this.state.OS.arrival_date,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"entry_NF",children:"NF de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"entry_NF",value:this.state.OS.entry_NF,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_freight",children:"Frete de entrada"}),Object(T.jsxs)("select",{className:"".concat(a," bg-white"),name:"incoming_freight",value:this.state.OS.incoming_freight,onChange:this.handleInputChange,children:[Object(T.jsx)("option",{value:"false",children:"N\xf3s"}),Object(T.jsx)("option",{value:"true",children:"Cliente"})]})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_shipping_company",children:"Transportadora de entrada"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"incoming_shipping_company",value:this.state.OS.incoming_shipping_company,onChange:this.handleInputChange})]})}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"description",children:"Condi\xe7\xe3o do equipamento"}),Object(T.jsx)("textarea",{className:"w-full pl-2 border rounded-md ",name:"description",rows:"3",value:this.state.OS.description,onChange:this.handleInputChange})]})}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",children:"Servi\xe7o"}),this.itemsList.map((function(t,a){return Object(T.jsxs)("div",{className:"flex-row w-full h-10 my-2 border rounded-md border-gray-300",children:[Object(T.jsx)("span",{className:"inline-flex h-full w-2/12 font-light justify-center items-center rounded-l-md bg-gray-200",children:"Item ".concat(a+1)}),Object(T.jsx)("input",{type:"text",id:a,value:t,onChange:e.handleItemsListChange,className:"h-full w-10/12 pl-3 align-top rounded-r-md"},a)]},a)}))]})}),Object(T.jsx)("div",{className:"flex mt-2 mr-3 justify-evenly",children:Object(T.jsxs)("div",{className:"flex justify-center w-full",children:[Object(T.jsx)(F,{size:"12",color:"blue-500",icon:"plus",custom_style:"mr-5",click:this.addItemToList}),Object(T.jsx)(F,{size:"12",color:"red-500",icon:"minus",custom_style:"ml-5",click:this.removeItemFromList})]})}),Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"departure_date",children:"Data de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"date",name:"departure_date",value:this.state.OS.departure_date||"",onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"outgoing_NF",children:"NF de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"outgoing_NF",value:this.state.OS.outgoing_NF,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"incoming_freight",children:"Frete de sa\xedda"}),Object(T.jsxs)("select",{className:"".concat(a," bg-white"),name:"outgoing_freight",value:this.state.OS.outgoing_freight,onChange:this.handleInputChange,children:[Object(T.jsx)("option",{value:"false",children:"N\xf3s"}),Object(T.jsx)("option",{value:"true",children:"Cliente"})]})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"outgoing_shipping_company",children:"Transportadora de sa\xedda"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"outgoing_shipping_company",value:this.state.OS.outgoing_shipping_company,onChange:this.handleInputChange})]})}),Object(T.jsxs)("div",{className:"".concat(n),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"components_value",children:"Componentes"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"components_value",value:v(this.state.OS.components_value),onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"labor_value",children:"M\xe3o de obra"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"labor_value",value:v(this.state.OS.labor_value),onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"total_value",children:"Valor total"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"total_value",value:v(this.calcTotalValue()),onChange:this.handleInputChange,disabled:!0})]})]}),Object(T.jsx)("div",{className:"".concat(n),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"technician",children:"T\xe9cnico respons\xe1vel"}),Object(T.jsx)("input",{className:"".concat(a),type:"text",name:"technician",list:"technicians-list",value:this.state.OS.technician,onChange:this.handleInputChange,autoComplete:"off",required:!0}),Object(T.jsx)(I,{field:"technician",id:"technicians-list"})]})}),Object(T.jsx)("div",{className:"flex justify-start ml-3 mt-5",children:Object(T.jsx)(q,{click:function(){e.validateForm()&&e.saveOS()},type:"submit",color:"green-500",width:"w-32",text:"Cadastrar",icon:"save"})})]})]},this.props.OS)}}]),a}(h.a.Component);function W(e){return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:e.isOpen,onRequestClose:e.hideMethod,style:{overlay:{backgroundColor:"#0005"},content:{height:"250px",width:"520px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f6af1c"}},children:[Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Cuidado!"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:e.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex justify-center h-10 mt-12 text-2xl font-bolder",children:Object(T.jsxs)("h3",{children:["Esta a\xe7\xe3o \xe9 ",Object(T.jsx)("u",{children:"irrevers\xedvel"}),"!"]})}),Object(T.jsxs)("div",{className:"flex justify-end mt-10",children:[Object(T.jsx)(q,{click:e.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:e.delMethod,color:"green-500",width:"w-28",text:"Deletar",icon:"check"})]})]})}var B=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).hideOSModal=function(){i.setState({displayOSModal:!1})},i.displayNewOSModal=function(){i.setState({displayNewOSModal:!0})},i.hideNewOSModal=function(){i.setState({displayNewOSModal:!1})},i.displayTagsModal=function(){i.setState({displayTagsModal:!0})},i.hideTagsModal=function(){i.setState({displayTagsModal:!1})},i.displayDeleteModal=function(){i.setState({displayDeleteModal:!0})},i.hideDeleteModal=function(){i.setState({displayDeleteModal:!1})},i.startEditing=function(){i.setState({editingMode:!0})},i.saveEditing=Object(s.a)(Object(n.a)().mark((function e(){return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i.setState({editingMode:!1}),d.a.patch("".concat("https://sys.gwenergy.com.br/api","/equipments/").concat(i.state.equipmentData.serial,"/"),x(i.state.equipmentData),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0,equipmentData:x(e.data),equipmentDataCopy:x(e.data)})})).catch((function(e){i.successfulUpdate=!1,i.restoreOriginalEquipmentData(),i.setState({displayToast:!0})}));case 2:case"end":return e.stop()}}),e)}))),i.cancelEdit=function(){i.setState({editingMode:!1}),i.restoreOriginalEquipmentData()},i.deleteEquipment=function(){d.a.delete("".concat("https://sys.gwenergy.com.br/api","/equipments/").concat(i.state.equipmentData.serial,"/"),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){window.location.assign("./../search")})).catch((function(e){console.log(e)}))},i.restoreOriginalEquipmentData=function(){i.setState({equipmentData:x(i.state.equipmentDataCopy)})},i.handleOSButtonClick=function(e){var t=e.target;i.setState({OSToShow:i.state.equipmentData.service_orders[t.id],displayOSModal:!0})},i.handleInputChange=function(e){var t=e.target,a=t.name,n=t.value.toUpperCase();["value","client_phone"].includes(a)&&(n=C(n)),"modelo"===a&&i.getSerial(n),"value"===a&&(n=String(Number(n)));var s=x(i.state.equipmentData);s[a]=n,i.setState({equipmentData:s})},i.handleCheckboxChanges=function(e){var t=e.target,a=t.name,n=x(i.state.equipmentData);n[a]=t.checked,i.setState({equipmentData:n})},i.state={OSToShow:null,editingMode:!1,displayToast:!1,displayOSModal:!1,displayTagsModal:!1,displayNewOSModal:!1,displayDeleteModal:!1,equipmentData:x(e.equipmentData),equipmentDataCopy:x(e.equipmentData)},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao atualizar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro atualizado!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"render",value:function(){var e=this,t="flex-col ml-3",a="flex mt-3 mr-3 justify-evenly",n="w-full h-8 pl-2 border rounded-md";return Object(T.jsxs)("div",{className:"w-4/5 max-w-6xl border-2 rounded border-primary",id:"view",children:[Object(T.jsx)(L,{isOpen:this.state.displayOSModal,OSToShow:this.state.OSToShow,hideMethod:this.hideOSModal},this.state.OSToShow),Object(T.jsx)(H,{serial:this.state.equipmentData.serial,isOpen:this.state.displayNewOSModal,hideMethod:this.hideNewOSModal}),Object(T.jsx)(P,{equipmentsData:[this.state.equipmentData],isOpen:this.state.displayTagsModal,hideMethod:this.hideTagsModal}),Object(T.jsx)(W,{isOpen:this.state.displayDeleteModal,hideMethod:this.hideDeleteModal,delMethod:this.deleteEquipment}),this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("form",{className:"flex-col",autoComplete:"off",children:[Object(T.jsx)("h1",{className:"text-center text-3xl my-6",children:"FICHA DO EQUIPAMENTO"}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"model",children:"Modelo"}),Object(T.jsx)("input",{className:"".concat(n),type:"text",name:"model",value:this.state.equipmentData.model.name,disabled:!0})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"serial",children:"Serial"}),Object(T.jsx)("input",{className:"".concat(n),type:"text",name:"serial",value:g(this.state.equipmentData.serial),disabled:!0})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"NF",children:"NF"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"number",name:"NF",value:this.state.equipmentData.NF,onChange:this.handleInputChange,disabled:!this.state.editingMode})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"dealer",children:"Revendedor"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"dealer",value:this.state.equipmentData.dealer,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"buyer",children:"Comprador"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"buyer",value:this.state.equipmentData.buyer,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-3/12"),children:[Object(T.jsx)("label",{className:"",htmlFor:"value",children:"Valor"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"value",required:!0,onChange:this.handleInputChange,disabled:!this.state.editingMode,value:v(this.state.equipmentData.value)})]}),Object(T.jsxs)("div",{className:"flex-col ml-3 w-1/12",children:[Object(T.jsx)("label",{className:"ml-2",htmlFor:"model",children:"Estoque"}),Object(T.jsx)("input",{type:"checkbox",name:"in_stock",className:"".concat(n),disabled:!this.state.editingMode,onChange:this.handleCheckboxChanges,checked:this.state.equipmentData.in_stock})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"client",children:"Cliente final"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"client",value:this.state.equipmentData.client,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"CPF",children:"CPF"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"CPF",value:y(this.state.equipmentData.CPF),onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"client_phone",children:"Telefone"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"text",name:"client_phone",value:N(this.state.equipmentData.client_phone),onChange:this.handleInputChange,disabled:!this.state.editingMode})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"manufacturing_date",children:"Data de fabrica\xe7\xe3o"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"date",name:"manufacturing_date",value:this.state.equipmentData.manufacturing_date,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"start_of_warranty",children:"In\xedcio da garantia"}),Object(T.jsx)("input",{className:"".concat(n," editable"),type:"date",name:"start_of_warranty",value:this.state.equipmentData.start_of_warranty,onChange:this.handleInputChange,disabled:!this.state.editingMode})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"technician",children:"T\xe9cnico respons\xe1vel"}),Object(T.jsx)("input",{required:!0,className:"".concat(n," editable"),type:"text",name:"technician",list:"technicians-list",value:this.state.equipmentData.technician,onChange:this.handleInputChange,disabled:!this.state.editingMode}),Object(T.jsx)(I,{field:"technician",id:"technicians-list"})]})]}),Object(T.jsx)("div",{className:"".concat(a),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"comments",children:"Coment\xe1rios"}),Object(T.jsx)("textarea",{className:"w-full pl-2 border rounded-md editable",name:"comments",rows:"4",value:this.state.equipmentData.comments,onChange:this.handleInputChange,disabled:!this.state.editingMode})]})}),Object(T.jsx)("div",{className:"".concat(a),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"service_orders",children:"Hist\xf3rico de manuten\xe7\xf5es"}),Object(T.jsxs)("div",{id:"service_orders",className:"mt-3 mb-1",children:[this.state.equipmentData.service_orders.map((function(t,a){return Object(T.jsxs)("button",{type:"button",id:a,onClick:e.handleOSButtonClick,className:"w-full h-10 border border-gray-200 hover:bg-gray-200 rounded-sm bg-gray-100",children:["OS-",t.id]},a)})),!this.state.equipmentData.service_orders.length&&Object(T.jsx)("div",{className:"w-full h-10 border flex justify-center items-center border-gray-200 rounded-sm bg-gray-100",children:"Nenhuma O.S. registrada"})]})]})}),Object(T.jsxs)("div",{className:"flex mt-3 mb-3 ml-3 justify-between",children:[Object(T.jsxs)("div",{children:[!this.state.editingMode&&Object(T.jsx)(q,{click:this.startEditing,color:"yellow-500",width:"w-28",text:"Editar",icon:"edit"}),!this.state.editingMode&&Object(T.jsx)(q,{click:this.displayTagsModal,color:"blue-500",width:"w-44",text:"Gerar etiqueta",icon:"ticket-alt"}),!this.state.editingMode&&Object(T.jsx)(q,{click:this.displayNewOSModal,color:"gray-600",width:"w-36",text:"Nova O.S.",icon:"cog"}),this.state.editingMode&&Object(T.jsx)(q,{click:this.cancelEdit,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),this.state.editingMode&&Object(T.jsx)(q,{click:this.saveEditing,color:"green-500",width:"w-28",text:"Salvar",icon:"save"})]}),!this.state.editingMode&&Object(T.jsx)(q,{click:this.displayDeleteModal,custom_style:"mr-4",color:"red-500",width:"w-28",text:"Deletar",icon:"trash"})]})]})]})}}]),a}(h.a.Component),X=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(){var e;return Object(c.a)(this,a),(e=t.call(this)).getEquipmentData=Object(s.a)(Object(n.a)().mark((function t(){var a,s;return Object(n.a)().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/equipments/?serial=").concat(e.serial),headers:{Authorization:"Token ".concat(m())}},t.next=3,d()(a);case 3:s=t.sent,e.setState({equipmentData:s.data[0]});case 5:case"end":return t.stop()}}),t)}))),e.serial=e.getURLSerial(),e.state={equipmentData:{}},e}return Object(i.a)(a,[{key:"getURLSerial",value:function(){return window.location.hash.substring(1)}},{key:"componentDidMount",value:function(){this.getEquipmentData()}},{key:"render",value:function(){return Object(T.jsxs)("div",{className:"flex justify-center items-center py-5 h-auto w-full bg-secondary",children:[0!==Object.keys(this.state.equipmentData).length&&Object(T.jsx)(B,{equipmentData:this.state.equipmentData}),Object(T.jsx)(b.SyncLoader,{loading:0===Object.keys(this.state.equipmentData).length})]})}}]),a}(h.a.Component),Y=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).handleSubmit=function(){var e=Object(s.a)(Object(n.a)().mark((function e(t){var a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t.preventDefault(),a={method:"post",url:"".concat("https://sys.gwenergy.com.br/api","/api-token-auth/"),data:{username:i.state.username,password:i.state.password}},d.a.post("".concat("https://sys.gwenergy.com.br/api","/api-token-auth/"),a.data).then((function(e){i.props.setToken(e.data.token),i.props.navigate("search/")})).catch((function(e){i.setState({username:"",password:"",displayToast:!0})}));case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i.state={username:"",password:"",displayToast:!1},i.errorToast=Object(T.jsx)(_,{data:{position:"top_right",color:"bg-red-700",title:"Erro",text:"Usu\xe1rio ou senha inv\xe1lidos",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))}}),i}return Object(i.a)(a,[{key:"render",value:function(){var e=this;return Object(T.jsxs)("div",{className:"w-screen h-screen flex flex-col items-center justify-center bg-gray-600",children:[Object(T.jsxs)("div",{className:"w-1/2 h-auto max-w-screen-sm flex flex-col items-center shadow-xl rounded-lg bg-gray-100",children:[Object(T.jsx)("h1",{className:"my-10 text-3xl text-blue-800 font-medium",children:"Sistema GW"}),Object(T.jsx)("hr",{className:"w-9/12 border-gray-300"}),Object(T.jsxs)("form",{className:"w-9/12 mt-8 text-xl text-blue-700 font-medium",onSubmit:this.handleSubmit,children:[Object(T.jsxs)("div",{className:"flex flex-col",children:[Object(T.jsx)("label",{htmlFor:"user",children:"Usu\xe1rio"}),Object(T.jsx)("input",{type:"text",id:"user",value:this.state.username,className:"h-10 mt-2 px-2 border rounded text-black border-gray-300",onInput:function(t){return e.setState({username:t.target.value})},autoFocus:!0})]}),Object(T.jsxs)("div",{className:"flex flex-col mt-6",children:[Object(T.jsx)("label",{htmlFor:"password",children:"Senha"}),Object(T.jsx)("input",{type:"password",id:"password",value:this.state.password,className:"h-10 mt-2 px-2 border rounded text-black border-gray-300",onInput:function(t){return e.setState({password:t.target.value})}})]}),Object(T.jsx)("button",{type:"submit",className:"mt-8 mb-10 p-2 rounded-md text-white bg-blue-700 hover:bg-blue-800",children:"Entrar"})]})]}),this.state.displayToast&&this.errorToast]})}}]),a}(h.a.Component),G=a(4);function Q(e){var t=Object(G.n)(),a=e.equipment,n=e.rowNumber%2===0?"bg-gray-200":"bg-gray-100",s="pl-2 border border-gray-300",c=O(a.manufacturing_date);return Object(T.jsxs)("tr",{className:"".concat(s," ").concat(n," cursor-pointer hover:bg-white"),onClick:function(){return t("/view/?#".concat(a.serial))},children:[Object(T.jsx)("td",{className:"text-center",children:e.rowNumber}),Object(T.jsx)("td",{className:"".concat(s),children:a.serial}),Object(T.jsx)("td",{className:"".concat(s),children:a.model.name}),Object(T.jsx)("td",{className:"".concat(s),children:a.NF}),Object(T.jsx)("td",{className:"".concat(s),children:a.dealer}),Object(T.jsx)("td",{className:"".concat(s),children:a.client}),Object(T.jsx)("td",{className:"".concat(s),children:c}),Object(T.jsx)("td",{className:"".concat(s),children:a.technician}),Object(T.jsx)("td",{className:"".concat(s),children:a.in_stock?"SIM":"N\xc3O"}),Object(T.jsx)("td",{className:"".concat(s),children:a.service_orders.length>0?"SIM":"N\xc3O"})]})}function $(e){return Object(T.jsxs)("table",{className:"w-full bg-primary",children:[Object(T.jsx)("thead",{className:"text-white h-10",children:Object(T.jsx)("tr",{className:"text-left",children:e.headerWords.map((function(e,t){return Object(T.jsx)("th",{className:"pl-2",children:e},t)}))})}),Object(T.jsxs)("tbody",{children:[!e.loading&&e.equipments.map((function(e,t){return Object(T.jsx)(Q,{equipment:e,rowNumber:t+1},e.serial)})),e.loading&&Object(T.jsx)("tr",{children:Object(T.jsx)("td",{colSpan:e.headerWords.length,className:"bg-secondary",children:Object(T.jsx)("div",{className:"h-screen flex justify-center mt-80",children:Object(T.jsx)(b.SyncLoader,{loading:!0,color:"#000"})})})})]})]})}var J=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getEquipments.bind(Object(j.a)(n)),1e3)},n.state={loading:!1,equipments:[]},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getEquipments()}},{key:"getEquipments",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.setState({loading:!0}),t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/equipments/?only_in_stock"),headers:{Authorization:"Token ".concat(m())}},e.next=4,d()(t);case 4:a=e.sent,this.setState({equipments:a.data,loading:!1});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){return Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsx)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:Object(T.jsx)("h1",{className:"text-2xl font-bold text-primary",children:"Equipamentos em estoque"})}),Object(T.jsx)($,{headerWords:["N\xba","Serial","Modelo","NF","Revendedor","Cliente","Fabrica\xe7\xe3o","T\xe9cnico",Object(T.jsx)(k.a,{icon:"boxes"}),Object(T.jsx)(k.a,{icon:"tools"})],equipments:this.state.equipments,loading:this.state.loading})]})}}]),a}(h.a.Component),Z=a(28);function K(e){var t=e.text.split(";");return Object(T.jsxs)(Z.b,{to:e.url,className:"flex flex-col items-center justify-center w-full h-20 py-1 hover:bg-gray-900",children:[Object(T.jsx)(k.a,{icon:e.iconName,className:"text-3xl"}),t.map((function(e,t){return Object(T.jsx)("p",{children:e},t)}))]})}var ee=a.p+"static/media/Logo.75162e20.png";function te(){return Object(T.jsxs)("div",{className:"inline-block h-auto w-24 text-tertiary",children:[Object(T.jsx)("div",{className:"p-2 mt-2 mb-2",children:Object(T.jsx)("img",{src:ee,alt:""})}),Object(T.jsxs)("div",{className:"flex flex-col items-center text-sm font-bold",children:[Object(T.jsx)(K,{url:"/search",iconName:"search",text:"Pesquisar"}),Object(T.jsx)(K,{url:"/register",iconName:"plus",text:"Inserir"}),Object(T.jsx)(K,{url:"/service-orders",iconName:"tools",text:"O.S."}),Object(T.jsxs)("div",{className:"flex flex-col items-center justify-center w-full",children:[Object(T.jsx)("p",{children:"______________"}),Object(T.jsx)("p",{className:"mt-4 font-bold text-base",children:"Estoque"}),Object(T.jsx)("p",{className:"mb-2",children:"______________"}),Object(T.jsx)(K,{url:"/components",iconName:"cog",text:"Componentes;simples"}),Object(T.jsx)(K,{url:"/compound-components",iconName:"cogs",text:"Componentes;compostos"}),Object(T.jsx)(K,{url:"/models",iconName:"list",text:"Modelos"}),Object(T.jsx)(K,{url:"/inventory",iconName:"boxes",text:"Equipamentos"})]})]})]})}var ae=a(31),ne=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;Object(c.a)(this,a),(i=t.call(this,e)).handleComponentsChange=function(e){var t=e.target,a=t.name,n=t.value;if(!(n<0)){var s=x(i.state.components);s[a].N=n,i.setState({components:s})}},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.updateModel=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=Object(ae.a)({subcomponents:i.state.components.filter((function(e){return Number(e.N)>0}))},i.state.payload),d.a.patch("".concat("https://sys.gwenergy.com.br/api","/models/").concat(i.state.model.id,"/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0}),setTimeout(window.location.reload.bind(window.location),1e3)})).catch((function(e){i.successfulUpdate=!1,i.setState({displayToast:!0})}));case 2:case"end":return e.stop()}}),e)})));var o=e.components;return(e.componentsList?e.componentsList.components:[]).forEach((function(e){o.forEach((function(t){e.component===t.id&&(t.N=e.amount)}))})),i.state={model:e.model,payload:{ncm:e.model.ncm,value:e.model.value},displayToast:!1,components:o,defaultSimpleComponents:o},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao salvar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",icon:"check-circle",color:"bg-green-600",position:"top_right",text:"Registro salvo!",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"componentDidUpdate",value:function(){var e=this.state.defaultSimpleComponents!==this.state.components;!this.props.isOpen&&e&&this.setState({components:this.state.defaultSimpleComponents})}},{key:"render",value:function(){var e=this;return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{maxHeight:"720px",height:"fit-content",width:"500px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Sub-componentes"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex text-2xl font-bolder",children:Object(T.jsxs)("form",{id:"form",autoComplete:"off",className:"flex-col text-base",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsx)("label",{htmlFor:"description",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{type:"text",disabled:!0,name:"description",value:this.state.model.name,className:"w-full h-9 pl-2 border border-gray-400 rounded-md"})]}),Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsx)("label",{htmlFor:"ncm",children:"NCM"}),Object(T.jsx)("input",{type:"text",name:"ncm",maxLength:8,value:this.state.payload.ncm||"",className:"w-full h-9 pl-2 border border-gray-400 rounded-md",onChange:function(t){var a=t.target.value;e.setState({payload:Object(ae.a)(Object(ae.a)({},e.state.payload),{},{ncm:a})})}})]}),Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsx)("label",{htmlFor:"value",children:"Valor"}),Object(T.jsx)("input",{type:"text",name:"value",value:"R$ "+(this.state.payload.value>0?v(this.state.payload.value):""),className:"w-full h-9 pl-2 border border-gray-400 rounded-md",onChange:function(t){var a=String(Number(w(t.target.value)));e.setState({payload:Object(ae.a)(Object(ae.a)({},e.state.payload),{},{value:a})})}})]}),Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsxs)("div",{className:"flex justify-between",children:[Object(T.jsx)("p",{children:"Sub-componente"}),Object(T.jsx)("p",{children:"Quantidade"})]}),Object(T.jsx)("fieldset",{className:"w-full border rounded-md overflow-hidden border-gray-400 bg-blue-400",children:this.state.components.map((function(t,a){return Object(T.jsxs)("div",{className:"py-1 flex items-center justify-between overflow-none ".concat(t.N>0?"bg-blue-400":"bg-white"),children:[Object(T.jsx)("label",{htmlFor:a,className:"flex-1 pl-3",children:t.description.substring(0,40)}),Object(T.jsx)("input",{name:a,type:"number",value:t.N,className:"w-1/6 bg-transparent outline-none text-center",onChange:e.handleComponentsChange})]},a)}))})]})]})}),Object(T.jsxs)("div",{className:"flex justify-between mt-5 mb-1",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:function(){e.validateForm()&&e.updateModel()},type:"submit",color:"green-500",width:"w-32",text:"Atualizar",icon:"save"})]})]})}}]),a}(h.a.Component),se=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).state={components:e.components,displayModal:!1},n}return Object(i.a)(a,[{key:"render",value:function(){var e=this,t="pl-2 border border-gray-300",a=this.props.rowNumber%2===0?"bg-gray-200":"bg-gray-100";return Object(T.jsxs)("tr",{className:"".concat(t," ").concat(a," uppercase"),children:[this.state.components.length>0&&Object(T.jsx)(ne,{isOpen:this.state.displayModal,hideMethod:function(){e.setState({displayModal:!1})},model:this.props.model,components:this.state.components,componentsList:this.props.componentsList}),Object(T.jsx)("td",{className:"text-center",children:this.props.model.id}),Object(T.jsx)("td",{className:"".concat(t),children:this.props.model.name}),Object(T.jsx)("td",{className:"".concat(t),children:this.props.model.ncm}),Object(T.jsx)("td",{className:"".concat(t," uppercase"),children:this.props.model.category}),Object(T.jsx)("td",{className:"".concat(t," uppercase"),children:"R$ "+v(this.props.model.value)}),Object(T.jsx)("td",{className:"border border-gray-300 px-2 text-center",children:Object(T.jsx)("button",{onClick:function(){e.setState({displayModal:!0})},children:Object(T.jsx)(k.a,{icon:"list",className:"mx-3 text-blue-500"})})})]})}}]),a}(h.a.Component);function ce(e){var t=0;return e.models.map((function(e){return t+=e.value*e.amount})),Object(T.jsxs)("table",{className:"w-full bg-primary",children:[Object(T.jsx)("thead",{className:"text-white h-10",children:Object(T.jsx)("tr",{className:"text-left",children:e.headerWords.map((function(e,t){return Object(T.jsx)("th",{className:"pl-2",children:e},t)}))})}),Object(T.jsxs)("tbody",{children:[!e.loading&&e.dataLoaded&&e.models.map((function(t,a){return Object(T.jsx)(se,{model:t,rowNumber:a+1,components:e.components?x(e.components):e.components,componentsList:e.componentsLists[t.id]?x(e.componentsLists[t.id]):e.componentsLists[t.id]},t.id)})),(e.loading||!e.dataLoaded)&&Object(T.jsx)("tr",{children:Object(T.jsx)("td",{colSpan:e.headerWords.length,className:"bg-secondary",children:Object(T.jsx)("div",{className:"h-screen flex justify-center mt-80",children:Object(T.jsx)(b.SyncLoader,{loading:!0,color:"#000"})})})})]})]})}var ie=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).handleTextInput=function(e){n.searchText=e.target.value.toUpperCase(),n.startPreRequestTimeout()},n.startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getModels.bind(Object(j.a)(n)),1e3)},n.searchText="",n.state={models:[],components:[],loading:!1,dataLoaded1:!1,dataLoaded2:!1,componentsLists:{}},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getModels(!0),this.getComponents(),this.getComponentsLists()}},{key:"getModels",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a,s,c=arguments;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(t=!(c.length>0&&void 0!==c[0])||c[0])&&this.setState({loading:!0}),a={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/models/?name=").concat(this.searchText),headers:{Authorization:"Token ".concat(m())}},e.next=5,d()(a);case 5:s=e.sent,t?this.setState({models:s.data,loading:!1}):this.setState({models:s.data});case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"getComponentsLists",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a,s;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components-lists/"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:a=e.sent,s={},a.data.forEach((function(e){e.model&&(s[e.model]=e)})),this.setState({dataLoaded1:!0,componentsLists:s});case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"getComponents",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components/"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:(a=e.sent).data.forEach((function(e){e.N=0})),this.setState({dataLoaded2:!0,components:a.data});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){return Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsx)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300 bg-gray-200",children:[Object(T.jsx)("span",{className:"h-full mx-4",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{type:"text",className:"h-full w-52 px-4 uppercase outline-none focus:ring-2 focus:ring-tertiary",autoFocus:!0,onInput:this.handleTextInput}),Object(T.jsx)(k.a,{icon:"search",className:"mx-3 text-blue-600"})]})}),Object(T.jsx)(ce,{compound:!1,models:this.state.models,loading:this.state.loading,components:this.state.components,componentsLists:this.state.componentsLists,headerWords:["C\xf3digo","Nome","NCM","Categoria","Valor","Componentes"],dataLoaded:this.state.dataLoaded1&&this.state.dataLoaded2})]})}}]),a}(h.a.Component),oe=a(14);function re(e){return Object(T.jsx)("select",{className:e.className,onChange:e.onChange,children:Object.entries(e.optionValues).map((function(e){var t=Object(oe.a)(e,2),a=t[0],n=t[1];return Object(T.jsx)("option",{value:n,children:a},n)}))})}var le=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).handleColumnSelectChanges=function(e){n.searchColumn=e.target.value,n.startPreRequestTimeout()},n.handleOSSelectChanges=function(e){n.OSFilter=e.target.value,n.startPreRequestTimeout()},n.handleCheckboxChanges=function(e){var t=e.target;n.LimitResultsFilter="&limit_results",t.checked&&(n.LimitResultsFilter=""),n.startPreRequestTimeout()},n.handleTextInput=function(e){n.searchText=e.target.value.toUpperCase(),n.startPreRequestTimeout()},n.startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getEquipments.bind(Object(j.a)(n)),1e3)},n.OSFilter="",n.LimitResultsFilter="&limit_results",n.searchText="",n.searchColumn="serial",n.state={loading:!1,equipments:[]},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getEquipments()}},{key:"getEquipments",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.setState({loading:!0}),t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/equipments/?").concat(this.searchColumn,"=").concat(this.searchText).concat(this.OSFilter).concat(this.LimitResultsFilter),headers:{Authorization:"Token ".concat(m())}},e.next=4,d()(t);case 4:a=e.sent,this.setState({equipments:a.data,loading:!1});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){return Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsxs)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:[Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300",children:[Object(T.jsx)(re,{className:"h-full w-30 pl-2 outline-none border-r border-gray-300 bg-white",optionValues:{Serial:"serial",Revendedor:"dealer","T\xe9cnico":"technician",Cliente:"client",Modelo:"modelo",NF:"NF"},onChange:this.handleColumnSelectChanges}),Object(T.jsx)("input",{type:"text",className:"h-9 px-4 uppercase outline-none focus:ring-2 focus:ring-tertiary",autoFocus:!0,onInput:this.handleTextInput}),Object(T.jsx)(k.a,{icon:"search",className:"mx-3 text-blue-600"})]}),Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300 bg-gray-200",children:[Object(T.jsx)("span",{className:"h-full mx-4",children:"Apenas registros com manuten\xe7\xf5es?"}),Object(T.jsx)(re,{className:"h-full w-24 pl-2 outline-none border-l border-gray-300 bg-white",optionValues:{"N\xe3o":"",Sim:"&only_with_OS"},onChange:this.handleOSSelectChanges})]}),Object(T.jsxs)("div",{className:"h-10 flex items-center",children:[Object(T.jsx)("input",{type:"checkbox",id:"limit_results",className:"w-5 h-5 mr-2",onChange:this.handleCheckboxChanges}),Object(T.jsx)("label",{htmlFor:"limit_results",children:"At\xe9 1000 resultados"})]})]}),Object(T.jsx)($,{headerWords:["N\xba","Serial","Modelo","NF","Revendedor","Cliente","Fabrica\xe7\xe3o","T\xe9cnico",Object(T.jsx)(k.a,{icon:"boxes"}),Object(T.jsx)(k.a,{icon:"tools"})],equipments:this.state.equipments,loading:this.state.loading})]})}}]),a}(h.a.Component),de=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(){var e;return Object(c.a)(this,a),(e=t.call(this)).getModels=Object(s.a)(Object(n.a)().mark((function t(){var a,s;return Object(n.a)().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/models/"),headers:{Authorization:"Token ".concat(m())}},t.next=3,d()(a);case 3:s=t.sent,e.setState({modelsArray:s.data});case 5:case"end":return t.stop()}}),t)}))),e.organizeModelsByCategory=function(){var t,a=Object(E.a)(e.state.modelsArray);try{for(a.s();!(t=a.n()).done;){var n=t.value;e.modelsByCategoryJSON.hasOwnProperty(n.category)||(e.modelsByCategoryJSON[n.category]=[]),e.modelsByCategoryJSON[n.category].push(n)}}catch(s){a.e(s)}finally{a.f()}},e.generateSelectOptions=function(){for(var t=[],a=0,n=Object.entries(e.modelsByCategoryJSON);a0&&0===this.state.optGroups.length&&(this.organizeModelsByCategory(),this.generateSelectOptions())}},{key:"render",value:function(){var e=this;return Object(T.jsxs)("select",{className:"w-full h-9 pl-2 border rounded-md bg-white",onChange:function(t){e.props.change(t),document.querySelector("#NF").focus()},defaultValue:"default",name:"modelo",children:[Object(T.jsx)("option",{value:"default",disabled:!0,hidden:!0,children:"Selecione o modelo"}),this.state.optGroups]})}}]),a}(h.a.Component),ue=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).getFieldUniqueValues=function(){var e,t=[],a=Object(E.a)(n.props.equipments);try{for(a.s();!(e=a.n()).done;){var s=e.value;s[n.props.field]&&t.push(s[n.props.field])}}catch(c){a.e(c)}finally{a.f()}n.setState({uniqueValues:Array.from(new Set(t))})},n.generateDatalistOptions=function(){n.setState({options:n.state.uniqueValues.map(n.valueToElement)})},n.valueToElement=function(e){return Object(T.jsx)("option",{value:e},e)},n.first_request=!0,n.state={uniqueValues:[],options:[]},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getFieldUniqueValues()}},{key:"componentDidUpdate",value:function(){this.first_request&&(this.first_request=!1,this.generateDatalistOptions())}},{key:"render",value:function(){return Object(T.jsx)("datalist",{id:this.props.id,children:this.state.options})}}]),a}(h.a.Component),he=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).displayTagsModal=function(){i.setState({displayTagsModal:!0})},i.hideTagsModal=function(){i.setState({displayTagsModal:!1})},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.getEquipments=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/equipments/"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:a=e.sent,i.setState({equipments:a.data});case 5:case"end":return e.stop()}}),e)}))),i.registerEquipments=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:""===(t=x(i.state.equipmentData)).value&&delete t.value,d.a.post("".concat("https://sys.gwenergy.com.br/api","/equipments/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){1===i.state.equipmentData.N_equipments?window.location.assign("./../view/#".concat(i.state.equipmentData.serial)):i.setState({equipmentData:i.defaultEquipmentData,responseData:e.data,displayTagsModal:!0})})).catch((function(e){console.log(e),409===e.response.status&&alert("Erro!\nComponente insuficiente: ".concat(e.response.data))}));case 3:case"end":return e.stop()}}),e)}))),i.handleInputChange=function(e){var t=e.target,a=t.name,n=t.value.toUpperCase();["value","client_phone"].includes(a)&&(n=C(n)),"modelo"===a&&i.getSerial(n),"serial"===a&&(n=n.replaceAll(" ","")),"value"===a&&(n=String(Number(n)));var s=x(i.state.equipmentData);s[a]=n,i.setState({equipmentData:s})},i.handleCheckboxChanges=function(e){var t=e.target,a=t.name,n=x(i.state.equipmentData);n[a]=t.checked,i.setState({equipmentData:n})},i.getSerial=function(){var e=Object(s.a)(Object(n.a)().mark((function e(t){return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:2===t.length&&(t="0"+t),d.a.get("".concat("https://sys.gwenergy.com.br/api","/equipments/generate_serial/?model=").concat(t),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){var t=x(i.state.equipmentData);t.serial=e.data,i.setState({equipmentData:t})})).catch((function(e){console.log(e)}));case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),i.defaultEquipmentData={N_equipments:1,use_components:!0,in_stock:!0,modelo:"",serial:"",NF:0,dealer:"",buyer:"",value:"0",client:"",CPF:"",client_phone:"",manufacturing_date:V(),start_of_warranty:V(),technician:"",comments:""},i.state={equipments:[],responseData:[],displayToast:!1,displayTagsModal:!1,equipmentData:x(i.defaultEquipmentData)},i.N_tags=4,i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao atualizar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getEquipments()}},{key:"render",value:function(){var e=this,t="flex-col ml-3",a="flex mt-4 mr-3 justify-evenly",n="w-full h-9 pl-2 border rounded-md";return Object(T.jsxs)("div",{className:"w-4/5 max-w-6xl border-2 rounded border-primary",id:"view",children:[this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("form",{id:"form",className:"flex-col",autoComplete:"off",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsx)("h1",{className:"text-center text-3xl my-6",children:"CADASTRAR EQUIPAMENTO"}),Object(T.jsx)(P,{isOpen:this.state.displayTagsModal,hideMethod:this.hideTagsModal,afterDownloadMethod:function(){window.location.assign("./../view/#".concat(e.state.responseData[0].serial))},equipmentsData:this.state.responseData}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"modelo",children:"Modelo"}),Object(T.jsx)(de,{change:this.handleInputChange.bind(this)})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"serial",children:"Serial"}),Object(T.jsx)("input",{required:!0,type:"text",name:"serial",className:"".concat(n),onChange:this.handleInputChange,value:g(this.state.equipmentData.serial)})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"NF",children:"NF"}),Object(T.jsx)("input",{required:!0,id:"NF",name:"NF",type:"number",onChange:this.handleInputChange,value:this.state.equipmentData.NF,className:"".concat(n," editable")})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/2"),children:[Object(T.jsx)("label",{className:"",htmlFor:"dealer",children:"Revendedor"}),Object(T.jsx)("input",{type:"text",name:"dealer",list:"dealers-list",onChange:this.handleInputChange,value:this.state.equipmentData.dealer,className:"".concat(n," editable")}),this.state.equipments.length>0&&Object(T.jsx)(ue,{field:"dealer",id:"dealers-list",equipments:this.state.equipments,value:this.state.equipmentData.dealer})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"buyer",children:"Comprador"}),Object(T.jsx)("input",{type:"text",name:"buyer",list:"buyers-list",onChange:this.handleInputChange,value:this.state.equipmentData.buyer,className:"".concat(n," editable")}),this.state.equipments.length>0&&Object(T.jsx)(ue,{field:"buyer",id:"buyers-list",equipments:this.state.equipments,value:this.state.equipmentData.dealer})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/4"),children:[Object(T.jsx)("label",{className:"",htmlFor:"value",children:"Valor"}),Object(T.jsx)("input",{type:"text",name:"value",required:!0,onChange:this.handleInputChange,className:"".concat(n," editable"),value:v(this.state.equipmentData.value)})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"client",children:"Cliente final"}),Object(T.jsx)("input",{type:"text",name:"client",list:"clients-list",onChange:this.handleInputChange,value:this.state.equipmentData.client,className:"".concat(n," editable")}),this.state.equipments.length>0&&Object(T.jsx)(ue,{field:"client",id:"clients-list",equipments:this.state.equipments,value:this.state.equipmentData.dealer})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"CPF",children:"CPF"}),Object(T.jsx)("input",{name:"CPF",type:"text",list:"CPFs-list",onChange:this.handleInputChange,className:"".concat(n," editable"),value:y(this.state.equipmentData.CPF)}),this.state.equipments.length>0&&Object(T.jsx)(ue,{field:"CPF",id:"CPFs-list",equipments:this.state.equipments,value:this.state.equipmentData.dealer})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"client_phone",children:"Telefone"}),Object(T.jsx)("input",{type:"text",list:"phones-list",name:"client_phone",onChange:this.handleInputChange,className:"".concat(n," editable"),value:N(this.state.equipmentData.client_phone)}),this.state.equipments.length>0&&Object(T.jsx)(ue,{field:"client_phone",id:"phones-list",equipments:this.state.equipments,value:this.state.equipmentData.dealer})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"manufacturing_date",children:"Data de fabrica\xe7\xe3o"}),Object(T.jsx)("input",{type:"date",name:"manufacturing_date",onChange:this.handleInputChange,className:"".concat(n," editable"),value:this.state.equipmentData.manufacturing_date})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"start_of_warranty",children:"In\xedcio da garantia"}),Object(T.jsx)("input",{type:"date",name:"start_of_warranty",onChange:this.handleInputChange,className:"".concat(n," editable"),value:this.state.equipmentData.start_of_warranty})]}),Object(T.jsxs)("div",{className:"".concat(t," w-1/3"),children:[Object(T.jsx)("label",{className:"",htmlFor:"technician",children:"T\xe9cnico respons\xe1vel"}),Object(T.jsx)("input",{required:!0,type:"text",name:"technician",list:"technicians-list",onChange:this.handleInputChange,className:"".concat(n," editable"),value:this.state.equipmentData.technician}),this.state.equipments.length>0&&Object(T.jsx)(I,{field:"technician",id:"technicians-list"})]})]}),Object(T.jsx)("div",{className:"".concat(a),children:Object(T.jsxs)("div",{className:"".concat(t," w-full"),children:[Object(T.jsx)("label",{className:"",htmlFor:"comments",children:"Coment\xe1rios"}),Object(T.jsx)("textarea",{rows:"5",name:"comments",onChange:this.handleInputChange,value:this.state.equipmentData.comments,className:"w-full pl-2 border rounded-md editable"})]})}),Object(T.jsxs)("div",{className:"flex ml-3 mr-3 mt-2 mb-4 justify-between",children:[Object(T.jsx)(q,{click:function(){e.validateForm()&&e.registerEquipments()},type:"submit",color:"green-500",width:"w-32",text:"Cadastrar",icon:"save"}),Object(T.jsxs)("div",{className:"h-10 flex items-center",children:[Object(T.jsx)("input",{type:"checkbox",name:"use_components",className:"w-6 h-6 mr-2",onChange:this.handleCheckboxChanges,checked:this.state.equipmentData.use_components}),Object(T.jsx)("label",{htmlFor:"use_components",children:"Consumir componentes"})]}),Object(T.jsxs)("div",{className:"h-10 flex items-center",children:[Object(T.jsx)("input",{type:"checkbox",name:"in_stock",className:"w-6 h-6 mr-2",onChange:this.handleCheckboxChanges,checked:this.state.equipmentData.in_stock}),Object(T.jsx)("label",{htmlFor:"in_stock",children:"Em estoque"})]}),Object(T.jsxs)("div",{className:"flex border rounded-md",children:[Object(T.jsx)("span",{className:"flex justify-center items-center w-32 rounded-l-md bg-gray-300",children:"Quantidade:"}),Object(T.jsx)("input",{min:"1",name:"N_equipments",type:"number",onChange:this.handleInputChange,value:this.state.equipmentData.N_equipments,className:"w-36 rounded-r-md text-center"})]})]})]})]})}}]),a}(h.a.Component),me=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(){var e;return Object(c.a)(this,a),(e=t.call(this)).state={},e}return Object(i.a)(a,[{key:"render",value:function(){return Object(T.jsx)("div",{className:"flex justify-center items-center h-auto w-full bg-secondary",children:Object(T.jsx)(he,{})})}}]),a}(h.a.Component),pe=a(38),be=a.n(pe);function je(e){var t=Object(G.n)(),a=e.os,n=e.rowNumber%2===0?"bg-gray-200":"bg-gray-100",s="pl-2 border border-gray-300",c=O(a.arrival_date),i=O(a.departure_date),o=Number(C(a.labor_value)),r=Number(C(a.components_value)),l=String(o+r);return Object(T.jsxs)("tr",{className:"".concat(s," ").concat(n," cursor-pointer hover:bg-white"),onClick:function(){return t("/view/?#".concat(a.serial))},children:[Object(T.jsx)("td",{className:"text-center",children:a.id}),Object(T.jsx)("td",{className:"".concat(s),children:a.serial}),Object(T.jsx)("td",{className:"".concat(s),children:c}),Object(T.jsx)("td",{className:"".concat(s),children:be()(i,"YYYY/MM/DD").isValid()?i:"N\xc3O DESPACHADO"}),Object(T.jsx)("td",{className:"".concat(s),children:a.technician}),Object(T.jsx)("td",{className:"".concat(s),children:[""," ",","].includes(v(a.components_value))?"-":"R$ ".concat(v(a.components_value))}),Object(T.jsx)("td",{className:"".concat(s),children:[""," ",","].includes(v(a.labor_value))?"-":"R$ ".concat(v(a.labor_value))}),Object(T.jsx)("td",{className:"".concat(s),children:[""," ",","].includes(v(l))?"-":"R$ ".concat(v(l))})]})}function xe(e){return Object(T.jsxs)("table",{className:"w-full bg-primary",children:[Object(T.jsx)("thead",{className:"text-white h-10",children:Object(T.jsx)("tr",{className:"text-left",children:e.headerWords.map((function(e){return Object(T.jsx)("th",{className:"pl-2",children:e},e)}))})}),Object(T.jsxs)("tbody",{children:[!e.loading&&e.serviceOrders.map((function(e,t){return Object(T.jsx)(je,{os:e,rowNumber:t+1},e.id)})),e.loading&&Object(T.jsx)("tr",{children:Object(T.jsx)("td",{colSpan:e.headerWords.length,className:"bg-secondary",children:Object(T.jsx)("div",{className:"h-screen flex justify-center mt-80",children:Object(T.jsx)(b.SyncLoader,{loading:!0,color:"#000"})})})})]})]})}var Oe=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).handleColumnSelectChanges=function(e){n.searchColumn=e.target.value,n.startPreRequestTimeout()},n.handleSituationSelectChanges=function(e){n.OSFilter=e.target.value,n.startPreRequestTimeout()},n.handleTextInput=function(e){n.searchText=e.target.value.toUpperCase(),n.startPreRequestTimeout()},n.startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getServiceOrders.bind(Object(j.a)(n)),1e3)},n.filterOSs=function(){switch(n.OSFilter){case"ALL":return n.state.serviceOrders;case"F":return n.state.serviceOrders.filter((function(e){return be()(e.departure_date,"YYYY/MM/DD").isValid()}));case"NF":return n.state.serviceOrders.filter((function(e){return!be()(e.departure_date,"YYYY/MM/DD").isValid()}));default:return[]}},n.OSFilter="NF",n.searchText="",n.searchColumn="id",n.state={loading:!1,serviceOrders:[]},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getServiceOrders()}},{key:"getServiceOrders",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.setState({loading:!0}),t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/service-orders/?").concat(this.searchColumn,"=").concat(this.searchText),headers:{Authorization:"Token ".concat(m())}},e.next=4,d()(t);case 4:a=e.sent,this.setState({serviceOrders:a.data,loading:!1});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this.filterOSs();return Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsxs)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:[Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300",children:[Object(T.jsx)(re,{className:"h-full w-32 pl-2 outline-none border-r border-gray-300 bg-white",optionValues:{OS:"id","T\xe9cnico":"technician"},onChange:this.handleColumnSelectChanges}),Object(T.jsx)("input",{type:"text",className:"h-9 w-52 px-4 uppercase outline-none focus:ring-2 focus:ring-tertiary",autoFocus:!0,onInput:this.handleTextInput}),Object(T.jsx)(k.a,{icon:"search",className:"mx-3 text-blue-600"})]}),Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300 bg-gray-200",children:[Object(T.jsx)("span",{className:"h-full mx-4",children:"Situa\xe7\xe3o"}),Object(T.jsx)(re,{className:"h-full w-52 pl-2 outline-none border-l border-gray-300 bg-white",optionValues:{"N\xc3O FINALIZADAS":"NF",FINALIZADAS:"F",TODAS:"ALL"},onChange:this.handleSituationSelectChanges})]})]}),Object(T.jsx)(xe,{headerWords:["OS","Serial","Entrada","Sa\xedda","T\xe9cnico","Componentes","M\xe3o de obra","Valor total"],serviceOrders:e,loading:this.state.loading})]})}}]),a}(h.a.Component),ge=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).handleInputChange=function(e){var t=e.target,a=t.name,n=t.value;["description","provider"].includes(a)&&(n=n.toUpperCase()),"value"===a&&(n=w(n),n=Number(n));var s=x(i.state.component);s[a]=n,i.setState({component:s})},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.saveComponent=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=x(i.state.component),d.a.post("".concat("https://sys.gwenergy.com.br/api","/components/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0}),setTimeout(window.location.reload.bind(window.location),1e3)})).catch((function(e){i.successfulUpdate=!1,i.setState({displayToast:!0})}));case 2:case"end":return e.stop()}}),e)}))),i.state={component:{description:"",ncm:"",measurement_unit:"UN",amount:0,min_amount:1,value:1,provider:"",its_compound:!1},displayToast:!1},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao salvar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro salvo!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"render",value:function(){var e=this,t="w-full h-9 pl-2 border border-gray-400 rounded-md",a="mt-4";return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{height:"fit-content",width:"440px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Novo componente"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex text-2xl font-bolder",children:Object(T.jsxs)("form",{id:"form",autoComplete:"off",className:"flex-col text-base",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"description",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"description",value:this.state.component.description,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"ncm",children:"NCM"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"ncm",maxLength:8,value:this.state.component.ncm,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"measurement_unit",children:"Unidade de medida"}),Object(T.jsxs)("select",{className:"".concat(t," bg-white"),name:"measurement_unit",value:this.state.component.measurement_unit,onChange:this.handleInputChange,children:[Object(T.jsx)("option",{value:"UN",children:"Unidade"}),Object(T.jsx)("option",{value:"MT",children:"Metro"}),Object(T.jsx)("option",{value:"GM",children:"Grama"})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"amount",children:"Quantidade"}),Object(T.jsx)("input",{className:"".concat(t),type:"number",name:"amount",value:this.state.component.amount,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"min_amount",children:"Quantidade m\xednima"}),Object(T.jsx)("input",{className:"".concat(t),type:"number",name:"min_amount",value:this.state.component.min_amount,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"value",children:"Valor"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"value",value:"R$ ".concat(f(String(this.state.component.value))),onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"provider",children:"Fornecedor"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"provider",value:this.state.component.provider,onChange:this.handleInputChange})]})]})}),Object(T.jsxs)("div",{className:"flex justify-between mt-6 mb-2",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:function(){e.validateForm()&&e.saveComponent()},type:"submit",color:"green-500",width:"w-32",text:"Cadastrar",icon:"save"})]})]})}}]),a}(h.a.Component);function fe(e){var t=e.component,a="pl-2 border border-gray-300",n=t.min_amount>t.amount;document.body.style.cursor="auto";var s=e.rowNumber%2===0?"bg-gray-200":"bg-gray-100";function c(a,n){document.body.style.cursor="progress","value"===a&&(n=Number(w(n))),("string"===typeof n||n instanceof String)&&(n=n.toUpperCase()),function(e,t){if("measurement_unit"===e&&!["UN","MT","GM"].includes(t))return alert('Unidade deve ser um valor entre "UN", "MT" e "GM"'),!1;if("value"===e&&!S(t))return alert("Valor inv\xe1lido"),!1;if("ncm"===e&&""!==t&&8!==t.length)return alert("NCM deve possui 8 d\xedgitos"),!1;if(["amount","min_amount"].includes(e)&&!S(t))return alert("Quantidades devem ser n\xfameros!"),!1;return!0}(a,n)&&String(t[a])!==String(n)&&e.updateMethod(t.id,a,n)}return n&&(s="bg-red-400"),Object(T.jsxs)("tr",{className:"".concat(a," ").concat(s," ").concat(n?"":"hover:bg-white"," uppercase"),children:[Object(T.jsx)("td",{className:"text-center",children:t.id}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("description",e.target.innerHTML)},children:t.description}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("ncm",e.target.innerHTML)},children:t.ncm}),Object(T.jsx)("td",{className:"".concat(a," uppercase"),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("measurement_unit",e.target.innerHTML)},children:t.measurement_unit}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("min_amount",e.target.innerHTML)},children:t.min_amount}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("amount",e.target.innerHTML)},children:t.amount}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("value",e.target.innerHTML)},children:"R$ ".concat(f(String(t.value)))}),Object(T.jsx)("td",{className:"".concat(a),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(e){return c("provider",e.target.innerHTML)},children:t.provider}),Object(T.jsx)("td",{className:"".concat(a," text-center"),contentEditable:!1,suppressContentEditableWarning:!0,children:Object(T.jsx)("input",{type:"checkbox",className:"w-4 h-4",checked:t.should_export,onChange:function(e){c("should_export",e.target.checked)}})}),Object(T.jsx)("td",{className:"border border-gray-300 px-2 text-center",children:Object(T.jsx)("button",{onClick:function(){return e.displayDeleteModal(t.id)},children:Object(T.jsx)(k.a,{icon:"trash",className:"mx-3 text-red-500"})})})]})}var ve=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;Object(c.a)(this,a),(i=t.call(this,e)).handleSimpleComponentsChange=function(e){var t=e.target,a=t.name,n=t.value;if(!(n<0)){var s=x(i.state.simpleComponents);s[a].N=n,i.setState({simpleComponents:s})}},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.updateComponent=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:(t=i.state.component).subcomponents=i.state.simpleComponents.filter((function(e){return Number(e.N)>0})),d.a.put("".concat("https://sys.gwenergy.com.br/api","/components/").concat(t.id,"/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0}),setTimeout(window.location.reload.bind(window.location),1e3)})).catch((function(e){i.successfulUpdate=!1,i.setState({displayToast:!0})}));case 3:case"end":return e.stop()}}),e)})));var o=e.simpleComponents;return(e.componentsList?e.componentsList.components:[]).forEach((function(e){o.forEach((function(t){e.component===t.id&&(t.N=e.amount)}))})),i.state={displayToast:!1,component:e.component,simpleComponents:o,defaultSimpleComponents:o},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao salvar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro salvo!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"componentDidUpdate",value:function(){var e=this.state.defaultSimpleComponents!==this.state.simpleComponents;!this.props.isOpen&&e&&this.setState({simpleComponents:this.state.defaultSimpleComponents})}},{key:"render",value:function(){var e=this;return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{maxHeight:"720px",height:"fit-content",width:"500px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Sub-componentes"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex text-2xl font-bolder",children:Object(T.jsxs)("form",{id:"form",autoComplete:"off",className:"flex-col text-base",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsx)("label",{htmlFor:"description",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{type:"text",disabled:!0,name:"description",value:this.state.component.description,className:"w-full h-9 pl-2 border border-gray-400 rounded-md"})]}),Object(T.jsxs)("div",{className:"mt-4",children:[Object(T.jsxs)("div",{className:"flex justify-between",children:[Object(T.jsx)("p",{children:"Sub-componente"}),Object(T.jsx)("p",{children:"Quantidade"})]}),Object(T.jsx)("fieldset",{className:"w-full border rounded-md overflow-hidden border-gray-400 bg-blue-400",children:this.state.simpleComponents.map((function(t,a){return Object(T.jsxs)("div",{className:"py-1 flex items-center justify-between overflow-none ".concat(t.N>0?"bg-blue-400":"bg-white"),children:[Object(T.jsx)("label",{htmlFor:a,className:"flex-1 pl-3",children:t.description.substring(0,40)}),Object(T.jsx)("input",{name:a,type:"number",value:t.N,className:"w-1/6 bg-transparent outline-none text-center",onChange:e.handleSimpleComponentsChange})]},a)}))})]})]})}),Object(T.jsxs)("div",{className:"flex justify-between mt-6 mb-2",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:function(){e.validateForm()&&e.updateComponent()},type:"submit",color:"green-500",width:"w-32",text:"Atualizar",icon:"save"})]})]})}}]),a}(h.a.Component),ye=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).updateComponent=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t={number_of_new_registers:i.state.numberOfNewRegisters},d.a.patch("".concat("https://sys.gwenergy.com.br/api","/components/").concat(i.props.component.id,"/update_inventory/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){window.location.reload()})).catch((function(e){409===e.response.status&&alert("Erro!\nComponente insuficiente: ".concat(e.response.data))}));case 2:case"end":return e.stop()}}),e)}))),i.state={numberOfNewRegisters:1},i}return Object(i.a)(a,[{key:"render",value:function(){var e=this,t="w-10 h-10 bg-tertiary hover:bg-gray-400";return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005"},content:{height:"250px",width:"550px",margin:"auto",border:"2px solid #000c"}},children:[Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Quantidade de componentes fabricados:"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex justify-center h-10 mt-12 text-2xl font-bolder",children:Object(T.jsxs)("div",{className:"h-11 fit-content border-2 rounded border-gray-600",children:[Object(T.jsx)("button",{className:t,onClick:function(){e.state.numberOfNewRegisters>1&&e.setState({numberOfNewRegisters:e.state.numberOfNewRegisters-1})},children:"-"}),Object(T.jsx)("input",{type:"text",id:"tags_modal_input",className:"w-12 h-10 text-center bg-gray-100",onChange:function(t){var a=Number(t.target.value);a&&e.setState({numberOfNewRegisters:a})},value:this.state.numberOfNewRegisters}),Object(T.jsx)("button",{className:t,onClick:function(){e.setState({numberOfNewRegisters:e.state.numberOfNewRegisters+1})},children:"+"})]})}),Object(T.jsxs)("div",{className:"flex justify-end mt-10",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:this.updateComponent,color:"green-500",width:"w-28",text:"Cadastrar",icon:"cog"})]})]})}}]),a}(h.a.Component),Ne=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).state={displayEditModal:!1,displayInsertModal:!1},n}return Object(i.a)(a,[{key:"updateComponent",value:function(e,t){"value"===e&&(t=Number(w(t))),("string"===typeof t||t instanceof String)&&(t=t.toUpperCase()),this.isValid(e,t)&&String(this.props.component[e])!==String(t)&&this.props.updateMethod(this.props.component.id,e,t)}},{key:"isValid",value:function(e,t){return"measurement_unit"!==e||["UN","MT","GM"].includes(t)?"value"!==e||S(t)?"ncm"===e&&""!==t&&8!==t.length?(alert("NCM deve possui 8 d\xedgitos"),!1):!(["amount","min_amount"].includes(e)&&!S(t))||(alert("Quantidades devem ser n\xfameros!"),!1):(alert("Valor inv\xe1lido"),!1):(alert('Unidade deve ser um valor entre "UN", "MT" e "GM"'),!1)}},{key:"render",value:function(){var e=this;return this.criticalAmount=this.props.component.min_amount>this.props.component.amount,this.rowColor=this.props.rowNumber%2===0?"bg-gray-200":"bg-gray-100",this.criticalAmount&&(this.rowColor="bg-red-400"),this.rowStyle="pl-2 border border-gray-300",Object(T.jsxs)("tr",{className:"".concat(this.rowStyle," ").concat(this.rowColor," ").concat(this.criticalAmount?"":"hover:bg-white"," uppercase"),children:[Object(T.jsx)(ye,{isOpen:this.state.displayInsertModal,component:this.props.component,hideMethod:function(){e.setState({displayInsertModal:!1})}}),this.props.simpleComponents.length>0&&Object(T.jsx)(ve,{isOpen:this.state.displayEditModal,hideMethod:function(){e.setState({displayEditModal:!1})},component:this.props.component,componentsList:this.props.componentsList,simpleComponents:this.props.simpleComponents}),Object(T.jsx)("td",{className:"text-center",children:this.props.component.id}),Object(T.jsx)("td",{className:"".concat(this.rowStyle),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("description",t.target.innerHTML)},children:this.props.component.description}),Object(T.jsx)("td",{className:"".concat(this.rowStyle),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("ncm",t.target.innerHTML)},children:this.props.component.ncm}),Object(T.jsx)("td",{className:"".concat(this.rowStyle," uppercase"),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("measurement_unit",t.target.innerHTML)},children:this.props.component.measurement_unit}),Object(T.jsx)("td",{className:"".concat(this.rowStyle),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("min_amount",t.target.innerHTML)},children:this.props.component.min_amount}),Object(T.jsx)("td",{className:"".concat(this.rowStyle),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("amount",t.target.innerHTML)},children:this.props.component.amount}),Object(T.jsx)("td",{className:"".concat(this.rowStyle),contentEditable:!0,suppressContentEditableWarning:!0,onBlur:function(t){return e.updateComponent("value",t.target.innerHTML)},children:"R$ ".concat(f(String(this.props.component.value)))}),Object(T.jsx)("td",{className:"border border-gray-300 px-2 text-center",children:Object(T.jsx)("button",{onClick:function(){e.setState({displayInsertModal:!0})},children:Object(T.jsx)(k.a,{icon:"plus",className:"mx-3 text-green-600"})})}),Object(T.jsx)("td",{className:"border border-gray-300 px-2 text-center",children:Object(T.jsx)("button",{onClick:function(){e.setState({displayEditModal:!0})},children:Object(T.jsx)(k.a,{icon:"list",className:"mx-3 text-blue-500"})})}),Object(T.jsx)("td",{className:"border border-gray-300 px-2 text-center",children:Object(T.jsx)("button",{onClick:function(){return e.props.displayDeleteModal(e.props.component.id)},children:Object(T.jsx)(k.a,{icon:"trash",className:"mx-3 text-red-500"})})})]},this.props.component.amount)}}]),a}(h.a.Component);function we(e){var t="pl-2",a=0;return e.components.map((function(e){return a+=e.value*e.amount})),Object(T.jsxs)("table",{className:"w-full bg-primary",children:[Object(T.jsx)("thead",{className:"text-white h-10",children:Object(T.jsx)("tr",{className:"text-left",children:e.headerWords.map((function(e,a){return Object(T.jsx)("th",{className:t,children:e},a)}))})}),Object(T.jsxs)("tbody",{children:[!e.loading&&!e.compound&&e.components.map((function(t,a){return Object(T.jsx)(fe,{component:t,rowNumber:a+1,updateMethod:e.updateMethod,displayDeleteModal:e.displayDeleteModal},t.id)})),!e.loading&&e.compound&&e.dataLoaded&&e.components.map((function(t,a){return Object(T.jsx)(Ne,{component:t,rowNumber:a+1,updateMethod:e.updateMethod,simpleComponents:e.simpleComponents?x(e.simpleComponents):e.simpleComponents,componentsList:e.componentsLists[t.id]?x(e.componentsLists[t.id]):e.componentsLists[t.id],displayDeleteModal:e.displayDeleteModal},t.id)})),(e.loading||!e.dataLoaded)&&Object(T.jsx)("tr",{children:Object(T.jsx)("td",{colSpan:e.headerWords.length,className:"bg-secondary",children:Object(T.jsx)("div",{className:"h-screen flex justify-center mt-80",children:Object(T.jsx)(b.SyncLoader,{loading:!0,color:"#000"})})})})]}),Object(T.jsx)("thead",{className:"text-white text-base h-7",children:Object(T.jsxs)("tr",{className:"text-left",children:[Object(T.jsx)("th",{}),Object(T.jsx)("th",{}),Object(T.jsx)("th",{}),Object(T.jsx)("th",{}),Object(T.jsx)("th",{}),Object(T.jsx)("th",{}),Object(T.jsxs)("th",{className:t,children:["Total: R$ ",f(String(a))]})]})})]})}function Ce(e){return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:e.isOpen,onRequestClose:e.hideMethod,style:{overlay:{backgroundColor:"#0005"},content:{height:"250px",width:"300px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Escolha uma data"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:e.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex justify-center h-10 mt-12 text-2xl font-bolder",children:Object(T.jsx)("input",{type:"date",name:"date",defaultValue:new Date((new Date).valueOf()-864e5).toLocaleDateString("en-CA"),className:"w-full h-9 pl-2 border border-gray-400 rounded-md"})}),Object(T.jsx)("div",{className:"flex justify-end mt-10",children:Object(T.jsx)(q,{click:function(){!function(e){Se.apply(this,arguments)}(document.getElementsByName("date")[0].value)},color:"green-500",width:"w-28",text:"Gerar",icon:"cog"})})]})}function Se(){return(Se=Object(s.a)(Object(n.a)().mark((function e(t){return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("".concat("https://sys.gwenergy.com.br/api","/stock-reports/?date=").concat(t),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){return e.blob()})).then((function(e){var a=document.createElement("a");a.href=URL.createObjectURL(e),a.download="estoque_".concat(t,".xlsx"),a.click()})).catch((function(e){console.log(e)}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ke=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).displayNewComponentModal=function(){n.setState({displayNewComponentModal:!0})},n.hideNewComponentModal=function(){n.setState({displayNewComponentModal:!1})},n.displayReportModal=function(){n.setState({displayReportModal:!0})},n.hideReportModal=function(){n.setState({displayReportModal:!1})},n.displayDeleteModal=function(e){n.componentToDelete=e,n.setState({displayDeleteModal:!0})},n.hideDeleteModal=function(){n.setState({displayDeleteModal:!1})},n.handleTextInput=function(e){n.searchText=e.target.value.toUpperCase(),n.startPreRequestTimeout()},n.handleCheckboxChanges=function(e){var t=e.target;n.setState({missingComponents:t.checked})},n.startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getComponents.bind(Object(j.a)(n)),1e3)},n.searchText="",n.state={components:[],loading:!1,missingComponents:!1,displayDeleteModal:!1,displayReportModal:!1,displayNewComponentModal:!1},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getComponents(!0)}},{key:"getComponents",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a,s,c=arguments;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(t=!(c.length>0&&void 0!==c[0])||c[0])&&this.setState({loading:!0}),a={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components/?its_compound=0&description=").concat(this.searchText),headers:{Authorization:"Token ".concat(m())}},e.next=5,d()(a);case 5:s=e.sent,t?this.setState({components:s.data,loading:!1}):this.setState({components:s.data});case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateComponent",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(t,a,s){var c,i=this;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:(c={})[a]=s,d.a.patch("".concat("https://sys.gwenergy.com.br/api","/components/").concat(t,"/"),c,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.getComponents(!1)})).catch((function(e){console.log(e)}));case 3:case"end":return e.stop()}}),e)})));return function(t,a,n){return e.apply(this,arguments)}}()},{key:"deleteComponent",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t=this;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:d.a.delete("".concat("https://sys.gwenergy.com.br/api","/components/").concat(this.componentToDelete,"/"),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){t.hideDeleteModal(),t.getComponents()})).catch((function(e){400===e.response.status&&alert("Erro!\nComponente utilizado por: ".concat(e.response.data))}));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this.state.components;return this.state.missingComponents&&(e=e.filter((function(e){return e.min_amount>e.amount}))),Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsx)(ge,{isOpen:this.state.displayNewComponentModal,hideMethod:this.hideNewComponentModal}),Object(T.jsx)(Ce,{isOpen:this.state.displayReportModal,hideMethod:this.hideReportModal}),Object(T.jsx)(W,{delMethod:this.deleteComponent.bind(this),isOpen:this.state.displayDeleteModal,hideMethod:this.hideDeleteModal}),Object(T.jsxs)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:[Object(T.jsx)(F,{size:"12",color:"gray-500",icon:"file-csv",custom_style:"mr-8",click:this.displayReportModal}),Object(T.jsx)(F,{size:"12",color:"blue-500",icon:"plus",custom_style:"mr-10",click:this.displayNewComponentModal}),Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300 bg-gray-200",children:[Object(T.jsx)("span",{className:"h-full mx-4",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{type:"text",className:"h-full w-52 px-4 uppercase outline-none focus:ring-2 focus:ring-tertiary",autoFocus:!0,onInput:this.handleTextInput}),Object(T.jsx)(k.a,{icon:"search",className:"mx-3 text-blue-600"})]}),Object(T.jsxs)("div",{className:"h-10 flex items-center",children:[Object(T.jsx)("input",{type:"checkbox",id:"limit_results",className:"w-5 h-5 mr-2",onChange:this.handleCheckboxChanges}),Object(T.jsx)("label",{htmlFor:"limit_results",children:"Apenas componentes em falta"})]})]}),Object(T.jsx)(we,{compound:!1,dataLoaded:!0,loading:this.state.loading,components:e,updateMethod:this.updateComponent.bind(this),displayDeleteModal:this.displayDeleteModal.bind(this),headerWords:["C\xf3digo","Descri\xe7\xe3o","NCM","Unidade","Quantidade m\xednima","Quantidade","Valor","Fornecedor","Exportar",""]})]})}}]),a}(h.a.Component),Te=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var i;return Object(c.a)(this,a),(i=t.call(this,e)).handleInputChange=function(e){var t=e.target,a=t.name,n=t.value;["description","provider"].includes(a)&&(n=n.toUpperCase());var s=x(i.state.component);s[a]=n,i.setState({component:s})},i.handleSimpleComponentsChange=function(e){var t=e.target,a=t.name,n=t.value;if(!(n<0)){var s=x(i.state.simpleComponents);s[a].N=n,i.setState({simpleComponents:s})}},i.validateForm=function(){return document.querySelector("#form").checkValidity()},i.saveComponent=Object(s.a)(Object(n.a)().mark((function e(){var t;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:(t=i.state.component).subcomponents=i.state.simpleComponents.filter((function(e){return Number(e.N)>0})),d.a.post("".concat("https://sys.gwenergy.com.br/api","/components/"),t,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.successfulUpdate=!0,i.setState({displayToast:!0}),setTimeout(window.location.reload.bind(window.location),1e3)})).catch((function(e){i.successfulUpdate=!1,i.setState({displayToast:!0})}));case 3:case"end":return e.stop()}}),e)}))),i.state={component:{description:"",ncm:"",measurement_unit:"UN",amount:0,min_amount:1,value:0,provider:"",its_compound:!0},displayToast:!1,simpleComponents:[]},i.errorToastData={title:"Erro",color:"bg-red-700",position:"top_right",text:"Falha ao salvar!",icon:"exclamation-circle",click:i.setState.bind(Object(j.a)(i))},i.successToastData={title:"Sucesso",color:"bg-green-600",position:"top_right",text:"Registro salvo!",icon:"check-circle",click:i.setState.bind(Object(j.a)(i))},i}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getComponents()}},{key:"getComponents",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components/?its_compound=0"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:(a=e.sent).data.forEach((function(e){e.N=0})),this.setState({simpleComponents:a.data});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this,t="w-full h-9 pl-2 border border-gray-400 rounded-md",a="mt-4";return Object(T.jsxs)(D.a,{ariaHideApp:!1,isOpen:this.props.isOpen,onRequestClose:this.props.hideMethod,style:{overlay:{backgroundColor:"#0005",overflowY:"auto"},content:{maxHeight:"720px",height:"fit-content",width:"500px",margin:"auto",border:"2px solid #000c",backgroundColor:"#f3f4f5"}},children:[this.state.displayToast&&this.successfulUpdate&&Object(T.jsx)(_,{data:this.successToastData}),this.state.displayToast&&!this.successfulUpdate&&Object(T.jsx)(_,{data:this.errorToastData}),Object(T.jsxs)("div",{className:"flex justify-between text-2xl font-bold",children:[Object(T.jsx)("h2",{children:"Novo componente"}),Object(T.jsx)("button",{className:"font-bold text-gray-600",onClick:this.props.hideMethod,children:"X"})]}),Object(T.jsx)("div",{className:"flex text-2xl font-bolder",children:Object(T.jsxs)("form",{id:"form",autoComplete:"off",className:"flex-col text-base",onSubmit:function(e){return e.preventDefault(),!1},children:[Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"description",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"description",value:this.state.component.description,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"ncm",children:"NCM"}),Object(T.jsx)("input",{className:"".concat(t),type:"text",name:"ncm",maxLength:8,value:this.state.component.ncm,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"measurement_unit",children:"Unidade de medida"}),Object(T.jsxs)("select",{className:"".concat(t," bg-white"),name:"measurement_unit",value:this.state.component.measurement_unit,onChange:this.handleInputChange,children:[Object(T.jsx)("option",{value:"UN",children:"Unidade"}),Object(T.jsx)("option",{value:"MT",children:"Metro"}),Object(T.jsx)("option",{value:"GM",children:"Grama"})]})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"amount",children:"Quantidade"}),Object(T.jsx)("input",{className:"".concat(t),type:"number",name:"amount",value:this.state.component.amount,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsx)("label",{htmlFor:"min_amount",children:"Quantidade m\xednima"}),Object(T.jsx)("input",{className:"".concat(t),type:"number",name:"min_amount",value:this.state.component.min_amount,onChange:this.handleInputChange})]}),Object(T.jsxs)("div",{className:"".concat(a),children:[Object(T.jsxs)("div",{className:"flex justify-between",children:[Object(T.jsx)("p",{children:"Sub-componente"}),Object(T.jsx)("p",{children:"Quantidade"})]}),Object(T.jsx)("fieldset",{className:"w-full border rounded-md overflow-hidden border-gray-400 bg-blue-400",children:this.state.simpleComponents.map((function(t,a){return Object(T.jsxs)("div",{className:"py-1 flex items-center justify-between overflow-none ".concat(t.N>0?"bg-blue-400":"bg-white"),children:[Object(T.jsx)("label",{htmlFor:a,className:"flex-1 pl-3",children:t.description.substring(0,40)}),Object(T.jsx)("input",{name:a,type:"number",value:t.N,className:"w-1/6 bg-transparent outline-none text-center",onChange:e.handleSimpleComponentsChange})]},a)}))})]})]})}),Object(T.jsxs)("div",{className:"flex justify-between mt-6 mb-2",children:[Object(T.jsx)(q,{click:this.props.hideMethod,color:"red-500",width:"w-32",text:"Cancelar",icon:"ban"}),Object(T.jsx)(q,{click:function(){e.validateForm()&&e.saveComponent()},type:"submit",color:"green-500",width:"w-32",text:"Cadastrar",icon:"save"})]})]})}}]),a}(h.a.Component),_e=function(e){Object(o.a)(a,e);var t=Object(r.a)(a);function a(e){var n;return Object(c.a)(this,a),(n=t.call(this,e)).displayNewComponentModal=function(){n.setState({displayNewComponentModal:!0})},n.hideNewComponentModal=function(){n.setState({displayNewComponentModal:!1})},n.displayDeleteModal=function(e){n.componentToDelete=e,n.setState({displayDeleteModal:!0})},n.hideDeleteModal=function(){n.setState({displayDeleteModal:!1})},n.handleTextInput=function(e){n.searchText=e.target.value.toUpperCase(),n.startPreRequestTimeout()},n.handleCheckboxChanges=function(e){var t=e.target;n.setState({missingComponents:t.checked})},n.startPreRequestTimeout=function(){clearTimeout(n.timeout),n.timeout=setTimeout(n.getComponents.bind(Object(j.a)(n)),1e3)},n.searchText="",n.state={components:[],componentsLists:{},simpleComponents:[],loading:!1,dataLoaded:!1,missingComponents:!1,displayDeleteModal:!1,displayNewComponentModal:!1},n}return Object(i.a)(a,[{key:"componentDidMount",value:function(){this.getComponents(!0),this.getSimpleComponents(),this.getComponentsLists()}},{key:"getComponents",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a,s,c=arguments;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(t=!(c.length>0&&void 0!==c[0])||c[0])&&this.setState({loading:!0}),a={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components/?its_compound=1&description=").concat(this.searchText),headers:{Authorization:"Token ".concat(m())}},e.next=5,d()(a);case 5:s=e.sent,t?this.setState({components:s.data,loading:!1}):this.setState({components:s.data});case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"getSimpleComponents",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components/?its_compound=0"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:(a=e.sent).data.forEach((function(e){e.N=0})),this.setState({simpleComponents:a.data});case 6:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"getComponentsLists",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t,a,s;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t={method:"get",url:"".concat("https://sys.gwenergy.com.br/api","/components-lists/"),headers:{Authorization:"Token ".concat(m())}},e.next=3,d()(t);case 3:a=e.sent,s={},a.data.forEach((function(e){e.component&&(s[e.component]=e)})),this.setState({dataLoaded:!0,componentsLists:s});case 7:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"updateComponent",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(t,a,s){var c,i=this;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:(c={})[a]=s,d.a.patch("".concat("https://sys.gwenergy.com.br/api","/components/").concat(t,"/"),c,{headers:{Authorization:"Token ".concat(m())}}).then((function(e){i.getComponents(!1)})).catch((function(e){console.log(e)}));case 3:case"end":return e.stop()}}),e)})));return function(t,a,n){return e.apply(this,arguments)}}()},{key:"deleteComponent",value:function(){var e=Object(s.a)(Object(n.a)().mark((function e(){var t=this;return Object(n.a)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:d.a.delete("".concat("https://sys.gwenergy.com.br/api","/components/").concat(this.componentToDelete,"/"),{headers:{Authorization:"Token ".concat(m())}}).then((function(e){t.hideDeleteModal(),t.getComponents()})).catch((function(e){console.log(e)}));case 1:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}()},{key:"render",value:function(){var e=this.state.components;return this.state.missingComponents&&(e=e.filter((function(e){return e.min_amount>e.amount}))),Object(T.jsxs)("div",{className:"inline-block h-screen overflow-x-hidden overflow-y-scroll w-full bg-secondary",children:[Object(T.jsx)(Te,{isOpen:this.state.displayNewComponentModal,hideMethod:this.hideNewComponentModal}),Object(T.jsx)(W,{delMethod:this.deleteComponent.bind(this),isOpen:this.state.displayDeleteModal,hideMethod:this.hideDeleteModal}),Object(T.jsxs)("nav",{className:"w-full h-20 flex sticky top-0 items-center justify-center bg-secondary",children:[Object(T.jsx)(F,{size:"12",color:"blue-500",icon:"plus",custom_style:"mr-10",click:this.displayNewComponentModal}),Object(T.jsxs)("div",{className:"h-10 mr-10 border rounded border-gray-300 bg-gray-200",children:[Object(T.jsx)("span",{className:"h-full mx-4",children:"Descri\xe7\xe3o"}),Object(T.jsx)("input",{type:"text",className:"h-full w-52 px-4 uppercase outline-none focus:ring-2 focus:ring-tertiary",autoFocus:!0,onInput:this.handleTextInput}),Object(T.jsx)(k.a,{icon:"search",className:"mx-3 text-blue-600"})]}),Object(T.jsxs)("div",{className:"h-10 flex items-center",children:[Object(T.jsx)("input",{type:"checkbox",id:"limit_results",className:"w-5 h-5 mr-2",onChange:this.handleCheckboxChanges}),Object(T.jsx)("label",{htmlFor:"limit_results",children:"Apenas componentes em falta"})]})]}),Object(T.jsx)(we,{compound:!0,loading:this.state.loading,components:e,dataLoaded:this.state.dataLoaded,componentsLists:this.state.componentsLists,simpleComponents:this.state.simpleComponents,updateMethod:this.updateComponent.bind(this),displayDeleteModal:this.displayDeleteModal.bind(this),headerWords:["C\xf3digo","Descri\xe7\xe3o","NCM","Unidade","Quantidade m\xednima","Quantidade","Valor","","",""]})]})}}]),a}(h.a.Component),Me=a(29),De=a(20);function qe(){var e=Object(G.n)();return m()?Object(T.jsxs)("div",{className:"min-h-screen overflow-x-hidden flex bg-primary text-md",children:[Object(T.jsx)(te,{}),Object(T.jsxs)(G.c,{children:[Object(T.jsx)(G.a,{path:"*",element:Object(T.jsx)(le,{})}),Object(T.jsx)(G.a,{path:"view/*",element:Object(T.jsx)(X,{})}),Object(T.jsx)(G.a,{path:"models/",element:Object(T.jsx)(ie,{})}),Object(T.jsx)(G.a,{path:"search/",element:Object(T.jsx)(le,{})}),Object(T.jsx)(G.a,{path:"inventory/",element:Object(T.jsx)(J,{})}),Object(T.jsx)(G.a,{path:"register/",element:Object(T.jsx)(me,{})}),Object(T.jsx)(G.a,{path:"service-orders/",element:Object(T.jsx)(Oe,{})}),Object(T.jsx)(G.a,{path:"components/",element:Object(T.jsx)(ke,{})}),Object(T.jsx)(G.a,{path:"compound-components/",element:Object(T.jsx)(_e,{})})]})]}):Object(T.jsx)(Y,{setToken:p,navigate:e})}Me.b.add(De.a,De.g,De.h,De.l,De.o,De.i,De.n,De.b,De.m,De.r,De.s,De.d,De.p,De.k,De.c,De.q,De.e,De.f,De.j);var Fe=a(53),Ie=function(e){e&&e instanceof Function&&a.e(6).then(a.bind(null,353)).then((function(t){var a=t.getCLS,n=t.getFID,s=t.getFCP,c=t.getLCP,i=t.getTTFB;a(e),n(e),s(e),c(e),i(e)}))};a.n(Fe).a.render(Object(T.jsx)(h.a.StrictMode,{children:Object(T.jsx)(Z.a,{children:Object(T.jsx)(qe,{})})}),document.getElementById("root")),Ie()},78:function(e,t,a){},79:function(e,t,a){}},[[178,1,2]]]); //# sourceMappingURL=main.00ee0930.chunk.js.map