1import{K as Le,r as v,j as e,B as J,a1 as be,F as me,d as $e,C as mt,S as ke,M as Ge,a as Qe,b as ht,l as Ze,h as ut,c as pt,a4 as Ue,e as xt,u as ft,g as gt,v as bt,z as yt,L as vt,I as jt,a0 as Nt,t as wt,o as kt}from"./index-_aijvlUq.js";import{u as Dt,P as Ct}from"./PageHeader-DCofr6qo.js";import{p as Ve}from"./performances-duTJPchz.js";import{d as St,e as Tt,u as Mt,a as $t,H as Lt,O as At,f as Rt,g as Et,P as It,b as Pt,h as Ot,c as Ft,m as Bt,r as Ke}from"./RehearsalsTabPanel-QAqBXhwA.js";import{v as Je}from"./venues-DxAiztOL.js";import{o as Yt}from"./orgEvents-BRXhXibs.js";import{e as Wt}from"./ensembles-WGlB365j.js";import{I as ve}from"./Input-ysTyZFq5.js";import{b as _t,A as Ht,u as zt,a as Ut}from"./useQuickActions-DMVMPpKD.js";import{E as Vt}from"./EmptyState-CPGKooqj.js";import{M as Ce}from"./Menu-CATQC14B.js";import{T as Kt}from"./Tabs-CGDUdv1I.js";import{a as Jt}from"./helpWanted-C0itiuLN.js";import"./helpRequests-Bol7uyz2.js";import"./RestoreEventDialog-B5yJWYUU.js";import"./ConfirmDialog-CODvETNM.js";import"./ActiveFiltersBar-DPDav4h_.js";import"./MusicLibraryFilterBar-C3yZnsfl.js";import"./Avatar-BMcjKrGk.js";import"./sectionLeader-CxeZyjmi.js";import"./useDragReorder-BPTlhWx5.js";import"./notifications-B26coFA7.js";import"./Badge-DJIi163x.js";const qt=[{date:"2025-01-01",name:"New Year's Day"},{date:"2025-01-20",name:"Martin Luther King Jr. Day"},{date:"2025-02-17",name:"Presidents' Day"},{date:"2025-05-26",name:"Memorial Day"},{date:"2025-06-19",name:"Juneteenth"},{date:"2025-07-04",name:"Independence Day"},{date:"2025-09-01",name:"Labor Day"},{date:"2025-10-13",name:"Columbus Day"},{date:"2025-11-11",name:"Veterans Day"},{date:"2025-11-27",name:"Thanksgiving"},{date:"2025-12-25",name:"Christmas Day"},{date:"2026-01-01",name:"New Year's Day"},{date:"2026-01-19",name:"Martin Luther King Jr. Day"},{date:"2026-02-16",name:"Presidents' Day"},{date:"2026-05-25",name:"Memorial Day"},{date:"2026-06-19",name:"Juneteenth"},{date:"2026-07-04",name:"Independence Day"},{date:"2026-09-07",name:"Labor Day"},{date:"2026-10-12",name:"Columbus Day"},{date:"2026-11-11",name:"Veterans Day"},{date:"2026-11-26",name:"Thanksgiving"},{date:"2026-12-25",name:"Christmas Day"},{date:"2027-01-01",name:"New Year's Day"},{date:"2027-01-18",name:"Martin Luther King Jr. Day"},{date:"2027-02-15",name:"Presidents' Day"},{date:"2027-05-31",name:"Memorial Day"},{date:"2027-06-19",name:"Juneteenth"},{date:"2027-07-04",name:"Independence Day"},{date:"2027-09-06",name:"Labor Day"},{date:"2027-10-11",name:"Columbus Day"},{date:"2027-11-11",name:"Veterans Day"},{date:"2027-11-25",name:"Thanksgiving"},{date:"2027-12-25",name:"Christmas Day"},{date:"2028-01-01",name:"New Year's Day"},{date:"2028-01-17",name:"Martin Luther King Jr. Day"},{date:"2028-02-21",name:"Presidents' Day"},{date:"2028-05-29",name:"Memorial Day"},{date:"2028-06-19",name:"Juneteenth"},{date:"2028-07-04",name:"Independence Day"},{date:"2028-09-04",name:"Labor Day"},{date:"2028-10-09",name:"Columbus Day"},{date:"2028-11-11",name:"Veterans Day"},{date:"2028-11-23",name:"Thanksgiving"},{date:"2028-12-25",name:"Christmas Day"}],Xt=(()=>{const s={};for(const c of qt)s[c.date]=c.name;return s})();function et(s){return Xt[s]||null}function Gt(s){const c=parseInt(s.slice(5,7),10);return c===12||c<=2?"winter":c<=5?"spring":c<=8?"summer":"fall"}const tt={winter:{bg:"#dbeafe",label:"Winter",text:"#1e40af"},spring:{bg:"#dcfce7",label:"Spring",text:"#166534"},summer:{bg:"#fef3c7",label:"Summer",text:"#a16207"},fall:{bg:"#fed7aa",label:"Fall",text:"#9a3412"}},Qt=[{bg:"#c7d2fe",text:"#3730a3"},{bg:"#bfdbfe",text:"#1e40af"},{bg:"#a5f3fc",text:"#155e75"},{bg:"#99f6e4",text:"#115e59"},{bg:"#bbf7d0",text:"#166534"},{bg:"#d9f99d",text:"#3f6212"},{bg:"#fef08a",text:"#854d0e"},{bg:"#fde68a",text:"#92400e"},{bg:"#fed7aa",text:"#9a3412"},{bg:"#fecaca",text:"#991b1b"},{bg:"#fbcfe8",text:"#9d174d"},{bg:"#ddd6fe",text:"#5b21b6"}],Pe=["January","February","March","April","May","June","July","August","September","October","November","December"],qe=["Su","Mo","Tu","We","Th","Fr","Sa"];function Zt({performances:s,rehearsals:c=[],orgEvents:j=[],blackoutDates:D=[],selectedId:u,onSelect:M,canAction:C=!1,onDayAction:p,onEmptyDayClick:$,forceViewMode:P=null}){const T=new Date,x=Le(),[y,R]=v.useState(T.getFullYear()),[S,Y]=v.useState(T.getMonth()),[_,W]=v.useState(P||"month"),f=P||_,K=P?()=>{}:W,[O,H]=v.useState(null),[L,U]=v.useState(null),[k,z]=v.useState(new Set);function h(){S===0?(R(a=>a-1),Y(11)):Y(a=>
1a-1)}function N(){S===11?(R(a=>a+1),Y(0)):Y(a=>a+1)}function b(){R(T.getFullYear()),Y(T.getMonth())}const Q={};for(const a of s)a.performanceDate&&!k.has(a.ensembleName)&&(Q[a.performanceDate]||(Q[a.performanceDate]=[]),Q[a.performanceDate].push(a));const l={};for(const a of c)a.rehearsalDate&&!k.has(a.ensembleName)&&(l[a.rehearsalDate]||(l[a.rehearsalDate]=[]),l[a.rehearsalDate].push(a));const o={};for(const a of j)a.eventDate&&(o[a.eventDate]||(o[a.eventDate]=[]),o[a.eventDate].push(a));const I="#7c3aed",Z={};for(const a of D)a.date&&(Z[a.date]||(Z[a.date]=[]),Z[a.date].push(a));function se({year:a,month:n,day:g,large:w=!1,colIndex:F=3}){const q=String(n+1).padStart(2,"0"),B=String(g).padStart(2,"0"),ee=`${a}-${q}-${B}`,ae=Q[ee]??[],X=l[ee]??[],oe=o[ee]??[],xe=Z[ee]??[],Ae=ee===x,Oe=ae.some(r=>r.id===u),re=ae.length>0,le=X.length>0,ce=oe.length>0,ye=xe.length>0,Re=ye&&(re||le)&&xe.some(r=>ae.some(de=>de.venueId===r.venueId)||X.some(de=>de.venueId===r.venueId)),rt=[...ae].sort((r,de)=>(r.ensembleName??"").localeCompare(de.ensembleName??"")),lt=[...X].sort((r,de)=>(r.ensembleName??"").localeCompare(de.ensembleName??"")),Ee=(re||le)&&ae.every(r=>!!r.cancelledAt)&&X.every(r=>!!r.cancelledAt);ae.some(r=>!!r.cancelledAt)||X.some(r=>!!r.cancelledAt);const ot=re?ne(rt[0].ensembleName):null,Fe=le?ne(lt[0].ensembleName):null,Ie=[...new Set([...ae.map(r=>r.ensembleName??""),...X.map(r=>r.ensembleName??"")])].filter(Boolean);let he,ue,pe,fe;re?(he="!rounded-sm",ue="",pe="text-white font-semibold",fe="cursor-pointer"):le?(he="!rounded-full",ue="",pe="text-white font-medium",fe=C?"cursor-pointer":"cursor-default"):ce?(he="!rounded-md",ue="",pe="text-white font-medium",fe="cursor-pointer"):Ae?(he="!rounded-full",ue="",pe="text-brand-primary font-bold",fe=C&&$?"cursor-pointer hover:bg-brand-primary/10":"cursor-default"):ye?(he="!rounded-full",ue="bg-red-50",pe="text-gray-500",fe="cursor-default"):(he="!rounded-full",ue="",pe="text-gray-500",fe=C&&$?"cursor-pointer hover:bg-gray-100":"cursor-default");const it=L&&(ae.some(r=>r.id===L)||X.some(r=>r.performanceId===L)),Be=Re?"ring-2 ring-red-500 ring-offset-1":Oe?"ring-2 ring-white ring-offset-1":it?"ring-2 ring-amber-400 ring-offset-1":Ae&&(re||le)?"ring-2 ring-offset-1 ring-brand-primary":Ae?"ring-2 ring-brand-primary":"",Ye=w?"w-7 h-7 text-xs":"w-5 h-5 text-[10px]",We=!re&&!le&&!ce,ct=re||le||ce||C&&We&&$,De=Ee?"#dc2626":ot||Fe||(ce?I:null),_e=Ee?"line-through decoration-[1.5px]":"",dt=re&&!le&&!Ee&&ae.every(r=>r.rosterMode==="selected"),He=De?dt?{backgroundColor:"#fff",color:De,boxShadow:`inset 0 0 0 2px ${De}`}:{backgroundColor:De}:void 0,ze=O===ee&&(re||le||ce||ye),ge=[];if(ze){Re&&ge.push({type:"conflict",label:"BLACKOUT CONFLICT"});for(const r of ae)ge.push({type:"perf",ensemble:r.ensembleName,title:r.title||"Performance",timeLabel:me(r.performanceTime),venue:r.venueName,color:ne(r.ensembleName),cancelled:!!r.cancelledAt,partial:r.rosterMode==="selected",cancellationReason:r.cancellationReason});for(const r of X)ge.push({type:"rehearsal",ensemble:r.ensembleName,title:r.performanceTitle?`Rehearsal for ${r.performanceTitle}${r.castOnly?" (not the whole band)":""}`:r.title||"Rehearsal",timeLabel:me(r.startTime),endLabel:me(r.endTime),venue:r.venueName,color:ne(r.ensembleName),cancelled:!!r.cancelledAt,cancellationReason:r.cancellationReason});for(const r of oe)ge.push({type:"event",title:r.title||"Event",timeLabel:me(r.startTime),endLabel:me(r.endTime),venue:r.venueName,color:I,cancelled:!!r.cancelledAt,cancellationReason:r.cancellationReason});for(const r of xe)ge.push({type:"blackout",venue:r.venueName,reason:r.reason})}return e.jsxs("div",{className:w?"relative flex flex-col items-center gap-px":"relative flex items-center justify-center",onMouseEnter:re||le||ce||ye?()=>{H(ee),re?U(ae[0].id):le&&X[0].performanceId&&U(X[0].performanceId)}:void 0,onMouseLeave:re||le||ce||ye?()=>{H(null),U(null)}:void 0,children:[ct?e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>{re?M?.(Oe?null:ae[0].id):le&&X[0].performanceId&&M?.(u===X[0].performanceId?null:X[0].performanceId),p&&(re||le||ce)&&p(ee,{perfs:ae,rehearsals:X,events:oe}),C&&We&&$&&$(ee)},style:He,className:`!p-0 ${Ye} flex items-center justify-center transition-colors ${he} ${ue} ${pe} ${fe} ${Be} ${_e}`,children:g}):e.jsx("span",{className:`${Ye} flex items-center justify-center ${he} ${ue} ${pe} ${Be} ${_e}`,style:He,children:g}),ye&&e.jsx("div",{className:"absolute inset-0 pointer-events-none flex items-center justify-center",children:e.jsx("div",{className:`${w?"w-7 h-7":"w-5 h-5"} rounded-full overflow-hidden`,children:e.jsx("svg",{className:"w-full h-full",viewBox:"0 0 20 20",preserveAspectRatio:"none",children:e.jsx("line",{x1:"3",y1:"3",x2:"17",y2:"17",stroke:Re?"#ef4444":"#9ca3af",strokeWidth:"2",strokeLinecap:"round"})})})}),(Ie.length>1||re&&le||ce&&(re||le))&&e.jsxs("div",{className:"flex gap-0.5",children:[re&&le&&Ie.length<=1?e.jsx("span",{className:"w-1.5 h-1 rounded-sm shrink-0",style:{backgroundColor:Fe}}):Ie.map(r=>e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0",style:{backgroundColor:ne(r)}},r)),ce&&(re||le)&&e.jsx("span",{className:"w-1 h-1 rounded-sm shrink-0",style:{backgroundColor:I}})]}),ze&&ge.length>0&&e.jsxs("div",{className:`absolute bottom-full mb-2 z-20 bg-gray-800 text-white rounded-lg pointer-events-none shadow-xl ${F<=1?"left-0":F>=5?"right-0":"left-1/2 -translate-x-1/2"}`,style:{minWidth:200,maxWidth:280},children:[e.jsx("div",{className:"px-3 py-2 space-y-2",children:ge.map((r,de)=>e.jsxs("div",{children:[de>0&&e.jsx("div",{className:"border-t border-gray-600 -mx-3 mb-2"}),r.type==="conflict"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-red-400 font-semibold text-xs",children:[e.jsx("span",{children:"â "}),e.jsx("span",{children:r.label})]}),(r.type==="perf"||r.type==="rehearsal"||r.type==="event")&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:r.partial?{backgroundColor:"transparent",boxShadow:`inset 0 0 0 1.5px ${r.color}`}:{backgroundColor:r.color}}),e.jsx("span",{className:"text-[11px] font-semibold truncate",children:r.type==="perf"?r.partial?"Performance · part of the band":"Performance":r.type==="rehearsal"?"Rehearsal":"Event"}),r.cancelled&&e.jsx("span",{className:"ml-auto text-[10px] font-bold tracking-wider px-1.5 py-0.5 rounded bg-red-500 text-white",children:"CANCELLED"})]}),e.jsx("div",{className:`text-xs text-gray-200 pl-3.5 ${r.cancelled?"line-through opacity-70":""}`,children:r.title}),r.timeLabel&&e.jsxs("div",{className:`text-[11px] text-gray-300 pl-3.5 ${r.cancelled?"line-through opacity-70":""}`,children:[r.timeLabel,r.endLabel?` â ${r.endLabel}`:""]}),r.venue&&e.jsx("div",{className:`text-[11px] text-gray-500 pl-3.5 ${r.cancelled?"line-through opacity-70":""}`,children:r.venue}),r.cancelled&&r.cancellationReason&&e.jsxs("div",{className:"text-[11px] text-red-300 pl-3.5 italic",children:["Reason: ",r.cancellationReason]})]}),r.type==="blackout"&&e.jsxs("div",{className:"flex items-center gap-1.5 text-red-300 text-xs",children:[e.jsx("span",{children:"â"}),e.jsxs("span",{children:[r.venue||"Venue",": ",r.reason||"Blackout"]})]})]},de))}),e.jsx("div",{className:`absolute top-full w-0 h-0 border-x-[6px] border-x-trans
1parent border-t-[6px] border-t-gray-800 ${F<=1?"left-3":F>=5?"right-3":"left-1/2 -translate-x-1/2"}`})]})]})}function V(a,n){const g=new Date(a,n,1).getDay(),w=new Date(a,n+1,0).getDate(),F=Array(g).fill(null);for(let q=1;q<=w;q++)F.push(q);return F}const E=y===T.getFullYear()&&S===T.getMonth(),ie=y===T.getFullYear(),te={};for(const a of s)a.ensembleName&&(te[a.ensembleName]=a.ensembleColor||null);for(const a of c)a.ensembleName&&!te[a.ensembleName]&&(te[a.ensembleName]=a.ensembleColor||null);function ne(a){return te[a]||be(a)}const d=Object.keys(te),A=P?null:e.jsx("div",{className:"flex rounded-md overflow-hidden border border-gray-200 text-xs shrink-0",children:[["month","Mo"],["year","Yr"],["timeline","TL"]].map(([a,n])=>e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>K(a),className:`!rounded-none !px-2 !py-1 ${f===a?"!bg-brand-primary !text-white font-medium":"!text-gray-500 hover:!bg-gray-50"}`,children:n},a))}),m=D.length>0;function G(a){z(n=>{const g=new Set(n);return g.has(a)?g.delete(a):g.add(a),g})}const t=j.length>0,i=s.length>0||c.length>0||t||m?e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-3 pt-2 border-t border-gray-100",children:[d.length>0?d.map(a=>{const n=k.has(a);return e.jsxs("button",{type:"button",onClick:()=>G(a),className:`flex items-center gap-1.5 text-xs transition-colors ${n?"text-gray-300 line-through":"text-gray-600 hover:text-gray-800"}`,children:[e.jsx("span",{className:"w-3.5 h-3.5 rounded-full inline-block shrink-0 transition-opacity",style:{backgroundColor:ne(a),opacity:n?.25:1}}),a]},a)}):e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"w-3.5 h-3.5 rounded-full bg-brand-primary inline-block"})," Concert"]}),s.length>0&&c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-300",children:"|"}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"w-3 h-3 rounded-sm border-2 border-gray-400 inline-block shrink-0"}),"Concert"]}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"w-3 h-3 rounded-full border-2 border-gray-400 inline-block shrink-0"}),"Rehearsal"]})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-300",children:"|"}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"w-3 h-3 rounded-md inline-block shrink-0",style:{backgroundColor:I}}),"Event"]})]}),m&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-300",children:"|"}),e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"relative w-3.5 h-3.5 rounded-full bg-red-50 inline-flex items-center justify-center shrink-0 overflow-hidden",children:e.jsx("svg",{className:"w-full h-full",viewBox:"0 0 20 20",children:e.jsx("line",{x1:"4",y1:"4",x2:"16",y2:"16",stroke:"#9ca3af",strokeWidth:"2",strokeLinecap:"round"})})}),"Blackout"]})]})]}):null;if(f==="month"){const a=V(y,S);return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:h,className:"!p-1","aria-label":"Previous month",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-700",children:[Pe[S]," ",y]}),!E&&e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:b,className:"text-xs text-brand-primary hover:underline",children:"Today"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[A,e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:N,className:"!p-1","aria-label":"Next month",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})})]})]}),e.jsx("div",{className:"grid grid-cols-7 mb-1",children:qe.map(n=>e.jsx("div",{className:"text-center text-xs font-medium text-gray-600 py-1",children:n},n))}),e.jsx("div",{className:"grid grid-cols-7",children:a.map((n,g)=>n===null?e.jsx("div",{},`pad-${g}`):e.jsx("div",{className:"flex items-center justify-center py-0.5",children:e.jsx(se,{year:y,month:S,day:n,large:!0,colIndex:g
1%7})},`${y}-${S}-${n}`))}),i]})}if(f==="timeline"){const a=k.size>0?s.filter(w=>!k.has(w.ensembleName)):s,n=k.size>0?c.filter(w=>!k.has(w.ensembleName)):c,g=`tl:${[...k].sort().join("|")}`;return e.jsx(aa,{performances:a,rehearsals:n,orgEvents:j,selectedId:u,onSelect:M,canAction:C,onDayAction:p,modeToggle:A,legend:i},g)}return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>R(a=>a-1),className:"!p-1","aria-label":"Previous year",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-700",children:y}),!ie&&e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:b,className:"text-xs text-brand-primary hover:underline",children:"This year"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[A,e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>R(a=>a+1),className:"!p-1","aria-label":"Next year",children:e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-3",children:Array.from({length:12},(a,n)=>{const g=V(y,n);return e.jsxs("div",{children:[e.jsx("p",{className:`text-xs font-semibold mb-1 cursor-pointer hover:text-brand-primary transition-colors ${y===T.getFullYear()&&n===T.getMonth()?"text-brand-primary":"text-gray-600"}`,onClick:()=>{Y(n),K("month")},children:Pe[n].slice(0,3)}),e.jsxs("div",{className:"grid grid-cols-7 gap-px",children:[qe.map(w=>e.jsx("div",{className:"text-center text-[8px] font-medium text-gray-300 leading-tight",children:w},w)),g.map((w,F)=>w===null?e.jsx("div",{},`pad-${n}-${F}`):e.jsx("div",{className:"flex items-center justify-center",children:e.jsx(se,{year:y,month:n,day:w,colIndex:F%7})},`${y}-${n}-${w}`))]})]},n)})}),i]})}const je=864e5,Ne=22;function Se(s){return s?new Date(s+"T00:00:00").toLocaleDateString("en-US",{month:"short",day:"numeric"}):""}const ea=90,ta=365;function Te(s,c){const j=new Date(s+"T00:00:00");return j.setDate(j.getDate()+c),mt(j)}function aa({performances:s,rehearsals:c,orgEvents:j=[],selectedId:D,onSelect:u,canAction:M,onDayAction:C,modeToggle:p,legend:$}){const P=v.useRef(null),T=Le(),[x,y]=v.useState(null),[R,S]=v.useState(!1),Y=R?null:Te(T,-90),_=R?null:Te(T,ta),W=t=>!t||(!Y||t>=Y)&&(!_||t<=_),f=R?0:s.filter(t=>!W(t.performanceDate)).length+c.filter(t=>!W(t.rehearsalDate)).length+j.filter(t=>!W(t.eventDate)).length;s=s.filter(t=>W(t.performanceDate)),c=c.filter(t=>W(t.rehearsalDate)),j=j.filter(t=>W(t.eventDate));const K={},O={};for(const t of c)if(t.performanceId)K[t.performanceId]||(K[t.performanceId]=[]),K[t.performanceId].push(t);else{const i=t.ensembleName||"Unassigned";O[i]||(O[i]=[]),O[i].push(t)}const H={};for(const t of s){const i=t.ensembleName||"Unassigned";H[i]||(H[i]=[]),H[i].push({performance:t,rehearsals:(K[t.id]||[]).sort((a,n)=>a.rehearsalDate.localeCompare(n.rehearsalDate))})}for(const t of Object.keys(O))H[t]||(H[t]=[]);const L=Object.entries(H).map(([t,i])=>({name:t,color:i[0]?.performance.ensembleColor||O[t]?.[0]?.ensembleColor||be(t),groups:i.sort((a,n)=>a.performance.performanceDate.localeCompare(n.performance.performanceDate)),standalone:(O[t]||[]).sort((a,n)=>a.rehearsalDate.localeCompare(n.rehearsalDate))})),U=[...s.map(t=>t.performanceDate),...c.map(t=>t.rehearsalDate),T].filter(Boolean).sort();if(U.length===0)return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsx("div",{className:"flex items-center justify-end mb-3",children:p}),e.jsx("p",{className:"text-sm text-gray-600 text-center py-8",children:"No performances scheduled."})]});const k=new Date(U[0]+"T00:00:00"),z=new Date(U[U.length-1]+"T00:00:00");if(k.setDate(k.getDate()-14),z.setDate(z.getDate()+7),!R){const t=new Date(Te(T,-90)+"T00:00:00"),i=new Date(Te(T,ea)+"T00:00:00");k<t&&k.setTime(t.getTime()),z<i&&z.setTime(i.getTime())}const N=(Math.round((z-k)/je)+1)*Ne;function b(t){const i=new Date(t+"T00:00:00");return Math.round((i-k)/je)*Ne}const Q=b(T),l=T,o=parseInt(l.slice(0,4),10),I=parseInt(l.slice(5,7),10)-1,Z=[];{const t=new Date(k);for(t.setDate(1);t<=z;){const i=new Date(t);i.setMonth(i.getMonth()+1);const a=t<k?k:t,n=i>z?new Date(z.getTime()+je):i,g=Math.round((a-k)/je)*Ne,w=Math.round((n-k)/je)*Ne;Z.push({key:`${t.getFullYear()}-${t.getMonth()}`,label:Pe[t.getMonth()].slice(0,3),showYear:t.getMonth()===0,year:t.getFullYear(),left
1:g,width:Math.max(0,w-g),color:Qt[t.getMonth()],isCurrent:t.getFullYear()===o&&t.getMonth()===I}),t.setMonth(t.getMonth()+1),t.setDate(1)}}const se=[],V=new Date(k),E=(1-V.getDay()+7)%7;for(V.setDate(V.getDate()+E);V<=z;)se.push({day:V.getDate(),offset:Math.round((V-k)/je)*Ne}),V.setDate(V.getDate()+7);v.useEffect(()=>{if(P.current){const t=P.current.clientWidth;P.current.scrollLeft=Math.max(0,Q-t/2)}},[Q,R]);const ie=120,te=64,ne=32,d=22,A=26,m=22,G="#7c3aed";for(const t of L){for(let i=0;i<t.groups.length;i++)t.groups[i]._row=i%2;t._rowCount=t.groups.length>1?2:1}return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 gap-2",children:[e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-700",children:"Timeline"}),(R||f>0)&&e.jsx("button",{type:"button",onClick:()=>S(t=>!t),className:"text-xs text-band-600 hover:text-band-700 hover:underline whitespace-nowrap",children:R?"Show recent only":`Show all dates (${f} outside this window)`})]}),p]}),L.length===0?e.jsx("p",{className:"text-sm text-gray-600 text-center py-8",children:f>0?e.jsxs(e.Fragment,{children:["Nothing scheduled in the next few months. ",e.jsx("button",{type:"button",onClick:()=>S(!0),className:"text-band-600 hover:text-band-700 hover:underline",children:"Show all dates"})," to see the ",f," outside this window."]}):"No performances scheduled."}):e.jsxs("div",{className:"flex",children:[e.jsxs("div",{className:"shrink-0",style:{width:ie},children:[e.jsx("div",{style:{height:ne}}),L.map(t=>e.jsx("div",{className:"border-b border-gray-100",style:{height:24+t._rowCount*te},children:e.jsxs("div",{className:"flex items-center gap-1.5 px-2 text-xs font-semibold text-gray-600 truncate",style:{height:24},children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:t.color}}),e.jsx("span",{className:"truncate",children:t.name})]})},t.name)),j.length>0&&e.jsx("div",{className:"border-b border-gray-100",style:{height:24+te},children:e.jsxs("div",{className:"flex items-center gap-1.5 px-2 text-xs font-semibold text-gray-600 truncate",style:{height:24},children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm shrink-0",style:{backgroundColor:G}}),e.jsx("span",{className:"truncate",children:"Events"})]})})]}),e.jsx("div",{ref:P,className:"flex-1 overflow-x-auto overflow-y-hidden",children:e.jsxs("div",{style:{width:N,position:"relative"},children:[e.jsxs("div",{className:"relative border-b border-gray-200",style:{height:ne},children:[Z.map((t,i)=>e.jsx("div",{className:"absolute top-0 flex items-start overflow-hidden",style:{left:t.left,width:t.width,height:ne,backgroundColor:t.color.bg,borderLeft:i===0?"none":"1px solid rgba(15,23,42,0.22)",boxShadow:t.isCurrent?`inset 0 -2px 0 ${t.color.text}`:"none"},children:e.jsxs("span",{className:"px-1.5 pt-0.5 text-[10px] font-bold uppercase tracking-wide whitespace-nowrap",style:{color:t.color.text},children:[t.label,t.showYear?` '${String(t.year).slice(2)}`:""]})},t.key)),se.map((t,i)=>e.jsx("span",{className:"absolute bottom-0 text-[8px] font-medium text-gray-500",style:{left:t.offset+1},children:t.day},i))]}),L.map(t=>e.jsxs("div",{className:"relative border-b border-gray-100",style:{height:24+t._rowCount*te},children:[e.jsx("div",{style:{height:24}}),t.groups.map(i=>{const a=b(i.performance.performanceDate),n=i.rehearsals[0]?.rehearsalDate,g=n?b(n):a,w=a-g+Ne,F=24+(i._row||0)*te,q=F+18;return e.jsxs("div",{children:[e.jsx("div",{className:"absolute truncate text-[10px] font-semibold pointer-events-none",style:{left:g,top:F+2,maxWidth:w+40,color:t.color},children:i.performance.title}),i.rehearsals.length>0&&e.jsx("div",{className:"absolute rounded-full",style:{left:g,top:q+5,width:w,height:3,backgroundColor:t.color,opacity:.15}}),i.rehearsals.map((B,ee)=>{const ae=b(B.rehearsalDate),X=!!B.cancelledAt;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:`absolute flex items-center justify-center rounded-md text-white text-[10px] font-semibold transition-shadow ${X?"ring-2 ring-red-500 ring-offset-1":"hover:ring-2 hover:ring-white hover:ring-offset-1"}`,style:{left:ae,top:q,width:d,height:d,backgroundColor:t.color,opacity:X?.35:.75},onClick:()=>{u?.(D===B.performanceId?null:B.performanceId),M&&C&&C(B.rehearsalDate,{perfs:[],rehearsals:[B]})},onMouseEnter:oe=>y({type:"rehearsal",data:B,x:oe.clientX,y:oe.clientY}),onMouseLeave:()=>y(null),children:["R",ee+1]}),e.jsx("div",{className:`absolute text-[9px] pointer-events-none whitespace-nowrap ${X?"text-gray-400 line-through":"text-gray-500"}`,style:{left:ae-6,top:q+d+2},children:Se(B.rehearsalDate)})]},B.id)}),(()=>{const B=!!i.performance.cancelledAt;return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:`absolute flex items-center justify-center rounded-full text-white text-[10px] font-bold transition-shadow ${D===i.performance.id?"ring-2 ring-white ring-offset-1":""} ${B?"ring-2 ring-red-500 ring-offset-1":"hover:ring-2 hover:ring-white hover:ring-offset-1"}`,style:{left:a-2,top:q-2,width:A,height:A,...i.performance.rosterMode==="selected"?{backgroundColor:"#fff",color:t.color,boxShadow:`inset 0 0 0 2.5px ${t.color}`}:{backgroundColor:t.color},opacity:B?.45:1},onClick:()=>{const ee=i.performance.id;u?.(D===ee?null:ee),M&&C&&C(i.performance.performanceDate,{perfs:[i.performance],rehearsals:[]})},onMouseEnter:ee=>y({type:"performance",data:i.performance,x:ee.clientX,y:ee.clientY}),onMouseLeave:()=>y(null),children:"P"}),e.jsx("div",{className:`absolute text-[9px] font-semibold pointer-events-none whitespace-nowrap ${B?"text-gray-400 line-through":""}`,style:{left:a-10,top:q+A+1,color:B?void 0:t.color},children:Se(i.performance.performanceDate)})]})})()]},i.performance.id)}),(t.standalone||[]).map(i=>{const a=b(i.rehearsalDate),n=42,g=!!i.cancelledAt;return e.jsxs("div",{children:[e.jsx("button",{type:"button",className:`absolute flex items-center justify-center rounded-md text-white text-[10px] font-semibold transition-shadow ${g?"ring-2 ring-red-500 ring-offset-1":"hover:ring-2 hover:ring-white hover:ring-offset-1"}`,style:{left:a,top:n,width:d,height:d,backgroundColor:t.color,opacity:g?.35:.75},onClick:()=>{M&&C&&C(i.rehearsalDate,{perfs:[],rehearsals:[i]})},onMouseEnter:w=>y({type:"rehearsal",data:i,x:w.clientX,y:w.clientY}),onMouseLeave:()=>y(null),children:"R"}),e.jsx("div",{className:`absolute text-[9px] pointer-events-none whitespace-nowrap ${g?"text-gray-400 line-through":"text-gray-500"}`,style:{left:a-6,top:n+d+2},children:Se(i.rehearsalDate)})]},i.id)})]},t.name)),j.length>0&&e.jsxs("div",{className:"relative border-b border-gray-100",style:{height:24+te},children:[e.jsx("div",{style:{height:24}}),j.map(t=>{if(!t.eventDate)return null;const i=b(t.eventDate),a=!!t.cancelledAt,n=42;return e.jsxs("div",{children:[e.jsx("div",{className:`absolute text-[10px] font-semibold pointer-events-none whitespace-nowrap ${a?"text-gray-400 line-through":""}`,style:{left:i,top:n-14,maxWidth:100,color:a?void 0:G},children:t.title}),e.jsx("button",{type:"button",className:`absolute flex items-center justify-center text-white text-[10px] font-bold transition-shadow ${a?"ring-2 ring-red-500 ring-offset-1":"hover:ring-2 hover:ring-white hover:ring-offset-1"}
1`,style:{left:i,top:n,width:m,height:m,backgroundColor:G,opacity:a?.4:1,transform:"rotate(45deg)"},onMouseEnter:g=>y({type:"event",data:t,x:g.clientX,y:g.clientY}),onMouseLeave:()=>y(null),children:e.jsx("span",{style:{transform:"rotate(-45deg)"},children:"â"})}),e.jsx("div",{className:`absolute text-[9px] pointer-events-none whitespace-nowrap ${a?"text-gray-400 line-through":"text-gray-500"}`,style:{left:i-6,top:n+m+4},children:Se(t.eventDate)})]},t.id)})]}),e.jsx("div",{className:"absolute top-0 bottom-0 border-l-2 border-dashed pointer-events-none",style:{left:Q,borderColor:"rgb(var(--brand-primary))"}}),e.jsx("div",{className:"absolute pointer-events-none",style:{left:Q-22,top:2},children:e.jsx("span",{className:"inline-block px-1.5 py-0.5 rounded text-[9px] font-bold uppercase tracking-wider text-white",style:{backgroundColor:"rgb(var(--brand-primary))"},children:"Today"})})]})})]}),L.length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100 flex flex-wrap gap-x-5 gap-y-1 text-xs text-gray-600",children:[L.map(t=>{const i=t.groups.filter(g=>!g.performance.cancelledAt).length,a=t.groups.reduce((g,w)=>g+w.rehearsals.filter(F=>!F.cancelledAt).length,0),n=i>0?(a/i).toFixed(1):"0";return e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:t.color}}),e.jsxs("span",{className:"font-medium",children:[t.name,":"]}),e.jsxs("span",{children:[i," ",i===1?"concert":"concerts",", ",a," ",a===1?"rehearsal":"rehearsals"]}),i>0&&e.jsxs("span",{className:"text-gray-400",children:["(avg ",n,"/concert)"]})]},t.name)}),j.filter(t=>!t.cancelledAt).length>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{backgroundColor:G}}),e.jsx("span",{className:"font-medium",children:"Events:"}),e.jsx("span",{children:j.filter(t=>!t.cancelledAt).length})]}),L.some(t=>t.groups.some(i=>i.performance.rosterMode==="selected"))&&e.jsxs("span",{className:"inline-flex items-center gap-1.5","data-testid":"partial-legend",children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0 border-[1.5px] border-gray-500 bg-white"}),e.jsx("span",{children:"Hollow = only part of the band plays it"})]})]}),x&&e.jsx("div",{className:"fixed z-50 bg-gray-800 text-white text-[10px] leading-tight rounded px-2.5 py-1.5 shadow-lg pointer-events-none max-w-56",style:{left:x.x+12,top:x.y-8},children:x.type==="rehearsal"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"font-semibold",children:[x.data.ensembleName," Rehearsal",x.data.cancelledAt?" · CANCELLED":""]}),e.jsx("div",{children:$e(x.data.rehearsalDate)}),x.data.startTime&&e.jsxs("div",{children:[me(x.data.startTime),x.data.endTime?`â${me(x.data.endTime)}`:""]}),x.data.venueName&&e.jsx("div",{children:x.data.venueName}),e.jsx("div",{className:"text-gray-400 mt-0.5",children:x.data.performanceTitle?`for: ${x.data.performanceTitle}`:x.data.title||"Standalone rehearsal"})]}):x.type==="event"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"font-semibold",children:[x.data.title,x.data.cancelledAt?" · CANCELLED":""]}),e.jsx("div",{children:$e(x.data.eventDate)}),x.data.startTime&&e.jsxs("div",{children:[me(x.data.startTime),x.data.endTime?`â${me(x.data.endTime)}`:""]}),x.data.venueName&&e.jsx("div",{children:x.data.venueName})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"font-semibold",children:[x.data.title||x.data.ensembleName,x.data.cancelledAt?" · CANCELLED":""]}),x.data.rosterMode==="selected"&&e.jsx("div",{className:"text-gray-300",children:"Only part of the band plays this one"}),e.jsx("div",{children:$e(x.data.performanceDate)}),x.data.performanceTime&&e.jsx("div",{children:me(x.data.performanceTime)}),x.data.venueName&&e.jsx("div",{children:x.data.venueName})]})}),$]})}const Me="__standalone__",at=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function sa(s,c,j){const D=[],u=new Date(s+"T12:00:00");u.setDate(u.getDate()+(j-u.getDay()+7)%7);const M=new Date(c+"T12:00:00");for(;u<=M&&D.length<53;){const C=u.getFullYear(),p=String(u.getMonth()+1).padStart(2,"0"),$=String(u.getDate()).padStart(2,"0");D.push(`${C}-${p}-${$}`),u.setDate(u.getDate()+7)}return D}function na(s){const c=new Date(s+"T12:00:00");return{day:at[c.getDay()].slice(0,3),date:c.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}}function st({date:s=null,performances:c=[],rehearsals:j=[],ensembles:D=[],venues:u=[],onCreate:M,onCancel:C}){const[p,$]=v.useState({ensembleId:D.length===1?D[0].id:"",fromDate:s||"",toDate:"",weekday:"",performanceId:Me,title:"",venueId:"",startTime:"",endTime:""}),[P,T]=v.useState(null),[x,y]=v.useState(new Set),[R,S]=v.useState(!1),Y=!!s,_=Y?s:p.fromDate,W=!!p.toDate,f=W||p.performanceId===Me,K=(c||[]).filter(h=>h.performanceDate&&h.ensembleId===p.ensembleId&&(!_||h.performanceDate>=_)),O=!W||p.toDate>=_,H=!!p.ensembleId&&!!_&&O&&(!W||p.weekday!==""),L=new Set([...(j||[]).filter(h=>h.ensembleId===p.ensembleId).map(h=>h.rehearsalDate),...(c||[]).filter(h=>h.ensembleId===p.ensembleId).map(h=>h.performanceDate)]);function U(h){const N=D.find(b=>b.id===h);$(b=>({...b,ensembleId:h,performanceId:Me,venueId:N?.defaultRehearsalVenueId||"",startTime:N?.defaultRehearsalStartTime||"",endTime:N?.defaultRehearsalEndTime||"",weekday:N?.defaultRehearsalDay!=null?String(N.defaultRehearsalDay):b.weekday}))}const k=u.find(h=>h.id===p.venueId)?.name||"No venue";async function z(h){if(h.preventDefault(),!H||R)return;if(W&&!P){T({dates:sa(_,p.toDate,Number(p.weekday))}),y(new Set);return}const N=P?P.dates.filter(b=>!x.has(b)&&!L.has(b)):null;S(!0);try{await M({date:N?N[0]:_,performanceId:f?null:p.performanceId,ensembleId:f?p.ensembleId:null,title:f&&p.title.trim()||null,venueId:p.venueId,startTime:p.startTime,endTime:p.endTime,repeatUntil:W?p.toDate:null,dates:N})}finally{S(!1)}}if(P){const h=P.dates.map(b=>({iso:b,...na(b),conflict:L.has(b),removed:x.has(b)})),N=h.filter(b=>!b.conflict&&!b.removed).length;return e.jsxs("form",{onSubmit:z,className:"space-y-3",children:[e.jsxs("p",{className:"text-sm text-gray-700",children:[e.jsx("span",{className:"font-semibold",children:N})," rehearsal",N===1?"":"s"," will be created for ",e.jsx("span",{className:"font-semibold",children:D.find(b=>b.id===p.ensembleId)?.name}),p.title.trim()?e.jsxs(e.Fragment,{children:[" â â",p.title.trim(),"â"]}
1):null,". Remove any dates that don't work."]}),e.jsx("ul",{className:"divide-y divide-gray-100 border border-gray-200 rounded-lg max-h-72 overflow-y-auto",children:h.map(b=>e.jsxs("li",{className:`flex items-center gap-3 px-3 py-2 text-sm ${b.removed||b.conflict?"bg-gray-50":""}`,children:[e.jsx("span",{className:`w-10 shrink-0 font-medium ${b.removed||b.conflict?"text-gray-400 line-through":"text-gray-700"}`,children:b.day}),e.jsx("span",{className:`${b.removed||b.conflict?"text-gray-400 line-through":"text-gray-800"}`,children:b.date}),e.jsx("span",{className:`text-xs truncate ${b.removed||b.conflict?"text-gray-300":"text-gray-500"}`,children:k}),e.jsx("span",{className:"ml-auto shrink-0",children:b.conflict?e.jsx("span",{className:"text-xs text-amber-700 font-medium",children:"already scheduled â skipped"}):b.removed?e.jsx(J,{type:"button",variant:"ghost",size:"sm",className:"!text-xs !px-2 !py-0.5 text-brand-primary",onClick:()=>y(Q=>{const l=new Set(Q);return l.delete(b.iso),l}),children:"Undo"}):e.jsx(J,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove ${b.date}`,className:"!px-2 !py-0.5 text-gray-400 hover:text-red-600",onClick:()=>y(Q=>new Set(Q).add(b.iso)),children:"â"})})]},b.iso))}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(J,{type:"submit",size:"sm",disabled:N===0||R,isLoading:R,children:["Create ",N," Rehearsal",N===1?"":"s"]}),e.jsx(J,{type:"button",size:"sm",variant:"secondary",onClick:()=>T(null),children:"Back"}),e.jsx(J,{type:"button",size:"sm",variant:"ghost",onClick:C,children:"Cancel"})]})]})}return e.jsxs("form",{onSubmit:z,className:"space-y-2",children:[e.jsx(ke,{label:"Ensemble *",value:p.ensembleId,onChange:h=>U(h.target.value),options:[{value:"",label:"Select an ensembleâ¦"},...D.map(h=>({value:h.id,label:h.name}))]}),Y?null:e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ve,{label:"From date *",type:"date",value:p.fromDate,onChange:h=>$(N=>({...N,fromDate:h.target.value})),required:!0}),e.jsx(ve,{label:"To date (optional)",type:"date",value:p.toDate,onChange:h=>$(N=>({...N,toDate:h.target.value}))})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:`Leave "To date" empty for a single rehearsal. Set it to block out weekly rehearsals â you'll see the full list of dates to review before anything is created. When a performance is added later, the rehearsals before it are tied to it automatically.`})]}),Y&&e.jsxs("div",{children:[e.jsx(ve,{label:"Repeat weekly until (optional)",type:"date",value:p.toDate,onChange:h=>$(N=>({...N,toDate:h.target.value}))}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Blocks out weekly rehearsals through the end date â you'll review the list before anything is created."})]}),W&&e.jsx(ke,{label:"Repeats on",value:p.weekday,onChange:h=>$(N=>({...N,weekday:h.target.value})),options:[{value:"",label:"Select a dayâ¦"},...at.map((h,N)=>({value:String(N),label:`${h}s`}))]}),!W&&e.jsx(ke,{label:"Tied to a performance? (optional)",value:p.performanceId,onChange:h=>$(N=>({...N,performanceId:h.target.value})),options:[{value:Me,label:"No performance â standalone rehearsal"},...K.map(h=>({value:h.id,label:`${h.title} (${$e(h.performanceDate)})`}))]}),f&&e.jsx(ve,{label:"Label (optional)",placeholder:"e.g. Sectionals, Summer reading session",value:p.title,onChange:h=>$(N=>({...N,title:h.target.value}))}),e.jsx(ke,{label:"Rehearsal Location",value:p.venueId,onChange:h=>$(N=>({...N,venueId:h.target.value})),options:[{value:"",label:"No venue"},...u.map(h=>({value:h.id,label:h.name}))]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ve,{label:"Start Time",type:"time",value:p.startTime,onChange:h=>$(N=>({...N,startTime:h.target.value}))}),e.jsx(ve,{label:"End Time",type:"time",value:p.endTime,onChange:h=>$(N=>({...N,endTime:h.target.value}))})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(J,{type:"submit",size:"sm",disabled:!H||R,isLoading:R,children:W?"Review datesâ¦":"Create rehearsal"}),e.jsx(J,{type:"button",size:"sm",variant:"ghost",onClick:C,children:"Cancel"})]})]})}const ra=["January","February","March","April","May","June","July","August","September","October","November","December"],la=["Su","Mo","Tu","We","Th","Fr","Sa"],nt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Frid
1ay","Saturday"],oa=26,ia=8;function ca(s,c){const j=new Date(s,c,1).getDay(),D=new Date(s,c+1,0).getDate(),u=Array(j).fill(null);for(let M=1;M<=D;M++)u.push(M);return u}function da(s,c,j){const D=String(c+1).padStart(2,"0"),u=String(j).padStart(2,"0");return`${s}-${D}-${u}`}function ma({performances:s=[],rehearsals:c=[],orgEvents:j=[],blackoutDates:D=[],ensembles:u=[],onDayAction:M=null,venues:C=[],onCreatePerformance:p=null,onCreateEvent:$=null,onCreateRehearsal:P=null}){const T=new Date,x=Le(),[y,R]=v.useState(T.getFullYear()),[S,Y]=v.useState(null),[_,W]=v.useState(new Set),[f,K]=v.useState(new Set);function O(l){W(o=>{const I=new Set(o);return I.has(l)?I.delete(l):I.add(l),I})}function H(l){K(o=>{const I=new Set(o);return I.has(l)?I.delete(l):I.add(l),I})}const L=v.useMemo(()=>{const l=new Map;for(const o of s)o.ensembleName&&!l.has(o.ensembleName)&&l.set(o.ensembleName,o.ensembleColor||be(o.ensembleName));for(const o of c)o.ensembleName&&!l.has(o.ensembleName)&&l.set(o.ensembleName,o.ensembleColor||be(o.ensembleName));return[...l.entries()].map(([o,I])=>({name:o,color:I})).sort((o,I)=>o.name.localeCompare(I.name))},[s,c]),U=v.useMemo(()=>[{key:"performance",label:"Performances",color:"#2e6b8a",shape:"square",has:s.length>0},{key:"rehearsal",label:"Rehearsals",color:"#9ca3af",shape:"circle",has:c.length>0},{key:"event",label:"Events",color:"#7c3aed",shape:"diamond",has:j.length>0}].filter(l=>l.has),[s,c,j]),k=v.useMemo(()=>{const l={};if(f.has("performance"))return l;for(const o of s)!o.performanceDate||_.has(o.ensembleName)||(l[o.performanceDate]||(l[o.performanceDate]=[]),l[o.performanceDate].push(o));return l},[s,_,f]),z=v.useMemo(()=>{const l={};if(f.has("rehearsal"))return l;for(const o of c)!o.rehearsalDate||_.has(o.ensembleName)||(l[o.rehearsalDate]||(l[o.rehearsalDate]=[]),l[o.rehearsalDate].push(o));return l},[c,_,f]),h=v.useMemo(()=>{const l={};if(f.has("event"))return l;for(const o of j)o.eventDate&&(l[o.eventDate]||(l[o.eventDate]=[]),l[o.eventDate].push(o));return l},[j,f]),N=v.useMemo(()=>{const l={};for(const o of D)o.date&&(l[o.date]||(l[o.date]=[]),l[o.date].push(o));return l},[D]),b=y===T.getFullYear(),Q=v.useMemo(()=>{if(!S)return null;const l=new Date(S+"T12:00:00Z"),o={},I={};for(const E of s)o[E.id]=E.performanceDate,I[E.id]=E.title;const Z={};for(const E of c){if(!E.rehearsalDate||!E.ensembleId)continue;const ie=`${E.ensembleId}|${E.rehearsalDate}`;Z[ie]||(Z[ie]=[]),Z[ie].push(E)}const se=new Set;for(const E of s)E.performanceDate&&E.ensembleId&&se.add(`${E.ensembleId}|${E.performanceDate}`);const V=[];for(const E of u){if(E.defaultRehearsalDay==null)continue;const ie=E.defaultRehearsalDay,te=[],ne=s.filter(G=>G.ensembleId===E.id&&G.performanceDate&&G.performanceDate<S).reduce((G,t)=>t.performanceDate>G?t.performanceDate:G,""),d=new Date(l),A=(d.getUTCDay()-ie+7)%7||7;d.setUTCDate(d.getUTCDate()-A);const m=ne?oa:ia;for(let G=0;G<m;G++){const t=d.toISOString().slice(0,10);if(ne&&t<=ne)break;const i=et(t),a=N[t]||[],n=Z[`${E.id}|${t}`]||[],g=n.some(B=>!B.performanceId),w=n.find(B=>B.performanceId&&(o[B.performanceId]||"")>S),F=se.has(`${E.id}|${t}`)||n.some(B=>B.performanceId&&(o[B.performanceId]||"")<=S),q=!i&&a.length===0&&!F;te.unshift({date:t,holiday:i,blackoutCount:a.length,taken:F,adoptable:q&&(g||!!w),reassignFromTitle:w?I[w.performanceId]:null,usable:q}),d.setUTCDate(d.getUTCDate()-7)}V.push({ensembleId:E.id,ensembleName:E.name,ensembleColor:E.color||be(E.name),dayName:nt[ie],slots:te})}return V},[S,u,s,c,N]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>R(l=>l-1),className:"!p-1.5","aria-label":"Previous year",children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 19l-7-7 7-7"})})}),e.jsx("p",{className:"text-2xl font-bold text-gray-800 tabular-nums",children:y}),e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>R(l=>l+1),className:"!p-1.5","aria-label":"Next year",children:e.jsx("svg",{className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})}),!b&&e.jsx(J,{variant:"ghost",size:"sm",type:"button",onClick:()=>R(T.getFullYear()),className:"text-sm text-brand-primary",children:"This year"})]}),e.jsx("p",{className:"text-xs text-gray-500 max-w-md",children:"Click any future date to see what a concert there would look like â rehearsal lead-up, holiday conflicts, blackouts."})]}),U.length>1&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-3 pt-3 border-t border-gray-100",children:[e.jsx("span",{className:"text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Show"}
1),U.map(l=>{const o=f.has(l.key);return e.jsxs("button",{type:"button",onClick:()=>H(l.key),"aria-pressed":!o,className:`flex items-center gap-1.5 text-xs transition-colors ${o?"text-gray-300 line-through":"text-gray-600 hover:text-gray-800"}`,children:[e.jsx("span",{className:`inline-block shrink-0 transition-opacity ${l.shape==="circle"?"w-3 h-3 rounded-full":l.shape==="diamond"?"w-2.5 h-2.5 rotate-45":"w-3 h-3 rounded-sm"}`,style:{backgroundColor:l.color,opacity:o?.25:1}}),l.label]},l.key)})]}),L.length>1&&e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-3 pt-3 border-t border-gray-100",children:[e.jsx("span",{className:"text-xs font-medium text-gray-400 uppercase tracking-wide",children:"Ensembles"}),L.map(l=>{const o=_.has(l.name);return e.jsxs("button",{type:"button",onClick:()=>O(l.name),className:`flex items-center gap-1.5 text-xs transition-colors ${o?"text-gray-300 line-through":"text-gray-600 hover:text-gray-800"}`,children:[e.jsx("span",{className:"w-3.5 h-3.5 rounded-full inline-block shrink-0 transition-opacity",style:{backgroundColor:l.color,opacity:o?.25:1}}),l.name]},l.name)})]})]}),e.jsx("div",{className:"hidden md:grid grid-cols-4 gap-3",children:["winter","spring","summer","fall"].map(l=>{const o=tt[l];return e.jsx("div",{className:"rounded-md px-3 py-1.5 text-center text-xs font-semibold",style:{backgroundColor:o.bg,color:o.text},children:o.label},l)})}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-4",children:Array.from({length:12},(l,o)=>e.jsx(ha,{year:y,month:o,todayStr:x,perfMap:k,rehearsalMap:z,eventMap:h,blackoutMap:N,onWhatIf:I=>{const Z=k[I]||[],se=z[I]||[],V=h[I]||[];if((Z.length>0||se.length>0||V.length>0)&&M){M(I,{perfs:Z,rehearsals:se,events:V});return}Y(I)},whatIfDate:S},o))}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-3 flex flex-wrap gap-x-5 gap-y-1 text-xs",children:[e.jsx(we,{color:"#2e6b8a",shape:"square",label:"Performance"}),e.jsx(we,{color:"#9ca3af",shape:"circle",label:"Rehearsal"}),e.jsx(we,{color:"#7c3aed",shape:"diamond",label:"Event"}),e.jsx(we,{pattern:"blackout",label:"Blackout"}),e.jsx(we,{pattern:"holiday",label:"US Federal Holiday"})]}),S&&e.jsx(pa,{date:S,previews:Q,onClose:()=>Y(null),performances:s,rehearsals:c,ensembles:u,venues:C,onCreatePerformance:p,onCreateEvent:$,onCreateRehearsal:P})]})}function ha({year:s,month:c,todayStr:j,perfMap:D,rehearsalMap:u,eventMap:M,blackoutMap:C,onWhatIf:p,whatIfDate:$}){const P=ca(s,c),T=Gt(`${s}-${String(c+1).padStart(2,"0")}-15`),x=tt[T];return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-gray-100 flex items-baseline justify-between",style:{backgroundColor:x.bg+"40"},children:[e.jsx("h3",{className:"font-semibold text-sm",style:{color:x.text},children:ra[c]}),e.jsx("span",{className:"text-[10px] uppercase tracking-wider font-semibold",style:{color:x.text},children:x.label})]}),e.jsx("div",{className:"grid grid-cols-7 gap-px text-[10px] font-medium text-gray-400 px-2 pt-2",children:la.map(y=>e.jsx("div",{className:"text-center",children:y},y))}),e.jsx("div",{className:"grid grid-cols-7 gap-px p-2",children:P.map((y,R)=>{if(y===null)return e.jsx("div",{},`pad-${R}`);const S=da(s,c,y);return e.jsx(ua,{dateStr:S,day:y,isToday:S===j,isSelected:S===$,perfs:D[S],rehs:u[S],events:M[S],blackouts:C[S],onClick:()=>p(S)},S)})})]})}function ua({dateStr:s,day:c,isToday:j,isSelected:D,perfs:u,rehs:M,events:C,blackouts:p,onClick:$}){const P=et(s),T=u&&u.length>0,x=M&&M.length>0,y=C&&C.length>0,R=p&&p.length>0,S=new Date(s+"T12:00:00").getDay(),Y=S===0||S===6,_=T?u[0].ensembleColor||be(u[0].ensembleName):null,W=x?M[0].ensembleColor||be(M[0].ensembleName):null,f=_||W||(y?"#7c3aed":null),K=T?"rounded-sm":y?"rounded-md":"rounded-full",O=T&&!x&&u.every(k=>k.rosterMode==="selected");let H="";D?H="ring-2 ring-brand-primary ring-offset-1":j&&(H="ring-2 ring-brand-primary");const L=[];L.push(new Date(s+"T12:00:00").toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"})),P&&L.push(`Holiday: ${P}`),R&&L.push(`Blackout: ${p.map(k=>k.venueName||"Venue").join(", ")}`),T&&L.push(`${u.length} concert${u.length>
11?"s":""}: ${u.map(k=>(k.title||k.ensembleName)+(k.rosterMode==="selected"?" (part of the band)":"")).join(", ")}`),x&&L.push(`${M.length} rehearsal${M.length>1?"s":""}`),y&&L.push(`Event: ${C.map(k=>k.title).join(", ")}`);const U=L.join(` 2`);return e.jsxs("button",{type:"button",onClick:$,title:U,className:`relative flex items-center justify-center text-[11px] font-semibold transition-colors h-7 w-full overflow-hidden ${Y?"text-gray-700":"text-gray-500"} ${H} ${f&&!O?"text-white":R?"":"hover:bg-gray-50 rounded"}`,style:f?{...O?{backgroundColor:"#fff",color:f,boxShadow:`inset 0 0 0 2px ${f}`}:{backgroundColor:f},borderRadius:K==="rounded-sm"?2:K==="rounded-md"?4:999}:void 0,"aria-label":U,children:[R&&!f&&e.jsx("div",{className:"absolute inset-0 pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(45deg, rgba(239,68,68,0.15) 0, rgba(239,68,68,0.15) 2px, transparent 2px, transparent 6px)"}}),e.jsx("span",{className:`relative ${P&&!f?"pr-2":""}`,children:c}),P&&e.jsx("span",{className:`absolute top-0 right-0.5 text-[8px] font-bold leading-none ${f?"text-white/90":"text-amber-700"}`,"aria-hidden":"true",children:"H"})]})}function we({color:s,shape:c,pattern:j,label:D}){let u=null;return j==="blackout"?u=e.jsx("span",{className:"inline-block w-3.5 h-3.5 rounded-sm shrink-0",style:{backgroundImage:"repeating-linear-gradient(45deg, rgba(239,68,68,0.4) 0, rgba(239,68,68,0.4) 2px, transparent 2px, transparent 5px)"}}):j==="holiday"?u=e.jsx("span",{className:"inline-flex items-center justify-center w-3.5 h-3.5 rounded-sm shrink-0 bg-amber-50 border border-amber-300 text-[8px] font-bold text-amber-700",children:"H"}):c==="square"?u=e.jsx("span",{className:"inline-block w-3 h-3 rounded-sm shrink-0",style:{backgroundColor:s}}):c==="diamond"?u=e.jsx("span",{className:"inline-block w-3 h-3 rounded-sm shrink-0",style:{backgroundColor:s,transform:"rotate(45deg)"}}):u=e.jsx("span",{className:"inline-block w-3 h-3 rounded-full shrink-0",style:{backgroundColor:s}}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-gray-600",children:[u,D]})}function pa({date:s,previews:c,onClose:j,performances:D=[],rehearsals:u=[],ensembles:M=[],venues:C=[],onCreatePerformance:p,onCreateEvent:$,onCreateRehearsal:P}){const T=new Date(s+"T12:00:00"),x=nt[T.getDay()],y=T.toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric",year:"numeric"}),R=s<Le(),S=!R&&!!(p||P||$),[Y,_]=v.useState(!1);async function W(f){await P(f),_(!1)}return e.jsxs(Ge,{isOpen:!0,onClose:j,title:y,size:"lg",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-brand-primary -mt-1 mb-3",children:S?`Plan this ${x}`:`What-If â ${x}`}),S&&e.jsxs("div",{className:"mb-4 rounded-lg border border-brand-primary/20 bg-brand-primary/5 p-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-brand-primary mb-2",children:"Add to this date"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[p&&e.jsx(J,{size:"sm",type:"button",onClick:()=>p(s),children:"New performance"}),P&&e.jsx(J,{size:"sm",type:"button",variant:"secondary",onClick:()=>_(f=>!f),children:"New rehearsal"}),$&&e.jsx(J,{size:"sm",type:"button",variant:"secondary",onClick:()=>$(s),children:"New event"})]}),Y&&P&&e.jsx("div",{className:"mt-3 rounded-lg border border-gray-200 bg-white p-3",children:e.jsx(st,{date:s,performances:D,rehearsals:u,ensembles:M,venues:C,onCreate:W,onCancel:()=>_(!1)})})]}),R&&e.jsx("p",{className:"text-xs text-gray-500 mb-3 italic",children:"This date is in the past â the preview shows what the lead-up would have looked like."}),!c||c.length===0?e.jsx("p",{className:"text-sm text-gray-600",children:"No ensembles have a default rehearsal day configured. Set one on each ensemble's edit page to enable the rehearsal lead-up preview."}):e.jsx("div",{className:"space-y-4",children:c.map(f=>{const K=f.slots.filter(L=>L.usable).length,O=f.slots.filter(L=>L.adoptable).length,H=f.slots.length-K;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:f.ensembleColor}}),e.jsx("p",{className:"text-sm font-semibold text-gray-800",children:f.ensembleName}),e.jsxs("p",{className:"text-xs text-gray-500",children:[f.dayName," cadence"]})]}),e.jsxs("p",{className:"text-xs font-medium text-gray-600",children:[K," usable ",K===1?"rehearsal":"rehearsals",O>0&&e.jsxs("span",{className:"text-green-700",children:[" (",O," already scheduled)"]}),H>
20&&e.jsxs("span",{className:"text-amber-700",children:[" · ",H," ",H===1?"conflict":"conflicts"]})]})]}),e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-8 gap-1.5",children:f.slots.map(L=>e.jsx(xa,{slot:L},L.date))})]},f.ensembleId)})})]})}function xa({slot:s}){const c=new Date(s.date+"T12:00:00"),j=c.toLocaleDateString("en-US",{month:"short",day:"numeric"});let D="bg-gray-100 text-gray-700 border-gray-200",u=null;s.usable?s.adoptable?(D="bg-green-100 text-green-900 border-green-300 font-semibold",u="â"):(D="bg-green-50 text-green-800 border-green-200",u="â"):s.holiday?(D="bg-amber-50 text-amber-800 border-amber-200",u="â "):s.blackoutCount>0?(D="bg-red-50 text-red-700 border-red-200",u="â"):s.taken&&(D="bg-gray-100 text-gray-400 line-through border-gray-200",u=null);const M=[c.toLocaleDateString("en-US",{weekday:"long",month:"long",day:"numeric"}),s.holiday?`Holiday: ${s.holiday}`:null,s.blackoutCount>0?`${s.blackoutCount} blackout`:null,s.taken?"Already scheduled":null,s.adoptable?s.reassignFromTitle?`Rehearsal currently tied to "${s.reassignFromTitle}" â it will move to this performance`:"Standalone rehearsal already scheduled â it will be tied to this performance":s.usable?"Usable rehearsal":null].filter(Boolean).join(" · ");return e.jsx("div",{title:M,className:`px-1.5 py-1 rounded border text-[11px] text-center font-medium ${D}`,children:e.jsxs("div",{className:"flex items-center justify-center gap-0.5",children:[u&&e.jsx("span",{"aria-hidden":"true",children:u}),e.jsx("span",{children:j})]})})}const fa=[{key:"all",label:"All"},{key:"perf",label:"Performances"},{key:"rehearsal",label:"Rehearsals"},{key:"event",label:"Events"}];function ga(){return Ze()}function ba(s){const c=new Date(`${s}-01T00:00:00`);return Number.isNaN(c.getTime())?s:c.toLocaleDateString(void 0,{month:"long",year:"numeric"})}function ya({perfs:s,rehearsals:c,orgEvents:j,ensembles:D=[],onSelectDay:u,selectedDate:M=null,dayPanel:C=null,onOpenHelp:p=null}){const[$,P]=v.useState("all"),[T,x]=v.useState(""),{myPlans:y,updatePlan:R}=St(),{canFully:S}=Qe(),Y=S("attendance:take"),_=ht(d=>!!d.user?.sectionId),W=Y?"manager":"section",[f,K]=v.useState(null),[O,H]=v.useState(null),[L,U]=v.useState(0),k=Tt(Y?"org":_?"section":null,L),[z,h]=v.useState(null),{myPlans:N,updatePlan:b}=Mt(),Q=$t({enabled:!S("performance:update")}),l=Bt({updateRehearsalPlan:R,updatePerformancePlan:b}),[o,I]=v.useState(null),Z=ga(),V=v.useMemo(()=>_t({perfs:s,rehearsals:c,orgEvents:j}).filter(d=>d.date>=Z),[s,c,j,Z]).filter(d=>!($!=="all"&&d.kind!==$||T&&d.kind!=="event"&&d.raw?.ensembleId!==T)),E=v.useMemo(()=>{const d=new Map;for(const A of V){const m=A.date.slice(0,7);d.has(m)||d.set(m,[]),d.get(m).push(A)}return[...d.entries()]},[V]),ie=d=>u?()=>u(d.date,{perfs:(s||[]).filter(A=>A.performanceDate===d.date),rehearsals:(c||[]).filter(A=>A.rehearsalDate===d.date),events:(j||[]).filter(A=>A.eventDate===d.date)}):null,te=!!C&&!!M&&V.some(d=>d.date===M),ne=(d,A)=>d[A+1]?.date!==d[A].date;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-1",role:"group","aria-label":"Filter by type",children:fa.map(d=>e.jsx("button",{type:"button",onClick:()=>P(d.key),"aria-pressed":$===d.key,className:`px-3 py-1.5 rounded-full text-sm font-medium border transition-colors ${$===d.key?"bg-band-600 border-band-600 text-white":"bg-white border-gray-200 text-gray-600 hover:border-band-400 hover:text-band-700"}`,children:d.label},d.key))}),D.length>1&&e.jsx("div",{className:"ml-auto w-full sm:w-56",children:e.jsx(ke,{value:T,onChange:d=>x(d.target.value),"aria-label":"Filter by ensemble",placeholder:"All ensembles",options:D.map(d=>({value:d.id,label:d.name}))})})]}),E.length===0?e.jsx(Vt,{title:"Nothing scheduled",description:"No upcoming items match this filter."}):E.map(([d,A])=>e.jsx("section",{children:e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2.5 bg-gray-50 border-b border-gray-200",children:[e.jsx("span",{className:"w-1 h-4 rounded-full bg-brand-primary shrink-0","aria-hidden":"true"}),e.jsx("h3",{className:"text-sm font-bold text-gray-900 uppercase tracking-wide",children:ba(d)}),e.jsx("span",{className:"text-xs font-semibold text-gray-400",children:A.length})]}),e.jsx("div",{className:"divide-y divide-gray-100",children:A.map((m,G)=>
2{const t=m.kind==="rehearsal"&&!m.cancelled?y?.[m.raw?.id]:null,i=m.kind==="perf"&&!m.cancelled?N?.[m.raw?.id]:null,a=te&&m.date===M&&ne(A,G);return e.jsxs("div",{children:[e.jsx(Ht,{row:m,onTap:ie(m),selected:!!M&&m.date===M,trailing:(()=>{const n=m.raw?.id,g=m.cancelled?null:m.kind==="perf"?k?.performances?.[n]:m.kind==="rehearsal"?k?.rehearsals?.[n]:null,w=t?e.jsx(Ot,{state:t,onOpen:()=>h(t.row)}):i?e.jsx(Ft,{state:i,onOpen:()=>I(i.row)}):null,F=m.kind==="perf"&&!m.cancelled&&Q[n]&&p?e.jsx(Lt,{state:Q[n],onOpen:()=>p(n)}):null;if(!g&&!w&&!F)return null;const q=g?m.kind==="perf"?`/performances?highlight=${n}`:m.raw?.performanceId?`/performances?highlight=${m.raw.performanceId}&openRehearsalId=${n}`:null:null;return e.jsxs("span",{className:"flex items-center gap-1.5",children:[w,F,g?e.jsx(At,{count:g,to:q}):null]})})()}),a&&e.jsx("div",{className:"p-3 bg-band-50/40","data-testid":"day-panel-inline",children:C})]},m.key)})})]})},d)),C&&!te&&C,e.jsx(Rt,{rehearsal:z,current:z?y?.[z.id]:null,isOpen:!!z,onClose:()=>h(null),onSaved:d=>{R(z.id,d),U(A=>A+1)},onBulkSaved:d=>{l(d),U(A=>A+1)},onRecordOther:(Y||_)&&z?()=>{const d=z;h(null),K(d)}:null}),e.jsx(Et,{variant:W,rehearsalId:f?.id||null,isOpen:!!f,onClose:()=>{K(null),U(d=>d+1)}}),e.jsx(It,{performance:o,current:o?N?.[o.id]:null,isOpen:!!o,onClose:()=>I(null),onSaved:d=>{b(o.id,d),U(A=>A+1)},onBulkSaved:d=>{l(d),U(A=>A+1)},onRecordOther:(Y||_)&&o?()=>{const d=o;I(null),H(d)}:null}),e.jsx(Pt,{variant:W,performanceId:O?.id||null,isOpen:!!O,onClose:()=>{H(null),U(d=>d+1)}})]})}const Xe=[{key:"list",label:"List"},{key:"timeline",label:"Timeline"},{key:"year",label:"Year"}];function Ha(){Dt();const{currentOrg:s}=ut(),{showError:c,showSuccess:j}=pt(),{canFully:D,role:u,authority:M}=Qe(),C=D("performance:update"),p=D("attendance:take"),$=C||p,P=u===Ue.PRESIDENT||u===Ue.SUPERADMIN||M==="owner"||M==="admin",[T,x]=xt(),y=ft();function R(n){y(`/performances?new=true&date=${n}`)}function S(n){y(`/events?new=true&date=${n}`)}async function Y({date:n,performanceId:g,ensembleId:w,title:F,venueId:q,startTime:B,endTime:ee,repeatUntil:ae,dates:X}){try{if((ae||X?.length)&&w){const oe=await Ke.createSeries({orgId:s.id,ensembleId:w,...X?.length?{dates:X}:{startDate:n,endDate:ae},title:F||null,venueId:q||null,startTime:B||null,endTime:ee||null}),xe=[`${oe.created} rehearsal${oe.created===1?"":"s"} created`];oe.skipped?.length&&xe.push(`${oe.skipped.length} date${oe.skipped.length===1?"":"s"} skipped (already scheduled)`),oe.adopted&&xe.push(`${oe.adopted} tied to an upcoming performance`),j(xe.join(" · "))}else await Ke.create({orgId:s.id,...g?{performanceId:g}:{ensembleId:w},...F?{title:F}:{},rehearsalDate:n,venueId:q||null,startTime:B||null,endTime:ee||null}),j("Rehearsal added");A()}catch(oe){c(oe.message||"Failed to add rehearsal")}}const W=(T.get("view")==="agenda"?"list":T.get("view"))||"list",[f,K]=v.useState(Xe.find(n=>n.key===W)?W:"list"),[O,H]=v.useState(null),[L,U]=v.useState([]),[k,z]=v.useState([]),[h,N]=v.useState([]),[b,Q]=v.useState([]),[l,o]=v.useState([]),[I,Z]=v.useState(null),[se,V]=v.useState(null),[E,ie]=v.useState(null),te=gt(),[ne,d]=v.useState(!1);v.useEffect(()=>{bt.get("/members/me/calendar-feed").then(n=>ie(n?.printUrl||null)).catch(yt("printable schedule link is an enhancement"))},[]);async function A(){if(s)try{const[n,g,w,F,q,B]=await Promise.all([Ve.list(s.id,{}),Ve.rehearsals(s.id),Yt.list({filter:"upcoming",includeCancelled:!0}).catch(()=>[]),Je.listAllBlackoutDates().catch(()=>[]),Wt.list(s.id).catch(()=>[]),Je.list(s.id).catch(()=>[])]);H(Array.isArray(n)?n:[]),U(Array.isArray(g)?g:[]),z(Array.isArray(w)?w:[]),N(Array.isArray(F)?F:[]),Q(Array.isArray(q)?q:[]),o(Array.isArray(B)?B:[])}catch{c(wt("schedule"))}}v.useEffect(()=>{A()},[s?.id]);const m=zt({perfs:O,setPerfs:H,rehearsalList:L,setRehearsalList:U,orgEventsList:k,expandedPerfId:I,setExpandedPerfId:Z,venuesList:l,isAdmin:P,showSuccess:j,showError:c,onRefresh:A,blackoutDates:h}),G=v.useRef(null);v.useEffect(()=>{if(!m.actionDayStr)return;const n=f==="list"?"nearest":"center",g=setTimeout(()=>G.current?.scrollIntoView({behavior:"smooth",block:n}),60);return()=>clearTimeout(g)},[m.actionDayStr,f]);async function t(n,g){try{const w=g==="perf"?"performance":"rehearsal",F=await kt.generateToken({eventId:n.id,eventType:w});V({token:F.token,title:w==="performance"?n.title:n.performanceTitle||n.title||"Rehearsal",date:w==="performance"?n.performanceDate:n.rehearsalDate,eventType:w})}catch(w){c(w.message||"Failed to generate attendance link")}}function i(n){K(n);const g=new URLSearchParams(T);g.set("view",n),x(g,{replace:!0})}const a=m.actionDayStr&&$&&(m.actionPerfs.length>0||m.actionRehearsals.length>0||m.actionEvents.length>0)?e.jsx("div",{className:f==="list"?"":"mt-4",ref:G,children:e.jsx(Ut,{dayStr:m.actionDayStr,performances:m.actionPerfs,rehearsals:m.actionRehearsals,events:m.actionEvents,openAction:m.openAction,formData:m.actionFormData,setFormData:m.setActionFormData,venues:l,isAdmin:P,isDrafting:m.isDrafting,isSaving:m.isSavingAction,copied:m.copied,draftHint:m.draftHint,onOpenAction:m.handleOpenAction,onSaveDate:m.saveDateChange,onSaveLocation:m.saveLocationChange,onSaveTime:m.saveTimeChange,onCancelEvent:m.cancelEvent,onUncancelEvent:m.uncancelEvent,onCopyMessage:m.copyMessage,onSendMessage:m.sendMessage,onClose:m.closeActionPanel,onCloseAction:m.closeAction,onDraftNotification:m.handleDraftNotification,onDraftMessage:m.handleDraftMessage,onTakeAttendance:p?t:void 0,attendanceOnly:!C,blackoutSiblings:m.blackoutSiblings,ensembles:b,onAddRehearsal:C?Y:void 0,onRehearsalChanged:A})}):null;return e.jsxs("div",{className:"px-4 md:px-0",children:[e.jsx(Ct,{title:"Schedule",subt
2itle:"Your performances, rehearsals, and events.",breadcrumbs:[{label:"Home",to:"/"},{label:"Schedule"}],actions:C||E?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(vt,{to:"/help/rehearsal-management",className:"text-xs text-brand-primary hover:underline flex items-center gap-1",children:[e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Help"]}),E&&e.jsxs(J,{variant:C?"secondary":"primary",size:"md",onClick:()=>jt(E,{isMobile:te}),children:[e.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a2 2 0 002-2v-4a2 2 0 00-2-2H9a2 2 0 00-2 2v4a2 2 0 002 2zm8-12V5a2 2 0 00-2-2H9a2 2 0 00-2 2v4h10z"})}),"Open printable schedule"]}),C&&e.jsxs(Ce,{align:"right",menuId:"schedule-new-menu",trigger:e.jsxs(J,{variant:"primary",size:"md","aria-label":"Create new schedule item",children:["New",e.jsx("svg",{className:"h-4 w-4 ml-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),children:[e.jsx(Ce.Item,{onClick:()=>y("/performances?new=true"),children:"New performance"}),e.jsx(Ce.Item,{onClick:()=>d(!0),children:"New rehearsal"}),e.jsx(Ce.Item,{onClick:()=>y("/events?new=true"),children:"New event"})]})]}):void 0}),e.jsx(Ge,{isOpen:ne,onClose:()=>d(!1),title:"New rehearsal",children:e.jsx(st,{performances:(O||[]).filter(n=>n.performanceDate>=Ze()),rehearsals:L,ensembles:b,venues:l,onCreate:async n=>{await Y(n),d(!1)},onCancel:()=>d(!1)})}),e.jsx(Kt,{className:"mb-4",ariaLabel:"Schedule views",tabs:Xe,value:f,onChange:i}),f==="list"&&(O==null?e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-8 text-center",children:e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"})}):e.jsx(ya,{onOpenHelp:n=>y(Jt(n)),perfs:O,rehearsals:L,orgEvents:k,ensembles:b,onSelectDay:$?m.handleDayAction:void 0,selectedDate:m.actionDayStr,dayPanel:a})),f==="timeline"&&(O==null?e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-8 text-center",children:e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"})}):e.jsx(Zt,{performances:O,rehearsals:L,orgEvents:k,blackoutDates:h,forceViewMode:"timeline",canAction:C,onDayAction:$?m.handleDayAction:void 0})),f!=="list"&&a,f==="year"&&(O==null?e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-8 text-center",children:e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"})}):e.jsx(ma,{performances:O,rehearsals:L,orgEvents:k,blackoutDates:h,ensembles:b,venues:l,onDayAction:$?m.handleDayAction:void 0,onCreatePerformance:C?R:void 0,onCreateEvent:C?S:void 0,onCreateRehearsal:C?Y:void 0})),e.jsx(Nt,{isOpen:!!se,onClose:()=>V(null),token:se?.token,eventTitle:se?.title,eventDate:se?.date,eventType:se?.eventType})]})}export{Ha as SchedulePage};
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.