1import{r as p,j as e,m as d}from"./vendor-motion-9qIbWfdh.js";import{O as W,u as z,aG as y,N as I,j as Q,a7 as r,U as V,ai as b,k as M,aJ as Y,G as J,a$ as _,ae as A,a as D,aW as X,aa as g,T as Z,b0 as ee,b4 as P,as as F,ab as se,aB as R,a8 as v,ac as ae,a9 as te,q,g as O}from"./index-RER_5nha.js";import{a as f,u as L}from"./vendor-query-CrasLRbE.js";import{U as ie}from"./user-plus-YhgjuniB.js";import{M as ne}from"./map-pin-xlcybZvl.js";import"./vendor-react-C0Dkio3Y.js";import"./vendor-charts-JEUKlbbs.js";const re={1:"bg-red-500",2:"bg-orange-400",3:"bg-yellow-400",4:"bg-green-400",5:"bg-green-600"};function ue(){W("My Coach | VeriBite");const{toast:K}=z(),[h,w]=p.useState(""),k=p.useRef(null),{data:n,isLoading:B}=f({queryKey:["/api/my-coach"],queryFn:async()=>{const s=await fetch("/api/my-coach",{credentials:"include"});if(!s.ok)throw new Error("Failed to fetch coach data");return s.json()}}),{data:$}=f({queryKey:["/api/trainer-connections","client","pending"],queryFn:async()=>{const s=await fetch("/api/trainer-connections?role=client&status=pending",{credentials:"include"});return s.ok?s.json():[]}}),o=n?.connection?.id,m=n?.connected,{data:l,isLoading:C}=f({queryKey:["/api/coach-messages",o],queryFn:async()=>{const s=await fetch(`/api/coach-messages/${o}`,{credentials:"include"});return s.ok?s.json():[]},enabled:!!m&&!!o,refetchInterval:3e4});p.useEffect(()=>{m&&o&&l&&l.length>0&&fetch(`/api/coach-messages/${o}/read`,{method:"PATCH",credentials:"include"}).catch(()=>{})},[m,o,l?.length]),p.useEffect(()=>{k.current?.scrollIntoView({behavior:"smooth"})},[l]);const u=L({mutationFn:async s=>(await O("POST","/api/coach-messages",{connectionId:n.connection.id,receiverId:n.connection.trainerId,message:s})).json(),onSuccess:()=>{w(""),q.invalidateQueries({queryKey:["/api/coach-messages",o]})},onError:()=>{K({title:"Failed to send message",variant:"destructive"})}}),S=()=>{!h.trim()||u.isPending||u.mutate(h.trim())};if(B)return e.jsxs("div",{className:"min-h-screen bg-background flex items-center justify-center pb-32",children:[e.jsx(y,{className:"w-6 h-6 animate-spin text-muted-foreground"}),e.jsx(I,{})]});const i=n?.coach,a=n?.program,j=n?.habits||[],c=n?.dayTargets,T=n?.recentCheckins||[],N=$||[],E=new Date().toISOString().split("T")[0],{data:U}=f({queryKey:["/api/habits/completions",E],enabled:m&&j.length>0}),G=L({mutationFn:async s=>{await O("POST","/api/habits/toggle",{habit:s,date:E})},onSuccess:()=>{q.invalidateQueries({queryKey:["/api/habits/completions"]})}});return e.jsxs("div",{className:"min-h-screen bg-background pb-32",children:[e.jsx("div",{className:"sticky top-0 z-30 bg-background/95 backdrop-blur-md border-b border-border px-4 py-3",style:{paddingTop:"calc(env(safe-area-inset-top, 0px) + 12px)"},children:e.jsxs("div",{className:"flex items-center gap-3 max-w-lg lg:max-w-2xl mx-auto",children:[e.jsx(Q,{fallback:"/coaching","data-testid":"button-back-coach"}),e.jsx("div",{className:"flex-1",children:e.jsx("h1",{className:"text-base font-display font-bold","data-testid":"text-page-title",children:"My Coach"})})]})}),e.jsxs("div",{className:"px-4 max-w-lg lg:max-w-2xl mx-auto space-y-4 mt-4",children:[!m&&N.length===0&&e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:e.jsxs(r,{className:"p-6 text-center","data-testid":"card-no-coach",children:[e.jsx(V,{className:"w-10 h-10 text-muted-foreground/30 mx-auto mb-3"}),e.jsx("p",{className:"text-base font-medium mb-1",children:"No coach connected"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Connect with a certified coach to get personalized guidance on your nutrition and fitness journey"}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(b,{href:"/trainers",children:e.jsxs(M,{className:"w-full","data-testid":"button-find-coach",children:[e.jsx(ie,{className:"w-4 h-4 mr-1.5"}),"Find a Coach"]})})})]})}),N.length>0&&!m&&e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:e.jsx(r,{className:"p-4 border-amber-200 dark:border-amber-800 bg-amber-50/50 dark:bg-amber-950/20","data-testid":"card-pending-connection",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-amber-500/20 flex items-center justify-center flex-shrink-0",children:e.jsx(Y,{className:"w-5 h-5 text-amber-600 dar
1k:text-amber-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Connection pending"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Waiting for ",N[0].trainerProfile?.displayName||"your coach"," to accept"]})]})]})})}),m&&i&&e.jsxs(e.Fragment,{children:[e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},children:e.jsxs(r,{className:"p-4","data-testid":"card-coach-profile",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0",children:e.jsx(J,{className:"w-6 h-6 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-base font-display font-bold","data-testid":"text-coach-name",children:i.displayName}),i.city&&i.state&&e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(ne,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.city,", ",i.state]})]}),i.experienceYears&&e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[e.jsx(_,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.experienceYears," years experience"]})]})]}),e.jsxs(A,{variant:"secondary",className:"text-[10px] bg-emerald-100 dark:bg-emerald-900/30 text-emerald-700 dark:text-emerald-400",children:[e.jsx(D,{className:"w-3 h-3 mr-1"})," Connected"]})]}),i.bio&&e.jsx("p",{className:"text-xs text-muted-foreground mt-3 line-clamp-3",children:i.bio}),i.specialties&&i.specialties.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:i.specialties.slice(0,5).map((s,t)=>e.jsx(A,{variant:"secondary",className:"text-[10px]",children:s},t))})]})}),e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05},children:e.jsxs(r,{className:"p-4","data-testid":"card-coach-messages",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(X,{className:"w-4 h-4 text-primary"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"MESSAGES"})]}),e.jsxs("div",{className:"max-h-64 overflow-y-auto space-y-2 mb-3",children:[C&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(y,{className:"w-4 h-4 animate-spin text-muted-foreground"})}),!C&&(!l||l.length===0)&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"No messages yet. Start the conversation with your coach."}),l&&l.map(s=>{const t=s.senderId!==n.connection.trainerId;return e.jsx("div",{className:g("flex",t?"justify-end":"justify-start"),"data-testid":`message-item-${s.id}`,children:e.jsxs("div",{className:g("max-w-[80%] rounded-md px-3 py-2",t?"bg-primary text-primary-foreground":"bg-muted text-foreground"),children:[e.jsx("p",{className:"text-sm break-words",children:s.message}),e.jsx("p",{className:g("text-[10px] mt-1",t?"text-primary-foreground/70":"text-muted-foreground"),children:new Date(s.createdAt).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})})]})},s.id)}),e.jsx("div",{ref:k})]}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx(Z,{value:h,onChange:s=>w(s.target.value),placeholder:"Write a message...",className:"resize-none text-sm min-h-[40px] max-h-[80px]",rows:1,onKeyDown:s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),S())},"data-testid":"input-coach-message"}),e.jsx(M,{size:"icon",onClick:S,disabled:!h.trim()||u.isPending,"data-testid":"button-send-message",children:u.isPending?e.jsx(y,{className:"w-4 h-4 animate-spin"}):e.jsx(ee,{className:"w-4 h-4"})})]})]})}),e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1},children:e.jsx(b,{href:"/daily-checkin",children:e.jsx(r,{className:"p-4 bg-primary/5 border-primary/20 cursor-pointer hover-elevate","data-testid":"card-checkin-cta",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center flex-shrink-0",children:e.jsx(P,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Daily Check-in"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Log your readiness, sleep, water, and habits"})]}),e.jsx(F,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"})]})})})}),a&&e.jsx(d.div,{initial:{opacity:0,y:10}
1,animate:{opacity:1,y:0},transition:{delay:.1},children:e.jsxs(r,{className:"p-4","data-testid":"card-active-program",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(se,{className:"w-4 h-4 text-primary"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"ACTIVE PROGRAM"})]}),e.jsx("p",{className:"text-sm font-display font-bold","data-testid":"text-program-name",children:a.name}),a.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1","data-testid":"text-program-description",children:a.description}),a.startedAt&&a.duration&&e.jsx("div",{className:"mt-3","data-testid":"program-progress",children:(()=>{const s=Math.floor((Date.now()-new Date(a.startedAt).getTime())/6048e5),t=Math.min(s/a.duration*100,100);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground mb-1",children:[e.jsxs("span",{children:["Week ",Math.min(s+1,a.duration)," of ",a.duration]}),e.jsxs("span",{children:[Math.round(t),"%"]})]}),e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${t}%`}})})]})})()}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.duration," weeks"]})]}),a.startedAt&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(R,{className:"w-3 h-3 text-muted-foreground"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Started ",new Date(a.startedAt).toLocaleDateString()]})]}),a.dailyCalories&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(v,{className:"w-3 h-3 text-orange-500"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.dailyCalories," cal/day"]})]}),a.dailyProtein&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ae,{className:"w-3 h-3 text-emerald-500"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.dailyProtein,"g protein"]})]})]}),a.habits&&a.habits.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1.5",children:"PROGRAM HABITS"}),e.jsx("div",{className:"space-y-1",children:a.habits.map((s,t)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary flex-shrink-0"}),e.jsx("span",{className:"text-xs text-foreground",children:s})]},t))})]}),a.questions&&a.questions.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1.5",children:"CHECK-IN QUESTIONS"}),e.jsx("div",{className:"space-y-1",children:a.questions.map((s,t)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"text-[10px] text-muted-foreground mt-0.5",children:[t+1,"."]}),e.jsx("span",{className:"text-xs text-foreground",children:s})]},t))})]})]})}),j.length>0&&e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.2},children:e.jsxs(r,{className:"p-4","data-testid":"card-assigned-habits",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(te,{className:"w-4 h-4 text-amber-500"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"DAILY HABITS FROM COACH"})]}),e.jsx("div",{className:"space-y-2",children:j.map((s,t)=>{const x=U?.some(H=>H.habit===s);return e.jsxs("div",{className:`flex items-center gap-3 p-2 rounded-md cursor-pointer transition-colors ${x?"bg-green-500/10":"bg-muted/30"}`,onClick:()=>G.mutate(s),"data-testid":`habit-toggle-${t}`,children:[e.jsx("div",{className:`w-5 h-5 rounded border-2 flex items-center justify-center flex-shrink-0 transition-colors ${x?"bg-green-500 border-green-500":"border-muted-foreground/30"}`,children:x&&e.jsx(D,{className:"w-3.5 h-3.5 text-white"})}),e.jsx("span",{className:`text-sm ${x?"line-through text-muted-foreground":"text-foreground"}`,children:s})]},t)})}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-2",children:"Tap to mark habits as done"})]})}),c&&e.jsx(d.div,{initial:{opacity:0,y:10}
1,animate:{opacity:1,y:0},transition:{delay:.25},children:e.jsxs(r,{className:"p-4","data-testid":"card-day-targets",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(v,{className:"w-4 h-4 text-orange-500"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"NUTRITION TARGETS"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-2 bg-muted/30 rounded-md",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Training Day"}),e.jsxs("p",{className:"text-sm font-medium",children:[c.trainingCalories||"â"," cal"]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["P: ",c.trainingProtein||"â","g / C: ",c.trainingCarbs||"â","g / F: ",c.trainingFat||"â","g"]})]}),e.jsxs("div",{className:"p-2 bg-muted/30 rounded-md",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Rest Day"}),e.jsxs("p",{className:"text-sm font-medium",children:[c.restCalories||"â"," cal"]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["P: ",c.restProtein||"â","g / C: ",c.restCarbs||"â","g / F: ",c.restFat||"â","g"]})]})]})]})}),T.length>0&&e.jsx(d.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.3},children:e.jsxs(r,{className:"p-4","data-testid":"card-recent-checkins",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(P,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"RECENT CHECK-INS"})]}),e.jsx("div",{className:"flex gap-1.5",children:T.map((s,t)=>{const x=s.readinessScore||3;return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1",children:[e.jsx("div",{className:g("w-full h-8 rounded-md",re[x]||"bg-muted")}),e.jsx("span",{className:"text-[9px] text-muted-foreground",children:new Date(s.date||s.createdAt).toLocaleDateString("en-US",{weekday:"narrow"})})]},t)})})]})}),e.jsx("div",{className:"pb-4",children:e.jsx(b,{href:"/daily-intake",children:e.jsx(r,{className:"p-3 hover-elevate cursor-pointer","data-testid":"link-daily-intake",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-orange-500/10 flex items-center justify-center",children:e.jsx(v,{className:"w-4 h-4 text-orange-500"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Today's Intake"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"View your logged meals and macros"})]}),e.jsx(F,{className:"w-4 h-4 text-muted-foreground"})]})})})})]})]}),e.jsx(I,{})]})}export{ue 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.