1import{r as n,j as e,U as k,a as Ce,a4 as we,Y as M,bD as Pe,ce as Ae,bl as Re,ak as Le,a7 as ke,Z as De}from"./vendor-CAFxqyA_.js";import{bf as B,aU as ne,ia as re,i6 as ie,id as le,aX as oe,aY as ce,ie as ue,a_ as de,c as L,g as U,ig as me,ih as pe,im as Ee,io as Fe,u as W,b1 as Me,ii as Y,ik as Be,b as V,ij as X,o as Te,C as Z,hL as J,il as q,n as Q,cg as Ue}from"./index-BK8JT8yM.js";import{A as Ie,a as He,b as Ye}from"./AthleteStatusBadge-BGiG2tSf.js";import{P as Oe}from"./PageTabs-CKQsbACr.js";import{A as _e,a as Ke,b as O}from"./AthleteResubscribeWaiverGate-pfEzpWf3.js";import{A as We}from"./AthleteCompanyWaiversPanel-DyAxDVIc.js";import{d as Ve}from"./AthleteNutritionCard-o0KJ4uV9.js";import{a as he,u as fe}from"./stripe-Cewq76PC.js";import{p as ee,P as ge,i as xe,r as be,a as qe,e as Ge}from"./waiverSigningSubmit-onYV5QiK.js";import{S as ye}from"./SideDrawer-BM2asQnC.js";import{r as T,L as te,B as se}from"./firebase-D4orPhEo.js";import{m as $e}from"./athleteProgramBillingHistory-rvhuvqOw.js";import{w as ze}from"./withCheckoutTimeout-FRaqOY4B.js";import{c as Xe,n as Ne,a as Ze,b as Je}from"./nutritionClientCheckout-B85WBghH.js";import{d as _,e as ae,g as Qe}from"./athleteDashboard-rE7THLE2.js";import"./athleteGymMembershipStatus-Badqz9td.js";import"./athleteProgramStatus-CTsm6In7.js";import"./useCheckoutWaiverGate-B6Q2HReU.js";import"./checkoutEntryPhase-Df0MfPCG.js";import"./memberWaiver-DXp7dFAz.js";import"./nutritionDisplay-YzS_TzRt.js";import"./statusBadges-B85EcjIx.js";import"./CheckoutContactBillingFields-Cid1sD0h.js";import"./checkoutMarketingCopy-FVDV-utN.js";import"./marketingSmsUtils-BvoXH2kx.js";import"./WaiverSigningContent-DnRPK0k0.js";import"./nutritionClientCover-7-lZPABD.js";import"./programPublicUrl-C9flt1ED.js";import"./athleteNutritionPlanStatus-FIqRA62s.js";function I(t,s){const r=t;if(!r?.success)throw new Error(r?.message||s);return r}async function et(t,s=50){const o=await T(B,"getNutritionClientPaymentHistory")({nutritionClientId:t,limit:s});return o.data?.success?(o.data.payments??[]).map($e):[]}async function tt(t){const r=await T(B,"cancelNutritionClientSubscription")({nutritionClientId:t});I(r.data,"Failed to cancel subscription.")}async function st(t){const r=await T(B,"leaveFreeNutritionClient")({nutritionClientId:t});I(r.data,"Failed to leave nutrition coaching.")}async function at(t){const r=await T(B,"resubscribeNutritionClientSubscription")({nutritionClientId:t});return I(r.data,"Failed to resubscribe."),r.data}async function nt(t){const r=await T(B,"createNutritionClientPaymentMethodSetupIntent")({nutritionClientId:t});return I(r.data,"Failed to load payment form."),{...r.data,connectAccountId:r.data.connectAccountId||r.data.stripeAccountId}}async function rt(t,s,r){const u=await T(B,"setNutritionClientDefaultPaymentMethod")({nutritionClientId:t,paymentMethodId:s,...r?{billingAddress:r}:{}});I(u.data,"Failed to update payment method.")}function it({nutritionClientId:t,addressForm:s,paymentElementOptions:r,remountKey:o,onSuccess:u}){const N=he(),l=fe(),[i,d]=n.useState(!1),[c,a]=n.useState(null),[b,y]=n.useState(!1),m=xe(s),p=async()=>{if(!N||!l)return;const h=be(s);if("error"in h){a(h.error);return}const f=h.address;d(!0),a(null);try{const{error:x}=await l.submit();if(x){a(x.message??"Validation failed");return}const{error:g,setupIntent:S}=await N.confirmSetup({elements:l,confirmParams:me({billingAddress:pe(f),email:f.email}),redirect:"if_required"});if(g){a(g.message??"Update failed");return}const j=S?.payment_method;S?.status==="succeeded"&&j&&typeof j=="string"?(await rt(t,j,f),u()):a("Payment Method setup incomplete.")}catch(x){a(x instanceof Error?x.message:"Failed to save payment method.")}finally{d(!1)}};return e.jsxs(ue,{ready:!0,framed:!1,title:null,children:[e.jsx(de,{mountKey:o,options:r,compact:!0,onReadyChange:y,onLoadError:a}),e.jsxs("button",{type:"button",onClick:()=>{p()},disabled:!N||!b||!m||i,className:L(U,"inline-flex w-full items-center justify-center gap-2"),children:[i?e.jsx(k,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,"Save payment method"]}),c?e.jsx("p",{className:"rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700",role:"alert",children:c}):null]})}function lt({nutritionClientId:t,existingCustomerAddress:s,clientSecret:r,stripePromise:o,isDarkMode:u,onSuccess:N}){const{sessionReady:l,isSignedIn:i,buildPrefill:d}=ie(),[c,a]=n.useState(()=>ee(s)),b=ce(r);n.useEffect(()=>{a(ee(s))},[s]),n.useEffect(()=>{if(!l||!i)return;const m=d();a(p=>({...p,firstName:p.firstName||m.firstName,lastName:p.lastName||m.lastName,email:p.email||m.email,phone:p.phone||m.phone||""}))},[d,i,l]);const y=n.useMemo(()=>le({country:c.country}),[c.country]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{value:c,onChange:a}),e.jsx(oe,{stripePromise:o,clientSecret:r,isDarkMode:u,remountKey:b,skipMountGate:!0,appearancePreset:"shop",children:e.jsx(it,{nutritionClientId:t,addressForm:c,paymentElementOptions:y,remountKey:b,onSuccess:N})})]})}function ot({open:t,nutritionClientId:s,companyId:r,onClose:o,onSuccess:u,onError:N}){const[l,i]=n.useState(!1),[d,c]=n.useState(null),[a,b]=n.useState(null),[y,m]=n.useState(void 0);n.useEffect(()=>{if(!t||!s){c(null),b(null),m(void 0),i(!1);return}let h=!1;return i(!0),c(null),b(null),(async()=>{try{const f=await nt(s);if(!f.clientSecret||!f.connectAccountId)throw new Error("Payment setup is not available.");const x=ne({companyId:r,connectAccountId:f.connectAccountId,publishableKey:f.publishableKey});if(h)return;c(x),b(f.clientSecret),m(f.existingCustomerAddress)}catch(f){h||(N(f instanceof Error?f.message:"Failed to load card form."),o())}finally{h||i(!1)}})(),()=>{h=!0}},[r,o,N,t,s]);const p=re();return e.jsx(ye,{open:t,onClose:o,title:"Update Payment Method",description:"Your new card will be used for future nutrition coaching charges.",widthClass:"max-w-lg",closeDisabled:l,children:l?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-gray-400","aria-hidden":!0})}):!d||!a?e.jsx("p",{className:"rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700",role:"alert",children:"Unable to load card form. Close and try again."}):e.jsx(lt,{nutritionClientId:s,existingCustomerAddress:y,clientSecret:a,stripePromise:d,isDarkMode:p,onSuccess:()=>{u(),o()}})})}function ct(t){if(!(typeof t!="number"||!Number.isFinite(t)||t<0))return Math.round(t*100)}function ut({clientId:t,clientSecret:s,addressForm:r,paymentElementOptions:o,remountKey:u,marketingOptIn:N,payAmountCents:l,onSuccess:i,onError:d}){const c=he(),a=fe(),{currentUser:b}=W(),[y,m]=n.useState(!1),[p,h]=n.useState(null),[f,x]=n.useState(!1),[g,S]=n.useState(!1),j=xe(r),D=async()=>
1{if(!c||!a||!s)return;const v=be(r);if("error"in v){h(v.error);return}const A=v.address;m(!0),h(null);let F=!1;try{const{error:P}=await a.submit();if(P){h(P.message??"Validation failed");return}const{error:R,setupIntent:C}=await c.confirmSetup({elements:a,clientSecret:s,confirmParams:me({billingAddress:pe(A),email:A.email}),redirect:"if_required"});if(R){h(R.message??"Payment setup failed");return}if(!C?.id){h("Failed to collect payment method.");return}if(!b?.uid){h("Sign in to continue.");return}const E=await Ze({clientId:t,setupIntentId:C.id,billingAddress:A});await Je({clientId:t,userId:b.uid,subscriptionResult:E,stripe:c}),F=!0,S(!0),i(),Ge(b.uid)}catch(P){const R=Ne(P);h(R),d(R)}finally{F||m(!1)}};return g?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-gray-400","aria-hidden":!0})}):e.jsxs(ue,{ready:!0,children:[e.jsx(de,{mountKey:u,options:o,compact:!0,onReadyChange:x,onLoadError:h}),e.jsxs("button",{type:"button",onClick:()=>{D()},disabled:y||!f||!j,className:L(U,"inline-flex w-full items-center justify-center gap-2"),children:[y?e.jsx(k,{className:"h-4 w-4 animate-spin","aria-hidden":!0}):null,Me("Subscribe",l)]}),p?e.jsx("p",{className:"rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700",role:"alert",children:p}):null]})}function dt({clientId:t,clientSecret:s,stripePromise:r,isDarkMode:o,payAmountCents:u,onSuccess:N,onError:l}){const{sessionReady:i,isSignedIn:d,buildPrefill:c}=ie(),[a,b]=n.useState(()=>qe()),[y,m]=n.useState(!0),p=ce(s);n.useEffect(()=>{if(!i||!d)return;const f=c();b(x=>({...x,firstName:f.firstName,lastName:f.lastName,email:f.email,phone:f.phone||x.phone}))},[c,d,i]);const h=n.useMemo(()=>le({country:a.country}),[a.country]);return e.jsxs("form",{id:"nutrition-client-resubscribe-payment-form",onSubmit:f=>f.preventDefault(),className:"space-y-4",children:[e.jsx(ge,{value:a,onChange:b,marketingOptIn:y,onMarketingOptInChange:m}),e.jsx(oe,{stripePromise:r,clientSecret:s,isDarkMode:o,remountKey:p,skipMountGate:!0,appearancePreset:"shop",children:e.jsx(ut,{clientId:t,clientSecret:s,addressForm:a,paymentElementOptions:h,remountKey:p,marketingOptIn:y,payAmountCents:u,onSuccess:N,onError:l})})]})}function mt({open:t,clientId:s,companyId:r,priceLabel:o,priceAmount:u,isPaymentRequired:N=!1,onClose:l,onSuccess:i,onError:d}){const[c,a]=n.useState(!1),[b,y]=n.useState(!1),[m,p]=n.useState(null),[h,f]=n.useState(null),x=n.useRef(!1),g=n.useRef(0),S=n.useRef(l),j=n.useRef(d);S.current=l,j.current=d,n.useEffect(()=>{t&&Ee()},[t]),n.useEffect(()=>{if(!t){x.current=!1,y(!1),p(null),f(null),a(!1);return}if(x.current)return;let P=!1;const R=++g.current;return a(!0),p(null),f(null),(async()=>{try{const C=await ze(Xe(s));if(!C.success||!C.clientSecret||!C.connectAccountId)throw new Error(C.message??"Failed to initialize payment.");const E=ne({companyId:r,connectAccountId:C.connectAccountId,publishableKey:C.publishableKey});if(P||x.current||R!==g.current)return;p(E),f(C.clientSecret)}catch(C){!P&&!x.current&&R===g.current&&(j.current(Ne(C)),S.current())}finally{!P&&!x.current&&R===g.current&&a(!1)}})(),()=>{P=!0}},[s,r,t]);const D=re(),v=N?"Add payment method":"Resubscribe",A=N?"Add your billing details and payment method to start nutrition coaching.":"Add your billing details and payment method to restart nutrition coaching.",F=()=>{x.current=!0,y(!0),i()};return e.jsx(ye,{open:t,onClose:l,title:v,description:A,widthClass:"max-w-lg",closeDisabled:c||b,children:e.jsx(_e,{open:t,companyId:r,surface:"nutrition",providerName:"your coach",children:b||c?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(k,{className:"h-6 w-6 animate-spin text-gray-400","aria-hidden":!0})}):!m||!h?e.jsx("p",{className:"rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700",role:"alert",children:"Unable to load payment. Close and try again."}):e.jsx(dt,{clientId:s,clientSecret:h,stripePromise:m,isDarkMode:D,payAmountCents:ct(u)??Fe(o),onSuccess:F,onError:d})})})}const pt=[{id:"overview",label:"Overview"},{id:"billing",label:"Billing"},{id:"waivers",label:"Waivers"}];function K({label:t,value:s,unit:r}){return e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50 px-3 py-3 text-center",children:[e.jsxs("p",{className:"text-lg font-semibold tabular-nums text-gray-900",children:[s.toLocaleStr
1ing(),e.jsx("span",{className:"ml-0.5 text-xs font-normal text-gray-500",children:r})]}),e.jsx("p",{className:"mt-0.5 text-xs text-gray-500",children:t})]})}function ht({row:t}){const s=t.refundStatus!=="none";return e.jsxs("li",{className:"flex items-start justify-between gap-4 px-4 py-4 sm:px-5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:t.dateLabel}),e.jsx("span",{className:L("inline-flex rounded-full px-2 py-0.5 text-xs font-medium",t.paymentStatusLabel==="Paid"?"bg-emerald-50 text-emerald-700":t.paymentStatusLabel==="Pending"?"bg-gray-100 text-gray-700":"bg-red-50 text-red-700"),children:t.paymentStatusLabel}),s?e.jsx("span",{className:L("inline-flex rounded-full px-2 py-0.5 text-xs font-medium",t.refundStatus==="full"?"bg-gray-100 text-gray-700":"bg-orange-50 text-orange-700"),children:t.refundStatus==="full"?"Fully Refunded":"Partially Refunded"}):null]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500",children:t.description}),t.documentUrl?e.jsxs("a",{href:t.documentUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-2 inline-flex text-xs font-medium text-gray-900 hover:underline",children:["View ",t.documentType==="receipt"?"Receipt":"Invoice"]}):null]}),e.jsx("div",{className:"shrink-0 text-right",children:s?e.jsxs("div",{className:"flex flex-col items-end",children:[e.jsx("p",{className:"text-xs text-gray-400 line-through",children:t.originalAmountLabel}),e.jsx("p",{className:L("text-sm font-semibold",t.refundStatus==="full"?"text-gray-500":"text-gray-900"),children:t.netAmountLabel}),t.refundedAmountLabel?e.jsxs("p",{className:"mt-0.5 text-xs font-medium text-red-600",children:["â",t.refundedAmountLabel," refunded"]}):null]}):e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:t.netAmountLabel})})]})}function ft(t){const{client:s,isFree:r}=t,o=s.isDeleted===!0,u=s.billingStatus.toLowerCase(),N=s.status==="LIVE"&&!o,l=!o&&(u==="canceling"||s.cancelAtPeriodEnd===!0),i=!o&&u==="paused",d=!o&&!i&&(u==="inactive"||s.status==="INACTIVE"),c=N&&u==="active",a=!o&&c&&!r,b=!o&&(c||i)&&!l&&!r,y=!o&&N&&l&&!r,m=!o&&!r&&!l&&!i&&(d||s.hadStripeEnrollment===!0&&!c);return{canManageBilling:a,canCancelSubscription:b,canReactivateSubscription:y,canResubscribe:m,canLeaveFree:!o&&r,isDeleted:o,isCanceling:l,isPaused:i,isInactive:d}}function gt({detail:t,activeTab:s,onTabChange:r,onRefresh:o,loadingBilling:u=!1}){const N=Ce(),{currentUser:l}=W(),{client:i}=t,d=Ve(i),c=t.isFree,a=ft(t),b=i.companyName?.trim()||"Your Coach",[y,m]=n.useState(null),[p,h]=n.useState(!1),[f,x]=n.useState(!1),[g,S]=n.useState(!1),[j,D]=n.useState(!1),[v,A]=n.useState(!1),[F,P]=n.useState(!1),[R,C]=n.useState(!1),E=a.isInactive&&!c&&i.hadStripeEnrollment!==!0,je=!c||t.billingHistory.length>0;async function H(){await o?.()}async function Se(){if(!g){S(!0),m(null);try{await tt(i.id),h(!1),await H()}catch(w){m(w instanceof Error?w.message:"Failed to cancel subscription.")}finally{S(!1)}}}async function ve(){if(!j){D(!0),m(null);try{await st(i.id),x(!1),N(q())}catch(w){m(w instanceof Error?w.message:"Failed to leave nutrition coaching.")}finally{D(!1)}}}async function G(){if(!v){if(a.canResubscribe){C(!0);return}if(a.canReactivateSubscription){A(!0),m(null);try{if((await at(i.id)).action==="new_subscription_required"){C(!0);return}await H()}catch(w){const $=w instanceof Error?w.message:"Failed to resubscribe.",z=$.toLowerCase();z.includes("waiver")||z.includes("sign")?(C(!0),m("Please sign the updated waiver, then try again.")):m($)}finally{A(!1)}}}}return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ke,{title:"Nutrition Coaching",subtitle:i.companyName||void 0,statusLabel:d.label,statusTone:d.tone,leading:i.coverImageUrl?e.jsx("img",{src:i.coverImageUrl,alt:"",className:"h-12 w-12 rounded-lg object-cover"}):i.companyLogo?e.jsx("img",{src:i.companyLogo,alt:"",className:"h-12 w-12 rounded-lg border border-gray-200 bg-white object-contain p-2"}):e.jsx("span",{className:"flex h-12 w-12 items-center justify-center rounded-lg bg-gray-100 text-gray-600",children:e.jsx(we,{className:"h-6 w-6","aria-hidden":!0})})}),y?e.jsx("p",{className:"rounded-lg bg-red-50 px-4 py-3 text-sm text-red-700",role:"alert",children:y}):null,a.isDeleted?e.jsx(Y,{variant:"block",icon:M,title:"Nutrition Coaching Deleted",className:"border-red-200 bg-red-50 text-red-700",children:e.jsx("p",{className:"text-red-800",children:c?"This nutrition coaching has been deleted. Access is no longer available.":"This nutrition coaching has been deleted. Your Subscription has ended and access is no longer available."})}):null,!a.isDeleted&&a.isCanceling?e.jsx(Y,{variant:"block",icon:M,title:"Subscription Canceled",children:"Your subscription is ending. You keep access until the current billing period ends."}):null,!a.isDeleted&&a.isInactive&&!c?e.jsx(Y,{variant:"block",icon:M,title:E?"Payment Required":"Access Ended",children:E?"Add a payment method to restore nutrition coaching access.":"Your nutrition coaching access has ended. Resubscribe to restore access."}
1):null,!a.isDeleted&&a.isPaused?e.jsx(Y,{variant:"block",icon:M,title:"Access Paused",children:c?"Your nutrition coaching is paused. You can leave below, or contact your coach if you need access restored.":"Your nutrition coaching and subscription are paused. You won't be charged until access resumes. You can cancel below, or contact your coach if you need help."}):null,e.jsx(Oe,{tabs:pt,activeTab:s,onChange:r}),s==="overview"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs(O,{title:"Your Coach",children:[e.jsx("p",{className:"text-sm text-gray-900",children:b}),e.jsxs("p",{className:"mt-2 text-sm text-gray-500",children:["Member since ",t.memberSinceLabel,". Open the WODBumP athlete app to log meals and track macros."]})]}),e.jsx(O,{title:"Daily Targets",description:"Set by your coach.",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(K,{label:"Calories",value:i.calories,unit:"kcal"}),e.jsx(K,{label:"Protein",value:i.protein,unit:"g"}),e.jsx(K,{label:"Carbs",value:i.carbohydrates,unit:"g"}),e.jsx(K,{label:"Fat",value:i.fat,unit:"g"})]})}),e.jsx(O,{title:"Log Meals in the App",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"rounded-lg bg-gray-100 p-2 text-gray-700",children:e.jsx(Pe,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Meal plans, logging, and progress live in the mobile app. This dashboard is for billing and account management."}),e.jsxs("a",{href:Be,target:"_blank",rel:"noopener noreferrer",className:L(U,"mt-4 inline-flex gap-2"),children:[e.jsx(Ae,{className:"h-4 w-4","aria-hidden":!0}),"Download Athlete App"]})]})]})})]}):null,s==="billing"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs(O,{title:c?"Coaching Details":"Current Plan",description:c?"No payment or billing on file.":void 0,children:[e.jsx("div",{className:"mb-4",children:e.jsx(Ie,{label:d.label,tone:d.tone})}),e.jsxs("dl",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-gray-500",children:"Plan"}),e.jsx("dd",{className:"font-medium text-gray-900",children:t.priceLabel})]}),e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-gray-500",children:"Payment type"}),e.jsx("dd",{className:c?"text-gray-500":"text-gray-900",children:t.billingIntervalLabel})]}),c?e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-gray-500",children:"Started"}),e.jsx("dd",{className:"text-gray-900",children:t.memberSinceLabel})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-gray-500",children:a.isCanceling?"Access Until":"Next Charge"}),e.jsx("dd",{className:"text-right text-gray-900",children:t.nextBillLabel})]}),e.jsxs("div",{className:"flex justify-between gap-4",children:[e.jsx("dt",{className:"text-gray-500",children:"Payment Method"}),e.jsx("dd",{className:"text-gray-900",children:t.paymentMethodLabel})]})]})]}),a.canManageBilling||a.canReactivateSubscription||a.canResubscribe||a.canCancelSubscription||a.canLeaveFree?e.jsxs("div",{className:"mt-5 flex flex-wrap gap-2",children:[a.canManageBilling?e.jsxs("button",{type:"button",onClick:()=>P(!0),className:L(V,"inline-flex items-center gap-2"),children:[e.jsx(Re,{className:"h-4 w-4","aria-hidden":!0}),"Update Payment Method"]}):null,a.canReactivateSubscription?e.jsxs("button",{type:"button",disabled:v,onClick:()=>{G()},className:U,children:[v?e.jsx(k,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}):null,"Reactivate subscription"]}):null,a.canResubscribe?e.jsxs("button",{type:"button",disabled:v,onClick:()=>{G()},className:U,children:[v?e.jsx(k,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}):null,E?"Add payment method":"Resubscribe"]}):null,a.canCancelSubscription?e.jsx("button",{type:"button",onClick:()=>h(!0),className:X,children:"Cancel Subscription"}):null,a.canLeaveFree?e.jsx("button",{type:"button",onClick:()=>x(!0),className:X,children:"Leave Nutrition Coaching"}):null]}):null]}),je?e.jsxs("section",{className:Te,children:[e.jsx("div",{className:"border-b border-gray-100 px-4 py-4 sm:px-5",children:e.jsx("h2",{className:"text-sm font-semibold text-gray-900",children:"Billing History"})}),u&&t.billingHistory.length===0?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-gray-500 sm:px-5",children:"Loading billing historyâ¦"}):e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"divide-y divide-gray-100",children:t.billingHistory.map(w=>e.jsx(ht,{row:w},w.id))}),t.billingHistory.length===0?e.jsx("p",{className:"px-4 py-8 text-center text-sm text-gray-500 sm:px-5",children:"No billing history yet."}):null]})]}):null]}
1):null,s==="waivers"?e.jsx(We,{companyId:i.companyId,userId:l?.uid,surface:"nutrition"}):null,i.companyId?e.jsxs(e.Fragment,{children:[e.jsx(ot,{open:F,nutritionClientId:i.id,companyId:i.companyId,onClose:()=>P(!1),onSuccess:()=>{H()},onError:w=>m(w)}),e.jsx(mt,{open:R,clientId:i.id,companyId:i.companyId,priceLabel:t.priceLabel,priceAmount:i.priceAmount,isPaymentRequired:E,onClose:()=>C(!1),onSuccess:()=>{C(!1),H()},onError:w=>m(w)})]}):null,e.jsx(Z,{open:p,onClose:()=>{g||h(!1)},titleId:"cancel-nutrition-subscription-title",title:"Cancel Subscription",description:"You will keep access until the end of the current billing period.",closeDisabled:g,icon:e.jsx("span",{className:"rounded-lg bg-red-50 p-2 text-red-700",children:e.jsx(M,{className:"h-5 w-5","aria-hidden":!0})}),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:g,onClick:()=>h(!1),className:L("flex-1",V),children:"Keep Subscription"}),e.jsxs("button",{type:"button",disabled:g,onClick:()=>{Se()},className:L("flex-1",J),children:[g?e.jsx(k,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}):null,g?"Cancelingâ¦":"Cancel Subscription"]})]})}),e.jsx(Z,{open:f,onClose:()=>{j||x(!1)},titleId:"leave-nutrition-title",title:"Leave Nutrition Coaching",description:"You will lose access to this free nutrition coaching immediately.",closeDisabled:j,icon:e.jsx("span",{className:"rounded-lg bg-red-50 p-2 text-red-700",children:e.jsx(M,{className:"h-5 w-5","aria-hidden":!0})}),actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:j,onClick:()=>x(!1),className:L("flex-1",V),children:"Stay Enrolled"}),e.jsxs("button",{type:"button",disabled:j,onClick:()=>{ve()},className:L("flex-1",J),children:[j?e.jsx(k,{className:"h-4 w-4 shrink-0 animate-spin","aria-hidden":!0}):null,j?"Leavingâ¦":"Leave"]})]})})]})}function xt(t,s){const{currentUser:r,sessionReady:o}=W(),u=r?.uid,[N,l]=n.useState(()=>{if(!o||!u||!t)return null;const g=_(u,t);return g?ae(g):null}),[i,d]=n.useState(()=>t?o?u?!_(u,t):!1:!0:!1),[c,a]=n.useState(!1),[b,y]=n.useState(null),m=n.useRef(null),p=n.useRef(null),h=n.useCallback(async g=>{if(!o)return;if(!u||!t){l(null),d(!1);return}const S=_(u,t),j=g?.silent===!0,D=g?.fromServer!==!1;!j&&!S&&d(!0),y(null);try{const v=await Qe(u,t,{fromServer:D});l(A=>v?{...v,billingHistory:A?.billingHistory.length?A.billingHistory:v.billingHistory}:null)}catch(v){!j&&!S&&l(null),y(v instanceof Error?v.message:"Could not load your nutrition coaching.")}finally{d(!1)}},[t,o,u]),f=n.useCallback(async()=>{if(!t)return;m.current===t||a(!0);try{const S=await et(t);m.current=t,l(j=>j&&{...j,billingHistory:S})}catch{l(S=>S&&{...S,billingHistory:[]})}finally{a(!1)}},[t]),x=n.useCallback(()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(()=>{p.current=null,h({silent:!0,fromServer:!0})},500)},[h]);return n.useEffect(()=>{if(!o){d(!0);return}if(!u||!t){l(null),d(!1);return}const g=_(u,t);g?(l(ae(g)),d(!1)):(l(null),d(!0)),m.current=null,h({silent:!!g,fromServer:!0})},[t,h,o,u]),n.useEffect(()=>{s?.activeTab==="billing"&&f()},[s?.activeTab,f]),n.useEffect(()=>{if(!u||!t)return;const g=te(se(Q,"NutritionClients",t),()=>{x()}),S=te(se(Q,"Users",u,"myNutrition",t),()=>{x()});return()=>{p.current&&(clearTimeout(p.current),p.current=null),g(),S()}},[t,x,u]),{detail:N,loading:i,loadingBilling:c,error:b,reload:h,reloadBilling:f}}function bt(t){const s=t.get("tab");return s==="billing"||s==="waivers"?s:"overview"}function $t(){const{clientId:t}=Le(),[s,r]=ke(),{sessionReady:o}=W(),u=bt(s),N=y=>{r(m=>{const p=new URLSearchParams(m);return y==="overview"?p.delete("tab"):p.set("tab",y),p},{replace:!0})},{detail:l,loading:i,loadingBilling:d,error:c,reload:a}=xt(t,{activeTab:u}),b=n.useMemo(()=>l?.client.companyName?{pageTitle:`Nutrition · ${l.client.companyName} · Athlete dashboard`}:{pageTitle:"Nutrition Coaching · Athlete dashboard"},[l?.client.companyName]);return Ue(b),e.jsxs(He,{title:l?.client.companyName?`${l.client.companyName} Nutrition`:"Nutrition Coaching",maxWidth:"max-w-3xl",children:[e.jsx(Ye,{to:q()}),(!o||i)&&!l?e.jsx("div",{className:"rounded-xl border border-gray-200 bg-white px-6 py-12 text-center shadow-sm",children:e.jsx("p",{className:"text-sm text-gray-600",children:"Loading nutritionâ¦"})}):c&&!l?e.jsx("p",{className:"rounded-lg bg-red-50 px-4 py-3 text-sm text-red-700",role:"alert",children:c}):l?e.jsx(gt,{detail:l,activeTab:u,onTabChange:N,onRefresh:()=>a({silent:!0,fromServer:!0}),loadingBilling:d}):e.jsxs("div",{className:"rounded-xl border border-gray-200 bg-white px-6 py-12 text-center shadow-sm",children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Nutrition coaching not found."}),e.jsx(De,{to:q(),className:"mt-3 inline-block text-sm font-medium text-gray-900 hover:underline",children:"Return to Dashboard"})]})]})}export{$t 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.