1import{j as e,A as zt,m as Ve}from"./vendor-motion-BCZB3-z1.js";import{a as g}from"./vendor-sentry-DP0LZMSq.js";import{ah as it,ai as Le,c as je,$ as Oe,aj as X,s as A,ak as lt,k as F,I as Y,L as ct,al as ge,D as ye,y as be,z as _e,A as Ne,E as ve,B as w,f as z,am as dt,G as Gt,a as we,e as Kt,t as Ht,an as Wt,ao as B,ap as U,aq as $,ar as q,as as V,a2 as ae,p as Qt,q as te,at as Yt,au as ze,av as Ge,S as Bt,aw as Jt,ax as Xt,U as mt,ay as ut,a0 as Zt,az as Ke,aA as es,aB as ts,aC as ss,aD as as,aE as ns}from"./index-ByyljyvC.js";import{t as ke,e as He,f as O,g as os,a as rs}from"./eventTime-Cb27oUFt.js";import{P as is,S as We}from"./PortalPage-C7fYkBhT.js";import{f as ls,h as ht,g as xt,a as pt,b as gt,c as Qe,d as ft,C as cs,u as ds,E as Ce}from"./EventCard-BOAIwoTX.js";import{a as oe,s as jt,C as ms,i as us}from"./calendar-BoSodz7a.js";import{P as yt,a as bt,b as _t}from"./popover-Cf3VxTP-.js";import{S as G,a as K,b as H,c as W,d as Q}from"./select-DH3IGvLw.js";import{f as M}from"./format-BiImzp_i.js";import{S as hs}from"./settings-2-DT0aHqOQ.js";import{C as Ie}from"./mapProvider-CqOFSBae.js";import{c as Nt}from"./copyToClipboard-DvXTn8RG.js";import{C as vt}from"./clock-Cv5gjkaH.js";import{D as wt}from"./download-SnScmOhL.js";import{C as Te}from"./card-DN92vKL9.js";import{S as J}from"./skeleton-uZ7YvIZJ.js";import{E as Ye}from"./empty-state-DV0B7k45.js";import{S as xs}from"./sliding-pill-tabs-7M78CjgG.js";import{A as ps,a as gs,b as fs,c as js,d as ys,e as bs,f as _s,g as Ns}from"./alert-dialog-BtRF7Zb-.js";import{f as vs}from"./vendor-react-D0KsNtg2.js";import{e as ws}from"./endOfMonth-BsqzHdGd.js";import{t as Me}from"./en-US-wfBU2YNu.js";import{L as Es}from"./list-BcfSZfpa.js";import{C as Ss}from"./chevron-left-DVXp6UXD.js";import{i as ks}from"./subDays-DHuPv7JS.js";import{P as Be}from"./plus-9mKG1X3O.js";import"./vendor-supabase-D_im1pln.js";import"./arrow-left-vLnC6qBM.js";import"./pencil-DBqoWshF.js";import"./trash-2-Bd2L7_Yq.js";import"./index-DpwtpmPA.js";const Cs=it("Grid3x3",[["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"}]]);const Ts=it("Rss",[["path",{d:"M4 11a9 9 0 0 1 9 9",key:"pv89mb"}],["path",{d:"M4 4a16 16 0 0 1 16 16",key:"k0647b"}],["circle",{cx:"5",cy:"19",r:"1",key:"bfqh0e"}]]);function Ms(t,a){const o=Me(t.start),r=Me(t.end);let d=+o>+r;const i=d?+o:+r,u=d?r:o;u.setHours(0,0,0,0);let j=1;const m=[];for(;+u<=i;)m.push(Me(u)),u.setDate(u.getDate()+j),u.setHours(0,0,0,0);return d?m.reverse():m}function Je(t,a){return oe(t,-1)}const Xe=30;function De(t){const a=/^(\d{1,2}):(\d{2})$/.exec(t);if(!a)return t;const o=Number(a[1]),r=a[2],d=o>=12?"PM":"AM";return`${o===0?12:o>12?o-12:o}:${r} ${d}`}const fe=Array.from({length:1440/Xe},(t,a)=>{const o=a*Xe,r=Math.floor(o/60),d=o%60,i=`${r.toString().padStart(2,"0")}:${d.toString().padStart(2,"0")}`;return{value:i,label:De(i)}});function Ze(t,a,o,r){const d=jt(new Date(t,a));for(;d.getDay()!==o;)d.setDate(d.getDate()+1);for(let i=1;i<r;i++)d.setDate(d.getDate()+7);return d}function Ps(t,a,o=new Date){const r=Ze(o.getFullYear(),o.getMonth(),t,a);if(r>o)return r;const d=oe(o,1);return Ze(d.getFullYear(),d.getMonth(),t,a)}function et(t,a,o){const r=new Date(t,a+1,0);for(;r.getDay()!==o;)r.setDate(r.getDate()-1);return r}function As(t,a=new Date){const o=et(a.getFullYear(),a.getMonth(),t);if(o>a)return o;const r=oe(a,1);return et(r.getFullYear(),r.getMonth(),t)}const tt="event_presets",re={amber:"bg-amber-500",blue:"bg-blue-500",rose:"bg-rose-500",green:"bg-primary",violet:"bg-violet-500",slate:"bg-slate-400"},Ds={amber:"Amber",blue:"Blue",rose:"Rose",green:"Green",violet:"Violet",slate:"Gray"},Ls=Object.keys(re),Et=[{value:1,label:"First"},{value:2,label:"Second"},{value:3,label:"Third"},{value:4,label:"Fourth"},{value:-1,label:"Last"}],St=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Os={location_source:"custom",location_name:"Johnson County Library â Leawood Pioneer",location_address:"4700 Town Center Dr, Leawood, KS 66211",location:"Johnson County Library â Leawood Pioneer, 4700 Town Center Dr, Leawood, KS 66211",location_place_id:null,location_lat:null,location_lng:null,location_maps_url:null},ne=[{id:"thirsty-thursday",title:"Thirsty Thursday",description:"Join us for drinks and socializing!",weekday:4,nth:3,startTime:"17:00",endTime:"20:00",color:"amber",location:null},{id:"mens-lunch",title:"Men's Lunch",description:"Monthly lunch gathering for the men of the community.",weekday:5,nth:2,startTime:"11:30",endTime:"13:00",color:"blue",location:null},{id:"ladies-lunch",title:"Ladies Lunch",description:"Monthly lunch gathering for the ladies of the community.",weekday:6,nth:1,startTime:"13:00",endTime:"14:30",color:"rose",location:null},{id:"hoa-meeting",title:"HOA Meeting",description:"Monthly HOA board meeting. All residents welcome.",weekday:2,nth:3,startTime:"19:00",endTime:"20:30",color:"green",location:Os}],st=/^([01]\d|2[0-3]):[0-5]\d$/;function kt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function se(t){return typeof t=="string"?t:null}function at(t){return typeof t=="number"&&Number.isFinite(t)?t:null}function Pe(t){return typeof t=="string"&&t.trim().length>0}function Fe(t){if(!kt(t))return null;const a=t.location_source;if(a!=="google_place"&&a!=="custom")return null;const o={location:se(t.location),location_source:a,location_name:se(t.location_name),location_address:se(t.location_address),location_place_id:se(t.location_place_id),location_lat:at(t.location_lat),location_lng:at(t.location_lng),location_maps_url:se(t.location_maps_url)};return!Pe(o.location)&&!Pe(o.location_name)&&!Pe(o.location_address)?null:o}function Is(t){if(!kt(t))return null;const{id:a,title:o,description:r,weekday:d,nth:i,startTime:u,endTime:j,color:m}=t;return typeof a!="string"||a.trim().length===0||typeof o!="string"||!Number.isInteger(d)||d<0||d>6||i!==1&&i!==2&&i!==3&&i!==4&&i!==-1||typeof u!="string"||!st.test(u)||typeof j!="str
1ing"||!st.test(j)||typeof m!="string"||!(m in re)?null:{id:a,title:o,description:typeof r=="string"?r:"",weekday:d,nth:i,startTime:u,endTime:j,color:m,location:Fe(t.location)}}function Fs(t){let a=t;if(typeof t=="string")try{a=JSON.parse(t)}catch{return ne}if(!Array.isArray(a))return ne;const o=new Set,r=[];for(const d of a){const i=Is(d);!i||o.has(i.id)||(o.add(i.id),r.push(i))}return r.length>0?r:ne}function Rs(t){return JSON.stringify(t.map(a=>({...a,location:Fe(a.location)})))}function Us(t,a=new Date){return t.nth===-1?As(t.weekday,a):Ps(t.weekday,t.nth,a)}function nt(t){var r;const a=((r=Et.find(d=>d.value===t.nth))==null?void 0:r.label)??"",o=St[t.weekday]??"";return`${a} ${o}, ${De(t.startTime)} â ${De(t.endTime)}`.trim()}function $s(){return{id:`preset-${Date.now()}`,title:"",description:"",weekday:4,nth:1,startTime:"17:00",endTime:"18:00",color:"slate",location:null}}const ot=["event-presets"];function Ct(){const t=Le(),{toast:a}=je(),{data:o,isLoading:r}=Oe({queryKey:ot,queryFn:async()=>{const{data:i,error:u}=await A.from("site_content").select("value").eq("key",tt).maybeSingle();return u?(console.error("Error fetching event presets:",u),ne):Fs(i==null?void 0:i.value)},staleTime:300*1e3}),d=X({mutationFn:async i=>{const{data:u}=await A.auth.getUser();if(!u.user)throw new Error("Not authenticated");const{error:j}=await A.from("site_content").upsert({key:tt,value:Rs(i),updated_at:new Date().toISOString(),updated_by:u.user.id},{onConflict:"key"});if(j)throw j},onSuccess:()=>{t.invalidateQueries({queryKey:ot}),a({title:"Presets saved"})},onError:i=>{console.error("Error saving event presets:",i),a({title:"Couldn't save the presets. Please try again.",variant:"destructive"})}});return{presets:o??ne,isLoading:r,savePresets:d.mutateAsync,isSaving:d.isPending}}async function qs(t){if(t.trim().length<2)return[];const{data:a,error:o}=await A.functions.invoke("place-search",{body:{mode:"autocomplete",query:t.trim()}});if(o)throw await lt(o,"Unable to search places right now.");return(a==null?void 0:a.suggestions)??[]}async function Vs(t){const{data:a,error:o}=await A.functions.invoke("place-search",{body:{mode:"details",placeId:t}});if(o)throw await lt(o,"Unable to load place details right now.");if(!(a!=null&&a.place))throw new Error("Place details were unavailable.");return a.place}const rt={location:"",location_source:"custom",location_name:null,location_address:null,location_place_id:null,location_lat:null,location_lng:null,location_maps_url:null};function zs(t){return"displayName"in t?t.displayName:t.title}function Gs(t){return"formattedAddress"in t?t.formattedAddress:t.subtitle}function Tt({value:t,onChange:a,disabled:o=!1,searchPlaces:r=qs,resolvePlace:d=Vs}){const[i,u]=g.useState((t==null?void 0:t.location_source)??"google_place"),[j,m]=g.useState((t==null?void 0:t.location_source)==="google_place"?t.location_name??"":""),[f,_]=g.useState([]),[l,N]=g.useState(!1),[S,k]=g.useState(!1),[p,n]=g.useState(null);g.useEffect(()=>{u((t==null?void 0:t.location_source)??"google_place")},[t==null?void 0:t.location_source]),g.useEffect(()=>{if((t==null?void 0:t.location_source)==="google_place"){m(t.location_name??"");return}m(""),_([])},[t==null?void 0:t.location_name,t==null?void 0:t.location_source]);const x=g.useMemo(()=>i!=="google_place"||!(t!=null&&t.location_name)&&!(t!=null&&t.location_address)?null:{title:t.location_name,address:t.location_address},[i,t]),c=y=>{if(_([]),n(null),y==="custom"){u("custom"),m(""),a({...rt,location:(t==null?void 0:t.location_source)==="custom"?t.location??"":""});return}u("google_place"),a({location:null,location_source:"google_place",location_name:null,location_address:null,location_place_id:null,location_lat:null,location_lng:null,location_maps_url:null})},v=async y=>{if(m(y),n(null),y.trim().length<2){_([]);return}N(!0);try{_(await r(y))}catch(b){_([]),n(b instanceof Error?b.message:"Unable to search places right now.")}finally{N(!1)}},P=async y=>{n(null),k(!0);try{const b=await d(y.placeId),Z=b.locationName??b.name??null,T=b.locationAddress??b.address??null,R=b.locationLat??b.latitude??null,I=b.locationLng??b.longitude??null,ie=b.locationMapsUrl??b.mapsUrl??null;a({location:ls({locationName:Z,locationAddress:T}),location_source:"google_place",location_name:Z,location_address:T,location_place_id:b.placeId,location_lat:R,location_lng:I,location_maps_url:ie}),m(Z??""),_([])}catch(b){n(b instanceof Error?b.message:"Unable to load place details right now.")}finally{k(!1)}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{role:"group","aria-label":"Location type",className:"inline-grid grid-cols-2 gap-1 rounded-lg bg-muted p-1",children:[{value:"google_place",label:"Find a place"},{value:"custom",label:"Enter a custom location"}].map(y=>{const b=i===y.value;return e.jsx("button",{type:"button","aria-pressed":b,"data-state":b?"active":"inactive",onClick:()=>c(y.value),disabled:o,className:F("h-9 rounded-md px-4 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",b?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:y.label},y.value)})}),i==="google_place"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("label",{htmlFor:"place-search-input",className:"sr-only",children:"Find a place"}),e.jsx(Y,{id:"place-search-input",value:j,placeholder:"Restaurant, clubhouse, or address",onChange:y=>{v(y.target.value)},disabled:o||S}),(l||S)&&e.jsx(ct,{className:"absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 animate-spin text-muted-foreground"})]}),f.length>0&&e.jsx("div",{className:"rounded-lg border border-border/70 bg-elevated",children:f.map(y=>e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 border-b border-border/60 px-3 py-3 text-left last:border-b-0 hover:bg-muted/40",onClick:()=>{P(y)},children:[e.jsx(ge,{className:"mt-0.5 h-4 w-4 shrink-0 text-primary"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block font-medium text-foreground",children:zs(y)}),e.jsx("span",{className:"block text-sm text-muted-foreground",children:Gs(y)})]})]},y.placeId))}),x&&e.jsx("div",{className:"rounded-xl border border-primary/20 bg-primary/5 dark:bg-primary/[0.14] px-4 py-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"rounded-full bg-primary/10 dark:bg-primary/[0.18] p-2 text-primary",children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[x.title&&e.jsx("p",{className:"font-medium text-foreground",children:x.title}),x.address&&e.jsx("p",{className:"text-sm text-muted-foreground",children:x.address})]})]})})]}):e.jsxs("div",{children:[e.jsx("label",{htmlFor:"custom-location-input",className:"sr-only",children:"Custom location"}),e.jsx(Y,{id:"custom-location-input",value:(t==null?void 0:t.location_source)==="custom"?t.location??"":"",placeholder:"Taylor's house",onChange:y=>a({...rt,location:y.target.value}),disabled:o})]}),p&&e.jsx("p",{className:"text-sm text-destructive",children:p})]})}const Ks="bg-primary/10 font-semibold text-primary dark:bg-primary/[0.14]";function Hs(t){return t.map(a=>({...a,location:a.location?{...a.location}:null}))}function Ws(t){for(const a of t){if(a.title.trim().length===0)return{id:a.id,message:"Every preset needs a title."};if(a.endTime<=a.startTime){const o=a.title.trim();return{id:a.id,message:`The end time for ${o} needs to be after its start time.`}}}return null}const Qs=({open:t,onOpenChange:a})=>{const{presets:o,savePresets:r,isSaving:d}=Ct(),[i,u]=g.useState([]),[j,m]=g.useState(null),[f,_]=g.useState(null);g.useEffect(()=>{var x;if(!t)return;const n=Hs(o);u(n),m(((x=n[0])==null?void 0:x.id)??null),_(null)},[t]);const l=i.find(n=>n.id===j)??i[0]??null,N=n=>{l&&(_(null),u(x=>x.map(c=>c.id===l.id?{...c,...n}:c)))},S=()=>{const n=$s();_(null),u(x=>[...x,n]),m(n.id)},k=()=>{var c,v;if(!l||i.length<=1)return;const n=i.findIndex(P=>P.id===l.id),x=i.filter(P=>P.id!==l.id);_(null),u(x),m(((c=x[Math.max(0,n-1)])==null?void 0:c.id)??((v=x[0])==null?void 0:v.id)??null)},p=async()=>{const n=Ws(i);if(n){m(n.id),_(n.message);return}try{await r(i.map(x=>({...x,title:x.title.trim(),location:Fe(x.location)}))),a(!1)}catch{}};return e.jsx(ye,{open:t,onOpenChange:a,children:e.jsxs(be,{className:"flex max-h-[88vh] w-[calc(100vw-2rem)] flex-col gap-5 overflow-hidden sm:max-w-3xl lg:max-w-5xl",children:[e.jsxs(_e,{className:"shrink-0",children:[e.jsx(Ne,{children:"Event presets"}),e.jsx(ve,{className:"sr-only",children:"These fill in the Create event form with one click. Changes apply for every admin and board member."})]}),e.jsxs("div",{className:"-mx-1 min-h-0 flex-1 overflow-y-auto px-1 md:grid md:grid-cols-[16rem_minmax(0,1fr)] md:gap-8 md:overflow-hidden",children:[e.jsxs("div",{className:"hidden md:block md:min-
1h-0 md:overflow-y-auto md:border-r md:border-border/70 md:pr-5 md:pt-1",children:[e.jsx("ul",{className:"space-y-1","aria-label":"Presets",children:i.map(n=>{const x=(l==null?void 0:l.id)===n.id;return e.jsx("li",{children:e.jsxs("button",{type:"button","aria-current":x?"true":void 0,onClick:()=>{m(n.id),_(null)},className:F("flex w-full items-start gap-3 rounded-lg px-3 py-2.5 text-left text-sm transition-colors hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",x?Ks:"text-foreground"),children:[e.jsx("span",{className:F("mt-1.5 h-2.5 w-2.5 shrink-0 rounded-full",re[n.color]),"aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:n.title.trim()||"Untitled preset"}),e.jsx("span",{className:"block text-xs font-normal text-muted-foreground",children:nt(n)})]})]})},n.id)})}),e.jsx(w,{type:"button",variant:"outline",size:"sm",className:"mt-3 w-full",onClick:S,children:"Add preset"})]}),e.jsxs("div",{className:"space-y-5 md:min-h-0 md:overflow-y-auto md:pr-2 md:pt-1",children:[e.jsxs("div",{className:"space-y-2 md:hidden",children:[e.jsx(z,{htmlFor:"preset-picker",children:"Preset"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(G,{value:(l==null?void 0:l.id)??"",onValueChange:n=>{m(n),_(null)},children:[e.jsx(K,{id:"preset-picker",className:"min-w-0 flex-1",children:e.jsx(H,{placeholder:"Choose a preset"})}),e.jsx(W,{children:i.map(n=>e.jsx(Q,{value:n.id,children:n.title.trim()||"Untitled preset"},n.id))})]}),e.jsx(w,{type:"button",variant:"outline",onClick:S,children:"Add preset"})]})]}),l&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"preset-title",children:"Title *"}),e.jsx(Y,{id:"preset-title",value:l.title,placeholder:"e.g., Thirsty Thursday",onChange:n=>N({title:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"preset-description",children:"Description"}),e.jsx(dt,{id:"preset-description",rows:3,className:"resize-none",value:l.description,placeholder:"What's this event about?",onChange:n=>N({description:n.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"preset-nth",children:"Repeats on"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(G,{value:String(l.nth),onValueChange:n=>N({nth:Number(n)}),children:[e.jsx(K,{id:"preset-nth","aria-label":"Which week of the month",children:e.jsx(H,{})}),e.jsx(W,{children:Et.map(n=>e.jsx(Q,{value:String(n.value),children:n.label},n.value))})]}),e.jsxs(G,{value:String(l.weekday),onValueChange:n=>N({weekday:Number(n)}),children:[e.jsx(K,{"aria-label":"Day of the week",children:e.jsx(H,{})}),e.jsx(W,{children:St.map((n,x)=>e.jsx(Q,{value:String(x),children:n},n))})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:nt(l)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"preset-start-time",children:"Start time"}),e.jsxs(G,{value:l.startTime,onValueChange:n=>N({startTime:n}),children:[e.jsx(K,{id:"preset-start-time",children:e.jsx(H,{placeholder:"Select time"})}),e.jsx(W,{children:fe.map(n=>e.jsx(Q,{value:n.value,children:n.label},n.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{htmlFor:"preset-end-time",children:"End time"}),e.jsxs(G,{value:l.endTime,onValueChange:n=>N({endTime:n}),children:[e.jsx(K,{id:"preset-end-time",children:e.jsx(H,{placeholder:"Select time"})}),e.jsx(W,{children:fe.map(n=>e.jsx(Q,{value:n.value,children:n.label},n.value))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{id:"preset-color-label",className:"text-sm font-medium leading-none",children:"Color"}),e.jsx("div",{role:"radiogroup","aria-labelledby":"preset-color-label",className:"flex flex-wrap gap-2.5",children:Ls.map(n=>{const x=l.color===n;return e.jsx("button",{type:"button",role:"radio","aria-checked":x,"aria-label":Ds[n],onClick:()=>N({color:n}),className:F("flex h-10 w-10 items-center justify-center rounded-full transition-shadow focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"),children:e.jsx("span",{className:F("block h-7 w-7 rounded-full ring-offset-2 ring-offset-card",re[n],x&&"ring-2 ring-foreground"),"aria-hidden":"true"})},n)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"block text-sm font-medium leading-none",children:"Location"}),e.jsx(Tt,{value:l.location,onChange:n=>N({location:n})},l.id)]}),e.jsx("div",{children:e.jsx(w,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:k,disabled:i.length<=1,children:"Remove preset"})})]})]})]}),f&&e.jsx("p",{role:"alert",className:"shrink-0 text-sm text-destructive",children:f}),e.jsxs(Gt,{className:"shrink-0",children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>a(!1),disabled:d,children:"Cancel"}),e.jsxs(w,{type:"button",onClick:()=>{p()},disabled:d,children:[d&&e.jsx(ct,{className:"animate-spin","aria-hidden":"true"}
1),d?"Saving...":"Save presets"]})]})]})})},Ys=Qt({title:te().min(1,"Title is required"),description:te().optional(),date:Yt({required_error:"Date is required"}),startTime:te().min(1,"Start time is required"),endTime:te().min(1,"End time is required"),hostName:te().optional()}),Bs=({open:t,onOpenChange:a,onSubmit:o,initialData:r,defaultHostName:d})=>{const[i,u]=g.useState(null),[j,m]=g.useState(!1),[f,_]=g.useState(!1),[l,N]=g.useState(null),{presets:S}=Ct(),{isAdmin:k}=we(),p=Kt({resolver:Ht(Ys),defaultValues:{title:"",description:"",startTime:"17:00",endTime:"20:00",hostName:d||""}});g.useEffect(()=>{if(r){const c=ke(r.start_time),v=ke(r.end_time);p.reset({title:r.title,description:r.description||"",date:c,startTime:M(c,"HH:mm"),endTime:M(v,"HH:mm"),hostName:r.host_name||""}),N(r.location_source==="google_place"?{location:r.location||null,location_source:"google_place",location_name:r.location_name||null,location_address:r.location_address||null,location_place_id:r.location_place_id||null,location_lat:r.location_lat??null,location_lng:r.location_lng??null,location_maps_url:r.location_maps_url||null}:r.location?{location:r.location,location_source:"custom",location_name:null,location_address:null,location_place_id:null,location_lat:null,location_lng:null,location_maps_url:null}:null)}else p.reset({title:"",description:"",date:void 0,startTime:"17:00",endTime:"20:00",hostName:d||""}),N(null);u(null)},[r,d,p,t]);const n=c=>{if(i===c.id){u(null),p.reset({title:"",description:"",date:void 0,startTime:"17:00",endTime:"20:00",hostName:d||""}),N(null);return}u(c.id),p.setValue("title",c.title),p.setValue("date",Us(c,ke(new Date))),p.setValue("startTime",c.startTime),p.setValue("endTime",c.endTime),p.setValue("description",c.description),N(c.location?{...c.location}:null)},x=async c=>{_(!0);try{const v=He(c.date,c.startTime),P=He(c.date,c.endTime);await o({title:c.title,description:c.description||void 0,start_time:v.toISOString(),end_time:P.toISOString(),host_name:c.hostName||null,location:(l==null?void 0:l.location)??null,location_source:(l==null?void 0:l.location_source)??null,location_name:(l==null?void 0:l.location_name)??null,location_address:(l==null?void 0:l.location_address)??null,location_place_id:(l==null?void 0:l.location_place_id)??null,location_lat:(l==null?void 0:l.location_lat)??null,location_lng:(l==null?void 0:l.location_lng)??null,location_maps_url:(l==null?void 0:l.location_maps_url)??null}),a(!1)}finally{_(!1)}};return e.jsx(ye,{open:t,onOpenChange:a,children:e.jsxs(be,{className:"flex max-h-[92vh] w-[calc(100vw-2rem)] flex-col gap-5 overflow-hidden sm:max-w-3xl lg:max-w-4xl",children:[e.jsxs(_e,{className:"shrink-0 pr-6",children:[e.jsx(Ne,{children:r?"Edit event":"Create new event"}),e.jsx(ve,{className:"sr-only",children:r?"Update the event details below.":"Fill in the details for the new community event."})]}),!r&&e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.jsx("span",{className:"mr-1 text-sm font-medium text-muted-foreground",children:"Start from"}),S.map(c=>e.jsxs(w,{type:"button",variant:i===c.id?"default":"outline",size:"sm",onClick:()=>n(c),"aria-pressed":i===c.id,className:"gap-2",children:[e.jsx("span",{className:F("h-2 w-2 rounded-full",i===c.id?"bg-primary-foreground/80":re[c.color]),"aria-hidden":"true"}),c.title]},c.id)),k&&e.jsxs(w,{type:"button",variant:"ghost",size:"sm",className:"gap-1.5 text-muted-foreground",onClick:()=>m(!0),children:[e.jsx(hs,{"aria-hidden":"true"}),"Edit presets"]})]}),!r&&k&&e.jsx(Qs,{open:j,onOpenChange:m}),e.jsx(Wt,{...p,children:e.jsxs("form",{onSubmit:p.handleSubmit(x),className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"-mx-1 min-h-0 flex-1 space-y-5 overflow-y-auto px-1 pb-5 sm:-mx-2 sm:px-2",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,1.25fr)_minmax(14rem,0.75fr)]",children:[e.jsx(B,{control:p.control,name:"title",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"Event title *"}),e.jsx(q,{children:e.jsx(Y,{placeholder:"e.g., Thirsty Thursday",...c})}),e.jsx(V,{})]})}),e.jsx(B,{control:p.control,name:"hostName",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"Host name"}),e.jsx(q,{children:e.jsx(Y,{placeholder:"Who's hosting?",...c})}),e.jsx(V,{})]})})]}),e.jsx(B,{control:p.control,name:"description",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"Description"}),e.jsx(q,{children:e.jsx(dt,{placeholder:"What's this event about?",className:"resize-none",rows:3,...c})}),e.jsx(V,{})]})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3 sm:items-end",children:[e.jsx(B,{control:p.control,name:"date",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"Date *"}),e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx(q,{children:e.jsxs(w,{variant:"outline",className:F("w-full pl-3 text-left font-normal",!c.value&&"text-muted-foreground"),children:[c.value?M(c.value,"PPP"):e.jsx("span",{children:"Pick a date"}),e.jsx(ae,{className:"ml-auto h-4 w-4 opacity-50"})]})})}),e.jsx(_t,{className:"w-auto p-0",align:"start",children:e.jsx(ms,{mode:"single",selected:c.value,onSelect:c.onChange,disabled:v=>v<new Date(new Date().setHours(0,0,0,0)),initialFocus:!0,className:F("p-3 pointer-events-auto")})})]}),e.jsx(V,{})]})}),e.jsx(B,{control:p.control,name:"startTime",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"Start time *"}),e.jsxs(G,{onValueChange:c.onChange,value:c.value,children:[e.jsx(q,{children:e.jsx(K,{children:e.jsx(H,{placeholder:"Select time"})})}),e.jsx(W,{children:fe.map(v=>e.jsx(Q,{value:v.value,children:v.label},v.value))})]}),e.jsx(V,{})]})}),e.jsx(B,{control:p.control,name:"endTime",render:({field:c})=>e.jsxs(U,{children:[e.jsx($,{children:"End time *"}),e.jsxs(G,{onValueChange:c.onChange,value:c.value,children:[e.jsx(q,{children:e.jsx(K,{children:e.jsx(H,{placeholder:"Select time"})})}),e.jsx(W,{children:fe.map(v=>e.jsx(Q,{value:v.value,children:v.label},v.value))})]}),e.jsx(V,{})]})})]}),e.jsxs(U,{children:[e.jsx($,{children:"Location"}
1),e.jsx(q,{children:e.jsx(Tt,{value:l,onChange:N})}),e.jsx(V,{})]})]}),e.jsxs("div",{className:"mt-3 flex shrink-0 justify-end gap-3 border-t pt-4",children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(w,{type:"submit",disabled:f,children:f?"Saving...":r?"Update event":"Create event"})]})]})})]})})},Js=()=>{const{toast:t}=je(),{user:a}=we(),o=Le(),{data:r,isLoading:d}=Oe({queryKey:["calendar-token",a==null?void 0:a.id],queryFn:async()=>{if(!a)return null;const{data:m,error:f}=await A.from("calendar_tokens").select("*").eq("user_id",a.id).single();if(f&&f.code!=="PGRST116")throw f;return m},enabled:!!a}),i=X({mutationFn:async()=>{if(!a)throw new Error("Not authenticated");const{data:m,error:f}=await A.from("calendar_tokens").insert({user_id:a.id}).select().single();if(f)throw f;return m},onSuccess:()=>{o.invalidateQueries({queryKey:["calendar-token"]}),t({title:"Calendar subscription created",description:"You can now add this feed to your calendar app."})},onError:m=>{ze(m),t({title:"Error creating subscription",description:Ge(m),variant:"destructive"})}}),u=X({mutationFn:async()=>{if(!a||!r)throw new Error("No token to regenerate");await A.from("calendar_tokens").delete().eq("user_id",a.id);const{data:m,error:f}=await A.from("calendar_tokens").insert({user_id:a.id}).select().single();if(f)throw f;return m},onSuccess:()=>{o.invalidateQueries({queryKey:["calendar-token"]}),t({title:"Token regenerated",description:"Your old calendar subscription will no longer work. Add the new URL to your calendar."})},onError:m=>{ze(m),t({title:"Error regenerating token",description:Ge(m),variant:"destructive"})}});return{calendarToken:r,isLoading:d,createToken:i,regenerateToken:u,getSubscriptionUrl:()=>r?`${Bt}/functions/v1/calendar-feed?token=${r.token}`:null}},Xs=({open:t,onOpenChange:a})=>{const{calendarToken:o,isLoading:r,createToken:d,regenerateToken:i,getSubscriptionUrl:u}=Js(),[j,m]=g.useState(!1),f=u(),_=async()=>{f&&(await navigator.clipboard.writeText(f),m(!0),setTimeout(()=>m(!1),2e3))},l=()=>{d.mutate()},N=()=>{confirm("Are you sure? Your current subscription will stop working.")&&i.mutate()};return e.jsx(ye,{open:t,onOpenChange:a,children:e.jsxs(be,{className:"flex max-h-[calc(100dvh-2rem)] min-h-0 flex-col overflow-hidden p-0 sm:max-h-[min(44rem,calc(100dvh-4rem))] sm:max-w-2xl",children:[e.jsxs(_e,{className:"px-6 pt-6",children:[e.jsx(Ne,{children:"Subscribe to calendar"}),e.jsx(ve,{children:"Add community events to Apple Calendar, Google Calendar or Outlook."})]}),e.jsx("div",{className:"min-h-0 flex-1 space-y-6 overflow-y-auto overscroll-contain px-6 pb-6 pt-4",children:r?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(z,{children:"Your subscription link"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Y,{value:f||"",readOnly:!0,className:"font-mono text-xs"}),e.jsx(w,{variant:"outline",size:"icon",onClick:_,title:j?"Copied!":"Copy to clipboard",children:j?e.jsx(Jt,{className:"h-4 w-4 text-green-600 dark:text-green-400"}):e.jsx(Ie,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keep this URL private. Anyone with it can see your community events."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"How to subscribe"}),e.jsxs("div",{className:"divide-y divide-border",children:[e.jsxs("div",{className:"py-4 first:pt-2 last:pb-0",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Apple Calendar"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Open the ",e.jsx("strong",{children:"Calendar"})," app on your iPhone, iPad, or Mac â tap the calendar icon at the bottom of the screen â scroll all the way to the bottom and tap ",e.jsx("strong",{children:"Add Calendar"})," â choose ",e.jsx("strong",{children:"Add Subscription Calendar"})," â paste the URL above and tap ",e.jsx("strong",{children:"Subscribe"})]})]}),e.jsxs("div",{className:"py-4 first:pt-2 last:pb-0",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Google Calendar"}),e.jsxs("p",{className:"mt-1 space-y-1 text-sm text-muted-foreground",children:[e.jsxs("span",{className:"block",children:["Open ",e.jsx("strong",{children:"Google Calendar"})," on a computer (this can't be done from the mobile app) â find ",e.jsx("strong",{children:"Other
1calendars"})," in the left sidebar â click the ",e.jsx("strong",{children:"+"})," icon â select ",e.jsx("strong",{children:"From URL"})," â paste the URL above and click ",e.jsx("strong",{children:"Add calendar"})]}),e.jsx("span",{className:"block text-muted-foreground/70",children:"Once added, events will automatically appear in the Google Calendar app on your phone."})]})]}),e.jsxs("div",{className:"py-4 first:pt-2 last:pb-0",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Outlook"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Open ",e.jsx("strong",{children:"Outlook"})," on a computer or at outlook.com â go to ",e.jsx("strong",{children:"Calendar"})," â click ",e.jsx("strong",{children:"Add calendar"})," â select ",e.jsx("strong",{children:"Subscribe from web"})," â paste the URL above, give it a name, and click ",e.jsx("strong",{children:"Import"})]})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:o.last_used_at&&e.jsxs("span",{children:["Last synced: ",new Date(o.last_used_at).toLocaleDateString()]})}),e.jsxs(w,{variant:"ghost",size:"sm",onClick:N,disabled:i.isPending,className:"text-muted-foreground",children:[e.jsx(Xt,{className:"h-3 w-3 mr-1"}),"Regenerate link"]})]})]}):e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"Generate a personal subscription URL to sync events automatically."}),e.jsx(w,{onClick:l,disabled:d.isPending,children:d.isPending?"Creating...":"Generate subscription link"})]})})]})})};function Zs({event:t,open:a,onOpenChange:o,canEdit:r,onEdit:d,rsvpCount:i=0,isGoing:u=!1,onRsvp:j,onCancelRsvp:m,showRsvp:f=!1,isAdmin:_=!1}){const{profile:l}=we(),{toast:N}=je();if(!t)return null;const S=new Date(t.start_time),k=new Date(t.end_time),p=k.getTime()<Date.now(),n=t.location_source==="google_place"&&ht({locationName:t.location_name,locationAddress:t.location_address}),x=xt({location:t.location,locationName:t.location_name,locationAddress:t.location_address,locationLat:t.location_lat,locationLng:t.location_lng,locationMapsUrl:t.location_maps_url,locationPlaceId:t.location_place_id},l==null?void 0:l.preferred_map_provider),c=pt({location:t.location,locationName:t.location_name,locationAddress:t.location_address}),v=async()=>{if(!c)return;if(await Nt(c)){N({title:"Address copied!",description:"The event address is ready to paste."});return}N({title:"Unable to copy address",description:"Your browser blocked clipboard access. Please copy the address manually.",variant:"destructive"})};return e.jsx(ye,{open:a,onOpenChange:o,children:e.jsxs(be,{className:"sm:max-w-[560px]",children:[e.jsxs(_e,{children:[e.jsx(Ne,{className:" text-xl",children:t.title}),e.jsxs(ve,{children:[O(S,"EEEE, MMMM d, yyyy")," â¢"," ",O(S,"h:mm a")," - ",O(k,"h:mm a")]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ae,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"text-foreground",children:O(S,"PPPP")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(vt,{className:"h-4 w-4 text-primary shrink-0"}),e.jsxs("span",{className:"text-foreground",children:[O(S,"p")," - ",O(k,"p")]})]}),t.host_name&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(mt,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Posted by"}),e.jsx("span",{className:"text-foreground font-medium",children:t.host_name})]}),t.location&&e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(ge,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("div",{className:"min-w-0",children:n?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-foreground font-medium",children:t.location_name||t.location}),t.location_address&&e.jsx("p",{className:"text-muted-foreground",children:t.location_address}),e.jsx(gt,{eventId:t.id,startTime:t.start_time,locationLat:t.location_lat,locationLng:t.location_lng,locationSource:t.location_source,enabled:a}),(x||c)&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-3",children:[x&&e.jsxs("a",{href:x,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary underline-offset-4 hover:underline",children:[e.jsx(ut,{className:"h-3.5 w-3.5"}),"Open in Maps"]}),c&&e.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary underline-offset-4 hover:underline",children:[e.jsx(Ie,{className:"h-3.5 w-3.5"}),"Copy address"]})]})]}):e.jsx("span",{className:"text-foreground",children:t.location})})]})]}),t.description&&e.jsx("div",{className:"rounded-lg border p-3",children:e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.description})}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-start",children:[p&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"This event has ended."}),!p&&f&&j&&m&&e.jsx(Qe,{eventId:t.id,count:i,isGoing:u,onRsvp:j,onCancel:m,isAdmin:_,showCount:!1,buttonSize:"default"}),!p&&e.jsxs(w,{variant:"outline",className:"w-full sm:w-auto",onClick:()=>
1ft({title:t.title,description:t.description||void 0,location:t.location||void 0,latitude:t.location_lat||void 0,longitude:t.location_lng||void 0,startTime:S,endTime:k,hostName:t.host_name||void 0}),children:[e.jsx(wt,{className:"h-4 w-4 mr-2"}),"Add to your Calendar"]}),r&&e.jsx(w,{className:"w-full sm:w-auto",onClick:()=>d(t.id),children:"Edit Event"})]}),f&&i>0&&j&&m&&e.jsx("div",{className:"flex justify-start sm:justify-start",children:e.jsx(Qe,{eventId:t.id,count:i,isGoing:u,onRsvp:j,onCancel:m,compact:!0,isAdmin:_,countLabel:p?"went":"going"})}),f&&!p&&e.jsx(cs,{isGoing:u})]})]})})}const Ae=t=>{const a=t.toLowerCase();return a.includes("thirsty thursday")?{bg:"bg-amber-100 dark:bg-secondary-wash/[0.14]",text:"text-amber-800 dark:text-amber-300",dot:"bg-amber-500"}:a.includes("men's lunch")||a.includes("mens lunch")?{bg:"bg-blue-100 dark:bg-blue-900/30",text:"text-blue-800 dark:text-blue-400",dot:"bg-blue-500"}:a.includes("ladies lunch")||a.includes("ladies' lunch")?{bg:"bg-rose-100 dark:bg-rose-900/30",text:"text-rose-800 dark:text-rose-400",dot:"bg-rose-500"}:a.includes("hoa meeting")||a.includes("board meeting")?{bg:"bg-teal-100 dark:bg-teal-900/30",text:"text-teal-800 dark:text-teal-400",dot:"bg-teal-500"}:{bg:"bg-primary/10 dark:bg-primary/[0.18]",text:"text-primary",dot:"bg-muted-foreground"}},Aa=()=>{const{user:t,profile:a,isAdminOrBoardMember:o,isAdmin:r}=we(),{toast:d}=je(),i=Le(),[u,j]=g.useState(new Date),[m,f]=g.useState("list"),[_,l]=g.useState(!1),[N,S]=g.useState(!1),[k,p]=g.useState(null),[n,x]=g.useState(null),[c,v]=g.useState(!1),[P,y]=g.useState(null),[b,Z]=g.useState(""),[T,R]=vs(),{data:I=[],isLoading:ie}=Oe(ns),ee=Zt("event_rsvps"),Mt=I.map(s=>s.id),{counts:le,userRsvps:ce,rsvp:de,cancelRsvp:me}=ds(ee?Mt:[]),Pt=X({mutationFn:async s=>{const{data:h,error:E}=await A.from("events").insert({...s,created_by:t==null?void 0:t.id}).select().single();if(E)throw E},onSuccess:()=>{i.invalidateQueries({queryKey:["events"]}),d({title:"Event created successfully!"})},onError:s=>{d({title:"We couldn't save that event",description:"The event was not added to the calendar. Please check the details and try again.",variant:"destructive"})}}),At=X({mutationFn:async({id:s,...h})=>{const{error:E}=await A.from("events").update(h).eq("id",s);if(E)throw E},onSuccess:()=>{i.invalidateQueries({queryKey:["events"]}),d({title:"Event updated successfully!"})},onError:s=>{d({title:"We couldn't save your changes",description:"The event is unchanged. Please try again in a moment.",variant:"destructive"})}}),Dt=X({mutationFn:async s=>{await as("event",[s])},onSuccess:()=>{i.invalidateQueries({queryKey:["events"]}),d({title:"Event moved to Recently Deleted"})},onError:s=>{d({title:"We couldn't remove that event",description:"The event is still on the calendar. Please try again in a moment.",variant:"destructive"})}}),Lt=async s=>{k?await At.mutateAsync({id:k.id,...s}):await Pt.mutateAsync(s),p(null)},ue=s=>{const h=I.find(E=>E.id===s);h&&(p(h),l(!0))},Ot=s=>{x(s),v(!0)},Ee=()=>{if(!T.get("event"))return;const s=new URLSearchParams(T);s.delete("event"),R(s,{replace:!0})};g.useEffect(()=>{if(T.get(Ke)!==es||!o)return;p(null),l(!0);const s=new URLSearchParams(T);s.delete(Ke),R(s,{replace:!0})},[o,T,R]),g.useEffect(()=>{if(T.get("subscribe")!=="1")return;S(!0);const s=new URLSearchParams(T);s.delete("subscribe"),R(s,{replace:!0})},[T,R]);const Se=s=>{y(s)},It=()=>{P&&(Dt.mutate(P),y(null))},Ft=us(u,new Date),Re=s=>{const h=Ae(s.title),E=s.location_source==="google_place"&&ht({locationName:s.location_name,locationAddress:s.location_address}),D=xt({location:s.location,locationName:s.location_name,locationAddress:s.location_address,locationLat:s.location_lat,locationLng:s.location_lng,locationMapsUrl:s.location_maps_url,locationPlaceId:s.location_place_id},a==null?void 0:a.preferred_map_provider),L=pt({location:s.location,locationName:s.location_name,locationAddress:s.location_address});return e.jsxs("div",{children:[e.jsx("div",{className:`bg-gradient-to-r ${h.bg} px-4 py-3 border-b border-border/30`,children:e.jsx("h4",{className:`font-semibold text-sm ${h.text}`,children:s.title})}),e.jsxs("div",{className:"p-4 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ae,{className:"h-3.5 w-3.5 text-primary shrink-0"}),e.jsx("span",{className:"text-foreground",children:O(s.start_time,"EEEE, MMMM d, yyyy")})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(vt,{className:"h-3.5 w-3.5 text-primary shrink-0"}),e.jsxs("span",{className:"text-foreground",children:[O(s.start_time,"h:mm a")," - ",O(s.end_time,"h:mm a")]})]}),s.host_name&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(mt,{className:"h-3.5 w-3.5 text-primary shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Posted by"}),e.jsx("span",{className:"text-foreground font-medium",children:s.host_name})]}),s.location&&e.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[e.jsx(ge,{className:"h-3.5 w-3.5 text-primary shrink-0"}
1),e.jsx("div",{className:"min-w-0",children:E?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium text-foreground",children:s.location_name||s.location}),s.location_address&&e.jsx("p",{className:"text-muted-foreground",children:s.location_address}),e.jsx(gt,{eventId:s.id,startTime:s.start_time,locationLat:s.location_lat,locationLng:s.location_lng,locationSource:s.location_source}),(D||L)&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-3",children:[D&&e.jsxs("a",{href:D,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary underline-offset-4 hover:underline",children:[e.jsx(ut,{className:"h-3.5 w-3.5"}),"Open in Maps"]}),L&&e.jsxs("button",{type:"button",onClick:()=>{Vt(L)},className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary underline-offset-4 hover:underline",children:[e.jsx(Ie,{className:"h-3.5 w-3.5"}),"Copy address"]})]})]}):e.jsx("span",{className:"text-foreground",children:s.location})})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground pt-2 border-t border-border/30 leading-relaxed",children:s.description}),e.jsx("div",{className:"pt-1",children:e.jsxs(w,{variant:"outline",size:"sm",className:"w-full h-8 text-xs",onClick:()=>ft({title:s.title,description:s.description||void 0,location:s.location||void 0,latitude:s.location_lat||void 0,longitude:s.location_lng||void 0,startTime:new Date(s.start_time),endTime:new Date(s.end_time),hostName:s.host_name||void 0}),children:[e.jsx(wt,{className:"h-3.5 w-3.5 mr-1.5"}),"Add to your Calendar"]})})]})]})},Ue=jt(u),Rt=ws(u),Ut=Ms({start:Ue,end:Rt}),he=I.filter(s=>{var E,D,L,C;if(!b)return!0;const h=b.toLowerCase();return s.title.toLowerCase().includes(h)||((E=s.description)==null?void 0:E.toLowerCase().includes(h))||((D=s.location)==null?void 0:D.toLowerCase().includes(h))||((L=s.location_name)==null?void 0:L.toLowerCase().includes(h))||((C=s.location_address)==null?void 0:C.toLowerCase().includes(h))}),$t=s=>he.filter(h=>rs(h.start_time)===M(s,"yyyy-MM-dd"));g.useEffect(()=>{const s=T.get("event");if(!s||I.length===0)return;const h=I.find(E=>E.id===s);if(!h){d({title:"Event not found",description:"That event may have been removed or is no longer available.",variant:"destructive"}),Ee();return}f("list"),Ot(h),setTimeout(()=>{const E=document.getElementById(`event-${s}`);E==null||E.scrollIntoView({behavior:"smooth",block:"center"})},0)},[I,T]);const $e=new Date,xe=m==="grid"?he.filter(s=>os(s.start_time)===M(u,"yyyy-MM")):he.filter(s=>new Date(s.end_time)>=$e),qe=he.filter(s=>new Date(s.end_time)<$e).slice().sort((s,h)=>new Date(h.start_time).getTime()-new Date(s.start_time).getTime()),qt=a?`${a.first_name} ${a.last_name}`.trim():"",Vt=async s=>{if(!s)return;if(await Nt(s)){d({title:"Address copied!",description:"The event address is ready to paste."});return}d({title:"Unable to copy address",description:"Your browser blocked clipboard access. Please copy the address manually.",variant:"destructive"})};return e.jsxs(e.Fragment,{children:[e.jsxs(is,{width:"wide",back:!0,title:"Calendar",actions:e.jsxs(e.Fragment,{children:[e.jsxs(w,{variant:"outline",onClick:()=>S(!0),children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),"Subscribe"]}),o&&e.jsxs(w,{onClick:()=>l(!0),children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Add event"]})]}),children:[e.jsxs("div",{className:"mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"relative w-full sm:max-w-xl",children:[e.jsx(ts,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Y,{placeholder:"Search events...",value:b,onChange:s=>Z(s.target.value),className:"pl-10"})]}),e.jsx("div",{className:"flex w-full items-center justify-start sm:w-auto sm:justify-end",children:e.jsx(xs,{tabs:[{value:"list",label:"List",icon:Es},{value:"grid",label:"Calendar",icon:Cs}],value:m,onChange:s=>f(s),layoutId:"calendar-view-toggle-pill","aria-label":"Calendar view",className:"w-full sm:w-auto"})})]}),e.jsx(zt,{mode:"wait",children:m==="grid"?e.jsxs(Ve.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},children:[e.jsxs(Te,{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] items-center gap-2 mb-6",children:[e.jsx("div",{className:"flex justify-start",children:e.jsx(w,{variant:"outline",size:"icon","aria-label":`Go to ${M(Je(u),"MMMM yyyy")}`,onClick:()=>j(Je(u)),children:e.jsx(Ss,{className:"h-4 w-4"})})}),e.jsx("h2",{className:"text-xl font-semibold text-center",children:M(u,"MMMM yyyy")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[!Ft&&e.jsx(w,{variant:"outline",onClick:()=>j(new Date),children:"Today"}),e.jsx(w,{variant:"outline",size:"icon","aria-label":`Go to ${M(oe(u,1),"MMMM yyyy")}`,onClick:()=>j(oe(u,1)),children:e.jsx(ss,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-2",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(s=>e.jsx("div",{className:"text-center text-sm font-medium text-muted-foreground py-2",children:s},s))}),e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[Array.from({length:Ue.getDay()}).map((s,h)=>e.jsx("div",{className:"aspect-square"},`empty-${h}`)),Ut.map(s=>{const h=$t(s),E=ks(s,new Date),D=`aspect-square p-1 border rounded-lg transition-colors ${E?"border-primary bg-primary/5 dark:bg-primary/[0.14]":"border-border/50 hover:border-border"}`,L=e.jsxs("div",{className:"flex flex-col h-full text-left",children:[e.jsx("span",{className:`text-sm font-medium ${E?"text-primary":"text-foreground"}`,children:M(s,"d")}),e.jsxs("div",{className:"flex-1 overflow-hidden",children:[e.jsxs("div",{className:"hidden sm:block",children:[h.slice(0,2).map(C=>{const pe=Ae(C.title);return e.jsx("span",{className:`block w-full text-left text-xs ${pe.bg} ${pe.text} rounded px-1 py-0.5 truncate mb-0.5`,title:C.title,children:C.title},C.id)}),h.length>2&&e.jsxs("span",{className:"block text-xs text-muted-foreground",children:["+",h.length-2," more"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-0.5 sm:hidden mt-1",children:[h.slice(0,3).map(C=>{const pe=Ae(C.title);return e.jsx("div",{className:`w-1.5 h-1.5 rounded-full ${pe.dot}`,title:C.title},C.id)}),h.length>3&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-muted-foreground"})]})]})]});return h.length===0?e.jsx("div",{className:D,children:L},s.toISOString()):e.jsxs(yt,{children:[e.jsx(bt,{asChild:!0,children:e.jsx("button",{type:"button",className:`${D} block w-full cursor-pointer hover:bg-muted/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1`,"aria-label":h.length===1?`${M(s,"EEEE, MMMM d")}: ${h[0].title}`:`${M(s,"EEEE, MMMM d")}: ${h.length} events`,children:L})}),e.jsx(_t,{className:"w-80 p-0 overflow-hidden",side:"bottom",align:"center",sideOffset:8,collisionPadding:12,children:h.length===1?Re(h[0]):e.jsxs("div",{className:"max-h-[26rem] overflow-y-auto",children:[e.jsxs("div",{className:"px-4 py-3 bg-muted border-b border-border/30",children:[e.jsx("h4",{className:"font-semibold text-sm text-foreground",children:M(s,"EEEE, MMMM d")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[h.length," events"]})]}),e.jsx("div",{className:"divide-y divide-border/30",children:h.map(C=>e.jsx("div",{children:Re(C)},C.id))})]})})]},s.toISOString())})]})]}),e.jsxs("div",{className:"mt-8",children:[e.jsx(We,{as:"h3",title:m==="grid"?`Events in ${M(u,"MMMM yyyy")}`:"Upcoming events",className:"mb-4"}),e.jsx("div",{className:"space-y-4",children:ie?e.jsx("div",{className:"space-y-4","aria-hidden":"true",children:[1,2].map(s=>e.jsxs(Te,{className:"p-6",children:[e.jsx(J,{className:"h-6 w-1/3 mb-4"}),e.jsx(J,{className:"h-4 w-1/2 mb-2"}),e.jsx(J,{className:"h-4 w-2/3"})]},s))}):xe.length===0?e.jsx(Ye,{icon:ae,title:"No events this month",description:m==="grid"?"No events scheduled for this month.":"No upcoming events scheduled.",size:"compact"}):xe.slice(0,5).map(s=>e.jsx(Ce,{id:s.id,title:s.title,description:s.description,startTime:new Date(s.start_time),endTime:new Date(s.end_time),hostName:s.host_name,location:s.location,locationSource:s.location_source,locationName:s.location_name,locationAddress:s.location_address,locationLat:s.location_lat,locationLng:s.location_lng,locationMapsUrl:s.location_maps_url,locationPlaceId:s.location_place_id,isAdminOrBoard:o,onEdit:ue,onDelete:Se,showRsvp:ee,rsvpCount:le[s.id]||0,isGoing:ce.has(s.id),onRsvp:de,onCancelRsvp:me,isAdmin:r},s.id))})]})]},"grid"):e.jsxs(Ve.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"space-y-6",children:[ie?e.jsx("div",{className:"space-y-4","aria-hidden":"true",children:[1,2,3].map(s=>e.jsxs(Te,{className:"p-6",children:[e.jsx(J,{className:"h-6 w-1/3 mb-4"}),e.jsx(J,{className:"h-4 w-1/2 mb-2"}),e.jsx(J,{className:"h-4 w-2/3"})]},s))}):xe.length===0?e.jsx(Ye,{icon:ae,title:"No Upcoming Events",description:"There are no events scheduled at this time.",action:o&&e.jsxs(w,{onClick:()=>l(!0),children:[e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Create new event"]})}):xe.map(s=>e.jsx("div",{id:`event-${s.id}`,children:e.jsx(Ce,{id:s.id,title:s.title,description:s.description,startTime:new Date(s.start_time),endTime:new Date(s.end_time),hostName:s.host_name,location:s.location,locationSource:s.location_source,locationName:s.location_name,locationAddress:s.location_address,locationLat:s.location_lat,locationLng:s.location_lng,locationMapsUrl:s.location_maps_url,locationPlaceId:s.location_place_id,isAdminOrBoard:o,onEdit:ue,onDelete:Se,showRsvp:ee,rsvpCount:le[s.id]||0,isGoing:ce.has(s.id),onRsvp:de,onCancelRsvp:me,isAdmin:r})},s.id)),qe.length>0&&e.jsxs("div",{className:"pt-8 border-t border-border",children:[e.jsx(We,{as:"h3",title:"Past events",className:"mb-4"}),e.jsx("div",{className:"space-y-4",children:qe.map(s=>e.jsx("div",{id:`event-${s.id}`,children:e.jsx(Ce,{id:s.id,title:s.title,description:s.description,startTime:new Date(s.start_time),endTime:new Date(s.end_time),hostName:s.host_name,location:s.location,locationSource:s.location_source,locationName:s.location_name,locationAddress:s.location_address,locationLat:s.location_lat,locationLng:s.location_lng,locationMapsUrl:s.location_maps_url,locationPlaceId:s.location_place_id,isAdminOrBoard:o,onEdit:ue,onDelete:Se,showRsvp:ee,rsvpCount:le[s.id]||0,isGoing:ce.has(s.id),onRsvp:de,onCancelRsvp:me,isAdmin:r})},s.id))})]})]},"list")})]}),e.jsx(Bs,{open:_,onOpenChange:s=>{l(s),s||p(null)},onSubmit:Lt,initialData:k||void 0,defaultHostName:qt}),e.jsx(Zs,{event:n,open:c,onOpenChange:s=>{v(s),s||(x(null),Ee())},canEdit:o,onEdit:s=>{o&&(v(!1),Ee(),ue(s))},showRsvp:ee,rsvpCount:n&&le[n.id]||0,isGoing:n?ce.has(n.id):!1,onRsvp:de,onCancelRsvp:me,isAdmin:r}),e.jsx(ps,{open:!!P,onOpenChange:()=>y(null),children:e.jsxs(gs,{children:[e.jsxs(fs,{children:[e.jsx(js,{children:"Delete this event?"}),e.jsx(ys,{children:"It will move to Recently Deleted with its RSVPs. An admin can restore it to the calendar."})]}),e.jsxs(bs,{children:[e.jsx(_s,{children:"Keep event"}),e.jsx(Ns,{onClick:It,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete event"})]})]})}),e.jsx(Xs,{open:N,onOpenChange:S})]})};export{Aa 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.