1import{j as e}from"./index-jKTyR-Oz.js";import{f as Z,b as a,L as ee}from"./vendor-react-Cipdfa8D.js";import{c as se,i as te,B as c,aa as ae,P as ie,C as S,d as k,z as W,G as ne,ab as re,f as le}from"./BlobImage-CyV_QrJF.js";import{E as ce}from"./EmptyState-6PFzJBt1.js";import{d as I,b as G,C as oe,S as de,a as me}from"./SecretSantaPanel-GBVSogj3.js";import{S as pe,E as xe}from"./SuggestedEventsStrip-DG6679m0.js";import{a as he}from"./eventStyle-Dc-aAjRb.js";import{c as ue}from"./links-BZuurpuw.js";import{e as ge,a as ye}from"./events-DEq3wXND.js";import{A as fe}from"./arrow-left-wHn7bbRP.js";import"./participants-CBSgF7ji.js";import"./Confetti-DUrEm_tM.js";import"./HelpTip-JluEPmNb.js";import"./help-v_MLblbq.js";import"./eye-B4L6KDIW.js";import"./maximize-2-D4-1ZElh.js";import"./map-pin-DHZSwmps.js";import"./wishlist-gkLMYNBQ.js";const je=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]],Ne=se("grid-3x3",je),R={birthday:"bg-pink-500",anniversary:"bg-red-500",holiday:"bg-green-500",custom:"bg-blue-500"};function we(i,n){const r=[],f=new Date(i,n,1),o=new Date(i,n+1,0),j=f.getDay();for(let t=j-1;t>=0;t--){const x=new Date(i,n,-t);r.push(x)}for(let t=1;t<=o.getDate();t++)r.push(new Date(i,n,t));const h=6-o.getDay();for(let t=1;t<=h;t++)r.push(new Date(i,n+1,t));return r}function D(i){const n=String(i.getMonth()+1).padStart(2,"0"),r=String(i.getDate()).padStart(2,"0");return`${i.getFullYear()}-${n}-${r}`}function Ie(){const{id:i}=Z(),n=i||"",[r,f]=a.useState(0),[o,j]=a.useState(null),[h,t]=a.useState(null),[x,_]=a.useState([]),[U,Y]=a.useState(!0),[q,g]=a.useState(!1),[N,M]=a.useState("list"),[d,w]=a.useState(()=>new Date),[p,u]=a.useState(null);te(()=>u(null),p!==null);const[E,$]=a.useState(null),[z,T]=a.useState(!0),[A,P]=a.useState(!1);a.useEffect(()=>{n&&b()},[n]);async function b(){try{const s=await ue.get(n);j(s),f(s.id),_(await ge.listByCircle(s.id))}catch(s){console.error("Failed to load data:",s)}finally{Y(!1)}}function H(s){_(l=>[...l,{id:s.id,name:s.name,event_type:s.event_type,date:s.date,time:s.time,participant:s.participant,participant_name:s.participant_name,circle:s.circle,days_until:s.days_until,is_upcoming:s.is_upcoming,is_active:s.is_active}].sort((m,v)=>new Date(m.date).getTime()-new Date(v.date).getTime())),g(!1)}function O(s){const l=D(s);return x.filter(m=>m.date===l)}function V(){w(new Date(d.getFullYear(),d.getMonth()-1,1))}function J(){w(new Date(d.getFullYear(),d.getMonth()+1,1))}function K(){w(new Date)}const F=x.filter(s=>s.days_until>=0&&s.status!=="completed"),L=x.filter(s=>s.days_until<0||s.status==="completed").sort((s,l)=>l.days_until-s.days_until);if(U)return e.jsx("div",{className:"flex items-center justify-center min-h-[50vh]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"})});const Q=we(d.getFullYear(),d.getMonth()),B=new Date;return B.setHours(0,0,0,0),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ee,{to:`/c/${r}`,children:e.jsx(c,{variant:"ghost",size:"sm",children:e.jsx(fe,{className:"h-4 w-4"})})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-2xl font-semibold text-gray-900",children:"Events"}),o&&e.jsx("p",{className:"text-gray-500",children:o.name})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex border rounded-lg overflow-hidden",children:[e.jsx(c,{variant:N==="list"?"primary":"ghost",size:"sm",className:"rounded-none",onClick:()=>M("list"),children:e.jsx(ae,{className:"h-4 w-4"})}),e.jsx(c,{variant:N==="calendar"?"primary":"ghost",size:"sm",className:"rounded-none",onClick:()=>M("calendar"),children:e.jsx(Ne,{className:"h-4 w-4"})})]}),e.jsxs(c,{size:"sm",onClick:()=>g(!0),children:[e.jsx(ie,{className:"h-4 w-4 mr-1"}),"Add Event"]})]})]}),o&&e.jsx(pe,{circle:o,circleId:r,events:x,blurb:"Based on your circle type and location â one tap to add, reminders included.",onAdded:b}),N==="list"?e.jsxs("div",{className:"space-y-3",children:[F.length===0?e.jsx(ce,{art:"events",title:"Nothing in the diary",body:"Birthdays turn up here on their own once people fill in their date. Anything else â a wedding, a new baby, the end of term â you add.",action:{label:"Add an event",onClick:()=>g(!0)}}):F.map(s=>{const l=s.days_until<=7;return e.jsx(S,{className:`transition-colors ${l?"border-primary-200 bg-primary-50/50":""}`,children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex cursor-pointer items-center gap-4",onClick:()=>$(s),children:[e.jsx("img",{src:he(s.event_type,s.name).icon,alt:"",className:"h-12 w-12 shrink-0 rounded-2xl object-cover shadow-sm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-gray-900",children:s.name}),l&&e.jsx(W,{variant:"warning",className:"text-xs",children:I(s.days_until)})]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm text-gray-500 mt-1",children:[e.jsx("span",{children:G(s.date)}),s.time&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(oe,{className:"h-3 w-3"}),s.time]})]}),s.participant_name&&e.jsxs("p",{className:"text-sm text-gray-400 mt-1",children:["For ",s.participant_name]})]}),!l&&e.jsx("span",{className:"text-sm text-gray-400 whitespace-nowrap",children:I(s.days_until)}),e.jsx("button",{type:"button",onClick:m=>{m.stopPropagation(),t(h===s.id?null:s.id)},className:`rounded-lg p-2 transition-colors ${h===s.id?"bg-primary-100 text-primary-700":"text-gray-400 hover:bg-gray-100 hover:text-primary-600"}`,title:"Secret Santa","aria-label":`Secret Santa for ${s.name}`,children:e.jsx(ne,{className:"h-4 w-4"})})]}),h===s.id&&e.jsx(de,{eventId:s.id,circleId:r})]})},s.id)}),L.length>0&&e.jsxs("div",{className:"pt-4",children:[e.jsx("h2",{className:"mb-2 text-sm font-semibold uppercase tracking-wide text-gray-500",children:"Past events"}),e.jsx("div",{className:"space-y-2",children:L.slice(0,8).map(s=>e.jsx(S,{className:"bg-gray-50/60",children:e.jsxs(k,{className:"flex items-center gap-3 p-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"truncate font-medium text-gray-700",children:s.name}),e.jsxs("p",{className:"text-xs text-gray-400",children:[G(s.date),s.participant_name?` · ${s.participant_name}`:""]})]}),s.status==="completed"?e.jsx(W,{className:"bg-green-100 text-green-700",children:"Wrapped up â"}):o?.is_admin?e.jsx(c,{size:"sm",variant:"outline",onClick:()=>{u(s),T(!!s.participant)},children:"ð Wrap up"}):e.jsx("span",{className:"text-xs text-gray-400",children:"Done"})]})},`past-${s.id}`))})]})]}):e.jsx(S,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:d.toLocaleDateString("en-AU",{month:"long",year:"numeric"})}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(c,{variant:"ghost",size:"sm",onClick:K,children:"Today"}),e.jsx(c,{variant:"ghost",size:"sm",onClick:V,children:e.jsx(re,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"sm",onClick:J,children:e.jsx(le,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"grid grid-cols-7 mb-2",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(s=>e.jsx("div",{className:"text-center text-xs font-medium text-gray-500 py-2",children:s},s))}),e.jsx("div",{className:"grid grid-cols-7 gap-px bg-gray-200 rounded-lg overflow-hidden",children:Q.map((s,l)=>{const m=s.getMonth()===d.getMonth(),v=D(s)===D(B),C=O(s);return e.jsxs("div",{className:` 2 min-h-[80px] p-1 bg-white 3 ${m?"":"bg-gray-50"} 4 `,children:[e.jsx("div",{className:` 5 text-sm font-medium mb-1 w-7 h-7 flex items-center justify-center rounded-full 6 ${v?"bg-primary-600 text-white":""} 7 ${m?"text-gray-700":"text-gray-400"} 8 `,children:s.getDate()}),e.jsxs("div",{className:"space-y-0.5",children:[C.slice(0,2).map(y=>{const X=R[y.event_type]||"bg-gray-500";return e.jsxs("div",{className:"text-xs truncate px-1 py-0.5 rounded flex items-center gap-1",title:y.name,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${X} flex-shrink-0`}),e.jsx("span",{className:"truncate",children:y.name})]},y.id)}),C.length>2&&e.jsxs("div",{className:"text-xs text-gray-400 px-1",children:["+",C.length-2," more"]})]})]},l)})}),e.jsx("div",{className:"flex flex-wrap gap-4 mt-4 pt-4 border-t",children:["birthday","anniversary","holiday","custom"].map(s=>e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-600",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${R[s]}`}),e.jsx("span",{className:"capitalize",children:s})]},s))})]})}),E&&e.jsx(xe,{event:E,onClose:()=>$(null)}),p&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-end justify-center bg-black/50 p-4 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:items-center",onClick:()=>u(null),children:e.jsxs("div",{className:"w-full max-w-md rounded-3xl bg-white p-6 shadow-xl",onClick:s=>s.stopPropagation(),children:[e.jsxs("h3",{className:"font-display text-lg font-semibold text-gray-900",children:["Wrap up ",p.name,"?"]}),e.jsx("p",{className:"mt-1 text-sm text-gray-600",children:"Marks the event as completed and lets everyone know it's a wrap."}),p.participant&&e.jsxs("label",{className:"mt-4 flex items-start gap-3 rounded-2xl bg-primary-50 p-3 text-sm text-primary-800",children:[e.jsx("input",{type:"checkbox",checked:z,onChange:s=>T(s.target.checked),className:"mt-0.5 rounded border-gray-300 text-primary-600"}),e.jsxs("span",{children:[e.jsx("strong",{children:"Reveal the gifts ð"})," â ",p.participant_name," will finally see who claimed what on their wishlist."]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(c,{variant:"outline",size:"sm",onClick:()=>u(null),children:"Cancel"}),e.jsx(c,{size:"sm",disabled:A,onClick:async()=>{P(!0);try{await ye.complete(p.id,!!p.participant&&z),u(null),b()}catch(s){console.error("Failed to complete event:",s)}finally{P(!1)}},children:A?"Wrappingâ¦":"Complete event"})]})]})}),q&&e.jsx(me,{circleId:r,onClose:()=>g(!1),onCreated:H})]})}export{Ie as EventsPage};
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.