1import{c as g,j as n,dd as Ae,de as Be,df as Nt,bb as zt,dg as Vt,dh as Yt,bV as ct,di as Gt,b9 as Qt,ay as Mt,K as Wt,bl as Ht,aj as Xt,aH as Jt,dj as Zt,bO as es,aA as ts,R as ss}from"./vendor-1kUQ7zn2.js";import{a0 as ns,bS as St,ag as as,ah as os,bT as vt,c as A,B as rs,ai as is,bU as Ct,ae as Ie,aK as cs,s as lt,bV as ls,bW as us,bX as ds,bY as hs,bZ as fs,b_ as Rt,b$ as ps,c0 as ut,c1 as ms,c2 as xs,c3 as bs,c4 as gs,c5 as ks,ac as ws}from"./index--kdl1ae9.js";import{S as js}from"./slider-D6mh3qnw.js";import{b as ys}from"./focusStats-sBxcroA-.js";import{u as Ns,p as Ms,P as dt,f as Ss,Q as re,s as we,a as vs,r as ht,n as ft,b as Cs,c as Rs,i as Es,d as Ts,K as oe,C as pt,U as mt,w as Ps,e as As,g as Bs,F as Is,h as Ds}from"./focus-adIRnHuT.js";import{D as Fs}from"./vendor-date-en1IyhsK.js";import{P as Ls}from"./ParentHint-C6NcJBXf.js";import"./vendor-supabase-Dh2gyaRa.js";import"./vendor-motion-BX-jsy7E.js";const Os=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;function $s(e){const[t,s]=ns("focus-notes",[]),[o,a]=g.useState(null);return g.useEffect(()=>{if(!e){a(null);return}const l=t.find(p=>p.taskId===e);a(p=>{if(l)return l;if(p&&p.taskId===e)return p;const h=new Date().toISOString();return{id:Os(),taskId:e,content:"",createdAt:h,updatedAt:h}})},[e,t]),{notes:t,activeNote:o,updateNoteContent:l=>{if(!o)return;const p={...o,content:l,updatedAt:new Date().toISOString()},h=t.filter(u=>u.id===o.id||u.content.trim()),r=h.some(u=>u.id===o.id);s(r?h.map(u=>u.id===o.id?p:u):[...h,p]),a(p)},deleteNote:l=>{const p=t.filter(h=>h.id!==l);s(p),o?.id===l&&a(null)},clearAllNotes:()=>{s([]),a(null)}}}const L=2*Math.PI;function ge(e=Math.random()*4294967296>>>0){let t=e>>>0;return()=>{t=t+1831565813>>>0;let s=t;return s=Math.imul(s^s>>>15,s|1),s^=s+Math.imul(s^s>>>7,s|61),((s^s>>>14)>>>0)/4294967296}}const b=(e,t,s)=>t+(s-t)*e(),V=(e,t,s)=>t*Math.pow(s/t,e()),De=()=>typeof performance<"u"?performance.now():Date.now();let be=null;const xt=[];function qs(){return new Promise(e=>{if(typeof MessageChannel>"u"){setTimeout(e,0);return}be||(be=new MessageChannel,be.port1.onmessage=()=>xt.shift()?.()),xt.push(e),be.port2.postMessage(0)})}class Fe{constructor(t=10){this.budgetMs=t}budgetMs;last=De();due(){return De()-this.last>this.budgetMs}async pause(){await qs(),this.last=De()}}class T{b0=1;b1=0;b2=0;a1=0;a2=0;z1=0;z2=0;constructor(t,s,o,a=Math.SQRT1_2,i=0){t&&s&&o&&this.set(t,s,o,a,i)}set(t,s,o,a=Math.SQRT1_2,i=0){const d=Math.min(Math.max(s,5),o*.49),c=L*d/o,l=Math.cos(c),h=Math.sin(c)/(2*a),r=Math.pow(10,i/40);let u,f,x,k,y,w;switch(t){case"lowpass":u=(1-l)/2,f=1-l,x=u,k=1+h,y=-2*l,w=1-h;break;case"highpass":u=(1+l)/2,f=-(1+l),x=u,k=1+h,y=-2*l,w=1-h;break;case"bandpass":u=h,f=0,x=-h,k=1+h,y=-2*l,w=1-h;break;case"peaking":u=1+h*r,f=-2*l,x=1-h*r,k=1+h/r,y=-2*l,w=1-h/r;break;case"lowshelf":{const S=2*Math.sqrt(r)*h;u=r*(r+1-(r-1)*l+S),f=2*r*(r-1-(r+1)*l),x=r*(r+1-(r-1)*l-S),k=r+1+(r-1)*l+S,y=-2*(r-1+(r+1)*l),w=r+1+(r-1)*l-S;break}case"highshelf":{const S=2*Math.sqrt(r)*h;u=r*(r+1+(r-1)*l+S),f=-2*r*(r-1+(r+1)*l),x=r*(r+1+(r-1)*l-S),k=r+1-(r-1)*l+S,y=2*(r-1-(r+1)*l),w=r+1-(r-1)*l-S;break}}return this.b0=u/k,this.b1=f/k,this.b2=x/k,this.a1=y/k,this.a2=w/k,this}process(t){const s=this.b0*t+this.z1;return this.z1=this.b1*t-this.a1*s+this.z2,this.z2=this.b2*t-this.a2*s,s}}class Et{b0=0;b1=0;b2=0;b3=0;b4=0;b5=0;b6=0;process(t){this.b0=.99886*this.b0+t*.0555179,this.b1=.99332*this.b1+t*.0750759,this.b2=.969*this.b2+t*.153852,this.b3=.8665*this.b3+t*.3104856,this.b4=.55*this.b4+t*.5329522,this.b5=-.7616*this.b5-t*.016898;const s=this.b0+this.b1+this.b2+this.b3+this.b4+this.b5+this.b6+t*.5362;return this.b6=t*.115926,s*.11}}class _s{y=0;dcX=0;dcY=0;leak;gain;dcR;constructor(t,s=12,o=8){this.leak=Math.exp(-L*s/t),this.gain=(1-this.leak)*18,this.dcR=Math.exp(-L*o/t)}process(t){this.y=this.leak*this.y+this.gain*t;const s=this.y-this.dcX+this.dcR*this.dcY;return this.dcX=this.y,this.dcY=s,s}}const ze=(e,t)=>Math.exp(-L*e/t);class W{points;seg;constructor(t,s,o,a=0,i=1){const d=Math.max(2,Math.round(s/o));this.seg=s/d,this.points=new Float32Array(d);for(let c=0;c<d;c++)this.points[c]=a+(i-a)*t()}at(t){const s=t/this.seg,o=Math.floor(s),a=s-o,i=this.points.length,d=this.points[(o%i+i)%i],c=this.points[((o+1)%i+i)%i],l=a*a*(3-2*a);return d+(c-d)*l}}
1async function de(e,t,s){const o=2*Math.sqrt(3);for(let a=0;a<e.length;a++)(a&16383)===0&&s.due()&&await s.pause(),e[a]=(t()-.5)*o}async function H(e,t,s,o){const a=e.length,i=Math.min(a,o);for(let d=a-i;d<a;d++)(d&16383)===0&&s.due()&&await s.pause(),t(e[d],d);for(let d=0;d<a;d++)(d&16383)===0&&s.due()&&await s.pause(),e[d]=t(e[d],d)}function Us(e){let t=0;for(let s=0;s<e.length;s++)t+=e[s]*e[s];return Math.sqrt(t/Math.max(1,e.length))}function _(e,t){const s=Us(e);if(s>0){const o=t/s;for(let a=0;a<e.length;a++)e[a]*=o}return e}function Ks(e,t=1){let s=0;for(let o=0;o<e.length;o++)s=Math.max(s,Math.abs(e[o]));if(s>0){const o=t/s;for(let a=0;a<e.length;a++)e[a]*=o}return e}function Ve(e,t,s){const o=s-t;for(let a=0;a<e.length;a++){const i=e[a],d=Math.abs(i);if(d>t){const c=(d-t)/o;e[a]=Math.sign(i)*(t+o*(c/(1+c)))}}}function Ye(e,t=.7){return e<=0||e>=1?0:Math.pow(Math.sin(Math.PI*Math.pow(e,t)),1.3)}function je(e,t,s,o=0,a){const i=t.reduce((c,l)=>Math.max(c,l.start+l.dur),0)+.02,d=new Float32Array(Math.ceil(i*e));for(const c of t){const l=Math.floor(c.start*e),p=Math.floor(c.dur*e);let h=0;for(let r=0;r<p;r++){const u=r/p;let f=c.freq(u);a&&(f*=1+a.depth*Math.sin(L*a.rate*r/e)),h+=L*f/e;const x=Ye(u,c.skew??.7)*c.amp;d[l+r]+=x*(Math.sin(h)+s*Math.sin(2*h)+o*Math.sin(3*h))}}return d}function X(e,t,s){const o=ze(s,t);let a=0;for(let i=0;i<e.length;i++)a=o*a+(1-o)*e[i],e[i]=a;return Ks(e,1)}function zs(e,t){const s=2+Math.floor(t()*4),o=b(t,2300,3300),a=b(t,.15,.38),i=b(t,-.05,.04),d=[];let c=0;for(let l=0;l<s;l++){const p=o*(1+i*l)*b(t,.97,1.03),h=b(t,.05,.1);d.push({start:c,dur:h,freq:r=>p*(1+a*(1-r)*(1-r)),amp:b(t,.7,1),skew:.55}),c+=h+b(t,.06,.15)}return X(je(e,d,.06),e,5500)}function Vs(e,t){const s=b(t,.5,1),o=b(t,2e3,2800),a=b(t,-.1,.12),i=b(t,-.1,.1),d=b(t,18,34),c=b(t,.035,.08),l=b(t,7,12),p=Math.floor(s*e),h=new Float32Array(p+Math.floor(e*.02));let r=0;const u=t()*L;for(let f=0;f<p;f++){const x=f/p,k=1+a*Math.sin(Math.PI*x)+i*x,y=o*k*(1+c*Math.sin(L*d*f/e));r+=L*y/e;const w=.35+.65*Math.pow(.5+.5*Math.sin(L*l*f/e+u),1.5);h[f]=Ye(x,.8)*w*(Math.sin(r)+.05*Math.sin(2*r))}return X(h,e,5e3)}function Ys(e,t){const s=b(t,2400,3100),o=b(t,.8,.9),a=t()<.6?2:3,i=[];let d=0;for(let c=0;c<a;c++){const l=c===0||a===3&&c===1&&t()<.5,p=l?s:s*o,h=b(t,-.03,.02),r=b(t,.2,.36);i.push({start:d,dur:r,freq:u=>p*(1+h*u),amp:l?1:.85,skew:.8}),d+=r+b(t,.04,.12)}return X(je(e,i,.03,0,{rate:b(t,5,7),depth:.008}),e,5e3)}function Gs(e,t){const s=b(t,420,560),o=3+Math.floor(t()*3),a=[];let i=0;for(let d=0;d<o;d++){const c=d===1,l=c?b(t,.45,.65):b(t,.25,.4),p=c?b(t,.04,.08):b(t,-.02,.03);a.push({start:i,dur:l,freq:h=>s*(1+p*Math.sin(Math.PI*h)),amp:c?1:.75,skew:.9}),i+=l+b(t,.12,.3)}return X(je(e,a,.25,.07),e,2500)}function Qs(e,t){const s=b(t,.5,1),o=b(t,13,19),a=b(t,2800,3500),i=b(t,.05,.15),d=[];for(let c=0;c<s;c+=1/o){const l=c/s,p=a*(1-i*l);d.push({start:c,dur:.6/o,freq:h=>p*(1+.08*(1-h)),amp:Ye(Math.min(.999,l*.9+.05),.5),skew:.5})}return X(je(e,d,.04),e,5e3)}const Ws=[["chirp",zs,7],["warble",Vs,5],["whistle",Ys,5],["dove",Gs,4],["trill",Qs,4]];function Hs(e,t){const s=V(t,900,2e3),o=b(t,.25,.7),a=e*b(t,.012,.03),i=Math.floor(a*5),d=new Float32Array(i);let c=0;const l=e*.001;for(let p=0;p<i;p++)c+=L*s*(1+o*(1-Math.exp(-p/(a*.8))))/e,d[p]=Math.sin(c)*(1-Math.exp(-p/l))*Math.exp(-p/a);return X(d,e,6e3)}function Xs(e,t){const s=Math.floor(e*b(t,.25,.45)),o=new Float32Array(s),a=new T("bandpass",V(t,220,520),e,b(t,3,6)),i=new T("bandpass",V(t,700,1500),e,b(t,2,4)),d=Math.floor(e*b(t,6e-4,.0018));for(let p=0;p<s;p++){const h=p<d?(t()*2-1)*(1-p/d):0;o[p]=a.process(h)*5+i.process(h)*2.5}const c=2+Math.floor(t()*7),l=new T;for(let p=0;p<c;p++){l.set("bandpass",V(t,1500,4500),e,b(t,1.5,3.5)),l.z1=0,l.z2=0;const h=Math.floor(e*b(t,.01,.22)),r=Math.floor(e*b(t,.003,.008)),u=Math.max(2,Math.floor(e*2e-4)),f=b(t,.15,.6);for(let x=0;x<r&&h+x<s;x++)o[h+x]+=l.process(x<u?t()*2-1:0)*f*3}return X(o,e,7e3)}function Js(e,t){const s=3+Math.floor(t()*5),o=b(t,.12,.4),a=new Float32Array(Math.floor(e*(o+.15)));for(let i=0;i<s;i++){const d=Math.floor(e*o*t()),c=V(t,220,650),l=e/(.043*c+.0014*Math.pow(c,1.5)),p=Math.min(a.length-d,Math.floor(l*5)),h=b(t,.2,.5),r=b(t,.4,1);let u=0;for(let f=0;f<p;
1f++)u+=L*c*(1+h*f/p)/e,a[d+f]+=Math.sin(u)*r*(1-Math.exp(-f/(e*.001)))*Math.exp(-f/l)}return X(a,e,3e3)}async function Zs(e,t,s,o){const a=[],i=async(d,c,l)=>{for(let p=0;p<l;p++)o.due()&&await o.pause(),a.push({kind:d,data:c(t,s)})};switch(e){case"birds":for(const[d,c,l]of Ws)await i(d,c,l);break;case"drips":await i("drip",Hs,14);break;case"pops":await i("pop",Xs,14);break;case"gurgles":await i("gurgle",Js,12);break}return a}function en(e,t,s=1.6){const o=Math.floor(e*s),a=Math.floor(e*.012),i=[];for(let d=0;d<2;d++){const c=new Float32Array(o);let l=0,p=0;for(let r=a;r<o;r++){const u=(r-a)/e,f=ze(1500+6e3*Math.exp(-u/.25),e);l=f*l+(1-f)*(t()*2-1);const x=Math.exp(-u/.33)*Math.min(1,u/.006);c[r]=l*x,p+=c[r]*c[r]}const h=1/Math.sqrt(p||1);for(let r=0;r<o;r++)c[r]*=h;i.push(c)}return[i[0],i[1]]}const Tt=24,F=.25,he=2,tn=async(e,t,s,o)=>{const a=new Float32Array(t);await de(a,s,o);const i=new T("highpass",30,e,.6),d=new T("highshelf",4e3,e,.7,-5),c=new T("lowpass",8e3,e,.6);return await H(a,l=>c.process(d.process(i.process(l))),o,e*he),_(a,F)},sn=async(e,t,s,o)=>{const a=new Float32Array(t);await de(a,s,o);const i=new Et,d=new T("highpass",25,e,.6),c=new T("lowpass",11e3,e,.55);return await H(a,l=>c.process(d.process(i.process(l))),o,e*he),_(a,F)},nn=async(e,t,s,o)=>{const a=new Float32Array(t);await de(a,s,o);const i=new _s(e,12,8),d=new T("highpass",28,e,.6),c=new T("lowpass",3500,e,.5);return await H(a,l=>c.process(d.process(i.process(l))),o,e*he),_(a,F)},an=async(e,t,s,o)=>{const a=new Float32Array(t),i=t/e,d=new W(s,t,e*2.5,.65,1),c=Math.round(320*i);for(let r=0;r<c;r++){(r&255)===0&&o.due()&&await o.pause();const u=Math.floor(s()*t),f=(.04+.96*Math.pow(s(),3.2))*d.at(u),x=Math.floor(e*b(s,.002,.007)),k=x*b(s,.18,.3),y=e*3e-4,w=ze(V(s,1200,6500),e);let S=0,M=0,R=u;for(let N=0;N<x;N++){S=w*S+(1-w)*(s()*2-1),M=w*M+(1-w)*S;const B=(N<y?N/y:1)*Math.exp(-N/k);a[R]+=M*B*f*6,++R===t&&(R=0)}}const l=Math.round(7*i);for(let r=0;r<l;r++){const u=Math.floor(s()*t),f=V(s,1300,3400),x=b(s,.08,.3),k=e*b(s,.004,.011),y=Math.floor(k*5),w=e*6e-4,S=b(s,.03,.22)*Math.pow(s(),.7);let M=s()*L,R=u;for(let N=0;N<y;N++){const B=f*(1+x*N/y);M+=L*B/e;
1const C=(1-Math.exp(-N/w))*Math.exp(-N/k);a[R]+=Math.sin(M)*C*S,++R===t&&(R=0)}}const p=new T("highpass",250,e,.6),h=new T("lowpass",7e3,e,.55);return await H(a,r=>h.process(p.process(r)),o,e*.5),_(a,F),Ve(a,F*2.5,F*4.5),_(a,F)},on=async(e,t,s,o)=>{const a=t/e,i=new Float32Array(t),d=new W(s,t,e*.35,.15,1),c=new W(s,t,e*3,.6,1),l=Math.round(150*a);for(let x=0;x<l;x++){(x&127)===0&&o.due()&&await o.pause();const k=Math.floor(s()*t),y=V(s,380,2100),w=.043*y+.0014*Math.pow(y,1.5),S=e/w,M=Math.min(Math.floor(S*4),Math.floor(e*.05)),R=b(s,.1,.45),N=e*8e-4,B=d.at(k)*c.at(k),C=Math.pow(s(),1.8)*B*B*Math.min(1.6,Math.sqrt(900/y));let U=0,K=k;for(let O=0;O<M;O++){U+=L*y*(1+R*O/M)/e;const $=(1-Math.exp(-O/N))*Math.exp(-O/S);i[K]+=Math.sin(U)*$*C,++K===t&&(K=0)}}_(i,1);const p=new Float32Array(t);await de(p,s,o);const h=[{f:new W(s,t,e*1.1,350,650),q:2.2,g:1,bq:new T},{f:new W(s,t,e*.8,750,1300),q:2.8,g:.75,bq:new T},{f:new W(s,t,e*.6,1500,2600),q:3.2,g:.45,bq:new T}],r=new Et;await H(p,(x,k)=>{if((k&63)===0)for(const w of h)w.bq.set("bandpass",w.f.at(k),e,w.q);let y=r.process(x)*.35;for(const w of h)y+=w.bq.process(x)*w.g;return y*(.55+.45*c.at(k))},o,e*he),_(p,.75);for(let x=0;x<t;x++)i[x]+=p[x];const u=new T("highpass",120,e,.6),f=new T("lowpass",6e3,e,.5);return await H(i,x=>f.process(u.process(x)),o,e*.5),_(i,F),Ve(i,F*2.5,F*4.5),_(i,F)},rn=async(e,t,s,o)=>{const a=new Float32Array(t),i=t/e,d=new W(s,t,e*.9,0,1),c=new T,l=Math.round(60*i);for(let u=0;u<l;u++){(u&63)===0&&o.due()&&await o.pause();const f=Math.floor(s()*t),x=d.at(f);if(s()>.15+.85*x*x)continue;const k=1+Math.floor(s()*4),y=Math.pow(s(),3.5)*.9+.06;let w=f;for(let S=0;S<k;S++){c.set("bandpass",V(s,1400,5500),e,b(s,1.2,4)),c.z1=0,c.z2=0;const M=Math.max(2,Math.floor(e*b(s,8e-5,5e-4))),R=Math.floor(e*b(s,.003,.009)),N=y*b(s,.35,1);let B=w%t;for(let C=0;C<R;C++){const U=C<M?s()*2-1:0;a[B]+=c.process(U)*N*5,++B===t&&(B=0)}w+=Math.floor(e*b(s,.0015,.012))}}const p=Math.round(150*i);for(let u=0;u<p;u++){const f=Math.floor(s()*t),x=Math.floor(e*b(s,8e-4,.002)),k=.03*s();let y=f;for(let w=0;w<x;w++)a[y]+=(s()*2-1)*k*(1-w/x),++y===t&&(y=0)}const h=new T("highpass",350,e,.6),r=new T("lowpass",6500,e,.55);return await H(a,u=>r.process(h.process(u)),o,e*.5),_(a,F),Ve(a,F*3,F*5.5),_(a,F)},cn=async(e,t,s,o)=>{const a=new Float32Array(t);await de(a,s,o);const i=new W(s,t,e*2.2,.3,1),d=new W(s,t,e*.045,0,1),c=new T("highpass",1100,e,.6),l=new T("lowpass",5200,e,.6),p=new T("bandpass",700,e,.7);await H(a,(u,f)=>{const x=i.at(f),k=d.at(f),y=k*k*x;return l.process(c.process(u))*(.15*x+y)+p.process(u)*.25*x},o,e*he);const h=Math.round(60*(t/e)),r=new T;for(let u=0;u<h;u++){const f=Math.floor(s()*t),x=i.at(f);if(s()>x)continue;r.set("bandpass",V(s,2e3,4800),e,1.5),r.z1=0,r.z2=0;const k=Math.floor(e*b(s,.002,.006)),y=b(s,.1,.5);let w=f;for(let S=0;S<k;S++)a[w]+=r.process((s()*2-1)*(1-S/k))*y,++w===t&&(w=0)}return _(a,F)},ln={white:tn,pink:sn,brown:nn,rainDrops:an,babble:on,crackle:rn,rustle:cn};function un(e,t,s,o,a=Tt){return ln[e](t,Math.floor(t*a),s,o)}const bt=3,dn=250,hn=.13,fn=.11,Pt=.8,pn={white:.219,pink:.269,brown:.417,rain:.255,ocean:.465,stream:.285,wind:.73,fireplace:.345,forest:.338},mn=()=>
1{if(typeof navigator>"u")return!1;const e=navigator;return/iP(hone|ad|od)/.test(e.userAgent)||e.platform==="MacIntel"&&e.maxTouchPoints>1||typeof e.deviceMemory=="number"&&e.deviceMemory<=2},Ge={seconds:Tt,keepAll:!0},xn={sampleRate:24e3,seconds:12,keepAll:!1};class bn{constructor(t,s=Ge){this.ctx=t,this.profile=s,this.rate=s.sampleRate??t.sampleRate}ctx;profile;textures=new Map;banks=new Map;reverb=null;used=null;rate;toBuffer(t,s=this.rate){const o=this.ctx.createBuffer(t.length,t[0].length,s);return t.forEach((a,i)=>o.getChannelData(i).set(a)),o}track(){return this.used=new Set,this.used}retainOnly(t){this.textures.forEach((s,o)=>{t.has(`t:${o}`)||this.textures.delete(o)}),this.banks.forEach((s,o)=>{t.has(`b:${o}`)||this.banks.delete(o)}),t.has("reverb")||(this.reverb=null)}clear(){this.retainOnly(new Set)}get size(){return this.textures.size+this.banks.size+(this.reverb?1:0)}texture(t){this.used?.add(`t:${t}`);let s=this.textures.get(t);return s||(s=un(t,this.rate,ge(),new Fe,this.profile.seconds).then(o=>this.toBuffer([o])),s.catch(()=>this.textures.delete(t)),this.textures.set(t,s)),s}bank(t){this.used?.add(`b:${t}`);let s=this.banks.get(t);return s||(s=Zs(t,this.rate,ge(),new Fe).then(o=>o.map(a=>({kind:a.kind,buffer:this.toBuffer([a.data])}))),s.catch(()=>this.banks.delete(t)),this.banks.set(t,s)),s}reverbIR(){if(this.used?.add("reverb"),!this.reverb){const t=this.ctx.sampleRate;this.reverb=new Fe().pause().then(()=>this.toBuffer(en(t,ge()),t)),this.reverb.catch(()=>{this.reverb=null})}return this.reverb}}class gn{constructor(t,s){this.ctx=t,this.rng=ge(),this.trim=this.gain(s),this.output=this.gain(0),this.trim.connect(this.output)}ctx;output;trim;rng;startTime=0;loops=[];nodes=[];grains=new Set;tickers=[];started=!1;stopped=!1;track(t){return this.nodes.push(t),t}gain(t){const s=this.track(this.ctx.createGain());return s.gain.value=t,s}filter(t,s,o=Math.SQRT1_2,a=0){const i=this.track(this.ctx.createBiquadFilter());return i.type=t,i.frequency.value=s,i.Q.value=o,i.gain.value=a,i}panner(t=0){if(typeof this.ctx.createStereoPanner!="function")return this.gain(1);const s=this.track(this.ctx.createStereoPanner());return s.pan.value=t,s}chain(...t){for(let s=0;s<t.length-1;s++)t[s].connect(t[s+1]);return t[t.length-1]}loop(t,s){const o=this.track(this.ctx.createChannelMerger(2)),a=(1-Math.max(0,Math.min(1,s)))*(Math.PI/4),i=Math.cos(a),d=Math.sin(a),c=t.duration,l=this.rng()*c,p=(l+c*b(this.rng,.35,.65))%c;return[l,p].forEach((h,r)=>{const u=this.ctx.createBufferSource();u.buffer=t,u.loop=!0,this.track(u);const f=this.gain(r===0?i:d),x=this.gain(r===0?d:i);u.connect(f).connect(o,0,0),u.connect(x).connect(o,0,1),this.loops.push({src:u,offset:h})}),o}grain(t,s,o){if(this.stopped)return 0;const a=this.ctx.createBufferSource();a.buffer=t,a.playbackRate.value=o.rate??1;const i=this.ctx.createGain();i.gain.value=o.gain;const d=[i];let c=a;if(o.lowpass){const l=this.ctx.createBiquadFilter();l.type="lowpass",l.frequency.value=o.lowpass,l.Q.value=.5,c=c.connect(l),d.push(l)}if(c=c.connect(i),o.pan!==void 0&&typeof this.ctx.createStereoPanner=="function"){const l=this.ctx.createStereoPanner();l.pan.value=Math.max(-1,Math.min(1,o.pan)),c=c.connect(l),d.push(l)}if(c.connect(o.dest),o.send){const l=this.ctx.createGain();l.gain.value=o.send.gain,c.connect(l).connect(o.send.node),d.push(l)}return a.onended=()=>{this.grains.delete(a);try{a.disconnect(),d.forEach(l=>l.disconnect())}catch{}},this.grains.add(a),a.start(s),t.duration/(o.rate??1)}every(t){this.tickers.push(t)}process(t,s,o){let a=-1;this.every(i=>{a<0&&(a=this.startTime+t);let d=0;for(;a<i&&d++<200;){const c=o(a)||0;a+=c+s()}})}start(t){if(!this.started){this.started=!0,this.startTime=t;for(const{src:s,offset:o}of this.loops)s.start(t,o);this.output.gain.setValueAtTime(0,t),this.output.gain.setTargetAtTime(1,t,hn)}}tick(t){if(!(!this.started||this.stopped))for(const s of this.tickers)s(t)}stop(t){if(this.stopped)return;this.stopped=!0;const s=t+Pt;try{this.output.gain.cancelScheduledValues(t),this.output.gain.setTargetAtTime(0,t,fn)}catch{}for(const{src:o}of this.loops)try{o.stop(s)}catch{}for(const o of this.grains)try{o.stop(s)}catch{}}
1dispose(){this.stopped=!0;for(const{src:t}of this.loops)try{t.stop()}catch{}for(const t of this.grains)try{t.stop()}catch{}for(const t of this.nodes)try{t.disconnect()}catch{}this.grains.clear(),this.tickers=[]}}function P(e,t,s,o){e.setTargetAtTime(t,s,Math.max(.005,o))}function ie(e,t,s,o,a,i){e.process(b(e.rng,0,a),()=>b(e.rng,a,i),d=>{const c=s*Math.pow(10,b(e.rng,-1,1)*o/20);P(t,c,d,(a+i)/5)})}const se=(e,t)=>t[Math.floor(e()*t.length)],ye=(e,t,s)=>s+-Math.log(1-e()*.999)*t,Le=(e,t)=>async(s,o)=>{const a=await o.texture(e);s.chain(s.loop(a,t),s.trim)},kn=async(e,t)=>{const[s,o,a,i]=await Promise.all([t.texture("pink"),t.texture("rainDrops"),t.texture("brown"),t.bank("drips")]),d=e.gain(.55);e.chain(e.loop(s,.95),e.filter("highpass",500,.6),e.filter("lowpass",4800,.5),e.filter("peaking",2200,.8,1.5),d,e.trim);const c=e.gain(.75);e.chain(e.loop(o,.7),c,e.trim);const l=e.gain(.35);e.chain(e.loop(a,.8),e.filter("lowpass",320,.6),l,e.trim),ie(e,d.gain,.55,1.5,3,8),ie(e,c.gain,.75,1.5,2,6);const p=e.gain(1);e.chain(p,e.filter("lowpass",5e3,.5),e.trim),e.process(1.5,()=>ye(e.rng,1.6,.35),h=>{e.grain(se(e.rng,i).buffer,h,{dest:p,rate:b(e.rng,.85,1.2),gain:.05+.12*Math.pow(e.rng(),2),pan:b(e.rng,-.8,.8)})})},wn=async(e,t)=>{const[s,o,a]=await Promise.all([t.texture("pink"),t.texture("brown"),t.texture("rainDrops")]),i=e.gain(.6);e.chain(e.loop(o,.8),e.filter("lowpass",420,.6),i,e.trim);const d=e.panner(0);d.connect(e.trim);const c=e.filter("lowpass",500,.6),l=e.gain(.15);e.chain(e.loop(s,.9),e.filter("highpass",110,.6),c,l,d);const p=e.gain(.02);e.chain(e.loop(s,.95),e.filter("highpass",1400,.6),e.filter("lowpass",6e3,.5),p,d);const h=e.gain(.01);e.chain(e.loop(a,.9),e.filter("highpass",2200,.6),h,d);let r=e.rng()*Math.PI*2;e.process(.2,()=>0,u=>{r+=b(e.rng,.5,.9);const f=Math.min(1,Math.max(.35,.68+.2*Math.sin(r)+b(e.rng,-.2,.2))),x=b(e.rng,7,12.5)*(.85+.3*f),k=x*b(e.rng,.38,.5),y=x-k,w=u+k;return P(i.gain,.55+.45*f,u,k/2.5),P(l.gain,.2+.65*f,u,k/3),P(c.frequency,600+1600*f,u,k/3),"pan"in d&&P(d.pan,b(e.rng,-.3,.3),u,k/2),P(i.gain,.5,w,y/3),P(l.gain,.16,w,y/3.5),P(c.frequency,480,w,y/3),P(p.gain,.45*f,w-.3,.3),P(p.gain,.02,w+.7,y/3.2),P(h.gain,.35*f,w,.4),P(h.gain,.01,w+1.2,y/3),x})},jn=async(e,t)=>{const[s,o,a,i]=await Promise.all([t.texture("babble"),t.texture("pink"),t.texture("brown"),t.bank("gurgles")]),d=e.gain(.85);e.chain(e.loop(s,.75),d,e.trim);const c=e.filter("lowpass",2200,.6),l=e.gain(.3);e.chain(e.loop(o,.9),e.filter("highpass",250,.6),c,l,e.trim);const p=e.gain(.3);e.chain(e.loop(a,.8),e.filter("lowpass",240,.6),p,e.trim),ie(e,d.gain,.85,1.5,2,6),ie(e,l.gain,.3,2,3,9),e.process(1,()=>b(e.rng,3,8),r=>P(c.frequency,b(e.rng,1700,2800),r,1.5));const h=e.gain(1);e.chain(h,e.filter("lowpass",2800,.5),e.trim),e.process(2,()=>ye(e.rng,4,1.5),r=>{e.grain(se(e.rng,i).buffer,r,{dest:h,rate:b(e.rng,.9,1.12),gain:b(e.rng,.08,.2),pan:b(e.rng,-.6,.6)})})},yn=async(e,t)=>{const[s,o]=await Promise.all([t.texture("pink"),t.texture("brown")]),a=r=>{const u=e.filter("bandpass",400,.9),f=e.gain(.4);return e.chain(e.loop(s,.9),u,f,e.panner(r),e.trim),{bp:u,g:f}},i=[a(-.35),a(.35)],d=e.gain(.35);e.chain(e.loop(o,.8),e.filter("lowpass",170,.6),d,e.trim);const c=e.gain(.05);e.chain(e.loop(s,.95),e.filter("highpass",1600,.6),e.filter("lowpass",5e3,.5),c,e.trim);const l=e.filter("bandpass",800,11),p=e.gain(0);e.chain(e.loop(s,.6),l,p,e.trim);let h=.4;e.process(0,()=>b(e.rng,1.2,4),r=>{h=.55*h+.45*b(e.rng,.15,.7),e.rng()<.12&&(h=b(e.rng,.75,1));const u=b(e.rng,.6,1.6);for(const f of i){const x=Math.max(0,Math.min(1,h+b(e.rng,-.12,.12)));P(f.g.gain,.12+.55*x,r,u),P(f.bp.frequency,260+620*x,r,u*1.2),P(f.bp.Q,.7+.6*x,r,u)}P(d.gain,.25+.25*h,r,u*1.5),P(c.gain,.03+.08*h,r,u),P(p.gain,Math.max(0,h-.6)*.6,r,u*1.3),P(l.frequency,650+450*h+b(e.rng,-60,60),r,u*1.5)})},Nn=async(e,t)=>{const[s,o,a,i]=await Promise.all([t.texture("brown"),t.texture("pink"),t.texture("crackle"),t.bank("pops")]),d=e.gain(.5);e.chain(e.loop(s,.7),e.filter("lowpass",260,.6),d,e.trim);const c=e.gain(.16);e.chain(e.loop(o,.8),e.filter("bandpass",650,.7),e.filter("lowpass",2400,.5),c,e.trim);const l=e.gain(.5);
1e.chain(e.loop(a,.5),l,e.trim),ie(e,d.gain,.5,1.5,2,5),e.process(0,()=>b(e.rng,.2,.8),h=>P(c.gain,b(e.rng,.1,.22),h,.15)),ie(e,l.gain,.5,2.5,1.5,5);const p=e.gain(1);e.chain(p,e.filter("lowpass",6e3,.5),e.trim),e.process(2,()=>ye(e.rng,3.5,.8),h=>{const r=()=>({dest:p,rate:b(e.rng,.85,1.2),gain:b(e.rng,.15,.4),pan:b(e.rng,-.5,.5)});e.grain(se(e.rng,i).buffer,h,r()),e.rng()<.25&&e.grain(se(e.rng,i).buffer,h+b(e.rng,.08,.3),r())})},Mn=async(e,t)=>{const[s,o,a,i]=await Promise.all([t.texture("rustle"),t.texture("pink"),t.bank("birds"),t.reverbIR()]),d=e.gain(.5);e.chain(e.loop(s,.85),e.filter("lowpass",6500,.5),d,e.trim);const c=e.gain(.25);e.chain(e.loop(o,.9),e.filter("highpass",150,.6),e.filter("lowpass",900,.6),c,e.trim),e.process(0,()=>b(e.rng,2,6),x=>{const k=b(e.rng,.25,1);P(d.gain,.35+.25*k,x,1.2),P(c.gain,.18+.12*k,x,1.5)});const l=e.gain(1);l.connect(e.trim);const p=e.ctx.createConvolver();p.buffer=i;const h=e.gain(.5);e.chain(p,h,e.trim);const r=["chirp","warble","whistle","dove","trill"],u=()=>{const x=e.rng(),k=x<.3?"chirp":x<.52?"warble":x<.74?"whistle":x<.87?"dove":"trill",w=a.filter(M=>M.kind===k).sort(()=>e.rng()-.5).slice(0,2+Math.floor(e.rng()*2)),S=e.rng();return{kinds:w.length?w:a.filter(M=>M.kind===r[0]),pan:b(e.rng,-.85,.85),gain:(k==="trill"?.5:k==="dove"?.9:1)*(.18-.11*S),lp:6e3-2800*S,wet:.25+.6*S,rate:b(e.rng,.95,1.05),dove:k==="dove"}},f=[u(),u(),u()];e.process(b(e.rng,1.5,4),()=>ye(e.rng,3.2,1.2),x=>{if(e.rng()<.07&&(f[Math.floor(e.rng()*f.length)]=u()),e.rng()<.12)return b(e.rng,5,12);const k=se(e.rng,f),y=k.dove?1:1+Math.floor(e.rng()*3),w=se(e.rng,k.kinds);let S=x;for(let M=0;M<y;M++){const R=e.rng()<.75?w:se(e.rng,k.kinds),N=e.grain(R.buffer,S,{dest:l,rate:k.rate*b(e.rng,.98,1.02),gain:k.gain*b(e.rng,.8,1.05),pan:k.pan+b(e.rng,-.05,.05),lowpass:k.lp,send:{node:p,gain:k.wet}});S+=N+b(e.rng,.7,2.5)}return S-x})},Sn={white:Le("white",.85),pink:Le("pink",.85),brown:Le("brown",.75),rain:kn,ocean:wn,stream:jn,wind:yn,fireplace:Nn,forest:Mn};async function vn(e,t,s){const o=new gn(e,pn[t]);try{await Sn[t](o,s)}catch(a){throw o.dispose(),a}return o}class Cn{constructor(t,s,o=Ge){this.ctx=t,this.destination=s,this.cache=new bn(t,o)}ctx;destination;cache;current=null;fading=new Set;token=0;timer=null;async play(t){const s=++this.token,o=this.cache.track(),a=await vn(this.ctx,t,this.cache);if(s!==this.token){a.dispose();return}this.cache.profile.keepAll||this.cache.retainOnly(o);const i=this.ctx.currentTime;this.retire(i),a.output.connect(this.destination),a.start(i),a.tick(i+bt),this.current=a,this.ensureTimer()}stop(){++this.token,this.retire(this.ctx.currentTime),this.clearTimer()}dispose(){++this.token,this.clearTimer(),this.current?.dispose(),this.fading.forEach(t=>t.dispose()),this.current=null,this.fading.clear(),this.cache.clear()}retire(t){const s=this.current;this.current=null,s&&(s.stop(t),this.fading.add(s),setTimeout(()=>{s.dispose(),this.fading.delete(s)},(Pt+.3)*1e3))}ensureTimer(){this.timer||(this.timer=setInterval(()=>{this.current?.tick(this.ctx.currentTime+bt)},dn))}clearTimer(){this.timer&&clearInterval(this.timer),this.timer=null}}const ke=[{id:"white",label:"White Noise",description:"Steady hiss",icon:"â»ï¸",category:"noise"},{id:"pink",label:"Pink Noise",description:"Soft & balanced",icon:"ð©·",category:"noise"},{id:"brown",label:"Brown Noise",description:"Deep & warm",icon:"ð¤",category:"noise"},{id:"rain",label:"Rain",description:"Gentle rainfall",icon:"ð§ï¸",category:"nature"},{id:"ocean",label:"Ocean",description:"Rolling waves",icon:"ð",category:"nature"},{id:"stream",label:"Stream",description:"Flowing water",icon:"ð§",category:"nature"},{id:"wind",label:"Wind",description:"Soft breeze",icon:"ð",category:"nature"},{id:"fireplace",label:"Fireplace",description:"Crackling fire",icon:"ð¥",category:"nature"},{id:"forest",label:"Forest",description:"Birds & rustling",icon:"ð²",category:"nature"}],Oe="ambient-sound-type",gt="ambient-sound-volume",Rn=.85,$e=e=>Rn*Math.pow(Math.max(0,Math.min(1,e)),.6),En=()=>typeof window>"u"?null:window.AudioContext||window.webkitAudioContext||null;function At(e){e.state!=="running"&&e.resume().catch(()=>{});try{const t=e.createBufferSource();t.buffer=e.createBuffer(1,1,e.sampleRate),t.connect(e.destination),t.start(0)}catch{}}const qe=new WeakSet;function Tn(e){if(e.state==="running"||qe.has(e))return;qe.add(e);const t=()=>{qe.delete(e),window.removeEventListener("pointerdown",t,!0),window.removeEventListener("keydown",t,!0),e.state!=="closed"&&At(e)};window.addEventListener("pointerdown",t,!0),window.addEventListener("keydown",t,!0)}function kt(e,t){const s=e.context.currentTime;try{e.gain.cancelScheduledValues(s),e.gain.setTargetAtTime(t,s,.03)}catch{e.gain.value=t}}function Pn(){const[e,t]=g.useState(()=>{try{const u=localStorage.getItem(Oe);if(u&&ke.some(f=>f.id===u))return u}catch{}return"off"}),[s,o]=g.useState(()=>{try{const u=parseFloat(localStorage.getItem(gt)||"0.3");return isNaN(u)?.3:Math.max(0,Math.min(1,u))}catch{return .3}}),a=g.useRef(null),i=g.useRef(null),d=g.useRef(null),c=g.useCallback(()=>{try{d.current?.stop()}catch{}},[]),l=g.useCallback((u,f)=>{if(u==="off"){c();return}try{if(!a.current||a.current.state==="closed"){const k=En();if(!k)return;
1a.current=new k}const x=a.current;if(At(x),Tn(x),!i.current||i.current.context!==x){i.current=x.createGain(),i.current.gain.value=$e(f);const k=x.createDynamicsCompressor();k.threshold.value=-3,k.knee.value=0,k.ratio.value=20,k.attack.value=.003,k.release.value=.25,i.current.connect(k),k.connect(x.destination)}else kt(i.current,$e(f));(!d.current||d.current.ctx!==x)&&(d.current?.dispose(),d.current=new Cn(x,i.current,mn()?xn:Ge)),d.current.play(u).catch(k=>{})}catch{}},[c]),p=g.useCallback(u=>{t(u);try{localStorage.setItem(Oe,u)}catch{}if(u==="off"){c();try{localStorage.setItem("white-noise-playing","false")}catch{}}else{l(u,s);try{localStorage.setItem("white-noise-playing","true")}catch{}}},[s,l,c]),h=g.useCallback(u=>{const f=Math.max(0,Math.min(1,u));o(f);try{localStorage.setItem(gt,f.toString())}catch{}i.current&&kt(i.current,$e(f))},[]),r=g.useCallback(()=>{c(),t("off");try{localStorage.setItem(Oe,"off"),localStorage.setItem("white-noise-playing","false")}catch{}},[c]);return g.useEffect(()=>(e!=="off"&&l(e,s),()=>{c()}),[]),g.useEffect(()=>()=>{c();const u=a.current,f=d.current;!u||u.state==="closed"||(a.current=null,i.current=null,d.current=null,setTimeout(()=>{try{f?.dispose()}catch{}try{u.close()}catch{}},700))},[c]),{activeSound:e,volume:s,isPlaying:e!=="off",selectSound:p,changeVolume:h,stopAll:r}}const _e=e=>e.stopPropagation(),Bt=g.memo(({activeSound:e,volume:t,onSelectSound:s,onChangeVolume:o,triggerClassName:a})=>{const i=e!=="off",d=g.useCallback(r=>{o(r[0])},[o]),c=g.useCallback(()=>{s("off")},[s]),l=g.useMemo(()=>ke.filter(r=>r.category==="noise"),[]),p=g.useMemo(()=>ke.filter(r=>r.category==="nature"),[]),h=g.useMemo(()=>ke.find(r=>r.id===e)?.label,[e]);return n.jsxs(St,{children:[n.jsxs(as,{children:[n.jsx(os,{asChild:!0,children:n.jsx(vt,{asChild:!0,children:a?n.jsx("button",{type:"button","aria-label":i?`Playing: ${h}`:"Ambient sounds",onClick:_e,className:A("white-noise-player",a,i&&"is-on"),children:i?n.jsx(Ae,{}):n.jsx(Be,{})}):n.jsxs(rs,{variant:"ghost",size:"icon",onClick:_e,className:A("white-noise-player","h-7 w-7 rounded-full transition-all duration-200 relative",i?"text-primary hover:bg-primary/10":"text-muted-foreground hover:bg-primary/10"),children:[i?n.jsx(Ae,{className:"h-4 w-4"}):n.jsx(Be,{className:"h-4 w-4"}),i&&n.jsx("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-primary animate-pulse"})]})})}),n.jsx(is,{side:"bottom",children:n.jsx("p",{children:i?`Playing: ${h}`:"Ambient sounds"})})]}),n.jsxs(Ct,{side:"top",align:"center",className:"w-80 p-0 overflow-hidden rounded-xl",onClick:_e,children:[n.jsx("div",{className:"px-4 pt-4 pb-2",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("h4",{className:"text-sm font-semibold text-slate-800 dark:text-slate-200",children:"Focus Sounds"}),i&&n.jsx("button",{onClick:c,className:"text-[11px] font-medium text-slate-400 hover:text-red-500 dark:hover:text-red-400 transition-colors px-2 py-0.5 rounded-md hover:bg-red-50 dark:hover:bg-red-950/20",children:"Stop"})]})}),n.jsxs("div",{className:"px-3 pb-1",children:[n.jsx("span",{className:"text-[10px] uppercase tracking-widest font-semibold text-slate-400 dark:text-slate-500 px-1",children:"Noise"}),n.jsx("div",{className:"grid grid-cols-3 gap-1.5 mt-1.5",children:l.map(r=>{const u=e===r.id;return n.jsx(Ke,{icon:r.icon,label:r.label,description:r.description,selected:u,onClick:()=>s(u?"off":r.id)},r.id)})})]}),n.jsxs("div",{className:"px-3 pt-2 pb-2",children:[n.jsx("span",{className:"text-[10px] uppercase tracking-widest font-semibold text-slate-400 dark:text-slate-500 px-1",children:"Nature"}),n.jsx("div",{className:"grid grid-cols-3 gap-1.5 mt-1.5",children:p.map(r=>{const u=e===r.id;return n.jsx(Ke,{icon:r.icon,label:r.label,description:r.description,selected:u,onClick:()=>s(u?"off":r.id)},r.id)})})]}),i&&n.jsxs("div",{className:"px-4 pb-4 pt-2 border-t border-slate-100 dark:border-border/60 mt-1",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Be,{className:"h-3.5 w-3.5 text-slate-300 dark:text-slate-600 flex-shrink-0"}
1),n.jsx(js,{value:[t],onValueChange:d,min:.05,max:1,step:.05,className:"flex-1"}),n.jsx(Ae,{className:"h-3.5 w-3.5 text-slate-300 dark:text-slate-600 flex-shrink-0"})]}),n.jsxs("p",{className:"text-center text-[10px] text-slate-400 mt-1.5",children:[Math.round(t*100),"%"]})]})]})]})});Bt.displayName="AmbientSoundPicker";const Ke=g.memo(({icon:e,label:t,description:s,selected:o,onClick:a})=>n.jsxs("button",{onClick:a,className:A("flex flex-col items-center gap-0.5 py-2.5 px-1 rounded-xl transition-all duration-200","text-center group cursor-pointer select-none",o?"bg-primary/8 dark:bg-primary/15 ring-1 ring-primary/25 shadow-sm shadow-primary/5":"hover:bg-slate-50 dark:hover:bg-muted/50"),children:[n.jsx("span",{className:A("text-base leading-none transition-transform duration-200",o?"scale-110":"group-hover:scale-105"),children:e}),n.jsx("span",{className:A("text-[11px] font-medium leading-tight mt-0.5",o?"text-primary dark:text-primary":"text-slate-600 dark:text-slate-400"),children:t}),n.jsx("span",{className:A("text-[9px] leading-tight",o?"text-primary/60":"text-slate-400 dark:text-slate-500"),children:s})]}));Ke.displayName="SoundTile";const An=[{k:"pomodoroMinutes",label:"Focus",step:5,unit:"m"},{k:"shortBreakMinutes",label:"Break",step:1,unit:"m"},{k:"longBreakMinutes",label:"Long break",step:5,unit:"m"},{k:"roundsPerSet",label:"Rounds",step:1,unit:""}],Bn=()=>{const{preferences:e,applyPreset:t,setPreference:s}=Ns(),o=Ms(e),[a,i]=g.useState(o===null),d=a||o===null;return n.jsxs("div",{className:"fv-settings",role:"group","aria-label":"Pomodoro settings",children:[n.jsx("div",{className:"fv-settings-h",children:"Pomodoro"}),Object.keys(dt).map(c=>{const l=dt[c],p=o===c&&!a;return n.jsxs("button",{type:"button",role:"radio","aria-checked":p,className:A("fv-settings-row",p&&"is-on"),onClick:()=>{t(c),i(!1)},children:[n.jsx("span",{className:"fv-radio","aria-hidden":!0}),n.jsx("span",{children:l.label}),n.jsxs("span",{className:"fv-settings-meta",children:[l.pomodoroMinutes," · ",l.shortBreakMinutes," · ",l.longBreakMinutes]})]},c)}),n.jsxs("button",{type:"button",role:"radio","aria-checked":d,className:A("fv-settings-row",d&&"is-on"),onClick:()=>i(!0),children:[n.jsx("span",{className:"fv-radio","aria-hidden":!0}),n.jsx("span",{children:"Custom"}),n.jsxs("span",{className:"fv-settings-meta",children:[e.pomodoroMinutes," · ",e.shortBreakMinutes," · ",e.longBreakMinutes]})]}),d&&n.jsx("div",{className:"fv-steppers",children:An.map(c=>{const l=e[c.k];return n.jsxs("div",{className:"fv-stepper",children:[n.jsx("span",{children:c.label}),n.jsx("button",{type:"button","aria-label":`Less ${c.label.toLowerCase()}`,onClick:()=>s(c.k,l-c.step),children:n.jsx(Nt,{})}),n.jsxs("b",{children:[l,c.unit]}),n.jsx("button",{type:"button","aria-label":`More ${c.label.toLowerCase()}`,onClick:()=>s(c.k,l+c.step),children:n.jsx(zt,{})})]},c.k)})}),n.jsx("div",{className:"fv-settings-sep"}),n.jsxs("label",{className:"fv-settings-switch",children:[n.jsx("span",{children:"Start breaks automatically"}),n.jsx(Ie,{checked:e.autoStartBreaks,onCheckedChange:c=>s("autoStartBreaks",c)})]}),n.jsxs("label",{className:"fv-settings-switch",children:[n.jsx("span",{children:"Start focus automatically"}),n.jsx(Ie,{checked:e.autoStartFocus,onCheckedChange:c=>s("autoStartFocus",c)})]}),n.jsxs("label",{className:"fv-settings-switch",children:[n.jsx("span",{children:"Chime at round and break end"}),n.jsx(Ie,{checked:e.soundEnabled,onCheckedChange:c=>s("soundEnabled",c)})]})]})},wt=[[0,"Let's lock in."],[5,"Warming up nicely."],[15,"You're in the zone."],[45,"Deep work mode."],[60,"One hour of pure focus."],[90,"You're unstoppable."]],jt="fv-timer-min",In=(e,t,s,o,a=Date.now())=>e?Math.max(0,Math.floor(((t&&s?s:a)-e.getTime()-o)/1e3)):0,Dn=e=>{const t=e.phase==="break"?e.round%e.rounds+1:e.round,s=e.breakEndsAt?Fs(e.breakEndsAt,"HH:mm"):"",o=e.phase==="ready"&&e.filled===0;if(e.phase==="break"){const a=e.breakKind==="long";return{status:a?"Long break":"Short break",line:`Back at ${s}`,milestone:a?`Set of ${e.rounds} done. Step away for a bit.`:"Stand up, look far away.",breakIcon:!0,nextRound:t,mini:`Break · back at ${s}`}}if(e.phase==="ready")return{status:"Break's over",line:o?"Ready for a new set":`Ready for roun
1d ${e.round}`,milestone:"Fresh start. Pick up where you left off.",breakIcon:!1,nextRound:t,mini:`Ready for round ${e.round}`};switch(e.focusState){case"paused":return{status:"Paused",line:"Resume when ready",milestone:"Paused, take a moment.",breakIcon:!1,nextRound:t,mini:"Paused"};case"done":return{status:"Round done",line:`Take a ${e.breakMinutes} min break?`,milestone:`Round ${e.round} done. Nice.`,breakIcon:!1,nextRound:t,mini:"Round done"};case"over":return{status:"Overtime",line:"Break when you're ready",milestone:"",breakIcon:!1,nextRound:t,mini:"Overtime"};default:return{status:"Focus",line:`${e.nextBreak==="long"?"Long":"Short"} break next`,milestone:"",breakIcon:!1,nextRound:t,mini:`Focus · Round ${e.round} of ${e.rounds}`}}},It=g.memo(({timer:e,cycle:t})=>{const[s,o]=g.useState(()=>Date.now());g.useEffect(()=>{let E;const D=()=>{o(Date.now()),E=window.setTimeout(D,1e3-Date.now()%1e3+5)};D();const J=()=>{document.visibilityState==="visible"&&(window.clearTimeout(E),D())};return document.addEventListener("visibilitychange",J),()=>{window.clearTimeout(E),document.removeEventListener("visibilitychange",J)}},[]);const{activeSound:a,volume:i,selectSound:d,changeVolume:c,stopAll:l}=Pn(),p=g.useRef(l);p.current=l,g.useEffect(()=>()=>p.current(),[]);const[h,r]=g.useState(()=>{try{return localStorage.getItem(jt)==="1"}catch{return!1}}),u=()=>r(E=>{try{localStorage.setItem(jt,E?"0":"1")}catch{}return!E}),f=t.view(s),x=e.focusAt(s),k=Dn(f),y=f.sign?Math.floor(f.clock):Math.ceil(f.clock),[w,S]=Ss(y),M=f.phase==="break",R=f.focusState==="paused",N=k.milestone||([...wt].reverse().find(([E])=>x/60>=E)?.[1]??wt[0][1]),B=f.phase==="focus"&&!R,C=f.phase==="focus"?R?"Resume (P)":"Pause (P)":`Start round ${k.nextRound}${f.phase==="break"?" now":""} (P)`,U=n.jsx("button",{type:"button",className:"fv-icon-btn",title:C,"aria-label":C,onClick:t.togglePause,children:B?n.jsx(Vt,{}):n.jsx(Yt,{fill:"currentColor"})}),K=f.phase==="break"?[{label:"Skip break",title:"Skip break (B)",primary:!1,run:t.skip}]:f.phase==="ready"?[{label:`Start round ${f.round}`,title:`Start round ${f.round} (B)`,primary:!0,run:t.startRound}]:f.focusState==="done"?[{label:"Start break",title:`Start a ${f.breakMinutes} min break (B)`,primary:!0,run:t.startBreak},{label:"Keep going",title:"Keep going",primary:!1,run:t.keepGoing}]:f.focusState==="over"?[{label:"Take break",title:`Take a ${f.breakMinutes} min break (B)`,primary:!1,run:t.startBreak}]:[],O=n.jsxs("span",{className:A("fv-clock",R&&"is-paused",M&&"is-break"),"aria-label":`${f.label.toLowerCase()} ${f.sign}${w} minutes ${S} seconds`,children:[f.sign,w,n.jsx("i",{children:":"}),S]}),$=n.jsx("span",{className:"fv-dots","aria-label":`Round ${f.round} of ${f.rounds}`,children:Array.from({length:f.rounds},(E,D)=>n.jsx("span",{className:A(D<f.filled&&"is-on",f.phase==="focus"&&D===f.filled&&"is-current")},D))});return h?n.jsx("div",{className:"fv-card",children:n.jsxs("div",{className:"fv-timer is-min",role:"button",tabIndex:0,title:"Show timer","aria-label":"Show timer",onClick:u,onKeyDown:E=>{E.key==="Enter"&&E.target===E.currentTarget&&(E.preventDefault(),u())},children:[n.jsxs("div",{className:"fv-timer-min-l",children:[O,n.jsx("span",{children:k.mini})]}),n.jsxs("div",{className:"fv-timer-ctl",onClick:E=>E.stopPropagation(),children:[(f.focusState==="done"||f.focusState==="over")&&n.jsx("button",{type:"button",className:"fv-text-btn",title:"Start break (B)",onClick:t.startBreak,children:"Break"}),U,n.jsx("button",{type:"button",className:"fv-icon-btn",title:"Show timer","aria-label":"Show timer",onClick:u,children:n.jsx(ct,{})})]})]})}):n.jsx("div",{className:"fv-card",children:n.jsxs("div",{className:"fv-timer",children:[n.jsxs("div",{className:"fv-timer-top",children:[n.jsxs("div",{className:"fv-timer-l",children:[n.jsxs("div",{className:"fv-clock-row",children:[O,n.jsxs("span",{className:"fv-elapsed",children:[n.jsx("span",{className:"fv-swap",children:f.label},f.label),n.jsx("span",{})]})]}),n.jsxs("span",{className:"fv-milestone",children:[k.breakIcon?n.jsx(Gt,{}):n.jsx(Qt,{}),n.jsx("span",{className:"fv-swap",children:N},N)]})]}),n.jsxs("div",{className:"fv-timer-ctl",children:[U,n.jsx(Bt,{activeSound:a,volume:i,onSelectSound:d,onChangeVolume:c,triggerClassName:"fv-icon-btn"}),n.jsxs(St,{children:[n.jsx(vt,{asChild:!0,children:n.jsx("button",{type:"button",className:"fv-icon-btn",title:"Pomodoro settings","aria-label":"Pomodoro settings",children:n.jsx(ct,{})})}),n.jsx(Ct,{align:"end",className:"w-auto p-0",children:n.jsx(Bn,{})})]}),n.jsx("button",{type:"button",className:"fv-icon-btn",title:"Minimize timer","aria-label":"Minimize timer",onClick:u,children:n.jsx(Nt,{})})]})]}),n.jsxs("div",{className:"fv-timer-bottom",children:[n.jsxs("div",{className:A("fv-dial",R&&"is-paused",M&&"is-break",f.phase==="ready"&&"is-ready"),"aria-hidden":!0,
1children:[n.jsxs("svg",{width:"84",height:"84",viewBox:"0 0 84 84",children:[n.jsx("circle",{className:"trk",cx:"42",cy:"42",r:"36"}),n.jsx("circle",{className:"val",cx:"42",cy:"42",r:"36",style:{strokeDashoffset:226.2*(1-(f.phase==="focus"?f.ring:0))}},`f${f.phase}`),n.jsx("circle",{className:"val val-brk",cx:"42",cy:"42",r:"36",style:{strokeDashoffset:226.2*(1-(M?f.ring:0))}},`b${f.phase}`)]}),n.jsx("span",{className:"fv-dial-core",children:n.jsx("span",{})})]}),n.jsxs("div",{className:"fv-status","aria-live":"polite",children:[n.jsx("b",{className:"fv-swap",children:k.status},k.status),n.jsx("span",{children:k.line}),n.jsxs("small",{children:[$,"Round ",f.round," of ",f.rounds," · ",ys(x/60)," focused"]})]}),K.length>0&&n.jsx("div",{className:"fv-cycle",children:K.map(E=>n.jsx("button",{type:"button",className:A(E.primary&&"is-primary"),title:E.title,onClick:E.run,children:E.label},E.label))},`${f.phase}-${f.focusState}`)]})]})})});It.displayName="FocusTimerCard";const Fn=({open:e,currentId:t,onPick:s,onClose:o})=>{const[a,i]=g.useState(""),[d,c]=g.useState(0),l=g.useRef(null),p=g.useRef(null);g.useEffect(()=>{l.current?.focus()},[]);const h=g.useMemo(()=>{const u=a.trim().toLocaleLowerCase();return u?e.filter(f=>f.task.content.toLocaleLowerCase().includes(u)):e},[e,a]),r=Math.min(d,Math.max(0,h.length-1));return g.useEffect(()=>{p.current?.querySelector(`[data-i="${r}"]`)?.scrollIntoView({block:"nearest"})},[r]),n.jsxs("div",{className:"fv-search fv-pop",role:"dialog","aria-label":"Search tasks in this queue",children:[n.jsxs("div",{className:"fv-search-field",children:[n.jsx(Mt,{"aria-hidden":!0}),n.jsx("input",{ref:l,value:a,onChange:u=>{i(u.target.value),c(0)},placeholder:"Jump to a task in this queue","aria-label":"Search tasks","aria-controls":"fv-search-list","aria-activedescendant":h.length?`fv-sr-${r}`:void 0,onKeyDown:u=>{u.key==="ArrowDown"?(u.preventDefault(),c(Math.min(r+1,h.length-1))):u.key==="ArrowUp"?(u.preventDefault(),c(Math.max(r-1,0))):u.key==="Enter"&&h[r]?(u.preventDefault(),s(h[r].task.id)):u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),o())}}),n.jsx("span",{className:"fv-kbd",children:"Esc"})]}),n.jsxs("div",{className:"fv-search-list",id:"fv-search-list",role:"listbox",ref:p,children:[h.map((u,f)=>n.jsxs("button",{id:`fv-sr-${f}`,"data-i":f,type:"button",role:"option","aria-selected":f===r,className:A("fv-row-btn",f===r&&"is-sel"),onPointerMove:()=>{f!==r&&c(f)},onClick:()=>s(u.task.id),children:[n.jsx("span",{className:"fv-dot",style:{background:re[u.q].color}}),n.jsx("span",{className:"fv-search-title fv-ell",children:u.task.content}),n.jsx(Ls,{task:u.task,lead:!1,className:"fv-search-parent"}),u.task.id===t&&n.jsx("span",{className:"fv-search-tag",children:"current"}),n.jsx("span",{className:"fv-rel-date",children:we(u.task)||"No date"})]},u.task.id)),!h.length&&n.jsx("span",{className:"fv-search-empty",children:a?`No open task in this queue matches â${a}â.`:"No open tasks in this queue."}),n.jsx("span",{className:"fv-search-help",children:"â â to move · Enter to focus · the timer keeps running"})]})]})},Dt="fv-notes-synced";let Ue=null;const Ln=()=>(Ue??=(async()=>{try{const{data:{user:e}}=await lt.auth.getUser();if(!e)return null;const{data:t}=await lt.from("profiles").select("todoist_access_token").eq("id",e.id).single();return t?.todoist_access_token??null}catch{return null}})(),Ue.then(e=>(e||(Ue=null),e))),yt=()=>{try{return JSON.parse(localStorage.getItem(Dt)||"{}")}catch{return{}}},On=async(e,t)=>{const s=t.trim(),o=yt();if(!s||o[e]===s)return;const a=await Ln();if(a)try{await new cs(a).addComment({taskId:e,content:s});try{localStorage.setItem(Dt,JSON.stringify({...yt(),[e]:s}))}catch{}}catch{}},$n=5e3,qn="focus-after-complete",_n=()=>{try{return localStorage.getItem(qn)==="choose"?"choose":"next"}catch{return"next"}},Un=({text:e})=>{const t=e.split(/(https?:\/\/[^\s)]+)/g);return n.jsx(n.Fragment,{children:t.map((s,o)=>o%2?n.jsx("a",{href:s,target:"_blank",rel:"noreferrer",children:s},o):s)})},Kn=({queue:e,focusedTaskId:t,onTaskFocus:s,onCompleteTask:o,onExit:a})=>{const i=ls();us();
1const d=ds({isTaskFocus:!0}),c=g.useRef(i);c.current=i;const l=g.useRef(!1);g.useEffect(()=>(hs(c.current),()=>{l.current||fs(c.current)}),[]);const p=vs(d),h=g.useRef(new Map);e.forEach(m=>h.current.set(m.task.id,m));const[r,u]=g.useState([]),f=g.useMemo(()=>new Set(r),[r]),[x,k]=g.useState([]),y=g.useRef([]),w=g.useMemo(()=>{const m=e.map(j=>j.task.id),v=new Set([...r,...x]);return y.current.forEach((j,I)=>{v.has(j)&&!m.includes(j)&&m.splice(Math.min(I,m.length),0,j)}),x.forEach(j=>{m.includes(j)||m.push(j)}),y.current=m,m},[e,r,x]),S=g.useRef(w);S.current=w;const M=g.useMemo(()=>w.filter(m=>!f.has(m)),[w,f]),R=g.useMemo(()=>M.map(m=>h.current.get(m)).filter(Boolean),[M]);g.useEffect(()=>{if(!x.length)return;const m=new Set(e.map(j=>j.task.id)),v=x.filter(j=>m.has(j));v.length&&k(j=>j.filter(I=>!v.includes(I)))},[e,x]);const N=t&&h.current.has(t)?t:M[0],B=N?h.current.get(N):void 0,[C,U]=g.useState("work"),[K,O]=g.useState(!1),[$,E]=g.useState(null),[D,J]=g.useState(0),[Ne,ce]=g.useState(!1),[Z,ee]=g.useState(!1),[Ft,Qe]=g.useState(!1),[Lt,Ot]=g.useState("in");g.useEffect(()=>{if(!D)return;const m=window.setTimeout(()=>J(0),Math.max(0,D-Date.now()));return()=>window.clearTimeout(m)},[D]),g.useEffect(()=>{N&&N!==t&&s(N)},[N,t,s]);const Me=g.useRef("in"),Se=g.useRef(null),ve=g.useRef(0),Ce=m=>{Me.current=m,Ot(m)},ne=g.useCallback(m=>{if(ht()){m();return}if(Se.current=m,Me.current==="out")return;const v=++ve.current;Ce("out"),window.setTimeout(()=>{if(v!==ve.current)return;const j=Se.current;Se.current=null,j?.(),Ce("pre"),requestAnimationFrame(()=>requestAnimationFrame(()=>{v===ve.current&&Ce("in")}))},110)},[]),le=g.useRef(N);g.useEffect(()=>{le.current=N},[N]);const{activeNote:Re,updateNoteContent:$t}=$s(C==="work"?N:void 0),fe=Re&&N&&Re.taskId===N?Re.content??"":"",[qt,We]=g.useState(""),Ee=g.useRef(),He=g.useRef({id:N,text:fe});He.current={id:N,text:fe};const q=g.useCallback(()=>{const{id:m,text:v}=He.current;m&&v.trim()&&On(m,v)},[]),Xe=g.useCallback(()=>{Z&&(ee(!1),q())},[Z,q]);g.useEffect(()=>()=>window.clearTimeout(Ee.current),[]);const z=g.useCallback(m=>{m&&(q(),ee(!1),ce(!1),le.current=m,ne(()=>{U("work"),O(!1),J(0),s(m)}))},[q,ne,s]),pe=g.useCallback(m=>{if(C!=="work")return;const v=M.indexOf(le.current??"")+m;if(v<0||v>=M.length)return;const j=M[v];le.current=j,q(),ee(!1),ne(()=>s(j))},[C,M,q,ne,s]),Je=g.useRef();g.useEffect(()=>()=>window.clearTimeout(Je.current),[]);const Te=g.useCallback(()=>{if(C!=="work"||K||!N||Me.current!=="in")return;const m=N;q(),ee(!1),O(!0),o(m),Je.current=window.setTimeout(()=>{const v=new Set([...r,m]),j=ft(S.current,m,v);u(I=>I.includes(m)?I:[...I,m]),E(m),J(Date.now()+$n),ne(()=>{O(!1),j&&_n()==="next"?(le.current=j,U("work"),s(j)):U("done")})},ht()?0:300)},[C,K,N,r,q,o,ne,s]),me=g.useCallback(()=>{if(!$||Date.now()>D)return;const m=$;J(0),u(v=>v.filter(j=>j!==m)),k(v=>[...v,m]),z(m),Rt(m).then(v=>{if(!v)throw new Error("This completion canât be undone");return v()}).catch(v=>{Wt.error("Couldn't restore the task",{description:"It is still completed in Todoist."}),k(j=>j.filter(I=>I!==m)),u(j=>j.includes(m)?j:[...j,m])})},[$,D,z]),ue=g.useCallback(()=>{q();const m=In(d.sessionStartTime,d.isPaused,d.pausedTime,d.totalPausedTime),v=r.map(I=>h.current.get(I)).filter(I=>!!I);l.current=!0;const j=ps(i);Cs(j?j.focus*60:m,v,N&&!f.has(N)?N:M[0]),ut(),a()},[q,i,d.sessionStartTime,d.isPaused,d.pausedTime,d.totalPausedTime,r,f,N,M,a]),Ze=g.useRef(()=>{});Ze.current=()=>{q(),l.current=!0,ut(),a()},ms(()=>Ze.current());const et=p.togglePause,Pe=g.useCallback(()=>{ee(!1),ce(!0)},[]),tt=C==="done"?$:N,ae=tt?h.current.get(tt):void 0,_t=M.join("|"),Y=g.useMemo(()=>ae?Rs(ae.task,R.filter(m=>m.task.id!==ae.task.id)):[],[ae?.task.id,ae?.task.content,_t]),G=C==="done"&&$?ft(w,$,f):null,st=g.useCallback(()=>{z(Y[0]?.item.task.id??G)},[Y,G,z]),nt=g.useRef();nt.current=m=>{const v=m.target;if(v?.classList?.contains("task-title-input"))return;if((m.metaKey||m.ctrlKey)&&(m.key==="k"||m.key==="K")){m.preventDefault(),Ne?ce(!1):Pe();return}if(Ne){m.key==="Escape"&&(m.preventDefault(),m.stopPropagation(),ce(!1));return}if(m.key==="Escape"&&Z){m.preventDefault(),m.stopPropagation(),Xe(),document.activeElement?.blur?.();return}if(Es(v)||m.metaKey||m.ctrlKey||m.altKey||v?.closest?.("[data-radix-popper-content-wrapper]"))return;
1const j=m.key.length===1?m.key.toLowerCase():m.key;let I=!0;C==="work"?j===" "?Te():j==="ArrowRight"?pe(1):j==="ArrowLeft"?pe(-1):j==="Escape"?ue():j==="p"?et():j==="b"?p.breakKey():j==="r"?Qe(xe=>!xe):j==="e"?ee(xe=>(xe&&q(),!xe)):j==="/"?Pe():j==="u"?me():I=!1:j==="Enter"?st():j==="n"?z(G):j>="1"&&j<="3"&&Y[+j-1]?z(Y[+j-1].item.task.id):j==="u"?me():j==="Escape"?ue():j==="p"?et():j==="b"?p.breakKey():I=!1,I&&(m.preventDefault(),m.stopPropagation())},g.useEffect(()=>{const m=v=>nt.current?.(v);return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[]),g.useLayoutEffect(()=>{const m=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=m}},[]);const at=(C==="done"?ae?.q:B?.q)??"do",Ut=re[at].color,te=$?h.current.get($):void 0,Q=N?M.indexOf(N):-1,ot=C==="work"&&Q>0?`Previous: ${h.current.get(M[Q-1])?.task.content} (â)`:"First task",rt=C==="work"&&Q>=0&&Q<M.length-1?`Next: ${h.current.get(M[Q+1])?.task.content} (â)`:"Last task",it=D>Date.now()&&!!te&&!te.task.due?.isRecurring,Kt=C==="done"?[["1â3","Related"],["N","Next in order"],["Enter","Start highlighted"],["U","Undo"],["Esc","Back to matrix"]]:[["â â","Navigate"],["Space","Complete"],["R","Related"],["E","Notes"],["P","Pause"],["Esc","Exit"]];return n.jsxs("div",{className:"fv-root",role:"dialog","aria-modal":"true","aria-label":"Single task focus",style:{"--fv-color":Ut},children:[Ts.map(m=>n.jsx("div",{className:A("fv-tint",`q-${m}`,m===at&&"is-on"),"aria-hidden":!0},m)),n.jsxs("div",{className:"fv-column",children:[n.jsxs("div",{className:"fv-card",children:[n.jsx("div",{className:"fv-progress",style:{gap:w.length>48?0:void 0},"aria-hidden":!0,children:w.map(m=>{const v=f.has(m);return n.jsx("span",{className:A(!v&&C==="work"&&m===N&&"is-current"),style:v?{background:re[h.current.get(m)?.q??"do"].color}:void 0},m)})}),n.jsxs("div",{className:"fv-head",children:[n.jsxs("div",{className:"fv-head-l",children:[n.jsx("button",{type:"button",className:"fv-icon-btn",title:ot,"aria-label":ot,"aria-disabled":C!=="work"||Q<=0,onClick:()=>pe(-1),children:n.jsx(Ht,{})}),n.jsx("span",{className:"fv-counter","aria-label":"Position in queue",children:C==="done"?n.jsxs(n.Fragment,{children:[n.jsx("b",{children:r.length})," / ",r.length+M.length]}):n.jsxs(n.Fragment,{children:[n.jsx("b",{children:Math.max(1,Q+1)})," / ",Math.max(1,M.length)]})}),n.jsx("button",{type:"button",className:"fv-icon-btn",title:rt,"aria-label":rt,"aria-disabled":C!=="work"||Q<0||Q>=M.length-1,onClick:()=>pe(1),children:n.jsx(Xt,{})}),n.jsxs("span",{className:"fv-queue fv-ell",children:[n.jsx(Jt,{"aria-hidden":!0}),n.jsx("b",{className:"fv-ell",children:i}),n.jsx("span",{className:"fv-ell",children:C==="done"?`· ${M.length} left`:`· ${w.length} ${w.length===1?"task":"tasks"}, all quadrants`})]})]}),n.jsxs("div",{className:"fv-head-r",children:[n.jsx("button",{type:"button",className:"fv-icon-btn",title:"Search tasks (âK or /)","aria-label":"Search tasks",onClick:Pe,children:n.jsx(Mt,{})}),n.jsxs("button",{type:"button",className:A("fv-icon-btn",Z&&"is-on"),title:"Notes (E)","aria-label":"Notes","aria-pressed":Z,"aria-disabled":C!=="work",onClick:()=>{C==="work"&&(Z?Xe():ee(!0))},style:{position:"relative"},children:[n.jsx(Zt,{}),C==="work"&&fe.trim()&&n.jsx("span",{className:"fv-note-dot","aria-label":"Has a note"})]}),C==="work"&&n.jsxs("button",{type:"button",className:"fv-complete",onClick:Te,children:[n.jsx("span",{className:"fv-complete-ring"}),"Complete",n.jsx(oe,{children:"Space"})]})]})]}),Ne&&n.jsx(Fn,{open:R,currentId:C==="work"?N:void 0,onPick:m=>z(m),onClose:()=>ce(!1)}),n.jsx("div",{className:"fv-body","data-phase":Lt,children:C==="work"&&B?n.jsx(zn,{item:B,completing:K,onComplete:Te,notesOpen:Z,noteText:fe,noteStatus:qt,onNote:m=>{$t(m),We("Savingâ¦"),window.clearTimeout(Ee.current),Ee.current=window.setTimeout(()=>We("Saved · syncs to Todoist on close"),600)},related:Y,relOpen:Ft,onToggleRelated:()=>Qe(m=>!m),onPick:z},B.task.id):C==="work"?n.jsxs("div",{className:"fv-done",children:[n.jsx("span",{className:"fv-last",children:"No open tasks in this view."}),n.jsx("div",{className:"fv-actions",children:n.jsxs("button",{type:"button",className:"fv-ghost",onClick:ue,children:["Back to matrix",n.jsx(oe,{children:"Esc"})]})})]}):n.jsxs("div",{className:"fv-done",style:{"--fv-done":re[te?.q??"do"].color},children:[n.jsxs("div",{className:"fv-done-row",children:[n.jsx("span",{className:"fv-done-check",children:n.jsx(pt,{})}),n.jsx("span",{className:"fv-done-title fv-ell",children:te?.task.content}),it&&n.jsx(mt,{until:D,onUndo:me})]}),n.jsxs("span",{className:"fv-session-line",children:[r.length," done this session · the timer keeps running"]}),Y.length>0&&n.jsxs("div",{className:"fv-rel-group",children:[n.jsx("div",{className:"fv-caption",children:"Related to what you finished"}),Y.map((m,v)=>n.jsxs("button",{type:"button",className:A("fv-row-btn fv-pick",v===0&&"is-hi"),onClick:()=>z(m.item.task.id),children:[n.jsx("span",{className:"fv-key",children:v+1}),n.jsxs("span",{className:"fv-rel-text",children:[n.jsx("span",{className:"fv-rel-title fv-ell",children:m.item.task.content}),n.jsx("span",{className:"fv-rel-why fv-ell",children:m.why})]}),n.jsx("span",{className:"fv-rel-score",children:m.score}),n.jsx("span",{className:"fv-rel-date",children:we(m.item.task)})]},m.item.task.id))]}),G?n.jsxs("div",{children:[n.jsx("div",{className:"fv-caption",children:"Next in order"}),n.jsxs("button",{type:"button",className:A("fv-row-btn fv-pick",!Y.length&&"is-hi"),onClick:()=>z(G),children:[n.jsx("span",{className:"fv-key",children:"N"}),n.jsx("span",{className:"fv-rel-title fv-ell",style:{flex:1,maxWidth:"none"},children:h.current.get(G)?.task.content}),n.jsx("span",{className:"fv-rel-date",children:h.current.get(G)?we(h.current.get(G).task):""})]})]}):n.jsx("span",{className:"fv-last",children:"That was the last task in this queue."}),n.jsxs("div",{className:"fv-actions",children:[(Y.length>0||G)&&n.jsxs("button",{type:"button",className:"fv-primary",onClick:st,children:["Start highlighted",n.jsx(oe,{children:"Enter"})]}),n.jsxs("button",{type:"button",className:"fv-ghost",onClick:ue,children:["Back to matrix",n.jsx(oe,{children:"Esc"})]})]})]})}),n.jsxs("div",{className:"fv-foot",children:[n.jsx("div",{className:"fv-hints kbd-hint",children:Kt.map(([m,v])=>n.jsxs("span",{children:[n.jsx(oe,{children:m}),v]},m))}),n.jsxs("button",{type:"button",className:"fv-exit",onClick:ue,children:[n.jsx(es,{"aria-hidden":!0}),"Exit focus"]}
1)]})]}),n.jsx(It,{timer:d,cycle:p})]}),C==="work"&&it&&te&&n.jsxs("div",{className:"fv-toast",role:"status",style:{"--fv-done":re[te.q].color},children:[n.jsx("span",{className:"fv-toast-check",children:n.jsx(pt,{})}),n.jsxs("span",{children:["Completed ",n.jsx("b",{children:te.task.content})]}),n.jsx(mt,{until:D,onUndo:me})]})]})},zn=({item:e,completing:t,onComplete:s,notesOpen:o,noteText:a,noteStatus:i,onNote:d,related:c,relOpen:l,onToggleRelated:p,onPick:h})=>{const{task:r,q:u}=e,f=re[u],x=xs(r.id,r.content),k=Ps(r),y=As(r),w=Bs(r),S=bs(r.labels),M=g.useRef(null);return g.useEffect(()=>{o&&M.current?.focus({preventScroll:!0})},[o]),n.jsxs("div",{className:A("fv-work",t&&"is-completing"),children:[n.jsxs("span",{className:"fv-quad",children:[n.jsx("span",{className:"fv-dot"}),n.jsx("b",{children:f.name}),"· ",f.axis]}),n.jsxs("div",{className:"fv-heading",children:[n.jsx(Is,{task:r}),n.jsxs("div",{className:"fv-title-row",children:[n.jsx("button",{type:"button",className:"fv-check",title:"Complete (Space)","aria-label":"Complete task",onClick:s,children:n.jsx("svg",{viewBox:"0 0 8 8","aria-hidden":!0,children:n.jsx("path",{d:"M1 4.2 3.1 6.2 7 1.8"})})}),n.jsx("h2",{className:"fv-title",title:x.editing?void 0:"Double-click to rename",onDoubleClick:()=>x.start(),children:x.editing?n.jsx(gs,{value:x.title,onCommit:x.commit,onCancel:x.cancel}):n.jsxs("span",{children:[x.title,n.jsx("span",{className:"fv-strike","aria-hidden":!0})]})})]})]}),n.jsxs("div",{className:"fv-meta",children:[n.jsxs("span",{className:"fv-when",children:[w&&n.jsx("span",{className:"fv-pri",children:w}),n.jsx("span",{className:A("fv-date",k.late&&"is-late"),children:k.date}),k.rel&&n.jsx("span",{children:k.rel}),y&&n.jsx("span",{children:y})]}),S.length>0&&n.jsx("span",{className:"fv-labels",children:S.map(R=>n.jsx("span",{children:R},R))}),r.description?.trim()&&n.jsx("p",{className:"fv-desc",children:n.jsx(Un,{text:r.description.trim()})}),n.jsx(Vn,{parentId:r.id}),o&&n.jsxs("div",{className:"fv-notes fv-pop",children:[n.jsxs("span",{className:"fv-caption",children:[n.jsx("span",{children:"Note"}),n.jsx("span",{children:i})]}),n.jsx("textarea",{ref:M,value:a,onChange:R=>d(R.target.value),placeholder:"What you found, what is left. Saved as you type.","aria-label":"Note for this task"})]})]}),n.jsxs("div",{className:"fv-related",children:[n.jsxs("button",{type:"button",className:"fv-row-btn fv-related-toggle","aria-expanded":l,onClick:p,children:[n.jsx("b",{children:"Related tasks"}),n.jsx("span",{children:Ds(c)}),n.jsx("span",{style:{flex:1}}),n.jsx(oe,{children:"R"}),n.jsx(ts,{className:A("fv-chev",l&&"is-open"),"aria-hidden":!0})]}),l&&c.length>0&&n.jsx("div",{className:"fv-related-list",children:c.map(R=>n.jsxs("button",{type:"button",className:"fv-row-btn",onClick:()=>h(R.item.task.id),children:[n.jsx("span",{className:"fv-ring"}),n.jsxs("span",{className:"fv-rel-text",children:[n.jsx("span",{className:"fv-rel-title fv-ell",children:R.item.task.content}),n.jsx("span",{className:"fv-rel-why fv-ell",children:R.why})]}),n.jsx("span",{className:"fv-rel-score",children:R.score}),n.jsx("span",{className:"fv-rel-date",children:we(R.item.task)})]},R.item.task.id))})]})]})},Vn=({parentId:e})=>{const{nestedSubtasksByParent:t}=ks(),{nestSubtasks:s}=ws(),o=t.get(e)??[],a=g.useRef(new Map),[i,d]=g.useState([]);o.forEach(h=>a.current.set(h.id,h));const c=new Set(o.map(h=>h.id)),l=[...a.current.values()].filter(h=>c.has(h.id)||i.includes(h.id));if(!s||!l.length)return null;const p=h=>{if(i.includes(h)){d(r=>r.filter(u=>u!==h)),Rt(h,4e3).then(r=>r?.()).catch(()=>d(r=>[...r,h]));return}d(r=>[...r,h]),window.dispatchEvent(new CustomEvent("task:complete",{detail:{taskId:h}}))};return n.jsxs("div",{className:"fv-subs",children:[n.jsxs("span",{className:"fv-caption",children:["Subtasks · ",i.filter(h=>l.some(r=>r.id===h)).length,"/",l.length]}),l.map(h=>{const r=i.includes(h.id);return n.jsxs("button",{type:"button",className:A("fv-row-btn",r&&"is-done"),"aria-pressed":r,onClick:()=>p(h.id),children:[n.jsx("span",{className:"fv-ring"}),n.jsx("span",{className:"fv-ell",children:h.content})]}
1,h.id)})]})},Yn=ss.memo(({focusedTaskId:e,queue:t,onTaskFocus:s,onCompleteTask:o,onExitFocusMode:a})=>{const i=g.useCallback(()=>{try{localStorage.setItem("white-noise-playing","false"),localStorage.setItem("ambient-sound-type","off")}catch{}a()},[a]);return g.useEffect(()=>(window.addEventListener("focus-mode-complete",i),()=>window.removeEventListener("focus-mode-complete",i)),[i]),n.jsx(Kn,{queue:t,focusedTaskId:e,onTaskFocus:s,onCompleteTask:o,onExit:i})});Yn.displayName="FocusedTaskOverlay";export{Yn as FocusedTaskOverlay};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.