1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/fetchStatistics-DxgDBPFq.js","assets/index--kdl1ae9.js","assets/vendor-1kUQ7zn2.js","assets/vendor-date-en1IyhsK.js","assets/vendor-supabase-Dh2gyaRa.js","assets/vendor-motion-BX-jsy7E.js","assets/index-CQlyKjDu.css"])))=>i.map(i=>d[i]); 2import{j as e,$ as is,c as u,Z as Ys,ck as os,aD as zs,bf as Ks,cl as Qs,a4 as rs,cm as Us,cn as Vs,aB as ls,co as Xs,b8 as Zs,cp as He,bS as Js,bl as cs,aj as et,K as st,bF as tt,cq as at,M as nt}from"./vendor-1kUQ7zn2.js";import{d as ie}from"./vendor-supabase-Dh2gyaRa.js";import{c as B,u as be,D as it,a as ot,b as rt,d as lt,e as ct,f as dt,B as X,s as R,g as se,h as ut,i as mt,j as ht,k as Ge,C as ce,l as Te,m as Ne,n as xt,o as ft,p as pt,q as We,r as ye,t as le,v as gt,_ as yt,w as jt,E as vt}from"./index--kdl1ae9.js";import{m as $,A as bt}from"./vendor-motion-BX-jsy7E.js";import{p as ne,a as we,t as Nt,i as Se,s as W,d as Ye,g as wt,b as E,c as kt,h as V,e as St,f as ze}from"./focusStats-sBxcroA-.js";import{a as H,g as Y,j as de,P as Ke,D as q,f as U,Q as Mt}from"./vendor-date-en1IyhsK.js";import{R as ds,B as $t,C as Ct,X as Et,Y as Dt,T as us,L as ms,a as _t,b as hs,P as Tt,c as Ft,d as Lt}from"./vendor-charts-gGf1aRzE.js";const It=({isRefreshing:s})=>e.jsx(is,{className:B("h-4 w-4 transition-all duration-500",s&&"animate-spin text-violet-600 dark:text-violet-400")});function xs({open:s,onOpenChange:t,onSuccess:a}){const[n,r]=u.useState(!1),{toast:o}=be(),{session:l}=ie.useSessionContext(),i=async()=>{if(!l?.user?.id){o({title:"Error",description:"You must be logged in to reset statistics",variant:"destructive"});return}r(!0);try{await R.from("focus_sessions").delete().eq("user_id",l.user.id),await R.from("task_completions").update({focus_session_id:null,focus_duration_minutes:null}).eq("user_id",l.user.id).not("focus_session_id","is",null),o({title:"Focus stats reset",description:"Your focus statistics have been successfully reset"}),a&&a(),t(!1)}catch{o({title:"Reset failed",description:"There was an error resetting your statistics",variant:"destructive"})}finally{r(!1)}};return e.jsx(it,{open:s,onOpenChange:t,children:e.jsxs(ot,{className:"sm:max-w-md",children:[e.jsxs(rt,{children:[e.jsxs(lt,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(Ys,{className:"h-5 w-5"}),"Reset focus stats?"]}),e.jsx(ct,{children:"This will permanently delete all your focus session data. This action cannot be undone."})]}),e.jsxs("div",{className:"bg-destructive/10 border border-destructive/20 rounded-md p-4 my-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This will reset:"}),e.jsxs("ul",{className:"text-sm mt-2 space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"⢠All focus sessions"}),e.jsx("li",{children:"⢠Focus time and deep focus time"}),e.jsx("li",{children:"⢠Links from completed tasks to their sessions (the tasks stay completed)"})]})]}),e.jsxs(dt,{className:"gap-2 sm:gap-0",children:[e.jsx(X,{variant:"outline",onClick:()=>t(!1),disabled:n,children:"Cancel"}),e.jsx(X,{variant:"destructive",onClick:i,disabled:n,className:"gap-2",children:n?e.jsx(e.Fragment,{children:"Resettingâ¦"}):e.jsxs(e.Fragment,{children:[e.jsx(os,{className:"h-4 w-4"}),"Reset focus stats"]})})]})]})})}const fs=u.memo(({onRefresh:s,refreshing:t})=>{const[a,n]=u.useState(!1),r=se(),[o,l]=u.useState(null);return u.useEffect(()=>{r&&l(document.getElementById("mx-stats-actions"))},[r]),r?e.jsxs(e.Fragment,{children:[o&&zs.createPortal(e.jsxs(ut,{children:[e.jsx(mt,{asChild:!0,children:e.jsx("button",{type:"button",className:"mx-icon-btn","aria-label":"More",children:e.jsx(Ks,{className:"h-5 w-5","aria-hidden":!0})})}),e.jsxs(ht,{align:"end",className:"min-w-[200px]",children:[s&&e.jsxs(Ge,{className:"min-h-11 gap-3 text-[15px]",disabled:t,onSelect:()=>s(),children:[e.jsx(Qs,{className:"h-4 w-4","aria-hidden":!0})," Refresh"]}),e.jsxs(Ge,{className:"min-h-11 gap-3 text-[15px]",onSelect:()=>n(!0),children:[e.jsx(os,{className:"h-4 w-4","aria-hidden":!0})," Reset focus stats"]})]})]}),o),e.jsx(xs,{open:a,onOpenChange:n,onSuccess:s})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-2",children:[e.jsx($.h1,{className:"text-3xl font-bold tracking-tight",initial:{opacity:0,y:-10}
2,animate:{opacity:1,y:0},transition:{duration:.3},children:"Your Statistics"}),e.jsx("div",{className:"flex items-center space-x-2",children:s&&e.jsx(X,{variant:"outline",size:"icon",onClick:s,disabled:t,className:"h-10 w-10 transition-all duration-300",children:e.jsx(It,{})})})]})})});fs.displayName="StatisticsHeader";const ps=u.createContext(void 0);function Rt({children:s,value:t}){return e.jsx(ps.Provider,{value:t,children:s})}function gs(){const s=u.useContext(ps);if(s===void 0)throw new Error("useStatistics must be used within a StatisticsProvider");return s}const At=({onCancel:s})=>{const t={animate:{scale:[.98,1.02,.98],opacity:[.7,1,.7],transition:{duration:3,repeat:1/0,ease:[.4,0,.6,1]}}},a={animate:{y:[0,-5,0],transition:{duration:2.5,repeat:1/0,ease:"easeInOut"}}};return e.jsx("div",{className:"min-h-[400px] bg-background/95 backdrop-blur-sm p-8 flex items-center justify-center",children:e.jsxs($.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{duration:.5,ease:[.22,1,.36,1]},className:"relative bg-card/80 p-8 rounded-lg shadow-lg border max-w-md w-full space-y-6 backdrop-blur-sm",style:{background:"linear-gradient(109.6deg, rgba(223,234,247,1) 11.2%, rgba(244,248,252,1) 91.1%)"},children:[e.jsx($.div,{className:"absolute top-4 right-4",whileHover:{scale:1.05},whileTap:{scale:.95},children:e.jsx(X,{variant:"ghost",size:"icon",onClick:s,className:"hover:bg-destructive/10 transition-colors",children:e.jsx(rs,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsxs($.div,{className:"relative",animate:{rotate:360},transition:{duration:8,repeat:1/0,ease:"linear"},children:[e.jsx($.div,{...t,className:"h-12 w-12 border-4 border-[#9b87f5] border-t-transparent rounded-full shadow-lg"}),e.jsx($.div,{initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},transition:{delay:.2,duration:.5,ease:"easeOut"},className:"absolute inset-0 flex items-center justify-center",children:e.jsx($.div,{animate:{scale:[1,1.15,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut"},children:e.jsx(Us,{className:"h-5 w-5 text-[#8B5CF6]"})})})]}),e.jsx($.h3,{className:"text-xl font-semibold text-foreground bg-clip-text text-transparent",style:{backgroundImage:"linear-gradient(102.3deg, rgba(147,39,143,1) 5.9%, rgba(234,172,232,1) 64%, rgba(246,219,245,1) 89%)"},initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1,duration:.6,ease:[.22,1,.36,1]},children:"Analyzing Your Data"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx($.p,{className:"text-muted-foreground text-center",initial:{opacity:0}
2,animate:{opacity:1},transition:{delay:.2,duration:.6},...t,children:"Fetching and processing your task completion data..."}),e.jsxs("div",{className:"flex justify-center gap-8 py-4",children:[e.jsxs($.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.3,duration:.6},className:"flex flex-col items-center gap-2 hover:scale-105 transition-transform duration-200",...a,children:[e.jsx($.div,{animate:{scale:[1,1.12,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut",delay:.2},children:e.jsx(Vs,{className:"h-6 w-6 text-[#9b87f5]"})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Tasks"})]}),e.jsxs($.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.4,duration:.6},className:"flex flex-col items-center gap-2 hover:scale-105 transition-transform duration-200",...a,style:{animationDelay:"0.15s"},children:[e.jsx($.div,{animate:{scale:[1,1.12,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut",delay:.4},children:e.jsx(ls,{className:"h-6 w-6 text-[#D6BCFA]"})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Time"})]}),e.jsxs($.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.5,duration:.6},className:"flex flex-col items-center gap-2 hover:scale-105 transition-transform duration-200",...a,style:{animationDelay:"0.3s"},children:[e.jsx($.div,{animate:{scale:[1,1.12,1]},transition:{duration:2,repeat:1/0,ease:"easeInOut",delay:.6},children:e.jsx(Xs,{className:"h-6 w-6 text-[#8B5CF6]"})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Trends"})]})]}),e.jsx("div",{className:"relative h-2 bg-muted rounded-full overflow-hidden shadow-inner",children:e.jsx($.div,{className:"absolute inset-y-0 left-0 bg-gradient-to-r from-[#9b87f5] to-[#8B5CF6]",initial:{width:"0%"},animate:{width:["0%","35%","65%","85%","92%","97%","98%","99%"],transition:{duration:8,ease:"easeInOut",times:[0,.1,.3,.5,.7,.8,.9,1]}}})}),e.jsx($.p,{className:"text-sm text-center text-muted-foreground",initial:{opacity:0}
2,animate:{opacity:1},transition:{delay:.6,duration:.6},...t,style:{animationDelay:"0.5s"},children:"This might take a moment. Feel free to cancel if needed."})]})]})]})})},$e=u.memo(({percentage:s,color:t})=>{const a=Math.max(0,Math.min(100,s)),n=Math.max(a,2);return e.jsx("div",{className:"mt-4 h-2 rounded-full bg-muted/30 overflow-hidden",children:e.jsx($.div,{className:"h-full rounded-full transition-all duration-300 group-hover:opacity-80",style:{background:t,opacity:.9},initial:{width:0},animate:{width:`${n}%`},transition:{duration:.8,ease:"easeOut"}})})});$e.displayName="TaskProgressIndicator";function je({d:s,className:t}){return s?e.jsx("p",{className:B("sts-delta",s.up&&"is-up",t),children:s.text}):null}function Qe({values:s,color:t,width:a=96,height:n=28,domainMin:r,domainMax:o,className:l,ariaLabel:i}){const c=u.useMemo(()=>`sparkline-gradient-${Math.random().toString(36).slice(2)}`,[]),{path:x,fillPath:d,lastPoint:p}=u.useMemo(()=>{if(s.length===0)return{path:"",fillPath:"",lastPoint:null};if(s.length===1){const C=n/2;return{path:`M 0 ${C} L ${a} ${C}`,fillPath:"",lastPoint:{x:a,y:C}}}const v=r??Math.min(...s),w=(o??Math.max(...s))-v||1,S=2,y=n-S*2,k=s.length>1?a/(s.length-1):a,T=s.map((C,D)=>{const _=D*k,M=n-S-(C-v)/w*y;return{x:_,y:M}}),L=T.map((C,D)=>`${D===0?"M":"L"} ${C.x.toFixed(2)} ${C.y.toFixed(2)}`).join(" "),A=`${L} L ${T[T.length-1].x.toFixed(2)} ${n} L ${T[0].x.toFixed(2)} ${n} Z`;return{path:L,fillPath:A,lastPoint:T[T.length-1]}},[s,a,n,r,o]);return x?e.jsxs("svg",{width:a,height:n,viewBox:`0 0 ${a} ${n}`,className:B("block",l),role:"img","aria-label":i,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:c,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:t,stopOpacity:"0.28"}),e.jsx("stop",{offset:"100%",stopColor:t,stopOpacity:"0"})]})}),e.jsx("path",{d,fill:`url(#${c})`}),e.jsx("path",{d:x,fill:"none",stroke:t,strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",opacity:.9}),p&&e.jsx("circle",{cx:p.x,cy:p.y,r:2,fill:t})]}):e.jsx("div",{className:B("h-[28px] w-[96px]",l),role:"img","aria-label":i??"No data"})}
2const ys=u.memo(({title:s,value:t,percentage:a,color:n,subtitle:r,delta:o=null,sparkValues:l,sparkMax:i,sparkLabel:c,compact:x=!1})=>{const d=Array.isArray(l)&&l.length>1;return x?e.jsxs("div",{className:"mx-stat-tile is-quadrant",style:{"--tile":n},children:[e.jsx("p",{className:"mx-stat-label",children:e.jsx("span",{children:s})}),e.jsxs("p",{className:"mx-stat-value",children:[e.jsx("span",{style:{color:n},children:t.toLocaleString()}),e.jsx("span",{className:"mx-stat-sub",children:r||`${a.toFixed(1)}%`})]}),e.jsx(je,{d:o}),e.jsx($e,{percentage:a,color:n}),d&&e.jsx(Qe,{values:l,color:n,width:120,height:22,domainMin:0,domainMax:i&&i>0?i:void 0,ariaLabel:c??`${s} completions trend`})]}):e.jsx($.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{duration:.5},className:"h-full",children:e.jsxs(ce,{className:"h-full bg-card/30 backdrop-blur-xl border-border/30 overflow-hidden relative group",children:[e.jsx("div",{className:"absolute inset-0 opacity-5 transition-opacity duration-300 group-hover:opacity-10",style:{background:n}}),e.jsx("div",{className:"absolute h-1 top-0 left-0 right-0 opacity-70 transition-all duration-300 group-hover:opacity-100",style:{background:n}}),e.jsx(Te,{className:"pb-2",children:e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:s})}),e.jsx(Ne,{children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs($.div,{className:"flex items-baseline gap-2",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5,ease:"easeOut"},children:[e.jsx("span",{className:"text-4xl font-bold tracking-tight",style:{color:n},children:t.toLocaleString()}),e.jsx("span",{className:"text-sm text-muted-foreground",children:r||`${a.toFixed(1)}%`})]}),e.jsx(je,{d:o}
2),e.jsx($e,{percentage:a,color:n}),d&&e.jsx("div",{className:"mt-1 flex items-center justify-end","aria-hidden":!1,children:e.jsx(Qe,{values:l,color:n,width:120,height:26,domainMin:0,domainMax:i&&i>0?i:void 0,ariaLabel:c??`${s} completions trend`})})]})})]})})});ys.displayName="StatCard";const Ot={"Do First":"#ef4444",Schedule:"#3b82f6",Delegate:"#f97316",Backlog:"#8a8580"},Ue=["Do First","Schedule","Delegate","Backlog"],js=()=>({"Do First":0,Schedule:0,Delegate:0,Backlog:0}),Pt=s=>xt(s??void 0),ve=(s,t,a)=>{const n=js();let r=0;const o=t.getTime(),l=a.getTime();for(const i of s){const c=Date.parse(i.completed_at);c>=o&&c<l&&(n[Pt(i.quadrant)]++,r++)}return{counts:n,total:r}},Ve=(s,t,a,n)=>{if(!n)return 0;const r=s>H(n)?s:H(n),o=t<H(a)?t:H(a);return Math.max(0,de(o,r)+1)},Bt=(s,t,a,n,r)=>{const o=[];if(s==="day"){for(let i=0;i<24;i++){const c=Ke(t,i),x=Ke(t,i+1),{counts:d,total:p}=ve(n,c,x);o.push({start:c,label:q(c,"HH"),title:`${q(c,"HH:mm")}â${i===23?"24:00":q(x,"HH:mm")}`,isNow:r>=c&&r<x,isFuture:c>r,counts:d,total:p})}return o}const l=H(r);for(let i=t;i<=a;i=Y(i,1)){const{counts:c,total:x}=ve(n,i,Y(i,1));o.push({start:i,label:s==="week"?q(i,"EEE d"):q(i,"d"),title:q(i,"EEE d MMM"),isNow:U(i,l),isFuture:i>l,counts:c,total:x})}return o},qt=(s,t,a,n,r=new Date)=>{const o=H(r),[l,i]=ne(s,t,o),c=Y(i,1),{counts:x,total:d}=ve(a,l,c),p=we(s,l,i,o,t,n),v=ve(a,p.a,Y(p.b,1)),b=js();Ue.forEach(y=>{b[y]=v.counts[y]/p.divide});const w=Ue.map(y=>({name:y,value:x[y],percentage:d?x[y]/d*100:0,color:Ot[y]})).sort((y,k)=>k.value-y.value),S=!!n&&n<l;return{range:s,a:l,b:i,buckets:Bt(s,l,i,a,r),totals:w,total:d,days:Ve(l,i,o,n),prev:p,prevByQuadrant:b,prevTotal:v.total/p.divide,prevDays:Ve(p.a,p.b,o,n),hasBase:S,isFirst:!!n&&n>=l&&n<c}},vs=(s,t=0)=>String(Number(s.toFixed(t))),ge=(s,t,a,n=0)=>{const r=Number(s.toFixed(n)),o=Number(t.toFixed(n));if(!r&&!o)return null;if(!o)return{text:a.none,up:!1};const l=Number((r-o).toFixed(n));return l===0?{text:`Same as ${a.vs.replace(/^vs /,"")}`,up:!1}:{text:`${l>0?"+":"â"}${vs(Math.abs(l),n)} ${a.vs}`,up:l>0}},Ht=(s,t,a,n,r)=>{const o=(c,x)=>q(c,x),l=s==="day"?t===0?"Today":t===-1?"Yesterday":o(a,"EEE d MMM"):s==="week"?t===0?"This week":t===-1?"Last week":`${o(a,"d MMM")} â ${o(n,"d MMM")}`:o(a,"MMMM yyyy"),i=s==="day"?o(a,"EEEE d MMMM"):s==="week"?`Mon ${o(a,"d MMM")} â Sun ${o(n,"d MMM")}`:o(a,"MMMM yyyy")+(n>r?`, to ${o(r,"d MMM")}`:"");return{short:l,long:i}},Gt=(s,t,a=new Date)=>{const n=H(a),[r,o]=ne(s,t,n),l=we(s,r,o,n,t,null),i=l.a<r?l.a:r,c=Y(o>n?n:o,1);return{a:r,b:o,from:i,to:c}},bs=u.memo(({summary:s})=>{const{range:t,totals:a,buckets:n,prev:r,prevByQuadrant:o,hasBase:l}=s,i=se(),c=u.useMemo(()=>n.filter(d=>!d.isFuture),[n]),x=u.useMemo(()=>{let d=0;for(const p of c)for(const v of Object.values(p.counts))v>d&&(d=v);return d},[c]);return e.jsx("div",{className:i?"mx-stat-tiles":"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6",children:a.map(d=>e.jsx(ys,{title:d.name,value:d.value,percentage:d.percentage,color:d.color,delta:l?ge(d.value,o[d.name],r,t==="day"?1:0):null,sparkValues:c.map(p=>p.counts[d.name]),sparkMax:x,sparkLabel:`${d.name} completions ${t==="day"?"by hour":"per day"}`,compact:i},d.name))})});bs.displayName="StatCardsGrid";const Wt=({active:s,payload:t})=>{if(!s||!t?.length)return null;const a=t[0].payload;if(!a||a._isFuture)return null;const n=t.reduce((l,i)=>l+(i.value||0),0),r=[...t].sort((l,i)=>i.value-l.value),o={"Do First":"#ef4444",Schedule:"#3b82f6",Delegate:"#fb923c",Backlog:"#8a8580"};return e.jsxs("div",{className:"rounded-lg border border-border/60 bg-popover/95 backdrop-blur-md shadow-xl px-3 py-2.5 min-w-[180px]",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:a.title??a.label}),a._isNow&&e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wider text-muted-foreground",children:a._nowLabel??"Today"})]}),e.jsx("div",{className:"mt-2 space-y-1",children:r.map(({name:l,value:i,color:c})=>e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{"aria-hidden":!0,
2className:"block h-1.5 w-1.5 rounded-full shrink-0",style:{background:o[l]??c}}),e.jsx("span",{className:"text-muted-foreground truncate",children:l})]}),e.jsx("span",{className:"font-medium tabular-nums",style:{opacity:i===0?.4:1},children:i})]},l))}),e.jsxs("div",{className:"mt-2 pt-2 border-t border-border/40 flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total"}),e.jsx("span",{className:"font-semibold tabular-nums",children:n})]})]})},Xe=["Do First","Schedule","Delegate","Backlog"],Me=s=>`bar-grad-${s.toLowerCase().replace(/\s+/g,"-")}`,Yt=({buckets:s,range:t,colors:a,onPick:n})=>{const r=se(),o=u.useMemo(()=>{const l=s.findIndex(i=>i.isNow);return s.map((i,c)=>{let x=!0;if(t==="day"&&(x=!r||i.isNow||c%3===0&&!(l>=0&&Math.abs(c-l)<=1)),t==="month"){const d=i.start.getDate();x=i.isNow||(!r||[1,8,15,22,29].includes(d))&&!(r&&l>=0&&Math.abs(c-l)<=2)}return{label:i.label,title:i.title,start:i.start,_isNow:i.isNow,_isFuture:i.isFuture,_isWeekend:t!=="day"&&Mt(i.start),_show:x,_twoLine:r&&t==="week",_nowLabel:t==="day"?"Now":"Today",...i.counts}})},[s,t,r]);return e.jsx("div",{className:"h-[400px]",children:e.jsx(ds,{width:"100%",height:"100%",children:e.jsxs($t,{data:o,margin:{top:16,right:12,left:-8,bottom:0},barCategoryGap:t==="week"?"28%":"18%",barGap:2,style:n?{cursor:"pointer"}:void 0,onClick:l=>{const i=l?.activeTooltipIndex;if(!n||typeof i!="number")return;const c=o[i];c&&!c._isFuture&&n(c.start)},children:[e.jsx("defs",{children:Xe.map(l=>{const i=a[l];return e.jsxs("linearGradient",{id:Me(l),x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:i,stopOpacity:1}),e.jsx("stop",{offset:"100%",stopColor:i,stopOpacity:.72})]},l)})}),e.jsx(Ct,{stroke:"currentColor",strokeOpacity:.07,strokeDasharray:"3 4",vertical:!1}),e.jsx(Et,{dataKey:"label",tick:l=>e.jsx(zt,{...l,data:o}),tickLine:!1,axisLine:{stroke:"currentColor",strokeOpacity:.08},dy:6,interval:0,height:r&&t==="week"?46:30}),e.jsx(Dt,{allowDecimals:!1,tick:{fill:"currentColor",fontSize:11,fillOpacity:.55},tickLine:!1,axisLine:!1,width:32}),e.jsx(us,{cursor:{fill:"currentColor",fillOpacity:.04},content:e.jsx(Wt,{})}),e.jsx(ms,{content:e.jsx(Kt,{colors:a}),verticalAlign:"bottom",height:32}),Xe.map(l=>e.jsx(_t,{dataKey:l,stackId:t==="week"?void 0:"q",fill:`url(#${Me(l)})`,radius:t==="week"?[4,4,0,0]:[2,2,0,0],maxBarSize:t==="week"?28:16,isAnimationActive:!0,animationDuration:500,children:o.map((i,c)=>e.jsx(hs,{fill:`url(#${Me(l)})`,stroke:i._isNow?a[l]:void 0,strokeOpacity:i._isNow?.55:0,strokeWidth:i._isNow?1:0},`${l}-${c}`))},l))]})})})};function zt({x:s=0,y:t=0,index:a=0,data:n}){const r=n[a];return!r||!r._show?null:e.jsx("g",{transform:`translate(${s},${t})`,children:e.jsx("text",{x:0,y:0,dy:12,textAnchor:"middle",fill:"currentColor",fillOpacity:r._isNow?.95:r._isFuture?.3:r._isWeekend?.45:.6,fontSize:11,fontWeight:r._isNow?600:400,children:r._twoLine?r.label.split(" ").map((o,l)=>e.jsx("tspan",{x:0,dy:l===0?12:14,children:o},l)):r.label})})}function Kt({payload:s,colors:t}){return s?e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-x-4 gap-y-1.5 pt-2",children:s.map(a=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{"aria-hidden":!0,className:"block h-1.5 w-1.5 rounded-full",style:{background:t[a.value]??"#888"}}),e.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:a.value})]},a.value))}):null}const Qt=({summary:s,colors:t,onPickDay:a})=>{const n=s.range==="day",r=s.total===0?"":n?`${s.total} ${s.total===1?"task":"tasks"}`:"Select a day to see it by hour";return e.jsx($.div,{className:"col-span-2 h-full",initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5},children:e.jsxs(ce,{className:"h-full bg-card/30 backdrop-blur-xl border-border/50",children:[e.jsx(Te,{className:"pb-2",children:e.jsxs("div",{className:"sts-chart-h",children:[e.jsx("h3",{children:n?"Completions by hour":"Completions per day"}),e.jsx("span",{children:r})]})}),e.jsxs(Ne,{className:"relative",children:[e.jsx(Yt,{buckets:s.buckets,range:s.range,colors:t,onPick:n?void 0:a},s.range),s.total===0&&e.jsx("p",{className:"pointer-events-none absolute inset-x-0 top-[40%] px-6 text-center text-sm text-muted-foreground",children:"No completed tasks in this period."})]})]})})},Ce={"Do First":["rgba(239, 68, 68, 0.95)","rgba(185, 43, 39, 0.95)"],Schedule:["rgba(59, 130, 246, 0.95)","rgba(37, 99, 235, 0.95)"],Delegate:["rgba(251, 146, 60, 0.95)","rgba(234, 108, 20, 0.95)"],Backlog:["rgba(138, 133, 128, 0.95)","rgba(104, 100, 96, 0.95)"]},fe=Math.PI/180,Ze=s=>`pie-grad-${s.toLowerCase().replace(/\s+/g,"-")}`,Ut=({cx:s,cy:t,midAngle:a,innerRadius:n,outerRadius:r,percent:o})=>{if(o<.02)return null;const l=n+6,i=n+(r-n)*1.18,c=s+l*Math.cos(-a*fe),x=t+l*Math.sin(-a*fe),d=s+i*Math.cos(-a*fe),p=t+i*Math.sin(-a*fe);return e.jsxs("g",{children:[e.jsx("path",{d:`M${c},${x}L${d},${p}`,stroke:"currentColor",strokeWidth:.6,fill:"none",opacity:.35}),e.jsx("text",{x:d+(d>s?4:-4),y:p,fill:"currentColor",textAnchor:d>s?"start":"end",dominantBaseline:"middle",className:"text-[11px] font-medium tabular-nums",fillOpacity:.85,children:`${(o*100).toFixed(0)}%`})]})},Ee=u.memo(({data:s,total:t})=>e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-x-4 gap-y-2 pt-5 px-2",children:s.map(a=>e.jsxs($.div,{className:"flex items-center gap-1.5",whileHover:{scale:1.04},transition:{type:"spring",stiffness:400,damping:14}
2,children:[e.jsx("span",{"aria-hidden":!0,className:"block h-2 w-2 rounded-full",style:{background:`linear-gradient(180deg, ${Ce[a.name]?.[0]??"#888"}, ${Ce[a.name]?.[1]??"#666"})`}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a.name}),e.jsx("span",{className:"text-xs font-semibold tabular-nums",children:a.value}),e.jsx("span",{className:"text-[10px] text-muted-foreground tabular-nums",children:t>0?`· ${(a.value/t*100).toFixed(0)}%`:""})]},a.name))}));Ee.displayName="RichLegend";const Ns=u.memo(({data:s})=>{const t=se(),{processedData:a,total:n}=u.useMemo(()=>{const o=s.filter(c=>c.value>0),l=o.reduce((c,x)=>c+x.value,0);return{processedData:o.map(c=>({...c,percentage:l>0?(c.value/l*100).toFixed(1):"0"})).sort((c,x)=>x.value-c.value),total:l}},[s]),r=a.length>0;return e.jsx($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5},className:"h-full",children:e.jsxs(ce,{className:"h-full bg-card/30 backdrop-blur-xl border-border/50 hover:shadow-lg transition-all duration-300",children:[e.jsx(Te,{className:"pb-2",children:e.jsxs(ft,{className:"text-base font-semibold tracking-tight",children:["Task distribution",e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:"Completed"})]})}),e.jsxs(Ne,{className:t?"pt-2 relative":"h-[400px] pt-2 relative",children:[!r&&e.jsx("p",{className:"absolute inset-0 flex items-center justify-center px-6 text-center text-sm text-muted-foreground",children:"No completed tasks in this period."}),e.jsx(ds,{width:"100%",height:t?220:"100%",children:e.jsxs(Tt,{children:[e.jsx("defs",{children:Object.entries(Ce).map(([o,[l,i]])=>e.jsxs("linearGradient",{id:Ze(o),x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:l}),e.jsx("stop",{offset:"100%",stopColor:i})]},o))}),e.jsxs(Ft,{data:a,cx:"50%",cy:t?"50%":"45%",innerRadius:t?"64%":78,outerRadius:t?"92%":118,paddingAngle:3,dataKey:"value",labelLine:!1,label:t?!1:Ut,isAnimationActive:!0,animationBegin:0,animationDuration:700,animationEasing:"ease-out",stroke:"hsl(var(--background))",strokeWidth:2,children:[a.map(o=>e.jsx(hs,{fill:`url(#${Ze(o.name)})`,className:"transition-opacity duration-200 hover:opacity-90"},`cell-${o.name}`)),r&&e.jsx(Lt,{position:"center",content:({viewBox:o})=>{if(!o||!("cx"in o)||!("cy"in o))return null;const{cx:l,cy:i}=o;return e.jsx("text",{x:l,y:i,textAnchor:"middle",dy:"0.36em",className:"fill-foreground",style:{fontSize:t?34:42,fontWeight:600,fontVariantNumeric:"tabular-nums",letterSpacing:"-0.02em"},children:n})}})]}),e.jsx(us,{contentStyle:{backgroundColor:"hsl(var(--popover) / 0.95)",border:"1px solid hsl(var(--border) / 0.6)",borderRadius:"8px",padding:"8px 12px",backdropFilter:"blur(8px)",fontSize:"12px"},formatter:(o,l)=>[`${o} · ${n>0?(o/n*100).toFixed(1):0}%`,l]}),!t&&e.jsx(ms,{content:()=>e.jsx(Ee,{data:a,total:n})})]})}),t&&e.jsx(Ee,{data:a,total:n})]})]})})});Ns.displayName="TaskPieChart";const Vt=s=>s===0?"12am":s===12?"12pm":s>12?`${s-12}pm`:`${s}am`,ws=u.memo(({summary:s,heatmapData:t=[]})=>{const{data:a}=pt(),n=se(),r=a?.current??0,{range:o,a:l,totals:i,total:c,days:x,prev:d,prevByQuadrant:p,prevTotal:v,prevDays:b,hasBase:w,isFirst:S}=s,y=o==="day",k=u.useMemo(()=>{const h=Array(24).fill(0);t.forEach(({hour:N,intensity:O})=>{const G=Math.floor(O/60),Q=O%60;for(let Z=0;Z<G&&N+Z<24;Z++)h[N+Z]+=60;Q>0&&N+G<24&&(h[N+G]+=Q)});let j=0,P=0;return h.forEach((N,O)=>{N>j&&(j=N,P=O)}),j>0?Vt(P):"Not enough data"},[t]),T=i[0],L=c>0?T.value:0,A=c>0?T.name:"Not enough data",C=y?1:0,D=w&&c>
20?ge(L,p[T.name],d,C):null,_=x>0?c/x:0,M=b>0?v/b:0,F=S?{text:`Your first ${o} of tasks`,up:!1}:null,z=w?y?ge(c,v,d,1):ge(_,M,d,1):F,K=y&&U(l,new Date),f=[{title:"Most used quadrant",value:A,subtitle:c>0?`${L} ${L===1?"task":"tasks"} completed`:"No completed tasks in this period",icon:e.jsx(Zs,{className:"h-5 w-5 text-violet-500"}),color:"from-violet-500/20 to-violet-500/5",delta:D,extra:null},y?{title:"Tasks completed",value:String(c),subtitle:K?"Completed today":"Completed that day",icon:e.jsx(He,{className:"h-5 w-5 text-emerald-500"}),color:"from-emerald-500/20 to-emerald-500/5",delta:z,extra:null}:{title:"Average daily tasks",value:vs(_,1),subtitle:x>0?`Tasks per day · ${c} in ${x} ${x===1?"day":"days"}`:"Tasks per day",icon:e.jsx(He,{className:"h-5 w-5 text-emerald-500"}),color:"from-emerald-500/20 to-emerald-500/5",delta:z,extra:null},{title:"Peak productivity",value:k,subtitle:"Most productive hour",icon:e.jsx(ls,{className:"h-5 w-5 text-sky-500"}),color:"from-sky-500/20 to-sky-500/5",delta:null,extra:null},{title:"Current streak",value:r.toString(),subtitle:`${r===1?"day":"days"} of continuous activity`,icon:e.jsx(Js,{className:"h-5 w-5 text-amber-500"}),color:"from-amber-500/20 to-amber-500/5",delta:null,extra:a?e.jsxs("div",{className:"mt-3 space-y-1.5",children:[e.jsx("div",{className:"flex items-end gap-1.5",children:a.last7.map((h,j)=>e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("span",{className:B("h-2.5 w-2.5 rounded-full transition-colors",h.active?"bg-amber-500":"bg-muted-foreground/20",h.isToday&&"ring-2 ring-amber-500/40 ring-offset-1 ring-offset-background")}),e.jsx("span",{className:n?"text-[12px] leading-none text-muted-foreground/70":"text-[9px] leading-none text-muted-foreground/70",children:h.label})]},j))}),a.longest>1&&e.jsxs("p",{className:n?"text-[12px] text-muted-foreground":"text-[11px] text-muted-foreground",children:["Longest: ",a.longest," days"]})]}):null}];return n?e.jsx("div",{className:"mx-stat-tiles",children:f.map(h=>e.jsxs("div",{className:`mx-stat-tile bg-gradient-to-br ${h.color}`,children:[e.jsxs("p",{className:"mx-stat-label",children:[e.jsx("span",{children:h.title}),e.jsx("span",{className:"mx-stat-icon","aria-hidden":!0,children:h.icon})]}),e.jsx("p",{className:B("mx-stat-value",h.value.length>8&&"is-text"),children:h.value}),e.jsx("p",{className:"mx-stat-sub",children:h.subtitle}),e.jsx(je,{d:h.delta}),h.extra]},h.title))}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:f.map((h,j)=>e.jsx($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5,delay:.1*j},className:"h-full",children:e.jsxs(ce,{className:`h-full bg-gradient-to-br ${h.color} backdrop-blur-xl border-border/30 overflow-hidden relative p-6 transition-shadow duration-300`,children:[e.jsx("div",{className:"absolute top-2 right-2 opacity-70",children:h.icon}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:h.title}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-2xl font-bold tabular-nums",children:h.value}),e.jsx("span",{className:"text-sm text-muted-foreground",children:h.subtitle}),e.jsx(je,{d:h.delta,className:"mt-2"}),h.extra]})]})]})},h.title))})});ws.displayName="TaskOverview";const Je=[["day","Day"],["week","Week"],["month","Month"]],ks=({title:s,range:t,offset:a,earliest:n,onRange:r,onStep:o,className:l})=>{const i=H(new Date),[c,x]=ne(t,a,i),{short:d,long:p}=Ht(t,a,c,x,i),[,v]=ne(t,a-1,i),b=!!n&&v>=H(n);return e.jsxs("div",{className:B("fst-head sts-head",l),children:[e.jsxs("div",{className:"fst-title",children:[e.jsx("h2",{children:s}),e.jsx("span",{children:p})]}),e.jsxs("div",{className:"fst-period",children:[e.jsxs("div",{className:"fst-seg",role:"group","aria-label":"Period",children:[e.jsx("span",{className:"fst-seg-pill","aria-hidden":!0,style:{transform:`translateX(calc(${Je.findIndex(([w])=>w===t)} * (100% + 2px)))`}}),Je.map(([w,S])=>e.jsx("button",{type:"button","aria-pressed":t===w,onClick:()=>r(w),children:S},w))]}),e.jsxs("div",{className:"fst-step",children:[e.jsx("button",{type:"button",className:"fst-icon",title:"Previous","aria-label":"Previous period",disabled:!b,onClick:()=>o(-1),children:e.jsx(cs,{})}),e.jsx("span",{"aria-live":"polite",children:d}),e.jsx("button",{type:"button",className:"fst-icon",title:"Next","aria-label":"Next period",disabled:a>=0,onClick:()=>o(1),children:e.jsx(et,{})})]})]})]})},Ss=u.memo(({colors:s})=>{const{period:t,earliest:a,summary:n,heatmapData:r,stale:o}=gs();return e.jsxs("section",{className:"sts-section","aria-label":"Task statistics",children:[e.jsx(ks,{title:"Tasks",range:t.range,offset:t.offset,earliest:a,onRange:t.pickRange,onStep:t.step}),e.jsxs("div",{className:B("sts-body space-y-8",o&&"is-stale"),children:[e.jsx(ws,{summary:n,heatmapData:r}),e.jsx($.div,{initial:{opacity:0,y:20}
2,animate:{opacity:1,y:0},transition:{delay:.2,duration:.5},children:e.jsx(bs,{summary:n})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-12 gap-6",children:[e.jsx($.div,{className:"md:col-span-8",initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{delay:.4,duration:.5},children:e.jsx(Qt,{summary:n,colors:s,onPickDay:t.openDay})}),e.jsx($.div,{className:"md:col-span-4",initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{delay:.5,duration:.5},children:e.jsx(Ns,{data:n.totals})})]})]})]})});Ss.displayName="TaskCompletionSection";const Xt=(s,t)=>{const{session:a}=ie.useSessionContext(),n=a?.user?.id,[r,o]=u.useState([]),[l,i]=u.useState(null),[c,x]=u.useState(!1),d=u.useRef(0),p=u.useCallback(async()=>{if(!n)return;const v=++d.current,b=H(new Date),[w,S]=ne(s,t,b),y=we(s,w,S,b),k=new Date(Math.min(w.getTime(),y.a.getTime(),Y(b,-29).getTime())),T=Y(S>b?b:S,1);try{const[{data:L,error:A},{data:C}]=await Promise.all([R.from("focus_sessions").select("*").eq("user_id",n).gte("started_at",k.toISOString()).lt("started_at",T.toISOString()).order("started_at",{ascending:!1}),R.from("focus_sessions").select("started_at").eq("user_id",n).gt("duration_minutes",1).order("started_at",{ascending:!0}).limit(1)]);if(A)throw A;const D=(L??[]).map(M=>M.id);let _=[];for(let M=0;M<D.length;M+=150){const{data:F}=await R.from("task_completions").select("focus_session_id, task_content, quadrant, task_labels").in("focus_session_id",D.slice(M,M+150));_=_.concat(F??[])}if(v!==d.current)return;o(Nt(L??[],_)),i(C?.[0]?.started_at?new Date(C[0].started_at):null)}catch{}finally{v===d.current&&x(!0)}},[n,s,t]);return u.useEffect(()=>{p()},[p]),u.useEffect(()=>{const v=()=>{p()};return window.addEventListener("focus-session-saved",v),()=>window.removeEventListener("focus-session-saved",v)},[p]),{sessions:r,firstStart:l,loaded:c,reload:p}},pe="daily_focus_time",Zt=()=>{const{session:s}=ie.useSessionContext(),t=s?.user?.id,[a,n]=u.useState(0);u.useEffect(()=>{if(!t)return;let o=!0;return R.from("user_goals").select("target_value").eq("user_id",t).eq("goal_type",pe).limit(1).then(({data:l})=>{o&&n(l?.[0]?.target_value??0)}),()=>{o=!1}},[t]);const r=u.useCallback(async o=>{if(!t)return;const l=a;n(o);try{const{data:i}=await R.from("user_goals").select("id").eq("user_id",t).eq("goal_type",pe);if(o)if(i?.length){const{error:c}=await R.from("user_goals").update({target_value:o,updated_at:new Date().toISOString()}).eq("id",i[0].id);if(c)throw c}else{const{error:c}=await R.from("user_goals").insert({user_id:t,goal_type:pe,target_value:o});if(c)throw c}else if(i?.length){const{error:c}=await R.from("user_goals").delete().eq("user_id",t).eq("goal_type",pe);if(c)throw c}}catch{n(l)}},[t,a]);return{goal:a,setGoal:r}},Jt={do:"#ef4444",schedule:"#3b82f6",delegate:"#fb923c",backlog:"#8a8580"},ea=[["No goal",0],["1h",60],["1h 30m",90],["2h",120],["3h",180],["4h",240]],es=8,sa=5e3,ae=(s,t)=>q(s,t),ss=({m:s})=>{const t=Math.round(s);if(t<60)return e.jsxs(e.Fragment,{children:[e.jsx(le,{value:t}),"m"]});const a=Math.floor(t/60),n=t%60;return e.jsxs(e.Fragment,{children:[e.jsx(le,{value:a}
2),"h",n?e.jsxs(e.Fragment,{children:[" ",n<10&&"0",e.jsx(le,{value:n}),"m"]}):null]})},ta=()=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:e.jsx("path",{d:"M3 5h18l-7 8v6l-4 2v-8z"})}),aa=()=>e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M3 6h18"}),e.jsx("path",{d:"M8 6V4h8v2"}),e.jsx("path",{d:"M6 6l1 14h10l1-14"})]}),na=({period:s,earliest:t,onFirstStart:a})=>{const n=se(),{range:r,offset:o}=s,{sessions:l,firstStart:i,loaded:c,reload:x}=Xt(r,o);u.useEffect(()=>{a?.(i)},[i?.getTime()]),u.useEffect(()=>{k(null),S(!1)},[r,o]);const{goal:d,setGoal:p}=Zt(),[v,b]=u.useState(!1),[w,S]=u.useState(!1),[y,k]=u.useState(null),[T,L]=u.useState(null),[A,C]=u.useState(null),[D,_]=u.useState([]),[M,F]=u.useState(null),[z,K]=u.useState(!1),f=H(new Date),[h,j]=ne(r,o,f),P=u.useMemo(()=>l.filter(m=>!D.includes(m.id)),[l,D]),N=Se(P,h,j),O=W(N,"focus"),G=W(N,"deep"),Q=u.useMemo(()=>{const m=[];for(let g=h;g<=j;g=Y(g,1))m.push(g);return m},[h.getTime(),j.getTime()]),Z=m=>{const g=N.filter(I=>U(I.start,m));return{f:W(g,"focus"),dp:W(g,"deep"),n:g.length}},Fe=o===0,te=we(r,h,j,f,o,i),Le=Se(P,te.a,te.b),Ie=!!i&&i<h,Ds=!!i&&i>=h&&i<Y(j,1),_s=Ie?Ye(O,W(Le,"focus")/te.divide,te):Ds?{text:`Your first ${r} of focus`,up:!1}:null,Ts=Ie?Ye(G,W(Le,"deep")/te.divide,te):null,ue=N.reduce((m,g)=>m+g.tasks.length,0),Fs=N.reduce((m,g)=>Math.max(m,g.focus),0),ke=N.filter(m=>m.deep>0).length,Ls=wt({range:r,offset:o,goal:d,perDay:m=>Z(m).f,a:h,b:j,today:f,firstStart:i}),Is=t??i,oe=u.useCallback(async m=>{try{await R.from("task_completions").update({focus_session_id:null}).eq("focus_session_id",m.id);const{error:g}=await R.from("focus_sessions").delete().eq("id",m.id);if(g)throw g;x()}catch{_(I=>I.filter(ee=>ee!==m.id)),C(m.id),st.error("Couldnât delete the session. Try again.")}},[x]),re=u.useRef(M);re.current=M;const me=u.useRef();u.useEffect(()=>{if(M)return me.current=window.setTimeout(()=>{F(null),oe(M.s)},Math.max(0,M.until-Date.now())),()=>window.clearTimeout(me.current)},[M,oe]),u.useEffect(()=>{const m=()=>{const I=re.current;I&&(re.current=null,oe(I.s))},g=()=>{document.visibilityState==="hidden"&&(m(),F(null))};return document.addEventListener("visibilitychange",g),()=>{document.removeEventListener("visibilitychange",g),m()}},[oe]);const Rs=m=>{k(null),L(m.id),window.setTimeout(()=>{const g=re.current;g&&(window.clearTimeout(me.current),oe(g.s)),_(I=>[...I,m.id]),L(null),F({s:m,until:Date.now()+sa})},300)},As=()=>{const m=re.current;m&&(window.clearTimeout(me.current),F(null),_(g=>g.filter(I=>I!==m.s.id)),C(m.s.id))};u.useEffect(()=>{if(!A)return;const m=window.setTimeout(()=>C(null),260);return()=>window.clearTimeout(m)},[A]);const[J,Os]=u.useState(()=>We());u.useEffect(()=>{if(!J)return;const m=window.setInterval(()=>Os(We()),1e3);return()=>window.clearInterval(m)},[!!J]);const Ps=!!J&&h<=f&&j>=f,he=[...N].sort((m,g)=>g.start.getTime()-m.start.getTime()),Bs=w?he:he.slice(0,es),xe=[];Bs.forEach(m=>{const g=ae(m.start,"yyyy-MM-dd");let I=xe.find(ee=>ee.key===g);if(!I){const ee=ae(m.start,"EEE d MMM"),qe=de(f,m.start);I={key:g,label:qe===0?`Today · ${ee}`:qe===1?`Yesterday · ${ee}`:ee,rows:[],total:0},xe.push(I)}I.rows.push(m)}),xe.forEach(m=>{m.total=W(N.filter(g=>ae(g.start,"yyyy-MM-dd")===m.key),"focus")});const Re=W(N,"paused"),qs=N.length?`${N.length} ${N.length===1?"session":"sessions"} · ${Re?`${E(Re)} paused`:"no pauses"}`:"No sessions",Hs=Se(P,Y(f,-29),f),Ae=kt(Hs),Gs=s.openDay,Oe=m=>e.jsx("button",{type:"button",className:"fst-link",onClick:()=>b(g=>!g),"aria-expanded":v,children:m}),Ws=[{l:"Focus time",v:e.jsx(ss,{m:O}),act:d?Oe("Change"):null,s1:d?Ls:Oe("Set a daily goal"),s2:_s},{l:"Deep focus",deep:!0,v:e.jsx(ss,{m:G}),s1:O?G?`${Math.round(G/O*100)}% of focus time`:`No ${ye}m+ stretch`:Fe&&!i?"No focus yet":"No focus",s2:Ts},{l:"Sessions",v:e.jsx(le,{value:N.length}),s1:N.length?N.length===1?`${E(O)} long`:`Avg ${E(O/N.length)} · longest ${E(Fs)}`:"No sessions",s2:N.length?N.length===1?{text:ke?"Reached deep focus":"Didnât reach deep focus",up:!1}:{text:ke?`${ke} of ${N.length} reached deep focus`:"None reached deep focus",up:!1}:null},{l:"Completed in focus",v:e.jsx(le,{value:ue}),s1:ue?ue===1?`1 task in ${E(O)} of focus`:`One task every ${E(O/ue)}`:Fe?"None yet":"No tasks",s2:null}],Pe=`${r}:${o}`,Be=u.useRef(null);return u.useEffect(()=>{if(!v)return;const m=I=>{I.key==="Escape"&&b(!1)},g=I=>{Be.current?.contains(I.target)||b(!1)};return window.addEventListener("keydown",m),window.addEventListener("pointerdown",g),()=>{window.removeEventListener("keydown",m),window.removeEventListener("pointerdown",g)}},[v]),u.useEffect(()=>{if(!y)return;const m=g=>{g.key==="Escape"&&k(null)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[y]),e.jsxs("section",{className:"fst-root","aria-label":"Focus statistics",children:[e.jsx(ks,{title:"Focus",range:r,offset:o,earliest:Is,onRange:s.pickRange,onStep:s.step}),e.jsxs("div",{className:"fst-card fst-metrics",ref:Be,children:[Ws.map(m=>e.jsxs("div",{className:"fst-metric",children:[e.jsxs("span",{className:"fst-metric-l",children:[m.deep&&e.jsx("i",{"aria-hidden":!0}),m.l,m.act]}),e.jsx("span",{className:"fst-metric-v",children:c?m.v:e.jsx("span",{className:"fst-skel",style:{width:96,height:36}})}),e.jsx("span",{className:"fst-metric-1 fst-fade",children:c?m.s1:e.jsx("span",{className:"fst-skel",style:{width:140,height:12,marginTop:4}})},`1${Pe}`),e.jsx("span",{className:B("fst-metric-2 fst-fade",m.s2?.up&&"is-up"),children:c?m.s2?.text??"":""},`2${Pe}`)]},m.l)),v&&e.jsxs("div",{className:"fst-goal",role:"dialog","aria-label":"Daily focu
2s goal",children:[e.jsxs("div",{children:[e.jsx("b",{children:"Daily focus goal"}),e.jsx("p",{children:"Focus time per day, without pauses. Shown as a line in the chart and as days met."})]}),e.jsx("div",{className:"fst-goal-opts",children:ea.map(([m,g])=>e.jsx("button",{type:"button","aria-pressed":d===g,onClick:()=>{p(g),b(!1)},children:m},m))})]})]}),e.jsxs("div",{className:"fst-card fst-chart",children:[e.jsxs("div",{className:"fst-chart-h",children:[e.jsx("b",{children:r==="day"?"Your day":"Focus per day"}),e.jsx("span",{children:c?r==="day"?qs:N.length?"Select a day to see its sessions":"":""})]}),e.jsx("div",{className:"fst-chart-body",children:r==="day"?e.jsx(la,{list:N}):e.jsx(ca,{days:Q,perDay:Z,goal:d,range:r,today:f,firstStart:i,loaded:c,label:`Focus per day, ${r==="week"?`${ae(h,"EEE d MMM")} to ${ae(j,"EEE d MMM")}`:ae(h,"MMMM yyyy")}`,onPick:Gs})},r==="day"?"day":"bars"),e.jsxs("div",{className:"fst-legend",children:[e.jsxs("div",{children:[e.jsxs("span",{children:[e.jsx("i",{style:{background:"var(--ink)"}}),"Deep focus · ",ye,"m+ without a pause"]}),e.jsxs("span",{children:[e.jsx("i",{style:{background:"var(--fst-other)"}}),"Other focus"]}),r==="day"&&e.jsxs("span",{children:[e.jsx("i",{style:{background:"var(--r3)",boxShadow:"inset 0 0 0 1px var(--rl)"}}),"Pause"]})]}),c&&Ae&&e.jsx("p",{children:Ae})]})]}),e.jsxs("div",{className:"fst-card",children:[e.jsxs("div",{className:"fst-list-h",children:[e.jsx("b",{children:"Sessions"}),e.jsx("span",{children:N.length?`${N.length} ${N.length===1?"session":"sessions"} · ${E(O)} focus`:""})]}),Ps&&J&&e.jsxs("div",{className:"fst-row is-live",children:[e.jsxs("span",{className:"fst-live",children:[e.jsx("i",{}),"In progress"]}),e.jsxs("span",{className:"fst-time fst-mono",children:["since ",V(new Date(J.startedAt))]}),e.jsx("span",{className:"fst-amount",children:e.jsxs("span",{children:[E(Math.floor(J.focus))," ",String(Math.floor(J.focus*60%60)).padStart(2,"0"),"s so far"]})}),e.jsx("span",{className:"fst-ell",style:{fontSize:12.5,color:"var(--fa)"},children:"Counted when the session ends · not deletable while running"}),e.jsx("span",{})]}),c?N.length?xe.map(m=>e.jsxs("div",{children:[e.jsxs("div",{className:"fst-group-h",children:[e.jsx("span",{children:m.label}),e.jsx("span",{children:E(m.total)})]}),m.rows.map(g=>e.jsx(ra,{s:g,confirming:y===g.id,leaving:T===g.id,arriving:A===g.id,onAsk:()=>k(y===g.id?null:g.id),onCancel:()=>k(null),onDelete:()=>Rs(g)},g.id))]},m.key)):e.jsx("div",{className:"fst-empty",children:i?"No focus sessions in this period.":n?"No focus sessions yet. Tap a task, then Focus on this task, to start one.":"No focus sessions yet. Press Enter on a task in the matrix to start one."}):e.jsx("div",{style:{padding:"14px 28px"},children:[0,1,2].map(m=>e.jsx("span",{className:"fst-skel",style:{height:40,margin:"8px 0"}},m))}),e.jsxs("div",{className:"fst-list-f",children:[he.length>es?e.jsx("button",{type:"button",className:"fst-more",onClick:()=>S(m=>!m),children:w?"Show fewer":`Show all ${he.length} sessions`}):e.jsx("span",{}),e.jsx("button",{type:"button",className:"fst-reset",onClick:()=>K(!0),children:"Reset focus stats"})]})]}),M&&e.jsxs("div",{className:"fst-toast fst-root-toast",role:"status",children:[e.jsxs("span",{children:["Session deleted · ",e.jsxs("b",{children:[V(M.s.start)," · ",E(M.s.focus)]})]}),e.jsx(ia,{until:M.until,onUndo:As})]}),e.jsx(xs,{open:z,onOpenChange:K,onSuccess:()=>{_([]),x()}})]})},ia=({until:s,onUndo:t})=>{const[,a]=u.useState(0);return u.useEffect(()=>{const n=window.setInterval(()=>a(r=>r+1),250);return()=>window.clearInterval(n)},[]),e.jsxs("button",{type:"button",onClick:t,children:["Undo",e.jsxs("span",{children:[Math.max(0,Math.ceil((s-Date.now())/1e3)),"s"]})]})},oa=204,ts=1.7,ra=({s,confirming:t,leaving:a,arriving:n,onAsk:r,onCancel:o,onDelete:l})=>{const i=s.segs??[{type:"focus",start:s.start.toISOString(),minutes:s.focus}],c=i.reduce((y,k)=>y+k.minutes,0),x=oa-2*(i.length-1),d=c*ts>x?x/c:ts,p=St(s),v=`${s.tasks.length} ${s.tasks.length>1?"tasks":"task"} · ${s.tasks.map(y=>y.content).join(", ")}`,b=de(s.end,s.start)>0,w=u.useRef(null),S=u.useRef(!1);return u.useEffect(()=>{S.current&&!t&&!a&&(!document.activeElement||document.activeElement===document.body)&&w.current?.focus(),S.current=t},[t,a]),e.jsxs("div",{className:B("fst-row",t&&"is-confirm",a&&"is-leaving",n&&"is-arriving"),children:[e.jsxs("span",{className:"fst-time fst-mono","aria-label":`${V(s.start)} to ${V(s.end)}${b?" the next day":""}, ${E(s.focus)} focus`,children:[V(s.start),"â",V(s.end),b&&e.jsx("span",{className:"fst-next",children:" +1"}
2),e.jsxs("span",{className:"fst-m-amt","aria-hidden":!0,children:[" · ",E(s.focus)," focus"]})]}),e.jsxs("span",{className:"fst-m-detail fst-ell",children:[ze(s),s.tasks.length?` · ${v}`:""]}),e.jsx("span",{className:"fst-strip",role:"img","aria-label":p,title:p,children:i.map((y,k)=>e.jsx("span",{style:{width:Math.max(2,Math.round(y.minutes*d)),height:y.type==="pause"?2:8,background:y.type==="focus"&&y.minutes>=ye&&s.segs?"var(--ink)":"var(--fst-other)"}},k))}),e.jsxs("span",{className:"fst-amount",children:[e.jsxs("span",{children:[E(s.focus)," focus"]}),e.jsx("span",{children:ze(s)})]}),t?e.jsxs("span",{className:"fst-confirm",children:[e.jsxs("span",{children:["Delete this session? ",e.jsxs("span",{className:"fst-confirm-more",children:["Its ",E(s.focus)," of focus leaves your stats. Tasks stay completed."]})]}),e.jsx("button",{type:"button",onClick:o,children:"Cancel"}),e.jsx("button",{type:"button",onClick:l,autoFocus:!0,children:"Delete"})]}):e.jsxs("span",{className:"fst-tasks",children:[s.tasks.length?e.jsxs("span",{children:[s.tasks.slice(0,5).map((y,k)=>e.jsx("i",{style:{background:Jt[y.q]}},k)),e.jsx("span",{className:"fst-ell",children:v})]}):e.jsx("span",{className:"fst-none",children:"No tasks completed"}),s.filter&&s.filter!=="All tasks"&&e.jsxs("span",{title:"Matrix filter when the session started",children:[e.jsx(ta,{}),e.jsxs("span",{className:"fst-ell",children:["From ",s.filter]})]})]}),e.jsx("button",{ref:w,type:"button",className:"fst-icon fst-trash",title:"Delete session","aria-label":"Delete session",tabIndex:t?-1:0,onClick:r,children:e.jsx(aa,{})})]})},De=s=>String(s).padStart(2,"0"),as=s=>`${De(Math.floor(s/60)%24)}:${De(Math.floor(s%60))}`,la=({list:s})=>{const t=Math.min(360,...s.map(d=>d.start.getHours()*60+d.start.getMinutes())),a=Math.floor(t/180)*180,n=1440-a,r=[];for(let d=a;d<=1440;d+=180)r.push({l:De(d/60%24),left:`${(d-a)/n*100}%`});const o=[];s.forEach(d=>{const p=d.segs??[{type:"focus",start:d.start.toISOString(),minutes:d.focus}];let v=d.start.getHours()*60+d.start.getMinutes();p.forEach(b=>{const w=b.type==="focus"&&b.minutes>=ye&&!!d.segs,S=Math.max(v,a),y=Math.min(v+b.minutes,a+n);y>S&&o.push({left:`${(S-a)/n*100}%`,w:`calc(${(y-S)/n*100}% - 1px)`,top:b.type==="pause"?22:10,bg:b.type==="pause"?"var(--r3)":w?"var(--ink)":"var(--fst-other)",tip:`${as(v)}â${as(v+b.minutes)} · ${b.type==="pause"?"pause":w?"deep focus":"focus"} ${Math.round(b.minutes)}m`}),v+=b.minutes})});const l=[...s].sort((d,p)=>d.start.getTime()-p.start.getTime()),i=l.reduce((d,p)=>p.end>d?p.end:d,new Date(0)),c=s.reduce((d,p)=>d+p.pauses,0),x=s.length?`${s.length} ${s.length===1?"session":"sessions"} between ${V(l[0].start)} and ${V(i)}: ${E(W(s,"focus"))} focus, ${E(W(s,"deep"))} deep, ${c?`${c} ${c===1?"pause":"pauses"}`:"no pauses"}`:"No sessions this day";return e.jsxs("div",{className:"fst-day-scroll",children:[e.jsxs("div",{className:"fst-day",role:"img","aria-label":x,children:[r.map(d=>e.jsx("i",{style:{left:d.left}},d.l+d.left)),o.map((d,p)=>e.jsx("span",{title:d.tip,style:{left:d.left,width:d.w,top:d.top,bottom:d.top,background:d.bg}},p))]}),e.jsx("div",{className:"fst-day-ticks","aria-hidden":!0,children:r.map(d=>e.jsx("span",{style:{left:d.left},children:d.l},d.l+d.left))})]})},ca=({days:s,perDay:t,goal:a,range:n,today:r,firstStart:o,loaded:l,label:i,onPick:c})=>{const x=s.map(t),p=170/Math.max(a?240:180,...x.map(f=>f.f),a+20),[v,b]=u.useState(!1);u.useEffect(()=>{const f=requestAnimationFrame(()=>b(!0));return()=>cancelAnimationFrame(f)},[]);const w=v&&l,S=n==="week"?56:18,y=o?H(o):null,k=s.map(f=>!!y&&f>=y&&f<=r),T=x.reduce((f,h,j)=>h.f>x[f].f?j:f,0),L=s.findIndex(f=>U(f,r)),A=(f,h)=>a?f>=a?" · goal met":` · ${E(a-f)} ${U(h,r)?"to go":"short"}`:"",C=s.map((f,h)=>h).filter(f=>k[f]),[D,_]=u.useState(-1),M=C.includes(D)?D:C[C.length-1]??-1,F=u.useRef([]),z=(f,h)=>{if(n!=="month")return;const j=C.indexOf(h),P=f.key==="ArrowRight"?C[j+1]:f.key==="ArrowLeft"?C[j-1]:f.key==="Home"?C[0]:f.key==="End"?C[C.length-1]:void 0;P!==void 0&&(f.preventDefault(),_(P),F.current[P]?.focus())},K=f=>U(f,r)?String(f.getDate()):[1,8,15,22,29].includes(f.getDate())?L>=0&&Math.abs(de(f,r))<=2?"":String(f.getDate()):"";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:B("fst-bars",`is-${n}`,a>0&&"has-goal"),role:"group","aria-label":i,children:[a>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"fst-goal-line",style:{bottom:Math.round(a*p)}}),e.jsxs("span",{className:"fst-goal-tag",style:{bottom:Math.round(a*p)},"aria-label":`Goal ${E(a)}`,children:[e.jsx("span",{className:"fst-goal-word",children:"Goal "}),E(a)]})]}),s.map((f,h)=>{const j=x[h],P=Math.max(0,j.f-j.dp),N=`${h*(n==="week"?12:4)}ms`,O=q(f,"EEE d MMM"),G=`${j.n} ${j.n===1?"session":"sessions"}`;return e.jsxs("button",{ref:Q=>{F.current[h]=Q},type:"button",className:B("fst-bar",(h===L||h===T)&&"show-v"),disabled:!k[h],tabIndex:n==="month"&&k[h]?h===M?0:-1:void 0,title:k[h]?j.f?`${O} · ${E(j.f)}
2 focus · ${E(j.dp)} deep · ${G}${A(j.f,f)}`:`${O} · No focus`:void 0,"aria-label":j.f?`${q(f,"EEEE d MMMM")}: ${E(j.f)} focus, ${E(j.dp)} deep, ${G}. Open day.`:`${q(f,"EEEE d MMMM")}: no focus.${k[h]?" Open day.":""}`,onClick:()=>c(f),onFocus:()=>{n==="month"&&_(h)},onKeyDown:Q=>z(Q,h),children:[e.jsx("span",{className:"fst-bar-v",children:!w||!j.f||n==="month"?"":E(j.f)}),k[h]&&l&&!j.f?e.jsx("span",{className:"fst-bar-zero",style:{maxWidth:S}}):e.jsxs("span",{className:"fst-bar-stack",style:{maxWidth:S},children:[e.jsx("span",{className:"fst-bar-other",style:{height:w?Math.round(P*p):0,transitionDelay:N}}),e.jsx("span",{className:"fst-bar-deep",style:{height:w?Math.round(j.dp*p):0,borderRadius:P>0?"0 0 4px 4px":4,transitionDelay:N}})]})]},f.toISOString())})]}),e.jsx("div",{className:B("fst-bar-labels",`is-${n}`,a>0&&"has-goal"),"aria-hidden":!0,children:s.map((f,h)=>e.jsx("span",{className:B(U(f,r)&&"is-today",!k[h]&&!U(f,r)&&"is-future"),children:n==="week"?e.jsxs(e.Fragment,{children:[e.jsx("span",{children:q(f,"EEE")})," ",e.jsx("span",{children:q(f,"d")})]}):K(f)},f.toISOString()))})]})},da={"Do First":"#ef4444",Schedule:"#3b82f6",Delegate:"#fb923c",Backlog:"#8a8580"},Ms=u.memo(()=>{const{period:s,earliest:t,setFocusFirst:a}=gs();return e.jsxs("div",{className:"space-y-12",children:[e.jsx(Ss,{colors:da}),e.jsx(na,{period:s,earliest:t,onFirstStart:a})]})});Ms.displayName="StatsContainer";const ua=s=>s.reduce((t,a)=>(a.started_at&&t.push({hour:new Date(a.started_at).getHours(),dayOfWeek:new Date(a.started_at).getDay(),intensity:a.duration_minutes||0}),t),[]),ma=(s,t)=>{u.useEffect(()=>{if(!s)return;const a=R.channel(gt("task_completions_channel")).on("postgres_changes",{event:"*",schema:"public",table:"task_completions",filter:`user_id=eq.${s}`},()=>{t()}).subscribe();return()=>{R.removeChannel(a)}},[s,t])},ha=async(s,t,a)=>{const{data:n,error:r}=await R.from("task_completions").select("completed_at, quadrant").eq("user_id",s).gte("completed_at",t.toISOString()).lt("completed_at",a.toISOString()).order("completed_at",{ascending:!0});if(r)throw new Error(`Failed to fetch completions: ${r.message}`);return n??[]},xa=async s=>{const{data:t,error:a}=await R.from("task_completions").select("completed_at").eq("user_id",s).order("completed_at",{ascending:!0}).limit(1);if(a)throw new Error(`Failed to fetch completions: ${a.message}`);return t?.[0]?.completed_at?new Date(t[0].completed_at):null},fa=async(s,t,a,n)=>{const{fetchFocusSessions:r}=await yt(async()=>{const{fetchFocusSessions:l}=await import("./fetchStatistics-DxgDBPFq.js");return{fetchFocusSessions:l}},__vite__mapDeps([0,1,2,3,4,5,6]));return{timeRangeSessions:await r(s,t,a,!1)||[]}},pa=(s,t)=>{const{session:a}=ie.useSessionContext(),n=a?.user?.id,[r,o]=u.useState(null),[l,i]=u.useState(null),[c,x]=u.useState([]),[d,p]=u.useState(!0),[v,b]=u.useState(!1),[w,S]=u.useState(null),{toast:y}=be(),[k,T]=u.useState(0),L=2,A=u.useRef(0),C=u.useCallback(()=>{y({title:"Cancelled",description:"Statistics calculation was cancelled",variant:"default"}),p(!1)},[y]),D=u.useCallback(async()=>{if(!n){p(!1);return}const _=++A.current;b(!0),S(null);try{const M=new Date,{a:F,from:z,to:K}=Gt(s,t,M),[f,h]=await Promise.all([ha(n,z,K),xa(n)]);let j=[];try{const{timeRangeSessions:P}=await fa(n,F,K);j=ua(P)}catch{}if(_!==A.current)return;o(qt(s,t,f,h,M)),i(h),x(j),T(0)}
2catch(M){if(_!==A.current)return;const F=M instanceof Error?M:new Error(String(M));S(F),k<L&&(F.message.includes("Failed to fetch")||F.message.includes("network"))||y({title:"Error",description:`Failed to load statistics: ${F.message}`,variant:"destructive"})}finally{_===A.current&&(p(!1),b(!1))}},[s,t,y,n,k]);return u.useEffect(()=>{if(w&&k<L){const _=Math.min(1500*(k+1),5e3),M=setTimeout(()=>{T(F=>F+1),D()},_);return()=>clearTimeout(M)}},[w,k,D]),ma(n,D),u.useEffect(()=>{D()},[D]),{summary:r,first:l,heatmapData:c,isLoading:d,isFetching:v,error:w,refetch:u.useCallback(()=>(T(0),D()),[D]),cancelFetch:C}},$s="stats.range",ga=["day","week","month"],ya=()=>{try{const s=localStorage.getItem($s);return s&&ga.includes(s)?s:"week"}catch{return"week"}},ja=()=>{const[s,t]=u.useState(ya),[a,n]=u.useState(0),r=u.useCallback(i=>{t(i),n(0);try{localStorage.setItem($s,i)}catch{}},[]),o=u.useCallback(i=>n(c=>Math.min(0,c+i)),[]),l=u.useCallback(i=>{const c=H(new Date);i>c||(t("day"),n(de(i,c)))},[]);return{range:s,offset:a,pickRange:r,step:o,openDay:l}},Cs=u.memo(({error:s,onRetry:t})=>{const{toast:a}=be(),n=s.message.includes("API key"),r=s.message.includes("CORS")||s.message.includes("Failed to fetch"),o=s.message.includes("Edge Function")||s.message.includes("non-2xx status"),l=s.message.includes("Error from Todoist API"),i=s.message.includes("Invalid token")||s.message.toLowerCase().includes("auth_invalid_token"),c=s.message.includes("toLowerCase")||s.message.includes("null"),x=()=>{a({title:"Retrying",description:"Attempting to fetch statistics again",duration:3e3}),t&&t()};return e.jsx(ce,{className:"m-8",children:e.jsxs(Ne,{className:"p-6 space-y-4",children:[e.jsxs("p",{className:"text-destructive font-medium",children:["Failed to load statistics: ",s.message]}),n||i?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your Todoist API token appears to be invalid or expired. This can happen if:"}),e.jsxs("ul",{className:"list-disc pl-5 text-sm text-muted-foreground space-y-1",children:[e.jsx("li",{children:"You've recently changed your Todoist password"}),e.jsx("li",{children:"Your OAuth token has expired"}),e.jsx("li",{children:"You've revoked access from your Todoist account settings"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Please reconnect to Todoist from the Matrix view to refresh your token."})]}):o?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"There was an issue with our Todoist integration service. This might be due to an invalid API token or a temporary service issue."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again in a few moments or reconnect your Todoist account from the Matrix view."})]}):l?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Todoist API returned an error. This could be due to rate limiting or an authentication issue."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again later or reconnect your Todoist account."})]}):r?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"There was an issue connecting to the Todoist API. This could be due to network issues or API limits."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again in a few moments."})]}):c?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"There was an issue processing your task data. Some of your tasks may have incomplete data."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try reconnecting your Todoist account from the Matrix view, or try again later."})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please try again later."}),t&&e.jsxs(X,{variant:"outline",onClick:x,className:"mt-4 flex items-center gap-2",children:[e.jsx(is,{className:"h-4 w-4"}),"Try Again"]})]})})});Cs.displayName="StatisticsError";const _e=u.memo(()=>{const{toast:s}=be(),t=ja(),{summary:a,first:n,heatmapData:r,isLoading:o,isFetching:l,error:i,cancelFetch:c,refetch:x}=pa(t.range,t.offset),[d,p]=u.useState(null),v=n&&d?n<d?n:d:n??d,[b,w]=u.useState(!1);return u.useEffect(()=>{if(!l){w(!1);return}const S=window.setTimeout(()=>w(!0),150);return()=>window.clearTimeout(S)},[l]),u.useEffect(()=>{if(i){const S=i.message.includes("Failed to fetch")||i.message.includes("CORS")||i.message.includes("network"),y=i.message.includes("Edge Function")||i.message.includes("non-2xx status");S?s({title:"Network Issue",description:"Having trouble connecting to Todoist. Using our secure proxy instead.",duration:5e3}):y&&s({title:"Service Issue",description:"Having trouble with our Todoist integration service. Retrying...",duration:5e3});const k=setTimeout(()=>{x()},1500);return()=>clearTimeout(k)}},[i,s,x]),o&&!a?e.jsx(At,{onCancel:c}):a?e.jsx(Rt,{value:{period:t,earliest:v,setFocusFirst:p,summary:a,heatmapData:r,stale:b},children:e.jsxs("div",{className:"space-y-8",children:[e.jsx(fs,{onRefresh:x,refreshing:l}),e.jsx(Ms,{})]})}):e.jsx(Cs,{error:i??new Error("No statistics loaded"),onRetry:x})});_e.displayName="StatisticsContent";const ns=()=>{const[s,t]=u.useState(!1),{session:a}=ie.useSessionContext();u.useEffect(()=>{(async()=>
2{if(!a?.user?.id)return;const{data:o}=await R.from("profiles").select("has_seen_stats_tour").eq("id",a.user.id).single();o&&!o.has_seen_stats_tour&&t(!0)})()},[a?.user?.id]);const n=async()=>{a?.user?.id&&(await R.from("profiles").update({has_seen_stats_tour:!0}).eq("id",a.user.id),t(!1))};return s?e.jsx(bt,{children:e.jsxs($.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"fixed bottom-6 right-6 max-w-md bg-card p-6 rounded-lg shadow-xl border border-border/50 backdrop-blur-lg",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-semibold text-lg",children:"Welcome to Your Statistics!"})]}),e.jsx(X,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:n,children:e.jsx(rs,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"Track your productivity journey with beautiful visualizations. See your progress across different task categories and unlock achievements as you complete more tasks."}),e.jsx(X,{className:"mt-4 w-full",onClick:n,children:"Got it!"})]})}):null},Es=u.memo(({onBackToMatrix:s})=>se()?e.jsxs("div",{className:"mx-stats",children:[e.jsxs("header",{className:"mx-stats-bar",children:[e.jsx("button",{type:"button",className:"mx-icon-btn",onClick:s,"aria-label":"Back to matrix",children:e.jsx(cs,{className:"h-6 w-6","aria-hidden":!0})}),e.jsx("h1",{className:"mx-stats-title",children:"Statistics"}),e.jsx("div",{id:"mx-stats-actions",className:"mx-stats-actions"})]}),e.jsxs("div",{className:"mx-stats-body",children:[e.jsx(_e,{}),e.jsx(ns,{})]})]}):e.jsx("div",{className:"min-h-screen bg-gradient-to-b from-background/90 to-background/95 backdrop-blur-sm",children:e.jsxs("div",{className:"max-w-7xl mx-auto p-6 md:p-8",children:[e.jsx($.div,{initial:{opacity:0,x:-20},animate:{opacity:1,x:0},transition:{duration:.3},children:e.jsxs(X,{variant:"outline",className:"mb-6 gap-2 group hover:bg-primary/10 transition-all duration-300",onClick:s,children:[e.jsx(at,{className:"h-4 w-4 group-hover:transform group-hover:-translate-x-1 transition-transform"}),e.jsx("span",{className:"font-medium",children:"Back to Matrix"})]})}),e.jsx(_e,{}),e.jsx(ns,{})]})}));Es.displayName="StatisticsLayout";const va=u.memo(()=>{const s=nt(),{session:t}=ie.useSessionContext(),a=u.useCallback(()=>{s("/",{replace:!0})},[s]);return u.useEffect(()=>{jt("stats_opened")},[]),u.useEffect(()=>{t||s("/")},[t,s]),t?e.jsx($.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},transition:{duration:.5},children:e.jsx(vt,{children:e.jsx(Es,{onBackToMatrix:a})})}):null});va.displayName="Statistics";export{va as default};
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.