text: (window.webpackJsonpphonebook=window.webpackJsonpphonebook||[]).push([[0],{15:function(e,t,n){e.exports=n(38)},20:function(e,t,n){},38:function(e,t,n){"use strict";n.r(t);var a=n(0),r=n.n(a),o=n(13),c=n.n(o),u=(n(20),n(2)),l=n(3),i=n.n(l),s="".concat("/","api/persons"),f=function(){return i.a.get(s).then(function(e){return e.data})},m=function(e){return i.a.post(s,e).then(function(e){return e.data})},d=function(e){return i.a.delete("".concat(s,"/").concat(e)).then(function(e){return e.status})},p=function(e){return console.log("/"),i.a.put("".concat(s,"/").concat(e.id),e).then(function(e){return e})},b=n(14);function h(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,a)}return n}var w=function(e){var t=e.newName,n=e.setNewName,a=e.newNumber,o=e.setNewNumber,c=e.persons,u=e.setPersons,l=e.updateRecord,i=e.setNotification;return r.a.createElement("div",null,r.a.createElement("h2",null,"Add a new"),r.a.createElement("form",{onSubmit:function(e){e.preventDefault();var r={name:t,number:a};if(c.every(function(e){return t!==e.name}))m(r).then(function(e){u(c.concat(e)),i({content:"Record added successfully!",type:"success"})}).catch(function(e){400===e.response.status&&i({content:e.response.data.message,type:"danger"})});else if(window.confirm("".concat(t," is already in the phonebook, replace the old one with a new one?"))){var s=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?h(n,!0).forEach(function(t){Object(b.a)(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):h(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}({},c.find(function(e){return e.name===t}),{number:a});l(s)}e.target.name.value="",e.target.number.value="",n(""),o("")}},r.a.createElement("div",null,r.a.createElement("label",null,"Name: "),r.a.createElement("input",{name:"name",onChange:function(e){n(e.target.value)},placeholder:"Enter a new name"})),r.a.createElement("div",null,r.a.createElement("label",null,"Number: "),r.a.createElement("input",{name:"number",onChange:function(e){o(e.target.value)},placeholder:"Enter a new number"})),r.a.createElement("div",null,r.a.createElement("button",{type:"submit"},"add"))))},E=function(e){var t=e.person,n=e.deleteRecord;return r.a.createElement("p",null,t.name," ",t.number," \xa0",r.a.createElement("button",{onClick:function(){window.confirm("Delete ".concat(t.name,"?"))&&n(t.id)}},"delete"))},v=function(e){var t=e.persons,n=e.deleteRecord;return r.a.createElement("div",null,r.a.createElement("h2",null,"Numbers"),t.map(function(e){return r.a.createElement(E,{key:e.name,person:e,deleteRecord:n})}))},y=function(e){var t=e.setFilterTerm;return r.a.createElement("div",null,r.a.createElement("label",null,"Filter shown with: "),r.a.createElement("input",{onChange:function(e){t(e.target.value)}}))},g=function(e){var t=e.notification,n=e.setNotification;if(null===t.content||""===t.content)return null;var a="";switch(t.type.toLocaleLowerCase()){case"success":a="Success: ";break;case"info":a="Info: ";break;case"warning":a="Warning: ";break;case"danger":a="Danger: ";break;default:n({content:null,type:"info"})}return r.a.createElement(r.a.Fragment,null,r.a.createElement("div",{className:"alert "+t.type},r.a.createElement("span",null,a),t.content),void setTimeout(function(){n({content:null,type:"info"})},1e3*5))},O=function(){var e=Object(a.useState)([]),t=Object(u.a)(e,2),n=t[0],o=t[1],c=Object(a.useState)(""),l=Object(u.a)(c,2),i=l[0],s=l[1],m=Object(a.useState)(""),b=Object(u.a)(m,2),h=b[0],E=b[1],O=Object(a.useState)(""),j=Object(u.a)(O,2),N=j[0],k=j[1],P=Object(a.useState)({content:null,type:"info"}),S=Object(u.a)(P,2),R=S[0],C=S[1];Object(a.useEffect)(function(){f().then(function(e){o(e)})},[]);var D=n.filter(function(e){return""===N?e:e.name.toLocaleLowerCase().includes(N.toLocaleLowerCase())});return r.a.createElement("div",null,r.a.createElement("h1",null,"Phonebook"),r.a.createElement(g,{notification:R,setNotification:C}),r.a.createElement(y,{setFilterTerm:k}),r.a.createElement(w,{newName:i,setNewName:s,newNumber:h,setNewNumber:E,persons:n,setPersons:o,updateRecord:function(e){p(e).then(function(e){200===e.status&&C({content:"Record has been updated successfully!",type:"success"})}).catch(function(e){404===e.response.status&&C({content:"This record is not in phonebook or has already been delted",type:"danger"})}),o(n.map(function(t){return t.id!==e.id?t:e}))},setNotification:C}),r.a.createElement(v,{persons:D,deleteRecord:function(e){d(e).then(function(e){204===e&&C({content:"The entry has been deleted!",type:"info"})}).catch(function(e){404===e.response.status&&C({content:"This record is not in phonebook or has already been deleted",type:"danger"})}),o(n.filter(function(t){return t.id!==e}))}}))};c.a.render(r.a.createElement(O,null),document.getElementById("root"))}},[[15,1,2]]]);
  //# sourceMappingURL=main.95de6928.chunk.js.map