@augmentd-labs/canvas-web 2.26.35 → 2.26.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/assets/CalendarApplet-CI650A38.js +2 -0
  2. package/dist/assets/{FiltersApplet-NltVCRY8.js → FiltersApplet-Ia3RTHqt.js} +1 -1
  3. package/dist/assets/{HomeFab-Cc33x4F2.js → HomeFab-CXuEjvlA.js} +1 -1
  4. package/dist/assets/{LensApplet-D-E4YyKz.js → LensApplet-DxqrTTvu.js} +1 -1
  5. package/dist/assets/{NotesApplet-DZ7lSkfC.js → NotesApplet-ALnJx1R5.js} +1 -1
  6. package/dist/assets/{_agentId_-BuZ9wBek.js → _agentId_-DiuSEd4O.js} +0 -0
  7. package/dist/assets/{_contextId_-DURo7ANU.js → _contextId_-Bovrvd2T.js} +1 -1
  8. package/dist/assets/{_workspaceName_-JpQwQGvI.js → _workspaceName_-DXYHTbna.js} +1 -1
  9. package/dist/assets/{about-BpN8_1bC.js → about-CIz-eZ-8.js} +1 -1
  10. package/dist/assets/{add-B7zdhw47.js → add-Cf7qavr8.js} +1 -1
  11. package/dist/assets/{agents-ChD6m_5J.js → agents-t82sp0lw.js} +1 -1
  12. package/dist/assets/{appearance-DEL04cKR.js → appearance-Ba1GYZ_J.js} +1 -1
  13. package/dist/assets/{apps-BYrwwspU.js → apps-uPsYOOCl.js} +1 -1
  14. package/dist/assets/{content-app-view-Dcknmau8.js → content-app-view-DfmmWQ_z.js} +1 -1
  15. package/dist/assets/{home-Bg5pLpIh.js → home-CsrwkvZX.js} +1 -1
  16. package/dist/assets/{index-VAgMESOp.js → index-DRHEGJ8I.js} +2 -2
  17. package/dist/assets/{key-bindings--OI4Iz7e.js → key-bindings-CnvBrNMZ.js} +1 -1
  18. package/dist/assets/{registry-DQPkddij.js → registry-9MElXU-U.js} +2 -2
  19. package/dist/assets/{settings-B6TQfRMQ.js → settings-B9-XHGdl.js} +1 -1
  20. package/dist/assets/{settings-CljJz3ui.js → settings-CUxtVfMx.js} +1 -1
  21. package/dist/assets/{settings-BQmgBTa-.js → settings-Dkb35vRa.js} +1 -1
  22. package/dist/assets/{settings-BgqCRJzb.js → settings-DxEF5yL8.js} +1 -1
  23. package/dist/assets/{share-target-BZmiLt2r.js → share-target-DJICHfZZ.js} +1 -1
  24. package/dist/assets/{shared-qweQ1MKt.js → shared-DmdHUnl7.js} +1 -1
  25. package/dist/assets/{useAgentModels-Bda5ilvQ.js → useAgentModels-BjT4oN4e.js} +1 -1
  26. package/dist/assets/{workspaces-BK7Rj72s.js → workspaces-DpVuDD1E.js} +1 -1
  27. package/dist/index.html +2 -2
  28. package/dist/sw.js +1 -1
  29. package/package.json +2 -2
  30. package/dist/assets/CalendarApplet-gN_A0sQe.js +0 -2
