text: (this["webpackJsonpmy-todo-mvc"]=this["webpackJsonpmy-todo-mvc"]||[]).push([[0],{26:function(t,e,n){},47:function(t,e,n){"use strict";n.r(e);var c,a=n(0),r=n.n(a),o=n(9),i=n.n(o),s=(n(25),n(26),n(5)),u=n(2),l=n.n(u),d=n(4),p=n(12),b=n.n(p);function j(t){return f.apply(this,arguments)}function f(){return(f=Object(d.a)(l.a.mark((function t(e){var n,c;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,b()(e);case 3:return n=t.sent,0!==(c=n.data).c&&s.b.warning("Something wrong with the BUSINESS"),t.abrupt("return",c);case 9:throw t.prev=9,t.t0=t.catch(0),s.b.error("Something wrong with the NETWORK"),t.t0;case 13:case"end":return t.stop()}}),t,null,[[0,9]])})))).apply(this,arguments)}function h(t){return v.apply(this,arguments)}function v(){return(v=Object(d.a)(l.a.mark((function t(e){var n,c;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j({url:"/api/todos",method:"GET",params:e});case 2:return n=t.sent,c=n.d,t.abrupt("return",c);case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function O(t){return m.apply(this,arguments)}function m(){return(m=Object(d.a)(l.a.mark((function t(e){var n,c,a;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j({url:"/api/todo",method:"POST",data:e});case 2:return n=t.sent,c=n.c,a=n.d,0===c&&s.b.success("\ud83c\udf1f Created!"),t.abrupt("return",a);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function x(){return(x=Object(d.a)(l.a.mark((function t(e){var n;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j({url:"/api/todo",method:"DELETE",data:e});case 2:n=t.sent,0===n.c&&s.b.success("\ud83c\udf1f Deleted!");case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function C(t){return g.apply(this,arguments)}function g(){return(g=Object(d.a)(l.a.mark((function t(e){var n,c,a;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,j({url:"/api/todo",method:"PATCH",data:e});case 2:return n=t.sent,c=n.c,a=n.d,0===c&&s.b.success("\ud83c\udf1f Updated!"),t.abrupt("return",a);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}b.a.defaults.headers.post["Content-Type"]="application/json",function(t){t[t.All=1]="All",t[t.UNCOMPLETED=2]="UNCOMPLETED",t[t.COMPLETED=3]="COMPLETED"}(c||(c={}));var k=n(1),D=function(t){var e=t.onCreate,n=Object(a.useRef)(null),c=Object(a.useCallback)((function(t){if("Enter"===t.key){t.preventDefault();var c=n.current;c&&c.value.trim()&&(e(c.value.trim()),c.value="")}}),[e]);return Object(k.jsxs)("header",{className:"header",children:[Object(k.jsx)("h1",{children:"todos"}),Object(k.jsx)("input",{ref:n,className:"new-todo",placeholder:"What needs to be done?",autoFocus:!0,onKeyDown:c})]})},w=function(){return Object(k.jsxs)("footer",{className:"footer",children:[Object(k.jsx)("p",{children:"Double-click to edit a todo"}),Object(k.jsxs)("p",{children:["Refer to ",Object(k.jsx)("a",{href:"http://todomvc.com",children:"TodoMVC"})]})]})},y=n(6),E=function(t){var e=t.todo,n=t.onRemove,c=t.onUpdate,r=t.onToggle,o=Object(a.useState)(!1),i=Object(y.a)(o,2),s=i[0],u=i[1],l=Object(a.useState)(e.title),d=Object(y.a)(l,2),p=d[0],b=d[1],j=Object(a.useCallback)((function(){n({id:e.id,clientID:e.clientID||0})}),[e,n]),f=Object(a.useCallback)((function(){u(!0),b(e.title)}),[e]),h=Object(a.useCallback)((function(){var t=p.trim();t?(c({id:e.id,clientID:e.clientID||0,title:t}),u(!1)):n({id:e.id,clientID:e.clientID||0})}),[p,c,e,n]),v=Object(a.useCallback)((function(t){t.target&&b(t.target.value||"")}),[]),O=Object(a.useCallback)((function(t){"Escape"===t.key?(b(e.title),u(!1)):"Enter"===t.key&&h()}),[e,h]),m=Object(a.useCallback)((function(){r({id:e.id,clientID:e.clientID||0})}),[e,r]);return Object(k.jsxs)("div",{className:"todo-item ".concat(e.completed?"todo-item__completed":""),children:[Object(k.jsx)("div",{className:"todo-item--toggle",children:Object(k.jsx)("input",{className:"todo-item--toggle-input",type:"checkbox",checked:e.completed,onChange:m,disabled:s})}),s?Object(k.jsx)("input",{type:"text",className:"todo-item--editing-input",value:p,onBlur:h,onChange:v,onKeyDown:O,autoFocus:!0}):Object(k.jsx)("div",{className:"todo-item--content",onDoubleClick:f,children:e.title}),Object(k.jsx)("button",{className:"todo-item--remove",title:"Click to remove",onClick:j,disabled:s})]})},N=n(7),I=1;function T(t,e){var n=-1;return t.id?n=e.findIndex((function(e){return e.id===t.id})):t.clientID&&(n=e.findIndex((function(e){return e.clientID===t.clientID}))),n}var S=function(){var t=Object(a.useState)([]),e=Object(y.a)(t,2),n=e[0],r=e[1],o=Object(a.useState)(c.All),i=Object(y.a)(o,2),s=i[0],u=i[1],p=Object(a.useState)(!0),b=Object(y.a)(p,2),j=b[0],f=b[1],v=Object(a.useCallback)(Object(d.a)(l.a.mark((function t(){var e,n,a,o=arguments;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.length>0&&void 0!==o[0]?o[0]:c.All,n=o.length>1&&void 0!==o[1]?o[1]:100,f(!0),t.prev=3,t.next=6,h({limit:n,statusFilter:e});case 6:a=t.sent,r(a||[]);case 8:return t.prev=8,f(!1),t.finish(8);case 11:case"end":return t.stop()}}),t,null,[[3,,8,11]])}))),[]);Object(a.useEffect)((function(){v(s)}),[]);var m=Object(a.useCallback)((function(t){s!==t&&(u(t),v(t))}),[s,v]),g=Object(a.useCallback)(function(){var t=Object(d.a)(l.a.mark((function t(e){var c,a,o,i,s;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return c=++I,r([{id:"",title:e,completed:!1,clientID:c}].concat(Object(N.a)(n))),t.next=4,O({title:e});case 4:(a=t.sent)&&(o=a.id,(i=n.findIndex((function(t){return t.clientID===c})))>=0&&((s=Object(N.a)(n))[i].id=o,r(s)));case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[n]),k=Object(a.useCallback)((function(t){var e=T(t,n);if(e>=0){var c=Object(N.a)(n),a=c.splice(e,1);r(c),a[0]&&a[0].id&&function(t){x.apply(this,arguments)}({id:a[0].id})}}),[n]),D=Object(a.useCallback)(function(){var t=Object(d.a)(l.a.mark((function t(e){var c,a;return l.a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:(c=T(e,n))>=0&&((a=Object(N.a)(n))[c].title=e.title,r(a),a[c].id&&C({id:a[c].id,title:e.title}));case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[n]),w=Object(a.useCallback)((function(t){var e=T(t,n);if(e>=0){var c=Object(N.a)(n),a=!c[e].completed;c[e].completed=a,r(c),c[e].id&&C({id:c[e].id,completed:a})}}),[n]);return{todos:n,onCreate:g,onRemove:k,onUpdate:D,onToggle:w,onStatusFilterChange:m,isLoadingData:j,statusFilter:s}};var F=function(){var t=S(),e=t.todos,n=t.onCreate,a=t.onRemove,r=t.onUpdate,o=t.onToggle,i=t.statusFilter,u=t.onStatusFilterChange,l=t.isLoadingData,d=[{value:c.All,text:"All"},{value:c.UNCOMPLETED,text:"Uncompleted"},{value:c.COMPLETED,text:"Completed"}];return Object(k.jsxs)("div",{className:"todo-app ".concat(l?"todo-app-loading":""),children:[Object(k.jsx)(D,{onCreate:n}),Object(k.jsxs)("div",{className:"todo-count-filter",children:[Object(k.jsx)("div",{className:"todo-count",children:0===e.length?"None":"".concat(e.length," items left")}),Object(k.jsx)("div",{className:"todo-filter",children:d.map((function(t){return Object(k.jsx)("div",{className:"todo-filter-item ".concat(t.value===i?"todo-filter-item__actived":""),onClick:function(){return u(t.value)},children:t.text},t.value)}))})]}),Object(k.jsx)("div",{className:"todo-main",children:Object(k.jsx)("div",{className:"todo-list",children:e.map((function(t){return Object(k.jsx)(E,{todo:t,onRemove:a,onUpdate:r,onToggle:o},t.id||t.clientID)}))})}),Object(k.jsx)(w,{}),Object(k.jsx)(s.a,{})]})},L=function(t){t&&t instanceof Function&&n.e(3).then(n.bind(null,48)).then((function(e){var n=e.getCLS,c=e.getFID,a=e.getFCP,r=e.getLCP,o=e.getTTFB;n(t),c(t),a(t),r(t),o(t)}))};i.a.render(Object(k.jsx)(r.a.StrictMode,{children:Object(k.jsx)(F,{})}),document.getElementById("root")),L()}},[[47,1,2]]]);
  //# sourceMappingURL=main.8a3b9ab0.chunk.js.map