1import{h as K,c as oe,a as ce,r,e as de,z as me,t as ue,j as e,B as x,S as fe,d as I,E as xe,F as Y,l as he,p as pe}from"./index-_aijvlUq.js";import{u as be,P as ge}from"./PageHeader-DCofr6qo.js";import{o as N}from"./orgEvents-BRXhXibs.js";import{v as ve}from"./venues-DxAiztOL.js";import{I as A}from"./Input-ysTyZFq5.js";import{a as q}from"./Skeleton-B3Wj6cNd.js";import{C as X}from"./ConfirmDialog-CODvETNM.js";import{C as ye,H as je,a as Ce}from"./CancelEventDialog-iYnlU3wL.js";import{R as we}from"./RestoreEventDialog-B5yJWYUU.js";import{E as Ne}from"./EmptyState-CPGKooqj.js";import{h as J}from"./helpRequests-Bol7uyz2.js";import{b as Ee,c as Se}from"./helpWanted-C0itiuLN.js";import"./Menu-CATQC14B.js";import"./MemberMultiPicker-DdjcDFao.js";import"./TripForm-CydVdSPh.js";import"./equipmentValueReport-BI2xc4oS.js";import"./tripRates-CtgxAan6.js";import"./members-I3UAoZ9P.js";import"./downscaleImage-qyGK-a3D.js";const R={title:"",description:"",eventDate:"",startTime:"",endTime:"",venueId:"",notes:""};function Je(){be();const{currentOrg:n}=K(),{showSuccess:s,showError:l}=oe(),{canFully:u}=ce(),c=u("event:create"),f=K(t=>t.currentOrg?.volunteerSettings?.enabled!==!1),b=u("event:cancel"),[h,m]=r.useState(null),[y,d]=r.useState({}),[T,S]=r.useState([]),[g,_]=r.useState("upcoming"),[$,Z]=r.useState(!1),[G,P]=r.useState(!1),[v,F]=r.useState(null),[a,p]=r.useState(R),[L,U]=r.useState(!1),[ee,O]=r.useState(!1),[j,H]=r.useState(null),[C,M]=r.useState(null),[D,V]=r.useState(null),W=r.useRef(null),[k,te]=de();r.useEffect(()=>{n&&E()},[n,g,$]),r.useEffect(()=>{k.get("new")!=="true"||!c||(B(k.get("date")||""),k.delete("new"),k.delete("date"),te(k,{replace:!0}))},[]),r.useEffect(()=>{n&&ve.list(n.id).then(t=>S(Array.isArray(t)?t:[])).catch(()=>S([]))},[n]);async function E(){m(null);try{const t=await N.list({filter:g,includeCancelled:$});m(Array.isArray(t)?t:[]),c&&f?J.list({upcoming:!0}).then(o=>{const i={};for(const w of Array.isArray(o)?o:[])w.orgEventId&&(i[w.orgEventId]||=[]).push(w);d(i)}).catch(()=>{}):f&&J.forMe().then(o=>{const i={};for(const w of Array.isArray(o)?o:[])w.orgEventId&&(i[w.orgEventId]||=[]).push(w);d(i)}).catch(me("member help wanted on work days"))}catch{m([]),l(ue("events"))}}function B(t=""){F(null),p(t?{...R,eventDate:t}:R),P(!0),setTimeout(()=>W.current?.scrollIntoView({behavior:"smooth",block:"start"}),50)}function ne(t){F(t),p({title:t.title||"",description:t.description||"",eventDate:t.eventDate||"",startTime:t.startTime||"",endTime:t.endTime||"",venueId:t.venueId||"",notes:t.notes||""}),P(!0),setTimeout(()=>W.current?.scrollIntoView({behavior:"smooth",block:"start"}),50)}function z(){P(!1),F(null),p(R)}async function se(){if(!a.title.trim()){l("Title is required.");return}if(!a.eventDate){l("Event date is required.");return}const t={title:a.title.trim(),description:a.description.trim()||null,eventDate:a.eventDate,startTime:a.startTime||null,endTime:a.endTime||null,venueId:a.venueId||null,notes:a.notes.trim()||null};U(!0);try{v?(await N.update(v.id,t),s("Event updated.")):(await N.create(t),s("Event created.")),z(),await E()}catch(o){l(o.message||xe)}finally{U(!1)}}async function ae(){if(v)try{await N.remove(v.id),s("Event deleted."),O(!1),z(),await E()}catch(t){l(t.message||pe)}}async function re(t){if(j)try{const i=(await N.cancel(j.id,t))?.notification?.sent;t?.notify&&Number.isFinite(i)&&i>0?s(`Event cancelled · ${i} member${i===1?"":"s"} notified.`):t?.notify?s("Event cancelled · No recipients to notify."):s("Event cancelled silently."),H(null),await E()}catch(o){l(o.message||"Could not cancel event.")}}async function ie(t){if(C)try{const i=(await N.uncancel(C.id,t))?.notification?.sent;t?.notify&&Number.isFinite(i)&&i>0?s(`Event restored · ${i} member${i===1?"":"s"} notified.`):t?.notify?s("Event restored · No recipients to notify."):s("Event restored."),M(null),await E()}catch(o){l(o.message||"Could not restore event.")}}async function le(t){if(D)try{const i=(await N.publish(D.id,t))?.notification?.sent;t?.notify&&Number.isFinite(i)&&i>0?s(`Event announced · ${i} member${i===1?"":"s"} notified.`):t?.notify?s("Event announced · No recipients to notify (or already announced)."):s("Event marked as announced (no email sent)."),V(null),await E()}catch(o){l(o.message||"Could not announce event.")}}return n?e.jsxs("div",{className:"px-4 py-4 md:px-0 md:py-0",children:[e.jsx(ge,{title:"Events",subtitle:"Org-wide calendar items â galas, picnics, banquets, fundraisers. Independent of ensemble performances.",breadcrumbs:[{label:"Home",to:"/"},{label:"Events"}],actions:c&&!G?e.jsx(x,{onClick:()=>B(),children:"New event"}):null}),G&&c&&e.jsxs("div",{ref:W,className:"bg-white rounded-xl border border-gray-200 p-6 mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:v?"Edit Event":"New Event"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Title *"}),e.jsx(A,{value:a.title,onChange:t=>p({...a,title:t.target.value}),placeholder:"25th Anniversary Gala"})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Description"}),e.jsx("textarea",{value:a.description,onChange:t=>p({...a,description:t.target.value}),rows:3,placeholder:"What members need to know",className:"w-full px-3 py-2 rounded-md border border-gray-300 text-sm focus:outline-none focus:ring-2 focus:ring-band-500 focus:border-band-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Date *"}),e.jsx(A,{type:"date",value:a.eventDate,onChange:t=>p({...a,eventDate:t.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Venue"}),e.jsx(fe,{value:a.venueId,onChange:t=>p({...a,venueId:t.target.value}),options:[{value:"",label:"â None â"},...T.map(t=>({value:t.id,label:t.name}))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Start time"}),e.jsx(A,{type:"time",value:a.startTime,onChange:t=>p({...a,startTime:t.target.value})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"End time"}),e.jsx(A,{type:"time",value:a.endTime,onChange:t=>p({...a,endTime:t.target.value})})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Internal notes"}),e.jsx("textarea",{value:a.notes,onChange:t=>p({...a,notes:t.target.value}),rows:2,placeholder:"Visible to board only â not sent to members",className:"w-full px-3 py-2 rounded-md border border-gray-300 text-sm focus:outline-none focus:ring-2 focus:ring-band-500 focus:border-band-500"})]})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(x,{onClick:se,isLoading:L,disabled:L,children:v?"Save changes":"Create"}),e.jsx(x,{variant:"secondary",onClick:z,disabled:L,children:"Cancel"}),v&&b&&e.jsx(x,{variant:"danger",className:"ml-auto",onClick:()=>O(!0),children:"Delete"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3 flex-wrap",children:[e.jsx(Q,{label:"Upcoming",active:g==="upcoming",onClick:()=>_("upcoming")}),e.jsx(Q,{label:"Past",active:g==="past",onClick:()=>_("past")}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-gray-600 ml-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:t=>Z(t.target.checked),className:"rounded border-gray-300 text-band-600 focus:ring-band-500"}
1),"Show cancelled"]})]}),h===null?e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{}),e.jsx(q,{}),e.jsx(q,{})]}):h.length===0?e.jsx(Ne,{card:!0,title:`No ${g} events yet.`,action:c&&g==="upcoming"?e.jsx(x,{onClick:()=>B(),children:"New event"}):null}):e.jsx("div",{className:"space-y-2",children:h.map(t=>e.jsx(ke,{event:t,canManage:c,canCancel:b,onEdit:()=>ne(t),onCancel:()=>H(t),onRestore:()=>M(t),onAnnounce:()=>V(t),showHelp:f,helpRequests:y[t.id]||[],onHelpChange:o=>d(i=>({...i,[t.id]:o}))},t.id))}),e.jsx(X,{isOpen:ee,onClose:()=>O(!1),onConfirm:ae,title:"Delete event?",message:v?`Permanently remove "${v.title}"? Members will not be notified.`:"",confirmLabel:"Delete",cancelLabel:"Keep",confirmVariant:"danger"}),e.jsx(ye,{isOpen:!!j,onClose:()=>H(null),onConfirm:re,title:"Cancel event?",message:j?`Cancel "${j.title}"? It will stay on the calendar marked CANCELLED.`:"",defaultMessage:j?`The event "${j.title}" scheduled for ${I(j.eventDate)} has been cancelled. We apologize for any inconvenience.`:"",confirmLabel:"Cancel event"}),e.jsx(we,{isOpen:!!C,onClose:()=>M(null),onConfirm:ie,title:"Restore event?",message:C?`Bring "${C.title}" back on the calendar.`:"",defaultMessage:C?`Good news â the event "${C.title}" scheduled for ${I(C.eventDate)} is back on as scheduled.`:"",confirmLabel:"Restore event"}),e.jsx(Ae,{isOpen:!!D,target:D,onClose:()=>V(null),onConfirm:le})]}):null}function Q({label:n,active:s,onClick:l}){return e.jsx("button",{type:"button",onClick:l,className:`px-3 py-1.5 text-sm rounded-md transition-colors ${s?"bg-band-600 text-white":"bg-white text-gray-700 border border-gray-300 hover:bg-gray-50"}`,children:n})}function ke({event:n,canManage:s,canCancel:l,onEdit:u,onCancel:c,onRestore:f,onAnnounce:b,showHelp:h=!0,helpRequests:m=[],onHelpChange:y}){const d=!!n.cancelledAt,T=!!n.firstPublishedAt,S=[n.venueName,n.venueCity,n.venueState].filter(Boolean).join(", ");return e.jsxs("div",{className:`rounded-xl border p-4 ${d?"bg-red-50/40 border-red-200":"bg-white border-gray-200"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-violet-100 text-violet-700 border border-violet-200",children:"Event"}),d&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wide bg-red-100 text-red-700 border border-red-200",children:"Cancelled"}),!d&&!T&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wide bg-amber-50 text-amber-700 border border-amber-200",children:"Draft"})]}),e.jsx("h3",{className:`text-base font-semibold ${d?"text-gray-400 line-through":"text-gray-900"}`,children:n.title}),e.jsxs("p",{className:`text-sm mt-0.5 ${d?"text-gray-300 line-through":"text-gray-600"}`,children:[I(n.eventDate),n.startTime&&e.jsxs(e.Fragment,{children:[" · ",Y(n.startTime),n.endTime?`â${Y(n.endTime)}`:""]}),S&&e.jsxs(e.Fragment,{children:[" · ",S]})]}),n.description&&!d&&e.jsx("p",{className:"text-sm text-gray-500 mt-2 line-clamp-2",children:n.description}),d&&n.cancellationReason&&e.jsx("p",{className:"text-sm text-red-700 mt-1 italic",children:n.cancellationReason})]}),s&&e.jsxs("div",{className:"flex flex-col gap-1 shrink-0",children:[!d&&!T&&e.jsx(x,{size:"sm",onClick:b,children:"Announce"}),!d&&e.jsx(x,{size:"sm",variant:"ghost",onClick:u,children:"Edit"}),!d&&l&&e.jsx(x,{size:"sm",variant:"warning",onClick:c,children:"Cancel eventâ¦"}),d&&l&&e.jsx(x,{size:"sm",variant:"secondary",onClick:f,children:"Restore"})]})]}),s&&h&&!d&&n.eventDate>=he()&&e.jsx(Te,{event:n,requests:m,onChange:y}),!s&&h&&!d&&m.some(g=>g.status==="open"||g.youAreOn)&&e.jsx(De,{event:n,requests:m,onChange:y})]})}function Te({event:n,requests:s,onChange:l}){const[u,c]=r.useState(!1),[f,b]=r.useState(!1),h=s.filter(m=>m.status==="open");return e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100",children:[h.length===0&&!u?e.jsx(x,{type:"button",variant:"ghost",onClick:()=>{b(!0),c(!0)},children:"Ask for helpâ¦"}):e.jsxs(x,{type:"button",variant:"ghost","aria-expanded":u,onClick:()=>c(m=>!m),children:["Help wanted · ",Ee(s)]}),u&&e.jsx("div",{className:"mt-3",children:e.jsx(je,{orgEventId:n.id,defaultDate:n.eventDate||"",canManage:!0,startWithNew:f,onChange:l})})]})}function De({event:n,requests:s,onChange:l}){const[u,c]=r.useState(!1);return e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-100",children:[e.jsxs(x,{type:"button",variant:"ghost","aria-expanded":u,onClick:()=>c(f=>!f),children:["Help wanted · ",Se(s)]}),u&&e.jsx("div",{className:"mt-3",children:e.jsx(Ce,{orgEventId:n.id,list:s,onChange:l})})]})}function Ae({isOpen:n,target:s,onClose:l,onConfirm:u}){const[c,f]=r.useState(!0),[b,h]=r.useState("");
1if(r.useEffect(()=>{n&&s&&(f(!0),h(`We're excited to share that "${s.title}" is coming up on ${I(s.eventDate)}! Mark your calendars.`))},[n,s]),!n||!s)return null;const m=!s.firstPublishedAt;return e.jsx(X,{isOpen:n,onClose:l,onConfirm:()=>u({notify:c,message:b.trim()}),title:m?"Announce event?":"Re-announce event?",message:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-gray-600",children:m?"Sets the event as announced and (optionally) emails all active org members.":"Re-announcement is rare â this event was already announced. Ticking Notify will send a follow-up email to all members."}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-800",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:y=>f(y.target.checked),className:"rounded border-gray-300 text-band-600 focus:ring-band-500"}),"Email members about this event"]}),c&&e.jsx("textarea",{value:b,onChange:y=>h(y.target.value.slice(0,500)),rows:4,className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-band-500 focus:border-band-500"})]}),confirmLabel:m?"Announce":"Re-announce",cancelLabel:"Cancel",confirmVariant:"primary"})}export{Je as EventsPage};
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.