text: import{S as t,i as e,s as a,e as o,k as s,c as l,a as n,n as d,d as r,b as c,F as i,f as u,G as h,a7 as m,a8 as f,Y as p,Z as v,_ as g,a0 as x,a1 as b,R as E,t as j,L as w,g as y,Q as T,u as q,v as k,r as M,$ as O,a9 as _,B as F,a3 as N,H as R}from"../../chunks/vendor-dc4ce95f.js";function U(t,{pending:e,error:a,result:o}){let s;async function l(l){const n=s={};l.preventDefault();const d=new FormData(t);e&&e(d,t);try{const e=await fetch(t.action,{method:t.method,headers:{accept:"application/json"},body:d});if(n!==s)return;e.ok?o(e,t):a?a(e,null,t):console.error(await e.text())}catch(r){if(!a)throw r;a(null,r,t)}}return t.addEventListener("submit",l),{destroy(){t.removeEventListener("submit",l)}}}function B(t,e,a){const o=t.slice();return o[5]=e[a],o[6]=e,o[7]=a,o}function D(t,e){let a,j,w,y,T,q,k,M,F,N,B,D,I,L,P,$,H,S,V,A,C,G,Q,Y,Z,z,J,K=R;function W(...t){return e[3](e[5],e[6],e[7],...t)}function X(){return e[4](e[5])}return{key:t,first:null,c(){a=o("div"),j=o("form"),w=o("input"),T=s(),q=o("button"),N=s(),B=o("form"),D=o("input"),L=s(),P=o("button"),H=s(),S=o("form"),V=o("button"),G=s(),this.h()},l(t){a=l(t,"DIV",{class:!0});var e=n(a);j=l(e,"FORM",{action:!0,method:!0});var o=n(j);w=l(o,"INPUT",{type:!0,name:!0,value:!0,class:!0}),T=d(o),q=l(o,"BUTTON",{class:!0,"aria-label":!0}),n(q).forEach(r),o.forEach(r),N=d(e),B=l(e,"FORM",{class:!0,action:!0,method:!0});var s=n(B);D=l(s,"INPUT",{"aria-label":!0,type:!0,name:!0,value:!0,class:!0}),L=d(s),P=l(s,"BUTTON",{class:!0,"aria-label":!0}),n(P).forEach(r),s.forEach(r),H=d(e),S=l(e,"FORM",{action:!0,method:!0});var c=n(S);V=l(c,"BUTTON",{class:!0,"aria-label":!0}),n(V).forEach(r),c.forEach(r),G=d(e),e.forEach(r),this.h()},h(){c(w,"type","hidden"),c(w,"name","done"),w.value=y=e[5].done?"":"true",c(w,"class","svelte-dmxqmd"),c(q,"class","toggle svelte-dmxqmd"),c(q,"aria-label",k="Mark todo as "+(e[5].done?"not done":"done")),c(j,"action",M="/todos/"+e[5].uid+".json?_method=patch"),c(j,"method","post"),c(D,"aria-label","Edit todo"),c(D,"type","text"),c(D,"name","text"),D.value=I=e[5].text,c(D,"class","svelte-dmxqmd"),c(P,"class","save svelte-dmxqmd"),c(P,"aria-label","Save todo"),c(B,"class","text svelte-dmxqmd"),c(B,"action",$="/todos/"+e[5].uid+".json?_method=patch"),c(B,"method","post"),c(V,"class","delete svelte-dmxqmd"),c(V,"aria-label","Delete todo"),c(S,"action",A="/todos/"+e[5].uid+".json?_method=delete"),c(S,"method","post"),c(a,"class","todo svelte-dmxqmd"),i(a,"done",e[5].done),this.first=a},m(t,o){u(t,a,o),h(a,j),h(j,w),h(j,T),h(j,q),h(a,N),h(a,B),h(B,D),h(B,L),h(B,P),h(a,H),h(a,S),h(S,V),h(a,G),Z=!0,z||(J=[m(F=U.call(null,j,{pending:W,result:e[1]})),m(U.call(null,B,{result:e[1]})),m(C=U.call(null,S,{result:X}))],z=!0)},p(t,o){e=t,(!Z||1&o&&y!==(y=e[5].done?"":"true"))&&(w.value=y),(!Z||1&o&&k!==(k="Mark todo as "+(e[5].done?"not done":"done")))&&c(q,"aria-label",k),(!Z||1&o&&M!==(M="/todos/"+e[5].uid+".json?_method=patch"))&&c(j,"action",M),F&&f(F.update)&&1&o&&F.update.call(null,{pending:W,result:e[1]}),(!Z||1&o&&I!==(I=e[5].text)&&D.value!==I)&&(D.value=I),(!Z||1&o&&$!==($="/todos/"+e[5].uid+".json?_method=patch"))&&c(B,"action",$),(!Z||1&o&&A!==(A="/todos/"+e[5].uid+".json?_method=delete"))&&c(S,"action",A),C&&f(C.update)&&1&o&&C.update.call(null,{result:X}),1&o&&i(a,"done",e[5].done)},r(){Y=a.getBoundingClientRect()},f(){p(a),K(),v(a,Y)},a(){K(),K=g(a,Y,O,{duration:200})},i(t){Z||(t&&x((()=>{Q||(Q=b(a,_,{start:.7},!0)),Q.run(1)})),Z=!0)},o(t){t&&(Q||(Q=b(a,_,{start:.7},!1)),Q.run(0)),Z=!1},d(t){t&&r(a),t&&Q&&Q.end(),z=!1,E(J)}}}function I(t){let e,a,i,p,v,g,x,b,E,O,_,R,I=[],L=new Map,P=t[0];const $=t=>t[5].uid;for(let o=0;o<P.length;o+=1){let e=B(t,P,o),a=$(e);L.set(a,I[o]=D(a,e))}return{c(){e=s(),a=o("div"),i=o("h1"),p=j("Todos"),v=s(),g=o("form"),x=o("input"),E=s();for(let t=0;t<I.length;t+=1)I[t].c();this.h()},l(t){w('[data-svelte="svelte-181o7gf"]',document.head).forEach(r),e=d(t),a=l(t,"DIV",{class:!0});var o=n(a);i=l(o,"H1",{});var s=n(i);p=y(s,"Todos"),s.forEach(r),v=d(o),g=l(o,"FORM",{class:!0,action:!0,method:!0});var c=n(g);x=l(c,"INPUT",{name:!0,"aria-label":!0,placeholder:!0,class:!0}),c.forEach(r),E=d(o);for(let e=0;e<I.length;e+=1)I[e].l(o);o.forEach(r),this.h()},h(){document.title="Todos",c(x,"name","text"),c(x,"aria-label","Add todo"),c(x,"placeholder","+ tap to add a todo"),c(x,"class","svelte-dmxqmd"),c(g,"class","new svelte-dmxqmd"),c(g,"action","/todos.json"),c(g,"method","post"),c(a,"class","todos svelte-dmxqmd")},m(o,s){u(o,e,s),u(o,a,s),h(a,i),h(i,p),h(a,v),h(a,g),h(g,x),h(a,E);for(let t=0;t<I.length;t+=1)I[t].m(a,null);O=!0,_||(R=m(b=U.call(null,g,{result:t[2]})),_=!0)},p(t,[e]){if(b&&f(b.update)&&1&e&&b.update.call(null,{result:t[2]}),3&e){P=t[0],F();for(let t=0;t<I.length;t+=1)I[t].r();I=T(I,e,$,1,t,P,L,a,N,D,null,B);for(let t=0;t<I.length;t+=1)I[t].a();q()}},i(t){if(!O){for(let t=0;t<P.length;t+=1)k(I[t]);O=!0}},o(t){for(let e=0;e<I.length;e+=1)M(I[e]);O=!1},d(t){t&&r(e),t&&r(a);for(let e=0;e<I.length;e+=1)I[e].d();_=!1,R()}}}const L=async({fetch:t})=>{const e=await t("/todos.json");if(e.ok){return{props:{todos:await e.json()}}}const{message:a}=await e.json();return{error:new Error(a)}};function P(t,e,a){let{todos:o}=e;return t.$$set=t=>{"todos"in t&&a(0,o=t.todos)},[o,async function(t){const e=await t.json();a(0,o=o.map((t=>t.uid===e.uid?e:t)))},async(t,e)=>{const s=await t.json();a(0,o=[...o,s]),e.reset()},(t,e,s,l)=>{a(0,e[s].done=!!l.get("done"),o)},t=>{a(0,o=o.filter((e=>e.uid!==t.uid)))}]}export default class extends t{constructor(t){super(),e(this,t,P,I,a,{todos:0})}}export{L as load};
  