1import{c as G,r as o,j as e,q as Ce,s as $e,h as Se,d as ze,B as N,t as _e,L as Fe,E as ne,m as Ue,u as Je,n as We,b as qe,g as He,a as Ye,v as Ge,S as K,T as ve,w as ae,p as Ve}from"./index-_aijvlUq.js";import{u as Ke}from"./useMemberStore-C9_FW8gS.js";import{a as je}from"./agreements-BApgy4DC.js";import{B as oe}from"./Badge-DJIi163x.js";import{m as E}from"./members-I3UAoZ9P.js";import{E as ke}from"./EmptyState-CPGKooqj.js";import{e as Ze}from"./ensembles-WGlB365j.js";import{P as Qe}from"./PageHeader-DCofr6qo.js";import{b as Ne}from"./badges-sJrwZCWE.js";import{C as Pe}from"./ConfirmDialog-CODvETNM.js";import{C as Xe}from"./CameraCaptureButton-B4WpiVvJ.js";import{I as f}from"./Input-ysTyZFq5.js";import{U as et}from"./usStates-B3oQG6kH.js";import{I as we}from"./InstrumentPicker-KS7qdNLg.js";import{O as tt}from"./orgRoles-D1oGgqrm.js";import{r as re}from"./resizeImage-BUqRBCBG.js";import"./downscaleImage-qyGK-a3D.js";import"./ChipToggle-hmCaOMqs.js";function st({memberId:g,proxyName:y}){const{showSuccess:C,showError:m}=G(),[n,l]=o.useState(void 0),[h,p]=o.useState(!1),[k,A]=o.useState(""),[s,I]=o.useState(""),[c,b]=o.useState(""),[P,v]=o.useState(""),[M,B]=o.use
1State(!1);o.useEffect(()=>{let x=!0;return je.getMemberResponse(g).then(W=>{x&&l(W)}).catch(()=>{x&&l(null)}),()=>{x=!1}},[g]);async function z(){if(n&&k===n.response&&s===n.respondedBy&&(c||null)===(n.respondentName||null)&&(P.trim()||null)===(n.sourceNote||null)){p(!1);return}if(!k){m("Pick the answer first â Yes or No.");return}if(!s){m("Tell us who answered â the member, their guardian, or their application form.");return}if(!P.trim()){m("Add a short note about where this answer came from.");return}B(!0);try{const x=await je.recordMemberResponse(g,{response:k,respondedBy:s,respondentName:s==="proxy"&&(c||y)||null,sourceNote:P.trim()});l(x),p(!1),C("Photo permission recorded")}catch(x){m(x.message||"Failed to record the answer")}finally{B(!1)}}const T={member:"answered by the member",proxy:"answered by their guardian",admin:"from their application form"};return e.jsxs("div",{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-3",children:"Photo & Social Media"}),n===void 0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}):h?e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex gap-2",children:[{value:"granted",label:"Yes â photos OK"},{value:"declined",label:"No"}].map(x=>e.jsx("button",{type:"button",onClick:()=>{A(x.value),n&&x.value===n.response?(I(n.respondedBy||""),b(n.respondentName||""),v(n.sourceNote||"")):(I(""),b(""),v(""))},className:`px-3 py-1.5 rounded-full text-sm font-medium border transition-colors ${k===x.value?"bg-band-500 border-band-500 text-white":"bg-white border-gray-300 text-gray-700 hover:border-band-400"}`,children:x.label},x.value))}),e.jsx("div",{className:"flex gap-2",children:[{value:"member",label:"The member"},{value:"proxy",label:"Parent / guardian"},{value:"admin",label:"From their application form"}].map(x=>e.jsx("button",{type:"button",onClick:()=>{I(x.value),n&&x.value===n.respondedBy&&k===n.response?(b(n.respondentName||""),v(n.sourceNote||"")):(b(x.value==="proxy"&&y||""),v(x.value==="admin"?"Membership application":""))},className:`px-3 py-1 rounded-full text-xs font-medium border transition-colors ${s===x.value?"bg-gray-800 border-gray-800 text-white":"bg-white border-gray-300 text-gray-600 hover:border-gray-400"}`,children:x.label},x.value))}),s==="admin"&&e.jsx("p",{className:"text-xs text-gray-400",children:"Use this when copying an answer from a written application."}),s==="proxy"&&e.jsx("input",{type:"text",value:c,onChange:x=>b(x.target.value),placeholder:"Guardian's name",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-band-500 focus:border-band-500"}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"photo-source-note",className:"block text-xs font-medium text-gray-500 mb-1",children:"Where did this answer come from?"}),e.jsx("input",{id:"photo-source-note",type:"text",value:P,onChange:x=>v(x.target.value),placeholder:"e.g. paper application, told us at rehearsal, email from parent",className:"w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-band-500 focus:border-band-500"}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"Saved with the answer so you can trace it back later."})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:z,disabled:M,className:"px-3 py-1.5 rounded-lg text-sm font-medium bg-band-500 text-white hover:bg-band-600 disabled:opacity-50",children:M?"Savingâ¦":"Save"}),e.jsx("button",{type:"button",onClick:()=>p(!1),className:"px-3 py-1.5 rounded-lg text-sm font-medium text-gray-600 hover:bg-gray-100",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n?e.jsxs(e.Fragment,{children:[e.jsx(oe,{color:n.response==="granted"?"green":"gray",children:n.response==="granted"?"Photos OK":"Declined"}),e.jsxs("span",{className:"text-sm text-gray-500",children:[T[n.respondedBy]||n.respondedBy,n.respondentName?` (${n.respondentName})`:"",n.createdAt?` · ${Ce(n.createdAt)}`:"",n.agreementVersion?` · wording v${n.agreementVersion}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{color:"amber",children:"Not Answered"}),e.jsx("span",{className:"text-sm text-gray-500",children:"No photo-permission answer on record."})]}),e.jsx("button",{type:"button",onClick:()=>{A(n?.response||""),I(n?.respondedBy||""),b(n?.respondentName||""),v(n?.sourceNote||""),p(!0)},className:"text-sm font-medium text-band-600 hover:text-band-700 ml-auto",children:n?"Change answer":"Record answer"})]})]})}function at({memberId:g}){const[y,C]=o.useState(void 0);return o.useEffect(()=>{let m=!0;return E.getTimeline(g).then(n=>{m&&C(n||[])}).catch(()=>{m&&C([])}),()=>{m=!1}},[g]),e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"History"}),y===void 0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}):y.length===0?e.jsx(ke,{size:"compact",title:"No recorded changes yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs text-gray-400 uppercase tracking-wide",children:[e.jsx("th",{className:"py-2 pr-4 whitespace-nowrap",children:"When"}),e.jsx("th",{className:"py-2 pr-4 whitespace-nowrap",children:"Who"}),e.jsx("th",{className:"py-2",children:"What"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:y.map((m,n)=>e.jsxs("tr",{className:"align-top",children:[e.jsx("td",{className:"py-2 pr-4 whitespace-nowrap text-gray-500 tabular-nums",children:Ce(m.occurredAt)}),e.jsx("td",{className:"py-2 pr-4 whitespace-nowrap text-gray-700",children:m.actor}),e.jsxs("td",{className:"py-2 text-gray-700",children:[e.jsx("span",{className:m.superseded?"line-through text-gray-400":"",children:m.summary}),m.superseded&&e.jsx(oe,{color:"gray",className:"ml-2",children:"superseded"}),m.detail&&e.jsxs("p",{className:`text-xs mt-0.5 ${m.superseded?"text-gray-300":"text-gray-400"}`,children:["â",m.detail,"â"]})]})]},n))})]})})]})}const rt={app_modal:"in the app",email_link:"via email link",sms_reply:"by text reply",admin_on_behalf:"recorded by an admin"};function nt({memberId:g,hasPhone:y}){const{showSuccess:C,showError:m}
1=G(),[n,l]=o.useState(null),[h,p]=o.useState(!0),[k,A]=o.useState(!1),[s,I]=o.useState(""),[c,b]=o.useState(!1),[P,v]=o.useState(!1),[M,B]=o.useState(!1),z=$e(Se(S=>S.currentOrg?.planTier),"sms");async function T(){if(g){p(!0);try{l(await E.getSmsConsent(g))}catch{l(null)}finally{p(!1)}}}o.useEffect(()=>{T()},[g]);async function x(){if(!s.trim()){m("Add a note describing how the member gave consent.");return}b(!0);try{await E.recordSmsConsent(g,s.trim()),C("SMS consent recorded"),A(!1),I(""),await T()}catch(S){m(S.message||"Could not record consent")}finally{b(!1)}}async function W(){B(!0);try{const S=await E.sendSmsInvite(g);S?.sent===!1&&S?.alreadyConsented?C("This member is already opted in to text reminders."):C("Invite text sent â they opt in by replying JOIN."),await T()}catch(S){m(S.message||"Could not send the invite text")}finally{B(!1)}}async function Z(){try{await E.revokeSmsConsent(g),C("SMS consent removed"),v(!1),await T()}catch(S){m(S.message||"Could not remove consent")}}if(h)return null;if(!z)return e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50 p-4",children:[e.jsx("p",{className:"text-sm font-medium text-gray-700",children:"Text reminders (SMS)"}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Text reminders are part of the Complete plan. Members get every notice by email."})]});const R=n?.consented,_=n?.consentedAt?ze(n.consentedAt):null,a=n?.consentMethod?rt[n.consentMethod]||n.consentMethod:null;return e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50 p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700",children:"Text reminders (SMS)"}),R?e.jsxs("p",{className:"text-sm text-green-700 mt-0.5",children:["Opted in",a?` (${a})`:"",_?` on ${_}`:""]}):n?.invitePending?e.jsx("p",{className:"text-sm text-amber-700 mt-0.5",children:"Invite text sent â awaiting their JOIN reply."}):n?.everInvited?e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Invited once, no reply. They can still opt in from the app or the emailed link."}):e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"Not opted in to text reminders."})]}),R?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(!0),children:"Remove"}):!k&&e.jsxs("div",{className:"flex gap-2 shrink-0",children:[n?.inviteEnabled&&!n?.invitePending&&!n?.everInvited&&e.jsx(N,{type:"button",variant:"secondary",size:"sm",disabled:!y||M,isLoading:M,onClick:W,children:"Send invite text"}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",disabled:!y,onClick:()=>A(!0),children:"Record consent"})]})]}),!R&&!y&&e.jsx("p",{className:"text-xs text-gray-400 mt-2",children:"Add a phone number to enable text reminders."}),k&&e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Record consent the member gave you verbally, in writing, or on a signup sheet. This is your attestation on their behalf â note how/when they agreed."}),e.jsx(f,{label:"How was consent given? (required)",value:s,onChange:S=>I(S.target.value),placeholder:"e.g. Signed the SMS opt-in sheet at the June rehearsal"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(N,{type:"button",size:"sm",onClick:x,isLoading:c,disabled:c||!s.trim(),children:"Save consent"}),e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{A(!1),I("")},children:"Cancel"})]})]}),e.jsx(Pe,{isOpen:P,title:"Remove SMS consent?",message:"This member will stop receiving text reminders. You can record consent again later.",confirmLabel:"Remove consent",onConfirm:Z,onCancel:()=>v(!1)})]})}function ot({memberId:g,driverDocumentsOnFile:y=!1}){const C=G(c=>c.showSuccess),m=G(c=>c.showError),[n,l]=o.useState(null),[h,p]=o.useState(null),[k,A]=o.useState(!!y);o.useEffect(()=>{A(!!y)},[y]);async function s(){const c=!k;A(c);try{await E.setDriverDocuments(g,c),C(c?"Driver documents noted as on file.":"Driver documents no longer noted as on file.")}catch(b){A(!c),m(b?.message||ne)}}o.useEffect(()=>{if(!g)return;let c=!0;return Promise.resolve().then(()=>E.getTeams(g)).then(b=>{c&&l(Array.isArray(b)?b:[])}).catch(()=>{c&&(l([]),m(_e("teams")))}),()=>{c=!1}},[g,m]);async function I(c){const b=!c.on;p(c.id),l(P=>P.map(v=>v.id===c.id?{...v,on:b}:v));try{await E.setTeam(g,c.id,b),C(b?`Added to ${c.name}.`:`Taken off ${c.name}.`)}catch(P){l(v=>v.map(M=>M.id===c.id?{...M,on:!b}:M)),m(P?.message||ne)}finally{p(null)}}return n===null?null:e.jsxs("div",{className:"mt-6 pt-4 border-t border-gray-100","data-testid":"member-teams",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-700 mb-1",children:"Teams"}),e.jsx("p",{className:"text-xs text-gray-600 mb-3",children:"Teams say which jobs this member can do, like driving. A team gives no access. Teams save the moment you tick them. Roles above save with Save changes."}),n.length===0?e.jsxs(e.Fragment,{children:[e.jsx(ke,{size:"compact",title:"No teams yet."}),e.jsxs("p",{className:"text-sm text-gray-600",children:["Make one under Settings â ",e.jsx(Fe,{to:"/settings/roles",className:"text-brand-primary hover:underline",children:"Roles & Access"})," â Teams."]})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:n.map(c=>e.jsxs("label",{className:"flex items-center gap-2 min-h-[44px] text-sm text-gray-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:c.on,disabled:h===c.id,onChange:()=>
1I(c),className:"h-4 w-4 rounded border-gray-300 text-band-600 focus:ring-band-500"}),c.name]},c.id))}),e.jsxs("label",{className:"flex items-start gap-2 min-h-[44px] mt-3 text-sm text-gray-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:k,onChange:s,className:"mt-0.5 h-5 w-5 rounded border-gray-300 text-band-600 focus:ring-band-500"}),e.jsxs("span",{children:["Licensed driver, documents on file",e.jsx("span",{className:"block text-xs text-gray-600",children:"For anyone who drives for the band. Saves the moment you tick it."})]})]})]})}const it=[{value:"musician",label:"Musician"},{value:"director",label:"Director"},{value:"staff",label:"Staff (non-performing)"},{value:"guest",label:"Guest (occasional)"}],lt=[{value:"active",label:"Active"},{value:"inactive",label:"Inactive"},{value:"retired",label:"Alumni"}];function Pt(){const{id:g}=Ue(),y=Je(),C=We(),m=qe(t=>t.user),n=He(),l=!g&&C.pathname==="/account/profile",h=l?m?.memberId:g,p=!l&&C.state?.wizard===!0,k=C.state?.sendWelcome!==!1,{fetchMember:A,selectedMember:s,updateMember:I,isLoading:c}=Ke(),{showSuccess:b,showError:P}=G(),v=Se(t=>t.currentOrg),{canAny:M,canFully:B,authority:z}=Ye(),T=!l&&B("members:update"),x=!l&&B("members:delete"),W=!l&&B("roles:manage"),Z=z==="owner"||z==="admin",[R,_]=o.useState("personal"),[a,S]=o.useState(null),[V,ie]=o.useState({}),[F,le]=o.useState(!1),[ce,me]=o.useState(!1),[Ee,Q]=o.useState(!1),[L,Re]=o.useState(null),[Ae,Ie]=o.useState(null),[O,q]=o.useState(null),de=o.useRef(null),H=o.useRef(null),[Y,ue]=o.useState([]),[D,X]=o.useState(null),[xe,Me]=o.useState([]),[$,ee]=o.useState(null),[te,U]=o.useState({});o.useEffect(()=>{S(null),X(null),ee(null),U({}),H.current=null,A(h),Ge.get("/instruments",{params:{context:"member"}}).then(ue).catch(console.error)},[h]),o.useEffect(()=>{v?.id&&Ze.list(v.id).then(Me).catch(console.error)},[v?.id]),o.useEffect(()=>{if(s&&s.id===h){if(S({firstName:s.firstName??"",lastName:s.lastName??"",emailAddress:s.emailAddress??"",street:s.street??"",street2:s.street2??"",city:s.city??"",state:s.state??"",zip:s.zip??"",county:s.county??"",memberType:s.memberType??"musician",orgRoles:s.orgRoles??[],memberStatus:s.memberStatus??"active",onboardingDate:s.onboardingDate??"",birthday:s.birthday??"",profession:s.profession??"",bio:s.bio??"",programBio:s.programBio??"",phone:s.phone??"",notificationDelegateId:s.notificationDelegateId??"",emergencyContactName:s.emergencyContactName??"",emergencyContactRelationship:s.emergencyContactRelationship??"",emergencyContactEmail:s.emergencyContactEmail??"",emergencyContactPhone:s.emergencyContactPhone??"",communicationProxy:s.communicationProxy??!1,proxyName:s.proxyName??"",proxyEmail:s.proxyEmail??"",proxyPhone:s.proxyPhone??"",proxyRelationship:s.proxyRelationship??"",proxyMode:s.proxyMode??"replace"}),D===null&&X((s.instruments??[]).map(t=>({instrumentId:t.instrumentId}))),$===null){ee((s.ensembles??[]).map(r=>r.id));const t={};for(const r of s.ensembles??[])r.instrumentId&&(t[r.id]=r.instrumentId);U(t)}H.current||(H.current={form:{firstName:s.firstName??"",lastName:s.lastName??"",emailAddress:s.emailAddress??"",street:s.street??"",street2:s.street2??"",city:s.city??"",state:s.state??"",zip:s.zip??"",county:s.county??"",memberType:s.memberType??"musician",orgRoles:[...s.orgRoles??[]].sort(),memberStatus:s.memberStatus??"active",onboardingDate:s.onboardingDate??"",birthday:s.birthday??"",profession:s.profession??"",bio:s.bio??"",programBio:s.programBio??"",phone:s.phone??"",emergencyContactName:s.emergencyContactName??"",emergencyContactRelationship:s.emergencyContactRelationship??"",emergencyContactEmail:s.emergencyContactEmail??"",emergencyContactPhone:s.emergencyContactPhone??"",communicationProxy:s.communicationProxy??!1,proxyName:s.proxyName??"",proxyEmail:s.proxyEmail??"",proxyPhone:s.proxyPhone??"",proxyRelationship:s.proxyRelationship??"",proxyMode:s.proxyMode??"replace"},instruments:(s.instruments??[]).map(t=>({instrumentId:t.instrumentId})),ensembleIds:(s.ensembles??[]).map(t=>t.id),ensembleInstrumentMap:Object.fromEntries((s.ensembles??[]).filter(t=>t.instrumentId).map(t=>[t.id,t.instrumentId]))})}},[s,h]);async function he(t){const r=(typeof t=="string"?t:a?.emailAddress||"").trim();if(!r||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)){q(null);return}if(r.toLowerCase()===(s?.emailAddress||"").toLowerCase()){q(null);return}try{const i=await E.checkEmail(r);q({domainDeliverable:i?.domainDeliverable??null,suggestion:i?.suggestion??null})}catch{q(null)}}function d(t,r){S(i=>{const u={...i,[t]:r};if(t==="memberType"&&r==="director"){const j=u.orgRoles??[];j.includes("music_director")||(u.orgRoles=[...j,"music_director"])}return u}),V[t]&&ie(i=>({...i,[t]:null}))}function pe(t){X(t.map(r=>({instrumentId:r})))}function Te(t){const r=a.orgRoles??[];d("orgRoles",r.includes(t)?r.filter(i=>i!==t):[...r,t])}function De(t){ee(r=>{if(r.includes(t))return U(u=>{const j={...u};return delete j[t],j}),r.filter(u=>u!==t);const i=D?.[0];return i&&U(u=>({...u,[t]:i.instrumentId})),[...r,t]})}o.useEffect(()=>{if(D?.length===1&&$?.length>0){const t=D[0].instrumentId;U(r=>{const i={...r};let u=!1;for(const j of $)i[j]!==t&&(i[j]=t,u=!0);return u?i:r})}},[D,$]);async function ge(t){const r=t.target.files?.[0];if(!r)return;const i=await re(r);Re(i),Ie(URL.createObjectURL(i))}function Be(){const t={};if(!l){a.firstName?.trim()||(t.firstName="Required"),a.lastName?.trim()||(t.lastName="Required");const r=!!a.emailAddress?.trim(),i=!!a.phone?.trim(),u=a.communicationProxy&&(a.proxyEmail?.trim()||a.proxyPhone?.trim());r?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(a.emailAddress)||(t.emailAddress="Invalid email"):!i&&!u&&(t.emailAddress="Email, phone, or a communication proxy is required so the member can be reached.")}return ie(t),Object.keys(t).length===0}async function Oe(){me(!0);try{await E.softDelete(h),b("Member deleted successfully"),y("/members")}catch(t){P(t.message||Ve)}finally{me(!1),Q(!1)}}async function ye(t){if(t?.preventDefault&&t.preventDefault(),!!Be()){le(!0);try{if(l){const r={birthday:a.birthday,profession:a.profession,bio:a.bio,programBio:a.programBio,phone:a.phone,street:
1a.street,street2:a.street2,city:a.city,state:a.state,zip:a.zip,county:a.county,emergencyContactName:a.emergencyContactName,emergencyContactRelationship:a.emergencyContactRelationship,emergencyContactEmail:a.emergencyContactEmail,emergencyContactPhone:a.emergencyContactPhone,communicationProxy:a.communicationProxy,proxyName:a.proxyName,proxyEmail:a.proxyEmail,proxyPhone:a.proxyPhone,proxyRelationship:a.proxyRelationship,proxyMode:a.proxyMode,instruments:D??[]};if(await E.updateSelf(r),L){const i=await re(L);await E.uploadPhotoSelf(i)}}else{if(await I(h,{...a,instruments:D??[],ensembleAssignments:($??[]).map(r=>({ensembleId:r,instrumentId:te[r]||null}))}),L){const r=await re(L);await E.uploadPhoto(h,r)}if(p&&k)try{await E.createAccount(h)}catch(r){r.message?.includes("already has")||P("Member saved but failed to create login account: "+(r.message||""))}}b(l?"Profile updated successfully":p?"Member profile complete! Welcome email sent.":"Member updated successfully"),y(l?"/":`/members/${h}`)}catch(r){P(r.message||ne)}finally{le(!1)}}}const be=!H.current||L!=null||(()=>{const t=H.current;for(const w of Object.keys(t.form)){const J=a[w],fe=t.form[w];if(w==="orgRoles"){if(JSON.stringify([...J??[]].sort())!==JSON.stringify([...fe].sort()))return!0}else if(J!==fe)return!0}const r=[...$??[]].sort(),i=[...t.ensembleIds].sort();if(JSON.stringify(r)!==JSON.stringify(i)||JSON.stringify(te)!==JSON.stringify(t.ensembleInstrumentMap??{}))return!0;const u=[...D??[]].sort((w,J)=>w.instrumentId.localeCompare(J.instrumentId)),j=[...t.instruments].sort((w,J)=>w.instrumentId.localeCompare(J.instrumentId));if(u.length!==j.length)return!0;for(let w=0;w<u.length;w++)if(u[w].instrumentId!==j[w].instrumentId)return!0;return!1})();if(l&&!h)return e.jsxs("div",{className:"text-center py-20",children:[e.jsx("p",{className:"text-gray-500",children:"No member profile is linked to your account."}),e.jsx(N,{variant:"secondary",className:"mt-4",onClick:()=>y("/"),children:"Go home"})]});if(c||!a)return e.jsx("div",{className:"flex justify-center py-20",children:e.jsxs("svg",{className:"animate-spin motion-reduce:!animate-spin h-8 w-8 text-band-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})});const se=Ae||s?.photoUrl,Le=`${a.firstName?.[0]??""}${a.lastName?.[0]??""}`.toUpperCase();return e.jsxs("div",{className:n?"px-4 pt-3":"",children:[e.jsx(Pe,{isOpen:Ee,onClose:()=>Q(!1),onConfirm:Oe,isLoading:ce,title:"Delete Member",message:`Are you sure you want to delete ${a?.firstName} ${a?.lastName}? This cannot be undone.`,confirmLabel:"Delete"}),!n&&e.jsx(Qe,{title:l?"My Profile":p?`Set up ${s?.firstName} ${s?.lastName}'s Profile`:`Edit ${s?.firstName} ${s?.lastName}`,breadcrumbs:l?[{label:"Home",to:"/"},{label:"My Profile"}]:s?[{label:"Home",to:"/"},{label:"Members",to:"/members"},{label:`${s.firstName} ${s.lastName}`,to:`/members/${h}`},{label:p?"Setup":"Edit"}]:void 0,actions:!p&&e.jsx(N,{type:"submit",form:"edit-form",isLoading:F,disabled:!be,children:"Save changes"})}),(()=>{const t=l?[{key:"personal",label:"Personal"},{key:"contact",label:"Contact"}]:[{key:"personal",label:"Personal"},{key:"contact",label:"Contact"},{key:"instruments",label:"Instruments"},{key:"ensembles",label:"Ensembles"},...T?[{key:"admin",label:"Admin"},{key:"history",label:"History"}]:[]],r=t.findIndex(i=>i.key===R);return e.jsx("div",{className:"flex overflow-x-auto overflow-y-hidden border-b border-gray-200 mb-0",children:t.map((i,u)=>{const j=R===i.key,w=p&&u<r;return e.jsxs("button",{type:"button",onClick:()=>{(!p||u<=r)&&_(i.key)},disabled:p&&u>r,className:`px-5 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-px whitespace-nowrap ${j?"border-band-500 text-band-700":w?"border-transparent text-band-500 hover:text-band-700 hover:border-band-300":p&&u>r?"border-transparent text-gray-300 cursor-not-allowed":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"}`,children:[p&&w&&e.jsx("svg",{className:"mr-1 h-3.5 w-3.5 text-band-500 inline",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M16.704 5.29a1 1 0 010 1.42l-7.5 7.5a1 1 0 01-1.42 0l-3.5-3.5a1 1 0 111.42-1.42l2.79 2.79 6.79-6.79a1 1 0 011.42 0z",clipRule:"evenodd"})}),p&&e.jsxs("span",{className:"text-xs text-gray-400 mr-1",children:[u+1,"."]}),i.label]},i.key)})})})(),e.jsx("form",{id:"edit-form",onSubmit:ye,className:"bg-white rounded-b-xl border border-t-0 border-gray-200 p-6",children:e.jsxs("fieldset",{disabled:F,className:"contents",children:[R==="personal"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{children:[!l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"First Name",value:a.firstName,onChange:t=>d("firstName",t.target.value),error:V.firstName,required:!0}),e.jsx(f,{label:"Last Name",value:a.lastName,onChange:t=>d("lastName",t.target.value),error:V.lastName,required:!0})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4",children:[e.jsxs("div",{children:[e.jsx(f,{label:"Email Address",type:"email",value:a.emailAddress,onChange:t=>{d("emailAddress",t.target.value),O&&q(null)},onBlur:()=>he(),error:V.emailAddress,required:!a.communicationProxy,hint:a.communicationProxy?"Optional when a communication proxy is defined.":void 0}),O&&(O.domainDeliverable===!1||O.suggestion)&&e.jsxs("div",{className:"mt-2 rounded-lg border border-amber-200 bg-amber-50 text-amber-800 text-sm p-3",children:[O.domainDeliverable===!1&&e.jsx("p",{children:"This address's domain doesn't appear to receive mail."}),O.suggestion&&e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"!px-0 mt-1 text-amber-900 font-medium underline",onClick:()=>{d("emailAddress",O.suggestion),he(O.suggestion)},children:["Did you mean ",O.suggestion,"?"]})]})]}),e.jsx(K,{label:"Member Type",options:it,value:a.memberType,onCh
1ange:t=>d("memberType",t.target.value)})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4",children:e.jsx(K,{label:"Status",options:lt,value:a.memberStatus,onChange:t=>d("memberStatus",t.target.value)})})]}),l&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Name"}),e.jsxs("p",{className:"text-sm text-gray-900 py-2",children:[a.firstName," ",a.lastName]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),e.jsx("p",{className:"text-sm text-gray-900 py-2",children:a.emailAddress})]})]}),l&&e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-gray-50 p-4 mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Your stand tent"}),e.jsx("p",{className:"text-xs text-gray-500",children:"The folded name card for your music stand. Print, fold, done â reprint any time."})]}),e.jsx(N,{type:"button",variant:"secondary",size:"sm",onClick:()=>Ne.openPdf(Ne.myTentUrl()),children:"Print my stand tent"})]})]}),l&&e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Instruments"}),Y.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loading instruments..."}):e.jsx(we,{instruments:Y,selectedIds:(D??[]).map(t=>t.instrumentId),onChange:pe,allowCreate:!1})]})]}),R==="instruments"&&e.jsx("div",{className:"space-y-6",children:e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Instruments"}),Y.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loading instruments..."}):e.jsx(we,{instruments:Y,selectedIds:(D??[]).map(t=>t.instrumentId),onChange:pe,onCreated:t=>ue(r=>[...r,t])})]})}),R==="ensembles"&&e.jsx("div",{className:"space-y-6",children:e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Ensembles"}),xe.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No ensembles defined for this organization."}):e.jsx("div",{className:"space-y-2",children:xe.map(t=>{const r=($??[]).includes(t.id),i=(D??[]).map(u=>{const j=Y.find(w=>w.id===u.instrumentId);return j?{value:j.id,label:j.name}:null}).filter(Boolean);return e.jsxs("div",{className:`flex items-center gap-3 rounded-lg border px-4 py-3 transition-colors ${r?"border-band-300 bg-band-50":"border-gray-200 bg-white"}`,children:[e.jsx("input",{type:"checkbox",checked:r,onChange:()=>De(t.id),className:"h-4 w-4 rounded border-gray-300 text-band-600 focus:ring-band-500"}),e.jsx("span",{className:`text-sm font-medium flex-1 ${r?"text-gray-900":"text-gray-500"}`,children:t.name}),r&&i.length>1&&e.jsx(K,{value:te[t.id]||"",onChange:u=>U(j=>({...j,[t.id]:u.target.value||null})),options:[{value:"",label:"Select instrumentâ¦"},...i],className:"w-48"}),r&&i.length===1&&e.jsx("span",{className:"text-xs text-gray-500",children:i[0].label}),r&&i.length===0&&e.jsx("span",{className:"text-xs text-gray-400",children:"Select instruments first"})]},t.id)})})]})}),R==="contact"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Details"}),e.jsxs("div",{className:"flex items-center gap-6 mb-4",children:[e.jsx("div",{className:"shrink-0",children:se?e.jsx("img",{src:se,alt:"Profile",className:"h-20 w-20 rounded-full object-cover ring-2 ring-gray-200"}):e.jsx("div",{className:"h-20 w-20 rounded-full bg-band-100 text-band-700 flex items-center justify-center text-xl font-semibold ring-2 ring-gray-200",children:Le})}),e.jsxs("div",{children:[e.jsx(N,{type:"button",variant:"secondary",size:"sm",onClick:()=>de.current?.click(),children:se?"Change photo":"Upload photo"}),e.jsx(Xe,{label:"Take a photo",onChange:ge,className:"mt-1.5"}),L&&e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:L.name}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"JPEG, PNG, or WebP · max 5 MB"}),e.jsx("input",{ref:de,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:ge,"aria-label":"Upload profile photo"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"Birthday",type:"date",value:a.birthday,onChange:t=>d("birthday",t.target.value)}),!l&&e.jsx(f,{label:"Member Since",type:"date",value:a.onboardingDate,onChange:t=>d("onboardingDate",t.target.value)})]}),e.jsx("div",{className:"mt-4",children:e.jsx(f,{label:"Profession",value:a.profession,onChange:t=>d("profession",t.target.value),placeholder:"e.g. Teacher, Engineerâ¦"})}),e.jsxs("div",{className:"mt-4",children:[e.jsx(ve,{label:"Bio",value:a.bio,onChange:t=>d("bio",t.target.value),maxLength:500,rows:4,placeholder:"A short biography (optional)"}),e.jsxs("p",{className:"mt-1 text-xs text-gray-400 text-right",children:[a.bio?.length??0," / 500"]})]}),(a.memberType==="director"||(a.orgRoles||[]).some(t=>t==="music_director"||t==="assistant_conductor")||!!a.programBio)&&e.jsxs("div",{className:"mt-4",children:[e.jsx(ve,{label:"Program bio",value:a.programBio,onChange:t=>d("programBio",t.target.value),maxLength:3e3,rows:8}),e.jsxs("p",{className:"mt-1 text-xs text-gray-500",children:["Printed with the photo above under âAbout our conductorsâ when a concert program is exported. Write it for the audience. ",a.programBio?.length??0," / 3000"]})]})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Address & Phone"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{label:"Phone",value:a.p
1hone,onChange:t=>d("phone",ae(t.target.value)),placeholder:"(555) 555-5555"}),T&&h&&e.jsx(nt,{memberId:h,hasPhone:!!a.phone?.trim()}),e.jsx(f,{label:"Street Address",value:a.street,onChange:t=>d("street",t.target.value),placeholder:"123 Main St"}),e.jsx(f,{label:"Street Address Line 2",value:a.street2,onChange:t=>d("street2",t.target.value),placeholder:"Apt, Suite, Unit, etc."}),e.jsxs("div",{className:"grid grid-cols-6 gap-4",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"City",value:a.city,onChange:t=>d("city",t.target.value),placeholder:"Springfield"})}),e.jsx("div",{className:"col-span-2",children:e.jsx(K,{label:"State",options:et,value:a.state,onChange:t=>d("state",t.target.value)})}),e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"Zip Code",value:a.zip,onChange:t=>d("zip",t.target.value),placeholder:"62701"})})]}),e.jsx(f,{label:"County",value:a.county,onChange:t=>d("county",t.target.value),placeholder:"Sangamon"})]})]}),(l||M("members:read_sensitive"))&&e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Emergency Contact"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"Name",value:a.emergencyContactName,onChange:t=>d("emergencyContactName",t.target.value),placeholder:"Jane Doe"}),e.jsx(f,{label:"Relationship",value:a.emergencyContactRelationship,onChange:t=>d("emergencyContactRelationship",t.target.value),placeholder:"Spouse"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"Email Address",type:"email",value:a.emergencyContactEmail,onChange:t=>d("emergencyContactEmail",t.target.value),placeholder:"[email protected]"}),e.jsx(f,{label:"Phone",value:a.emergencyContactPhone,onChange:t=>d("emergencyContactPhone",ae(t.target.value)),placeholder:"(555) 555-5555"})]})]})]}),(l||M("members:read_sensitive"))&&e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Communication Proxy"}),e.jsxs("label",{className:"flex items-center gap-2 mb-4 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:a.communicationProxy||!1,onChange:t=>d("communicationProxy",t.target.checked),className:"rounded border-gray-300 text-brand-primary focus:ring-brand-primary h-4 w-4"}),e.jsx("span",{className:"text-sm text-gray-700",children:"Route notifications to a proxy contact"})]}),a.communicationProxy&&e.jsxs("div",{className:"space-y-4 pl-6 border-l-2 border-brand-primary/20",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Send communications to"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"proxyMode",checked:(a.proxyMode||"replace")==="replace",onChange:()=>d("proxyMode","replace"),className:"mt-0.5 border-gray-300 text-brand-primary focus:ring-brand-primary h-4 w-4"}),e.jsxs("span",{className:"text-sm text-gray-700",children:["Proxy only ",e.jsx("span",{className:"text-gray-500",children:"â the member won't receive email"})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"proxyMode",checked:a.proxyMode==="both",onChange:()=>d("proxyMode","both"),className:"mt-0.5 border-gray-300 text-brand-primary focus:ring-brand-primary h-4 w-4"}),e.jsxs("span",{className:"text-sm text-gray-700",children:["Both member and proxy ",e.jsx("span",{className:"text-gray-500",children:"â each gets a copy (e.g. parent and child)"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"Name",value:a.proxyName,onChange:t=>d("proxyName",t.target.value),placeholder:"Jane Doe"}),e.jsx(f,{label:"Relationship",value:a.proxyRelationship,onChange:t=>d("proxyRelationship",t.target.value),placeholder:"Parent"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(f,{label:"Email Address",type:"email",value:a.proxyEmail,onChange:t=>d("proxyEmail",t.target.value),placeholder:"[email protected]"}),e.jsx(f,{label:"Phone",value:a.proxyPhone,onChange:t=>d("proxyPhone",ae(t.target.value)),placeholder:"(555)555-5555"})]}),a.communicationProxy&&!a.proxyEmail&&!a.proxyPhone&&e.jsx("p",{className:"text-xs text-amber-600",children:"Add a proxy email or phone so this member can be reached."})]})]})]}),R==="history"&&T&&e.jsx(at,{memberId:h}),R==="admin"&&T&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(st,{memberId:h,proxyName:a.proxyName}),e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-1",children:"Roles & Access"}),e.jsx("p",{className:"text-xs text-gray-400 mb-4",children:"These titles determine what this member can do. Access is the combined total of every role checked."}),s?.id===m?.memberId&&!Z?e.jsx("p",{className:"text-sm text-gray-500",children:"You cannot change your own roles."}):W?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:tt.map(t=>{const r=(a.orgRoles??[]).includes(t.value);return e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-700 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r,onChange:()=>
1Te(t.value),className:"h-4 w-4 rounded border-gray-300 text-band-600 focus:ring-band-500"}),t.label]},t.value)})}),s&&!s.hasUserAccount&&e.jsx("p",{className:"text-xs text-gray-400 mt-3",children:"This member has no login account yet â roles take effect once a login is created."})]}):e.jsx("p",{className:"text-sm text-gray-400",children:"You don't have permission to change roles."}),e.jsx(ot,{memberId:h,driverDocumentsOnFile:s?.driverDocumentsOnFile})]}),x&&e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"Danger Zone"}),e.jsxs("div",{className:"rounded-lg border border-red-200 bg-red-50 p-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-800",children:"Delete this member"}),e.jsx("p",{className:"text-xs text-red-600 mt-0.5",children:"This action cannot be undone."})]}),e.jsx(N,{type:"button",variant:"danger",size:"sm",isLoading:ce,onClick:()=>Q(!0),children:"Delete member"})]})]})]}),(()=>{const t=l?["personal","contact"]:["personal","contact","instruments","ensembles",...T?["admin","history"]:[]],r=t.indexOf(R),i=r===0,u=r===t.length-1;return p?e.jsxs("div",{className:"flex items-center justify-between pt-4 mt-6 border-t border-gray-200",children:[e.jsx(N,{type:"button",variant:"secondary",onClick:()=>_(t[r-1]),disabled:i,children:"Back"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>y(`/members/${h}`),disabled:F,children:"Skip for now"}),u?e.jsx(N,{type:"button",isLoading:F,onClick:()=>ye(),children:k?"Save profile & send welcome":"Save profile"},"complete"):e.jsx(N,{type:"button",onClick:()=>_(t[r+1]),children:"Next"},"next")]})]}):e.jsxs("div",{className:"flex items-center gap-3 pt-4 mt-6 border-t border-gray-200",children:[e.jsx(N,{type:"submit",isLoading:F,disabled:!be,children:"Save changes"}),e.jsx(N,{type:"button",variant:"secondary",onClick:()=>y(l?"/":`/members/${h}`),disabled:F,children:"Cancel"}),l&&e.jsx(N,{type:"button",variant:"ghost",onClick:()=>y("/account/change-password"),className:"ml-auto",children:"Change password"})]})})()]})})]})}export{Pt as MemberEditPage};
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.