1import{j as t}from"./vendor-query-Cd1K-a1f.js";import{r as c}from"./vendor-react-BrtDVGEF.js";import{u as F,a as T,b as z,s as W,S as B,H as $,I as Y,B as S,F as G,C as H}from"./index-T3jWWUEU.js";import{B as j}from"./badge-BfoWilCF.js";import{FullScreenMap as V}from"./FullScreenMap-jUZ6xdKJ.js";import{i as b,s as v,g as y,a as w,b as P,f as E}from"./vendor-date-BEeda0v6.js";import{d as Q,a as Z,i as q,E as J}from"./vendor-icons-BKHJKxwD.js";import"./vendor-radix-C_0uraVY.js";import"./vendor-supabase-Bvq1Btpc.js";import"./vendor-charts-BfMOMpwd.js";import"./popover-B2EMP0za.js";import"./mapMetrics-d0dxhHU6.js";import"./select-BF8Jdk2g.js";import"./dropdown-menu-DtNRnxDu.js";import"./TypeCheckboxes-BspjhKHb.js";import"./checkbox-D08TNz87.js";import"./label-CJIksIzM.js";import"./vendor-mapbox-LWDo1F7w.js";/* empty css */const K=["All","Workouts","Trips","Races"],N={Workouts:"workouts",Trips:"trips",Races:"race"},_e=()=>{const[r,i]=c.useState([]),[l,u]=c.useState(!0),[a,p]=c.useState("All"),[h,g]=c.useState(!1),[f,m]=c.useState("");F(),T();const{categories:k}=z(!1),x=c.useMemo(()=>{const e={};return k.forEach(n=>{e[n.slug]=n.id}),e},[k]);c.useEffect(()=>{W.from("events").select("id, name, date, date_end, is_recurring_weekly, recurring_cadence, recurring_week_of_month, activity, details, location_name, google_maps_url, category_id, image_url").order("date",{ascending:!0}).then(({data:e})=>{i(e??[]),u(!1)})},[]);const L=(e,n)=>{if(n==="All")return!0;const s=N[n],o=x[s];if(o&&e.category_id===o)return!0;const d=e.activity.toLowerCase();switch(n){case"Workouts":return d==="workout";case"Trips":return d==="trip";case"Races":return d==="race";default:return!1}},A=c.useMemo(()=>{if(a==="All")return null;const e=N[a];return x[e]||null},[a,x]),I=c.useMemo(()=>Object.values(N).map(e=>x[e]).filter(e=>!!e),[x]),_=r.filter(e=>{var d,C;const n=L(e,a);if(!(e.is_recurring_weekly||e.recurring_cadence==="weekly"||e.recurring_cadence==="monthly")){const R=e.date_end?new Date(e.date_end):new Date(e.date);if(b(v(R),v(new Date)))return!1}if(!f)return n;const o=f.toLowerCase();return n&&(e.name.toLowerCase().includes(o)||(((d=e.details)==null?void 0:d.toLowerCase().includes(o))??!1)||(((C=e.location_name)==null?void 0:C.toLowerCase().includes(o))??!1)||e.activity.toLowerCase().includes(o))}).sort((e,n)=>{const s=D(e),o=D(n);return s.getTime()-o.getTime()}),O=c.useMemo(()=>{const e=new Date,n=r.filter(s=>!s.is_recurring_weekly&&!!s.date&&new Date(s.date)>=e).filter(s=>{var d;const o=((d=s.activity)==null?void 0:d.toLowerCase())||"";return o==="race"||o==="races"}).slice(0,50);if(n.length!==0)return{"@context":"https://schema.org","@type":"ItemList",itemListElement:n.map((s,o)=>({"@type":"ListItem",position:o+1,item:{"@type":"Event",name:s.name,startDate:s.date,...s.date_end?{endDate:s.date_end}:{},url:"https://www.zafiri.com/events",...s.image_url?{image:[s.image_url]}:{},eventAttendanceMode:"https://schema.org/OfflineEventAttendanceMode",eventStatus:"https://schema.org/EventScheduled",organizer:{"@type":"Organization",name:"Zafiri",url:"https://www.zafiri.com"},location:s.location_name?{"@type":"Place",name:s.location_name}:{"@type":"VirtualLocation",url:"https://www.zafiri.com/events"}}}))}},[r]);return t.jsxs("div",{className:"min-h-screen bg-background",children:[t.jsx(B,{title:"Events & Races - Zafiri",description:"Workouts, group runs, races, and training trips for endurance athletes. Find events near you.",jsonLd:O}),t.jsx($,{}),t.jsxs("main",{className:"container px-2 sm:px-4 py-16",children:[t.jsxs("div",{className:"mb-8 text-center",children:[t.jsx("h1",{className:"mb-4 text-4xl font-bold text-foreground",children:"Events"}),t.jsx("p",{className:"text-lg text-muted-foreground",children:"Races, training camps, and community events for endurance athletes"})]}),t.jsxs("div",{className:"mb-6 relative max-w-md mx-auto",children:[t.jsx(Q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),t.jsx(Y,{placeholder:"Search events...",value:f,onChange:e=>m(e.target.value),className:"pl-9"})]}),t.jsxs("div",{className:"mb-10 flex flex-wrap items-center justify-between gap-4",children:[t.jsx("div",{className:"flex flex-wrap items-center gap-2",children:K.map(e=>t.jsx("button",{onClick:()=>p(e),className:` 2 inline-flex items-center rounded-full border px-4 py-2 text-sm font-medium 3 transition-colors whitespace-nowrap cursor-pointer 4 ${a===e?"border-accent bg-accent text-accent-foreground":"border-border bg-background text-foreground hover:bg-muted"} 5 `,children:e},e))}),t.jsxs(S,{variant:"outline",size:"sm",onClick:()=>g(!0),children:[t.jsx(Z,{className:"mr-2 h-4 w-4"}),"Map View"]}
5)]}),l&&t.jsx("div",{className:"grid gap-6 md:grid-cols-2 lg:grid-cols-3",children:Array.from({length:3}).map((e,n)=>t.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-muted"},n))}),!l&&t.jsxs(t.Fragment,{children:[_.length>0&&t.jsx("div",{className:"grid gap-6 md:grid-cols-2 lg:grid-cols-3",children:_.map(e=>t.jsx(ee,{event:e},e.id))}),_.length===0&&t.jsxs("p",{className:"text-center text-muted-foreground py-12",children:["No ",a==="All"?"events":a.toLowerCase()," scheduled yet. Check back soon!"]})]})]}),t.jsx(V,{open:h,onClose:()=>g(!1),initialCategoryId:A,restrictCategoryIds:I}),t.jsx(G,{})]})},M=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],U=["1st","2nd","3rd","4th","5th"],D=r=>{const i=v(new Date),l=new Date(r.date);if(r.recurring_cadence==="weekly"||r.is_recurring_weekly){const u=y(l);let a=i;for(;y(a)!==u;)a=w(a,1);return b(a,i)&&(a=w(a,7)),a}if(r.recurring_cadence==="monthly"){const u=y(l),a=r.recurring_week_of_month||1,p=(g,f)=>{let m=new Date(g,f,1);for(;y(m)!==u;)m=w(m,1);return m=w(m,(a-1)*7),m};let h=p(i.getFullYear(),i.getMonth());if(b(h,i)){const g=P(i,1);h=p(g.getFullYear(),g.getMonth())}return h}return l},X=r=>{if(r.is_recurring_weekly||r.recurring_cadence==="weekly"||r.recurring_cadence==="monthly"){if(r.recurring_cadence==="monthly"){const a=M[new Date(r.date).getDay()];return`Every ${U[(r.recurring_week_of_month||1)-1]||""} ${a}`}return`Every ${M[new Date(r.date).getDay()]}`}const l=E(new Date(r.date),"EEEE, MMMM d, yyyy");if(r.date_end){const u=E(new Date(r.date_end),"MMMM d, yyyy");return`${l} â ${u}`}return l},ee=({event:r,isPast:i})=>t.jsxs(H,{className:`overflow-hidden transition-all duration-300 hover:shadow-lg ${i?"opacity-70":""}`,children:[r.image_url&&t.jsx("img",{src:r.image_url,alt:r.name,className:"h-44 w-full object-cover",loading:"lazy"}),t.jsxs("div",{className:"p-6",children:[t.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[t.jsx(j,{variant:i?"secondary":"default",children:r.activity}),(r.recurring_cadence==="weekly"||r.is_recurring_weekly)&&t.jsx(j,{variant:"outline",className:"text-xs",children:"Weekly"}),r.recurring_cadence==="monthly"&&t.jsx(j,{variant:"outline",className:"text-xs",children:"Monthly"})]}),t.jsx("h3",{className:"mb-2 text-lg font-bold text-foreground",children:r.name}),t.jsxs("div",{className:"mb-2 flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(q,{className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{children:X(r)})]}),r.details&&t.jsx("p",{className:"mb-4 text-sm text-muted-foreground line-clamp-3",children:r.details}),r.google_maps_url&&t.jsx(S,{asChild:!0,variant:"outline",size:"sm",children:t.jsxs("a",{href:r.google_maps_url,target:"_blank",rel:"noopener noreferrer",children:["View on Map ",t.jsx(J,{className:"ml-1 h-3 w-3"})]})})]})]});export{_e 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.