@@ -1,2 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{l as t,u as n}from"./code-editor-BOIngd5F.js";import{g as r,r as i}from"./chunk-62JRHF6Z-vspAGgtK.js";import{Fr as a,Hr as o,Jr as s,L as c,Ot as l,Pt as u,Vr as d,X as f,ct as p,et as m,fr as h,jr as g,mr as _,pn as v,qr as y,vn as b}from"./ui-CDoK3F3U.js";import{t as x}from"./utils-2pl1SbIp.js";import{h as S}from"./LinkToCard-BQ1yoFDr.js";import{Hn as C,In as w,St as T,jt as E,rt as D,vn as ee,w as te,wn as O}from"./workspace-BJELPCNs.js";import{o as ne,t as k}from"./useAddTarget-B3b6TyZr.js";import{a as A,o as j}from"./context-DZ1Hn7tt.js";import{n as M,o as N,s as P,t as F}from"./date-time-picker-txVhlNO0.js";import{n as re}from"./use-applet-target-ffIGaAqT.js";import{y as I}from"./index-VAgMESOp.js";import{r as ie,t as ae}from"./shared-BnpwVpxG.js";var L=e(n(),1),oe=864e5,se=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function R(e){return String(e).padStart(2,`0`)}function z(e){return`${e.getFullYear()}-${R(e.getMonth()+1)}-${R(e.getDate())}`}function B(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r)}function ce(e){return`${z(e)}T${R(e.getHours())}:${R(e.getMinutes())}`}function V(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function H(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate()+t,e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}function le(e,t){return new Date(e.getFullYear(),e.getMonth()+t,1)}function ue(e){let t=V(e);return H(t,-((t.getDay()+6)%7))}function de(e){return new Date(e.getFullYear(),e.getMonth(),1)}function U(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function fe(e){let t=ue(de(e));return Array.from({length:42},(e,n)=>H(t,n))}function W(e,t){let n=[],r=t.getTime()>e.getTime()?new Date(t.getTime()-1):e;for(let t=V(e);t.getTime()<=r.getTime();t=H(t,1))n.push(t);return n}function G(e,t){let n=e.getTime()-V(t).getTime();return Math.max(0,Math.min(oe,n))/6e4}var pe=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}),K=new Intl.DateTimeFormat(void 0,{month:`short`}),me=new Intl.DateTimeFormat(void 0,{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),q=new Intl.DateTimeFormat(void 0,{weekday:`short`,day:`numeric`,month:`short`}),J=new Intl.DateTimeFormat(void 0,{hour:`numeric`,minute:`2-digit`});function he(e){return pe.format(e)}function ge(e){return K.format(e)}function Y(e){return me.format(e)}function X(e){return q.format(e)}function Z(e){return J.format(e)}function _e(e,t){return U(e,t)?Y(e):e.getFullYear()===t.getFullYear()?e.getMonth()===t.getMonth()?`${e.getDate()} – ${t.getDate()} ${K.format(e)} ${e.getFullYear()}`:`${e.getDate()} ${K.format(e)} – ${t.getDate()} ${K.format(t)} ${t.getFullYear()}`:`${e.getDate()} ${K.format(e)} ${e.getFullYear()} – ${t.getDate()} ${K.format(t)} ${t.getFullYear()}`}function ve(e){return _e(e,H(e,6))}function ye(e){return J.format(new Date(2e3,0,1,e,0)).replace(/:00(?=\s|$)/,``)}var be={SU:0,MO:1,TU:2,WE:3,TH:4,FR:5,SA:6},xe=new Set([`FREQ`,`INTERVAL`,`COUNT`,`UNTIL`,`BYDAY`,`BYMONTHDAY`,`BYMONTH`,`WKST`]);function Se(e){let t={};for(let n of e.replace(/^RRULE:/i,``).split(`;`)){let e=n.trim();if(!e)continue;let r=e.indexOf(`=`);if(r<1)return null;t[e.slice(0,r).toUpperCase()]=e.slice(r+1).toUpperCase()}if(Object.keys(t).some(e=>!xe.has(e)))return null;let n=t.FREQ;if(n!==`DAILY`&&n!==`WEEKLY`&&n!==`MONTHLY`&&n!==`YEARLY`)return null;let r=t.INTERVAL?Number(t.INTERVAL):1;if(!Number.isInteger(r)||r<1)return null;let i=t.COUNT?Number(t.COUNT):null;if(i!==null&&(!Number.isInteger(i)||i<1))return null;let a=null;if(t.UNTIL){let e=/^(\d{4})(\d{2})(\d{2})(?:T(\d{2})(\d{2})(\d{2})(Z?))?$/.exec(t.UNTIL);if(!e)return null;let[,n,r,i,o,s,c,l]=e;if(a=o===void 0?new Date(Number(n),Number(r)-1,Number(i),23,59,59,999):l?new Date(Date.UTC(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c))):new Date(Number(n),Number(r)-1,Number(i),Number(o),Number(s),Number(c)),Number.isNaN(a.getTime()))return null}let o=[];if(t.BYDAY)for(let e of t.BYDAY.split(`,`)){let t=/^([+-]?\d{1,2})?(SU|MO|TU|WE|TH|FR|SA)$/.exec(e.trim());if(!t)return null;o.push({day:be[t[2]],ordinal:t[1]?Number(t[1]):null})}let s=t.BYMONTHDAY?t.BYMONTHDAY.split(`,`).map(Number):[];if(s.some(e=>!Number.isInteger(e)||e===0||e<-31||e>31))return null;let c=t.BYMONTH?t.BYMONTH.split(`,`).map(Number):[];return c.some(e=>!Number.isInteger(e)||e<1||e>12)||o.some(e=>e.ordinal!==null)&&n!==`MONTHLY`&&n!==`YEARLY`?null:{freq:n,interval:r,count:i,until:a,byDay:o,byMonthDay:s,byMonth:c}}function Ce(e,t){return new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds())}function we(e,t){return new Date(e,t+1,0).getDate()}function Te(e,t,n,r){let i=we(e,t),a=new Set;if(n.byMonthDay.length)for(let e of n.byMonthDay){let t=e>0?e:i+1+e;t>=1&&t<=i&&a.add(t)}if(n.byDay.length){let r=new Set;for(let{day:a,ordinal:o}of n.byDay){let n=[];for(let r=1;r<=i;r++)new Date(e,t,r).getDay()===a&&n.push(r);if(o===null)n.forEach(e=>r.add(e));else{let e=o>0?n[o-1]:n[n.length+o];e&&r.add(e)}}if(n.byMonthDay.length)for(let e of[...a])r.has(e)||a.delete(e);else r.forEach(e=>a.add(e))}return!n.byMonthDay.length&&!n.byDay.length&&r.getDate()<=i&&a.add(r.getDate()),[...a].sort((e,t)=>e-t).map(n=>Ce(new Date(e,t,n),r))}function Ee(e,t,n,r,i=0,a=5e3){let o=[],s=n.getTime()-Math.max(0,i),c=r.getTime(),l=0,u=t=>{let n=t.getTime();return e.until&&n>e.until.getTime()||(l++,n>=s&&n<c&&o.push(t),e.count!==null&&l>=e.count)?!1:l<a};if(!u(t))return o;let d=t.getTime();if(e.freq===`DAILY`){for(let n=e.interval,r=0;r<a*12;n+=e.interval,r++){let r=Ce(new Date(t.getFullYear(),t.getMonth(),t.getDate()+n),t);if(r.getTime()>=c&&e.count===null||!(e.byMonth.length&&!e.byMonth.includes(r.getMonth()+1))&&!u(r))break}return o}if(e.freq===`WEEKLY`){let n=e.byDay.length?[...new Set(e.byDay.map(e=>e.day))]:[t.getDay()],r=new Date(t.getFullYear(),t.getMonth(),t.getDate()-(t.getDay()+6)%7);for(let i=0;;i+=e.interval){let a=new Date(r.getFullYear(),r.getMonth(),r.getDate()+i*7);if(a.getTime()>=c+6048e5&&e.count===null)break;let o=!1;for(let e=0;e<7;e++){let r=new Date(a.getFullYear(),a.getMonth(),a.getDate()+e);if(!n.includes(r.getDay()))continue;let i=Ce(r,t);if(!(i.getTime()<=d)&&!u(i)){o=!0;break}}if(o)break}return o}let f=e.freq===`MONTHLY`?e.interval:12*e.interval;for(let n=0;;n+=f){let r=t.getFullYear()+Math.floor((t.getMonth()+n)/12),i=(t.getMonth()+n)%12;if(new Date(r,i,1).getTime()>=c&&e.count===null)break;if(e.freq===`YEARLY`&&e.byMonth.length&&!e.byMonth.includes(i+1)){let n=!1;for(let i of e.byMonth){for(let a of Te(r,i-1,e,t))if(!(a.getTime()<=d)&&!u(a)){n=!0;break}if(n)break}if(n)break;continue}if(e.freq===`MONTHLY`&&e.byMonth.length&&!e.byMonth.includes(i+1))continue;let a=!1;for(let n of Te(r,i,e,t))if(!(n.getTime()<=d)&&!u(n)){a=!0;break}if(a||n>4800)break}return o}function De(e){let t={DAILY:`day`,WEEKLY:`week`,MONTHLY:`month`,YEARLY:`year`}[e.freq],n=e.interval===1?`Every ${t}`:`Every ${e.interval} ${t}s`,r=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];return e.byDay.length?n+=` on `+e.byDay.map(({day:e,ordinal:t})=>t===null?r[e]:`${t===-1?`last`:`${t}.`} ${r[e]}`).join(`, `):e.byMonthDay.length&&(n+=` on day `+e.byMonthDay.join(`, `)),e.count!==null&&(n+=`, ${e.count} times`),e.until&&(n+=` until ${e.until.toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`})}`),n}function Oe(e){if(!e)return`none`;let t=Se(e);return!t||t.count!==null||t.until||t.interval!==1||t.byMonthDay.length||t.byMonth.length?`custom`:t.freq===`WEEKLY`&&t.byDay.length===5&&t.byDay.every(e=>e.ordinal===null&&e.day>=1&&e.day<=5)?`weekdays`:t.byDay.length?`custom`:{DAILY:`daily`,WEEKLY:`weekly`,MONTHLY:`monthly`,YEARLY:`yearly`}[t.freq]}function ke(e){switch(e){case`daily`:return`FREQ=DAILY`;case`weekly`:return`FREQ=WEEKLY`;case`monthly`:return`FREQ=MONTHLY`;case`yearly`:return`FREQ=YEARLY`;case`weekdays`:return`FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR`;default:return}}var Ae=`tasks`,je=`data/schema/event`,Me=`data/schema/task`;function Ne(e){if(typeof e!=`string`||!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function Pe(e){return new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate())}function Fe(e){return e.schema.startsWith(je)}function Ie(e){return e.schema===Me}function Le(e,t,n){let r=e.data??{};if(Ie(e)){let i=Ne(r.dueDate);if(!i||i<t||i>=n)return[];let a=String(r.status??`pending`);return[{key:`${e.id}@${i.getTime()}`,doc:e,kind:`task`,title:String(r.title??`Untitled`),start:i,end:i,allDay:!1,calendar:Ae,recurring:!1,unsupportedRule:!1,done:a===`completed`||a===`cancelled`}]}if(!Fe(e))return[];let i=Ne(r.start);if(!i)return[];let a=r.allDay===!0,o=r.end===null?null:Ne(r.end),s=a?Pe(i):i,c=a?o?Pe(o):H(s,1):o??(r.end===null?n:s),l=Math.max(0,c.getTime()-s.getTime()),u={doc:e,kind:`event`,title:String(r.title??`Untitled`),allDay:a,calendar:typeof r.calendar==`string`?r.calendar:``,done:!1},d=typeof r.recurrence==`string`?r.recurrence:``;if(!d)return c.getTime()<=t.getTime()&&!(c.getTime()===s.getTime()&&s>=t)||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!1,unsupportedRule:!1}];let f=Se(d);return f?Ee(f,s,t,n,l).map(t=>({...u,key:`${e.id}@${t.getTime()}`,start:t,end:new Date(t.getTime()+l),recurring:!0,unsupportedRule:!1})):c<=t||s>=n?[]:[{...u,key:`${e.id}@${s.getTime()}`,start:s,end:c,recurring:!0,unsupportedRule:!0}]}function Re(e,t,n){return e.flatMap(e=>Le(e,t,n)).sort((e,t)=>e.start.getTime()-t.start.getTime()||t.end.getTime()-e.end.getTime()||e.title.localeCompare(t.title))}function ze(e){let t=new Map;for(let n of e)for(let e of W(n.start,n.end)){let r=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`,i=t.get(r);i?i.push(n):t.set(r,[n])}return t}function Be(e){return e.allDay||e.end.getTime()-e.start.getTime()>=864e5||!U(e.start,new Date(e.end.getTime()-1))&&e.end.getTime()>e.start.getTime()}function Ve(e,t,n=30){let r=V(e),i=t.filter(e=>!Be(e)).map(e=>{let t=G(e.start,r),i=Math.max(n,G(e.end,r)-t);return{occurrence:e,top:t,height:Math.min(i,1440-t),column:0,columns:1}}).sort((e,t)=>e.top-t.top||t.height-e.height),a=[],o=-1,s=()=>{let e=[];for(let t of a){let n=e.findIndex(e=>e<=t.top);n<0&&(n=e.length,e.push(0)),e[n]=t.top+t.height,t.column=n}for(let t of a)t.columns=e.length;a=[]};for(let e of i)a.length&&e.top>=o&&s(),a.push(e),o=Math.max(o,e.top+e.height);return a.length&&s(),i}function He(e,t,n,r){if(t.kind===`task`)return{...e,dueDate:n.toISOString()};if(t.allDay)return{...e,start:`${z(n)}T00:00:00.000Z`,end:`${z(r)}T00:00:00.000Z`};let i={...e,start:n.toISOString()};return e.end===null||(r.getTime()>n.getTime()?i.end=r.toISOString():delete i.end),i}var Ue=[{id:`day`,label:`Day`,key:`d`},{id:`week`,label:`Week`,key:`w`},{id:`month`,label:`Month`,key:`m`},{id:`year`,label:`Year`,key:`y`},{id:`schedule`,label:`Schedule`,key:`s`}],We={view:`week`,hidden:[],showTasks:!0,defaultCalendar:`Personal`},Ge=`canvas:calendar:prefs`;function Ke(e){return`${Ge}:${e??`global`}`}function qe(e){try{let t=JSON.parse(localStorage.getItem(Ke(e))||`null`);if(!t||typeof t!=`object`)return We;let n=t;return{view:Ue.some(e=>e.id===n.view)?n.view:We.view,hidden:Array.isArray(n.hidden)?n.hidden.filter(e=>typeof e==`string`):[],showTasks:n.showTasks!==!1,defaultCalendar:typeof n.defaultCalendar==`string`&&n.defaultCalendar.trim()?n.defaultCalendar:We.defaultCalendar}}catch{return We}}function Je(e,t){try{localStorage.setItem(Ke(e),JSON.stringify(t))}catch{}}function Ye(e,t){let n=z(H(V(e),-1)),r=z(H(V(t),1));return{events:`t:events:${n}..${r}`,tasks:`t:tasks:${n}..${r}`}}var Xe=5e3;function Ze(e){return!!e&&!e.includes(`:`)&&![`content`,`events`,`tasks`].includes(e.toLowerCase())}function Qe(e){return e?e.mode===`context`?`ctx:${e.contextId}`:`${e.workspaceName}:${e.treeName}:${e.treeType}:${e.path}`:``}function $e(e,t,n,r){let[i,a]=(0,L.useState)([]),[o,s]=(0,L.useState)(!1),[c,l]=(0,L.useState)(null),[u,d]=(0,L.useState)(null),[f,p]=(0,L.useState)([]),m=t.getTime(),h=n.getTime(),g=(0,L.useCallback)(()=>{if(!e)return Promise.resolve();let t=Ye(new Date(m),new Date(h));return(e.mode===`context`?Promise.all([j(e.contextId,[w],[t.events],{limit:Xe}),r?j(e.contextId,[C],[t.tasks],{limit:Xe}):Promise.resolve([]),A(e.contextId)]).then(([e,t,n])=>{a([...e,...t]);let r=n.workspaceName||n.workspaceId;d(r?{workspaceName:r,path:n.path||`/`,treeName:n.treeId||`context`,treeType:`context`}:null)}):(()=>{let{workspaceName:n,path:i,treeName:o,treeType:s}=e,c={treeName:o,treeType:s,limit:0};return Promise.all([D(n,i,[w],{...c,filters:[t.events]}),r?D(n,i,[C],{...c,filters:[t.tasks]}):Promise.resolve({payload:[]})]).then(([e,t])=>{a([...e.payload||[],...t.payload||[]]),d({workspaceName:n,path:i,treeName:o,treeType:s})})})()).catch(e=>l(e instanceof Error?e.message:`Failed to load calendar`)).finally(()=>s(!1))},[e,m,h,r]),_=(0,L.useCallback)(async()=>{if(!e){a([]),d(null);return}s(!0),l(null),await g()},[e,g]),[v,y]=(0,L.useState)(null),b=`${Qe(e)}|${m}|${h}|${r}`;v!==b&&(y(b),e?(s(!0),l(null)):(a([]),d(null))),(0,L.useEffect)(()=>{g()},[g]),(0,L.useEffect)(()=>{let e=()=>{_()};return window.addEventListener(`workspace:documents:refresh`,e),()=>window.removeEventListener(`workspace:documents:refresh`,e)},[_]);let x=u?.workspaceName??null,S=(0,L.useCallback)(()=>x?Promise.all([T(x),E(x)]).then(([e,t])=>{let n=new Set;for(let t of e)t.startsWith(`data/calendar/`)&&t.length>14&&n.add(t.slice(14));for(let e of t)Ze(e.name)&&n.add(e.name);p([...n].sort())}).catch(()=>{}):Promise.resolve(),[x]);(0,L.useEffect)(()=>{S()},[S,i.length]),(0,L.useEffect)(()=>{let e=()=>{S()};return window.addEventListener(`workspace:timelines:changed`,e),()=>window.removeEventListener(`workspace:timelines:changed`,e)},[S]);let ee=(0,L.useCallback)(async e=>{if(!u)throw Error(`No workspace scope resolved`);await te(u.workspaceName,[e],u.path,[],u.treeName,u.treeType),a(t=>t.filter(t=>t.id!==e))},[u]),O=(0,L.useCallback)(e=>{a(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e])},[]);return(0,L.useMemo)(()=>({docs:i,loading:o,error:c,scope:u,knownCalendars:f,reload:_,removeDoc:ee,patchDoc:O}),[i,o,c,u,f,_,ee,O])}function et(e){return I(e?e.toLowerCase():`events`)}function tt(e){return e.kind===`task`?I(Ae):et(e.calendar)}function nt(e,t=18){return`color-mix(in oklch, ${e} ${t}%, transparent)`}function rt(e,t,n,r,i,a=30){let o=Math.max(0,Math.min(e.length-1,t)),s=Math.max(0,Math.min(e.length-1,r));if(o!==s){let[t,n]=o<s?[o,s]:[s,o];return{start:V(e[t]),end:H(V(e[n]),1),allDay:!0}}let c=e=>Math.floor(e/a)*a,l=c(Math.min(n,i)),u=c(Math.max(n,i))+a;l=Math.max(0,Math.min(1440-a,l)),u=Math.max(l+a,Math.min(1440,u));let d=V(e[o]);return{start:new Date(d.getTime()+l*6e4),end:new Date(d.getTime()+u*6e4),allDay:!1}}function it(e,t){let[n,r]=e.getTime()<=t.getTime()?[e,t]:[t,e];return{start:V(n),end:H(V(r),1),allDay:!0}}function at(e,t,n,r,i,a,o=15){let s=t=>Math.max(0,Math.min(e.length-1,t)),c=s(i)-s(n),l=Math.round((a-r)/o)*o,u=t.end.getTime()-t.start.getTime(),d=H(t.start,c),f=V(d),p=Math.max(0,Math.min(1440-o,(d.getTime()-f.getTime())/6e4+l)),m=new Date(f.getTime()+p*6e4);return{start:m,end:new Date(m.getTime()+u)}}function ot(e,t,n,r,i=15){let a=V(e[Math.max(0,Math.min(e.length-1,n))]),o=Math.min(1440,Math.ceil(r/i)*i),s=new Date(a.getTime()+o*6e4);return{start:t.start,end:s.getTime()<t.start.getTime()+i*6e4?new Date(t.start.getTime()+i*6e4):s}}function st(e,t){return{start:H(e.start,t),end:H(e.end,t)}}var Q=t();function ct({month:e,selection:t,marks:n,onPick:r,onPickRange:i,onPrev:a,onNext:s,onTitle:c,onDayMenu:l,title:u,className:f}){let p=new Date,m=fe(e),h=u??he(e),[g,_]=(0,L.useState)(null),v=(0,L.useRef)(g);(0,L.useEffect)(()=>{v.current=g});let y=(0,L.useRef)(!1),b=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,S=e=>{if(!i||e.button!==0)return;let t=b(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},C=e=>{if(!v.current)return;let t=b(e);t&&t!==v.current.to&&_({...v.current,to:t})},w=e=>{let t=v.current;if(!t||(e.currentTarget.releasePointerCapture(e.pointerId),_(null),t.from===t.to))return;y.current=!0,setTimeout(()=>{y.current=!1},0);let n=it(B(t.from),B(t.to));i?.(n.start,n.end)},T=(e,n)=>{if(y.current){y.current=!1;return}if(e.shiftKey&&i&&t){let e=it(t.start,n);i(e.start,e.end)}else r(n)},E=g?it(B(g.from),B(g.to)):t;return(0,Q.jsxs)(`div`,{className:x(`select-none`,f),children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[a?(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,Q.jsx)(o,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{}),c?(0,Q.jsx)(`button`,{type:`button`,onClick:c,className:`text-xs font-semibold hover:underline`,children:h}):(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:h}),s?(0,Q.jsx)(`button`,{type:`button`,onClick:s,className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,Q.jsx)(d,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-7 text-center text-[10px] text-muted-foreground`,children:se.map(e=>(0,Q.jsx)(`span`,{children:e[0]},e))}),(0,Q.jsx)(`div`,{className:x(`grid grid-cols-7 gap-y-px text-center text-[11px]`,g&&`cursor-crosshair`),onPointerDown:S,onPointerMove:C,onPointerUp:w,onPointerCancel:()=>_(null),children:m.map(t=>{let r=z(t),i=t.getMonth()===e.getMonth(),a=U(t,p),o=!!E&&t>=E.start&&t<E.end,s=!!E&&o&&U(t,E.start),c=!!E&&o&&U(t,new Date(E.end.getTime()-1)),u=n?.get(r)??[],d=[...new Set(u.map(tt))].slice(0,3);return(0,Q.jsxs)(`button`,{type:`button`,"data-day":r,onClick:e=>T(e,t),onContextMenu:l?e=>{e.preventDefault(),l(e,t)}:void 0,"aria-label":u.length?`${t.toDateString()}, ${u.length} ${u.length===1?`entry`:`entries`}`:t.toDateString(),title:u.length?u.slice(0,6).map(e=>e.title).join(`
2
- `)+(u.length>6?`\n+${u.length-6} more`:``):void 0,className:x(`relative mx-auto flex h-6 w-full items-center justify-center transition-colors hover:bg-muted`,s&&c?`rounded-full`:s?`rounded-l-full`:c?`rounded-r-full`:o?``:`rounded-full`,!i&&`text-muted-foreground/40`,a&&!o&&`font-bold text-primary`,o&&`bg-primary text-primary-foreground hover:bg-primary`,u.length>0&&!o&&`font-semibold`),style:u.length&&!o?{background:`color-mix(in srgb, ${d[0]} 22%, transparent)`}:void 0,children:[t.getDate(),u.length>0&&!o&&(0,Q.jsx)(`span`,{className:`absolute bottom-0 left-1/2 flex -translate-x-1/2 gap-px`,children:d.map(e=>(0,Q.jsx)(`span`,{className:`h-1 w-1 rounded-full`,style:{background:e}},e))})]},r)})})]})}function lt({occurrence:e,selected:t,moving:n,showTime:r=!0,onSelect:i,className:o,...s}){let c=tt(e),u=!e.allDay&&e.kind===`event`&&e.end.getTime()>e.start.getTime();return(0,Q.jsxs)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e)},title:`${e.title}${e.calendar?` · ${e.calendar}`:``}`,className:x(`flex w-full min-w-0 items-center gap-1 truncate rounded px-1 py-px text-left text-[11px] leading-4 text-foreground transition-colors hover:brightness-110`,!e.recurring&&`touch-none`,t&&`ring-1 ring-ring`,n&&`cursor-grabbing ring-2 ring-primary shadow-elevation-2`,e.done&&`line-through opacity-60`,o),style:{background:nt(c,e.allDay||e.kind===`task`?28:14),borderLeft:`3px solid ${c}`},...s,children:[e.kind===`task`&&(0,Q.jsx)(a,{className:`h-3 w-3 shrink-0`,style:{color:c}}),r&&u&&(0,Q.jsx)(`span`,{className:`shrink-0 tabular-nums text-muted-foreground`,children:Z(e.start)}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.recurring&&(0,Q.jsx)(l,{className:`ml-auto h-2.5 w-2.5 shrink-0 text-muted-foreground`})]})}function ut(e){let[t,n]=(0,L.useState)(null),r=(0,L.useRef)(null),i=(0,L.useRef)(!1),a=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null;return{moving:t,handlers:t=>t.recurring?{}:{onPointerDown:e=>{if(e.button!==0)return;let n=a(e);n&&(e.currentTarget.setPointerCapture(e.pointerId),r.current={o:t,fromKey:n,delta:0})},onPointerMove:e=>{let t=r.current;if(!t)return;let i=a(e);if(!i)return;let o=Math.round((B(i).getTime()-B(t.fromKey).getTime())/oe);o!==t.delta&&(t.delta=o,n(o?{key:t.o.key,...st(t.o,o)}:null))},onPointerUp:t=>{let a=r.current;if(r.current=null,!a||(t.currentTarget.releasePointerCapture(t.pointerId),n(null),!a.delta))return;i.current=!0,setTimeout(()=>{i.current=!1},0);let o=st(a.o,a.delta);e(a.o,o.start,o.end)},onPointerCancel:()=>{r.current=null,n(null)},onClickCapture:e=>{i.current&&(i.current=!1,e.stopPropagation(),e.preventDefault())}},apply:e=>t?e.map(e=>e.key===t.key?{...e,start:t.start,end:t.end}:e):e}}var $=48,dt=30,ft=15,pt=`w-12`,mt=48;function ht({days:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,compact:u}){let d=(0,L.useRef)(null),f=(0,L.useRef)(null),[p,m]=(0,L.useState)(null),h=(0,L.useRef)(p);(0,L.useEffect)(()=>{h.current=p});let g=t=>{let n=f.current;if(!n)return null;let r=n.getBoundingClientRect(),i=(r.width-mt)/e.length,a=Math.floor((t.clientX-r.left-mt)/i),o=Math.max(0,Math.min(1439,(t.clientY-r.top)/$*60));return a<0||a>=e.length?null:{day:a,min:o}},_=e=>{if(e.button!==0||e.target.closest(`button`))return;let t=g(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),m({fromDay:t.day,fromMin:t.min,toDay:t.day,toMin:t.min}))},v=e=>{if(!h.current)return;let t=g(e);t&&m({...h.current,toDay:t.day,toMin:t.min})},y=t=>{let n=h.current;if(!n)return;t.currentTarget.releasePointerCapture(t.pointerId),m(null);let r=rt(e,n.fromDay,n.fromMin,n.toDay,n.toMin,dt);a(r.start,r.allDay,r.end)},b=t=>{let n=g(t);n&&(t.preventDefault(),l(t,rt(e,n.day,n.min,n.day,n.min,dt).start,!1))},S=p?rt(e,p.fromDay,p.fromMin,p.toDay,p.toMin,dt):r,[C,w]=(0,L.useState)(null),T=(0,L.useRef)(C);(0,L.useEffect)(()=>{T.current=C});let E=(0,L.useRef)(null),D=(0,L.useRef)(!1),ee=(e,t)=>{if(e.button!==0||t.recurring)return;let n=g(e);n&&(e.currentTarget.setPointerCapture(e.pointerId),E.current={o:t,mode:e.target.dataset.resize?`resize`:`move`,fromDay:n.day,fromMin:n.min})},te=t=>{let n=E.current;if(!n)return;let r=g(t);if(!r)return;let i=n.mode===`move`?at(e,n.o,n.fromDay,n.fromMin,r.day,r.min,ft):ot(e,n.o,r.day,r.min,ft),a=i.start.getTime()===n.o.start.getTime()&&i.end.getTime()===n.o.end.getTime();w(a?null:{key:n.o.key,...i,mode:n.mode})},O=e=>{let t=E.current;if(E.current=null,!t)return;e.currentTarget.releasePointerCapture(e.pointerId);let n=T.current;w(null),n&&(D.current=!0,setTimeout(()=>{D.current=!1},0),o(t.o,n.start,n.end))},ne=ut(o),k=ne.apply(t),A=(0,L.useMemo)(()=>C?k.map(e=>e.key===C.key?{...e,start:C.start,end:C.end}:e):k,[k,C]),j=(0,L.useMemo)(()=>ze(A),[A]),[M,N]=(0,L.useState)(()=>new Date);(0,L.useEffect)(()=>{let e=setInterval(()=>N(new Date),6e4);return()=>clearInterval(e)},[]);let P=z(e[0]);(0,L.useEffect)(()=>{let t=d.current;t&&(t.scrollTop=(e.some(e=>U(e,M))?Math.max(0,M.getHours()-1):7)*$)},[P,e.length]);let F=Array.from({length:24},(e,t)=>t),re=e.map(e=>(j.get(z(e))??[]).filter(Be)),I=Math.max(0,...re.map(e=>e.length)),ie=!!p||!!C||!!ne.moving;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 border-b border-border`,children:[(0,Q.jsx)(`div`,{className:x(pt,`shrink-0`)}),e.map(e=>{let t=U(e,M);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(e),className:`flex min-w-0 flex-1 flex-col items-center border-l border-border/60 py-1 hover:bg-muted/50`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:se[(e.getDay()+6)%7]}),(0,Q.jsx)(`span`,{className:x(`flex h-7 w-7 items-center justify-center rounded-full text-sm font-semibold`,t&&`bg-primary text-primary-foreground`),children:e.getDate()})]},z(e))})]}),I>0&&(0,Q.jsxs)(`div`,{className:x(`flex shrink-0 border-b border-border bg-muted/20`,ne.moving&&`select-none`),children:[(0,Q.jsx)(`div`,{className:x(pt,`shrink-0 py-1 pr-1 text-right text-[10px] text-muted-foreground`),children:u?``:`all day`}),e.map((e,t)=>(0,Q.jsx)(`div`,{"data-day":z(e),className:`flex min-w-0 flex-1 flex-col gap-0.5 border-l border-border/60 p-0.5`,onClick:t=>{t.target===t.currentTarget&&a(V(e),!0)},onContextMenu:t=>{t.preventDefault(),l(t,V(e),!0)},children:re[t].map(e=>(0,Q.jsx)(lt,{occurrence:e,selected:e.key===n,moving:ne.moving?.key===e.key,showTime:!1,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...ne.handlers(e)},e.key))},z(e)))]}),(0,Q.jsx)(`div`,{ref:d,className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Q.jsxs)(`div`,{ref:f,className:x(`relative flex select-none`,p&&`cursor-crosshair`,C?.mode===`move`&&`cursor-grabbing`,C?.mode===`resize`&&`cursor-ns-resize`),style:{height:1152},onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:()=>m(null),onContextMenu:b,children:[(0,Q.jsx)(`div`,{className:x(pt,`relative shrink-0`),children:F.map(e=>(0,Q.jsx)(`div`,{className:`absolute right-1 -translate-y-1/2 text-[10px] tabular-nums text-muted-foreground`,style:{top:e*$},children:e===0?``:ye(e)},e))}),e.map(e=>{let t=Ve(e,j.get(z(e))??[]),r=U(e,M)?(M.getHours()*60+M.getMinutes())/60*$:null;return(0,Q.jsxs)(`div`,{"data-day":z(e),className:`relative min-w-0 flex-1 cursor-cell border-l border-border/60`,role:`presentation`,children:[S&&S.end>e&&S.start<V(new Date(e.getTime()+864e5))&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0.5 z-[5] rounded-md border border-primary bg-primary/15`,style:{top:G(S.start,e)/60*$,height:Math.max(8,(G(S.end,e)-G(S.start,e))/60*$)},children:(0,Q.jsx)(`span`,{className:`absolute left-1 top-0.5 text-[10px] font-medium text-primary`,children:S.allDay?`All day`:`${Z(S.start)} – ${Z(S.end)}`})}),F.map(e=>(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 border-t border-border/50`,style:{top:e*$}},e)),t.map(e=>{let t=e.occurrence,r=tt(t),a=100/e.columns,o=e.height<45,s=C?.key===t.key,l=!t.recurring;return(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{if(e.stopPropagation(),D.current){D.current=!1;return}i(t)},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),c(e,t)},onPointerDown:e=>ee(e,t),onPointerMove:te,onPointerUp:O,onPointerCancel:()=>{E.current=null,w(null)},title:`${t.title} · ${Z(t.start)}${t.end>t.start?` – ${Z(t.end)}`:``}`,className:x(`absolute overflow-hidden rounded-md border-l-[3px] px-1.5 text-left text-[11px] leading-tight text-foreground shadow-elevation-1 transition-[filter] hover:brightness-110`,l&&`touch-none`,s?`z-20 ring-2 ring-primary shadow-elevation-2`:ie&&`pointer-events-none`,t.key===n&&!s&&`ring-1 ring-ring`,t.done&&`line-through opacity-60`),style:{top:e.top/60*$,height:Math.max(18,e.height/60*$-2),left:`calc(${e.column*a}% + 2px)`,width:`calc(${a}% - 4px)`,background:nt(r,24),borderLeftColor:r,paddingTop:o?1:3},children:[(0,Q.jsx)(`span`,{className:x(`font-medium`,o?`inline`:`block truncate`),children:t.title}),!o&&(0,Q.jsxs)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:[Z(t.start),t.end>t.start?` – ${Z(t.end)}`:``,t.calendar&&!u?` · ${t.calendar}`:``]}),l&&t.kind===`event`&&(0,Q.jsx)(`span`,{"data-resize":`1`,className:`absolute inset-x-0 bottom-0 h-1.5 cursor-ns-resize`})]},t.key)}),r!==null&&(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 z-10 border-t-2 border-destructive`,style:{top:r},children:(0,Q.jsx)(`span`,{className:`absolute -left-1 -top-[5px] h-2 w-2 rounded-full bg-destructive`})})]},z(e))})]})})]})}var gt=3;function _t({month:e,occurrences:t,selectedKey:n,pending:r,onSelect:i,onCreate:a,onMove:o,onPickDay:s,onEntryMenu:c,onSlotMenu:l,narrow:u}){let d=fe(e),f=ut(o),p=f.apply(t),m=(0,L.useMemo)(()=>ze(p),[p]),h=new Date,[g,_]=(0,L.useState)(null),v=(0,L.useRef)(g);(0,L.useEffect)(()=>{v.current=g});let y=e=>(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-day]`))?.dataset.day??null,b=e=>{if(u||e.button!==0||e.target.closest(`button`))return;let t=y(e);t&&(e.currentTarget.setPointerCapture(e.pointerId),_({from:t,to:t}))},S=e=>{if(!v.current)return;let t=y(e);t&&t!==v.current.to&&_({...v.current,to:t})},C=e=>{let t=v.current;if(!t)return;e.currentTarget.releasePointerCapture(e.pointerId),_(null);let n=it(B(t.from),B(t.to));a(n.start,!0,n.end)},w=e=>{let t=y(e);t&&(e.preventDefault(),l(e,B(t),!0))},T=g?it(B(g.from),B(g.to)):r;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsx)(`div`,{className:`grid shrink-0 grid-cols-7 border-b border-border text-center text-[10px] uppercase tracking-wide text-muted-foreground`,children:se.map(e=>(0,Q.jsx)(`span`,{className:`py-1`,children:u?e[0]:e},e))}),(0,Q.jsx)(`div`,{className:x(`grid min-h-0 flex-1 grid-cols-7 grid-rows-6 overflow-y-auto`,g&&`cursor-crosshair select-none`,f.moving&&`select-none`),onPointerDown:b,onPointerMove:S,onPointerUp:C,onPointerCancel:()=>_(null),onContextMenu:w,children:d.map(t=>{let r=z(t),a=m.get(r)??[],o=t.getMonth()===e.getMonth(),l=U(t,h),d=a.length-gt;return(0,Q.jsxs)(`div`,{role:`presentation`,"data-day":r,onClick:e=>{u&&e.target===e.currentTarget&&s(t)},className:x(`flex min-h-[3.5rem] min-w-0 flex-col gap-0.5 border-b border-r border-border/60 p-0.5`,!o&&`bg-muted/20 text-muted-foreground/60`,!u&&`cursor-cell`,T&&t>=T.start&&t<T.end&&`bg-primary/15 ring-1 ring-inset ring-primary`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:x(`mx-auto flex h-5 w-5 items-center justify-center rounded-full text-[11px] hover:bg-muted sm:mx-0`,l&&`bg-primary font-bold text-primary-foreground hover:bg-primary`),title:`Open day`,children:t.getDate()}),u?(0,Q.jsx)(`div`,{className:`flex flex-wrap justify-center gap-0.5 px-0.5`,children:a.slice(0,4).map(e=>(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full`,style:{background:tt(e)}},e.key))}):(0,Q.jsxs)(Q.Fragment,{children:[a.slice(0,gt).map(e=>(0,Q.jsx)(lt,{occurrence:e,selected:e.key===n,moving:f.moving?.key===e.key,onSelect:i,onContextMenu:t=>{t.preventDefault(),t.stopPropagation(),c(t,e)},...f.handlers(e)},e.key)),d>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(t),className:`px-1 text-left text-[10px] text-muted-foreground hover:text-foreground`,children:[`+`,d,` more`]})]})]},r)})})]})}function vt({year:e,occurrences:t,onPickDay:n,onPickRange:r,onPickMonth:i,onSlotMenu:a}){let o=(0,L.useMemo)(()=>ze(t),[t]),s=Array.from({length:12},(t,n)=>new Date(e,n,1));return(0,Q.jsx)(`div`,{className:`grid h-full min-h-0 grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-x-4 gap-y-5 overflow-y-auto p-3`,children:s.map(e=>(0,Q.jsx)(ct,{month:e,marks:o,title:e.toLocaleDateString(void 0,{month:`long`}),onTitle:()=>i(e),onPick:n,onPickRange:r,onDayMenu:(e,t)=>a(e,t,!0)},z(e)))})}function yt({occurrences:e,selectedKey:t,onSelect:n,onEntryMenu:r,onEarlier:i,onLater:a,onPickDay:o,loading:s}){let c=(0,L.useMemo)(()=>[...ze(e).entries()].sort(([e],[t])=>e.localeCompare(t)),[e]),l=new Date;return(0,Q.jsxs)(`div`,{className:`h-full min-h-0 overflow-y-auto`,children:[(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Earlier`})}),!s&&!c.length&&(0,Q.jsx)(`p`,{className:`py-10 text-center text-sm text-muted-foreground`,children:`Nothing scheduled in this range.`}),c.map(([e,i])=>{let a=B(e),s=U(a,l);return(0,Q.jsxs)(`div`,{className:`flex border-t border-border/60 px-2 py-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(a),className:`flex w-14 shrink-0 flex-col items-start`,title:`Open day`,children:[(0,Q.jsx)(`span`,{className:x(`flex h-8 w-8 items-center justify-center rounded-full text-lg font-semibold`,s&&`bg-primary text-primary-foreground`),children:a.getDate()}),(0,Q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:[ge(a),`, `,se[(a.getDay()+6)%7]]})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:i.map(e=>{let i=tt(e),a=!Be(e)&&e.kind===`event`;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),onContextMenu:t=>{t.preventDefault(),r(t,e)},className:x(`flex w-full items-center gap-2 rounded-md px-2 py-1 text-left text-sm hover:bg-muted`,e.key===t&&`bg-muted ring-1 ring-ring`,e.done&&`line-through opacity-60`),children:[(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-full`,style:{background:i}}),(0,Q.jsx)(`span`,{className:`w-[7.5rem] shrink-0 text-xs tabular-nums text-muted-foreground`,children:a?`${Z(e.start)}${e.end>e.start?` – ${Z(e.end)}`:``}`:e.kind===`task`?`due ${Z(e.start)}`:`All day`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title}),e.calendar&&e.kind===`event`&&(0,Q.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:e.calendar})]},e.key)})})]},e)}),(0,Q.jsx)(`div`,{className:`flex justify-center py-2`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:a,className:`rounded-md border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:`Later`})})]})}var bt=`3.0`,xt=[{id:`none`,label:`Does not repeat`},{id:`daily`,label:`Every day`},{id:`weekdays`,label:`Every weekday`},{id:`weekly`,label:`Every week`},{id:`monthly`,label:`Every month`},{id:`yearly`,label:`Every year`},{id:`custom`,label:`Custom (RRULE)…`}];function St(e,t){let n=e.data??{},r=n.allDay===!0,i=String(n.start??``),a=typeof n.end==`string`?n.end:``,o=typeof n.recurrence==`string`?n.recurrence:``,s=Oe(o||void 0);return{title:String(n.title??``),calendar:typeof n.calendar==`string`?n.calendar:wt(e)?``:t,allDay:r,start:r?i.slice(0,10):N(i),end:r?Tt(i.slice(0,10),a):N(a),location:String(n.location??``),description:String(n.description??``),repeat:s,rrule:o}}function Ct(e,t){let n=e.end??new Date(e.start.getTime()+36e5);return{title:``,calendar:t,allDay:e.allDay,start:e.allDay?z(e.start):ce(e.start),end:e.allDay?z(H(n,-1)<e.start?e.start:H(n,-1)):ce(n),location:``,description:``,repeat:`none`,rrule:``}}function wt(e){let t=e.metadata;return typeof t?.source==`string`&&t.source?{source:t.source,connector:typeof t.connector==`string`?t.connector:``}:null}function Tt(e,t){if(!t)return``;let[n,r,i]=t.slice(0,10).split(`-`).map(Number),a=z(new Date(n,r-1,i-1));return a<e?e:a}function Et(e){return`${z(H(B(e),1))}T00:00:00.000Z`}function Dt(e,t){let n={...e,title:t.title.trim()},r=(e,t)=>{t===void 0||t===``||t===!1?delete n[e]:n[e]=t};return r(`calendar`,t.calendar.trim()),r(`allDay`,t.allDay),r(`location`,t.location.trim()),r(`description`,t.description.trim()),r(`recurrence`,t.repeat===`custom`?t.rrule.trim():ke(t.repeat)),t.allDay?(n.start=`${t.start}T00:00:00.000Z`,r(`end`,t.end?Et(t.end):void 0)):(n.start=P(t.start),r(`end`,P(t.end))),n}function Ot(e){return e.title.trim()?e.start?e.end&&e.end<e.start?`The end is before the start.`:e.calendar.includes(`:`)?`A calendar name cannot contain ":".`:e.repeat===`custom`&&(!e.rrule.trim()||!Se(e.rrule))?`Enter a supported RRULE (FREQ=…, INTERVAL, COUNT, UNTIL, BYDAY, BYMONTHDAY, BYMONTH).`:null:`Pick a start.`:`Give the event a title.`}function kt({subject:e,target:t,workspaceName:n,calendars:r,defaultCalendar:a,onClose:o,onSaved:s,onDelete:u}){let d=e.kind===`occurrence`?e.occurrence.doc:null,p=e.kind===`occurrence`&&e.occurrence.kind===`task`,[m,h]=(0,L.useState)(()=>d?St(d,a):Ct(e.draft,a)),[g,y]=(0,L.useState)(!1),[S,C]=(0,L.useState)(null),[T,E]=(0,L.useState)(!1),D=e.kind===`draft`?`draft:${e.draft.start.getTime()}:${e.draft.end?.getTime()??``}:${e.draft.allDay}`:e.occurrence.key,[te,O]=(0,L.useState)(D);te!==D&&(O(D),h(d?St(d,a):Ct(e.draft,a)),C(null)),(0,L.useEffect)(()=>{let e=e=>{e.key===`Escape`&&o()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[o]);let k=e=>h(t=>({...t,...e})),A=d?wt(d):null,j=typeof d?.data?.htmlLink==`string`?d.data.htmlLink:null,N=async()=>{let e=Ot(m);if(e){C(e);return}y(!0),C(null);try{if(d){if(!n)throw Error(`No workspace resolved for this calendar`);await ee(n,{id:d.id,schema:d.schema,schemaVersion:d.schemaVersion||bt,data:Dt(d.data??{},m),metadata:d.metadata})}else await ne(t,[{schema:w,schemaVersion:bt,data:Dt({},m),metadata:{features:[]}}]);s(m.calendar.trim())}catch(e){C(e instanceof Error?e.message:`Failed to save the event`)}finally{y(!1)}},P=p?`Task`:d?`Event`:`New event`;return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b border-border px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`h-3 w-3 rounded-full`,style:{background:et(p?`tasks`:m.calendar)}}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:P}),d&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`#`,d.id]}),(0,Q.jsx)(`span`,{className:`flex-1`}),d&&n&&(0,Q.jsx)(i,{to:`/workspaces/${encodeURIComponent(n)}/documents/${d.id}`,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Open document`,"aria-label":`Open document`,children:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`})}),d&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(!0),className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,title:`Link to…`,"aria-label":`Link to…`,children:(0,Q.jsx)(b,{className:`h-3.5 w-3.5`})}),d&&!p&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{u(d)},className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-destructive`,title:`Delete (moves to trash)`,"aria-label":`Delete`,children:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Close`,children:(0,Q.jsx)(c,{className:`h-4 w-4`})})]}),p&&d?(0,Q.jsx)(Mt,{doc:d,occurrence:e.occurrence,workspaceName:n,onSaved:()=>s(``)}):(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto p-3`,children:[(0,Q.jsx)(`input`,{value:m.title,onChange:e=>k({title:e.target.value}),placeholder:`Title`,autoFocus:!d,spellCheck:!1,className:`w-full border-0 border-b border-border bg-transparent px-0 py-1 text-base font-semibold outline-none placeholder:text-muted-foreground/60 focus:border-ring`}),(0,Q.jsx)(At,{value:m.calendar,calendars:r,onChange:e=>k({calendar:e})}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:m.allDay,onChange:e=>{let t=e.target.checked;if(t)k({allDay:t,start:m.start.slice(0,10),end:(m.end||m.start).slice(0,10)});else{let e=m.start.slice(0,10)||z(new Date);k({allDay:t,start:`${e}T09:00`,end:`${(m.end||e).slice(0,10)}T10:00`})}},className:`h-4 w-4 accent-primary`}),`All day`]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Start`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(F,{value:m.start,onChange:e=>k({start:e,end:m.end&&m.end<e?e:m.end})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:m.start,onChange:e=>k({start:e}),clearable:!1})})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`End`}),m.allDay?(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(F,{value:m.end,min:m.start,placeholder:`Same day`,onChange:e=>k({end:e})})}):(0,Q.jsx)(`div`,{className:`mt-1`,children:(0,Q.jsx)(M,{value:m.end,onChange:e=>k({end:e}),placeholder:`No end`})})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(l,{className:`h-3 w-3`}),` Repeat`]}),(0,Q.jsx)(`select`,{value:m.repeat,onChange:e=>k({repeat:e.target.value,rrule:e.target.value===`custom`?m.rrule||ke(m.repeat)||`FREQ=WEEKLY`:m.rrule}),className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:xt.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}),m.repeat===`custom`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`input`,{value:m.rrule,onChange:e=>k({rrule:e.target.value}),placeholder:`FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH`,spellCheck:!1,className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 font-mono text-xs`}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[11px] text-muted-foreground`,children:Se(m.rrule)?De(Se(m.rrule)):`RFC 5545 RRULE value`})]})]}),(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Location`}),(0,Q.jsx)(`input`,{value:m.location,onChange:e=>k({location:e.target.value}),spellCheck:!1,className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`})]}),(0,Q.jsxs)(`div`,{className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Description`}),(0,Q.jsx)(`div`,{className:`mt-1 rounded-md border border-input px-2 py-1.5`,children:(0,Q.jsx)(ae,{value:m.description,onChange:e=>k({description:e}),placeholder:`Notes, agenda, links…`})})]}),A&&(0,Q.jsxs)(`p`,{className:`rounded-md bg-muted/50 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[`Synced from `,A.connector||A.source,`. Edits stay in Canvas unless the connector supports write-back.`,j&&(0,Q.jsxs)(Q.Fragment,{children:[` `,(0,Q.jsx)(`a`,{href:j,target:`_blank`,rel:`noopener noreferrer`,className:`underline hover:text-foreground`,children:`Open at source`})]})]}),e.kind===`occurrence`&&e.occurrence.unsupportedRule&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`This series uses RRULE parts the calendar cannot expand; only its first occurrence is shown.`}),S&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,role:`alert`,children:S})]}),!p&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-3 py-2`,children:[(0,Q.jsx)(jt,{doc:d}),(0,Q.jsx)(`button`,{type:`button`,onClick:o,className:`rounded-md border border-border px-3 py-1.5 text-xs hover:bg-muted`,children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:N,disabled:g,className:x(`flex items-center gap-1 rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground disabled:opacity-50`),children:[g&&(0,Q.jsx)(v,{className:`h-3 w-3 animate-spin`}),d?`Save`:`Create`]})]}),T&&d&&(0,Q.jsx)(ie,{documentId:d.id,workspaceName:n??void 0,onClose:()=>E(!1)})]})}function At({value:e,calendars:t,onChange:n}){let r=t.some(t=>t.toLowerCase()===e.toLowerCase()),[i,a]=(0,L.useState)(!r&&!e&&t.length===0),o=r||!e?t:[e,...t];return(0,Q.jsxs)(`label`,{className:`block text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`Calendar`}),i?(0,Q.jsxs)(`span`,{className:`mt-1 flex gap-1`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:e,onChange:e=>n(e.target.value),placeholder:`New calendar name`,spellCheck:!1,className:`h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 text-sm outline-none focus-visible:ring-1 focus-visible:ring-ring`}),t.length>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{a(!1),n(t[0])},className:`rounded-md border border-border px-2 text-xs text-muted-foreground hover:bg-muted`,"aria-label":`Pick an existing calendar`,children:(0,Q.jsx)(c,{className:`h-3 w-3`})})]}):(0,Q.jsxs)(`select`,{value:e,onChange:e=>{e.target.value===`\0new`?(a(!0),n(``)):n(e.target.value)},className:`mt-1 h-8 w-full rounded-md border border-input bg-transparent px-2 text-sm`,children:[!e&&(0,Q.jsx)(`option`,{value:``,children:`No calendar`}),o.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e)),(0,Q.jsx)(`option`,{value:`\0new`,children:`New calendar…`})]})]})}function jt({doc:e}){let t=O(e??{id:-1,locations:[]});return!e||!t.replicating?null:(0,Q.jsx)(`span`,{className:`mr-auto text-[10px] text-muted-foreground`,children:t.label})}function Mt({doc:e,occurrence:t,workspaceName:n,onSaved:r}){let[i,o]=(0,L.useState)(!1),s=t.done;return(0,Q.jsxs)(`div`,{className:`space-y-3 p-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:async()=>{if(n){o(!0);try{let t=s?`pending`:`completed`;await ee(n,{id:e.id,schema:e.schema,schemaVersion:e.schemaVersion,data:{...e.data??{},status:t,completed:t===`completed`},metadata:e.metadata}),r()}finally{o(!1)}}},disabled:i,className:`mt-0.5 text-muted-foreground hover:text-foreground`,"aria-label":s?`Mark as pending`:`Mark as completed`,children:s?(0,Q.jsx)(a,{className:`h-4 w-4 text-success`}):(0,Q.jsx)(g,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:x(`font-semibold`,s&&`line-through text-muted-foreground`),children:t.title}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Due `,t.start.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})]})]})]}),typeof e.data?.description==`string`&&e.data.description&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-xs text-muted-foreground`,children:e.data.description}),(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Edit the task in the Todos app or on its document page.`})]})}function Nt({menu:e,onClose:t,onOpen:n,onOpenDocument:r,onToggleDone:i,onDelete:o,onCreate:s,onPickDay:c}){let l=e=>()=>{t(),e()};return(0,Q.jsx)(S,{x:e.x,y:e.y,onClose:t,className:`min-w-44 rounded-md border bg-popover p-1 text-xs shadow-elevation-3`,children:e.kind===`entry`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`p`,{className:`truncate px-3 py-1.5 text-[11px] text-muted-foreground`,title:e.occurrence.title,children:e.occurrence.title}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>n(e.occurrence)),children:`Open`}),r&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(_,{className:`h-3.5 w-3.5`}),onClick:l(()=>r(e.occurrence)),children:`Open document`}),e.occurrence.kind===`task`&&(0,Q.jsx)(Pt,{icon:e.occurrence.done?(0,Q.jsx)(g,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(a,{className:`h-3.5 w-3.5`}),onClick:l(()=>i(e.occurrence)),children:e.occurrence.done?`Mark as pending`:`Mark as completed`}),e.occurrence.kind===`event`&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(f,{className:`h-3.5 w-3.5`}),className:`text-destructive`,onClick:l(()=>o(e.occurrence)),children:`Delete…`})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`p`,{className:`px-3 py-1.5 text-[11px] text-muted-foreground`,children:[X(e.start),e.allDay?``:`, ${Z(e.start)}`]}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(y,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,e.allDay)),children:e.allDay?`New event`:`New event at ${Z(e.start)}`}),!e.allDay&&(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(m,{className:`h-3.5 w-3.5`}),onClick:l(()=>s(e.start,!0)),children:`New all-day event`}),(0,Q.jsx)(Pt,{icon:(0,Q.jsx)(h,{className:`h-3.5 w-3.5`}),onClick:l(()=>c(e.start)),children:`Open day`})]})})}function Pt({icon:e,onClick:t,className:n,children:r}){return(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:x(`flex w-full items-center gap-2 rounded px-3 py-1.5 text-left hover:bg-accent`,n),children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e}),r]})}var Ft=640,It=420,Lt=30,Rt=14;function zt(e,t,n,r){switch(e){case`day`:{let e=V(t);return{start:e,end:H(e,n)}}case`week`:{let e=ue(t);return{start:e,end:H(e,7)}}case`month`:{let e=fe(t);return{start:e[0],end:H(e[41],1)}}case`year`:return{start:new Date(t.getFullYear(),0,1),end:new Date(t.getFullYear()+1,0,1)};case`schedule`:{let e=V(t);return{start:H(e,-r.before),end:H(e,r.after)}}}}function Bt(e,t,n,r){switch(e){case`day`:return H(t,n*r);case`week`:return H(t,7*r);case`month`:return le(t,r);case`year`:return new Date(t.getFullYear()+r,t.getMonth(),1);case`schedule`:return H(t,Lt*r)}}function Vt(e,t,n,r){switch(e){case`day`:return n>1?_e(t,H(t,n-1)):r?X(t):Y(t);case`week`:return ve(ue(t));case`month`:return he(t);case`year`:return String(t.getFullYear());case`schedule`:return r?X(t):`From ${Y(t)}`}}function Ht({autoAdd:e=!1}){let t=re(),n=t?.mode===`workspace`?t.workspaceName:t?.mode===`context`?`ctx:${t.contextId}`:null,[i,a]=(0,L.useState)(()=>qe(n)),c=(0,L.useCallback)(e=>{a(t=>{let r={...t,...e};return Je(n,r),r})},[n]),l=i.view,[f,m]=(0,L.useState)(()=>V(new Date)),[h,g]=(0,L.useState)(1),[_,y]=(0,L.useState)(null),b=r(),[S,C]=(0,L.useState)({before:0,after:Lt}),[w,T]=(0,L.useState)(()=>e?{kind:`draft`,draft:{start:Ut(),allDay:!1}}:null),[E,D]=(0,L.useState)(!1),te=(0,L.useRef)(null),[O,ne]=(0,L.useState)(1024);(0,L.useEffect)(()=>{let e=te.current;if(!e)return;let t=new ResizeObserver(e=>{for(let t of e)ne(t.contentRect.width)});return t.observe(e),()=>t.disconnect()},[]);let A=O<Ft,j=O<It,M=(0,L.useMemo)(()=>zt(l,f,h,S),[l,f,h,S]),{docs:N,loading:P,error:F,scope:I,knownCalendars:ie,reload:ae,removeDoc:se,patchDoc:R}=$e(t,M.start,M.end,i.showTasks),z=(0,L.useMemo)(()=>{let e=new Map;for(let t of ie)e.set(t,t);for(let t of N){let n=t.data?.calendar;typeof n==`string`&&n.trim()&&e.set(n.trim().toLowerCase(),n.trim())}return i.defaultCalendar&&e.set(i.defaultCalendar.toLowerCase(),e.get(i.defaultCalendar.toLowerCase())??i.defaultCalendar),[...e.values()].sort((e,t)=>e.localeCompare(t))},[ie,N,i.defaultCalendar]),B=(0,L.useMemo)(()=>new Set(i.hidden),[i.hidden]),ce=(0,L.useMemo)(()=>N.some(e=>e.schema.startsWith(`data/schema/event`)&&!(typeof e.data?.calendar==`string`&&e.data.calendar.trim())),[N]),U=(0,L.useMemo)(()=>Re(N.filter(e=>{let t=typeof e.data?.calendar==`string`?e.data.calendar.trim().toLowerCase():``;return!B.has(t||``)}),M.start,M.end),[N,B,M]),fe=w?.kind===`occurrence`?w.occurrence.key:null,W=(0,L.useCallback)((e,t)=>{m(V(e)),g(1),C({before:0,after:Lt}),t&&c({view:t})},[c]),G=(0,L.useCallback)((e,t)=>{let n=Math.round((V(t).getTime()-V(e).getTime())/oe);if(n>Rt){W(e,`month`);return}W(e,`day`),g(Math.max(1,n))},[W]),pe=(0,L.useCallback)(e=>{g(1),c({view:e})},[c]),K=(0,L.useMemo)(()=>l===`day`||l===`week`?{start:M.start,end:M.end}:{start:f,end:H(f,1)},[l,M,f]),me=(0,L.useMemo)(()=>{if(w?.kind!==`draft`)return null;let{start:e,allDay:t,end:n}=w.draft;return{start:e,allDay:t,end:n??(t?H(V(e),1):new Date(e.getTime()+36e5))}},[w]),q=(0,L.useCallback)((e,t,n)=>T({kind:`draft`,draft:{start:e,allDay:t,end:n}}),[]),J=(0,L.useCallback)(e=>T({kind:`occurrence`,occurrence:e}),[]),he=(0,L.useCallback)(async(e,t,n)=>{if(!I)return;let r=e.doc,i=He(r.data??{},e,t,n);R({...r,data:i});try{await ee(I.workspaceName,{id:r.id,schema:r.schema,schemaVersion:r.schemaVersion||`3.0`,data:i,metadata:r.metadata})}catch{R(r)}},[I,R]),ge=(0,L.useCallback)(async e=>{if(!I)return;let t=e.doc,n=e.done?`pending`:`completed`,r={...t.data??{},status:n,completed:n===`completed`};R({...t,data:r});try{await ee(I.workspaceName,{id:t.id,schema:t.schema,schemaVersion:t.schemaVersion,data:r,metadata:t.metadata})}catch{R(t)}},[I,R]),Y=(0,L.useCallback)((e,t)=>y({x:e.clientX,y:e.clientY,kind:`entry`,occurrence:t}),[]),X=(0,L.useCallback)((e,t,n)=>y({x:e.clientX,y:e.clientY,kind:`slot`,start:t,allDay:n}),[]),Z=(0,L.useCallback)(async e=>{let t=e.data?.title?`"${e.data.title}"`:`#${e.id}`;if(window.confirm(`Delete event ${t}?\n\nIt is removed from this path and moves to the workspace trash if nothing else links it.`))try{await se(e.id),T(null)}catch{}},[se]),_e=e=>{let t=e.target;if(!([`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)||t.isContentEditable)){if(e.key===`ArrowLeft`)ve(-1),e.preventDefault();else if(e.key===`ArrowRight`)ve(1),e.preventDefault();else if(e.key===`t`)W(new Date);else if(e.key===`n`)q(Ut(f),!1);else if(e.key===`Escape`)T(null),D(!1);else{let t=Ue.find(t=>t.key===e.key);t&&pe(t.id)}}},ve=e=>{let t=h;W(Bt(l,f,h,e)),g(t)};if(!t)return(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-6 text-center text-sm text-muted-foreground`,children:k(t)});let ye=e=>{let t=e.toLowerCase();c({hidden:B.has(t)?i.hidden.filter(e=>e!==t):[...i.hidden,t]})},be=(0,Q.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,Q.jsx)(`p`,{className:`px-1 text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Calendars`}),z.map(e=>(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!B.has(e.toLowerCase()),onChange:()=>ye(e),className:`h-3.5 w-3.5 accent-primary`,style:{accentColor:et(e)}}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(e)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:e})]},e)),ce&&(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!B.has(``),onChange:()=>ye(``),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(``)}}),(0,Q.jsx)(`span`,{className:`truncate text-muted-foreground`,children:`Other events`})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-1 py-0.5 hover:bg-muted`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:i.showTasks,onChange:e=>c({showTasks:e.target.checked}),className:`h-3.5 w-3.5 accent-primary`}),(0,Q.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 rounded-sm`,style:{background:et(Ae)}}),(0,Q.jsx)(`span`,{className:`truncate`,children:`Tasks (due dates)`})]})]}),xe=(()=>{switch(l){case`day`:return(0,Q.jsx)(ht,{days:Array.from({length:h},(e,t)=>H(V(f),t)),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,compact:j||h>3});case`week`:return(0,Q.jsx)(ht,{days:Array.from({length:7},(e,t)=>H(ue(f),t)),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,compact:A});case`month`:return(0,Q.jsx)(_t,{month:de(f),occurrences:U,selectedKey:fe,pending:me,onSelect:J,onCreate:q,onMove:he,onPickDay:e=>W(e,`day`),onEntryMenu:Y,onSlotMenu:X,narrow:A});case`year`:return(0,Q.jsx)(vt,{year:f.getFullYear(),occurrences:U,onPickDay:e=>W(e,`day`),onPickRange:G,onPickMonth:e=>W(e,`month`),onSlotMenu:X});case`schedule`:return(0,Q.jsx)(yt,{occurrences:U,selectedKey:fe,onSelect:J,onEntryMenu:Y,loading:P,onEarlier:()=>C(e=>({...e,before:e.before+Lt})),onLater:()=>C(e=>({...e,after:e.after+Lt})),onPickDay:e=>W(e,`day`)})}})();return(0,Q.jsxs)(`div`,{ref:te,tabIndex:0,onKeyDown:_e,className:`relative flex h-full min-h-0 flex-col outline-none`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-2 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>W(new Date),className:`rounded-md border border-border px-2 py-1 text-xs hover:bg-muted`,title:`Today (t)`,children:`Today`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(-1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Previous`,title:`Previous (←)`,children:(0,Q.jsx)(o,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ve(1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":`Next`,title:`Next (→)`,children:(0,Q.jsx)(d,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-sm font-semibold`,children:Vt(l,f,h,j)}),P&&(0,Q.jsx)(v,{className:`h-3.5 w-3.5 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1`}),j?(0,Q.jsx)(`select`,{value:l,onChange:e=>pe(e.target.value),"aria-label":`View`,className:`h-7 rounded-md border border-input bg-transparent px-1.5 text-xs`,children:Ue.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))}):(0,Q.jsx)(`div`,{className:`flex overflow-hidden rounded-md border border-border`,role:`tablist`,"aria-label":`View`,children:Ue.map(e=>(0,Q.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e.id,onClick:()=>pe(e.id),title:`${e.label} (${e.key})`,className:x(`px-2 py-1 text-xs transition-colors`,l===e.id?`bg-foreground text-background`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:e.label},e.id))}),A&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),className:x(`rounded-md border p-1.5`,E?`border-foreground text-foreground`:`border-border text-muted-foreground hover:bg-muted hover:text-foreground`),"aria-label":`Calendars`,title:`Calendars`,children:(0,Q.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>q(Ut(f),!1),className:`flex items-center gap-1 rounded-md bg-primary px-2 py-1.5 text-xs text-primary-foreground`,title:`New event (n)`,children:[(0,Q.jsx)(u,{className:`h-3.5 w-3.5`}),!j&&`Event`]})]}),F&&(0,Q.jsx)(`p`,{className:`border-b border-border px-3 py-2 text-xs text-destructive`,children:F}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[!A&&(0,Q.jsxs)(`aside`,{className:`flex w-52 shrink-0 flex-col gap-4 overflow-y-auto border-r border-border p-3`,children:[(0,Q.jsx)(ct,{month:de(f),selection:K,onPick:e=>W(e,l===`year`||l===`month`?`day`:l),onPickRange:G,onPrev:()=>m(e=>le(e,-1)),onNext:()=>m(e=>le(e,1))}),be]}),(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[xe,A&&E&&(0,Q.jsx)(`div`,{className:`absolute right-2 top-2 z-20 w-56 rounded-md border border-border bg-popover p-2 text-popover-foreground shadow-elevation-2`,children:be})]}),w&&!A&&(0,Q.jsx)(`aside`,{className:`w-80 shrink-0 border-l border-border bg-card`,children:(0,Q.jsx)(kt,{subject:w,target:t,workspaceName:I?.workspaceName??null,calendars:z,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),ae()},onDelete:Z})})]}),w&&A&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-card`,children:(0,Q.jsx)(kt,{subject:w,target:t,workspaceName:I?.workspaceName??null,calendars:z,defaultCalendar:i.defaultCalendar,onClose:()=>T(null),onSaved:e=>{e&&c({defaultCalendar:e}),T(null),ae()},onDelete:Z})}),_&&(0,Q.jsx)(Nt,{menu:_,onClose:()=>y(null),onOpen:J,onOpenDocument:I?e=>b(`/workspaces/${encodeURIComponent(I.workspaceName)}/documents/${e.doc.id}`):null,onToggleDone:e=>{ge(e)},onDelete:e=>{Z(e.doc)},onCreate:(e,t)=>q(e,t),onPickDay:e=>W(e,`day`)}),!P&&!F&&!N.length&&l!==`schedule`&&(0,Q.jsxs)(`p`,{className:`pointer-events-none absolute bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-muted/80 px-3 py-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(s,{className:`mr-1 inline h-3 w-3`}),`Nothing here yet — click or drag a slot to add an event.`]})]})}function Ut(e){let t=new Date,n=e&&!Wt(e,t)?new Date(e.getFullYear(),e.getMonth(),e.getDate(),9,0):new Date(t);return(!e||Wt(e,t))&&n.setMinutes(t.getMinutes()<30?30:60,0,0),n}function Wt(e,t){return e.toDateString()===t.toDateString()}export{Ht as CalendarApplet};