1import{r as i,ab as We,bO as Qe,s as g,b8 as Te,j as e,cc as dt,cd as mt,ce as ut,cf as ht,aD as Ke,cg as gt,aj as I,c7 as pt,ch as Fe,bg as Xe,ci as xt,aO as X,c as ft,d as bt,v as H,cj as yt,ck as N,cl as Y,aW as vt,bI as B,ac as jt,aI as Nt,m as _t,cm as Me,cn as wt,aw as z,ay as Z,at as St,au as Ct,av as kt,co as Oe,g as At,aY as Dt,a_ as Ie,a$ as Le,b0 as Ue,b1 as qe,b2 as T,E as Et,U as Pt,ax as Tt}from"./index-CGIDmj67.js";import{C as Ft}from"./CommunityFooter-BmuyQ8BW.js";import{C as te,a as se,b as ae,d as Ze,c as ie}from"./card-Cvg9c-km.js";import{S as re}from"./separator-CraldfF0.js";import{u as Mt,c as Ot,p as v,l as ee,t as It,L as Lt,P as Ut}from"./LocationAutocomplete-BRM60ncF.js";import{compressAvatarFile as qt}from"./imageCompression-RSJ7V_pE.js";import{M as Rt,c as Bt}from"./MemberPortalHeader-hm1yUWHQ.js";import{Q as $t}from"./index-tW8edAuc.js";import{A as Re,a as Be,b as $e,c as Ve,d as He,e as Ge,f as Je,g as ze}from"./alert-dialog-Dr1GlKwx.js";import{B as Vt}from"./briefcase-ByBbYzxA.js";import"./leaflet-ZFqd1fNr.js";import"./log-out-CxNb9SIr.js";import"./trending-up-DdkjFtJt.js";const Ht=()=>{const[t,h]=i.useState(!1),[j,b]=i.useState(!1),[k,_]=i.useState(null),{user:f,profile:s,refreshProfile:w}=We(),{toast:m}=Qe(),A=async r=>{if(Ot("save"),v("save","validate","info","Starting profile save",{detail:{fields_changing:Object.keys(r)}}),!(s!=null&&s.id))return v("save","validate","error","No authenticated profile in context"),m({title:"Error",description:"You must be logged in to update your profile.",variant:"destructive"}),!1;v("save","validate","success",`Profile context OK (id=${s.id.slice(0,8)}â¦)`),h(!0);const p={...r};p.email!==void 0&&p.email!==s.email&&(console.warn("[useProfileUpdate] Ignoring email change in payload â use adminUpdateEmail() to keep profiles.email and auth.users.email in sync."),delete p.email);try{const a=Date.now(),{error:l,data:c}=await g.from("profiles").update({...p,updated_at:new Date().toISOString()}).eq("id",s.id).select("id").maybeSingle();if(l)return v("save","profiles_update","error",`profiles UPDATE failed: ${l.message}`,{durationMs:Date.now()-a,error:l}),console.error("Error updating profile:",l),m({title:"Error",description:"Failed to save your profile. Please try again.",variant:"destructive"}),!1;v("save","profiles_update",c?"success":"warn",c?"profiles UPDATE OK":"profiles UPDATE returned no row (RLS or id mismatch?)",{durationMs:Date.now()-a,detail:{row_returned:!!c}});const u=new Date().toISOString();_(u),await D(r);const x=Date.now();await w(),v("save","refresh_profile","success","Profile context refreshed",{durationMs:Date.now()-x}),m({title:"Profile Updated",description:"Your changes have been saved successfully."});try{const d={...s,...r};if([d.first_name,d.last_name,d.job_title,d.company_name,d.city,d.country,d.bio,d.linkedin_url].every(q=>typeof q=="string"&&q.trim().length>0)){const{count:q}=await g.from("member_events").select("id",{count:"exact",head:!0}).eq("member_id",s.id).eq("event_type","profile_completed");q||Te("profile_completed",null,s.id)}(r.open_to_virtual_meetups===!0&&s.open_to_virtual_meetups!==!0||r.open_to_f2f_meetups===!0&&s.open_to_f2f_meetups!==!0)&&Te("meetup_preference_enabled",{virtual:!!r.open_to_virtual_meetups,f2f:!!r.open_to_f2f_meetups},s.id)}catch(d){console.warn("engagement signal emit failed:",d)}return!0}catch(a){return v("save","profiles_update","error","Unexpected error during save",{error:a}),console.error("Error in updateProfile:",a),m({title:"Error",description:"An unexpected error occurred. Please try again.",variant:"destructive"}),!1}finally{h(!1)}},D=async r=>{if(!(s!=null&&s.id))return;const p=r.is_visible??s.is_visible,a=Date.now(),{data:l,error:c}=await g.from("directory_members").select("id").eq("profile_id",s.id).maybeSingle();if(c?v("save","directory_lookup","error",`directory_members lookup failed: ${c.message}`,{durationMs:Date.now()-a,error:c}):v("save","directory_lookup","success",l?"Found existing directory_members row":"No existing directory_members row",{durationMs:Date.now()-a,detail:{is_visible:p}}),p){const u={profile_id:s.id,email:s.email,first_name:r.first_name??s.first_name??"",last_name:r.last_name??s.last_name??"",avatar_url:s.avatar_url,job_title:r.job_title??s.job_title,company_name:r.company_name??s.company_name,city:r.city??s.city,state:r.state??s.state,country:r.country??s.c
1ountry,place_id:r.place_id??s.place_id,bio:r.bio??s.bio,linkedin_url:r.linkedin_url??s.linkedin_url,coordinates_lat:r.coordinates_lat??s.coordinates_lat,coordinates_lng:r.coordinates_lng??s.coordinates_lng,job_function_summary:r.job_function_summary??s.job_function_summary??null,is_visible:!0,is_champion:s.is_champion,available_for_messaging:r.available_for_messaging??s.available_for_messaging,open_to_virtual_meetups:r.open_to_virtual_meetups??s.open_to_virtual_meetups,open_to_f2f_meetups:r.open_to_f2f_meetups??s.open_to_f2f_meetups},x=Date.now();if(l){const{error:d}=await g.from("directory_members").update(u).eq("id",l.id);d?v("save","directory_sync","error",`directory_members UPDATE failed: ${d.message}`,{durationMs:Date.now()-x,error:d}):v("save","directory_sync","success","directory_members row updated",{durationMs:Date.now()-x})}else{const{error:d}=await g.from("directory_members").insert(u);d?v("save","directory_sync","error",`directory_members INSERT failed: ${d.message}`,{durationMs:Date.now()-x,error:d}):v("save","directory_sync","success","directory_members row inserted",{durationMs:Date.now()-x})}}else if(l){const u=Date.now(),{error:x}=await g.from("directory_members").delete().eq("id",l.id);x?v("save","directory_sync","error",`directory_members DELETE failed: ${x.message}`,{durationMs:Date.now()-u,error:x}):v("save","directory_sync","success","directory_members row removed (not visible)",{durationMs:Date.now()-u})}else v("save","directory_sync","info","Skipped â not visible and no existing row")};return{isSaving:t,isUploadingAvatar:j,lastSaveAt:k,updateProfile:A,uploadAvatar:async r=>{if(!(f!=null&&f.id))return m({title:"Error",description:"You must be logged in to upload an avatar.",variant:"destructive"}),null;if(!r.type.startsWith("image/"))return m({title:"Invalid File",description:"Please upload an image file.",variant:"destructive"}),null;if(r.size>5*1024*1024)return m({title:"File Too Large",description:"Please upload an image smaller than 5MB.",variant:"destructive"}),null;b(!0);try{const a=await qt(r).catch(L=>(console.warn("Avatar compression failed, uploading original:",L),null))??r,l=`${f.id}/avatar.jpg`,{error:c}=await g.storage.from("avatars").upload(l,a,{upsert:!0,contentType:"image/jpeg"});if(c)return console.error("Error uploading avatar:",c),m({title:"Upload Failed",description:"Failed to upload your photo. Please try again.",variant:"destructive"}),null;const{data:u}=g.storage.from("avatars").getPublicUrl(l),x=`${u.publicUrl}?t=${Date.now()}`,{error:d}=await g.from("profiles").update({avatar_url:x,updated_at:new Date().toISOString()}).eq("id",s==null?void 0:s.id);if(d)return console.error("Error updating avatar URL:",d),m({title:"Error",description:"Failed to save avatar. Please try again.",variant:"destructive"}),null;await w();const E=[s==null?void 0:s.first_name,s==null?void 0:s.last_name].filter(Boolean).join(" ").trim()||(s!=null&&s.email?s.email.split("@")[0]:"")||"Member avatar";return Mt({bucket:"avatars",storagePath:l,publicUrl:u.publicUrl,alt:E,category:"member",subjectType:"face_member",fileName:"avatar.jpg",mimeType:"image/jpeg",sizeBytes:a.size}),m({title:"Photo Updated",description:"Your profile photo has been updated."}),x}catch(p){return console.error("Error in uploadAvatar:",p),m({title:"Error",description:"An unexpected error occurred. Please try again.",variant:"destructive"}),null}finally{b(!1)}},deleteAvatar:async()=>{if(!(f!=null&&f.id)||!(s!=null&&s.id))return m({title:"Error",description:"You must be logged in to remove your photo.",variant:"destructive"}),!1;b(!0);try{const r=`${f.id}/avatar.jpg`,{error:p}=await g.storage.from("avatars").remove([r]);p&&console.warn("Avatar storage remove failed (continuing):",p);const{error:a}=await g.from("profiles").update({avatar_url:null,updated_at:new Date().toISOString()}).eq("id",s.id);return a?(console.error("Error clearing avatar URL:",a),m({title:"Error",description:"Failed to remove your photo. Please try again.",variant:"destructive"}),!1):(await w(),m({title:"Photo Removed",description:"Your profile photo has been removed."}),!0)}catch(r){return console.error("Error in deleteAvatar:",r),m({title:"Error",description:"An unexpected error occurred. Please try again.",variant:"destructive"}),!1}finally{b(!1)}}}},Gt=({status:t})=>t==="success"?e.jsx(ft,{className:"w-3.5 h-3.5 text-emerald-600"}):t==="error"?e.jsx(bt,{className:"w-3.5 h-3.5 text-destructive"}):e.jsx(H,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"}),$=({label:t,value:h})=>e.jsxs("div",{className:"flex items-baseline justify-between gap-3 text-xs py-0.5",children:[e.jsx("span",{className:"text-muted-foreground",children:t}),e.jsx("span",{className:"font-mono text-foreground text-right break-all",children:h??e.jsx("em",{className:"text-muted-foreground
1/60",children:"null"})})]}),Ye=({title:t,v:h})=>{var j,b;return e.jsxs("div",{className:"border border-border rounded-md p-3 bg-muted/30",children:[e.jsx("div",{className:"text-xs font-semibold text-foreground mb-2",children:t}),e.jsx($,{label:"city",value:h.city}),e.jsx($,{label:"state",value:h.state}),e.jsx($,{label:"country",value:h.country}),e.jsx($,{label:"country_code",value:h.country_code}),e.jsx($,{label:"coordinates_lat",value:(j=h.coordinates_lat)==null?void 0:j.toString()}),e.jsx($,{label:"coordinates_lng",value:(b=h.coordinates_lng)==null?void 0:b.toString()}),e.jsx($,{label:"place_id",value:h.place_id})]})},Jt=({open:t,onOpenChange:h,formValue:j,persistedValue:b,profileId:k})=>{const _=i.useSyncExternalStore(ee.subscribe,ee.getSnapshot,ee.getSnapshot),[f,s]=i.useState("idle"),[w,m]=i.useState(null),[A,D]=i.useState(null),F=i.useMemo(()=>JSON.stringify(j)!==JSON.stringify(b),[j,b]),U=async()=>{s("checking"),m(null);try{const{data:a,error:l}=await g.functions.invoke("get-mapbox-token");if(l)throw l;const c=(a==null?void 0:a.token)||null;if(!c){s("error"),m("Edge function returned no token");return}D(`${c.slice(0,8)}â¦`),s("ok"),m(`Token received (${c.length} chars)`)}catch(a){s("error"),m((a==null?void 0:a.message)||String(a))}},r=async()=>{try{const{data:a}=await g.functions.invoke("get-mapbox-token"),l=a==null?void 0:a.token;if(!l){X.error("No token");return}await It("forward_geocode",'Sample test query: "London"',async()=>{const c=await fetch(`https://api.mapbox.com/search/geocode/v6/forward?q=London&types=place&limit=3&access_token=${l}`),u=await c.json();if(!c.ok)throw new Error(`HTTP ${c.status}: ${(u==null?void 0:u.message)||c.statusText}`);return{status:c.status,body:u}},c=>({status:c.status,featureCount:(c.body.features||[]).length})),X.success("Sample geocode complete â see log")}catch(a){X.error((a==null?void 0:a.message)||"Sample geocode failed")}},p=()=>{const a={profileId:k,formValue:j,persistedValue:b,formIsDirty:F,edge:{status:f,detail:w,tokenSample:A},entries:_,capturedAt:new Date().toISOString()};navigator.clipboard.writeText(JSON.stringify(a,null,2)),X.success("Diagnostics copied to clipboard")};return i.useEffect(()=>{t&&f==="idle"&&U()},[t]),e.jsx(dt,{open:t,onOpenChange:h,children:e.jsxs(mt,{className:"max-w-3xl max-h-[85vh] overflow-y-auto",children:[e.jsxs(ut,{children:[e.jsxs(ht,{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"w-5 h-5"})," Location field diagnostics"]}),e.jsx(gt,{children:"Admin-only. Shows backend calls, edge function status, parsed Mapbox responses, and stored profile values."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border border-border rounded-md p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-sm font-semibold",children:"Edge function: get-mapbox-token"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(I,{size:"sm",variant:"outline",onClick:U,disabled:f==="checking",children:[e.jsx(pt,{className:`w-3.5 h-3.5 mr-1.5 ${f==="checking"?"animate-spin":""}`}),"Re-check"]}),e.jsx(I,{size:"sm",variant:"outline",onClick:r,children:"Test geocode"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(Fe,{variant:f==="ok"?"default":f==="error"?"destructive":"secondary",children:f}),e.jsx("span",{className:"text-muted-foreground",children:w??"â"}),A&&e.jsx("span",{className:"font-mono text-muted-foreground",children:A})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsx(Ye,{title:`Form value${F?" (unsaved)":""}`,v:j}),e.jsx(Ye,{title:"Persisted in profile",v:b})]}),F&&e.jsx("p",{className:"text-xs text-amber-600",children:"Form differs from persisted value. Click Save Changes to persist."}),e.jsxs("div",{className:"border border-border rounded-md",children:[e.jsxs("div",{className:"flex items-center justify-between p-2 border-b border-border",children:[e.jsxs("div",{className:"text-sm font-semibold",children:["Operation log (",_.length,")"]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(I,{size:"sm",variant:"ghost",onClick:p,children:[e.jsx(Xe,{className:"w-3.5 h-3.5 mr-1.5"})," Copy all"]}),e.jsxs(I,{size:"sm",variant:"ghost",onClick:()=>ee.clear(),children:[e.jsx(xt,{className:"w-3.5 h-3.5 mr-1.5"})," Clear"]})]})]}),e.jsx("div",{className:"max-h-[280px] overflow-y-auto divide-y divide-border",children:_.length===0?e.jsx("div",{className:"text-xs text-muted-foreground p-3",children:'No operations recorded. Try typing in the location search or clicking "Test geocode" above.'}):_.map(a=>e.jsxs("details",{className:"text-xs",children:[e.jsxs("summary",{className:"flex items-center gap-2 p-2 cursor-pointer hover:bg-muted/40 list-none",children:[e.jsx(Gt,{status:a.status}),e.jsx("span",{className:"font-mono text-muted-foreground shrink-0",children:new Date(a.ts).toLocaleTimeString()}),e.jsx(Fe,{variant:"outline",className:"text-[10px] px-1 py-0",children:a.op}),e.jsx("span",{className:"flex-1 truncate text-foreground",children:a.message}),typeof a.durationMs=="number"&&e.jsxs("span",{className:"text-muted-foreground shrink-0",children:[a.durationMs,"ms"]})]}),a.detail!==void 0&&e.jsx("pre",{className:"px-3 pb-2 text-[11px] font-mono bg-muted/20 overflow-x-auto whitespace-pre-wrap break-all",children:JSON.stringify(a.detail,null,2)})]},a.id))})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Profile ID: ",e.jsx("span",{className:"font-mono",children:k??"â"})]})]})]})})},zt=()=>{const{toast:t}=Qe(),[h,j]=i.useState(!0),[b,k]=i.useState(!1),[_,f]=i.useState(null),[s,w]=i.useState(null),[m,A]=i.useState(null),[D,F]=i.useState(null),[U,r]=i.useState(!1),[p,a]=i.useState(""),[l,c]=i.useState(!1),[u,x]=i.useState(""),[d,E]=i.useState(!1),L=async()=>{j(!0);const{data:n,error:S}=await g.auth.mfa.listFactors();if(S){t({title:"Could not load 2FA status",description:S.message,variant:"destructive"}),j(!1);return}const y=((n==null?void 0:n.totp)||[]).find(M=>M.status==="verified");y?(k(!0),f(y.id)):(k(!1),f(null)),j(!1)};i.useEffect(()=>{L()},[]);const G=async()=>{c(!0);try{const{data:n}=await g.auth.mfa.listFactors(),S=((n==null?void 0:n.totp)||[]).filter(V=>V.status!=="verified");for(const V of S)await g.auth.mfa.unenroll({factorId:V.id});const{data:y,error:M}=await g.auth.mfa.enroll({factorType:"totp",friendlyName:`WeQual ${new Date().toISOString().slice(0,10)}`});if(M)throw M;w(y.id),A(y.totp.uri),F(y.totp.secret),a("")}
1catch(n){t({title:"Could not start 2FA setup",description:n.message,variant:"destructive"})}finally{c(!1)}},q=async()=>{s&&await g.auth.mfa.unenroll({factorId:s}),w(null),A(null),F(null),a("")},R=async()=>{if(!(!s||p.length!==6)){c(!0);try{const{data:n,error:S}=await g.auth.mfa.challenge({factorId:s});if(S)throw S;const{error:y}=await g.auth.mfa.verify({factorId:s,challengeId:n.id,code:p});if(y)throw y;t({title:"2FA enabled",description:"Your account is now protected by an authenticator app."}),w(null),A(null),F(null),a(""),await L()}catch(n){t({title:"Code incorrect",description:n.message||"Please try again.",variant:"destructive"})}finally{c(!1)}}},W=async()=>{if(!(!_||u.length!==6)){c(!0);try{const{data:n,error:S}=await g.auth.mfa.challenge({factorId:_});if(S)throw S;const{error:y}=await g.auth.mfa.verify({factorId:_,challengeId:n.id,code:u});if(y)throw y;const{error:M}=await g.auth.mfa.unenroll({factorId:_});if(M)throw M;t({title:"2FA disabled"}),x(""),E(!1),await L()}catch(n){t({title:"Could not disable 2FA",description:n.message,variant:"destructive"})}finally{c(!1)}}},Q=async n=>{n&&!b?await G():!n&&b&&E(!0)},ne=async()=>{D&&(await navigator.clipboard.writeText(D),r(!0),setTimeout(()=>r(!1),1500))};return e.jsxs(te,{className:"bg-white border-border",children:[e.jsxs(se,{children:[e.jsxs(ae,{className:"text-midnight flex items-center gap-2",children:[e.jsx(yt,{className:"w-5 h-5 text-community"}),"2FA Security"]}),e.jsx(Ze,{className:"text-midnight/60",children:"Add a second step at sign-in using an authenticator app (Google Authenticator, 1Password, Authy, etc.)."})]}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(N,{htmlFor:"twofa-toggle",className:"text-midnight font-medium",children:"Two-factor authentication"}),e.jsx("p",{className:"text-sm text-midnight/60",children:h?"Checkingâ¦":b?"Enabled â required at sign-in.":"Off â only your password is required."})]}),e.jsx(Y,{id:"twofa-toggle",checked:b||!!s,disabled:h||l,onCheckedChange:Q})]}),s&&m&&e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"bg-muted"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-midnight font-medium mb-1",children:"Step 1 â Scan the QR code"}),e.jsx("p",{className:"text-sm text-midnight/60",children:"Open your authenticator app and scan this code. If you can't scan, enter the secret manually."})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-start gap-6",children:[e.jsx("div",{className:"bg-white p-4 border border-border rounded-md",children:e.jsx($t,{value:m,size:180})}),D&&e.jsxs("div",{className:"space-y-2 flex-1",children:[e.jsx(N,{className:"text-midnight/70 text-sm",children:"Manual secret"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted border border-border rounded text-sm font-mono break-all",children:D}),e.jsx(I,{type:"button",size:"sm",variant:"outline",onClick:ne,children:U?e.jsx(vt,{className:"w-4 h-4"}):e.jsx(Xe,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-xs text-midnight/50",children:"Account: WeQual · Type: Time-based (TOTP) · 6 digits"})]})]}),e.jsx(re,{className:"bg-muted"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-midnight font-medium mb-1",children:"Step 2 â Enter the 6-digit code"}),e.jsx("p",{className:"text-sm text-midnight/60 mb-3",children:"Type the code your authenticator app shows right now."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(B,{inputMode:"numeric",maxLength:6,value:p,onChange:n=>a(n.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"123456",className:"w-40 font-mono text-lg tracking-widest",autoComplete:"one-time-code"}),e.jsxs(I,{onClick:R,disabled:l||p.length!==6,children:[l&&e.jsx(H,{className:"w-4 h-4 mr-2 animate-spin"}),"Verify & enable"]}),e.jsx(I,{type:"button",variant:"ghost",onClick:q,disabled:l,children:"Cancel"})]})]})]})]}),d&&b&&e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"bg-muted"}),e.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/30 bg-destructive/5 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-midnight font-medium",children:"Disable 2FA"}),e.jsx("p",{className:"text-sm text-midnight/60",children:"Enter your current authenticator code to confirm."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(B,{inputMode:"numeric",maxLength:6,value:u,onChange:n=>x(n.target.value.replace(/\D/g,"").slice(0,6)),placeholder:"123456",className:"w-40 font-mono text-lg tracking-widest",autoComplete:"one-time-code"}),e.jsxs(I,{variant:"destructive",onClick:W,disabled:l||u.length!==6,children:[l&&e.jsx(H,{className:"w-4 h-4 mr-2 animate-spin"}),"Disable"]}
1),e.jsx(I,{type:"button",variant:"ghost",onClick:()=>{E(!1),x("")},disabled:l,children:"Cancel"})]})]})]})]})]})},Yt=[{match:/\bchief of staff\b/i,summary:"Strategy / Transformation",confidence:"medium"},{match:/\b(commercial)\b/i,summary:"Sales / Business Development",confidence:"medium"},{match:/\btransformation\b/i,summary:"Strategy / Transformation",confidence:"medium"},{match:/\bcmo\b/i,summary:"Marketing / Communications",confidence:"high"},{match:/\bcfo\b/i,summary:"Finance",confidence:"high"},{match:/\bchro\b/i,summary:"People / HR",confidence:"high"},{match:/\b(cio|cto|ciso)\b/i,summary:"Technology / Data",confidence:"high"},{match:/\bcpo\b/i,summary:"Product",confidence:"high"},{match:/\bcro\b/i,summary:"Sales / Business Development",confidence:"high"},{match:/\bcoo\b/i,summary:"Operations / Supply Chain",confidence:"high"},{match:/\bcco\b/i,summary:"Customer / Client",confidence:"medium"},{match:/\bcso\b/i,summary:"Strategy / Transformation",confidence:"medium"},{match:/\bcdo\b/i,summary:"Technology / Data",confidence:"medium"},{match:/\b(ceo|president|managing director|general manager)\b/i,summary:"Executive / General Management",confidence:"high"},{match:/\b(md)\b/i,summary:"Executive / General Management",confidence:"medium"},{match:/\b(chief medical officer|medical director|clinical|physician|surgeon|nurse|pharmac|oncolog|cardiolog|radiolog)\b/i,summary:"Medical / Clinical / Healthcare",confidence:"high"},{match:/\b(r&d|research and development|head of r&d|research director|principal scientist|scientific affairs|scientist)\b/i,summary:"Research / Science",confidence:"high"},{match:/\b(sustainability|esg|csr|corporate affairs|corporate social responsibility)\b/i,summary:"ESG / Sustainability / Corporate Affairs",confidence:"high"},{match:/\b(procurement|sourcing|chief procurement)\b/i,summary:"Procurement / Commercial",confidence:"high"},{match:/\b(pmo|programme director|program director|project director|programme manager|program manager|project manager)\b/i,summary:"Project / Program Management",confidence:"high"},{match:/\b(customer success|customer experience|client services|client success|head of customer|chief customer)\b/i,summary:"Customer / Client",confidence:"high"},{match:/\b(strategy|chief strategy|innovation director|head of innovation|m&a)\b/i,summary:"Strategy / Transformation",confidence:"high"},{match:/\b(engineering director|head of engineering|technical director|chief engineer)\b/i,summary:"Engineering",confidence:"high"},{match:/\b(head of technology|head of data|head of ai|head of it|it director|data director|data science|machine learning|software|devops|infrastructure|cybersecurity|security)\b/i,summary:"Technology / Data",confidence:"high"},{match:/\b(head of product|product director|vp product|product management|product owner|product lead)\b/i,summary:"Product",confidence:"high"},{match:/\b(marketing|brand|communications|comms|public relations|demand generation|content)\b/i,summary:"Marketing / Communications",confidence:"high"},{match:/\b(sales|business development|partnerships|revenue|account executive|account manager)\b/i,summary:"Sales / Business Development",confidence:"high"},{match:/\b(operations|supply chain|logistics|manufacturing|procurement|facilities)\b/i,summary:"Operations / Supply Chain",confidence:"high"},{match:/\b(general counsel|counsel|legal|compliance|risk|privacy|regulatory)\b/i,summary:"Legal / Compliance / Risk",confidence:"high"},{match:/\b(people|talent|hr|human resources|learning|l&d)\b/i,summary:"People / HR",confidence:"high"},{match:/\b(finance|controller|treasur|fp&a|tax|accounting|audit)\b/i,summary:"Finance",confidence:"high"}];function Wt(t){if(!t||!t.trim())return{summary:null,confidence:null};for(const h of Yt)if(h.match.test(t))return{summary:h.summary,confidence:h.confidence};return{summary:null,confidence:null}}const ms=()=>{const{profile:t,memberships:h,isLoading:j}=We(),{activeMemberTypeLabel:b}=jt(),{isAdmin:k,isUserAdmin:_,isContentAdmin:f,isWebsiteAdmin:s,isWequalUser:w,isWequalSales:m}=Nt(),A=k||_||f||s||w||m,D=k||w,[F,U]=i.useState(!1),{isSaving:r,isUploadingAvatar:p,lastSaveAt:a,updateProfile:l,uploadAvatar:c}=Ht(),u=i.useRef(null),[x,d]=i.useState(""),[E,L]=i.useState(""),[G,q]=i.useState(""),[R,W]=i.useState(""),[Q,ne]=i.useState(""),[n,S]=i.useState({city:null,state:null,country:null,country_code:null,coordinates_lat:null,coordinates_lng:null,place_id:null}),[y,M]=i.useState(""),[V,ue]=i.useState(""),[oe,he]=i.useState(!0),[ge,pe]=i.useState(!0),[xe,fe]=i.useState(!1),[be,ye]=i.useState(!1),[ce,ve]=i.useState(null),[je,Ne]=i.useState(""),[_e,we]=i.useState(""),[Se,Ce]=i.useState(null),[et,ke]=i.useState(null),[Qt,le]=i.useState(null),[Kt,Ae]=i.useState(!1);i.useEffect(()=>{t&&(d(t.first_name||""),L(t.last_name||""),q(t.email||""),W(t.job_title||t.role||""),ne(t.company_name||""),S({city:t.city??null,state:t.state??null,country:t.country??null,country_code:t.country_code??null,coordinates_lat:t.coordinates_lat??null,coordinates_lng:t.coordinates_lng??null,place_id:t.place_id??null}),M(t.bio||""),ue(t.linkedin_url||""),he(t.is_visible??!0),pe(t.available_for_messaging??!0),fe(t.open_to_virtual_meetups??!1),ye(t.open_to_f2f_meetups??!1),ve(t.avatar_url),Ne(t.gender||""),we(t.job_seniority||""),Ce(t.job_function_summary||null),ke(t.job_function_confidence||null),Ae(!1),le(null))},[t]);const tt=()=>{var o;(o=u.current)==null||o.click()},st=async o=>{var P;const C=(P=o.target.files)==null?void 0:P[0];if(C){const J=await c(C);J&&ve(J)}},at=()=>{if(!R.trim()||Se)return;const o=Wt(R);o.summary&&(o.confidence==="high"?(Ce(o.summary),ke(o.confidence),Ae(!0),le(null)):le({summary:o.summary,confidence:o.confidence}))},O=[];x.trim()||O.push("First name"),E.trim()||O.push("Last name"),R.trim()||O.push("Job title"),Q.trim()||O.push("Company"),G.trim()||O.push("Email"),!n.city&&!n.country&&O.push("Location");const K=O.length===0,[it,de]=i.useState(!1),De=i.useRef(!1),[rt,me]=i.useState(!1),Ee=i.useRef(!1),nt=async()=>{K&&(await l({first_name:x,last_name:E,job_title:R,city:n.city,state:n.state,country:n.country,country_code:n.country_code,coordinates_lat:n.coordinates_lat,coordinates_lng:n.coordinates_lng,place_id:n.place_id,bio:y,linkedin_url:V,job_function_summary:Se,job_function_confidence:et,is_visible:oe,available_for_messaging:ge,open_to_virtual_meetups:xe,open_to_f2f_meetups:be,gender:je||null,job_seniority:_e||null}),!ce&&!De.current?(De.current=!0,de(!0)):!y.trim()&&!Ee.current&&(Ee.current=!0,me(!0)))},ot=(t==null?void 0:t.is_champion)||!1,ct=(t==null?void 0:t.is_alumni)||!1,Pe=["executives","rising_leaders","alumni","guest","wequal","other"],lt=(()=>{const o=new Map;for(const C of h||[]){const P=o.get(C.member_type);(!P||C.is_active&&!P.isActive)&&o.set(C.member_type,{type:C.member_type,isActive:!!C.is_active})}return Array.from(o.values()).sort((C,P)=>Pe.indexOf(C.type)-Pe.indexOf(P.type))})();return j?e.jsx("div",{className:"min-h-screen bg-background member-portal-theme flex items-center justify-center",children:e.jsx(H,{className:"w-8 h-8 animate-spin text-community"})}):e.jsxs("div",{className:"min-h-screen bg-background member-portal-theme",children:[e.jsx(Rt,{}),e.jsx("main",{children:e.jsx("section",{className:"py-12 lg:py-16",children:e.jsx("div",{className:"container mx-auto px-6 lg:px-8 max-w-4xl",children:e.jsxs(_t.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-serif font-semibold text-midnight",children:"Your Profile"}),e.jsx("p",{className:"text-midnight/60 mt-2",children:"Manage how you appear in the WeQual community"})]}),e.jsx(zt,{}),e.jsxs(te,{className:"bg-white border-border",children:[e.jsx(se,{children:e.jsxs(ae,{className:"text-midnight flex items-center gap-2",children:[e.jsx(Me,{className:"w-5 h-5 text-community"}),"Profile Photo & Name"]})}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("div",{onClick:tt,className:"w-24 h-24 rounded-full bg-muted flex items-center justify-center overflow-hidden cursor-pointer group",children:[ce?e.jsx("img",{src:ce,alt:"Profile",className:"w-full h-full object-cover"}):e.jsx(Me,{className:"w-10 h-10 text-midnight/40"}),e.jsx("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity rounded-full",children:p?e.jsx(H,{className:"w-6 h-6 text-white animate-spin"}):e.jsx(wt,{className:"w-6 h-6 text-white"})})]}),e.jsx("input",{ref:u,type:"file",accept:"image/*",onChange:st,className:"hidden"})]}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("p",{className:"text-midnight font-medium",children:"Profile Photo"}),e.jsx("p",{className:"text-sm text-midnight/50",children:"Click to upload. Max 5MB, JPG or PNG."}),e.jsxs("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:[lt.map(({type:o,isActive:C})=>{const P=z[o];if(!P)return null;const J=e.jsx("span",{className:`${Z} ${C?"":"opacity-50"}`,style:P.style,children:P.label});return C?e.jsx("span",{children:J},o):e.jsxs(St,{children:[e.jsx(Ct,{asChild:!0,children:J}),e.jsx(kt,{children:"Past membership"})]},o)}),ct&&e.jsx("span",{className:Z,style:z.alumni.style,children:z.alumni.label}),A&&e.jsx("span",{className:Z,style:z.wequal.style,children:z.wequal.label}),ot&&e.jsxs("span",{className:`${Z} inline-flex items-center gap-1`,style:Oe.champion.style,children:[e.jsx(At,{className:"w-3 h-3"}),Oe.champion.label]})]})]})]}),e.jsx(re,{className:"bg-muted"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsxs(N,{htmlFor:"firstName",className:"text-midnight/70 md:w-28 md:shrink-0",children:["First Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(B,{id:"firstName",value:x,onChange:o=>d(o.target.value),required:!0,"aria-invalid":!x.trim(),className:"bg-muted border-border text-midnight md:flex-1"})]}),e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsxs(N,{htmlFor:"lastName",className:"text-midnight/70 md:w-28 md:shrink-0",children:["Last Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(B,{id:"lastName",value:E,onChange:o=>L(o.target.value),required:!0,"aria-invalid":!E.trim(),className:"bg-muted border-border text-midnight md:flex-1"})]})]}),e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-start md:gap-3",children:[e.jsxs(N,{htmlFor:"email",className:"text-midnight/70 md:w-28 md:shrink-0 md:pt-2",children:["Email Address ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs("div",{className:"md:flex-1",children:[e.jsx(B,{id:"email",type:"email",value:G,disabled:!0,className:"bg-muted border-border text-midnight/50"}),e.jsx("p",{className:"text-xs text-midnight/40 mt-1",children:"Contact support to change your email address"})]})]})]})]}),e.jsxs(te,{className:"bg-white border-border",children:[e.jsx(se,{children:e.jsxs(ae,{className:"text-midnight flex items-center gap-2",children:[e.jsx(Vt,{className:"w-5 h-5 text-community"}),"Professional Information"]})}),e.jsxs(ie,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsxs(N,{htmlFor:"jobTitle",className:"text-midnight/70 md:w-28 md:shrink-0",children:["Job Title ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(B,{id:"jobTitle",value:R,onChange:o=>W(o.target.value),onBlur:at,required:!0,"aria-invalid":!R.trim(),placeholder:"e.g. Chief Marketing Officer",className:"bg-muted border-border text-midnight placeholder:text-midnight/30 md:flex-1"})]}),e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsxs(N,{htmlFor:"companyName",className:"text-midnight/70 md:w-28 md:shrink-0",children:["Company ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(B,{id:"companyName",value:Q,disabled:!0,className:"bg-muted border-border text-midnight/50 md:flex-1"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Lt,{value:n,onChange:S,label:"Location",required:!0,placeholder:"Start typing a city, region, or country..."}),D&&e.jsxs("button",{type:"button",onClick:()=>U(!0),className:"absolute top-0 right-0 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground border border-border rounded-md px-2 py-1 bg-background",title:"Open location diagnostics (admin only)","aria-label":"Open location diagnostics",children:[e.jsx(Ke,{className:"w-3.5 h-3.5"}),"Debug"]})]}),e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsx(N,{htmlFor:"linkedinUrl",className:"text-midnight/70 md:w-28 md:shrink-0",children:"LinkedIn Profile"}),e.jsx(B,{id:"linkedinUrl",value:V,onChange:o=>ue(o.target.value),placeholder:"https://linkedin.com/in/yourprofile",className:"bg-muted border-border text-midnight placeholder:text-midnight/30 md:flex-1"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(N,{htmlFor:"bio",className:"text-midnight/70",children:"Bio"}),e.jsx(Dt,{id:"bio",value:y,onChange:o=>M(o.target.value),required:!0,"aria-invalid":!y.trim(),placeholder:"Provide a short summary of your key professional interests, what you feel you can offer the community, and what you want to gain. E.g. I'm fascinated about the overlap between humans and AI, can offer mentoring around career transitions and would love to connect with anyone in the AI space.",className:"bg-muted border-border text-midnight placeholder:text-midnight/30 min-h-[100px]",maxLength:500}),e.jsxs("p",{className:"text-xs text-midnight/40 text-right",children:[y.length,"/500"]})]}),e.jsxs("div",{className:"pt-4 border-t border-border/60 space-y-4",children:[e.jsx("p",{className:"text-sm italic text-midnight/50",children:"Hidden from other members, useful for matching"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsx(N,{htmlFor:"jobSeniority",className:"text-midnight/70 md:w-28 md:shrink-0",children:"Seniority"}),e.jsx("div",{className:"md:flex-1",children:e.jsxs(Ie,{value:_e,onValueChange:we,children:[e.jsx(Le,{id:"jobSeniority",className:"bg-muted border-border text-midnight",children:e.jsx(Ue,{placeholder:"Select seniority"})}),e.jsxs(qe,{children:[e.jsx(T,{value:"C-suite (CEO/CFO/COO/etc)",children:"C-suite (CEO/CFO/COO/etc)"}),e.jsx(T,{value:"C-suite -1 (SVP/VP)",children:"C-suite -1 (SVP/VP)"}),e.jsx(T,{value:"C-suite -2 (VP/Director)",children:"C-suite -2 (VP/Director)"}),e.jsx(T,{value:"C-suite -3 (Director/Head)",children:"C-suite -3 (Director/Head)"}),e.jsx(T,{value:"C-suite -4 (Head or equivalent)",children:"C-suite -4 (Head or equivalent)"}),e.jsx(T,{value:"C-suite -5 (Manager)",children:"C-suite -5 (Manager)"}),e.jsx(T,{value:"Other",children:"Other"})]})]})})]}),e.jsxs("div",{className:"space-y-2 md:space-y-0 md:flex md:items-center md:gap-3",children:[e.jsx(N,{htmlFor:"gender",className:"text-midnight/70 md:w-28 md:shrink-0",children:"Gender"}),e.jsx("div",{className:"md:flex-1",children:e.jsxs(Ie,{value:je,onValueChange:Ne,children:[e.jsx(Le,{id:"gender",className:"bg-muted border-border text-midnight",children:e.jsx(Ue,{placeholder:"Select gender"})}),e.jsxs(qe,{children:[e.jsx(T,{value:"Male",children:"Male"}),e.jsx(T,{value:"Female",children:"Female"}),e.jsx(T,{value:"Other",children:"Other"}),e.jsx(T,{value:"Prefer not to say",children:"Prefer not to say"})]})]})})]})]})]})]})]}),e.jsxs(te,{className:"bg-white border-border",children:[e.jsxs(se,{children:[e.jsxs(ae,{className:"text-midnight flex items-center gap-2",children:[e.jsx(Et,{className:"w-5 h-5 text-community"}),"Visibility & Preferences"]}),e.jsx(Ze,{className:"text-midnight/50",children:"Control how other members can find and connect with you"})]}),e.jsxs(ie,{className:"divide-y divide-border/60 py-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(N,{className:"text-midnight text-sm",children:"Visible in Member Directory"}),e.jsx("p",{className:"text-xs text-midnight/50 truncate",children:"Allow other members to find you in the community"})]}),e.jsx(Y,{checked:oe,onCheckedChange:he,className:"data-[state=checked]:bg-community"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(N,{className:"text-midnight text-sm flex items-center gap-2",children:[e.jsx(Bt,{className:"w-4 h-4 text-community shrink-0"}),"Available for Messaging"]}),e.jsx("p",{className:"text-xs text-midnight/50 truncate",children:"Allow other members to
1send you messages"})]}),e.jsx(Y,{checked:ge,onCheckedChange:pe,disabled:!oe,className:"data-[state=checked]:bg-community"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(N,{className:"text-midnight text-sm flex items-center gap-2",children:[e.jsx(Pt,{className:"w-4 h-4 text-community shrink-0"}),"Open to Virtual Meet-ups"]}),e.jsx("p",{className:"text-xs text-midnight/50 truncate",children:"Interested in connecting via video calls"})]}),e.jsx(Y,{checked:xe,onCheckedChange:fe,className:"data-[state=checked]:bg-community"})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(N,{className:"text-midnight text-sm flex items-center gap-2",children:[e.jsx(Tt,{className:"w-4 h-4 text-community shrink-0"}),"Open to Face-to-Face Meet-ups"]}),e.jsx("p",{className:"text-xs text-midnight/50 truncate",children:"Interested in meeting in person"})]}),e.jsx(Y,{checked:be,onCheckedChange:ye,className:"data-[state=checked]:bg-community"})]})]})]}),e.jsx(Ut,{lastSaveAt:a,isAdmin:k})]})})})}),e.jsx("div",{className:"sticky bottom-0 inset-x-0 z-40 border-t border-border bg-white/95 backdrop-blur-md shadow-[0_-4px_12px_-4px_hsl(var(--foreground)/0.08)]",children:e.jsxs("div",{className:"container mx-auto px-6 lg:px-8 max-w-4xl py-3 flex items-center justify-between gap-4",children:[e.jsx("p",{className:"text-sm text-midnight/60 hidden sm:block",children:K?"All required fields complete.":`Required to save: ${O.join(", ")}`}),e.jsx("p",{className:"text-xs text-destructive sm:hidden",children:K?"":`${O.length} required field${O.length===1?"":"s"} missing`}),e.jsx(I,{onClick:nt,disabled:r||!K,size:"lg",className:"bg-community hover:bg-community/90 text-community-foreground shrink-0",children:r?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):"Save Changes"})]})}),D&&e.jsx(Jt,{open:F,onOpenChange:U,formValue:n,persistedValue:{city:(t==null?void 0:t.city)??null,state:(t==null?void 0:t.state)??null,country:(t==null?void 0:t.country)??null,country_code:(t==null?void 0:t.country_code)??null,coordinates_lat:(t==null?void 0:t.coordinates_lat)??null,coordinates_lng:(t==null?void 0:t.coordinates_lng)??null,place_id:(t==null?void 0:t.place_id)??null},profileId:(t==null?void 0:t.id)??null}),e.jsx(Ft,{}),e.jsx(Re,{open:it,onOpenChange:de,children:e.jsxs(Be,{children:[e.jsxs($e,{children:[e.jsx(Ve,{children:"Add a profile photo?"}),e.jsx(He,{children:"A short bio helps other member engage with you in a way that's relevant from the start."})]}),e.jsxs(Ge,{children:[e.jsx(Je,{children:"Maybe later"}),e.jsx(ze,{onClick:()=>{var o;de(!1),(o=u.current)==null||o.click()},children:"Add photo now"})]})]})}),e.jsx(Re,{open:rt,onOpenChange:me,children:e.jsxs(Be,{children:[e.jsxs($e,{children:[e.jsx(Ve,{children:"Add a short bio?"}),e.jsx(He,{children:"A short bio helps other members understand why they would want to engage with you."})]}),e.jsxs(Ge,{children:[e.jsx(Je,{children:"Maybe later"}),e.jsx(ze,{onClick:()=>{me(!1),setTimeout(()=>{var o;(o=document.getElementById("bio"))==null||o.focus()},50)},children:"Add bio now"})]})]})})]})};export{ms as default};
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.