import{r as u,j as e}from"./vendor-react-DgEFbQIi.js";import{aG as ae,C as oe,j as le,_ as W,a as w,cP as B,cQ as Y,cR as z,a7 as ie,I as de,cc as ce,u as ue}from"./index-DFVuS8SP.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const me=ae("ListFilter",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]]),D=24*60,A=60,he=6*A;function xe(t){const s=t.reduce((n,o)=>Math.max(n,o.endMinutes),D),r=Math.min(Math.ceil((s-D)/A)*A,he);return D+Math.max(r,0)}function ge(t){const s=[...t].sort((i,m)=>i.startMinutes-m.startMinutes||i.endMinutes-m.endMinutes),r=[];let n=[],o=-1;const d=()=>{if(n.length===0)return;const i=Math.max(...n.map(m=>m.column))+1;for(const m of n)m.columns=i;r.push(...n),n=[],o=-1};for(const i of s){i.startMinutes>=o&&d();const m=new Set(n.filter(p=>p.endMinutes>i.startMinutes).map(p=>p.column));let x=0;for(;m.has(x);)x+=1;n.push({...i,column:x,columns:1}),o=Math.max(o,i.endMinutes)}return d(),r}function be(t,s){const r=Math.min(t.startMinutes,s),n=Math.min(t.endMinutes,s),o=r/s*100,d=Math.max(n-r,0)/s*100,i=100/t.columns;return{top:`${o}%`,height:`${d}%`,left:`${t.column*i}%`,width:`${i}%`}}const _=44,G=8,Q=[{chip:"bg-sky-500",block:"bg-sky-500/85 border-sky-600"},{chip:"bg-violet-500",block:"bg-violet-500/85 border-violet-600"},{chip:"bg-emerald-500",block:"bg-emerald-500/85 border-emerald-600"},{chip:"bg-amber-500",block:"bg-amber-500/85 border-amber-600"},{chip:"bg-rose-500",block:"bg-rose-500/85 border-rose-600"},{chip:"bg-cyan-500",block:"bg-cyan-500/85 border-cyan-600"},{chip:"bg-indigo-500",block:"bg-indigo-500/85 border-indigo-600"},{chip:"bg-lime-500",block:"bg-lime-500/85 border-lime-600"},{chip:"bg-fuchsia-500",block:"bg-fuchsia-500/85 border-fuchsia-600"},{chip:"bg-orange-500",block:"bg-orange-500/85 border-orange-600"}];function pe(t){return t===0?"12 AM":t===12?"12 PM":t<12?`${t} AM`:`${t-12} PM`}function H(t){const s=Math.max(t,0),r=Math.floor(s/60)%24,n=s%60,o=r>=12?"PM":"AM";return`${r%12||12}:${String(n).padStart(2,"0")} ${o}`}function X(t,s){const r=s>D?" (next day)":"";return`${H(t)} to ${H(s)}${r}`}function fe(t){const[s,r,n]=t.split("-").map(Number),o=new Date(s,r-1,n);return{weekday:o.toLocaleDateString(void 0,{weekday:"short"}),dayOfMonth:o.getDate(),isToday:t===new Date().toISOString().slice(0,10)}}function ye(t){if(t.length===0)return"";const s=m=>{const[x,p,N]=m.split("-").map(Number);return new Date(x,p-1,N)},r=s(t[0]),n=s(t[t.length-1]),o=r.getMonth()===n.getMonth(),d=r.toLocaleDateString(void 0,{month:"short",day:"numeric"}),i=n.toLocaleDateString(void 0,o?{day:"numeric"}:{month:"short",day:"numeric"});return`${d} to ${i}`}function Ne({venues:t,hidden:s,colorFor:r,query:n,onQueryChange:o,onToggle:d,onSolo:i,onShowAll:m,onHideAll:x}){const p=t.length-s.size,N=n.trim().toLowerCase(),k=N?t.filter(b=>b.name.toLowerCase().includes(N)):t;return e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center gap-2 rounded-full border border-border bg-white px-3 py-1 text-xs font-medium text-foreground transition-colors hover:bg-muted",children:[e.jsx(me,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Venues",e.jsxs("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[0.65rem] tabular-nums text-muted-foreground",children:[p," of ",t.length]})]})}),e.jsxs(z,{align:"start",className:"w-72 p-0",children:[e.jsxs("div",{className:"border-b border-border p-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ie,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":!0}),e.jsx(de,{value:n,onChange:b=>o(b.target.value),placeholder:"Search venues","aria-label":"Search venues",className:"h-9 pl-8 text-sm"})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:m,className:"text-xs font-medium text-primary transition-colors hover:underline",children:"Show all"}),e.jsx("button",{type:"button",onClick:x,className:"text-xs font-medium text-muted-foreground transition-colors hover:underline",children:"Hide all"})]})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto p-1",role:"group","aria-label":"Venues",children:k.length===0?e.jsx("p",{className:"px-2 py-6 text-center text-xs text-muted-foreground",children:"No venues match your search."}):k.map(b=>{var f;const h=s.has(b.listingId);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted",children:[e.jsxs("button",{type:"button",onClick:()=>d(b.listingId),"aria-pressed":!h,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx("span",{className:w("h-2.5 w-2.5 shrink-0 rounded-full",(f=r.get(b.listingId))==null?void 0:f.chip,h&&"opacity-30"),"aria-hidden":!0}),e.jsx("span",{className:w("min-w-0 flex-1 truncate text-sm",h?"text-muted-foreground":"text-foreground"),children:b.name}),h?null:e.jsx(ce,{className:"h-3.5 w-3.5 shrink-0 text-primary","aria-hidden":!0})]}),e.jsx("button",{type:"button",onClick:()=>i(b.listingId),className:"shrink-0 rounded px-1.5 py-0.5 text-[0.65rem] font-medium text-muted-foreground transition-colors hover:bg-background hover:text-foreground",children:"Only"})]},b.listingId)})})]})]})})}function ve({days:t,venues:s,blocks:r,tone:n,onPrev:o,onNext:d,canGoPrev:i=!0,isLoading:m=!1,renderBlockDetail:x,emptyMessage:p,timeZoneLabel:N,singleVenueDefault:k=!1}){const b=u.useRef(null),[h,f]=u.useState(()=>new Set),[E,L]=u.useState(""),g=u.useRef(!1),j=k&&s.length>G,c=u.useMemo(()=>{const a=new Map;return s.forEach((l,y)=>{a.set(l.listingId,Q[y%Q.length])}),a},[s]),C=u.useMemo(()=>new Map(s.map(a=>[a.listingId,a])),[s]),M=u.useMemo(()=>r.filter(a=>!h.has(a.listingId)),[r,h]),q=u.useMemo(()=>{var l;const a=new Map;for(const y of t)a.set(y,[]);for(const y of M)(l=a.get(y.dateKey))==null||l.push(y);return a},[t,M]),U=u.useMemo(()=>M.length===0?null:Math.min(...M.map(a=>a.startMinutes)),[M]),S=u.useMemo(()=>xe(M),[M]),F=Math.ceil(S/60),J=S>D,Z=D/S*100;u.useEffect(()=>{const a=b.current;if(!a)return;const l=U??8*60;a.scrollTop=Math.max(0,l/60*_-_)},[U,t]),u.useEffect(()=>{g.current||!j||s.length===0||(f(new Set(s.slice(1).map(a=>a.listingId))),g.current=!0)},[j,s]);const K=a=>{f(l=>{const y=new Set(l);return y.has(a)?y.delete(a):y.add(a),y})},ee=()=>f(new Set),te=()=>f(new Set(s.map(a=>a.listingId))),se=a=>f(new Set(s.filter(l=>l.listingId!==a).map(l=>l.listingId))),ne=!m&&M.length===0;return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",onClick:o,disabled:!i,"aria-label":"Previous days",className:"rounded-md border border-border p-1.5 text-foreground transition-colors hover:bg-muted disabled:cursor-not-allowed disabled:opacity-40",children:e.jsx(oe,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx("button",{type:"button",onClick:d,"aria-label":"Next days",className:"rounded-md border border-border p-1.5 text-foreground transition-colors hover:bg-muted",children:e.jsx(le,{className:"h-4 w-4","aria-hidden":!0})}),e.jsx("span",{className:"ml-2 text-sm font-medium text-foreground",children:ye(t)}),m?e.jsx(W,{className:"ml-2 h-4 w-4 animate-spin text-muted-foreground","aria-label":"Loading availability"}):null]}),N?e.jsx("span",{className:"text-xs text-muted-foreground",children:N}):null]}),s.length>G?e.jsx(Ne,{venues:s,hidden:h,colorFor:c,query:E,onQueryChange:L,onToggle:K,onSolo:se,onShowAll:ee,onHideAll:te}):s.length>1?e.jsx("div",{className:"flex flex-wrap gap-2",role:"group","aria-label":"Venues",children:s.map(a=>{var y;const l=h.has(a.listingId);return e.jsxs("button",{type:"button",onClick:()=>K(a.listingId),"aria-pressed":!l,className:w("flex items-center gap-1.5 rounded-full border px-3 py-1 text-xs font-medium transition-colors",l?"border-border bg-transparent text-muted-foreground":"border-transparent bg-muted text-foreground"),children:[e.jsx("span",{className:w("h-2 w-2 shrink-0 rounded-full",(y=c.get(a.listingId))==null?void 0:y.chip,l&&"opacity-30"),"aria-hidden":!0}),e.jsx("span",{className:"max-w-[10rem] truncate",children:a.name})]},a.listingId)})}):null,j?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Showing one venue to keep the week readable. Open Venues to add others and compare."}):null,e.jsxs("div",{className:"overflow-hidden rounded-xl border border-border bg-white",children:[e.jsxs("div",{className:"grid border-b border-border bg-muted/40",style:{gridTemplateColumns:`3.5rem repeat(${t.length}, 1fr)`},children:[e.jsx("div",{"aria-hidden":!0}),t.map(a=>{const l=fe(a);return e.jsxs("div",{className:"px-1 py-2 text-center",children:[e.jsx("div",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:l.weekday}),e.jsx("div",{className:w("text-sm font-semibold",l.isToday?"text-primary":"text-foreground"),children:l.dayOfMonth})]},a)})]}),e.jsx("div",{ref:b,"data-testid":"week-grid-scroll",className:"max-h-[26rem] overflow-y-auto",children:e.jsxs("div",{className:"grid","data-testid":"week-grid-axis",style:{gridTemplateColumns:`3.5rem repeat(${t.length}, 1fr)`,height:`${S/60*_}px`},children:[e.jsxs("div",{className:"relative border-r border-border",children:[Array.from({length:F},(a,l)=>e.jsx("div",{className:"absolute right-1 -translate-y-1/2 text-[0.65rem] text-muted-foreground",style:{top:`${l*60/S*100}%`},children:l===0?"":pe(l%24)},l)),J?e.jsx("div",{className:"absolute right-1 text-[0.55rem] font-semibold uppercase tracking-wide text-primary",style:{top:`calc(${Z}% + 0.4rem)`},children:"Next day"}):null]}),t.map(a=>{const l=q.get(a)??[],y=ge(l.map((v,I)=>({id:`${v.listingId}-${I}`,startMinutes:v.startMinutes,endMinutes:v.endMinutes})));return e.jsxs("div",{className:"relative border-r border-border last:border-r-0",children:[Array.from({length:F},(v,I)=>e.jsx("div",{className:w("absolute inset-x-0",I===24?"border-t-2 border-dashed border-primary/50":"border-t border-border/40"),style:{top:`${I*60/S*100}%`},"aria-hidden":!0},I)),y.map(v=>{const I=Number(v.id.split("-").pop()),$=l[I],P=C.get($.listingId);if(!P)return null;const re=be(v,S),T=c.get($.listingId);return e.jsxs(B,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs("button",{type:"button",style:re,className:w("absolute overflow-hidden rounded-[3px] border px-1 py-0.5 text-left text-[0.6rem] font-medium leading-tight text-white transition-opacity hover:opacity-90",T==null?void 0:T.block,n==="open"&&"opacity-90"),"aria-label":`${P.name}, ${X($.startMinutes,$.endMinutes)}`,children:[e.jsx("span",{className:"block truncate",children:P.name}),e.jsx("span",{className:"block truncate opacity-90",children:H($.startMinutes)})]})}),e.jsx(z,{className:"w-64 text-sm",align:"start",children:x($,P)})]},v.id)})]},a)})]})})]}),ne&&p?e.jsx("p",{className:"py-2 text-center text-sm text-muted-foreground",children:p}):null]})}function je(t){const[s,r,n]=t.split("-").map(Number),o=new Date(s,r-1,n);return{weekday:o.toLocaleDateString(void 0,{weekday:"short"}),dayOfMonth:o.getDate()}}function we(t){return X(t.startMinutes,t.endMinutes)}function Se({days:t,selectedDay:s,onSelectDay:r,tab:n,onTabChange:o,venues:d,open:i,booked:m,isLoading:x=!1,renderVenueAction:p,renderBookedDetail:N,emptyAvailableMessage:k="Nothing open on this date.",emptyBookedMessage:b="Nothing booked on this date.",showEmptyVenues:h=!1}){const f=n==="available"?i:m,E=u.useMemo(()=>{const g=new Map;for(const c of f){if(c.dateKey!==s)continue;const C=g.get(c.listingId)??[];C.push(c),g.set(c.listingId,C)}for(const c of g.values())c.sort((C,M)=>C.startMinutes-M.startMinutes);const j=d.map(c=>({venue:c,slots:g.get(c.listingId)??[]}));return h?j:j.filter(c=>c.slots.length>0)},[f,s,d,h]),L=g=>w("flex-1 rounded-sm px-3 py-1.5 text-sm font-medium transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",n===g?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground");return e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",role:"group","aria-label":"Pick a date",children:t.map(g=>{const j=je(g),c=g===s;return e.jsxs("button",{type:"button",onClick:()=>r(g),"aria-pressed":c,className:w("flex shrink-0 flex-col items-center rounded-lg border px-2.5 py-1.5 transition-colors",c?"border-transparent bg-foreground text-background":"border-border bg-white text-foreground hover:bg-muted"),children:[e.jsx("span",{className:"text-[0.65rem] uppercase tracking-wide opacity-70",children:j.weekday}),e.jsx("span",{className:"text-sm font-semibold",children:j.dayOfMonth})]},g)})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{role:"tablist","aria-label":"Availability view",className:"flex h-10 w-full items-center rounded-md bg-muted p-1",children:[e.jsx("button",{type:"button",role:"tab","aria-selected":n==="available",onClick:()=>o("available"),className:L("available"),children:"Available"}),e.jsx("button",{type:"button",role:"tab","aria-selected":n==="booked",onClick:()=>o("booked"),className:L("booked"),children:"Booked"})]}),x?e.jsx(W,{className:"h-4 w-4 shrink-0 animate-spin text-muted-foreground","aria-label":"Loading availability"}):null]}),e.jsx("div",{role:"tabpanel",className:"min-w-0",children:E.length===0?e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:n==="available"?k:b}):e.jsx("ul",{className:"space-y-2",children:E.map(({venue:g,slots:j})=>e.jsxs("li",{className:w("rounded-lg border border-border px-4 py-3",n==="available"?"bg-white":"bg-muted/30"),children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-foreground",children:g.name}),p==null?void 0:p(g)]}),j.length===0?e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:n==="available"?"No open hours this day":"No bookings this day"}):e.jsx("ul",{className:"space-y-1.5",children:j.map(c=>e.jsxs("li",{children:[e.jsx("p",{className:w("text-xs font-medium",n==="available"?"text-emerald-600":"text-muted-foreground"),children:we(c)}),n==="booked"?N==null?void 0:N(c):null]},`${c.listingId}-${c.startMinutes}-${c.endMinutes}`))})]},g.listingId))})})]})}function V(t){const s=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0");return`${s}-${r}-${n}`}function O(t,s){const[r,n,o]=t.split("-").map(Number),d=new Date(r,n-1,o);return d.setDate(d.getDate()+s),V(d)}function R(t){const[s,r,n]=t.split("-").map(Number),d=(new Date(s,r-1,n).getDay()+6)%7;return O(t,-d)}function Ie(t){const s=ue(),r=s?3:7,n=u.useMemo(()=>(t==null?void 0:t.initialDateKey)??V(new Date),[t==null?void 0:t.initialDateKey]),[o,d]=u.useState(n),i=s?o:R(o),m=u.useMemo(()=>Array.from({length:r},(h,f)=>O(i,f)),[i,r]),x=t==null?void 0:t.minDateKey,p=!x||i>x,N=u.useCallback(()=>{d(h=>{const f=O(s?h:R(h),-r);return x&&f<x?x:f})},[s,x,r]),k=u.useCallback(()=>{d(h=>O(s?h:R(h),r))},[s,r]),b=u.useCallback(()=>d(n),[n]);return{start:i,visibleDays:r,days:m,goPrev:N,goNext:k,goToday:b,canGoPrev:p}}function Ce(t){const[s,r]=u.useState(null),n=V(new Date);return[s&&t.includes(s)?s:t.includes(n)?n:t[0]??"",r]}export{Se as D,ve as W,Ce as a,X as f,V as t,Ie as u};