PageSourceSearch

https://app.backstagebaton.com/app/assets/SectionLeaderView-BnljavDA.js

js backstagebaton.com collected 2026-10-07 08:50:33 UTC 100,809 bytes, 1 lines download raw bytes

1import{c as je,r as i,t as me,j as e,B as $e,S as gt,d as we,M as nt,E as Ne,h as oe,e as _e,a as st,a6 as it,l as Ue,C as He,o as ot,g as xt}from"./index-_aijvlUq.js";import{u as yt}from"./useResumeRefetch-Dmzejf9t.js";import{s as C}from"./sectionLeader-CxeZyjmi.js";import{p as Ce}from"./performances-duTJPchz.js";import{I as Ke}from"./Input-ysTyZFq5.js";import{A as De}from"./Avatar-BMcjKrGk.js";import{u as vt}from"./useTouchDrag-11RbnYfb.js";import{a as jt,b as Be,s as Ie}from"./attendanceOrder-CJNalFBQ.js";import{p as lt}from"./paletteHash-DBBw93pZ.js";import{M as St}from"./MobileListSkeleton-BxuyWDCs.js";import{B as qe}from"./BottomSheet-BiQNSujt.js";import{T as Qe}from"./Tabs-CGDUdv1I.js";import{E as Me}from"./EmptyState-CPGKooqj.js";import{g as Nt,m as kt,f as wt,e as Xe,n as Ge,r as Ye,k as It,a as Je,b as et,c as tt,d as $t,j as Ct,i as Rt}from"./folderCustody-0jTNtNbN.js";import{F as rt,a as Tt}from"./FolderHolder-a1wRvI5n.js";import{C as ct,F as ze,P as dt,u as ut}from"./useConcertRehearsalsQuestion-CvhgYAiE.js";import{C as Dt}from"./ConfirmDialog-CODvETNM.js";import"./Badge-DJIi163x.js";import"./members-I3UAoZ9P.js";import"./downscaleImage-qyGK-a3D.js";import"./instruments-CRxWHJ-h.js";import"./Menu-CATQC14B.js";const Ve=d=>d.alias||d.label,Pt=d=>d.shared===!1?" (not ready yet)":d.shared==null&&!d.hasFolders?" (no folders yet)":"";function mt({sectionId:d,isMobile:p=!1}){const{showError:$}=je(),[w,N]=i.useState(void 0),[E,k]=i.useState({sectionId:null,perfId:""}),T=E.sectionId===d?E.perfId:"",[u,G]=i.useState(null),[S,V]=i.useState(null),[W,B]=i.useState(null),Z=i.useRef(null);i.useEffect(()=>{if(!d)return;let s=!1;return Z.current!==d&&(Z.current=d,N(void 0)),B(null),C.getFolders({sectionId:d,...T?{performanceId:T}:{}}).then(a=>{s||N(a||null)}).catch(()=>{s||(N(null),$(me("your section’s folders")))}),()=>{s=!0}},[d,T]);const g=i.useMemo(()=>w?.folders||[],[w]),h=i.useMemo(()=>Nt(g,s=>s.instrumentName),[g]),_=w?.performances||[],X=g.filter(s=>s.status==="out").length,v=g.filter(s=>s.status==="missing").length,re=(s,a)=>N(c=>c&&{...c,folders:c.folders.map(t=>t.id===s?a(t):t)});async function Y(s,a,c){const t=w;c&&re(s.id,c),G(s.id);try{const o=await C.setFolderCustody({performanceId:w?.performance?.id,folderId:s.id,...a});return o?.folder&&re(s.id,()=>o.folder),o}catch(o){return N(t),$(o?.message||Ne),null}finally{G(null)}}const U=()=>new Date().toISOString(),K=s=>{const a=Ye(s);return Y(s,{action:"check_out",memberId:a.memberId},c=>({...c,status:"out",heldByMemberId:a.memberId,heldByName:a.name,custodyAt:U(),lastEvent:{event:"check_out",createdAt:U()}}))},I=s=>Y(s,{action:"check_in"},a=>({...a,status:"returned",heldByMemberId:null,heldByName:null,custodyAt:U(),lastEvent:{event:"check_in",createdAt:U()}})),P=async(s,a)=>{V(a.memberId);const c=await Y(s,{action:"check_out",memberId:a.memberId},t=>({...t,status:"out",memberId:a.memberId,memberName:a.name,responsible:{kind:"player",memberId:a.memberId,name:a.name,source:"holder"},heldByMemberId:a.memberId,heldByName:a.name,custodyAt:U(),lastEvent:{event:"check_out",createdAt:U()}}));V(null),c&&B(null)},f=async s=>{V("clear");const a=await Y(s,{action:"unassign"},null);V(null),a&&B(null)},L=s=>Rt(s)?{label:"Check in",onClick:()=>I(s)}:Ye(s).kind==="player"?{label:"Check out",onClick:()=>K(s)}:{label:"Check out…",onClick:()=>B(s)},O=w?.holderDefault||kt({musicGoesHome:w?.musicGoesHome??null}),R=W?g.find(s=>s.id===W.id)||W:null,ne=wt(g),ee=R?Xe(w?.candidates?.[`${R.instrumentId}|${R.partNumber}`]||w?.candidates?.[`${R.instrumentId}|null`]||[],ne):[],le=new Set(ee.map(s=>s.memberId)),ce=R?Xe((w?.sectionMembers||[]).filter(s=>!le.has(s.memberId)),ne):[];if(w===void 0)return e.jsx("p",{className:"text-sm text-gray-400 py-4","data-testid":"section-folders-loading",children:"Loading…"});if(w===null)return e.jsx(Me,{size:"compact",title:"Couldn’t load your section’s folders.",description:"Refresh to try again."});const fe=R?`Folder ${Ge(R)} · ${Ve(R)}`:"",q=!!R&&u===R.id,Q=R?Ye(R):null,l=s=>e.jsx($e,{variant:s.memberId===Q.memberId?"secondary":"ghost",size:"md",className:"w-full justify-start min-h-[44px] py-2",isLoading:q&&S===s.memberId,disabled:q&&S!==s.memberId,"aria-pressed":s.memberId===Q.memberId,onClick:()=>
1P(R,s),...Ct({name:s.name,memberId:s.memberId,holdings:ne,folderId:R.id,responsibleNow:s.memberId===Q.memberId}),children:e.jsx(Tt,{name:s.name,memberId:s.memberId,holdings:ne,folderId:R.id,responsibleNow:s.memberId===Q.memberId,testId:`sf-candidate-${s.memberId}`})},s.memberId),n=R&&e.jsxs("div",{className:"space-y-3","data-testid":"section-folder-picker",children:[e.jsxs("p",{className:"text-sm text-gray-700","data-testid":"section-folder-picker-responsible",children:["Responsible now: ",e.jsx(rt,{folder:R})]}),e.jsx("p",{className:"text-sm text-gray-600",children:"Tap a name to hand this folder to them. They hold it for the season, and their name shows here and on the librarian's build sheet."}),ee.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-gray-500 mb-1",children:R.partNumber==null?"Playing this concert":"Seated on this chair"}),e.jsx("div",{className:"space-y-1",children:ee.map(l)})]}),ce.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-gray-500 mb-1",children:"Anyone else in the section"}),e.jsx("div",{className:"space-y-1",children:ce.map(l)})]}),ee.length===0&&ce.length===0&&e.jsx(Me,{size:"compact",title:"Nobody in the section yet."})]}),y=R?.memberId?e.jsxs("div",{className:"space-y-2","data-testid":"section-folder-picker-actions",children:[e.jsx("p",{className:"text-sm text-gray-600",children:It(O)}),e.jsx($e,{variant:"ghost",size:"md",className:"min-h-[44px]",isLoading:q&&S==="clear",disabled:q&&S!=="clear",onClick:()=>f(R),children:"Clear holder"})]}):null;return e.jsxs("div",{className:"space-y-3","data-testid":"section-folders","aria-busy":w===void 0||void 0,children:[_.length>1&&e.jsx(gt,{"aria-label":"Concert",value:T||w.performance?.id||"",onChange:s=>k({sectionId:d,perfId:s.target.value}),className:"!text-base md:max-w-md",options:_.map(s=>({value:s.id,label:`${we(s.performanceDate)} — ${s.title}${Pt(s)}`}))}),!w.performance&&e.jsx(Me,{size:"compact",title:"No upcoming concert.",description:"Folders are built for a concert; there is nothing scheduled yet."}),w.performance&&w.shared===!1&&e.jsx(Me,{size:"compact",title:`The librarian is still preparing the folders for ${w.performance.title}.`,description:"They’ll appear here when they’re ready."}),w.performance&&w.shared!==!1&&g.length===0&&e.jsx(Me,{size:"compact",title:"No folders for this concert yet.",description:"The librarian builds them under Music Folders."}),g.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-gray-600","data-testid":"section-folders-status",children:`${g.length} ${g.length===1?"folder":"folders"} · ${X} out${v?` · ${v} missing`:""}`}),e.jsxs("div",{className:"hidden md:grid md:grid-cols-[4rem_minmax(0,1fr)_minmax(0,1.3fr)_9rem_8rem] md:gap-3 px-3 pb-1 text-xs font-semibold uppercase tracking-wide text-gray-500 border-b border-gray-200","aria-hidden":"true",children:[e.jsx("span",{children:"#"}),e.jsx("span",{children:"Part"}),e.jsx("span",{children:"Holder"}),e.jsx("span",{children:"State"}),e.jsx("span",{className:"pl-3",children:"Action"})]}),h.map(([s,a])=>e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white",children:[e.jsxs("p",{className:"rounded-t-xl bg-gray-50 border-b border-gray-200 px-3 py-2 flex items-center gap-2 text-base font-semibold text-gray-900","data-testid":"section-folder-group",children:[e.jsx("span",{children:s}),e.jsxs("span",{className:"text-sm font-normal text-gray-500",children:[a.length," ",a.length===1?"folder":"folders"]})]}),a.map(c=>{const t=L(c);return e.jsxs("div",{className:"border-b border-gray-100 last:border-0 px-3 flex flex-col gap-1 md:grid md:grid-cols-[4rem_minmax(0,1fr)_minmax(0,1.3fr)_9rem_8rem] md:gap-3 md:items-center","data-testid":`sf-${c.id}`,"data-status":c.status||"built",children:[e.jsxs("button",{type:"button",onClick:()=>B(c),"aria-label":`Folder ${Ge(c)} ${Ve(c)}: choose who has it`,className:"flex-1 min-w-0 min-h-[44px] py-1.5 text-left rounded-lg md:hover:bg-gray-50 md:col-span-4 md:grid md:grid-cols-subgrid md:gap-3 md:items-center","data-testid":`sf-row-${c.id}`,children:[e.jsxs("span",{className:"flex items-center gap-2 md:contents",children:[e.jsx("span",{className:`text-base font-semibold tabular-nums shrink-0 ${c.folderNumber?"text-gray-900":"text-amber-800"}`,children:Ge(c)}),e.jsx("span",{className:"text-base text-gray-900 truncate min-w-0 flex-1",children:Ve(c)})]}),e.jsxs("span",{className:"block truncate text-sm text-gray-600 mt-0.5 md:contents md:mt-0",children:[e.jsx(rt,{folder:c,testId:`sf-holder-${c.id}`,className:"md:text-base md:text-gray-900"}),e.jsx("span",{className:`hidden md:inline-flex ${Je} ${tt(c)}`,"data-testid":`sf-state-${c.id}`,children:et(c)})]})]}),e.jsxs("span",{className:"flex items-center justify-between gap-2 pb-1 md:pb-0 md:py-1 md:justify-self-stretch","data-testid":`sf-actions-${c.id}`,children:[e.jsx("span",{className:`md:hidden ${Je} ${tt(c)}`,"aria-hidden":"true","data-testid":`sf-state-${c.id}-phone`,children:et(c)}),e.jsx($e,{variant:$t(c),size:"sm",className:"min-h-[44px] shrink-0 md:w-full md:justify-start",isLoading:u===c.id,onClick:t.onClick,children:t.label})]})]},c.id)})]},s)),e.jsx("p",{className:"text-sm text-gray-500",children:"Tap a folder to hand it to someone. Missing pieces and the roll call are the librarian’s, under Music Folders."})]}),p?e.jsx(qe,{isOpen:!!R,onClose:()=>B(null),title:fe,children:e.jsxs("div",{className:"px-4 pt-3 space-y-3",children:[n,y&&e.jsx("div",{className:"pt-2 border-t border-gray-100",children:y})]})}):e.jsx(nt,{isOpen:!!R,onClose:()=>B(null),title:fe,size:"sm",footer:y,children:n})]})}const At=[{value:"present",label:"Present",lit:"bg-green-500 text-white"},{value:"absent",label:"Absent",lit:"bg-red-500 text-white"}
1,{value:"excused",label:"Excused",lit:"bg-amber-500 text-white"}];function bt({value:d,onChange:p,size:$="sm",name:w,className:N=""}){const E=d||"unmarked",k=$==="lg"?"min-h-[44px] flex-1 px-3 text-sm":"px-3 py-1.5 text-xs";return e.jsx("div",{className:`flex gap-1 shrink-0 ${N}`,role:"group","aria-label":w?`${w} attendance`:"Attendance",children:At.map(T=>{const u=E===T.value;return e.jsx("button",{type:"button","aria-pressed":u,onClick:()=>p(jt(E,T.value)),className:`${k} rounded-full font-medium transition-all ${u?T.lit:"bg-gray-100 text-gray-500 hover:bg-gray-200"}`,children:T.label},T.value)})})}const Mt=[{key:"roster",label:"Roster"},{key:"folders",label:"Folders"},{key:"attendance",label:"Attendance"}];function zt(d){const p=["th","st","nd","rd"],$=d%100;return d+(p[($-20)%10]||p[$]||p[0])}function Ft(){const{showError:d}=je(),p=oe(f=>f.currentOrg?.id),[$,w]=i.useState([]),[N,E]=i.useState(null),[k,T]=i.useState(null),[u,G]=i.useState(null),[S,V]=i.useState([]),[W,B]=i.useState(!0),[Z]=_e(),[g,h]=i.useState(()=>Z.get("tab")==="attendance"?"attendance":"roster"),[_,X]=i.useState(!1),v=oe(f=>f.currentOrg?.trackPerformanceAttendance!==!1||f.currentOrg?.trackRehearsalAttendance!==!1),re=oe(f=>f.currentOrg?.trackRehearsalRsvps!==!1),Y=v||re,{can:U}=st(),K=!!U("folders:custody"),I=Mt.filter(f=>(f.key!=="attendance"||Y)&&(f.key!=="folders"||K)).map(f=>f.key==="attendance"&&!v?{...f,label:"Availability"}:f);i.useEffect(()=>{C.listSections().then(f=>{const L=Array.isArray(f)?f:[];w(L),L.length>0?E(O=>O||L[0].id):B(!1)}).catch(()=>{B(!1),d(me("your sections"))})},[]);function P(){N&&(B(!0),C.getRoster(null,N).then(f=>{T(f.section),G(f.members||[]),V(f.instrumentGroups||[])}).catch(()=>d(me("section roster"))).finally(()=>B(!1)))}return i.useEffect(()=>{P()},[N]),e.jsxs("div",{style:{paddingBottom:24},children:[e.jsxs("div",{"data-testid":"mobile-section-header",style:{display:"flex",alignItems:"center",gap:"var(--bb-space-3)",padding:"var(--bb-space-4)",background:"var(--bb-surface)",borderBottom:"1px solid var(--bb-border-soft)"},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)"},children:"My Section"}),e.jsx("div",{style:{fontSize:22,fontWeight:700,color:"var(--bb-fg)",marginTop:2},children:k?.name||"Section"}),e.jsxs("div",{style:{fontSize:13,color:"var(--bb-fg-muted)",marginTop:2},children:[u?.length||0," members",k?.ensembleName?` · ${k.ensembleName}`:""]}),e.jsxs("a",{...it("/app/guides/section-leader-guide.pdf","Section leader guide"),style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:11,color:"var(--bb-primary)",textDecoration:"none",marginTop:6},children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),"Quick guide (PDF)"]})]}),k&&u&&u.length>0&&e.jsxs("button",{type:"button","data-testid":"mobile-section-message","aria-label":`Send message to ${k?.name||"section"}`,onClick:()=>X(!0),style:{flexShrink:0,minHeight:44,minWidth:44,padding:"0 14px",display:"inline-flex",alignItems:"center",gap:6,border:"1px solid var(--bb-primary)",borderRadius:"var(--bb-radius-pill)",background:"var(--bb-primary-soft)",color:"var(--bb-primary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:[e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.75,"aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3 20l18-8L3 4v7l13 1-13 1v7z"})}),"Message"]})]}),e.jsx(Wt,{isOpen:_,onClose:()=>X(!1),sectionName:k?.name,instrumentGroups:S,ensembleId:k?.ensembleId,orgId:p}),$.length>1&&e.jsx("div",{"data-testid":"mobile-section-switcher",style:{display:"flex",gap:6,padding:"var(--bb-space-3) var(--bb-space-4)",overflowX:"auto",background:"var(--bb-bg)"},children:$.map(f=>{const L=N===f.id;return e.jsxs("button",{type:"button",onClick:()=>E(f.id),style:{flex:"0 0 auto",minHeight:44,padding:"0 16px",fontSize:13,fontWeight:600,borderRadius:"var(--bb-radius-pill)",border:"1px solid",borderColor:L?"var(--bb-primary)":"var(--bb-border-soft)",background:L?"var(--bb-primary)":"var(--bb-surface)",color:L?"#fff":"var(--bb-fg-muted)",cursor:"pointer",display:"inline-flex",alignItems:"center"},children:[f.name,e.jsxs("span",{style:{marginLeft:6,opacity:.7},children:["(",f.memberCount,")"]})]},f.id)})}),e.jsx("div",{style:{padding:"0 var(--bb-space-4)",background:"var(--bb-bg)"},children:e.jsx(Qe,{ariaLabel:"Section tabs",tabs:I,value:g,onChange:h})}),W?e.jsx(St,{variant:"member",count:4}):$.length===0&&!k?e.jsx("div",{style:{padding:"var(--bb-space-4)",color:"var(--bb-fg-muted)",fontSize:14},children:"You don't lead a section yet."}):g==="attendance"&&Y?e.jsx(Bt,{roster:u,ensembleId:k?.ensembleId}):g==="folders"&&K?e.jsx("div",{style:{padding:"var(--bb-space-3) var(--bb-space-4) 0"},children:e.jsx(mt,{sectionId:N,isMobile:!0})}):e.jsx(Et,{section:k,initialGroups:S,onReload:P})]})}function Et({section:d,initialGroups:p,onReload:$}){const{showSuccess:w,showError:N}=je(),E=oe(n=>n.currentOrg?.id),[k,T]=i.useState([]),[u,G]=i.useState(""),[S,V]=i.useState(null),[W,B]=i.useState(p||[]),[Z,g]=i.useState(null),[h,_]=i.useState(null),[X,v]=i.useState(!1),[re,Y]=i.useState(!1),[U,K]=i.useState(null),[I,P]=i.useState(null);i.useEffect(()=>{B(p||[])},[p]);async function f(){if(u)try{const[n,y]=await Promise.all([C.getRoster(u),C.getPerformanceRoster(u)]);B(n.instrumentGroups||[]),K(n.carryForwardFrom||null),V(y.performers||[])}catch{N(me("section seating"))}}const L=n=>u&&O&&!h?()=>P({...n,instrumentId:O.instrumentId,instrumentName:O.instrumentName}):void 0;i.useEffect(()=>{W.length>0&&(!Z||!W.find(n=>n.instrumentId===Z))&&g(W[0].instrumentId)},[W]),i.useEffect(()=>{!E||!d?.ensembleId||Ce.list(E,{ensembleId:d.ensembleId}).then(n=>{const y=Array.isArray(n)?n:n?.performances||[],s=Ue(),a=y.filter(c=>c.performanceDate>=s).sort((c,t)=>c.performanceDate.localeCompare(t.performanceDate));T(a),a.length>0&&G(c=>c||a[0].id)}).catch(()=>N(me("performances")))},[E,d?.ensembleId]),i.useEffect(()=>{if(_(null),!u){V(null),B(p||[]),K(null);return}C.getRoster(u).then(n=>{B(n.instrumentGroups||[]),K(n.carryForwardFrom||null)}
1).catch(()=>N(me("section seating"))),C.getPerformanceRoster(u).then(n=>V(n.performers||[])).catch(()=>V([]))},[u,p]);const O=W.find(n=>n.instrumentId===Z)||W[0],R=O&&h?ne(O,h.memberId):null;function ne(n,y){for(const s of n.slots){const a=s.members.find(c=>c.id===y);if(a)return a}return n.subs.find(s=>s.id===y)||(n.unavailable||[]).find(s=>s.id===y)||(n.performing||[]).find(s=>s.id===y)||null}function ee(n,y,s){B(a=>a.map(c=>{if(c.instrumentId!==y)return c;const t=c.unavailable||[],o=c.performing||[];let j=null;for(const D of c.slots){const J=D.members.find(de=>de.id===n);if(J){j=J;break}}if(j||(j=c.subs.find(D=>D.id===n)),j||(j=t.find(D=>D.id===n)),j||(j=o.find(D=>D.id===n)),!j)return c;const A=c.slots.map(D=>({...D,members:D.members.filter(J=>J.id!==n)})),M=c.subs.filter(D=>D.id!==n),ae=t.filter(D=>D.id!==n),H=o.filter(D=>D.id!==n),se=(D,J)=>D.lastName.localeCompare(J.lastName);if(s.type==="slot"){const D=A.find(J=>J.partNumber===s.partNumber);D&&(D.members=[...D.members,{...j,chairNumber:s.partNumber,isSub:!1,performanceStatus:"performing"}])}else s.type==="performing"?(H.push({...j,chairNumber:null,isSub:!1,performanceStatus:"performing"}),H.sort(se)):s.type==="unavailable"?(ae.push({...j,chairNumber:null,isSub:!1,performanceStatus:"unavailable"}),ae.sort(se)):(M.push({...j,chairNumber:null,isSub:!0,performanceStatus:"sub"}),M.sort(se));return{...c,slots:A,subs:M,unavailable:ae,performing:H}}))}async function le(n){if(!h||!O)return;const{memberId:y,instrumentId:s,source:a}=h;if(a.type===n.type&&a.partNumber===n.partNumber){_(null);return}if(n.type==="unavailable"&&!u){_(null);return}ee(y,s,n),_(null);const c=[{memberId:y,chairNumber:n.type==="slot"?n.partNumber:null,isSub:n.type==="sub",isUnavailable:n.type==="unavailable"}];try{W.find(o=>o.instrumentId===s)?.chairless&&u&&n.type!=="unavailable"?await C.toggleStandby(u,y,n.type==="performing"?"performing":"sub"):u?await C.updatePerformanceChairOrder(u,c):await C.updateChairOrder(c)}catch(t){N(t?.message||Ne),$?.()}}async function ce(n,y,s){if(!h||!O)return;const{memberId:a,instrumentId:c}=h,t=W,j=(y.members||[]).map(H=>H.id).filter(H=>H!==a),A=j.indexOf(s),M=A<0?j.length:A,ae=[...j.slice(0,M),a,...j.slice(M)];B(H=>H.map(se=>{if(se.instrumentId!==c)return se;const D=se.unavailable||[];let J=null;const de=se.slots.map(r=>{const b=r.members.find(x=>x.id===a);return b&&!J&&(J=b),{...r,members:r.members.filter(x=>x.id!==a)}}),F=se.subs.filter(r=>r.id!==a),xe=D.filter(r=>r.id!==a);if(J||(J=se.subs.find(r=>r.id===a)||D.find(r=>r.id===a)),J){const r=de.findIndex(b=>b.partNumber===n.partNumber);if(r>=0){const b={...J,chairNumber:n.partNumber,isSub:!1,performanceStatus:"performing"},x=new Map(de[r].members.map(m=>[m.id,m]));x.set(a,b),de[r]={...de[r],members:ae.map(m=>x.get(m)).filter(Boolean)}}}return{...se,slots:de,subs:F,unavailable:xe}})),_(null);try{if(h.source.type!=="slot"||h.source.partNumber!==n.partNumber){const H=[{memberId:a,chairNumber:n.partNumber,isSub:!1}];u?await C.updatePerformanceChairOrder(u,H):await C.updateChairOrder(H)}u?await C.reorderPerformanceSeats(u,n.partNumber,ae):await C.reorderSeats(n.partNumber,ae)}catch(H){B(t),N(H?.message||Ne)}}async function fe(n,y){if(!h||!O)return;const s=n.members.map(o=>o.id),a=s.indexOf(h.memberId),c=s.indexOf(y);if(a<0||c<0){_(null);return}if(a===c){_(null);return}s.splice(a,1),s.splice(c,0,h.memberId);const t=W;B(o=>o.map(j=>j.instrumentId!==O.instrumentId?j:{...j,slots:j.slots.map(A=>{if(A.partNumber!==n.partNumber)return A;const M=s.map(ae=>A.members.find(H=>H.id===ae)).filter(Boolean);return{...A,members:M}})})),_(null);try{u?await C.reorderPerformanceSeats(u,n.partNumber,s):await C.reorderSeats(n.partNumber,s)}catch(o){B(t),N(o?.message||"Could not save seat order.")}}function q(n,y){if(O){if(!h){_({memberId:n.id,instrumentId:O.instrumentId,source:y});return}if(h.memberId===n.id){_(null);return}if(h.instrumentId!==O.instrumentId){_(null);return}if(y.type==="slot"&&h.source.type==="slot"&&y.partNumber===h.source.partNumber){const s=O.slots.find(a=>a.partNumber===y.partNumber);s&&fe(s,n.id);return}if(y.type==="slot"){const s=O.slots.find(a=>a.partNumber===y.partNumber);if(s){ce(y,s,n.id);return}}le(y)}}function Q(n){h&&le(n)}async function l(){if(u){v(!0);try{await C.importDefaultToPerformance(u);const[n,y]=await Promise.all([C.getRoster(u),C.getPerformanceRoster(u)]);B(n.instrumentGroups||[]),K(n.carryForwardFrom||null),V(y.performers||[]),w("Section defaults imported.")}catch(n){N(n?.message||"Import failed.")}finally{v(!1)}}}return W.length===0?e.jsx("div",{style:{margin:"var(--bb-space-4)",padding:"var(--bb-space-6)",background:"var(--bb-surface)",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-lg)",textAlign:"center",color:"var(--bb-fg-muted)"},children:"No members in this section yet."}):e.jsxs("div",{style:{padding:"var(--bb-space-3) var(--bb-space-4) 0"},children:[e.jsxs("div",{style:{padding:"var(--bb-space-3)",background:"var(--bb-surface-sunken)",borderRadius:"var(--bb-radius-md)",marginBottom:"var(--bb-space-3)"},children:[e.jsx("label",{htmlFor:"mobile-roster-perf",style:{display:"block",fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:6},children:k.length>0?"Performance chairs":"No upcoming performances"}),e.jsxs("select",{id:"mobile-roster-perf","data-testid":"mobile-roster-perf",value:u,onChange:n=>G(n.target.value),disabled:k.length===0,style:{width:"100%",minHeight:44,padding:"10px 12px",fontSize:15,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",opacity:k.length===0?.6:1},children:[k.length===0&&e.jsx("option",{value:"",children:"No upcoming performances"}),k.map(n=>e.jsxs("option",{value:n.id,children:[we(n.performanceDate)," — ",n.title]},n.id))]}),u&&!U&&e.jsx("button",{type:"button","data-testid":"mobile-roster-import-defaults",onClick:l,disabled:X,style:{marginTop:8,minHeight:44,padding:"0 12px",border:"1px solid var(--bb-border)",borderRadius:"var(--bb-radius-md)",background:"var(--bb-surface)",color:"var(--bb-fg-body)",fontSize:13,fontWeight:600,cursor:X?"wait":"pointer",fontFamily:"inherit"},children:X?"Importing…":"Import defaults"})]}),W.length>1&&e.jsx(Qe,{ariaLabel:"Filter by instrument",size:"sm",className:"mb-2",tabs:W.map(n=>{const y=n.chairless?(n.performing||[]).length:n.slots.reduce((s,a)=>s+a.members.length,0);return{key:n.instrumentId,label:n.instrumentName,count:`${y}/${y+n.subs.length}`}}),value:Z,onChange:n=>{g(n),_(null)}}),h&&R&&e.jsxs("div",{"data-testid":"mobile-roster-pick-banner",role:"status",style:{position:"sticky",top:0,zIndex:5,marginBottom:"var(--bb-space-3)",padding:"10px 12px",borderRadius:"var(--bb-radius-md)",background:"var(--bb-primary-soft)",color:"var(--bb-primary-ink)",border:"1px solid var(--bb-primary)",display:"flex",alignItems:"center",gap:10},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:13,fontWeight:700,color:"var(--bb-primary)"},children:["Moving ",R.firstName," ",R.lastName]}),e.jsx("div",{style:{marginTop:2,fontSize:12,color:"var(--bb-fg-muted)"},children:O?.chairless?"Tap a group to place.":"Tap a chair or sub to place."})]}),e.jsx("button",{type:"button",onClick:()=>_(null),style:{minHeight:44,padding:"0 12px",border:"1px solid var(--bb-primary)",borderRadius:"var(--bb-radius-pill)",background:"var(--bb-surface)",color:"var(--bb-primary)",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:"inherit",flexShrink:0},children:"Cancel"})]}),O&&e.jsxs(e.Fragment,{children:[O.chairless?e.jsx("div",{style:{marginBottom:"var(--bb-space-3)"},children:e.jsxs(Ee,{label:"Playing this concert",emptyHint:"Nobody placed yet",isDest:!!h,onZoneTap:()=>Q({type:"performing"}),helpText:"Percussion is covered by station rather than by numbered chair, so there are no parts to assign here — just who is playing.",children:[(O.performing||[]).map(n=>e.jsx(We,{member:n,source:{type:"performing"}
1,isPicked:h?.memberId===n.id,onInstrument:L(n),onTap:()=>q(n,{type:"performing"})},n.id)),(O.performing||[]).length===0&&e.jsx(Oe,{active:!!h,text:h?"Tap to put them on this concert":"Nobody placed yet",onTap:()=>Q({type:"performing"})})]})}):e.jsx("div",{style:{marginBottom:"var(--bb-space-3)"},children:O.slots.map(n=>{const y=!!h,s=n.members||[];return e.jsxs(Ee,{label:`${zt(n.partNumber)} chair`,emptyHint:"Empty — tap to place here",isDest:y,onZoneTap:()=>Q({type:"slot",partNumber:n.partNumber}),children:[s.map((a,c)=>e.jsx(We,{member:a,seatIndex:c+1,source:{type:"slot",partNumber:n.partNumber},isPicked:h?.memberId===a.id,onInstrument:L(a),onTap:()=>q(a,{type:"slot",partNumber:n.partNumber})},a.id)),s.length===0&&e.jsx(Oe,{active:y,text:y?"Tap to place here":"Empty",onTap:()=>Q({type:"slot",partNumber:n.partNumber})})]},n.partNumber)})}),e.jsxs(Ee,{label:"Subs",emptyHint:"No subs",isDest:!!h,onZoneTap:()=>Q({type:"sub"}),tone:"warning",helpText:"In the section but sitting out this concert — available to step in if someone cancels last-minute.",children:[O.subs.map(n=>e.jsx(We,{member:n,source:{type:"sub"},isPicked:h?.memberId===n.id,onInstrument:L(n),onTap:()=>q(n,{type:"sub"})},n.id)),O.subs.length===0&&e.jsx(Oe,{active:!!h,text:h?"Tap to move to subs":"No subs",onTap:()=>Q({type:"sub"})})]}),u&&e.jsxs(Ee,{label:"Unavailable",emptyHint:"No one is unavailable",isDest:!!h,onZoneTap:()=>Q({type:"unavailable"}),tone:"unavailable",helpText:"Can't perform this concert or season — removed from the program and excluded from attendance tracking.",children:[(O.unavailable||[]).map(n=>e.jsx(We,{member:n,source:{type:"unavailable"},isPicked:h?.memberId===n.id,onInstrument:L(n),onTap:()=>q(n,{type:"unavailable"}
1),strike:!0},n.id)),(O.unavailable||[]).length===0&&e.jsx(Oe,{active:!!h,text:h?"Tap to move to unavailable":"No one is unavailable",onTap:()=>Q({type:"unavailable"})})]})]}),e.jsx(ct,{isOpen:!!I,onClose:()=>P(null),performanceId:u,member:I,ensembleId:d?.ensembleId||null,canManage:!1,sectionInstrumentIds:W.map(n=>n.instrumentId),onSaved:n=>{_(null),n?.instrumentId&&g(n.instrumentId),f(),$?.()}})]})}function Ee({label:d,isDest:p,onZoneTap:$,tone:w,helpText:N,children:E}){const k=w==="warning"?"var(--bb-warning)":w==="unavailable"?"#cbd5e1":w==="muted"?"var(--bb-border-soft)":"var(--bb-border)";return e.jsxs("section",{"data-testid":`mobile-roster-zone-${d.toLowerCase().replace(/\s+/g,"-")}`,style:{marginBottom:"var(--bb-space-3)",border:"1px solid",borderColor:p?"var(--bb-primary)":k,borderStyle:p?"dashed":"solid",borderRadius:"var(--bb-radius-md)",background:p?"var(--bb-primary-soft)":"var(--bb-surface)",overflow:"hidden"},children:[e.jsxs("button",{type:"button",onClick:$,disabled:!p,"aria-label":p?`Move selected member to ${d}`:d,style:{display:"block",width:"100%",padding:"8px 12px",border:"none",background:"transparent",textAlign:"left",fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:p?"var(--bb-primary)":"var(--bb-fg-muted)",cursor:p?"pointer":"default",fontFamily:"inherit"},children:[d,N&&e.jsx("span",{title:N,"aria-label":N,style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,borderRadius:"50%",background:"var(--bb-border-soft)",color:"var(--bb-fg-muted)",fontSize:9,fontWeight:700,marginLeft:6,letterSpacing:0,textTransform:"none",cursor:"help",verticalAlign:"middle"},children:"?"}),p&&e.jsx("span",{style:{marginLeft:6,fontWeight:500,textTransform:"none",letterSpacing:0},children:"· tap to place"})]}),e.jsx("div",{style:{borderTop:"1px solid var(--bb-border-soft)"},children:E})]})}function Oe({active:d,text:p,onTap:$}){const w=d&&typeof $=="function",N=w?"button":"div";return e.jsx(N,{type:w?"button":void 0,onClick:w?$:void 0,style:{minHeight:44,padding:"12px",fontSize:12,color:d?"var(--bb-primary)":"var(--bb-fg-subtle)",fontStyle:"italic",textAlign:"center",background:w?"var(--bb-primary-soft)":"transparent",border:"none",width:"100%",cursor:w?"pointer":"default",fontFamily:"inherit"},children:p})}function We({member:d,seatIndex:p,isPicked:$,onTap:w,onInstrument:N,strike:E}){const k=lt(d.id,6),T=((d.firstName?.[0]||"")+(d.lastName?.[0]||"")).toUpperCase()||"?";return e.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":$,"data-testid":$?"mobile-roster-picked-member":"mobile-roster-member",onClick:w,onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),w())},style:{display:"flex",alignItems:"center",gap:"var(--bb-space-3)",minHeight:56,padding:"8px 12px",borderTop:"1px solid var(--bb-border-soft)",background:$?"var(--bb-primary-soft)":"transparent",outline:$?"2px solid var(--bb-primary)":"none",outlineOffset:-2,cursor:"pointer",WebkitTapHighlightColor:"transparent"},children:[p!=null&&e.jsx("span",{"aria-hidden":"true",style:{width:20,flexShrink:0,textAlign:"center",fontSize:11,fontWeight:700,color:$?"var(--bb-primary)":"var(--bb-fg-subtle)"},children:p}),d.photoUrl?e.jsx("img",{src:d.photoUrl,alt:"",style:{width:36,height:36,borderRadius:"50%",objectFit:"cover",flexShrink:0}}):e.jsx("div",{"aria-hidden":"true",style:{width:36,height:36,borderRadius:"50%",background:`var(--bb-avatar-${k})`,color:`var(--bb-avatar-${k}-ink)`,fontSize:12,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:T}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:15,fontWeight:600,color:E?"var(--bb-fg-muted)":"var(--bb-fg)",textDecoration:E?"line-through":"none",display:"flex",alignItems:"center",gap:6,flexWrap:"wrap"},children:[e.jsxs("span",{children:[d.firstName," ",d.lastName]}),d.instrumentSource==="manual"&&e.jsx(ze,{})]}),(d.attendanceRate!=null||d.lastPerformanceDate)&&e.jsxs("div",{style:{marginTop:2,fontSize:12,color:"var(--bb-fg-muted)"},children:[d.attendanceRate!=null&&`${d.attendanceRate}% attendance`,d.lastPerformanceDate&&d.attendanceRate!=null&&" · ",d.lastPerformanceDate&&`last ${Ot(d.lastPerformanceDate)}`]})]}),$&&e.jsx("span",{"aria-hidden":"true",style:{fontSize:10,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-primary)",padding:"3px 8px",borderRadius:"var(--bb-radius-pill)",background:"var(--bb-surface)",border:"1px solid var(--bb-primary)",flexShrink:0},children:"Moving"}),N&&!$&&e.jsx(dt,{member:d,onChange:N})]})}function Ot(d){if(!d)return"";const p=new Date(d.length===10?`${d}T00:00:00`:d);return Number.isNaN(p.getTime())?d:p.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function at({members:d,picked:p,onToggle:$,isOpen:w,onToggleOpen:N,label:E}){const k=p.size;return e.jsxs("div",{style:{marginBottom:"var(--bb-space-3)"},children:[e.jsxs("button",{type:"button",onClick:N,"aria-expanded":w,style:{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",minHeight:44,padding:"6px 12px",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-md)",background:k>0?"var(--bb-primary-soft)":"var(--bb-surface)",color:k>0?"var(--bb-primary-ink)":"var(--bb-fg)",fontSize:13,fontWeight:600,fontFamily:"inherit",curs
1or:"pointer",textAlign:"left"},children:[e.jsxs("span",{children:[E||"Pick specific members",k>0&&e.jsxs("span",{style:{marginLeft:8,fontWeight:700},children:["(",k,")"]})]}),e.jsx("span",{"aria-hidden":"true",style:{fontSize:12},children:w?"▴":"▾"})]}),w&&e.jsx("div",{"data-testid":"section-msg-member-picker",style:{marginTop:8,maxHeight:240,overflowY:"auto",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-md)",background:"var(--bb-surface)"},children:d.length===0?e.jsx("div",{style:{padding:12,fontSize:13,color:"var(--bb-fg-muted)"},children:"No active members with email."}):d.map(T=>{const u=p.has(T.id);return e.jsxs("button",{type:"button",onClick:()=>$(T.id),"aria-pressed":u,style:{display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:44,padding:"8px 12px",border:"none",borderTop:"1px solid var(--bb-border-soft)",background:u?"var(--bb-primary-soft)":"transparent",color:"var(--bb-fg)",fontFamily:"inherit",fontSize:14,textAlign:"left",cursor:"pointer"},children:[e.jsx("span",{"aria-hidden":"true",style:{width:18,height:18,borderRadius:4,border:"2px solid",borderColor:u?"var(--bb-primary)":"var(--bb-border-soft)",background:u?"var(--bb-primary)":"transparent",color:"#fff",fontSize:12,fontWeight:700,display:"inline-flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:u?"✓":""}),e.jsxs("span",{style:{flex:1,minWidth:0},children:[e.jsx("span",{style:{display:"block",fontWeight:600},children:T.name}),T.instrumentName&&e.jsx("span",{style:{display:"block",fontSize:12,color:"var(--bb-fg-muted)"},children:T.instrumentName})]})]},T.id)})})]})}function Wt({isOpen:d,onClose:p,sectionName:$,instrumentGroups:w,ensembleId:N,orgId:E}){const{showSuccess:k,showError:T}=je(),[u,G]=i.useState(""),[S,V]=i.useState(""),[W,B]=i.useState(!1),[Z,g]=i.useState(()=>new Set),[h,_]=i.useState(()=>new Set),[X,v]=i.useState(!1),[re,Y]=i.useState("default"),[U,K]=i.useState([]),[I,P]=i.useState(""),[f,L]=i.useState("");i.useEffect(()=>{!d||!E||!N||Ce.list(E,{ensembleId:N}).then(a=>{const c=Array.isArray(a)?a:a?.performances||[],t=Ue(),o=c.filter(j=>j.performanceDate>=t).sort((j,A)=>j.performanceDate.localeCompare(A.performanceDate));K(o),!I&&o.length>0&&P(o[0].id)}).catch(()=>T(me("performances")))},[d,E,N]);const O=(w||[]).flatMap(a=>[...a.slots.flatMap(t=>t.members||[]),...a.performing||[],...a.subs||[]].filter(t=>t.memberStatus==="active"&&t.emailAddress&&t.emailAddress.trim()).map(t=>({id:t.id,name:`${t.firstName||""} ${t.lastName||""}`.trim()||t.emailAddress,instrumentId:a.instrumentId,instrumentName:a.instrumentName}))),R=new Map;for(const a of O)R.has(a.id)||R.set(a.id,a);const ne=Array.from(R.values()).sort((a,c)=>a.name.localeCompare(c.name)),ee=(w||[]).map(a=>{const c=O.filter(t=>t.instrumentId===a.instrumentId).length;return{id:a.instrumentId,name:a.instrumentName,eligible:c}}).filter(a=>a.eligible>0),le=ee.map(a=>a.id).filter(a=>!Z.has(a)),ce=Z.size===0,fe=new Set(O.filter(a=>!Z.has(a.instrumentId)).map(a=>a.id)),q=h.size>0?h.size:fe.size,Q=h.size>0?h.size:ne.length;i.useEffect(()=>{d&&(G(""),V(""),g(new Set),_(new Set),v(!1),Y("default"),L(""),P(""))},[d]);function l(a){_(c=>{const t=new Set(c);return t.has(a)?t.delete(a):t.add(a),t})}async function n(){if(!I){T("Pick a performance.");return}B(!0);try{const a=h.size>0?Array.from(h):void 0,c=await C.sendChairDetails(I,f.trim()||null,a);k(`Sent to ${c.sent} member${c.sent!==1?"s":""}.`),p?.()}catch(a){T(a?.message||"Could not send.")}finally{B(!1)}}function y(a){g(c=>{const t=new Set(c);return t.has(a)?t.delete(a):t.add(a),t})}async function s(){if(!S.trim()){T("Enter a message.");return}if(q===0){T("Pick at least one instrument or member.");return}B(!0);try{const a=Array.from(h),c=a.length>0?[]:ce?void 0:le,t=a.length>0?a:void 0,o=await C.notify(u.trim()||void 0,S.trim(),c,t);k(`Message sent to ${o.sent} member${o.sent!==1?"s":""}.`),p?.()}catch(a){T(a?.message||"Could not send message.")}finally{B(!1)}}return re==="template-chair-details"?e.jsx(qe,{isOpen:d,onClose:p,title:"Send Chair & Performance Details",children:e.jsxs("div",{style:{padding:"var(--bb-space-4)"},children:[e.jsx("button",{type:"button",onClick:()=>Y("default"),style:{minHeight:44,padding:"6px 12px",border:"none",background:"transparent",color:"var(--bb-primary)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"inherit",marginBottom:"var(--bb-space-3)",display:"inline-flex",alignItems:"center",gap:4},children:"← Back"}),e.jsxs("div",{style:{background:"var(--bb-info-soft, #eff6ff)",border:"1px solid var(--bb-info, #93c5fd)",borderRadius:"var(--bb-radius-md)",padding:"12px 14px",marginBottom:"var(--bb-space-3)"},children:[e.jsx("p",{style:{margin:"0 0 6px",fontSize:13,fontWeight:600,color:"#1e3a8a"},children:"What's included"}),e.jsxs("ul",{style:{margin:0,paddingLeft:16,color:"#1e3a8a",fontSize:12,lineHeight:1.5},children:[e.jsx("li",{children:"Full section lineup — every member's chair and seat"}),e.jsx("li",{children:"Performance details — date, time, call/setup, venue"}),e.jsx("li",{children:"First rehearsal — date, time, venue"}),e.jsx("li",{children:"Setlist with recording links (if set)"}
1),e.jsx("li",{children:"Your name, email, and phone as the signature"})]})]}),e.jsxs("div",{style:{marginBottom:"var(--bb-space-3)"},children:[e.jsx("label",{style:{display:"block",marginBottom:6,fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)"},children:"Performance"}),e.jsxs("select",{value:I,onChange:a=>P(a.target.value),style:{width:"100%",minHeight:44,padding:"10px 12px",fontSize:15,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)"},children:[U.length===0&&e.jsx("option",{value:"",children:"No upcoming performances"}),U.map(a=>e.jsxs("option",{value:a.id,children:[we(a.performanceDate)," — ",a.title]},a.id))]})]}),e.jsxs("div",{style:{marginBottom:"var(--bb-space-4)"},children:[e.jsxs("label",{style:{display:"block",marginBottom:6,fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)"},children:["Personal message ",e.jsx("span",{style:{textTransform:"none",letterSpacing:0,fontWeight:400,color:"var(--bb-fg-subtle)"},children:"(optional)"})]}),e.jsx("textarea",{rows:4,value:f,onChange:a=>L(a.target.value),placeholder:"Welcome to our next concert!",style:{width:"100%",padding:"10px 12px",fontSize:15,lineHeight:1.5,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",resize:"vertical",fontFamily:"inherit"}})]}),e.jsxs("div",{style:{background:"var(--bb-surface-sunken, #f5f7fa)",borderRadius:"var(--bb-radius-md)",padding:"10px 12px",marginBottom:"var(--bb-space-3)",fontSize:13,color:"var(--bb-fg)"},children:[e.jsx("strong",{children:"To:"})," ",h.size>0?`${h.size} selected member${h.size===1?"":"s"} only`:"Whole section (all active members with email)"]}),e.jsx(at,{members:ne,picked:h,onToggle:l,isOpen:X,onToggleOpen:()=>v(a=>!a),label:"Pick specific members (overrides whole-section)"}),e.jsx("button",{type:"button",onClick:n,disabled:W||!I||Q===0,style:{width:"100%",minHeight:44,padding:"0 16px",border:"none",borderRadius:"var(--bb-radius-md)",background:I&&Q>0?"var(--bb-primary, #2e6b8a)":"var(--bb-surface-sunken)",color:I&&Q>0?"#fff":"var(--bb-fg-muted)",fontSize:15,fontWeight:600,cursor:W?"wait":I&&Q>0?"pointer":"not-allowed",fontFamily:"inherit"},children:W?"Sending…":`Send${Q>0?` (${Q})`:""}`}),!I&&U.length===0&&e.jsx("p",{style:{margin:"8px 0 0",fontSize:12,color:"var(--bb-fg-muted)",textAlign:"center",fontStyle:"italic"},children:"No upcoming performances — chair details need a performance to send."})]})}):e.jsx(qe,{isOpen:d,onClose:p,title:"Send to Section",children:e.jsxs("div",{style:{padding:"var(--bb-space-4)"},children:[e.jsxs("div",{style:{marginBottom:"var(--bb-space-4)"},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:8},children:"Templates"}),e.jsxs("button",{type:"button",onClick:()=>Y("template-chair-details"),style:{display:"flex",alignItems:"center",gap:12,width:"100%",padding:"12px 14px",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-md)",background:"var(--bb-surface)",cursor:"pointer",textAlign:"left",fontFamily:"inherit"},children:[e.jsx("span",{style:{width:36,height:36,borderRadius:"50%",background:"var(--bb-primary-soft)",color:"var(--bb-primary)",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8 7h12M8 12h12M8 17h12M3 7h.01M3 12h.01M3 17h.01"})})}),e.jsxs("span",{style:{flex:1,minWidth:0},children:[e.jsx("span",{style:{display:"block",fontSize:14,fontWeight:600,color:"var(--bb-fg)"},children:"Send Chair & Performance Details"}),e.jsx("span",{style:{display:"block",fontSize:12,color:"var(--bb-fg-muted)",marginTop:2},children:"Chair list + concert details + first rehearsal + your contact info."})]}),e.jsx("span",{style:{flexShrink:0,color:"var(--bb-fg-subtle)"},children:"→"})]})]}),e.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:8},children:"Custom Message"}),e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",padding:"4px 10px",borderRadius:"var(--bb-radius-pill)",background:"var(--bb-primary-soft)",color:"var(--bb-primary-ink)",fontSize:12,fontWeight:600,marginBottom:"var(--bb-space-3)"},children:["To: ",q," ",h.size>0?"selected":$||"section"," member",q===1?"":"s"]}),ee.length>1&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:6},children:[e.jsx("div",{style:{fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)"},children:"Instruments"}),!ce&&e.jsx("button",{type:"button",onClick:()=>g(new Set),style:{minHeight:44,padding:"0 10px",border:"none",background:"transparent",color:"var(--bb-primary)",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:"Select all"})]}),e.jsx("div",{"data-testid":"mobile-section-msg-instruments",style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:"var(--bb-space-3)"},children:ee.map(a=>{const c=!Z.has(a.id);return e.jsxs("button",{type:"button","data-testid":`mobile-section-msg-instrument-${a.id}`,"aria-pressed":c,onClick:()=>y(a.id),style:{minHeight:44,padding:"0 12px",borderRadius:"var(--bb-radius-pill)",border:"1px solid",borderColor:c?"var(--bb-primary)":"var(--bb-border-soft)",background:c?"var(--bb-primary-soft)":"var(--bb-surface)",color:c?"var(--bb-primary)":"var(--bb-fg-muted)",fontSize:13,fontWeight:600,cursor:"pointer",fontFamily:"inherit",display:"inline-flex",alignItems:"center",gap:6,textDecoration:c?"none":"line-through"},children:[e.jsx("span",{"aria-hidden":"true",style:{fontSize:14,lineHeight:1},children:c?"✓":"×"}),a.name,e.jsxs("span",{style:{opacity:.75,fontSize:12},children:["(",a.eligible,")"]})]},a.id)})})]}),e.jsx(at,{members:ne,picked:h,onToggle:l,isOpen:X,onToggleOpen:()=>v(a=>!a)}),e.jsx("label",{htmlFor:"mobile-section-msg-subject",style:{display:"block",fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:6},children:"Subject"}),e.jsx("input",{id:"mobile-section-msg-subject","data-testid":"mobile-section-msg-subject",type:"text",value:u,onChange:a=>G(a.target.value),placeholder:"e.g. Bring your mutes Tuesday",style:{width:"100%",minHeight:44,padding:"10px 12px",fontSize:15,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",marginBottom:"var(--bb-space-3)"}}),e.jsx("label",{htmlFor:"mobile-section-msg-body",style:{display:"block",fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:6},children:"Message"}),e.jsx("textarea",{id:"mobile-section-msg-body","data-testid":"mobile-section-msg-body",rows:6,value:S,onChange:a=>V(a.target.value),placeholder:"Type your message…",style:{width:"100%",padding:"10px 12px",fontSize:15,lineHeight:1.5,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",resize:"vertical",minHeight:120,fontFamily:"inherit",marginBottom:"var(--bb-space-4)"}}),e.jsxs("div",{style:{display:"flex",gap:"var(--bb-space-2)"},children:[e.jsx("button",{type:"button",onClick:p,disabled:W,style:{flex:1,minHeight:48,padding:"12px 16px",border:"1px solid var(--bb-border)",borderRadius:"var(--bb-radius-md)",background:"var(--bb-surface)",color:"var(--bb-fg-body)",fontFamily:"inherit",fontSize:15,fontWeight:600,cursor:W?"not-allowed":"pointer"},children:"Cancel"}),e.jsx("button",{type:"button","data-testid":"mobile-section-msg-send",onClick:s,disabled:W||!S.trim()||q===0,style:{flex:1,minHeight:48,padding:"12px 16px",border:"none",borderRadius:"var(--bb-radius-md)",background:S.trim()&&q>0?"var(--bb-primary)":"var(--bb-surface-sunken)",color:S.trim()&&q>0?"#fff":"var(--bb-fg-muted)",fontFamily:"inherit",fontSize:15,fontWeight:600,cursor:W?"wait":S.trim()&&q>0?"pointer":"not-allowed"},children:W?"Sending…":`Send${q>0?` (${q})`:""}`})]})]})})}function Bt({roster:d,ensembleId:p}){const $=oe(l=>l.currentOrg?.trackRehearsalAttendance!==!1),{showError:w}=je(),N=oe(l=>l.currentOrg?.id),E=oe(l=>l.currentOrg?.trackPerformanceAttendance!==!1),k=oe(l=>l.currentOrg?.trackRehearsalAttendance!==!1),T=oe(l=>l.currentOrg?.trackRehearsalRsvps!==!1),u=!E&&!k&&T,G=oe(l=>l.currentOrg?.trackPerformanceRsvps!==!1),[S,V]=i.useState([]),[W,B]=i.useState(""),[Z,g]=i.useState({}),h=i.useRef(!1),[_,X]=_e();i.useEffect(()=>{!N||!p||Promise.all([E||G?Ce.list(N,{ensembleId:p}).catch(()=>[]):Promise.resolve([]),k||u?Ce.rehearsals(N,{ensembleId:p}).catch(()=>[]):Promise.resolve([])]).then(([l,n])=>{const y=(Array.isArray(l)?l:l?.performances||[]).map(D=>({id:D.id,type:"performance",label:D.title,date:D.performanceDate})),s=(Array.isArray(n)?n:[]).map(D=>({id:D.id,type:"rehearsal",label:`Rehearsal — ${D.performanceTitle||"TBD"}`,date:D.rehearsalDate})),a=new Date,c=new Date(a);c.setDate(a.getDate()-30);const t=new Date(a);t.setDate(a.getDate()+70);const o=He(c),j=He(t),A=new Date,M=`${A.getFullYear()}
1-${String(A.getMonth()+1).padStart(2,"0")}-${String(A.getDate()).padStart(2,"0")}`,ae=u?M:o,H=[...y.filter(D=>D.date>=(E?o:M)&&D.date<=j),...s.filter(D=>D.date>=ae&&D.date<=j)].sort((D,J)=>(D.date||"").localeCompare(J.date||""));V(H);const se=_.get("eventId");if(se){const D=_.get("eventType"),J=H.find(de=>de.id===se&&(!D||de.type===D));_.delete("eventId"),_.delete("eventType"),_.delete("tab"),X(_,{replace:!0}),J&&(B(J.id),h.current=!0)}if(!h.current){const D=new Date,J=`${D.getFullYear()}-${String(D.getMonth()+1).padStart(2,"0")}-${String(D.getDate()).padStart(2,"0")}`,de=H.find(F=>F.date>=J)||H[H.length-1];de&&(h.current=!0,B(de.id))}})},[N,p,E,k,u,G]);const v=S.find(l=>l.id===W)||null,re=(()=>{const l=new Date;return`${l.getFullYear()}-${String(l.getMonth()+1).padStart(2,"0")}-${String(l.getDate()).padStart(2,"0")}`})(),Y=v?.type==="rehearsal"&&(v.date>re||!$&&v.date>=re),U=v?.type==="performance"&&v.date>re,K=Y||U,[I,P]=i.useState({}),[f,L]=i.useState(null),[O,R]=i.useState({}),[ne,ee]=i.useState({});i.useEffect(()=>{if(!v){g({}),R({}),P({}),L(null),ee({});return}let l=!1;return K?(P({}),L(null),(v.type==="performance"?C.getPerformanceAvailability(v.id):C.getRehearsalAvailability(v.id)).then(y=>{if(l)return;const s={};for(const a of y?.rsvps||[])s[a.memberId]={response:a.response,reason:a.reason};P(a=>({...s,...a})),ee(y?.seats||{})}).catch(()=>w(me("availability"))),()=>{l=!0}):(ot.getEventAttendance(v.id,v.type).then(n=>{if(l||!n?.sections)return;const y={},s={},a={};for(const c of n.sections)for(const t of c.members)t.status&&t.status!=="unmarked"&&(y[t.memberId]=t.status),t.fromRsvp?s[t.memberId]="said can't make it":t.fromRoster&&(s[t.memberId]=t.expect==="out"?"out for the concert":"standby"),a[t.memberId]={partNumber:t.partNumber??null,seatPosition:t.seatPosition??null,rosterStatus:t.rosterStatus??null,rosterReason:t.rosterReason??null};g(c=>({...y,...c})),R(s),ee(a)}).catch(()=>w(me("attendance"))),()=>{l=!0})},[v?.id,v?.type]);async function le(l,n){if(!v){w("Pick an event first.");return}const y=Z[l]||"unmarked";g(s=>({...s,[l]:n}));try{await C.recordAttendance(v.id,v.type,[{memberId:l,status:n}])}catch(s){g(a=>a[l]===n?{...a,[l]:y}:a),w(s?.message||Ne)}}async function ce(l){const n=I[l],y=n?.response==="not_attending",s=y?"attending":"not_attending";P(a=>({...a,[l]:{response:s,reason:y?null:a[l]?.reason||null}}));try{await(v.type==="performance"?C.recordPerformanceAvailability(v.id,l,s):C.recordRehearsalAvailability(v.id,l,s))}catch(a){P(c=>({...c,[l]:n})),w(a?.message||Ne)}}async function fe(l,n){const y=I[l];L(null),P(s=>({...s,[l]:{response:"not_attending",reason:n||null}}));try{await(v.type==="performance"?C.recordPerformanceAvailability(v.id,l,"not_attending",n||null):C.recordRehearsalAvailability(v.id,l,"not_attending",n||null))}catch(s){P(a=>({...a,[l]:y})),w(s?.message||Ne)}}function q(l){const n=ne[l.id];return n&&(n.partNumber!=null||n.rosterStatus)?n:{chairNumber:l.chairNumber??null,seatPosition:l.seatPosition??null}}const Q=[...d||[]].map(l=>{const n=q(l);return{...l,chairNumber:n.partNumber??n.chairNumber??null,seatPosition:n.seatPosition??null}}).sort(Be);return e.jsxs("div",{style:{paddingBottom:32},children:[e.jsxs("div",{style:{padding:"var(--bb-space-4)",background:"var(--bb-bg)"},children:[e.jsx("label",{htmlFor:"mobile-attendance-event",style:{display:"block",fontSize:11,fontWeight:600,letterSpacing:"0.08em",textTransform:"uppercase",color:"var(--bb-fg-muted)",marginBottom:6},children:"Event"}),e.jsxs("select",{id:"mobile-attendance-event","data-testid":"mobile-attendance-event",value:W,onChange:l=>{B(l.target.value),g({}),R({}),P({}),L(null)},style:{width:"100%",minHeight:44,padding:"10px 12px",fontSize:15,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)"},children:[e.jsx("option",{value:"",children:"— Pick an event —"}),S.map(l=>e.jsxs("option",{value:l.id,children:[l.date," · ",l.label]},`${l.type}:${l.id}`))]})]}),v&&K&&e.jsx("p",{style:{margin:"0 var(--bb-space-4) var(--bb-space-3)",padding:"var(--bb-space-3)",fontSize:12,lineHeight:1.5,color:"var(--bb-warning-ink)",background:"var(--bb-warning-soft)",borderRadius:"var(--bb-radius-md)"},children:U?e.jsx(e.Fragment,{children:"This concert is coming up. Mark anyone who’s told you they can’t play — their chair opens up, and they’ll show as out on the roster and in the leadership digest."}):e.jsxs(e.Fragment,{children:["This rehearsal is coming up. Mark anyone who’s told you they can’t make it — they’ll show as out on the stage map and in the leadership digest",k?", and their attendance will be excused automatically that day.":"."]})}),v&&!K&&Q.length>0&&e.jsx("p",{style:{margin:"0 var(--bb-space-4) var(--bb-space-3)",fontSize:13,lineHeight:1.5,color:"var(--bb-fg-muted)"},children:"Tap Present, Absent or Excused under each name. Tap it again to clear it. Each tap saves on its own."}),Q.length===0?e.jsx("div",{style:{margin:"var(--bb-space-4)",padding:"var(--bb-space-6)",background:"var(--bb-surface)",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-lg)",textAlign:"center",color:"var(--bb-fg-muted)"},children:"No members to mark."}):e.jsx("ul",{"data-testid":"mobile-attendance-roster",style:{listStyle:"none",margin:0,padding:0,background:"var(--bb-surface)"},children:Q.map(l=>{const n=Z[l.id]||"unmarked",y=lt(l.id,6),s=((l.firstName?.[0]||"")+(l.lastName?.[0]||"")).toUpperCase()||"?",a=l.photoUrl?e.jsx("img",{src:l.photoUrl,alt:"",style:{width:40,height:40,borderRadius:"50%",objectFit:"cover",flexShrink:0}}):e.jsx("div",{"aria-hidden":"true",style:{width:40,height:40,borderRadius:"50%",background:`var(--bb-avatar-${y})`,color:`var(--bb-avatar-${y}-ink)`,fontSize:13,fontWeight:700,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:s}),c=q(l).rosterStatus==="unavailable";if(K){const t=I[l.id],o=t?.response==="not_attending";return e.jsxs("li",{style:{padding:"10px var(--bb-space-4)",borderTop:"1px solid var(--bb-border-soft)",background:o?"var(--bb-danger-soft)":"transparent",opacity:c?.5:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--bb-space-3)",minHeight:44},children:[a,e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:15,fontWeight:600,color:"var(--bb-fg)"},children:[l.firstName," ",l.lastName]}),Ie(l.instrument,q(l))&&e.jsx("div",{style:{marginTop:2,fontSize:12,color:"var(--bb-fg-muted)"},children:Ie(l.instrument,q(l))})]}),e.jsx("button",{type:"button","data-testid":"mobile-availability-toggle",onClick:()=>ce(l.id),style:{minHeight:44,minWidth:96,padding:"0 12px",borderRadius:"var(--bb-radius-pill)",border:"none",background:o?"var(--bb-danger)":"var(--bb-surface-sunken)",color:o?"#fff":"var(--bb-fg-muted)",fontSize:12,fontWeight:600,cursor:"pointer",fontFamily:"inherit"},children:o?"Out — undo":"Mark out"})]}),o&&(f===l.id?e.jsx("input",{autoFocus:!0,defaultValue:t?.reason||"",placeholder:"Reason (optional) — e.g. vacation",onBlur:j=>fe(l.id,j.target.value.trim()),onKeyDown:j=>{j.key==="Enter"&&j.target.blur()},style:{marginTop:8,width:"100%",minHeight:44,padding:"8px 12px",fontSize:14,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",fontFamily:"inherit"}}):e.jsx("button",{type:"button",onClick:()=>L(l.id),style:{marginTop:6,padding:0,border:"none",background:"none",fontSize:12,textAlign:"left",cursor:"pointer",fontFamily:"inherit",color:t?.reason?"var(--bb-fg-muted)":"var(--bb-brand-primary, var(--bb-fg))"},children:t?.reason?e.jsxs(e.Fragment,{children:["“",t.reason,"” ",e.jsx("span",{style:{fontWeight:600},children:"edit"})]}):e.jsx("span",{style:{fontWeight:600},children:"+ add reason"})}))]},l.id)}return e.jsxs("li",{style:{padding:"10px var(--bb-space-4)",borderTop:"1px solid var(--bb-border-soft)",opacity:c?.5:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--bb-space-3)",minHeight:44},children:[a,e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsxs("div",{style:{fontSize:15,fontWeight:600,color:"var(--bb-fg)"},children:[l.firstName," ",l.lastName,O[l.id]&&n==="excused"&&e.jsx("span",{style:{marginLeft:6,fontSize:10,fontWeight:700,color:"var(--bb-warning-ink)",background:"var(--bb-warning-soft)",borderRadius:999,padding:"1px 8px",whiteSpace:"nowrap",verticalAlign:"middle"},children:O[l.id]})]}),Ie(l.instrument,q(l))&&e.jsx("div",{style:{marginTop:2,fontSize:12,color:"var(--bb-fg-muted)"},children:Ie(l.instrument,q(l))})]})]}),e.jsx(bt,{size:"lg",className:"mt-2",name:`${l.firstName} ${l.lastName}`,value:n,onChange:t=>le(l.id,t)}
1)]},l.id)})}),Q.length>0&&v&&e.jsx("p",{style:{margin:"var(--bb-space-3) var(--bb-space-4)",fontSize:12,color:"var(--bb-fg-muted)",textAlign:"center"},children:"Changes save automatically as you tap."})]})}function Ze({title:d,variant:p="gray"}){const $=p==="amber"?"bg-amber-200 text-amber-800":p==="slate"?"bg-slate-200 text-slate-600":"bg-gray-200 text-gray-600";return e.jsx("span",{title:d,"aria-label":d,className:`inline-flex items-center justify-center w-4 h-4 rounded-full ${$} text-[10px] font-semibold cursor-help`,children:"?"})}function Le(d){return d==null?"bg-gray-100 text-gray-500":d>=80?"bg-green-100 text-green-700":d>=60?"bg-amber-100 text-amber-700":"bg-red-100 text-red-700"}const Lt={present:"bg-green-500 text-white",absent:"bg-red-500 text-white",excused:"bg-amber-400 text-white",unmarked:"bg-gray-200 text-gray-500"},Ht={present:"P",absent:"A",excused:"E",unmarked:"—"};function _t(d){if(!d)return"?";const p=new Date(`${d}T00:00:00`);if(Number.isNaN(p.getTime()))return d;const $=p.toLocaleDateString(void 0,{month:"short",day:"numeric"});return p.getFullYear()===new Date().getFullYear()?$:`${$} ’${String(p.getFullYear()).slice(2)}`}function gr(){const{showSuccess:d,showError:p}=je(),$=xt(),[w]=_e(),[N,E]=i.useState(()=>w.get("tab")==="attendance"?"attendance":"roster"),[k,T]=i.useState(null),[u,G]=i.useState([]),[S,V]=i.useState(null),[W,B]=i.useState(!0),[Z,g]=i.useState([]),[h,_]=i.useState(null);i.useEffect(()=>{C.listSections().then(P=>{const f=Array.isArray(P)?P:[];g(f),f.length>0&&!h&&_(f[0].id)}).catch(()=>p(me("your sections")))},[]),i.useEffect(()=>{h&&X()},[h]),yt(()=>X());async function X(){B(!0);try{const P=await C.getRoster(null,h);V(P.section),T(P.members),G(P.instrumentGroups||[])}catch{p(me("section roster"))}finally{B(!1)}}const v=oe(P=>P.currentOrg?.trackPerformanceAttendance!==!1||P.currentOrg?.trackRehearsalAttendance!==!1),re=oe(P=>P.currentOrg?.trackRehearsalRsvps!==!1),Y=v||re,{can:U}=st(),K=!!U("folders:custody"),I=[{key:"roster",label:"Roster"},...K?[{key:"folders",label:"Folders"}]:[],...Y?[{key:"attendance",label:v?"Attendance":"Availability"}]:[],{key:"communicate",label:"Communicate"}];return $?e.jsx(Ft,{}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900",children:S?.name||"My Section"}),e.jsxs("p",{className:"text-sm text-gray-400",children:[k?.length||0," members"]})]}),e.jsxs("a",{...it("/app/guides/section-leader-guide.pdf","Section leader guide"),className:"shrink-0 inline-flex items-center gap-1.5 text-xs text-brand-primary hover:underline mt-1.5",title:"Download the section leader quick guide (PDF)",children:[e.jsx("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),"Quick guide (PDF)"]})]}),Z.length>1&&e.jsx("div",{className:"flex gap-2 mb-3 overflow-x-auto",children:Z.map(P=>e.jsxs("button",{type:"button",onClick:()=>{_(P.id),E("roster")},onMouseDown:f=>f.preventDefault(),className:`shrink-0 px-4 py-1.5 rounded-lg text-sm font-medium transition-all ${h===P.id?"bg-brand-primary text-white shadow":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[P.name,e.jsxs("span",{className:"ml-1.5 text-xs opacity-70",children:["(",P.memberCount,")"]})]},P.id))}),e.jsx(Qe,{className:"mb-4",ariaLabel:"Section views",preserveFocus:!0,tabs:I,value:N,onChange:E}),W?e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((P,f)=>e.jsx("div",{className:"bg-white rounded-xl border border-gray-200 p-4 animate-pulse h-16"},f))}):e.jsxs(e.Fragment,{children:[N==="roster"&&e.jsx(Gt,{roster:k,section:S,onReload:X,setRoster:T,instrumentGroups:u}),N==="folders"&&K&&e.jsx(mt,{sectionId:h}),N==="attendance"&&Y&&e.jsx(Yt,{roster:k,ensembleId:S?.ensembleId}),N==="communicate"&&e.jsx(Vt,{sectionName:S?.name,memberCount:k?.length,ensembleId:S?.ensembleId,roster:k})]})]})}function Ut(d){const p=["th","st","nd","rd"],$=d%100;return d+(p[($-20)%10]||p[$]||p[0])}function Gt({roster:d,section:p,onReload:$,setRoster:w,instrumentGroups:N}){const{showSuccess:E,showError:k}=je(),T=oe(r=>r.currentOrg?.id),[u,G]=i.useState([]),[S,V]=i.useState(""),W=ut({sectionLeader:!0});function B(r,b){const x=M(U,r);W.ask({performanceId:S,memberId:r,memberName:x?[x.firstName,x.lastName].filter(
1Boolean).join(" "):"This member",concertTitle:u.find(m=>m.id===S)?.title||"",reason:b||void 0})}const[Z,g]=i.useState(null),[h,_]=i.useState(!1),[X,v]=i.useState(!1),[re,Y]=i.useState(null),[U,K]=i.useState(N||[]),[I,P]=i.useState(null),[f,L]=i.useState(null),[O,R]=i.useState(null),[ne,ee]=i.useState(null),[le,ce]=i.useState(null),[fe,q]=i.useState(""),[Q,l]=i.useState(null);i.useEffect(()=>{K(N||[])},[N]);async function n(){if(S)try{const[r,b]=await Promise.all([C.getRoster(S),C.getPerformanceRoster(S)]);K(r.instrumentGroups||[]),Y(r.carryForwardFrom||null),g(b.performers||[])}catch{k(me("section seating"))}}function y(r,b){if(!S)return null;const x={...r,instrumentId:b.instrumentId,instrumentName:b.instrumentName};return e.jsx(dt,{member:x,onChange:()=>l(x)})}i.useEffect(()=>{const r=()=>{L(null),R(null)};return document.addEventListener("dragend",r),()=>document.removeEventListener("dragend",r)},[]),i.useEffect(()=>{!T||!p?.ensembleId||Ce.list(T,{ensembleId:p.ensembleId}).then(r=>{const b=Array.isArray(r)?r:r?.performances||[],x=Ue(),m=b.filter(z=>z.performanceDate>=x).sort((z,ie)=>z.performanceDate.localeCompare(ie.performanceDate));G(m),m.length>0&&V(z=>z||m[0].id)}).catch(()=>k(me("performances")))},[T,p?.ensembleId]),i.useEffect(()=>{if(!S){g(null),K(N||[]),Y(null);return}C.getRoster(S).then(r=>{K(r.instrumentGroups||[]),Y(r.carryForwardFrom||null)}).catch(()=>k(me("section seating"))),C.getPerformanceRoster(S).then(r=>g(r.performers||[])).catch(()=>g([]))},[S,N]);async function s(){_(!0);try{const r=await C.importDefaultToPerformance(S);E(`Chair order imported (${r.updated} updated)`);const[b,x]=await Promise.all([C.getRoster(S),C.getPerformanceRoster(S)]);K(b.instrumentGroups||[]),Y(b.carryForwardFrom||null),g(x.performers||[])}catch(r){k(r.message||"Import failed")}finally{_(!1)}}const a=i.useRef(null);function c(r,b,x){const m={memberId:r,instrumentId:b,fromSlot:x};a.current=m,L(m)}function t(){a.current=null,L(null),R(null)}const o=vt({getLabel:r=>{for(const b of U||[]){const m=[...(b.slots||[]).flatMap(z=>z.members||[]),...b.subs||[],...b.unavailable||[],...b.performing||[]].find(z=>z.id===r);if(m)return[m.firstName,m.lastName].filter(Boolean).join(" ")}return""},hint:"Tap a chair or sub to place.",onCancel(){a.current=null,L(null)},onDrop(r,b){const x=a.current;if(a.current=null,L(null),R(null),ee(null),!x)return;const[m,z,ie]=b.split("|");if(z!==x.instrumentId)return;const he={preventDefault(){}};if(m==="slot")ae(he,Number(ie),z);else if(m==="sub")se(he,z);else if(m==="unavailable")J(he,z);else if(m==="performing")D(he,z);else if(m==="seat"){const[pe,ke]=(ie||"").split(":"),Se=Number(pe),ye=Number(ke);if(!Number.isFinite(Se)||!Number.isFinite(ye))return;H(r,z,x.fromSlot,Se,ye)}}});function j(r,b,x){return o.sourceProps(r,{onStart:()=>c(r,b,x)})}function A(r,b,x){K(m=>m.map(z=>{if(z.instrumentId!==b)return z;const ie=z.unavailable||[],he=z.performing||[];let pe=null;for(const te of z.slots){const ge=te.members.find(ve=>ve.id===r);if(ge){pe=ge;break}}if(pe||(pe=z.subs.find(te=>te.id===r)),pe||(pe=ie.find(te=>te.id===r)),pe||(pe=he.find(te=>te.id===r)),!pe)return z;const ke=z.slots.map(te=>({...te,members:te.members.filter(ge=>ge.id!==r)})),Se=z.subs.filter(te=>te.id!==r),ye=ie.filter(te=>te.id!==r),Pe=he.filter(te=>te.id!==r),ue=(te,ge)=>te.lastName.localeCompare(ge.lastName);if(x.type==="slot"){const te={...pe,chairNumber:x.partNumber,isSub:!1,performanceStatus:"performing"},ge=ke.find(ve=>ve.partNumber===x.partNumber);ge&&(ge.members=[...ge.members,te])}else x.type==="performing"?(Pe.push({...pe,chairNumber:null,isSub:!1,performanceStatus:"performing"}),Pe.sort(ue)):x.type==="unavailable"?(ye.push({...pe,chairNumber:null,isSub:!1,performanceStatus:"unavailable"}),ye.sort(ue)):(Se.push({...pe,chairNumber:null,isSub:!0,performanceStatus:"sub"}),Se.sort(ue));return{...z,slots:ke,subs:Se,unavailable:ye,performing:Pe}}))}function M(r,b){for(const x of r||[]){for(const m of x.slots||[]){const z=(m.members||[]).find(ie=>ie.id===b);if(z)return z}for(const m of x.subs||[])if(m.id===b)return m;for(const m of x.unavailable||[])if(m.id===b)return m;for(const m of x.performing||[])if(m.id===b)return m}return null}async function ae(r,b,x){r.preventDefault();const m=ne;if(R(null),ee(null),!f||f.instrumentId!==x)return;const{memberId:z,fromSlot:ie}=f;if(L(null),m?.partNumber===b){H(z,x,ie,b,m.index);return}A(z,x,{type:"slot",partNumber:b});try{const he=[{memberId:z,chairNumber:b,isSub:!1}];S?await C.updatePerformanceChairOrder(S,he):await C.updateChairOrder(he)}catch{k("Failed to save order")}}async function H(r,b,x,m,z){const he=U.find(ue=>ue.instrumentId===b)?.slots?.find(ue=>ue.partNumber===m);if(!he)return;const ke=(he.members||[]).map(ue=>ue.id).filter(ue=>ue!==r),Se=Math.max(0,Math.min(z,ke.length)),ye=[...ke.slice(0,Se),r,...ke.slice(Se)],Pe=U;K(ue=>ue.map(te=>{if(te.instrumentId!==b)return te;const ge=te.unavailable||[];let ve=null;const Ae=te.slots.map(be=>{const Re=be.members.find(Te=>Te.id===r);return Re&&!ve&&(ve=Re),{...be,members:be.members.filter(Te=>Te.id!==r)}}),ft=te.subs.filter(be=>be.id!==r),ht=ge.filter(be=>be.id!==r);if(ve||(ve=te.subs.find(be=>be.id===r)||ge.find(be=>be.id===r)),ve){const be=Ae.findIndex(Re=>Re.partNumber===m);if(be>=0){const Re={...ve,chairNumber:m,isSub:!1,performanceStatus:"performing"},Te=new Map(Ae[be].members.map(Fe=>[Fe.id,Fe]));Te.set(r,Re),Ae[be]={...Ae[be],members:ye.map(Fe=>
1Te.get(Fe)).filter(Boolean)}}}return{...te,slots:Ae,subs:ft,unavailable:ht}}));try{if(x!==m){const ue=[{memberId:r,chairNumber:m,isSub:!1}];S?await C.updatePerformanceChairOrder(S,ue):await C.updateChairOrder(ue)}S?await C.reorderPerformanceSeats(S,m,ye):await C.reorderSeats(m,ye)}catch(ue){K(Pe),k(ue?.message||"Failed to move to seat")}}async function se(r,b){if(r.preventDefault(),R(null),!f||f.instrumentId!==b)return;const{memberId:x}=f;L(null),A(x,b,{type:"sub"});try{if(U.find(m=>m.instrumentId===b)?.chairless)S&&await C.toggleStandby(S,x,"sub");else{const m=[{memberId:x,chairNumber:null,isSub:!0}];S?await C.updatePerformanceChairOrder(S,m):await C.updateChairOrder(m)}}catch{k("Failed to save")}}async function D(r,b){if(r.preventDefault(),R(null),!f||f.instrumentId!==b)return;const{memberId:x}=f;if(L(null),!!S){A(x,b,{type:"performing"});try{await C.toggleStandby(S,x,"performing")}catch{k("Failed to save")}}}async function J(r,b){if(r.preventDefault(),R(null),!f||f.instrumentId!==b)return;const{memberId:x,fromSlot:m}=f;if(m!=="sub"&&m!=="unavailable"){const z=M(U,x);if(z?.chairNumber){L(null),ce({memberId:x,instrumentId:b,member:z});return}}if(L(null),S){A(x,b,{type:"unavailable"});try{await C.updatePerformanceChairOrder(S,[{memberId:x,chairNumber:null,isUnavailable:!0}]),m!=="unavailable"&&B(x)}catch{k("Failed to save")}}}async function de(r,b,x){if(S){A(r,b,{type:"unavailable"});try{await C.updatePerformanceChairOrder(S,[{memberId:r,chairNumber:null,isUnavailable:!0,reason:x||void 0}]),B(r,x)}catch{k("Failed to save")}}}i.useEffect(()=>{U.length>0&&(!I||!U.find(r=>r.instrumentId===I))&&P(U[0].instrumentId)},[U]);const F=U.find(r=>r.instrumentId===I)||U[0],xe=()=>e.jsxs("svg",{className:"h-4 w-4 text-gray-400",fill:"currentColor",viewBox:"0 0 20 20",children:[e.jsx("circle",{cx:"7",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"7",cy:"10",r:"1.5"}),e.jsx("circle",{cx:"7",cy:"15",r:"1.5"}),e.jsx("circle",{cx:"13",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"13",cy:"10",r:"1.5"}),e.jsx("circle",{cx:"13",cy:"15",r:"1.5"})]});return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"bg-gray-50 rounded-xl border border-gray-200 p-3",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:u.length>0?"Showing performance chairs":"No upcoming performances"}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsxs("select",{value:S,onChange:r=>V(r.target.value),disabled:u.length===0,className:"flex-1 min-w-[200px] rounded-md border border-gray-300 px-3 py-1.5 text-sm focus:outline-none focus:ring-2 focus:ring-brand-primary disabled:opacity-60",children:[u.length===0&&e.jsx("option",{value:"",children:"No upcoming performances"}),u.map(r=>e.jsxs("option",{value:r.id,children:[we(r.performanceDate)," — ",r.title]},r.id))]}),S&&!re&&e.jsx($e,{variant:"secondary",size:"sm",onClick:s,disabled:h,className:"!text-xs",isLoading:h,children:"Import defaults"})]})]}),U.length>0&&e.jsx("div",{className:"border-b border-gray-200",children:e.jsx("div",{className:"flex flex-wrap gap-0",children:U.map(r=>{const b=r.instrumentId===I,x=r.chairless?(r.performing||[]).length:r.slots.reduce((z,ie)=>z+ie.members.length,0),m=x+r.subs.length;return e.jsxs("button",{type:"button",onClick:()=>P(r.instrumentId),onMouseDown:z=>z.preventDefault(),className:`px-3 py-1.5 text-sm font-medium border-b-2 transition-colors whitespace-nowrap ${b?"border-brand-primary text-brand-primary":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[r.instrumentName,e.jsxs("span",{className:`ml-1.5 text-xs ${b?"text-brand-primary":"text-gray-400"}`,children:[x,"/",m]})]},r.instrumentId)})})}),F&&e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("h4",{className:"text-sm font-semibold text-gray-700 mb-3 flex items-center gap-2",children:[F.instrumentName,F.chairless?e.jsx("span",{className:"text-xs font-normal text-gray-400",children:"(no chairs — percussion)"}):e.jsxs("span",{className:"text-xs font-normal text-gray-400",children:["(",F.maxParts," ",F.maxParts===1?"part":"parts",")"]})]}),F.chairless?e.jsxs("div",{...o.zoneProps(`performing|${F.instrumentId}`),className:`px-3 py-2 rounded-lg border-2 transition-colors ${O==="performing"||o.activeZone===`performing|${F.instrumentId}`?"border-brand-primary bg-blue-50":`border-gray-100 bg-gray-50 ${(F.performing||[]).length===0?"border-dashed":""}`}`,onDragOver:r=>{r.preventDefault(),R("performing")},onDragLeave:()=>R(null),onDrop:r=>D(r,F.instrumentId),children:[e.jsxs("p",{className:"text-[10px] font-semibold text-gray-500 uppercase tracking-wider mb-1 inline-flex items-center gap-1",children:["Playing this concert",e.jsx(Ze,{title:"Percussion is covered by station rather than by numbered chair, so there are no parts to assign here — just who is playing."})]}),(F.performing||[]).length===0&&e.jsxs("p",{className:"text-xs text-gray-400 italic py-1",children:[o.tapMode?"Tap here":"Drag a member here"," to put them on this concert"]}),e.jsx("div",{className:"space-y-0.5",children:(F.performing||[]).map(r=>e.jsxs("div",{draggable:!o.tapMode,onDragStart:()=>c(r.id,F.instrumentId,"performing"),onDragEnd:t,className:`flex items-center gap-2 px-2 py-1.5 rounded text-sm cursor-grab transition-colors hover:bg-gray-50 ${o.tapMode&&o.activeSource===r.id?"ring-2 ring-band-500 bg-band-50":f?.memberId===r.id||o.activeSource===r.id?"opacity-40":""}`,children:[e.jsx("span",{...j(r.id,F.instrumentId,"performing"),className:"shrink-0 touch-none p-2 -m-2 leading-none cursor-grab",children:e.jsx(xe,{})}),e.jsx(De,{src:r.photoUrl,firstName:r.firstName,lastName:r.lastName,size:"sm"}),e.jsxs("span",{className:"font-medium text-gray-800",children:[r.firstName," ",r.lastName]}),r.instrumentSource==="manual"&&e.jsx(ze,{}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[r.attendanceRate!==null&&e.jsxs("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold ${Le(r.attendanceRate)}`,children:[r.attendanceRate,"% attendance"]}),r.lastPerformanceDate&&e.jsxs("span",{className:"text-[10px] text-gray-400 whitespace-nowrap",children:["last performance ",we(r.lastPerformanceDate)]}),y(r,F)]})]},r.id))})]}):e.jsx("div",{className:"space-y-1.5",children:F.slots.map(r=>{const b=O===r.partNumber,x=r.members||[];return e.jsxs("div",{...o.zoneProps(`slot|${F.instrumentId}|${r.partNumber}`),className:`px-3 py-2 rounded-lg border-2 transition-colors ${b||o.activeZone===`slot|${F.instrumentId}|${r.partNumber}`?"border-brand-primary bg-blue-50":"border-gray-100 bg-gray-50"} ${x.length===0&&!b?"border-dashed":""}`,onDragOver:m=>{m.preventDefault(),R(r.partNumber)},onDragLeave:()=>R(null),onDrop:m=>ae(m,r.partNumber,F.instrumentId),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-xs font-bold text-gray-400 w-8 shrink-0",children:Ut(r.partNumber)}),x.length===0&&e.jsx("span",{className:"text-xs text-gray-300 italic",children:"Empty"})]}),x.length>0&&e.jsx("div",{className:"space-y-0.5 pl-10",children:x.map((m,z)=>(f?.instrumentId===F.instrumentId&&(x[0]?.chairNumber,r.partNumber),e.jsxs("div",{...o.zoneProps(`seat|${F.instrumentId}|${r.partNumber}:${z}`),draggable:!o.tapMode,onDragStart:()=>c(m.id,F.instrumentId,r.partNumber),onDragOver:ie=>{f&&f.instrumentId===F.instrumentId&&(ie.preventDefault(),ie.stopPropagation(),ee({partNumber:r.partNumber,index:z}))},onDrop:ie=>{!f||f.instrumentId!==F.instrumentId||(ie.preventDefault(),ie.stopPropagation(),ee(null),H(f.memberId,F.instrumentId,f.fromSlot,r.partNumber,z),L(null))},onDragEnd:()=>{t(),ee(null)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-sm cursor-grab transition-colors hover:bg-gray-50 ${o.tapMode&&o.activeSource===m.id?"ring-2 ring-band-500 bg-band-50":f?.memberId===m.id||o.activeSource===m.id?"opacity-40":""} ${ne?.partNumber===r.partNumber&&ne?.index===z||o.activeZone===`seat|${F.instrumentId}|${r.partNumber}:${z}`?"border-t-2 border-brand-primary":""}`,children:[e.jsx("span",{...j(m.id,F.instrumentId,r.partNumber),className:"shrink-0 touch-none p-2 -m-2 leading-none cursor-grab",children:e.jsx(xe,{})}),e.jsx("span",{className:"text-xs text-gray-400 w-4 shrink-0 text-center",children:z+1}),e.jsx(De,{src:m.photoUrl,firstName:m.firstName,lastName:m.lastName,size:"sm"}),e.jsxs("span",{className:"font-medium text-gray-800",children:[m.firstName," ",m.lastName]}),m.instrumentSource==="manual"&&e.jsx(ze,{}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[m.attendanceRate!==null&&e.jsxs("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold ${Le(m.attendanceRate)}`,children:[m.attendanceRate,"% attendance"]}),m.lastPerformanceDate&&e.jsxs("span",{className:"text-[10px] text-gray-400 whitespace-nowrap",children:["last performance ",we(m.lastPerformanceDate)]}),y(m,F)]})]},m.id)))})]},r.partNumber)})}),(F.subs.length>0||S)&&e.jsxs("div",{...o.zoneProps(`sub|${F.instrumentId}`),className:`border-t border-gray-100 pt-2 mt-3 ${O==="sub"||o.activeZone===`sub|${F.instrumentId}`?"bg-amber-50 rounded-lg":""}`,onDragOver:r=>{r.preventDefault(),R("sub")},onDragLeave:()=>R(null),onDrop:r=>se(r,F.instrumentId),children:[e.jsxs("p",{className:"text-[10px] font-semibold text-amber-500 uppercase tracking-wider mb-1 inline-flex items-center gap-1",children:["Subs",e.jsx(Ze,{variant:"amber",title:"In the section but sitting out this concert — available to step in if someone cancels last-minute."})]}),F.subs.length===0&&e.jsxs("p",{className:"text-xs text-gray-400 italic py-1",children:[o.tapMode?"Tap here":"Drag a member here"," to move to subs"]}),e.jsx("div",{className:"space-y-0.5",children:F.subs.map(r=>e.jsxs("div",{draggable:!o.tapMode,onDragStart:()=>c(r.id,F.instrumentId,"sub"),onDragEnd:t,className:`flex items-center gap-2 px-2 py-1.5 rounded text-sm cursor-grab transition-colors bg-amber-50 hover:bg-amber-100 ${o.tapMode&&o.activeSource===r.id?"ring-2 ring-band-500 bg-band-50":f?.memberId===r.id||o.activeSource===r.id?"opacity-40":""}`,children:[e.jsx("span",{...j(r.id,F.instrumentId,"sub"),className:"shrink-0 touch-none p-2 -m-2 leading-none cursor-grab",children:e.jsx(xe,{})}),e.jsx(De,{src:r.photoUrl,firstName:r.firstName,lastName:r.lastName,size:"sm"}),e.jsxs("span",{className:"font-medium text-amber-800",children:[r.firstName," ",r.lastName]}),r.instrumentSource==="manual"&&e.jsx(ze,{}),e.jsxs("div",{className:"ml-auto flex items-center gap-3",children:[r.attendanceRate!==null&&e.jsxs("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold ${Le(r.attendanceRate)}`,children:[r.attendanceRate,"% attendance"]}),r.lastPerformanceDate&&e.jsxs("span",{className:"text-[10px] text-gray-400 whitespace-nowrap",children:["last performance ",we(r.lastPerformanceDate)]}),y(r,F)]})]},r.id))})]}),S&&e.jsxs("div",{...o.zoneProps(`unavailable|${F.instrumentId}`),className:`border-t border-gray-100 pt-2 mt-3 ${O==="unavailable"||o.activeZone===`unavailable|${F.instrumentId}`?"bg-slate-100 rounded-lg":""}`,onDragOver:r=>{r.preventDefault(),R("unavailable")},onDragLeave:()=>R(null),onDrop:r=>J(r,F.instrumentId),children:[e.jsxs("p",{className:"text-[10px] font-semibold text-slate-500 uppercase tracking-wider mb-1 inline-flex items-center gap-1",children:["Unavailable",e.jsx(Ze,{variant:"slate",title:"Can't perform this concert or season — removed from the program and excluded from attendance tracking."})]}),(F.unavailable||[]).length===0&&e.jsxs("p",{className:"text-xs text-gray-400 italic py-1",children:[o.tapMode?"Tap here":"Drag a member here"," when they've declared out for this concert"]}),e.jsx("div",{className:"space-y-0.5",children:(F.unavailable||[]).map(r=>e.jsxs("div",{draggable:!o.tapMode,onDragStart:()=>c(r.id,F.instrumentId,"unavailable"),onDragEnd:t,className:`flex items-center gap-2 px-2 py-1.5 rounded text-sm cursor-grab transition-colors hover:bg-slate-100 ${o.tapMode&&o.activeSource===r.id?"ring-2 ring-band-500 bg-band-50":f?.memberId===r.id||o.activeSource===r.id?"opacity-40":""}`,children:[e.jsx("span",{...j(r.id,F.instrumentId,"unavailable"),className:"shrink-0 touch-none p-2 -m-2 leading-none cursor-grab",children:e.jsx(xe,{})}),e.jsx(De,{src:r.photoUrl,firstName:r.firstName,lastName:r.lastName,size:"sm"}),e.jsxs("span",{className:"font-medium text-slate-500 line-through",children:[r.firstName," ",r.lastName]}),r.instrumentSource==="manual"&&e.jsx(ze,{}),r.unavailableReason&&e.jsxs("span",{className:"text-xs text-slate-400 italic truncate",title:r.unavailableReason,children:["— ",r.unavailableReason]}),e.jsx("div",{className:"ml-auto flex items-center",children:y(r,F)})]},r.id))})]})]}),e.jsx(ct,{isOpen:!!Q,onClose:()=>l(null),performanceId:S,member:Q,ensembleId:p?.ensembleId||null,canManage:!1,sectionInstrumentIds:U.map(r=>r.instrumentId),onSaved:r=>{r?.instrumentId&&P(r.instrumentId),n(),$?.()}}),W.element,e.jsx(Dt,{isOpen:!!le,title:"Mark as Unavailable?",message:le?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{children:`${le.member?.firstName} ${le.member?.lastName} is currently in chair ${le.member?.chairNumber}. Marking them unavailable will remove their chair assignment and exclude them from attendance for this concert.`}),e.jsx(Ke,{label:"Reason (optional)",value:fe,onChange:r=>q(r.target.value),placeholder:"e.g. Out of town, surgery recovery",maxLength:500})]}):"",confirmLabel:"Mark Unavailable",confirmVariant:"danger",cancelLabel:"Keep Assigned",onConfirm:()=>{le&&(de(le.memberId,le.instrumentId,fe.trim()),ce(null),q(""))},onClose:()=>{ce(null),q("")}})]})}function Yt({roster:d,ensembleId:p}){const $=ut({sectionLeader:!0}),w=oe(t=>t.currentOrg?.trackRehearsalAttendance!==!1),{showError:N}=je(),E=oe(t=>t.currentOrg?.id),k=oe(t=>t.currentOrg?.trackPerformanceAttendance!==!1),T=oe(t=>t.currentOrg?.trackRehearsalAttendance!==!1),u=oe(t=>t.currentOrg?.trackRehearsalRsvps!==!1),G=!k&&!T&&u,S=oe(t=>t.currentOrg?.trackPerformanceRsvps!==!1),[V,W]=i.useState("take"),[B,Z]=i.useState([]),[g,h]=i.useState(null),_=i.useRef(!1),[X,v]=_e(),[re,Y]=i.useState({}),[U,K]=i.useState(null);i.useEffect(()=>{E&&Promise.all([k||S?Ce.list(E,{ensembleId:p}).catch(()=>[]):Promise.resolve([]),T||G?Ce.rehearsals(E,{ensembleId:p}).catch(()=>[]):Promise.resolve([])]).then(([t,o])=>{const j=(Array.isArray(t)?t:t?.performances||[]).map(b=>({id:b.id,type:"performance",label:b.title,date:b.performanceDate})),A=(Array.isArray(o)?o:[]).map(b=>({id:b.id,type:"rehearsal",label:`Rehearsal — ${b.performanceTitle||"TBD"}`,date:b.rehearsalDate})),M=new Date,ae=new Date(M);ae.setDate(M.getDate()-30);const H=He(ae),se=new Date(M);se.setDate(M.getDate()+70);const D=He(se),J=new Date,de=`${J.getFullYear()}
1-${String(J.getMonth()+1).padStart(2,"0")}-${String(J.getDate()).padStart(2,"0")}`,F=G?de:H,xe=[...j.filter(b=>b.date>=(k?H:de)&&b.date<=D),...A.filter(b=>b.date>=F&&b.date<=D)].sort((b,x)=>(b.date||"").localeCompare(x.date||""));Z(xe);const r=X.get("eventId");if(r){const b=X.get("eventType"),x=xe.find(m=>m.id===r&&(!b||m.type===b));X.delete("eventId"),X.delete("eventType"),X.delete("tab"),v(X,{replace:!0}),x&&(h(x),_.current=!0)}if(!_.current){const b=new Date,x=`${b.getFullYear()}-${String(b.getMonth()+1).padStart(2,"0")}-${String(b.getDate()).padStart(2,"0")}`,m=xe.find(z=>z.date>=x)||xe[xe.length-1];m&&(_.current=!0,h(m))}})},[E,p,k,T,G,S]);const[I,P]=i.useState(90);i.useEffect(()=>{V==="history"&&!U&&C.getAttendance().then(t=>{K(t.events||[]),P(t.windowDays||90)}).catch(()=>N(me("attendance history")))},[V]);const f=(()=>{const t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`})(),L=g?.type==="rehearsal"&&(g.date>f||!w&&g.date>=f),O=g?.type==="performance"&&g.date>f,R=L||O,[ne,ee]=i.useState({}),[le,ce]=i.useState(null),[fe,q]=i.useState({}),[Q,l]=i.useState({});i.useEffect(()=>{if(!g){Y({}),q({}),ee({}),ce(null),l({});return}let t=!1;return R?(ee({}),ce(null),(g.type==="performance"?C.getPerformanceAvailability(g.id):C.getRehearsalAvailability(g.id)).then(j=>{if(t)return;const A={};for(const M of j?.rsvps||[])A[M.memberId]={response:M.response,reason:M.reason};ee(M=>({...A,...M})),l(j?.seats||{})}).catch(()=>N(me("availability"))),()=>{t=!0}):(ot.getEventAttendance(g.id,g.type).then(o=>{if(t||!o?.sections)return;const j={},A={},M={};for(const ae of o.sections)for(const H of ae.members)H.status&&H.status!=="unmarked"&&(j[H.memberId]=H.status),H.fromRsvp?A[H.memberId]="said can't make it":H.fromRoster&&(A[H.memberId]=H.expect==="out"?"out for the concert":"standby"),M[H.memberId]={partNumber:H.partNumber??null,seatPosition:H.seatPosition??null,rosterStatus:H.rosterStatus??null,rosterReason:H.rosterReason??null};Y(ae=>({...j,...ae})),q(A),l(M)}).catch(()=>N(me("attendance"))),()=>{t=!0})},[g]);async function n(t,o){if(!g){N("Select an event first");return}const j=re[t]||"unmarked";Y(A=>({...A,[t]:o}));try{await C.recordAttendance(g.id,g.type,[{memberId:t,status:o}])}catch(A){Y(M=>M[t]===o?{...M,[t]:j}:M),N(A.message||Ne)}}function y(t){const o=Q[t.id];return o&&(o.partNumber!=null||o.rosterStatus)?o:{chairNumber:t.chairNumber??null,seatPosition:t.seatPosition??null}}function s(t){return t.map(o=>{const j=y(o);return{...o,chairNumber:j.partNumber??j.chairNumber??null,seatPosition:j.seatPosition??null}})}async function a(t){const o=ne[t],j=o?.response==="not_attending",A=j?"attending":"not_attending";ee(M=>({...M,[t]:{response:A,reason:j?null:M[t]?.reason||null}}));try{if(await(g.type==="performance"?C.recordPerformanceAvailability(g.id,t,A):C.recordRehearsalAvailability(g.id,t,A)),g.type==="performance"&&A==="not_attending"){const M=(d||[]).find(ae=>ae.id===t);$.ask({performanceId:g.id,memberId:t,memberName:M?[M.firstName,M.lastName].filter(Boolean).join(" "):"This member",concertTitle:g.label})}}catch(M){ee(ae=>({...ae,[t]:o})),N(M.message||Ne)}}async function c(t,o){const j=ne[t];ce(null),ee(A=>({...A,[t]:{response:"not_attending",reason:o||null}}));try{await(g.type==="performance"?C.recordPerformanceAvailability(g.id,t,"not_attending",o||null):C.recordRehearsalAvailability(g.id,t,"not_attending",o||null))}catch(A){ee(M=>({...M,[t]:j})),N(A.message||Ne)}}return e.jsxs("div",{children:[G&&e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Your band doesn’t track attendance, so there’s nothing to take here. Pick an upcoming rehearsal to record anyone who’s told you they can’t make it."}),e.jsxs("div",{className:`flex gap-2 mb-4 ${G?"hidden":""}`,children:[e.jsx("button",{type:"button",onClick:()=>W("take"),onMouseDown:t=>t.preventDefault(),className:`px-3 py-1.5 text-xs font-medium rounded-full ${V==="take"?"bg-brand-primary text-white":"bg-gray-100 text-gray-600"}`,children:"Take Attendance"}),e.jsx("button",{type:"button",onClick:()=>W("history"),onMouseDown:t=>t.preventDefault(),className:`px-3 py-1.5 text-xs font-medium rounded-full ${V==="history"?"bg-brand-primary text-white":"bg-gray-100 text-gray-600"}`,children:"History"})]}),V==="take"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("select",{value:g?`${g.type}:${g.id}`:"",onChange:t=>{if(!t.target.value){h(null);return}const[o,j]=t.target.value.split(":"),A=B.find(M=>M.id===j&&M.type===o);h(A||null),Y({})},className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-primary",children:[e.jsx("option",{value:"",children:"Select event…"}),B.map(t=>e.jsxs("option",{value:`${t.type}:${t.id}`,children:[t.date," — ",t.label]},`${t.type}:${t.id}`))]}),g&&R&&e.jsx("p",{className:"text-xs text-gray-600 bg-amber-50 border border-amber-200 rounded-lg p-3",children:O?e.jsx(e.Fragment,{children:"This concert is coming up. Mark anyone who’s told you they can’t play — their chair opens up, and they’ll show as out on the roster and in the leadership digest. Their own link can reverse it any time."}):e.jsx(e.Fragment,{children:"This rehearsal is coming up. Mark anyone who’s told you they can’t make it — they’ll show as out on the stage map and in the leadership digest, and their attendance will be excused automatically that day."})}),g&&R&&s([...d||[]]).sort(Be).map(t=>{const o=ne[t.id],j=o?.response==="not_attending",A=y(t).rosterStatus==="unavailable";return e.jsxs("div",{className:`w-full bg-white rounded-xl border p-3 ${j?"border-red-200 bg-red-50":"border-gray-200"} ${A?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(De,{src:t.photoUrl,firstName:t.firstName,lastName:t.lastName,size:"sm"}),e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsxs("span",{className:"block text-sm font-medium text-gray-900",children:[t.firstName," ",t.lastName]}),Ie(t.instrument,y(t))&&e.jsx("span",{className:"block text-xs text-gray-400",children:Ie(t.instrument,y(t))})]}),e.jsx("div",{className:"ml-auto shrink-0",children:e.jsx($e,{type:"button",size:"sm",variant:j?"danger":"secondary",onClick:()=>a(t.id),children:j?"Out — undo":"Mark out"})})]}),j&&(le===t.id?e.jsx(Ke,{autoFocus:!0,defaultValue:o?.reason||"",placeholder:"Reason (optional) — e.g. vacation",onBlur:M=>c(t.id,M.target.value.trim()),onKeyDown:M=>{M.key==="Enter"&&M.target.blur()},className:"mt-2"}):e.jsx("button",{type:"button",onClick:()=>ce(t.id),className:"mt-1.5 text-xs text-left",children:o?.reason?e.jsxs("span",{className:"text-gray-600",children:["“",o.reason,"” ",e.jsx("span",{className:"text-brand-primary font-medium",children:"edit"})]}):e.jsx("span",{className:"text-brand-primary font-medium",children:"+ add reason"})}))]},t.id)}),g&&!R&&(d||[]).length>0&&e.jsx("p",{className:"text-sm text-gray-500",children:"Click Present, Absent or Excused beside each name. Click it again to clear it. Each click saves on its own."}),g&&!R&&s([...d||[]]).sort(Be).map(t=>{const o=re[t.id]||"unmarked",j=y(t).rosterStatus==="unavailable";return e.jsxs("div",{className:`w-full flex flex-wrap items-center gap-3 bg-white rounded-xl border border-gray-200 p-3 min-h-[52px] ${j?"opacity-50":""}`,children:[e.jsx(De,{src:t.photoUrl,firstName:t.firstName,lastName:t.lastName,size:"sm"}),e.jsxs("div",{className:"min-w-[16rem] text-left",children:[e.jsxs("span",{className:"block text-sm font-medium text-gray-900",children:[t.firstName," ",t.lastName,fe[t.id]&&o==="excused"&&e.jsx("span",{className:"ml-2 text-[10px] font-semibold text-amber-700 bg-amber-50 border border-amber-200 rounded-full px-2 py-0.5 whitespace-nowrap align-middle",children:fe[t.id]})]}),Ie(t.instrument,y(t))&&e.jsx("span",{className:"block text-xs text-gray-400",children:Ie(t.instrument,y(t))})]}),e.jsx(bt,{className:"ml-auto",name:`${t.firstName} ${t.lastName}`,value:o,onChange:A=>n(t.id,A)})]},t.id)}),g&&e.jsx("p",{className:"text-xs text-gray-400 text-center",children:"Changes save automatically as you click."}),g&&R&&Object.values(ne).some(t=>t?.response==="not_attending")&&e.jsxs("p",{className:"text-xs text-gray-400 text-center",children:[Object.values(ne).filter(t=>t?.response==="not_attending").length," marked out for this rehearsal."]})]}),V==="history"&&e.jsx("div",{children:U?U.length===0?e.jsxs("p",{className:"text-sm text-gray-500",children:["Nothing on the calendar in the last ",I," days."]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto -mx-4 px-4",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-gray-400 uppercase tracking-wide border-b border-gray-100",children:[e.jsx("th",{className:"pb-2 pr-3 font-semibold sticky left-0 bg-white",children:"Member"}),U.map(t=>e.jsxs("th",{className:`pb-2 px-1.5 text-center font-semibold whitespace-nowrap ${t.taken===!1?"text-gray-300":""}`,title:`${t.title}${t.taken===!1?" — attendance not taken":""}`,children:[e.jsx("span",{className:`block mx-auto mb-0.5 w-4 h-4 rounded-full text-[9px] font-bold leading-4 normal-case ${t.eventType==="performance"?"bg-teal-100 text-teal-700":"bg-gray-100 text-gray-500"}`,children:t.eventType==="performance"?"P":"R"}),_t(t.date)]},`${t.eventType}:${t.eventId}`)),e.jsxs("th",{className:"pb-2 pl-2 text-center font-semibold whitespace-nowrap",children:[I,"-day rate"]})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:[...d||[]].sort(Be).map(t=>e.jsxs("tr",{children:[e.jsxs("td",{className:"py-2 pr-3 text-gray-700 font-medium whitespace-nowrap sticky left-0 bg-white",children:[t.firstName," ",t.lastName]}),U.map(o=>{if(o.taken===!1)return e.jsx("td",{className:"py-2 px-1.5 text-center",children:e.jsx("span",{className:"inline-block w-6 h-6 rounded-full border border-dashed border-gray-200",title:"Attendance not taken"})},`${o.eventType}:${o.eventId}`);if(o.notExpected?.includes(t.id))return e.jsx("td",{className:"py-2 px-1.5 text-center",children:e.jsx("span",{className:"inline-block w-6 h-6 rounded-full text-[10px] leading-6 text-gray-300",title:"Not on that concert — not expected",children:"·"})},`${o.eventType}:${o.eventId}`);const j=o.records?.find(M=>M.memberId===t.id),A=j?.status||"unmarked";return e.jsx("td",{className:"py-2 px-1.5 text-center",children:e.jsx("span",{className:`inline-flex items-center justify-center w-6 h-6 rounded-full text-[10px] font-bold ${Lt[A]}`,title:j?.note||void 0,children:Ht[A]}
1)},`${o.eventType}:${o.eventId}`)}),e.jsx("td",{className:"py-2 pl-2 text-center",children:e.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold ${Le(t.attendanceRate)}`,children:t.attendanceRate!==null?`${t.attendanceRate}%`:"—"})})]},t.id))})]})}),e.jsxs("p",{className:"mt-2 text-[11px] text-gray-400",children:[e.jsx("span",{className:"inline-block align-middle w-3.5 h-3.5 rounded-full bg-teal-100 mr-1"}),"Performance",e.jsx("span",{className:"inline-block align-middle w-3.5 h-3.5 rounded-full bg-gray-100 ml-3 mr-1"}),"Rehearsal",e.jsx("span",{className:"inline-block align-middle w-3.5 h-3.5 rounded-full border border-dashed border-gray-300 ml-3 mr-1"}),"Attendance not taken",e.jsx("span",{className:"inline-block align-middle w-3.5 text-center text-gray-300 ml-3 mr-1",children:"·"}),"Not on that concert",e.jsxs("span",{className:"ml-3",children:["Last ",I," days, newest first — scroll for more."]})]})]}):e.jsx("p",{className:"text-sm text-gray-400",children:"Loading…"})}),$.element]})}function Vt({sectionName:d,memberCount:p,ensembleId:$,roster:w}){const{showSuccess:N,showError:E}=je(),k=oe(I=>I.currentOrg?.id),[T,u]=i.useState(""),[G,S]=i.useState(""),[V,W]=i.useState(!1),[B,Z]=i.useState(null),[g,h]=i.useState(!1),[_,X]=i.useState([]),[v,re]=i.useState(()=>new Set),Y=(w||[]).filter(I=>I.memberStatus==="active"&&I.emailAddress&&I.emailAddress.trim()).map(I=>({id:I.id,name:`${I.firstName||""} ${I.lastName||""}`.trim()||I.emailAddress})).sort((I,P)=>I.name.localeCompare(P.name));function U(I){re(P=>{const f=new Set(P);return f.has(I)?f.delete(I):f.add(I),f})}i.useEffect(()=>{!k||!$||Ce.list(k,{ensembleId:$}).then(I=>{const P=Array.isArray(I)?I:I?.performances||[],f=Ue();X(P.filter(L=>L.performanceDate>=f).sort((L,O)=>L.performanceDate.localeCompare(O.performanceDate)))}).catch(()=>E(me("performances")))},[k,$]);async function K(){if(!G.trim()){E("Enter a message");return}W(!0);try{const I=Array.from(v),P=I.length>0?[]:void 0,f=I.length>0?I:void 0,L=await C.notify(T.trim()||void 0,G.trim(),P,f),O=`Message sent to ${L.sent} member${L.sent!==1?"s":""}`;N(O),Z(O),u(""),S(""),re(new Set)}catch(I){E(I.message||"Failed to send")}finally{W(!1)}}return e.jsxs("div",{className:"space-y-4 max-w-lg",children:[e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-5",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Templates"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("button",{type:"button",onClick:()=>h(!0),className:"w-full text-left rounded-lg border border-gray-200 hover:border-brand-primary hover:bg-brand-primary/5 transition-colors p-3 flex items-start gap-3",children:[e.jsx("span",{className:"shrink-0 w-9 h-9 rounded-full bg-brand-primary/10 text-brand-primary flex items-center justify-center",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:"M8 7h12M8 12h12M8 17h12M3 7h.01M3 12h.01M3 17h.01"})})}),e.jsxs("span",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium text-gray-900",children:"Send Chair & Performance Details"}),e.jsx("span",{className:"block text-xs text-gray-500 mt-0.5",children:"Email every member their chair, the concert details, the first rehearsal, and your contact info."})]}),e.jsx("span",{className:"shrink-0 text-gray-400",children:"→"})]})})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-5 space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide",children:"Custom Message"}),B&&e.jsxs("div",{className:"bg-green-50 border border-green-200 rounded-lg p-3 flex items-center gap-2",children:[e.jsx("svg",{className:"h-4 w-4 text-green-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2.5,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M5 13l4 4L19 7"})}),e.jsx("span",{className:"text-sm text-green-700",children:B})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-xs text-gray-400",children:"To:"}),v.size>0?e.jsxs("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium bg-band-100 text-band-700",children:[v.size," selected member",v.size===1?"":"s"]}):e.jsxs("span",{className:"inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium bg-teal-100 text-teal-700",children:["All ",d||"section"," members (",p||0,")"]})]}),e.jsx(pt,{members:Y,picked:v,onToggle:U,onClear:()=>re(new Set)}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Subject"}),e.jsx(Ke,{value:T,onChange:I=>u(I.target.value),placeholder:"e.g. Bring your mutes Tuesday"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Message"}),e.jsx("textarea",{rows:4,value:G,onChange:I=>S(I.target.value),placeholder:"Type your message…",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-primary resize-none"})]}),e.jsx($e,{onClick:K,disabled:V||!G.trim(),children:V?"Sending…":v.size>0?`Send to ${v.size} member${v.size===1?"":"s"}`:"Send to Section"})]}),e.jsx(Zt,{isOpen:g,onClose:()=>h(!1),upcomingPerfs:_,sectionName:d,memberCount:p,eligibleMembers:Y})]})}function Zt({isOpen:d,onClose:p,upcomingPerfs:$,sectionName:w,memberCount:N,eligibleMembers:E}){const{showSuccess:k,showError:T}=je(),[u,G]=i.useState(""),[S,V]=i.useState(""),[W,B]=i.useState(!1),[Z,g]=i.useState(()=>new Set),h=Z.size>0?Z.size:E?.length??N??0;i.useEffect(()=>{d&&!u&&$.length>0&&G($[0].id)},[d,$]),i.useEffect(()=>{d||(G(""),V(""),g(new Set))},[d]);function _(v){g(re=>{const Y=new Set(re);return Y.has(v)?Y.delete(v):Y.add(v),Y})}async function X(){if(!u){T("Pick a performance");return}B(!0);try{const v=Z.size>0?Array.from(Z):void 0,re=await C.sendChairDetails(u,S.trim()||null,v);k(`Sent to ${re.sent} member${re.sent!==1?"s":""}`),p()}catch(v){T(v.message||"Could not send")}finally{B(!1)}}return e.jsx(nt,{isOpen:d,onClose:p,title:"Send Chair & Performance Details",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3 text-sm text-blue-900",children:[e.jsx("p",{className:"font-medium mb-1",children:"What's included"}),e.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-xs text-blue-800",children:[e.jsx("li",{children:"Full section lineup — every member's chair and seat"}),e.jsx("li",{children:"Performance details — date, time, call/setup, venue"}),e.jsx("li",{children:"First rehearsal — date, time, venue"}),e.jsx("li",{children:"Setlist with recording links (if set)"}
1),e.jsx("li",{children:"Your name, email, and phone as the signature"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Performance"}),e.jsxs("select",{value:u,onChange:v=>G(v.target.value),className:"block w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm shadow-sm focus:outline-none focus:ring-2 focus:ring-band-500 focus:border-band-500",children:[$.length===0&&e.jsx("option",{value:"",children:"No upcoming performances"}),$.map(v=>e.jsxs("option",{value:v.id,children:[we(v.performanceDate)," — ",v.title]},v.id))]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:["Personal message ",e.jsx("span",{className:"text-gray-400 font-normal",children:"(optional, shown above the details)"})]}),e.jsx("textarea",{rows:4,value:S,onChange:v=>V(v.target.value),placeholder:"Welcome to our next concert! Looking forward to making music with you all…",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-primary resize-none"})]}),e.jsx(pt,{members:E||[],picked:Z,onToggle:_,onClear:()=>g(new Set),label:"Send only to specific members (overrides whole-section)"}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-2",children:[e.jsx("span",{className:"text-xs text-gray-500",children:Z.size>0?`Will send to ${Z.size} selected member${Z.size===1?"":"s"}`:`Will send to all ${w||"section"} members (${N||0})`}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx($e,{variant:"secondary",onClick:p,disabled:W,children:"Cancel"}),e.jsx($e,{onClick:X,disabled:W||!u||h===0,isLoading:W,children:W?"Sending…":`Send${h>0?` (${h})`:""}`})]})]})]})})}function pt({members:d,picked:p,onToggle:$,onClear:w,label:N}){const[E,k]=i.useState(!1),T=p.size;return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>k(u=>!u),"aria-expanded":E,className:`w-full flex items-center justify-between rounded-md border px-3 py-2 text-sm font-medium transition-colors ${T>0?"border-band-300 bg-band-50 text-band-700":"border-gray-300 bg-white text-gray-700 hover:border-band-400"}`,children:[e.jsxs("span",{children:[N||"Pick specific members",T>0&&e.jsxs("span",{className:"ml-2 font-bold",children:["(",T,")"]})]}),e.jsxs("span",{className:"flex items-center gap-2",children:[T>0&&e.jsx("span",{role:"button",tabIndex:0,onClick:u=>{u.stopPropagation(),w()},onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.stopPropagation(),w())},className:"text-xs underline text-band-700 hover:text-band-900",children:"clear"}),e.jsx("span",{"aria-hidden":"true",className:"text-xs",children:E?"▴":"▾"})]})]}),E&&e.jsx("div",{className:"mt-2 max-h-60 overflow-y-auto border border-gray-200 rounded-md bg-white",children:d.length===0?e.jsx("div",{className:"p-3 text-sm text-gray-500",children:"No active members with email."}):d.map(u=>{const G=p.has(u.id);return e.jsxs("button",{type:"button",onClick:()=>$(u.id),"aria-pressed":G,className:`w-full flex items-center gap-3 border-t border-gray-100 px-3 py-2 text-left text-sm hover:bg-gray-50 ${G?"bg-band-50":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:`w-4 h-4 rounded border-2 flex items-center justify-center text-white text-[10px] font-bold ${G?"bg-band-500 border-band-500":"border-gray-300"}`,children:G?"✓":""}),e.jsx("span",{className:"flex-1 min-w-0 text-gray-900",children:u.name})]},u.id)})})]})}export{gr as SectionLeaderView};

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.