PageSourceSearch

https://mindgolf.ai/assets/MyOrganizations-Dq7hZeUy.js

js mindgolf.ai collected 2026-10-05 14:52:14 UTC 36,307 bytes, 23 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DXi0I5ak.js","assets/vendor-ahVw9cdH.js","assets/radix--pSzM2y8.js","assets/supabase-DYrB2Yg5.js","assets/charts-CSweoJhv.js","assets/query-CeIq2NOR.js","assets/forms-Cc1FL3tT.js","assets/index-BxWLd995.css"])))=>i.map(i=>d[i]);
2import{bi as Ae,fO as Le,O as I,bA as A,bE as pe,bF as fe,bG as je,bH as ye,bI as Fe,dR as J,cf as oe,bK as _e,f3 as Ee,V as q,R as M,f7 as ve,f4 as Re,gR as Oe,hh as Ne,aa as Te,b_ as De,a7 as S,ac as ce,dU as U,cx as Pe,hw as Ye,az as K,cy as Me,cz as Ge,cA as Be,cB as He,bJ as v,c7 as Ue,hl as Ke,aw as be,am as $e,dB as we,be as Qe,bf as Ve,bg as de,bh as me,bC as H,bW as Ce,a5 as P,a6 as Y,t as ke,c9 as Je,_ as We,X,bY as Xe,eM as Z,eN as ee,eO as ae,aE as ue,f8 as xe,c2 as Ze,c3 as ea,c4 as aa,c5 as sa,c6 as se,e1 as ta,b0 as na,b1 as ra,bn as ia,b3 as la,b4 as oa,ew as ca}from"./index-DXi0I5ak.js";import{r as g,j as e}from"./vendor-ahVw9cdH.js";import{a as ie,b as da,u as W}from"./query-CeIq2NOR.js";import{A as ma}from"./AppBreadcrumb-DQQeh5xA.js";import{Y as ua,L as xa,C as ha,O as ga}from"./OrgDetailDrawer-DB3slvca.js";import{L as pa}from"./linkedin-CuJh4Bmc.js";import{B as fa}from"./briefcase-BJqM7a0P.js";import{S as ja}from"./slider-C_IZaYBN.js";import{C as ya}from"./CountrySelect-1cM-UIm8.js";import{T as _a}from"./TownSelect-Dbodino1.js";import{b as va,C as Na,c as ba,a as wa}from"./coach-marketplace-constants-4C6-w0Zk.js";import{S as Ca}from"./settings-2-Bx549eYj.js";import{G as Se}from"./gift-CGJQJ9yq.js";import{o as ka,s as te}from"./forms-Cc1FL3tT.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./breadcrumb-C59QT_kB.js";
2import"./useMarketplaceProfile-_82_uW1d.js";import"./command-CK_xWGRQ.js";import"./chevrons-up-down-DYfEac18.js";import"./credential-topics-CRtqvugt.js";const Sa=()=>{const a=ie(),{userId:l}=Ae(),m=Le({queryKey:["player-join-requests",l],queryFn:async()=>{if(!l)return[];const{data:o,error:x}=await I.from("player_join_requests").select(`
3          *,
4          organizations!player_join_requests_organization_id_fkey (
5            id, name, type
6          )
7        `).eq("player_id",l).order("created_at",{ascending:!1});if(x)throw x;return(o||[]).map(h=>({...h,organization:h.organizations}))}}),n=da({mutationFn:async o=>{const{data:x,error:h}=await I.functions.invoke("player-cancel-join-request",{body:{requestId:o}});if(h)throw h;if(x!=null&&x.error)throw new Error(x.error)},onSuccess:()=>{a.invalidateQueries({queryKey:["player-join-requests"]}),a.invalidateQueries({queryKey:["discoverable-orgs"]})}}),s=(m.data||[]).filter(o=>o.status==="pending");return{requests:m.data||[],pendingRequests:s,isLoading:m.isLoading,cancelRequest:n}},Q=(a,l)=>!l.length||(a||[]).some(m=>l.includes(m));function Ia(a,l){const m=typeof a=="string"?{searchQuery:a}:a,{searchQuery:n,filters:s,sort:o="top_rated"}=m;return W({queryKey:["discoverable-coaches",n,s,o],queryFn:async()=>{const{data:{user:x}}=await I.auth.getUser();if(!x)return[];let h=I.from("organizations").select(`
8          id, name, type, tagline, country_id, town_id,
9          organization_marketplace_profile (
10            years_experience, specialties, player_levels, session_formats,
11            languages_spoken, accepts_new_clients, rating_avg, rating_count,
12            bio, certifications, age_groups, handicap_range_min, handicap_range_max,
13            instagram_handle, youtube_url, linkedin_url
14          )
15        `).eq("is_discoverable",!0).eq("type","coach");n!=null&&n.trim()&&(h=h.ilike("name",`%${n.trim()}%`)),s!=null&&s.countryId&&(h=h.eq("country_id",s.countryId)),s!=null&&s.townId&&(h=h.eq("town_id",s.townId));const{data:b,error:d}=await h.limit(100);if(d)throw d;const[{data:w},{data:y}]=await Promise.all([I.from("organization_players").select("organization_id").eq("player_id",x.id).or("status.eq.active,consent_status.eq.accepted"),I.from("player_join_requests").select("organization_id").eq("player_id",x.id).eq("status","pending")]),C=new Set((w||[]).map(c=>c.organization_id)),N=new Set((y||[]).map(c=>c.organization_id)),p=(b||[]).map(c=>{const t=Array.isArray(c.organization_marketplace_profile)?c.organization_marketplace_profile[0]:c.organization_marketplace_profile;return{id:c.id,name:c.name,type:c.type,tagline:c.tagline,country_id:c.country_id,town_id:c.town_id,years_experience:(t==null?void 0:t.years_experience)??null,specialties:(t==null?void 0:t.specialties)||[],player_levels:(t==null?void 0:t.player_levels)||[],session_formats:(t==null?void 0:t.session_formats)||[],languages_spoken:(t==null?void 0:t.languages_spoken)||[],accepts_new_clients:(t==null?void 0:t.accepts_new_clients)??null,rating_avg:(t==null?void 0:t.rating_avg)??null,rating_count:(t==null?void 0:t.rating_count)??0,bio:(t==null?void 0:t.bio)??null,certifications:(t==null?void 0:t.certifications)||[],age_groups:(t==null?void 0:t.age_groups)||[],handicap_range_min:(t==null?void 0:t.handicap_range_min)??null,handicap_range_max:(t==null?void 0:t.handicap_range_max)??null,instagram_handle:(t==null?void 0:t.instagram_handle)??null,youtube_url:(t==null?void 0:t.youtube_url)??null,linkedin_url:(t==null?void 0:t.linkedin_url)??null}}),z=p.map(c=>c.id);if(z.length>0){const{data:c}=await I.from("coach_certifications").select("organization_id, tier, revoked_at, valid_through").in("organization_id",z).is("revoked_at",null),t=Date.now(),u=new Map;for(const j of c||[])new Date(j.valid_through).getTime()>t&&u.set(j.organization_id,j.tier);for(const j of p)j.certification_tier=u.get(j.id)??null}return[...p.filter(c=>C.has(c.id)||N.has(c.id)?!1:s?!(s.acceptsNewClients&&c.accepts_new_clients===!1||s.minRating>0&&(c.rating_avg??0)<s.minRating||s.minYearsExperience>0&&(c.years_experience??0)<s.minYearsExperience||!Q(c.specialties,s.specialties)||!Q(c.player_levels,s.playerLevels)||!Q(c.session_formats,s.sessionFormats)||!Q(c.languages_spoken,s.languages)
15):!0)].sort((c,t)=>{if(o==="top_rated"){const u=c.rating_avg??-1,j=t.rating_avg??-1;return j!==u?j-u:(t.rating_count||0)-(c.rating_count||0)}return o==="most_experienced"?(t.years_experience??0)-(c.years_experience??0):c.name.localeCompare(t.name)})}})}const he=({open:a,onOpenChange:l,preselectedOrg:m,hideRequestForm:n,pendingNotice:s})=>{const[o,x]=g.useState(""),[h,b]=g.useState(!1),[d,w]=g.useState(!1),[y,C]=g.useState(null),N=ie(),p=m||null,z=g.useCallback(async()=>{if(p){b(!0);try{const{data:f,error:L}=await I.functions.invoke("player-request-join",{body:{organizationId:p.id,message:o.trim()||null}});if(L)throw L;if(f!=null&&f.error)throw new Error(f.error);A.success("Join request sent!",{description:`Your request to join ${p.name} has been submitted.`}),x(""),w(!1),N.invalidateQueries({queryKey:["player-join-requests"]}),N.invalidateQueries({queryKey:["discoverable-coaches"]}),l(!1)}catch(f){A.error("Failed to send request",{description:f.message||"Please try again."})}finally{b(!1)}}},[p,o,N,l]);return e.jsx(pe,{open:a,onOpenChange:l,children:e.jsxs(fe,{className:"max-h-[90vh]",children:[e.jsxs(je,{children:[e.jsx(ye,{children:n?(p==null?void 0:p.name)||"Coach":`Join ${(p==null?void 0:p.name)||"Coach"}`}),e.jsx(Fe,{children:n?"Coach details":"Send a request to join this coach's program."})]}),e.jsx("div",{className:"px-4 pb-6 space-y-4 overflow-y-auto",children:p&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(qa,{coach:p}),!n&&e.jsx(J,{}),n?s&&e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-md bg-muted/50 border",children:[e.jsx(oe,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-sm font-medium",children:["Request to join ",p.name]}),e.jsx(_e,{placeholder:"Add an optional message (e.g., your name, why you'd like to join)...",value:o,onChange:f=>x(f.target.value),rows:3,maxLength:500}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-md bg-muted/50 border",children:[e.jsx(oe,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["By joining, you consent to sharing your identifiable data (name, email, handicap, performance metrics, and chat messages) with this organization's staff. You can revoke access at any time by leaving the organization. See our"," ",e.jsx("button",{type:"button",className:"underline text-primary",onClick:()=>C("terms"),children:"Terms"})," ","and"," ",e.jsx("button",{type:"button",className:"underline text-primary",onClick:()=>C("privacy"),children:"Privacy Policy"}),"."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ee,{id:"consent-check",checked:d,onCheckedChange:f=>w(f===!0)}),e.jsx("label",{htmlFor:"consent-check",className:"text-xs text-muted-foreground cursor-pointer",children:"I understand my data will be shared with this organization"})]}),e.jsxs(q,{className:"w-full",onClick:z,disabled:h||!d,children:[h?e.jsx(M,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ve,{className:"h-4 w-4 mr-2"}),"Send Join Request"]}),e.jsx(Re,{open:y!==null,onOpenChange:f=>!f&&C(null),type:y||"terms"})]})]})})]})})},B=a=>a.replace(/_/g," ").replace(/\b\w/g,l=>l.toUpperCase()),qa=({coach:a})=>{const l=a.handicap_range_min!==null||a.handicap_range_max!==null,m=[a.instagram_handle&&{icon:Oe,label:a.instagram_handle.replace(/^@/,""),href:`https://instagram.com/${a.instagram_handle.replace(/^@/,"")}`},a.youtube_url&&{icon:ua,label:"YouTube",href:a.youtube_url},a.linkedin_url&&{icon:pa,label:"LinkedIn",href:a.linkedin_url}].filter(Boolean);return e.jsxs("div",{className:"space-y-4",children:[a.rating_count>0&&a.rating_avg!==null&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 fill-yellow-400 text-yellow-400"}),e.jsx("span",{className:"text-sm font-medium",children:a.rating_avg.toFixed(1)}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",a.rating_count," reviews)"]})]}),a.bio&&e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:a.bio}),a.years_experience!==null&&e.jsx(R,{icon:Te,label:"Experience",children:e.jsxs("span",{className:"text-sm",children:[a.years_experience," years"]})}),a.certifications.length>0&&e.jsx(R,{icon:De,label:"Certifications",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.certifications.map(n=>e.jsx(S,{variant:"secondary",className:"text-xs",children:n},n))})}),a.languages_spoken.length>0&&e.jsx(R,{icon:xa,label:"Languages",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.languages_spoken.map(n=>e.jsx(S,{variant:"outline",className:"text-xs",children:B(n)},n))})}),a.specialties.length>0&&e.jsx(R,{icon:ce,label:"Coaching focus",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.specialties.map(n=>e.jsx(S,{variant:"secondary",className:"text-xs",children:B(n)},n))})}),a.player_levels.length>0&&e.jsx(R,{icon:U,label:"Player levels",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.player_levels.map(n=>e.jsx(S,{variant:"outline",className:"text-xs",children:B(n)},n))})}),a.age_groups.length>0&&e.jsx(R,{icon:U,label:"Age groups",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.age_groups.map(n=>e.jsx(S,{variant:"outline",className:"text-xs",children:B(n)},n))})}),a.session_formats.length>0&&e.jsx(R,{icon:fa,label:"Service model",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.session_formats.map(n=>e.jsx(S,{variant:"secondary",className:"text-xs",children:B(n)},n))})}),l&&e.jsx(R,{icon:ce,label:"Handicap range",children:e.jsxs("span",{className:"text-sm",children:[a.handicap_range_min??"—"," to ",a.handicap_range_max??"—"]}
15)}),m.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 pt-1",children:m.map(({icon:n,label:s,href:o})=>e.jsxs("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md border bg-muted/50 hover:bg-muted text-xs text-foreground",children:[e.jsx(n,{className:"h-3.5 w-3.5"}),s]},o))})]})},R=({icon:a,label:l,children:m})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wide",children:[e.jsx(a,{className:"h-3.5 w-3.5"}),l]}),e.jsx("div",{children:m})]}),re={countryId:null,townId:null,specialties:[],playerLevels:[],sessionFormats:[],languages:[],acceptsNewClients:!0,minRating:0,minYearsExperience:0};function Ie(a){let l=0;return a.countryId&&l++,a.townId&&l++,l+=a.specialties.length,l+=a.playerLevels.length,l+=a.sessionFormats.length,l+=a.languages.length,a.acceptsNewClients||l++,a.minRating>0&&l++,a.minYearsExperience>0&&l++,l}function V({options:a,selected:l,onChange:m}){const n=s=>{m(l.includes(s)?l.filter(o=>o!==s):[...l,s])};return e.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(s=>{const o=l.includes(s.value);return e.jsx("button",{type:"button",onClick:()=>n(s.value),className:K("px-3 py-1.5 rounded-full text-xs border transition-colors",o?"bg-primary text-primary-foreground border-primary":"bg-background border-input text-foreground hover:bg-muted"),children:s.label},s.value)})})}function za({value:a,onChange:l}){const[m,n]=g.useState(!1),[s,o]=g.useState(a);g.useEffect(()=>{m&&o(a)},[m,a]);const x=Ie(a),h=()=>{l(s),n(!1)},b=()=>{o(re)};return e.jsxs(Pe,{open:m,onOpenChange:n,children:[e.jsx(Ye,{asChild:!0,children:e.jsxs("button",{type:"button",className:K("p-1.5 rounded-md hover:bg-accent flex-shrink-0 relative",x>0&&"text-primary"),title:"Filters",children:[e.jsx(Ca,{className:K("h-4 w-4",x>0?"text-primary":"text-muted-foreground")}),x>0&&e.jsx(S,{variant:"secondary",className:"absolute -top-1 -right-1 h-4 min-w-4 px-1 text-[10px]",children:x})]})}),e.jsxs(Me,{side:"right",className:"w-full sm:max-w-md overflow-y-auto",children:[e.jsxs(Ge,{children:[e.jsx(Be,{children:"Filter coaches"}),e.jsx(He,{children:"Narrow down the list to find your match."})]}),e.jsxs("div",{className:"py-4 space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Country"}),e.jsx(ya,{value:s.countryId,onChange:d=>o({...s,countryId:d,townId:null})})]}),s.countryId&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Town"}),e.jsx(_a,{countryId:s.countryId,value:s.townId,onChange:d=>o({...s,townId:d})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Minimum rating"}),e.jsx("div",{className:"flex gap-1.5",children:[0,1,2,3,4,5].map(d=>{const w=s.minRating===d;return e.jsx("button",{type:"button",onClick:()=>o({...s,minRating:d}),className:K("flex-1 py-1.5 rounded-md text-xs border flex items-center justify-center gap-1",w?"bg-primary text-primary-foreground border-primary":"bg-background border-input"),children:d===0?"Any":e.jsxs(e.Fragment,{children:[d,e.jsx(Ne,{className:"h-3 w-3 fill-current"})]})},d)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Specialties"}),e.jsx(V,{options:va,selected:s.specialties,onChange:d=>o({...s,specialties:d})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Player level"}),e.jsx(V,{options:Na,selected:s.playerLevels,onChange:d=>o({...s,playerLevels:d})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Session format"}),e.jsx(V,{options:ba,selected:s.sessionFormats,onChange:d=>o({...s,sessionFormats:d})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Languages"}),e.jsx(V,{options:wa,selected:s.languages,onChange:d=>o({...s,languages:d})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{children:"Minimum years of experience"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s.minYearsExperience
15===0?"Any":`${s.minYearsExperience}+`})]}),e.jsx(ja,{min:0,max:30,step:1,value:[s.minYearsExperience],onValueChange:([d])=>o({...s,minYearsExperience:d})})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Accepting new clients"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Hide coaches not taking players"})]}),e.jsx(Ue,{checked:s.acceptsNewClients,onCheckedChange:d=>o({...s,acceptsNewClients:d})})]})]}),e.jsxs(Ke,{className:"flex-row gap-2",children:[e.jsxs(q,{variant:"outline",className:"flex-1 gap-1.5",onClick:b,children:[e.jsx(be,{className:"h-4 w-4"}),"Clear all"]}),e.jsx(q,{className:"flex-1",onClick:h,children:"Apply"})]})]})]})}const Aa=ka({coach_name:te().trim().min(1,"Coach name is required").max(120),coach_email:te().trim().toLowerCase().email("Valid email is required").max(255),personal_note:te().trim().max(500).optional()}),ne={coach_already_registered:"This user already exists on MindGolf.",invalid_email:"Please enter a valid email address.",invalid_name:"Please enter the coach's name.",cannot_invite_self:"You can't invite your own email."};function La({open:a,onOpenChange:l}){const m=ie(),[n,s]=g.useState("email"),[o,x]=g.useState(""),[h,b]=g.useState(""),[d,w]=g.useState(""),[y,C]=g.useState(!1),[N,p]=g.useState(null),[z,f]=g.useState(!1);g.useEffect(()=>{a||(x(""),b(""),w(""),p(null),f(!1),s("email"))},[a]);const L=async()=>{var j;const u=Aa.safeParse({coach_name:o,coach_email:h,personal_note:d||void 0});if(!u.success){A.error(((j=u.error.issues[0])==null?void 0:j.message)||"Please check the form");return}C(!0);try{const{data:k,error:$}=await I.functions.invoke("invite-coach",{body:u.data});if($){let T;try{const G=$.context;if(G&&typeof G.json=="function"){const F=await G.clone().json();T=F==null?void 0:F.error}}catch{}A.error(T&&ne[T]?ne[T]:"Couldn't send the invite. Please try again.");return}if(k!=null&&k.error){A.error(ne[k.error]||"Something went wrong. Please try again.");return}p({apply_url:k.apply_url,cap_reached:!!k.cap_reached}),k.email_sent?A.success("Invitation sent!"):A.success("Invite created. Share the link below — email couldn't be sent automatically."),m.invalidateQueries({queryKey:["my-coach-invites"]})}catch(k){console.error("[invite-coach] error:",k),A.error("Couldn't send the invite. Please try again.")}finally{C(!1)}},c=u=>{navigator.clipboard.writeText(u),f(!0),A.success("Link copied!"),setTimeout(()=>f(!1),2e3)},t=async u=>{if(navigator.share)try{await navigator.share({title:"Apply to coach on MindGolf",text:"I think you'd be a great coach for MindGolf — apply with my link!",url:u})}catch(j){j.name!=="AbortError"&&c(u)}else c(u)};return e.jsx(pe,{open:a,onOpenChange:l,children:e.jsxs(fe,{children:[e.jsx(je,{children:e.jsxs(ye,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5 text-primary"}),"Invite a Coach"]})}),e.jsxs("div",{className:"px-4 pb-6 space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Know a great golf coach? Invite them to apply to MindGolf. If approved and they sign their first paying player, you both get ",e.jsx("strong",{children:"1 month of Pro free"}),"."]}),N?e.jsxs("div",{className:"space-y-3",children:[e.jsx(S,{variant:"secondary",className:"text-xs",children:"Invite created"}),e.jsxs("div",{children:[e.jsx(v,{className:"text-xs text-muted-foreground",children:"Personal apply link"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("div",{className:"flex-1 p-2.5 bg-muted rounded-lg text-xs font-mono truncate",children:N.apply_url}),e.jsx(q,{variant:"outline",size:"icon",onClick:()=>c(N.apply_url),className:"shrink-0",children:z?e.jsx($e,{className:"h-4 w-4 text-green-500"}):e.jsx(we,{className:"h-4 w-4"})}),e.jsx(q,{variant:"default",size:"icon",onClick:()=>t(N.apply_url),className:"shrink-0",children:e.jsx(ve,{className:"h-4 w-4"})})]})]}),N.cap_reached&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:"You've reached the 5-reward cap. New invites won't earn additional rewards."}),e.jsx(q,{variant:"outline",className:"w-full",onClick:()=>l(!1),children:"Done"})]}):e.jsxs(Qe,{value:n,onValueChange:u=>s(u),children:[e.jsxs(Ve,{className:"grid w-full grid-cols-2",children:[e.jsx(de,{value:"email",children:"Send email"}),e.jsx(de,{value:"link",children:"Get a link"})]}),e.jsxs(me,{value:"email",className:"space-y-3 mt-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"coach-name",children:"Coach's name"}),e.jsx(H,{id:"coach-name",placeholder:"e.g. Alex Morgan",value:o,onChange:u=>x(u.target.value),maxLength:120})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"coach-email",children:"Coach's email"}),e.jsx(H,{id:"coach-email",type:"email",placeholder:"[email protected]",value:h,onChange:u=>b(u.target.value),maxLength:255})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(v,{htmlFor:"coach-note",className:"flex items-center justify-between",children:[e.jsx("span",{children:"Personal note (optional)"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[d.length,"/500"]})]}),e.jsx(_e,{id:"coach-note",placeholder:"A short message explaining why they'd love MindGolf…",value:d,onChange:u=>w(u.target.value.slice(0,500)),rows:3})]}),e.jsx(q,{onClick:L,disabled:y,className:"w-full",children:y?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-2 animate-spin"}),"Sending…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"h-4 w-4 mr-2"}),"Send invite"]})}),e.jsx("p",{className:"text-[11px] text-muted-foreground text-center",children:"Only invite coaches you personally know. Misuse may revoke rewards."})]}),e.jsxs(me,{value:"link",className:"space-y-3 mt-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generate a personal apply link by entering the coach's name and email — we'll create the invite without sending the email."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"coach-name-link",children:"Coach's name"}),e.jsx(H,{id:"coach-name-link",placeholder:"e.g. Alex Morgan",value:o,onChange:u=>x(u.target.value),maxLength:120})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(v,{htmlFor:"coach-email-link",children:"Coach's email"}),e.jsx(H,{id:"coach-email-link",type:"email",placeholder:"[email protected]",value:h,onChange:u=>b(u.target.value),maxLength:255})]}),e.jsx(q,{onClick:L,disabled:y,className:"w-full",variant:"outline",children:y?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating…"]}):"Create invite link"})]})]})]})]})})}function ge(a){return`${window.location.origin}/org/apply?ref=${encodeURIComponent(a)}`}function Fa(a){return a.first_paying_player_at?{label:"Active – reward earned",className:"bg-green-500/15 text-green-700 dark:text-green-400 border-green-500/30"}:a.coach_org_id?{label:"Coach activated",className:"bg-blue-500/15 text-blue-700 dark:text-blue-400 border-blue-500/30"}:a.application_status==="rejected"?{label:"Rejected",className:"bg-destructive/15 text-destructive border-destructive/30"}:a.application_status==="approved"||a.application_status==="converted"?{label:"Approved – awaiting first player",className:"bg-violet-500/15 text-violet-700 dark:text-violet-400 border-violet-500/30"}:a.application_id?{label:"Application pending",className:"bg-amber-500/15 text-amber-700 dark:text-amber-400 border-amber-500/30"}:{label:"Invited",className:"bg-muted text-muted-foreground border-border"}}function Ea(){const{data:a,isLoading:l}=W({queryKey:["my-coach-invites"],queryFn:async()=>{const{data:n,error:s}=await I.rpc("list_my_coach_invites");if(s)throw s;return n||[]}});if(l)return e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(M,{className:"h-4 w-4 animate-spin text-muted-foreground"})});if(!a||a.length===0)return null;const m=n=>{navigator.clipboard.writeText(ge(n)),A.success("Apply link copied!")};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-muted-foreground",children:"Your coach invites"}),a.map(n=>{const s=Fa(n),o=!n.application_id&&!n.coach_org_id;return e.jsx(P,{children:e.jsxs(Y,{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:n.coach_org_name||n.referred_email}),n.coach_org_name&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:n.referred_email}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:["Sent ",ke(new Date(n.created_at),{addSuffix:!0})]})]}),e.jsx(S,{variant:"outline",className:`text-[10px] h-5 shrink-0 ${s.className}`,children:s.label})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(q,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>m(n.referral_code),children:[e.jsx(we,{className:"h-3 w-3 mr-1.5"}),"Copy link"]}),e.jsx("a",{href:`mailto:${n.referred_email}?subject=${encodeURIComponent("Join MindGolf as a coach")}&body=${encodeURIComponent(`Hi! I'd love for you to check out MindGolf. Apply here: ${ge(n.referral_code)}`)}`,children:e.jsxs(q,{size:"sm",variant:"ghost",className:"h-7 text-xs",children:[e.jsx(Ce,{className:"h-3 w-3 mr-1.5"}),"Email"]})})]})]})},n.referral_id)})]})}function Ra({hasCoaches:a}){const[l,m]=g.useState(!1);return e.jsxs(na,{open:l,onOpenChange:m,children:[e.jsx(ra,{asChild:!0,children:e.jsxs("button",{type:"button",className:"w-full flex items-center gap-2.5 p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors text-left",children:[e.jsx(ia,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 text-sm font-medium text-card-foreground",children:"Understanding My Coaches"}),e.jsx(la,{className:K("h-4 w-4 text-muted-foreground transition-transform",l&&"rotate-180")}
15)]})}),e.jsx(oa,{className:"mt-2",children:e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-4 space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-card-foreground",children:"Why it exists"}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:"A central hub to manage all your coach connections in one place."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-card-foreground",children:"How it works"}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:"Browse and request to join a coach's program. Once approved, you'll see them listed here. You can view details, message your coach, or leave at any time."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-card-foreground",children:"What it does"}),e.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:"Gives you access to personalized coaching, training programs, and performance insights shared by your coach."})]})]})})]})}const ns=()=>{const{directMemberships:a,isLoading:l}=Je(),{pendingRequests:m,isLoading:n,cancelRequest:s}=Sa(),[o,x]=g.useState(null),[h,b]=g.useState(""),[d,w]=g.useState(null),[y,C]=g.useState(null),[N,p]=g.useState(!1),[z,f]=g.useState(re),[L,c]=g.useState("top_rated"),t=Ie(z),u=We("REFER_A_FRIEND_ENABLED"),{data:j,isLoading:k}=Ia({searchQuery:h,filters:z,sort:L}),{data:$}=W({queryKey:["pending-coach-detail",y],enabled:!!y,queryFn:async()=>{if(!y)return null;const{data:r,error:O}=await I.from("organizations").select(`
16          id, name, type, tagline, country_id, town_id,
17          organization_marketplace_profile (
18            years_experience, specialties, player_levels, session_formats,
19            languages_spoken, accepts_new_clients, rating_avg, rating_count,
20            bio, certifications, age_groups, handicap_range_min, handicap_range_max,
21            instagram_handle, youtube_url, linkedin_url
22          )
23        `).eq("id",y).maybeSingle();if(O)throw O;if(!r)return null;const i=Array.isArray(r.organization_marketplace_profile)?r.organization_marketplace_profile[0]:r.organization_marketplace_profile;return{id:r.id,name:r.name,type:r.type,tagline:r.tagline,country_id:r.country_id,town_id:r.town_id,years_experience:(i==null?void 0:i.years_experience)??null,specialties:(i==null?void 0:i.specialties)||[],player_levels:(i==null?void 0:i.player_levels)||[],session_formats:(i==null?void 0:i.session_formats)||[],languages_spoken:(i==null?void 0:i.languages_spoken)||[],accepts_new_clients:(i==null?void 0:i.accepts_new_clients)??null,rating_avg:(i==null?void 0:i.rating_avg)??null,rating_count:(i==null?void 0:i.rating_count)??0,bio:(i==null?void 0:i.bio)??null,certifications:(i==null?void 0:i.certifications)||[],age_groups:(i==null?void 0:i.age_groups)||[],handicap_range_min:(i==null?void 0:i.handicap_range_min)??null,handicap_range_max:(i==null?void 0:i.handicap_range_max)??null,instagram_handle:(i==null?void 0:i.instagram_handle)??null,youtube_url:(i==null?void 0:i.youtube_url)??null,linkedin_url:(i==null?void 0:i.linkedin_url)??null}}}),T=a.map(r=>r.organization.id),G=m.map(r=>r.organization_id),F=[...T,...G,...(j||[]).map(r=>r.id)],{data:_}=W({queryKey:["org-branding-with-staff",F],queryFn:async()=>{if(F.length===0)return{};const{enrichOrgAvatars:r}=await ca(async()=>{const{enrichOrgAvatars:D}=await import("./index-DXi0I5ak.js").then(E=>E.jS);return{enrichOrgAvatars:D}},__vite__mapDeps([0,1,2,3,4,5,6,7])),O=await r(F),i={};for(const D of F){const E=O.get(D),le=(E==null?void 0:E.staff_avatar_url)||(E==null?void 0:E.logo_url);le&&(i[D]=le)}return i},enabled:F.length>0}),qe=l||n,ze=a.length>0;return e.jsxs("div",{className:"space-y-3 pb-24",children:[e.jsx(ma,{items:[{label:"Home",href:"/dashboard"},{label:"My Coaches"}]}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(X,{className:"h-6 w-6"}),"My Coaches"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Connect with coaches for personalized guidance"})]}),e.jsx(Ra,{hasCoaches:a.length>0}),qe?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(M,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[m.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h2",{className:"text-sm font-semibold flex items-center gap-2 text-muted-foreground",children:[e.jsx(Xe,{className:"h-4 w-4"}),"Pending Requests"]}),m.map(r=>{var O,i;return e.jsx(P,{className:"cursor-pointer hover:bg-accent/50 transition-colors",onClick:()=>C(r.organization_id),children:e.jsxs(Y,{className:"p-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs(Z,{className:"h-8 w-8 shrink-0",children:[_!=null&&_[r.organization_id]?e.jsx(ee,{src:_[r.organization_id],alt:((O=r.organization)==null?void 0:O.name)||"Coach"}):null,e.jsx(ae,{className:"bg-muted text-muted-foreground",children:e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:((i=r.organization)==null?void 0:i.name)||"Unknown"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Sent ",ke(new Date(r.created_at),{addSuffix:!0})]})]})]}),e.jsx(q,{size:"sm",variant:"ghost",className:"text-destructive text-xs shrink-0",onClick:D=>{D.stopPropagation(),s.mutate(r.id)},disabled:s.isPending,children:"Cancel"})]})},r.id)}),e.jsx(J,{})]}),ze&&e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(P,{className:"cursor-pointer hover:bg-accent/50 transition-colors",onClick:()=>x(r),children:e.jsxs(Y,{className:"p-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsxs(Z,{className:"h-8 w-8 shrink-0",children:[_!=null&&_[r.organization.id]?e.jsx(ee,{src:_[r.organization.id],alt:r.organization.name}):null,e.jsx(ae,{className:"bg-muted text-muted-foreground",children:e.jsx(U,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-sm font-medium truncate",children:r.organization.name})]}),e.jsx(ue,{className:"h-4 w-4 text-muted-foreground shrink-0"})]})},r.organization.id))}),e.jsx(J,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("h2",{className:"text-sm font-semibold flex items-center gap-2 text-muted-foreground",children:[e.jsx(xe,{className:"h-4 w-4"}),"Available Coaches"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(Ze,{value:L,onValueChange:r=>c(r),children:[e.jsx(ea,{className:"w-auto h-7 px-2 gap-1 text-xs text-violet-600 dar
23k:text-violet-400",children:e.jsx(aa,{})}),e.jsxs(sa,{children:[e.jsx(se,{value:"top_rated",className:"text-xs",children:"Top rated"}),e.jsx(se,{value:"most_experienced",className:"text-xs",children:"Most experienced"}),e.jsx(se,{value:"recent",className:"text-xs",children:"Name (A–Z)"})]})]}),e.jsx(za,{value:z,onChange:f})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(xe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(H,{placeholder:"Search coaches...",value:h,onChange:r=>b(r.target.value),className:"pl-9"})]}),t>0&&e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{type:"button",onClick:()=>f(re),className:"text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(be,{className:"h-3 w-3"}),"Clear filters (",t,")"]})}),k?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(M,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(j||[]).length===0?e.jsx(P,{className:"border-dashed",children:e.jsxs(Y,{className:"p-6 text-center",children:[e.jsx(X,{className:"h-8 w-8 text-muted-foreground/30 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t>0?"No coaches match your filters — try widening your search":"No coaches available right now"})]})}):(j||[]).map(r=>e.jsx(P,{className:"cursor-pointer hover:bg-accent/50 transition-colors",onClick:()=>w(r),children:e.jsx(Y,{className:"p-3 space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsxs(Z,{className:"h-10 w-10 shrink-0",children:[_!=null&&_[r.id]?e.jsx(ee,{src:_[r.id],alt:r.name}):null,e.jsx(ae,{className:"bg-muted text-muted-foreground",children:e.jsx(U,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:r.name}),r.tagline&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:r.tagline}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mt-1",children:[e.jsx(ha,{avg:r.rating_avg,count:r.rating_count}),r.certification_tier&&e.jsx(ta,{tier:r.certification_tier}),e.jsx(S,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:"Free"}),r.accepts_new_clients!==!1&&e.jsx(S,{variant:"secondary",className:"text-[10px] h-4 px-1.5",children:"Accepting"})]})]})]}),e.jsx(X,{className:"h-4 w-4 text-muted-foreground shrink-0 mt-1"})]})})},r.id))]})]}),u&&e.jsxs(e.Fragment,{children:[e.jsx(J,{}),e.jsx(P,{className:"border-primary/20 bg-gradient-to-r from-primary/5 to-transparent cursor-pointer hover:border-primary/40 transition-colors",onClick:()=>p(!0),children:e.jsxs(Y,{className:"flex items-center gap-3 p-3",children:[e.jsx(Se,{className:"h-5 w-5 text-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Know a coach? Invite them"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You both get 1 month of Pro when they sign their first paying player"})]}),e.jsx(ue,{className:"h-5 w-5 text-muted-foreground shrink-0"})]})}),e.jsx(Ea,{})]}),e.jsx(he,{open:!!d,onOpenChange:r=>{r||w(null)},preselectedOrg:d}),e.jsx(he,{open:!!y,onOpenChange:r=>{r||C(null)},preselectedOrg:$||null,hideRequestForm:!0,pendingNotice:"Your join request is pending review. You'll be notified once the coach responds. You can cancel the request from the previous screen."}),e.jsx(ga,{membership:o,open:!!o,onOpenChange:r=>{r||x(null)},logoUrl:o?_==null?void 0:_[o.organization.id]:null}),e.jsx(La,{open:N,onOpenChange:p})]})};export{ns 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.