1import{j as e,a2 as p,r as i,B as f,n as T,i as q,d as ge,u as pe,b as xe,L as je}from"./index-DN4Mwqf7.js";import{a as E,F as k,C as fe}from"./index-CeTPcGzX.js";const P=["#4285f4","#ea4335","#fbbc04","#34a853","#ff6d01","#46bdc6","#7b1fa2","#c2185b"];function Se({members:n,enabledMembers:r,onToggle:a}){const j=n.some(u=>!u.calendarConnected);return e.jsxs("div",{className:"calendar-members",children:[e.jsxs("span",{style:{fontSize:"0.8rem",color:"#888",marginRight:"0.25rem"},children:[e.jsx(p,{name:"users"})," Members:"]}),n.map((u,d)=>{const h=P[d%P.length],g=r.has(u.username),o=u.calendarConnected;return e.jsxs("div",{className:"calendar-member-chip ".concat(g?"active":""," ").concat(o?"":"disconnected"),onClick:()=>o&&a(u.username),title:o?"".concat(g?"Hide":"Show"," ").concat(u.username,"'s calendar"):"".concat(u.username," has not connected Google Calendar"),style:g?{borderColor:h}:void 0,children:[e.jsx("span",{className:"member-dot",style:{backgroundColor:g?h:"#ccc"}}),u.username.split("@")[0],!o&&e.jsx(p,{name:"unlink",size:"small",style:{marginLeft:"0.15rem"}})]},u.username)}),j&&e.jsxs("span",{className:"calendar-members-hint",title:"OAuth is per-user â each member has to connect their own Google account",children:[e.jsx(p,{name:"info circle",size:"small"}),"Dashed members haven't linked Google Calendar yet â ask them to connect in"," ",e.jsx("em",{children:"My Account â Connected Services"}),"."]})]})}function ye({open:n,onClose:r,onCreate:a,defaultDate:j}){const u=j||new Date().toISOString().split("T")[0],[d,h]=i.useState(""),[g,o]=i.useState(u),[S,M]=i.useState("10:00"),[D,y]=i.useState("11:00"),[N,L]=i.useState(""),[O,_]=i.useState(!1),[z,W]=i.useState(!1),Y=async()=>{if(!d.trim()){T.error("Title is required");return}W(!0);try{const w=O?g:"".concat(g,"T").concat(S,":00"),m=O?g:"".concat(g,"T").concat(D,":00");await a({title:d.trim(),start:w,end:m,description:N,allDay:O}),h(""),L(""),_(!1),r()}catch(w){T.error(w.message||"Failed to create event")}finally{W(!1)}};return e.jsxs(E,{open:n,onClose:r,size:"small",children:[e.jsxs(E.Header,{children:[e.jsx(p,{name:"calendar plus"})," New Shared Event"]}),e.jsx(E.Content,{children:e.jsxs(k,{children:[e.jsx(k.Input,{label:"Title",placeholder:"Family dinner, Game night...",value:d,onChange:(w,{value:m})=>h(m),autoFocus:!0}),e.jsx(k.Input,{label:"Date",type:"date",value:g,onChange:(w,{value:m})=>o(m)}),e.jsx(k.Field,{children:e.jsx(fe,{label:"All day",checked:O,onChange:(w,{checked:m})=>_(!!m)})}),!O&&e.jsxs(k.Group,{widths:"equal",children:[e.jsx(k.Input,{label:"Start time",type:"time",value:S,onChange:(w,{value:m})=>M(m)}),e.jsx(k.Input,{label:"End time",type:"time",value:D,onChange:(w,{value:m})=>y(m)})]}),e.jsx(k.TextArea,{label:"Description (optional)",placeholder:"Details about the event...",value:N,onChange:(w,{value:m})=>L(String(m||"")),rows:2})]})}),e.jsxs(E.Actions,{children:[e.jsx(f,{basic:!0,onClick:r,disabled:z,children:"Cancel"}),e.jsxs(f,{color:"teal",onClick:Y,loading:z,disabled:z||!d.trim(),children:[e.jsx(p,{name:"plus"})," Create Event"]})]})]})}function we({event:n,open:r,onClose:a,currentUser:j,onOptIn:u,onOptOut:d,onDelete:h}){var g;if(!n)return null;const o=n.source==="shared",S=n.created_by===j,M=((g=n.opted_in)==null?void 0:g.includes(j))||!1,D=y=>new Date(y).toLocaleString(void 0,{weekday:"short",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});return e.jsxs(E,{open:r,onClose:a,size:"small",children:[e.jsxs(E.Header,{children:[e.jsx(p,{name:o?"calendar":"google"}),n.title,o&&e.jsx(q,{color:"teal",size:"mini",style:{marginLeft:"0.5rem",verticalAlign:"middle"},children:"Shared"}),!o&&e.jsx(q,{color:"blue",size:"mini",style:{marginLeft:"0.5rem",verticalAlign:"middle"},children:"Google"})]}),e.jsxs(E.Content,{children:[e.jsxs("p",{children:[e.jsx(p,{name:"clock"}),D(n.start),n.end&&n.end!==n.start&&e.jsxs(e.Fragment,{children:[" â ",D(n.end)]})]}),n.description&&e.jsx("p",{style:{color:"#666"},children:n.description}),n.owner&&e.jsxs("p",{children:[e.jsx(p,{name:"user"}),e.jsx("strong",{children:n.owner})]}),o&&n.opted_in&&n.opted_in.length>0&&e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsxs("strong",{children:["Attending (",n.opted_in.length,"):"]}),e.jsx("div",{style:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginTop:"0.5rem"},children:n.opted_in.map(y=>e.jsxs(q,{size:"small",children:[e.jsx(p,{name:"user"}),y.split("@")[0],y===j&&" (you)"]},y))})]})]}),e.jsxs(E.Actions,{children:[o&&!M&&e.jsxs(f,{color:"teal",onClick:()=>u(n),children:[e.jsx(p,{name:"check"})," I'm in"]}),o&&M&&!S&&e.jsxs(f,{basic:!0,color:"orange",onClick:()=>d(n),children:[e.jsx(p,{name:"remove"})," Opt out"]}),o&&S&&e.jsxs(f,{basic:!0,color:"red",onClick:()=>h(n),children:[e.jsx(p,{name:"trash"})," Delete"]}),e.jsx(f,{basic:!0,onClick:a,children:"Close"})]})]})}const Z=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function U(n){return new Date(n.getFullYear(),n.getMonth(),1)}function H(n){const r=n.getDay(),a=n.getDate()-r;return new Date(n.getFullYear(),n.getMonth(),a)}function I(n,r){const a=new Date(n);return a.setDate(a.getDate()+r),a}function V(n,r){return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate()}function Ce(n){return n.toLocaleDateString(void 0,{month:"long",year:"numeric"})}function be(n){const r=ge(),{username:a}=pe(),{hostname:j}=xe(),{application:u}=n,d=u!=null&&u.app_id?String(u.app_id).replace(/\.app\.CALENDAR$/,".stream.calendar"):"sys.".concat(j,".stream.calendar"),[h,g]=i.useState("month"),[o,S]=i.useState(new Date),[M,D]=i.useState([]),[y,N]=i.useState(new Set),[L,O]=i.useState(new Map),[_,z]=i.useState([]),[W,Y]=i.useState(!0),[w,m]=i.useState(!1),[$,A]=i.useState(null),[ee,J]=i.useState(),b=i.useMemo(()=>
1{if(h==="month"){const t=U(o),l=H(t),s=I(l,41);return{start:l.toISOString(),end:s.toISOString(),viewStart:l}}else{const t=H(o),l=I(t,6);return l.setHours(23,59,59),{start:t.toISOString(),end:l.toISOString(),viewStart:t}}},[o,h]);i.useEffect(()=>{a&&r.getMembers(a,j).then(t=>{t.some(c=>c.username===a)||(t=[{username:a,calendarConnected:!0,calendarWriteEnabled:!1},...t]),D(t);const s=new Set;s.add(a),t.forEach(c=>{c.calendarConnected&&s.add(c.username)}),N(s),console.log("[Calendar] members loaded:",t.length,"enabled:",Array.from(s))}).catch(t=>{console.error("[Calendar] Failed to load members:",t),D([{username:a,calendarConnected:!0,calendarWriteEnabled:!1}]),N(new Set([a]))})},[a,j]);const F=i.useCallback(async()=>{if(a){Y(!0);try{if(d){const s=await r.getSharedEvents(a,d,b.start,b.end);z(s)}const t=new Map,l=Array.from(y).map(async s=>{try{const c=s===a?await r.getGoogleEvents(a,b.start,b.end):await r.getMemberGoogleEvents(a,s,b.start,b.end,j);t.set(s,c),console.log("[Calendar] loaded ".concat(c.length," events for ").concat(s))}catch(c){console.error("[Calendar] Failed to load events for ".concat(s,":"),c.message),t.set(s,[])}});await Promise.all(l),O(t)}catch(t){console.error("[Calendar] Failed to load events:",t),T.error("Failed to load calendar events")}finally{Y(!1)}}},[a,b.start,b.end,y,d,j]);i.useEffect(()=>{F()},[F]);const te=i.useMemo(()=>{const t=[..._];for(const[,l]of L)t.push(...l);return t},[L,_]),K=t=>te.filter(l=>{const s=new Date(l.start);return V(s,t)}),Q=t=>{const l=M.findIndex(s=>s.username===t);return l>=0?P[l%P.length]:"#999"},ne=t=>{N(l=>{const s=new Set(l);return s.has(t)?s.delete(t):s.add(t),s})},ae=()=>{S(h==="month"?new Date(o.getFullYear(),o.getMonth()-1,1):I(o,-7))},se=()=>{S(h==="month"?new Date(o.getFullYear(),o.getMonth()+1,1):I(o,7))},oe=()=>S(new Date),re=async t=>{!a||!d||(await r.createSharedEvent(a,d,t),T.success("Event created"),F())},le=async t=>{if(!a||!d||!t.timestamp)return;const l=await r.optInEvent(a,d,t.timestamp);T.success(l.googleSynced?"Opted in and added to Google Calendar":"Opted in"),A(null),F()},ce=async t=>{!a||!d||!t.timestamp||(await r.optOutEvent(a,d,t.timestamp),T.success("Opted out"),A(null),F())},ie=async t=>{!a||!d||!t.timestamp||(await r.deleteSharedEvent(a,d,t.timestamp),T.success("Event deleted"),A(null),F())},X=t=>{J(t.toISOString().split("T")[0]),m(!0)},de=()=>{const t=H(o),l=new Date,s=[];for(let c=0;c<7;c++)s.push(I(t,c));return e.jsx("div",{className:"calendar-week-list",children:s.map((c,x)=>{const R=K(c),G=V(c,l);return e.jsxs("div",{className:"calendar-week-day ".concat(G?"today":""),onClick:()=>X(c),children:[e.jsxs("div",{className:"calendar-week-day-header",children:[e.jsx("div",{className:"calendar-week-day-name",children:Z[c.getDay()]}),e.jsx("div",{className:"calendar-week-day-number",children:c.getDate()}),e.jsx("div",{className:"calendar-week-day-month",children:c.toLocaleDateString(void 0,{month:"short"})})]}),e.jsx("div",{className:"calendar-week-day-events",children:R.length===0?e.jsx("div",{className:"calendar-week-empty",children:"No events"}):R.map((C,B)=>e.jsx("div",{className:"calendar-event-chip ".concat(C.source),style:C.source==="google"&&C.owner?{borderLeftColor:Q(C.owner)}:void 0,onClick:v=>{v.stopPropagation(),A(C)},title:"".concat(C.title).concat(C.owner?" (".concat(C.owner.split("@")[0],")"):""),children:C.title},B))})]},x)})})},ue=()=>{const t=U(o),l=H(t),s=new Date,c=[];for(let x=0;x<42;x++)c.push(I(l,x));return e.jsxs("div",{className:"calendar-month-grid",children:[Z.map(x=>e.jsx("div",{className:"calendar-day-header",children:x},x)),c.map((x,R)=>{const G=K(x),C=x.getMonth()!==o.getMonth(),B=V(x,s);return e.jsxs("div",{className:"calendar-day ".concat(C?"outside-month":""," ").concat(B?"today":""),onClick:()=>X(x),children:[e.jsx("div",{className:"calendar-day-number",children:x.getDate()}),G.slice(0,4).map((v,he)=>e.jsx("div",{className:"calendar-event-chip ".concat(v.source),style:v.source==="google"&&v.owner?{borderLeftColor:Q(v.owner)}:void 0,onClick:me=>{me.stopPropagation(),A(v)},title:"".concat(v.title).concat(v.owner?" (".concat(v.owner.split("@")[0],")"):""),children:v.title},he)),G.length>4&&e.jsxs("div",{style:{fontSize:"0.65rem",color:"#999",paddingLeft:"4px"},children:["+",G.length-4," more"]})]},R)})]})};return e.jsxs("main",{className:"calendar-app",children:[e.jsx(Se,{members:M,enabledMembers:y,onToggle:ne}),e.jsxs("div",{className:"calendar-toolbar",children:[e.jsxs("div",{className:"calendar-toolbar-nav",children:[e.jsx(f,{basic:!0,size:"small",icon:!0,onClick:ae,children:e.jsx(p,{name:"chevron left"})}),e.jsx(f,{basic:!0,size:"small",onClick:oe,children:"Today"}),e.jsx(f,{basic:!0,size:"small",icon:!0,onClick:se,children:e.jsx(p,{name:"chevron right"})}),e.jsx("span",{style:{fontWeight:600,fontSize:"1.1rem",marginLeft:"0.5rem"},children:Ce(o)}),W&&e.jsx(je,{active:!0,inline:!0,size:"tiny",style:{marginLeft:"0.5rem"}})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsxs(f.Group,{size:"small",children:[e.jsx(f,{basic:h!=="month",color:h==="month"?"teal":void 0,onClick:()=>g("month"),children:"Month"}),e.jsx(f,{basic:h!=="week",color:h==="week"?"teal":void 0,onClick:()=>g("week"),children:"Week"})]}),e.jsxs(f,{color:"teal",size:"small",onClick:()=>{J(void 0),m(!0)},children:[e.jsx(p,{name:"plus"})," New Event"]})]})]}),e.jsx("div",{className:"calendar-grid",children:h==="week"?de():ue()}),e.jsx(ye,{open:w,onClose:()=>m(!1),onCreate:re,defaultDate:ee}
1),e.jsx(we,{event:$,open:!!$,onClose:()=>A(null),currentUser:a||"",onOptIn:le,onOptOut:ce,onDelete:ie})]})}export{be as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.