text: (window.webpackJsonp=window.webpackJsonp||[]).push([[0],{15:function(e,n,t){e.exports=t(39)},38:function(e,n,t){},39:function(e,n,t){"use strict";t.r(n);var a=t(0),r=t.n(a),u=t(13),c=t.n(u),o=t(14),l=t(2),i=t(3),m=t.n(i),f="/api/persons",d=function(){return m.a.get(f).then(function(e){return e.data})},s=function(e){return m.a.post(f,e).then(function(e){return e.data})},b=function(e){return m.a.delete("".concat(f,"/").concat(e)).then(function(e){return e.data})},h=function(e,n){return m.a.put("".concat(f,"/").concat(e),n).then(function(e){return e.data})},v=function(e){return r.a.createElement("div",null,"filter shown with ",r.a.createElement("input",{value:e.value,onChange:e.onChange}))},E=function(e){var n=e.actions,t=n.addPerson,a=n.newName,u=n.newNumber,c=n.handleNameChange,o=n.handleNumberChange;return r.a.createElement("form",{onSubmit:t},r.a.createElement("div",null,"name: ",r.a.createElement("input",{value:a,onChange:c})),r.a.createElement("div",null,"number: ",r.a.createElement("input",{value:u,onChange:o})),r.a.createElement("div",null,r.a.createElement("button",{type:"submit"},"add")))},p=function(e){var n=e.name,t=e.number,a=e.id,u=e.removePerson;return r.a.createElement("tr",null,r.a.createElement("td",null,n),r.a.createElement("td",null,t),r.a.createElement("td",null,r.a.createElement("button",{onClick:function(){return function(){if(window.confirm("Delete ".concat(n,"?")))return u(a)}()}},"delete")))},w=function(e){var n=e.persons,t=e.filterName,a=e.removePerson;return r.a.createElement("table",null,r.a.createElement("tbody",null,n.filter(function(e){return e.name&&-1!==e.name.toLowerCase().search(t.toLowerCase())}).map(function(e){var n=e.name,t=e.number,u=e.id;return r.a.createElement(p,{name:n,id:u,number:t,key:u,removePerson:a})})))},g=function(e){var n=e.message,t=e.type;return null===n?null:r.a.createElement("div",{className:t},n)},j=(t(38),function(){var e=Object(a.useState)([]),n=Object(l.a)(e,2),t=n[0],u=n[1],c=Object(a.useState)(""),i=Object(l.a)(c,2),m=i[0],f=i[1],p=Object(a.useState)(""),j=Object(l.a)(p,2),O=j[0],N=j[1],C=Object(a.useState)(""),y=Object(l.a)(C,2),P=y[0],S=y[1],k=Object(a.useState)(null),D=Object(l.a)(k,2),I=D[0],J=D[1],L=Object(a.useState)(null),x=Object(l.a)(L,2),A=x[0],B=x[1],T=function(e,n){J(e),B(n),setTimeout(function(){J(null)},5e3)};return Object(a.useEffect)(function(){d().then(function(e){u(e)})},[]),r.a.createElement("div",null,r.a.createElement("h2",null,"Phonebook"),r.a.createElement(g,{message:I,type:A}),r.a.createElement(v,{value:P,onChange:function(e){S(e.target.value)}}),r.a.createElement("h3",null,"add a new"),r.a.createElement(E,{actions:{addPerson:function(e){e.preventDefault();var n=t.filter(function(e){return e.name===m});if(n.length)return window.confirm("".concat(m," is already added to phonebook, replace the old number with a new one?"))?function(e){var n=Object(o.a)({},e,{number:O});h(n.id,n).then(function(e){T("Number changed for '".concat(e.name,"'"),"success"),u(t.map(function(n){return n.id!==e.id?n:e})),f(""),N("")}).catch(function(){T("Information of '".concat(n.name,"' has already been removed from server"),"error"),u(t.filter(function(e){return e.id!==n.id}))})}(n[0]):void 0;s({name:m,number:O}).then(function(e){T("Added '".concat(e.name,"'"),"success"),u(t.concat(e)),f(""),N("")})},newName:m,newNumber:O,handleNameChange:function(e){f(e.target.value)},handleNumberChange:function(e){N(e.target.value)}}}),r.a.createElement("h3",null,"Numbers"),r.a.createElement(w,{persons:t,filterName:P,removePerson:function(e){b(e).then(function(){u(t.filter(function(n){return n.id!==e}))})}}))});c.a.render(r.a.createElement(j,null),document.getElementById("root"))}},[[15,1,2]]]);
  //# sourceMappingURL=main.bbaccef6.chunk.js.map