1import{c as Ye,r as p,u as qe,j as e,ak as we,Q as Ae,U as Re,W as Qe,T as ce,a as ne,a2 as Oe,B as Q,be as Xe,a4 as Je,M as Ze,a8 as et,K as tt,w as Ie,a5 as F,bg as st,aX as Le,bh as at,aT as nt,ay as ot,au as it,a9 as lt,bi as rt}from"./index-B-XoyWcT.js";import{c as dt,f as ct,b as pt}from"./date-utils-CvIgZV1q.js";import{i as $e,a as Pe,u as ut}from"./editor-shortcuts-B0ZpMnSz.js";import{u as oe}from"./useCanvasDraftValue-CzVxxDA1.js";import{a as ee,h as pe}from"./auto-resize-pfVCHhta.js";import{M as mt}from"./MobileSaveButton-DVgLK0Z6.js";import{u as ue,a as me,H as xe,E as fe}from"./EmojiPicker-B5PsjOWc.js";import{S as _e,T as xt}from"./TodoEditorModal-DWztV9Gy.js";import{T as te}from"./trash-2-7pNvyGe_.js";import{u as ft}from"./useTopChrome-DK1O8X1l.js";import{E as ht}from"./ExpandableSearch-DBe-lcwm.js";import{n as gt,m as bt}from"./search-match-ChbjFfDW.js";import{V as Ue}from"./VirtualList-CrQ7MX4Z.js";import{C as se}from"./check-check-Hqa7CY9h.js";import{C as Ve}from"./clock-3-C-wiyqU6.js";import{R as ie,A as he}from"./AttachmentLinkPreview-DDVRxX8-.js";import{T as jt}from"./TodoListRow-KfECEZJp.js";import{D as wt}from"./DrawerHeaderRow-BEF0Dimi.js";import"./HashtagChip-CefVyJh6.js";import"./emoji-search-CpBUui3D.js";import"./bookmark-category-icon-UWKt-qQw.js";import"./book-open-Tq5SwSgt.js";import"./palette-foKruS-W.js";import"./mask-email-BqD4ixP4.js";import"./circle-check-D7L_N8hd.js";import"./search-BEQv28Xs.js";import"./copy-FCNkX7J-.js";import"./grip-horizontal-BTvHcbV-.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const vt=[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]],kt=Ye("List",vt);function le(s){if(!s)return"";const n=new Date(s),u=String(n.getHours()).padStart(2,"0"),m=String(n.getMinutes()).padStart(2,"0");return`${u}:${m}`}function Nt(s,n){const[u="0",m="0"]=n.split(":");return dt(s,`${u}:${m}`)}function yt({event:s,selectedDateKey:n,onClose:u,onSave:m,onDelete:f}){const x=s!=null&&s.id?`event:${s.id}`:"event:new",{value:l,setValue:b,clearDraft:i}=oe(x,(s==null?void 0:s.label)??""),{value:c,setValue:a,clearDraft:j}=oe(`${x}:notes`,(s==null?void 0:s.notes)??""),{value:v,setValue:C,clearDraft:N}=oe(`${x}:time`,le(s==null?void 0:s.loggedAt)||"09:00"),k=!!(l.trim()&&v.trim()),y=p.useRef(null),h=p.useRef(null),{settings:S}=qe(),E=ue({value:l,textareaRef:y,onChange:b}),M=ue({value:c,textareaRef:h,onChange:a}),I=me({value:l,textareaRef:y,onChange:b}),A=me({value:c,textareaRef:h,onChange:a});p.useEffect(()=>{const r=(s==null?void 0:s.label)??"",D=(s==null?void 0:s.notes)??"",K=le(s==null?void 0:s.loggedAt)||"09:00";b(r),a(D),C(K)},[s]),p.useEffect(()=>{var r;if((r=y.current)==null||r.focus(),y.current){const D=y.current.value.length;y.current.setSelectionRange(D,D)}},[]),p.useEffect(()=>{y.current&&ee(y.current)},[l]),p.useEffect(()=>{h.current&&ee(h.current)},[c]);const J=()=>{const r=l.trim();if(!r||!v.trim())return;const D=c.trim()||void 0;m({label:r,notes:D,hashtags:Qe(r+(D?" "+D:"")),loggedAt:Nt(n,v).getTime()}),P()},P=()=>{i(),j(),N()},U=()=>{b((s==null?void 0:s.label)??""),a((s==null?void 0:s.notes)??""),C(le(s==null?void 0:s.loggedAt)||"09:00"),P(),u()},V=r=>{if(r.key==="Escape"){r.preventDefault(),U();return}if(r.key==="Enter"){if($e(r)){r.preventDefault(),J();return}if(r.currentTarget instanceof HTMLTextAreaElement&&Pe(r))return;r.preventDefault()}};return e.jsx(we,{onClose:U,onBackdropMouseDown:U,children:e.jsxs("div",{className:"w-full max-w-2xl rounded-app-dialog border border-app-line bg-app-surface p-5 shadow-soft",onMouseDown:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("input",{type:"time",value:v,onChange:r=>C(r.target.value),onKeyDown:V,className:"h-8 w-[104px] flex-none rounded-md border border-app-line bg-app-surface-muted px-2 py-0.5 text-sm font-medium text-app-ink-faint shadow-none outline-none focus:border-app-line-strong"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("div",{"aria-hidden":"true",className:"pointer-events-none absolute left-0 top-0 w-full select-none whitespace-pre-wrap break-words p-0 text-[28px] font-bold leading-[1.25] text-transparent",children:[Ae(l).map(({text:r,isHashtag:D,name:K},R)=>
6{if(D&&K){const L=Re(K),O=r.length>K.length+1?r[0]:"";return e.jsxs("span",{children:[O,e.jsxs("mark",{className:`${L.bg} ${L.darkBg} rounded-full`,style:{color:"transparent"},children:["#",K]})]},R)}return e.jsx("span",{children:r},R)}),l===""&&"â"]}),e.jsx("textarea",{ref:y,value:l,onChange:r=>b(r.target.value),onPaste:r=>{pe(r,l,b)},onKeyDown:r=>{E.handleKeyDown(r)||I.handleKeyDown(r)||V(r)},rows:1,placeholder:"What happened?",className:"relative block w-full resize-none border-0 bg-transparent p-0 text-[28px] font-bold leading-[1.25] text-app-ink caret-app-ink outline-none placeholder:text-app-ink-faint selection:bg-app-surface-muted selection:text-app-ink"}),e.jsx(xe,{isOpen:E.isOpen,suggestions:E.suggestions,activeIndex:E.activeIndex,onSelect:E.selectSuggestion,onHover:E.setActiveIndex,anchorRef:y}),e.jsx(fe,{isOpen:I.isOpen,suggestions:I.suggestions,activeIndex:I.activeIndex,onSelect:I.selectSuggestion,onHover:I.setActiveIndex,anchorRef:y})]}),e.jsx("p",{className:"mt-2 text-sm text-app-ink-faint",children:n}),e.jsxs("div",{className:"relative mt-4",children:[e.jsxs("div",{"aria-hidden":"true",className:"pointer-events-none absolute left-0 top-0 w-full select-none whitespace-pre-wrap break-words p-0 text-base leading-7 text-transparent",children:[Ae(c).map(({text:r,isHashtag:D,name:K},R)=>{if(D&&K){const L=Re(K),O=r.length>K.length+1?r[0]:"";return e.jsxs("span",{children:[O,e.jsxs("mark",{className:`${L.bg} ${L.darkBg} rounded-full`,style:{color:"transparent"},children:["#",K]})]},R)}return e.jsx("span",{children:r},R)}),c===""&&"â"]}),e.jsx("textarea",{ref:h,value:c,onChange:r=>a(r.target.value),onPaste:r=>{pe(r,c,a)},onKeyDown:r=>{M.handleKeyDown(r)||A.handleKeyDown(r)||V(r)},placeholder:"Add notes",rows:1,className:"relative block w-full resize-none border-0 bg-transparent p-0 text-base leading-7 text-app-ink-muted outline-none placeholder:text-app-ink-faint caret-app-ink selection:bg-app-surface-muted selection:text-app-ink"}),e.jsx(xe,{isOpen:M.isOpen,suggestions:M.suggestions,activeIndex:M.activeIndex,onSelect:M.selectSuggestion,onHover:M.setActiveIndex,anchorRef:h}),e.jsx(fe,{isOpen:A.isOpen,suggestions:A.suggestions,activeIndex:A.activeIndex,onSelect:A.selectSuggestion,onHover:A.setActiveIndex,anchorRef:h})]})]})]}),e.jsxs("div",{className:"mt-6 flex items-center justify-between gap-3",children:[s&&f?e.jsxs("button",{type:"button",onClick:f,className:"inline-flex items-center gap-2 rounded-full px-3 py-2 text-sm font-medium text-app-ink-faint transition hover:bg-app-surface-hover hover:text-app-ink",children:[e.jsx(te,{className:"h-4 w-4"}),"Delete"]}):e.jsx("div",{}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(_e,{className:"hidden text-sm md:inline"}),e.jsx(mt,{disabled:!k,onClick:J})]})]})]})})}const ge=Array.from({length:24},(s,n)=>n),Dt=72,Tt=44,Et=50,G=92,Ct=92,St={rowHeights:[],hourTops:[],totalHeight:0};function Mt(s,n){const u=new Set;for(const l of s)n.includes(l.dateKey)&&u.add(Math.floor(l.startMinutes/60));const m=ge.map(l=>u.has(l)?Dt:Tt),f=[];let x=0;for(const l of m)f.push(x),x+=l;return{rowHeights:m,hourTops:f,totalHeight:x+G}}function Kt(s,n){const u=Math.floor(s/60),m=s%60;return n.hourTops[u]+m/60*n.rowHeights[u]}function At(s,n,u){const m=new Map;for(const x of s){if(!n.includes(x.dateKey))continue;const l=m.get(x.dateKey)??[];l.push(x),m.set(x.dateKey,l)}const f={};for(const x of n){const l=[...m.get(x)??[]].sort((a,j)=>a.startMinutes-j.startMinutes),b=[];let i=null,c=-1;for(const a of l){const j=a.startMinutes,v=j+Et;if(!i||j>=c){i={id:`${x}:${a.id}`,dateKey:x,top:Kt(j,u),entries:[a]},b.push(i),c=v;continue}i.entries.push(a),c=Math.max(c,v)}f[x]=b}return f}function Rt(s){const n=s>=12?"PM":"AM";return`${s%12===0?12:s%12} ${n}`}function be(s){return new Date(s).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).replace(":00","").replace(/\s+/g,"")}function Y(s){return s.sourceType==="todo_completed"}function ve(s){return s.kind==="todo"}function ze(s){return ve(s)?s.todo.title:s.event.label}function X(s){return ve(s)?s.todo.dueTime?It(s.todo.dueTime):"":be(s.event.loggedAt)}function It(s){const[n,u]=s.split(":"),m=Number(n),f=Number(u);return new Date(2026,0,1,m,f).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).replace(":00","").replace(/\s+/g,"")}
6function je(s,n){if(s===n)return"Today";const u=new Date(`${s}T00:00:00`),m=u.toLocaleDateString("en-US",{weekday:"short"}),f=u.toLocaleDateString("en-US",{month:"short",day:"numeric"});return`${m}, ${f}`}function Lt(s){const n=Math.floor(s/60),u=s%60,m=new Date;return m.setHours(n,u,0,0),m.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})}function He({todo:s,compact:n=!1,onOpen:u}){return e.jsxs("button",{type:"button","aria-label":`Open todo ${s.title}`,onClick:m=>{m.stopPropagation(),u()},className:["group/todo flex w-full items-center gap-2 text-left transition",n?"px-1 py-0.5":"px-0 py-0"].join(" "),children:[e.jsx(ce,{as:"span","aria-hidden":"true",checked:s.status==="done",size:"sm"}),e.jsx("span",{className:["min-w-0 flex-1 truncate font-bold text-app-ink",n?"text-xs":"text-sm leading-5"].join(" "),children:s.title})]})}function Ht({days:s,todayKey:n,scrollRef:u,onEditEvent:m,onEditTodo:f,onToggleTodo:x}){return s.length?e.jsx(Ue,{items:s,getKey:l=>l.dateKey,scrollRef:u,className:"w-full min-w-0 pb-4",gap:16,threshold:12,estimateSize:140,overscan:4,renderItem:l=>{const b=l.dateKey===n;return e.jsxs("section",{"aria-label":je(l.dateKey,n),children:[e.jsxs("div",{className:"flex items-baseline gap-2 border-b border-app-line pb-1",children:[e.jsx("h3",{className:ne("text-sm font-bold",b?"text-app-ink":"text-app-ink-muted"),children:je(l.dateKey,n)}),e.jsx("span",{className:"text-[11px] text-app-ink-faint",children:l.allDayTodos.length+l.timed.length||"nothing"})]}),e.jsxs("ul",{className:"mt-2 flex flex-col gap-1",children:[l.allDayTodos.map(i=>
6e.jsxs("li",{className:"flex items-start gap-3 rounded-app-panel px-2 py-1.5",children:[e.jsx("span",{className:"w-14 flex-none pt-0.5 text-[11px] uppercase text-app-ink-faint",children:"All day"}),e.jsx(ce,{type:"button",checked:i.status==="done",align:"text",onClick:()=>x(i.id),"aria-label":i.status==="done"?`Reopen ${i.title}`:`Complete ${i.title}`}),e.jsx("button",{type:"button",onClick:()=>f(i.id),className:ne("min-w-0 flex-1 text-left text-sm",i.status==="done"?"text-app-ink-faint line-through":"text-app-ink"),children:i.title})]},`all-day-${i.id}`)),l.timed.map(i=>e.jsxs("li",{className:"flex items-start gap-3 rounded-app-panel px-2 py-1.5",children:[e.jsx("span",{className:"w-14 flex-none pt-0.5 text-[11px] tabular-nums text-app-ink-faint",children:Lt(i.startMinutes)}),i.kind==="todo"?e.jsx(ce,{type:"button",checked:i.todo.status==="done",align:"text",onClick:()=>x(i.todo.id),"aria-label":i.todo.status==="done"?`Reopen ${i.todo.title}`:`Complete ${i.todo.title}`}):e.jsx("span",{"aria-hidden":"true","data-agenda-event-icon":Y(i.event)?"completed-todo":"logged",className:"mt-0.5 flex h-5 w-5 flex-none items-center justify-center rounded-full bg-app-surface-muted",children:Y(i.event)?e.jsx(se,{className:"h-3 w-3 text-app-ink-faint"}):e.jsx(Ve,{className:"h-3 w-3 text-app-ink-faint"})}),e.jsx("button",{type:"button",onClick:()=>i.kind==="todo"?f(i.todo.id):m(i.event.id),className:ne("min-w-0 flex-1 text-left text-sm",i.kind==="todo"&&i.todo.status==="done"?"text-app-ink-faint line-through":"text-app-ink"),children:i.kind==="todo"?i.todo.title:i.event.label})]},`${i.kind}-${i.id}`)),!l.allDayTodos.length&&!l.timed.length?e.jsx("li",{className:"px-2 py-1.5 text-sm text-app-ink-faint",children:"Nothing scheduled"}):null]})]})}}):e.jsx("p",{className:"py-12 text-center text-sm text-app-ink-faint",children:"Nothing scheduled"})}function Ot({events:s,todayKey:n,focusedEventId:u,onEdit:m,onDelete:f,onDeleteTodoEvent:x,onLogEvent:l,highlightQuery:b,scrollRef:i}){const c=p.useRef(null),a=p.useMemo(()=>{const j=new Map;for(const N of s){const k=N.createdDateKey,y=j.get(k)??[];y.push(N),j.set(k,y)}const v=[];v.push({dateKey:n,events:[...j.get(n)??[]].sort((N,k)=>k.loggedAt-N.loggedAt)});const C=[...j.keys()].filter(N=>N<n).sort((N,k)=>k.localeCompare(N));for(const N of C)v.push({dateKey:N,events:[...j.get(N)??[]].sort((k,y)=>y.loggedAt-k.loggedAt)});return v},[s,n]);return p.useEffect(()=>{var C,N;if(!u)return;const j=(C=a.find(k=>k.events.some(y=>y.id===u)))==null?void 0:C.dateKey;j&&((N=c.current)==null||N.scrollToKey(j));const v=requestAnimationFrame(()=>{const k=document.querySelector(`[data-event-row-id="${u}"]`);k==null||k.scrollIntoView({behavior:"smooth",block:"center"})});return()=>cancelAnimationFrame(v)},[u,a]),a.length===0?e.jsx("p",{className:"py-12 text-center text-sm text-app-ink-faint",children:"No events yet"}):e.jsx(Ue,{ref:c,scrollRef:i,items:a,getKey:$t,className:"w-full min-w-0 pb-4",gap:0,threshold:12,estimateSize:260,overscan:4,renderItem:({dateKey:j,events:v},C)=>{const N=je(j,n),k=C===0,y=C===a.length-1;return e.jsxs("div",{className:"relative",children:[!k&&e.jsx("div",{className:"absolute left-[11px] top-0 h-[17px] w-px bg-app-line"}),!y&&e.jsx("div",{className:"absolute bottom-0 left-[11px] top-[22px] w-px bg-app-line"}),e.jsxs("div",{className:"relative flex items-center gap-1.5 py-2.5",children:[e.jsx("div",{className:"relative z-10 flex h-[14px] w-[22px] shrink-0 items-center justify-center",children:e.jsx("div",{className:"h-[10px] w-[10px] rounded-full border-2 border-app-ink-faint bg-app-canvas"})}),e.jsx("span",{className:"app-title-font text-sm font-bold text-app-ink",children:N}),e.jsx("span",{className:"rounded-app-badge bg-app-surface-muted px-2 py-0.5 text-[11px] font-bold text-app-ink-muted",children:v.length})]}),j===n&&v.length===0&&e.jsx("div",{className:"ml-10 mb-3 rounded-app-card bg-app-surface-muted px-5 py-6",children:e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-app-surface",children:e.jsx(Oe,{className:"h-4 w-4 text-app-ink-faint"})}),e.jsx("p",{className:"text-sm text-app-ink-faint",children:"Today seems eventless so far"}),e.jsxs(Q,{type:"button",onClick:l,className:"gap-1.5 px-3.5 py-1.5 text-xs",children:[e.jsx(Xe,{className:"h-3.5 w-3.5"}),"Log your event"]})]})}),v.length>0&&e.jsx("div",{className:"relative ml-6 pb-3",children:v.map((h,S)=>{const E=Y(h),M=S===0,I=S===v.length-1;return e.jsxs("div",{"data-event-row-id":h.id,className:["relative flex items-start gap-3 py-1.5 rounded-lg transition-colors duration-700",u===h.id?"bg-app-surface-hover":""].join(" "),children:[!M&&e.jsx("div",{className:"absolute left-[10px] top-0 h-[6px] w-px bg-app-line"}),!I&&e.jsx("div",{className:"absolute left-[10px] top-[26px] bottom-0 w-px bg-app-line"}),e.jsx("div",{className:"relative z-10 flex w-[21px] shrink-0 items-center justify-center",children:e.jsx("div",{className:"flex h-[20px] w-[20px] items-center justify-center rounded-full bg-app-surface-muted",children:E?e.
6jsx(se,{className:"h-3 w-3 text-app-ink-faint"}):e.jsx(Ve,{className:"h-3 w-3 text-app-ink-faint"})})}),E?e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start gap-1.5",children:[e.jsx("span",{className:"w-[68px] shrink-0 tabular-nums text-xs text-app-ink-faint",children:be(h.loggedAt)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(ie,{value:h.label,paragraphClassName:"text-sm text-app-ink-muted",highlightQuery:b}),e.jsx(he,{textValues:[h.label,h.notes],className:"mt-2"})]})]})}):e.jsxs("div",{role:"button",tabIndex:0,className:"group/event relative min-w-0 flex-1 cursor-pointer rounded-lg px-2 -mx-2 transition hover:bg-app-surface-hover",onClick:()=>m(h.id),onDoubleClick:()=>m(h.id),onKeyDown:A=>{A.key==="Enter"&&m(h.id)},children:[e.jsx("button",{type:"button","aria-label":"Delete event",onClick:A=>{A.stopPropagation(),f(h.id)},className:"absolute right-1 top-1 flex h-6 w-6 items-center justify-center rounded-full text-app-ink-faint opacity-0 transition hover:bg-app-surface-muted hover:text-app-ink-muted group-hover/event:opacity-100",children:e.jsx(te,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex items-start gap-1.5 pr-6",children:[e.jsx("span",{className:"w-[68px] shrink-0 tabular-nums text-xs text-app-ink-faint",children:be(h.loggedAt)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(ie,{value:h.label,paragraphClassName:"text-sm text-app-ink-muted",highlightQuery:b}),h.notes&&e.jsx(ie,{value:h.notes,className:"mt-0.5",paragraphClassName:"text-xs text-app-ink-faint",highlightQuery:b}),e.jsx(he,{textValues:[h.label,h.notes],className:"mt-2"})]})]})]})]},h.id)})})]})}})}const $t=s=>s.dateKey;function Pt({entries:s,onClose:n,onEdit:u,onToggleTodo:m,onUpdateTodo:f,onDeleteTodo:x,onDeleteTodoEvent:l,onOpenTodoEditor:b}){const i=[...s].sort((c,a)=>c.startMinutes-a.startMinutes);return e.jsx(we,{onClose:n,onBackdropMouseDown:n,children:e.jsxs("div",{className:"w-full max-w-lg rounded-app-dialog border border-app-line bg-app-surface p-5 shadow-soft",onMouseDown:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-bold uppercase text-app-ink-faint",children:[i.length," items"]}),e.jsx("p",{className:"mt-1 text-sm text-app-ink-muted",children:i[0]?X(i[0]):""})]}),e.jsx("button",{type:"button",onClick:n,className:"flex h-8 w-8 items-center justify-center rounded-full text-app-ink-faint transition hover:bg-app-surface-hover hover:text-app-ink",children:e.jsx(Je,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"space-y-1",children:i.map(c=>{const a=c.kind==="event"?c.event:null,j=c.kind==="todo"?c.todo:null,v=X(c);return e.jsx("div",{children:j?e.jsxs("div",{className:"flex items-start gap-3 py-1.5",children:[v?e.jsx("div",{className:"min-w-[76px] rounded-app-badge bg-app-surface-muted px-2 py-1 text-xs font-bold text-app-ink-faint",children:v}):null,e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(jt,{todo:j,canvasDateKey:c.dateKey,onToggle:m,onDelete:x,onSaveEdit:(C,N)=>f(C,N),onOpenEditor:C=>b(C.id)})})]}):e.jsxs("div",{className:"flex items-start gap-3 py-1.5",children:[v?e.jsx("div",{className:"min-w-[76px] rounded-app-badge bg-app-surface-muted px-2 py-1 text-xs font-bold text-app-ink-faint",children:v}):null,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[a&&Y(a)?e.jsx(se,{className:"h-4 w-4 text-app-ink-faint"}):null,e.jsx("p",{className:"text-sm font-bold text-app-ink",children:ze(c)})]}),a!=null&&a.notes?e.jsx("p",{className:"mt-1 text-sm leading-6 text-app-ink-muted",children:a.notes}):null,e.jsx(he,{textValues:[a==null?void 0:a.label,a==null?void 0:a.notes],className:"mt-2"})]}),a&&!Y(a)?e.jsx(Q,{variant:"ghost",onClick:()=>u(a.id),children:"Open"}):a!=null&&a.sourceTodoId?e.jsx("button",{type:"button","aria-label":"Uncheck todo",onClick:()=>l(a.sourceTodoId),className:"flex h-7 w-7 items-center justify-center rounded-full text-app-ink-faint transition hover:bg-app-surface-hover hover:text-app-ink-muted",children:e.jsx(te,{className:"h-3.5 w-3.5"})}):null]})},c.id)})})]})})}const _t="items-end px-4 pb-[calc(1rem+env(safe-area-inset-bottom))] md:items-center md:px-app-page md:pb-0",Ut="w-full max-w-2xl rounded-app-dialog border border-app-line bg-app-surface-raised p-5 shadow-app-drawer md:bg-app-surface md:shadow-soft";function Vt({dateKey:s,startedAt:n,onClose:u,onSave:m}
6){const[f,x]=p.useState(""),l=p.useRef(null),b=!!f.trim(),i=ue({value:f,textareaRef:l,onChange:x}),c=me({value:f,textareaRef:l,onChange:x});return p.useEffect(()=>{var a;(a=l.current)==null||a.focus(),l.current&&ee(l.current)},[]),p.useEffect(()=>{l.current&&ee(l.current)},[f]),e.jsx(we,{onClose:u,onBackdropMouseDown:u,className:_t,children:e.jsxs("div",{className:Ut,onMouseDown:a=>a.stopPropagation(),children:[e.jsx(wt,{className:"-mx-5 -mt-5 mb-2 px-4 pt-3 pb-2 md:hidden",onCancel:u,onSave:()=>m(f),canSave:b}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"rounded-app-badge border border-app-line bg-app-surface-muted px-2 py-0.5 text-xs font-medium text-app-ink-faint",children:new Date(n).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).replace(":00","").replace(/\s+/g,"")}),e.jsx(_e,{className:"hidden text-sm md:inline"})]}),e.jsxs("div",{className:"mt-3",children:[e.jsx("textarea",{ref:l,value:f,onChange:a=>x(a.target.value),onPaste:a=>{pe(a,f,x)},onKeyDown:a=>{if(!i.handleKeyDown(a)&&!c.handleKeyDown(a)&&a.key==="Enter"){if($e(a)){a.preventDefault(),m(f);return}Pe(a)||a.preventDefault()}},rows:1,placeholder:"Write your event",className:"block w-full resize-none border-0 bg-transparent p-0 text-[15px] leading-6 text-app-ink caret-app-ink outline-none placeholder:text-app-line-strong selection:bg-app-surface-muted selection:text-app-ink"}),e.jsx("p",{className:"mt-1 text-xs text-app-ink-faint",children:s})]}),e.jsx(xe,{isOpen:i.isOpen,suggestions:i.suggestions,activeIndex:i.activeIndex,onSelect:i.selectSuggestion,onHover:i.setActiveIndex,anchorRef:l}),e.jsx(fe,{isOpen:c.isOpen,suggestions:c.suggestions,activeIndex:c.activeIndex,onSelect:c.selectSuggestion,onHover:c.setActiveIndex,anchorRef:l})]})})}const re="event-view",de=rt(["week","timeline"]),zt=60;function bs(){var Ke;const{state:s,dispatch:n}=Ze(),u=et(),m=ut(),[f,x]=p.useState(null),[l,b]=p.useState(null),[i,c]=p.useState(null),[a,j]=p.useState(null),[v,C]=p.useState(null),N=p.useRef(null),[k,y]=p.useState(()=>tt(re,de,"week")),h=t=>{Ie(re,de,t),y(t)},S=m&&k==="week";p.useEffect(()=>{var d;const t=(d=u.state)==null?void 0:d.focusEventId;if(!t)return;window.history.replaceState({},""),y("timeline"),Ie(re,de,"timeline"),C(t);const o=window.setTimeout(()=>C(null),2e3);return()=>window.clearTimeout(o)},[]);const E=p.useMemo(()=>new Date,[]),M=p.useMemo(()=>F(E),[E]),I=p.useMemo(()=>s.events.filter(t=>!t.deletedAt).sort((t,o)=>t.loggedAt-o.loggedAt),[s.events]),[A,J]=p.useState(""),P=p.useMemo(()=>gt(A),[A]),U=p.useMemo(()=>P?I.filter(t=>bt(P,t.label,t.notes)):I,[I,P]),V=7,r=p.useMemo(()=>st(Le(E,s.ui.dateWindowOffset)),[s.ui.dateWindowOffset,E]),D=p.useMemo(()=>r.map(t=>F(t)),[r]),K=p.useMemo(()=>S?Array.from({length:zt},(t,o)=>F(Le(E,o))):[],[S,E]),R=S?K:D,L=p.useMemo(()=>{const t=F(E),o=s.todos.filter(g=>!g.deletedAt&&g.dueDateKey&&!g.recurrence),d=at(s.todos,R,t);return[...o,...d]},[s.todos,R,E]),O=I,Z=p.useMemo(()=>{const t={};for(const o of L)!o.dueDateKey||o.dueTime||!R.includes(o.dueDateKey)||(t[o.dueDateKey]=[...t[o.dueDateKey]??[],o]);return t},[L,R]),z=p.useMemo(()=>{const t=O.map(d=>{const g=new Date(d.loggedAt);return{kind:"event",id:d.id,dateKey:d.createdDateKey,startMinutes:g.getHours()*60+g.getMinutes(),event:d}}),o=L.flatMap(d=>{if(!d.dueDateKey||!d.dueTime)return[];const[g,T]=d.dueTime.split(":");return[{kind:"todo",id:d.id,dateKey:d.dueDateKey,startMinutes:Number(g)*60+Number(T),todo:d}]});return[...t,...o]},[L,O]),ke=p.useMemo(()=>O.filter(t=>R.includes(t.createdDateKey)),[O,R]),Ne=p.useMemo(()=>L.filter(t=>t.dueDateKey&&R.includes(t.dueDateKey)).length,[L,R]),_=p.useMemo(()=>S?St:Mt(z,D),[S,z,D]),ye=p.useMemo(()=>S?{}:At(z,D,_),[S,_,z,D]),We=p.useMemo(()=>{if(!S)return[];const t=new Map;for(const o of z)K.includes(o.dateKey)&&t.set(o.dateKey,[...t.get(o.dateKey)??[],o]);return K.map(o=>({dateKey:o,allDayTodos:Z[o]??[],timed:[...t.get(o)??[]].sort((d,g)=>d.startMinutes-g.startMinutes)})).filter(o=>o.dateKey===M||o.allDayTodos.length>0||o.timed.length>0)},[S,K,Z,z,M]),W=s.events.find(t=>
6t.id===f)??null,Be=l?((Ke=nt(l))==null?void 0:Ke.masterId)??l:null,B=s.todos.find(t=>t.id===Be)??null,Fe=p.useMemo(()=>{const[t]=D,o=D[D.length-1];return ct(t,o)},[E,D,r]),De=`72px repeat(${r.length}, minmax(0, 1fr))`,Te=t=>{n({type:"ui/set-date-window-offset",offset:s.ui.dateWindowOffset+(t==="next"?V:-V)})},Ge=p.useRef(null),Ee=p.useRef(null),ae=p.useRef(s.ui.dateWindowOffset),[Ce,Se]=p.useState(null);p.useLayoutEffect(()=>{if(ae.current===s.ui.dateWindowOffset)return;const t=s.ui.dateWindowOffset>ae.current?"next":"prev";ae.current=s.ui.dateWindowOffset,Se(t)},[s.ui.dateWindowOffset]);const Me=Ce?`omanote-week-slide-${Ce}`:"";return ft(e.jsx(ht,{value:A,onChange:J,placeholder:"Search in Events"})),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4",children:[e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase text-app-ink-faint",children:k==="timeline"?"Timeline":S?"Schedule":"Week view"}),e.jsx("p",{className:"mt-1 text-sm text-app-ink-muted",children:k==="timeline"?`${U.length} total events`:S?`${ke.length} logged · ${Ne} todos scheduled`:`${Fe} · ${ke.length} logged · ${Ne} todos`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k==="week"&&!S&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{variant:"soft",onClick:()=>{n({type:"ui/set-date-window-offset",offset:0}),n({type:"ui/set-selected-date",dateKey:F(E)})},children:"Today"}),e.jsx(Q,{variant:"ghost",className:"h-10 w-10 rounded-full p-0","aria-label":"Previous week",onClick:()=>Te("prev"),children:e.jsx(ot,{className:"h-4 w-4"})}),e.jsx(Q,{variant:"ghost",className:"h-10 w-10 rounded-full p-0","aria-label":"Next week",onClick:()=>Te("next"),children:e.jsx(it,{className:"h-4 w-4"})})]}),e.jsx(lt,{activeKey:k,ariaLabel:"Event view",highlightTestId:"event-view-highlight",items:[{key:"week",icon:e.jsx(Oe,{className:"h-3.5 w-3.5"}),ariaLabel:"Calendar view"},{key:"timeline",icon:e.jsx(kt,{className:"h-3.5 w-3.5"}),ariaLabel:"Timeline view"}],onChange:t=>h(t)})]})]}),k==="timeline"&&e.jsx("div",{ref:N,className:"scrollbar-hide min-h-0 flex-1 overflow-y-auto overflow-x-hidden",children:e.jsx(Ot,{scrollRef:N,events:U,todayKey:M,focusedEventId:v,onEdit:t=>x(t),onDelete:t=>n({type:"event/delete",eventId:t}),onDeleteTodoEvent:t=>n({type:"todo/toggle",todoId:t}),highlightQuery:P,onLogEvent:()=>m?n({type:"ui/open-composer",mode:"event"}):j({dateKey:M,startedAt:Date.now()})})}),S&&e.jsx("div",{ref:Ee,className:"scrollbar-hide min-h-0 flex-1 overflow-y-auto overflow-x-hidden",children:e.jsx(Ht,{days:We,todayKey:M,scrollRef:Ee,onEditEvent:t=>x(t),onEditTodo:t=>b(t),onToggleTodo:t=>n({type:"todo/toggle",todoId:t})})}),k==="week"&&!S&&e.jsx("div",{className:"min-h-0 flex-1 overflow-hidden rounded-app-dialog border border-app-line bg-app-surface shadow-none",onAnimationEnd:t=>{t.animationName.startsWith("omanote-week-slide")&&Se(null)},children:e.jsx("div",{ref:Ge,className:"scrollbar-hide h-full overflow-auto",children:e.jsxs("div",{className:"min-w-[920px]",children:[e.jsx("div",{className:"sticky top-0 z-20",children:e.jsxs("div",{className:"grid border-b border-app-line bg-app-surface/95 backdrop-blur",style:{gridTemplateColumns:De},children:[e.jsx("div",{className:"border-r border-app-line px-3 py-3"}),r.map(t=>{var $;const o=F(t),d=o===M,T=(ye[o]??[]).reduce((q,w)=>q+w.entries.length,0)+((($=Z[o])==null?void 0:$.length)??0);return e.jsx("div",{className:["border-r border-app-line px-3 py-3 text-left transition last:border-r-0",d?"bg-app-surface":"bg-app-surface-muted/90",Me].join(" "),children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:["text-[11px] font-bold uppercase","text-app-ink-faint"].join(" "),children:t.toLocaleDateString("en-US",{weekday:"short"})}),e.jsx("p",{className:["mt-1 text-sm font-bold",d?"text-app-ink":"text-app-ink-faint"].join(" "),children:t.toLocaleDateString("en-US",{month:"short",day:"numeric"})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:["rounded-app-badge px-2 py-0.5 text-[10px] font-bold",d?"bg-app-surface-muted text-app-ink-muted":"bg-app-line text-app-ink-faint"].join(" "),children:T})})]})},o)})]})}),e.jsxs("div",{className:"relative grid","data-testid":"week-calendar-grid",style:{gridTemplateColumns:De,height:_.totalHeight},children:[e.jsxs("div",{className:"relative border-r border-app-line bg-app-surface-muted/70",children:[e.jsx("div",{className:"absolute inset-x-0 border-b border-app-line",style:{to
6p:G}}),ge.map(t=>e.jsx("div",{className:"absolute inset-x-0 border-b border-app-line pr-3 text-right",style:{top:G+_.hourTops[t],height:_.rowHeights[t]},children:e.jsx("span",{className:"absolute -top-2 right-3 bg-app-surface-muted px-1 text-[10px] font-bold uppercase text-app-ink-faint",children:Rt(t)})},t))]}),D.map(t=>{const o=ye[t]??[],d=Z[t]??[],g=t===M;return e.jsxs("div",{className:["relative border-r border-app-line last:border-r-0",g?"bg-app-surface":"bg-app-surface-muted/90",Me].join(" "),children:[e.jsx("div",{className:"absolute inset-x-0 border-b border-app-line",style:{top:G}}),d.length?e.jsx("div",{className:"absolute top-2 z-10",style:{left:"6px",width:"calc(100% - 12px)"},children:d.length===1?e.jsx("div",{className:"overflow-hidden rounded-app-card border border-app-line bg-app-surface px-2 py-1.5 text-left shadow-soft transition hover:border-app-line-strong hover:shadow-soft",children:e.jsx(He,{todo:d[0],onOpen:()=>{b(d[0].id)}})}):e.jsxs("button",{type:"button",className:"block w-full overflow-hidden rounded-app-card border border-app-line bg-app-surface px-2 py-1.5 text-left shadow-soft transition hover:border-app-line-strong hover:shadow-soft",onClick:T=>{T.stopPropagation(),c(d.map($=>({kind:"todo",id:$.id,dateKey:t,startMinutes:0,todo:$})))},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("p",{className:"min-w-0 text-[10px] font-bold uppercase text-app-ink-faint",children:[d.length," todos"]}),e.jsx("span",{className:"shrink-0 rounded-app-badge bg-app-surface-muted px-2 py-0.5 text-[10px] font-bold text-app-ink-muted",children:"Stack"})]}),e.jsxs("div",{className:"mt-2 space-y-1",children:[d.slice(0,2).map(T=>e.jsx("p",{className:"truncate text-sm font-bold leading-5 text-app-ink",children:T.title},T.id)),d.length>2?e.jsxs("p",{className:"text-xs text-app-ink-faint",children:["+",d.length-2," more"]}):null]})]})}):null,ge.map(T=>e.jsx("div",{className:"absolute inset-x-0 border-b border-app-line",style:{top:G+_.hourTops[T],height:_.rowHeights[T]}},T)),o.map(T=>{const $=T.entries.length>1,q=T.entries.slice(0,2),w=T.entries[0];return e.jsx("div",{className:"absolute z-10 overflow-hidden rounded-app-card border border-app-line bg-app-surface px-2 py-1.5 text-left shadow-soft transition hover:border-app-line-strong hover:shadow-soft",style:{top:G+T.top+8,left:"6px",width:"calc(100% - 12px)",minHeight:$?Ct:void 0},children:$?e.jsxs("button",{type:"button",className:"block w-full text-left",onClick:H=>{H.stopPropagation(),c(T.entries)},children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("p",{className:"min-w-0 text-[10px] font-bold uppercase text-app-ink-faint",children:[X(T.entries[0])," · ",T.entries.length," items"]}),e.jsx("span",{className:"shrink-0 rounded-app-badge bg-app-surface-muted px-2 py-0.5 text-[10px] font-bold text-app-ink-muted",children:"Stack"})]}),e.jsxs("div",{className:"mt-3 space-y-1",children:[q.map(H=>e.jsx("p",{className:"truncate text-sm font-bold leading-5 text-app-ink",children:ze(H)},H.id)),T.entries.length>q.length?e.jsxs("p",{className:"text-xs text-app-ink-faint",children:["+",T.entries.length-q.length," more"]}):null]})]}):w&&ve(w)?e.jsx(He,{todo:w.todo,onOpen:()=>{b(w.todo.id)}}):w&&Y(w.event)?e.jsxs("div",{className:"group/todo relative block w-full text-left",children:[e.jsxs("button",{type:"button","aria-label":`Open todo ${w.event.label}`,className:"block w-full text-left",onClick:H=>{H.stopPropagation(),w.event.sourceTodoId&&b(w.event.sourceTodoId)},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-app-ink-faint",children:X(w)}),e.jsx(se,{className:"h-3.5 w-3.5 text-app-ink-faint"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm font-bold leading-5 text-app-ink",children:w.event.label}),w.event.notes?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-4 text-app-ink-muted",children:w.event.notes}):null]}),w.event.sourceTodoId?e.jsx("button",{type:"button","aria-label":"Uncheck todo",onClick:H=>{H.stopPropagation(),n({type:"todo/toggle",todoId:w.event.sourceTodoId})},className:"absolute right-2 top-2 flex h-7 w-7 items-center justify-center rounded-full text-app-ink-faint opacity-0 transition hover:bg-app-surface-hover hover:text-app-ink-muted group-hover/todo:opacity-100",children:e.jsx(te,{className:"h-3.5 w-3.5"})}):null]}):e.jsxs("button",{type:"button",className:"block w-full text-left",onClick:H=>{H.stopPropagation(),w&&x(w.event.id)},children:[e.jsx("p",{className:"text-[10px] font-bold uppercase text-app-ink-faint",children:w?X(w):""}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm font-bold leading-5 text-app-ink",children:w?w.event.label:""}),w!=null&&w.event.notes?e.jsx("p",{className:"mt-1 line-clamp-2 text-xs leading-4 text-app-ink-muted",children:w.event.notes}):null]})},T.id)})]},t)})]})]})})}),i?e.jsx(Pt,{entries:i,onClose:()=>c(null),onEdit:t=>{c(null),x(t)},onToggleTodo:t=>{n({type:"todo/toggle",todoId:t}),c(o=>(o==null?void 0:o.map(d=>{if(d.kind!=="todo"||d.todo.id!==t)return d;const g=d.todo.status==="done";return{...d,todo:{...d.todo,status:g?"open":"done",completedAt:g?void 0:Date.now(),updatedAt:Date.now()}}}))??null)},onUpdateTodo:(t,o)=>{n({type:"todo/update",todoId:t,title:o.title,dueDateKey:o.dueDateKey,dueTime:o.dueTime,folderId:o.folderId,folderName:o.folderName}),c(d=>(d==null?void 0:d.map(g=>g.kind!=="todo"||g.todo.id!==t?g:{...g,todo:{...g.todo,title:o.title,dueDateKey:o.dueDateKey,dueTime:o.dueTime,updatedAt:Date.now()}}))??null)},onDeleteTodo:t=>{n({type:"todo/delete",todoId:t}),c(o=>{const d=(o==null?void 0:o.filter(g=>g.kind!=="todo"||g.todo.id!==t))??[];return d.length?d:null})},onDeleteTodoEvent:t=>{n({type:"todo/toggle",todoId:t}),c(o=>{const d=(o==null?void 0:o.filter(g=>g.kind!=="event"||g.event.sourceTodoId!==t))??[];return d.length?d:null})},onOpenTodoEditor:t=>{c(null),b(t)}}):null,a?e.jsx(Vt,{dateKey:a.dateKey,startedAt:a.startedAt,onClose:()=>j(null),onSave:t=>{const o=pt(t,a.startedAt,a.dateKey);if(!o.title.trim()){j(null);return}n({type:"event/create",label:o.title,dateKey:a.dateKey,loggedAt:o.loggedAt}),j(null)}}):null,W&&W.sourceType!=="todo_completed"?e.jsx(yt,{event:W,selectedDateKey:W.createdDateKey,onClose:()=>x(null),onSave:t=>{n({type:"event/update",eventId:W.id,label:t.label,notes:t.notes,hashtags:t.hashtags,loggedAt:t.loggedAt}),x(null)},onDelete:()=>{n({type:"event/delete",eventId:W.id}),x(null)}}
6):null,B?e.jsx(xt,{todo:B,folders:s.todoFolders,selectedFolderId:B.folderId,selectedDateKey:B.dueDateKey??B.createdDateKey,onClose:()=>b(null),onToggle:t=>{n({type:"todo/toggle",todoId:t})},onSave:t=>{n({type:"todo/update",todoId:B.id,title:t.title,dueDateKey:t.dueDateKey,dueTime:t.dueTime,hashtags:t.hashtags,folderId:t.folderId,folderName:t.folderName,recurrence:t.recurrence,reminderEveryMinutes:t.reminderEveryMinutes,reminderUntil:t.reminderUntil}),b(null)}}):null]})}export{bs as EventScreen};
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.