PageSourceSearch

https://www.recipealchemy.ai/assets/DietPreferences-Nj5q3y2R.js

js recipealchemy.ai collected 2026-10-05 14:00:52 UTC 107,212 bytes, 291 lines download raw bytes

1import{j as e}from"./vendor-radix-BPSkPlGE.js";import{a as b,N as Rs}from"./vendor-router-ijjF5Wqn.js";import{bE as Ie,bF as Os,s as Bs,bG as ss,$ as x,bH as as,B as C,bI as is,T as ze,h as Fe,i as Re,bJ as Vs,aD as J,l as G,aE as be,bK as Gs,aF as Oe,f as ts,aK as E,ao as L,J as T,aJ as H,bL as $s,bM as Us,bN as Ws,bO as Hs,bP as Ys,_ as le,w as ns,x as Y,F as Ks,aG as rs,ah as cs,ai as os,aj as ls,ak as ds,al as ms,bQ as Ee,Y as Ye,aI as qs,aH as Js,u as ps,bR as Qs,bS as Xs,I as us,bT as F,bU as Zs,bV as Q,bW as ea,ay as gs,az as ee,aA as se,aB as ae,bX as sa,bY as aa,aN as ia,bZ as ta,bm as xe,P as Se,b_ as na,C as ra,D as ca,g as oa,b$ as la}from"./index-CDKaVpGr.js";import{P as Pe}from"./page-section-D0F9AI0s.js";import{aw as Be,q as ye,$ as da,_ as fe,y as de,a0 as fs,Q as Ve,ax as hs,a9 as te,n as ma,ay as xs,R as _s,ae as vs,az as pa,aA as ua,ai as bs,f as B,O as ys,g as ne,J as je,r as ga,aB as re,U as ge,a1 as fa,aC as ha,aD as xa,a7 as _a,aE as va,aF as ba,L as ya,aG as ja,a as Na,aH as Ke}from"./vendor-lucide-DdygwJ1I.js";import{u as wa}from"./vendor-query-DagTE0Ex.js";import{A as K,g as ka,e as js,f as Ca,h as Sa,t as qe,c as Pa,i as Ma,j as Aa,b as Da,H as Ia,W as Ea,d as Ta,k as Ns,l as ws,a as Te}from"./allergy-packs-BoK2dRJ7.js";import{g as ks,h as Cs,D as La,c as za,s as Fa,a as Ss,f as Ps,b as Ra}from"./DietInfoSheet-D6WFQxyD.js";import{U as Oa}from"./UniversalToggleGroup-BQsIi4yn.js";import"./vendor-supabase-CaTYeyJT.js";import"./vendor-mermaid-CP2TjrIP.js";const ie={MAJOR_DELTA:15,MIN_FAT_PCT:10,MAX_PROTEIN_PCT:50,MIN_PROTEIN_PCT:10},Ba=new Set(["keto","low-carb-high-protein","zone","atkins","carnivore"]);function Va(s){if(s.basis!=="calories")return!1;const i=s.protein_pct+s.carbs_pct+s.fat_pct;return i>=99&&i<=101}function Ga(s){if(Ba.has(s.pack_id))return"macro_defined";const i=s.defaults;if(i?.ui_hints&&typeof i.ui_hints=="object"){const t=i.ui_hints;if(t.macro_suggestion&&typeof t.macro_suggestion=="object"){const r=t.macro_suggestion;if(r.kind==="macro_defined")return"macro_defined";if(r.kind==="pattern")return"pattern"}}return s.family==="B_nutrient"||s.capabilities?.defines_macros===!0?"macro_defined":"pattern"}function $a(s){return s==="macro_defined"?1:.5}function Ua(s){return s.map(i=>{const n=ks(i);if(!n)return null;if(!Va(n))return console.warn(`[macro-merge] Invalid suggestion in pack ${i.pack_id}: basis=${n.basis}, sum=${n.protein_pct+n.carbs_pct+n.fat_pct}`),null;const t=Ga(i);return{pack_id:i.pack_id,pack_display_name:i.display_name,suggestion:n,kind:t,weight:$a(t)}}).filter(i=>i!==null)}function Wa(s){const i=[],n=[],t=s.filter(c=>c.kind==="macro_defined"),r=s.filter(c=>c.kind==="pattern");for(let c=0;c<t.length;c++)for(let a=c+1;a<t.length;a++){const m=t[c],o=t[a],d=["protein_pct","carbs_pct","fat_pct"];for(const l of d){const u=Math.abs(m.suggestion[l]-o.suggestion[l]);if(u>=ie.MAJOR_DELTA){const g=l.replace("_pct","");i.push({kind:"divergence",packs:[m.pack_id,o.pack_id],metric:l,delta:u,message:`${m.pack_display_name} and ${o.pack_display_name} differ by ${u}% on ${g}`})}}}for(const c of t)for(const a of r){const m=["protein_pct","carbs_pct","fat_pct"];for(const o of m){const d=Math.abs(c.suggestion[o]-a.suggestion[o]);if(d>=ie.MAJOR_DELTA){const l=o.replace("_pct","");n.push({packs:[c.pack_id,a.pack_id],metric:o,delta:d,message:`${a.pack_display_name} suggests different ${l} than ${c.pack_display_name} (${d}% difference)`})}}}return{conflicts:i,warnings:n}}function Ha(s){if(s.length===0)return null;if(s.length===1){const o=s[0];return{...o.suggestion,source_pack_ids:[o.pack_id]}}const i=s.filter(o=>o.kind==="macro_defined");if(i.length===0)return Ya(s);const n=Math.min(...i.map(o=>o.suggestion.carbs_pct)),t=Math.max(...i.map(o=>o.suggestion.protein_pct));if(t+n>100-ie.MIN_FAT_PCT)return null;const r=Math.min(t,ie.MAX_PROTEIN_PCT),c=n,a=100-c-r;if(a<ie.MIN_FAT_PCT||r<ie.MIN_PROTEIN_PCT)return null;const m=i.map(o=>o.pack_display_name).join(" + ");return{basis:"calories",protein_pct:r,carbs_pct:c,fat_pct:a,description:`Combined from ${m}`,source_pack_ids:i.map(o=>o.pack_id)}}function Ya(s){if(s.length===0)return null;const i=s.reduce((c,a)=>c+a.weight,0),n=Math.round(s.reduce((c,a)=>c+a.suggestion.protein_pct*a.weight,0)/i),t=Math.round(s.reduce((c,a)=>c+a.suggestion.carbs_pct*a.weight,0)/i),r=100-n-t;
1return{basis:"calories",protein_pct:n,carbs_pct:t,fat_pct:r,description:"Blended suggestion",source_pack_ids:s.map(c=>c.pack_id)}}function Ka(s){const i=Ua(s);if(i.length===0)return{status:"none",conflicts:[],warnings:[],candidates:[],recommended_action:"do_nothing"};if(i.length===1){const c=i[0];return{status:"single",merged:{...c.suggestion,source_pack_ids:[c.pack_id]},conflicts:[],warnings:[],candidates:i,recommended_action:"auto_apply"}}const{conflicts:n,warnings:t}=Wa(i);if(n.length>0)return{status:"conflict",conflicts:n,warnings:t,candidates:i,recommended_action:"ask_user"};const r=Ha(i);return r?{status:"merged",merged:r,conflicts:[],warnings:t,candidates:i,recommended_action:t.length>0?"ask_user":"auto_apply"}:{status:"conflict",conflicts:[{kind:"incompatible_constraints",packs:i.map(c=>c.pack_id),metric:"fat_pct",delta:0,message:"Combined constraints result in invalid macro distribution"}],warnings:t,candidates:i,recommended_action:"ask_user"}}function qa(s){return!s||typeof s!="object"?{}:s}function Ja(s){switch(s){case"blocker":return"text-destructive";case"error":return"text-destructive";case"warning":return"text-warning";case"info":return"text-muted-foreground";default:return"text-muted-foreground"}}function Qa(s){switch(s){case"blocker":return"bg-destructive/10 border-destructive/20";case"error":return"bg-destructive/10 border-destructive/20";case"warning":return"bg-warning/10 border-warning/20";case"info":return"bg-muted/50 border-border";default:return"bg-muted/50 border-border"}}const Le={all:["diet-conflicts"],list:()=>[...Le.all,"list"],forPacks:s=>[...Le.all,"for-packs",...s.sort()]};function Ms(s,i){const n=i.find(c=>c.pack_id===s.pack_a_id),t=i.find(c=>c.pack_id===s.pack_b_id);if(!n||!t)return!1;const r=(c,a)=>a?Ie(c,a)>=0:!0;return r(n.version,s.pack_a_version)&&r(t.version,s.pack_b_version)}function Ge(){return wa({queryKey:Le.list(),queryFn:async()=>{const{data:s,error:i}=await Bs.from("diet_pack_conflicts").select("*").order("severity",{ascending:!1}).order("created_at",{ascending:!1});if(i)throw new Error(`Failed to fetch diet pack conflicts: ${i.message}`);return s},staleTime:Os})}function Xa(s,i){const{data:n,isLoading:t,error:r}=Ge(),c=b.useMemo(()=>{if(!n||!i||s.length<2)return[];const a=new Map(i.map(d=>[d.pack_id,d])),m=[];for(const d of n){if(!Ms(d,s))continue;const l=a.get(d.pack_a_id),u=a.get(d.pack_b_id);m.push({conflict:d,pack_a_display_name:l?.display_name||d.pack_a_id,pack_b_display_name:u?.display_name||d.pack_b_id,suggested_resolution:qa(d.suggested_resolution),user_message:d.user_message??void 0,detail_message:d.detail_message??void 0,conflict_type:d.conflict_type??void 0,reason_code:d.reason_code??void 0})}const o={blocker:0,error:1,warning:2,info:3};return m.sort((d,l)=>(o[d.conflict.severity]??4)-(o[l.conflict.severity]??4))},[n,i,s]);return{activeConflicts:c,isLoading:t,error:r,hasConflicts:c.length>0,hasCriticalConflicts:c.some(a=>a.conflict.severity==="blocker"||a.conflict.severity==="error")}}function Za(s){const{data:i}=Ge();return b.useMemo(()=>{if(!i||s.length<2)return{total:0,critical:0,error:0,warning:0,info:0};const n=i.filter(t=>
1Ms(t,s));return{total:n.length,blocker:n.filter(t=>t.severity==="blocker").length,error:n.filter(t=>t.severity==="error").length,warning:n.filter(t=>t.severity==="warning").length,info:n.filter(t=>t.severity==="info").length}},[i,s])}function As(s,i,n,t,r){const{data:c}=Ge();return b.useMemo(()=>{if(n||!c||!r)return{hasConflicts:!1,conflicts:[],highestSeverity:null};const a=new Map(r.map(l=>[l.pack_id,l])),m=t.map(l=>l.pack_id),o=[];for(const l of c){let u=null,g=null,y=null;if(l.pack_a_id===s&&m.includes(l.pack_b_id)?(u=l.pack_b_id,g=l.pack_a_version,y=l.pack_b_version):l.pack_b_id===s&&m.includes(l.pack_a_id)&&(u=l.pack_a_id,g=l.pack_b_version,y=l.pack_a_version),u){const v=t.find(j=>j.pack_id===u),N=!g||Ie(i,g)>=0,p=!y||!v||Ie(v.version,y)>=0;if(N&&p){const j=a.get(u);o.push({conflict:l,otherPackId:u,otherPackName:j?.display_name||u,severity:l.severity})}}}const d={blocker:0,error:1,warning:2,info:3};return o.sort((l,u)=>(d[l.severity]??4)-(d[u.severity]??4)),{hasConflicts:o.length>0,conflicts:o,highestSeverity:o[0]?.severity||null}},[s,i,n,t,c,r])}function ei(s){switch(s){case"blocker":case"error":return fs;case"warning":return de;default:return fe}}function si({conflicts:s,onDismiss:i,onDismissAll:n,onRemovePack:t}){const[r,c]=b.useState(!0);if(s.length===0)return null;const a=s[0]?.conflict.severity||"warning",m=ei(a);return e.jsx("div",{className:x("rounded-lg border p-space-md",Qa(a)),children:e.jsxs(ss,{open:r,onOpenChange:c,children:[e.jsxs("div",{className:"flex items-start justify-between gap-space-md",children:[e.jsxs("div",{className:"flex items-start gap-space-3",children:[e.jsx(m,{className:x("size-icon-md mt-space-2xs shrink-0",Ja(a))}),e.jsx("div",{className:"flex flex-col gap-space-xs",children:e.jsx(as,{asChild:!0,children:e.jsxs("button",{className:"text-left flex items-center gap-space-sm group",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-fluid-sm",children:s.length===1?"Nutrition Conflict Detected":`${s.length} Nutrition Conflicts Detected`}),e.jsx("p",{className:"body-caption",children:r?"Click to collapse":"Click for details"})]}),r?e.jsx(Be,{className:"size-icon-sm text-muted-foreground"}):e.jsx(ye,{className:"size-icon-sm text-muted-foreground"})]})})})]}),n&&e.jsxs(C,{variant:"ghost",size:"icon",className:"size-icon-lg shrink-0",onClick:n,children:[e.jsx(da,{className:"size-icon-sm"}),e.jsx("span",{className:"sr-only",children:"Dismiss all"})]})]}),e.jsx(is,{className:"flex flex-col gap-space-3 mt-space-md",children:s.map(o=>e.jsx(ai,{activeConflict:o,onDismiss:i,onRemovePack:t},o.conflict.id))})]})})}function ai({activeConflict:s,onDismiss:i,onRemovePack:n}){const[t,r]=b.useState(!1),{conflict:c,pack_a_display_name:a,pack_b_display_name:m,suggested_resolution:o,user_message:d,detail_message:l}=s,u=o.prefer_pack,g=c.pack_a_id,y=c.pack_b_id,N=u?u===g?{id:y,name:m}:u===y?{id:g,name:a}:(console.warn(`prefer_pack "${u}" doesn't match conflict packs [${g}, ${y}]`),null):null;return e.jsx("div",{className:"rounded-md bg-background/50 p-space-3 text-fluid-sm",children:e.jsx("div",{className:"flex items-start justify-between gap-space-sm",children:e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-space-sm font-medium",children:[e.jsx("span",{children:a}),e.jsx("span",{className:"text-muted-foreground",children:"+"}),e.jsx("span",{children:m})]}),e.jsx("p",{className:"mt-space-xs text-muted-foreground",children:d||c.conflict_reason}),o.message&&e.jsxs("p",{className:"mt-space-sm text-fluid-xs text-foreground/70 italic",children:["💡 ",o.message]}),(N||i)&&e.jsxs("div",{className:"mt-space-3 flex flex-wrap items-center gap-space-sm",children:[N&&n&&e.jsxs(C,{variant:"outline",size:"sm",className:"h-7 text-fluid-xs",onClick:()=>n(N.id),children:["Remove ",N.name]}),i&&e.jsx(C,{variant:"ghost",size:"sm",className:"h-7 body-caption",onClick:()=>i(c.id),children:"Dismiss"})]}),l&&e.jsxs("div",{className:"mt-space-sm",children:[e.jsxs("button",{onClick:()=>r(!t),className:"text-fluid-xs text-primary hover:underline flex items-center gap-space-xs",children:[t?"Hide details":"Learn more",t?e.jsx(Be,{className:"size-icon-xs"}):e.jsx(ye,{className:"size-icon-xs"})]}),t&&e.jsx("p",{className:"mt-space-sm body-caption bg-surface-muted-medium p-space-sm rounded",children:l})]})]})})})}function ii({pack:s}){const[i,n]=b.useState(!1);return Cs(s.pack_id)?e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"ghost",size:"sm",className:x("h-auto py-space-xs px-space-sm text-fluid-xs font-medium","text-muted-foreground hover:text-foreground","gap-space-xs"),onClick:t=>{t.stopPropagation(),n(!0)},children:[e.jsx(fe,{className:"h-3.5 w-3.5"}),"Learn more"]}),e.jsx(La,{pack:s,open:i,onOpenChange:n})]}):null}function $e({pack:s,isActive:i,isLoading:n,onToggle:t,conflictPreview:r}){const c=ks(s),a=!i&&r?.hasConflicts;return e.jsxs("button",{onClick:t,disabled:n,className:x("list-row list-row--compact text-left transition-colors duration-200",i&&"bg-surface-positive-subtle",a&&"bg-surface-caution-subtle"),children:[e.jsx("div",{className:"size-icon-sm shrink-0 flex items-center justify-center",children:n&&e.jsx(Ve,{className:"size-icon-sm animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"flex flex-col gap-space-xs-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-space-sm gap-y-space-xs",children:[e.jsx("span",{className:x("text-fluid-base font-medium transition-colors",i?"text-foreground":"text-foreground
1/90"),children:s.display_name}),c&&e.jsxs(ze,{children:[e.jsx(Fe,{asChild:!0,children:e.jsxs("span",{className:"apple-chip apple-chip-primary font-mono",children:[e.jsx(hs,{className:"size-icon-xs"}),e.jsxs("span",{children:[c.protein_pct,"/",c.carbs_pct,"/",c.fat_pct]})]})}),e.jsx(Re,{side:"top",className:"max-w-xs",children:e.jsx("p",{className:"font-medium",children:c.description})})]}),a&&e.jsxs("span",{className:"apple-chip apple-chip-caution",children:[e.jsx(de,{className:"size-icon-xs"}),e.jsxs("span",{children:[r.conflictNames[0],r.conflictNames.length>1&&` +${r.conflictNames.length-1}`]})]})]}),s.description&&e.jsx("p",{className:"body-secondary",children:s.description}),Cs(s.pack_id)&&e.jsx("div",{role:"presentation",onClick:m=>m.stopPropagation(),children:e.jsx(ii,{pack:s})})]})]})}class ti extends b.Component{constructor(i){super(i),this.state={hasError:!1,error:null}}static getDerivedStateFromError(i){return{hasError:!0,error:i}}componentDidCatch(i,n){console.error("DietPacksSection error:",i,n)}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?e.jsx("div",{className:"rounded-lg border border-error/20 bg-error/5 p-space-lg",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-space-md",children:[e.jsx("div",{className:"p-space-3 rounded-full bg-error/10",children:e.jsx(de,{className:"size-icon-lg text-error"})}),e.jsxs("div",{className:"flex flex-col gap-space-xs",children:[e.jsx("h3",{className:"font-medium text-foreground",children:"Something went wrong"}),e.jsx("p",{className:"body-secondary max-w-md",children:Vs.NUTRITION_STYLES.LOAD_ERROR}),this.state.error?.message&&e.jsx("p",{className:"text-fluid-xs text-error/80 mt-space-sm font-mono",children:this.state.error.message})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:this.handleRetry,className:"gap-space-sm",children:[e.jsx(te,{className:"size-icon-sm"}),"Try Again"]})]})}):this.props.children}}function ni(s){const i=new Map;for(const n of s){const t=n.family||"other";i.has(t)||i.set(t,[]),i.get(t).push(n)}return i}const ri={A_allergy:{title:"Allergies & Safety",description:"Avoid ingredients that trigger immune responses or intolerances"},B_lifestyle:{title:"Lifestyle & Ethics",description:"Plant-based, ethical, and personal preference patterns"},C_health:{title:"Health & Medical",description:"Clinically-informed approaches for specific health goals"},D_faith:{title:"Faith & Tradition",description:"Dietary practices rooted in religious and cultural traditions"},E_performance:{title:"Performance & Goals",description:"Optimize macros for fitness, weight, or metabolic objectives"}};function ci(){const{data:s,isLoading:i,error:n}=J(),{data:t,isLoading:r}=G(),c=be(),a=b.useMemo(()=>s?s.filter(_=>!K.has(_.pack_id)):[],[s]),m=b.useMemo(()=>a.length?ni(a):new Map,[a]),o=b.useMemo(()=>t?.active_packs||[],[t?.active_packs]),d=b.useMemo(()=>o.map(_=>_.pack_id),[o]),l=b.useMemo(()=>new Set(d),[d]),{activeConflicts:u}=Xa(o,s),g=Za(o),{dismiss:y,isDismissed:v,clearAll:N}=Gs(d),p=b.useMemo(()=>u.filter(_=>!v(_.conflict.id)),[u,v]),j=async _=>{try{await c.mutateAsync({packId:_.pack_id,version:_.version});const S=l.has(_.pack_id);L.success(S?T.DIET.PACK_REMOVED.title:T.DIET.PACK_ADDED.title,{description:_.display_name})}catch(S){L.error(S instanceof Error?S.message:T.DIET.UPDATE_FAILED.title)}},w=async _=>{const S=s?.find(P=>P.pack_id===_);if(S)try{await c.mutateAsync({packId:S.pack_id,version:S.version}),L.success(T.DIET.PACK_REMOVED.title,{description:S.display_name})}catch(P){L.error(P instanceof Error?P.message:T.DIET.UPDATE_FAILED.title)}};return i||r?e.jsx("div",{className:"flex items-center justify-center py-space-2xl",children:e.jsx(Oe,{size:"lg",className:"text-primary"})}
1):n?e.jsx("div",{className:"rounded-lg border border-error/20 bg-error/5 p-space-lg text-center",children:e.jsx("p",{className:"text-fluid-sm text-error",children:"Failed to load diet packs. Please try again."})}):s?.length?e.jsxs(ts,{gap:"relaxed",children:[g.total>0&&e.jsx("div",{className:"flex items-center gap-space-sm",children:e.jsxs(E,{variant:"outline",className:x("gap-space-xs",g.error>0||g.critical>0?"border-destructive/40 text-destructive":"border-warning/40 text-warning"),children:[e.jsx(de,{className:"size-icon-xs"}),g.total," conflict",g.total>1?"s":""]})}),p.length>0&&e.jsx(si,{conflicts:p,onDismiss:y,onDismissAll:N,onRemovePack:w}),Array.from(m.entries()).map(([_,S])=>{const P=ri[_]||{title:_.replace("-"," ").replace(/\b\w/g,A=>A.toUpperCase()),description:""};return e.jsxs("section",{className:"flex flex-col gap-space-3",children:[e.jsxs("div",{className:"px-space-xs",children:[e.jsx("h3",{className:"apple-body font-semibold text-foreground",children:P.title}),P.description&&e.jsx("p",{className:"apple-caption text-muted-foreground",children:P.description})]}),e.jsx("div",{className:"grid gap-space-3 sm:grid-cols-2",children:S.map(A=>e.jsx(oi,{pack:A,isActive:l.has(A.pack_id),isLoading:c.isPending&&c.variables?.packId===A.pack_id,onToggle:()=>j(A),activePackRefs:o,allPacks:s},A.pack_id))})]},_)})]}):e.jsxs("div",{className:"rounded-lg border border-border bg-surface-muted p-space-xl text-center",children:[e.jsx(ma,{className:"mx-auto size-icon-3xl text-muted-foreground/50"}),e.jsx("p",{className:"mt-space-md text-muted-foreground",children:"No nutrition styles available yet."})]})}function oi({pack:s,isActive:i,isLoading:n,onToggle:t,activePackRefs:r,allPacks:c}){const a=As(s.pack_id,s.version,i,r,c);return e.jsx($e,{pack:s,isActive:i,isLoading:n,onToggle:t,conflictPreview:a.hasConflicts?{hasConflicts:!0,conflictNames:a.conflicts.map(m=>m.otherPackName),highestSeverity:a.highestSeverity}:void 0})}const li={"weight-loss":["high-protein","low-carb","keto"],maintenance:["balanced","mediterranean"],"muscle-gain":["high-protein","balanced"]};function di({value:s,onChange:i,goal:n,className:t,showLabel:r=!0}){const c=b.useMemo(()=>ka(),[]),a=js(s),m=b.useMemo(()=>n?li[n]??[]:[],[n]),o=b.useMemo(()=>[...c].sort((d,l)=>{const u=m.includes(d.id),g=m.includes(l.id);return u&&!g?-1:!u&&g?1:d.name.localeCompare(l.name)}),[c,m]);return e.jsxs("div",{className:x("flex flex-col gap-space-sm",t),children:[r&&e.jsx(H,{htmlFor:"diet-profile",children:"Macro Distribution"}),e.jsxs($s,{value:s,onValueChange:i,children:[e.jsx(Us,{id:"diet-profile",className:"w-full",children:e.jsx(Ws,{placeholder:"Select a profile",children:a&&e.jsxs("span",{className:"flex items-center gap-space-sm",children:[e.jsx("span",{children:a.name}),e.jsxs("span",{className:"body-caption font-mono",children:["P:",a.proteinPct,"% C:",a.carbsPct,"% F:",a.fatPct,"%"]})]})})}),e.jsx(Hs,{children:o.map(d=>{const l=m.includes(d.id);return e.jsx(Ys,{value:d.id,children:e.jsxs("div",{className:"flex flex-col gap-space-2xs",children:[e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx("span",{className:"font-medium",children:d.name}),l&&e.jsx(E,{variant:"success",size:"xs",children:"Recommended"})]}),e.jsx("div",{className:"flex items-center gap-space-3 body-caption",children:e.jsxs("span",{className:"font-mono",children:["P:",d.proteinPct,"% C:",d.carbsPct,"% F:",d.fatPct,"%"]})}),d.description&&e.jsx("span",{className:"body-caption line-clamp-1",children:d.description})]})},d.id)})})]}),a&&e.jsxs("div",{className:"flex gap-space-sm text-fluid-xs",children:[e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-[hsl(var(--macro-protein))]"}),e.jsxs("span",{children:["Protein ",a.proteinPct,"%"]})]}),e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-warning"}),e.jsxs("span",{children:["Carbs ",a.carbsPct,"%"]})]}),e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-[hsl(var(--macro-fat))]"}),e.jsxs("span",{children:["Fat ",a.fatPct,"%"]})]})]})]})}const ce="1.0.0",V="1.0.0",mi=le(["ready","skipped_not_needed","skipped_dependency_unavailable","skipped_circuit_open","failed"]);le(["missing_weight","missing_height","missing_age","missing_gender","missing_activity_level","weight_out_of_bounds","height_out_of_bounds","age_out_of_bounds","body_fat_out_of_bounds","schema_validation_failed","policy_integrity_fail","manifest_hash_mismatch","policy_load_failed","user_disabled_goals","up_to_date"]);const pi=le(["doi","isbn","url","internal"]);ns({kind:pi,id:Y(),edition:Y().nullable().optional(),section:Y().optional()});ns({status:mi,reason_codes:Ks(Y()),evaluator_version:Y(),policy_version:Y(),evaluated_at:Y(),input_fingerprint:Y()});le(["draft","reviewed","deprecated"]);le(["uncalibrated","calibrating","calibrated","failed"]);
1le(["insufficient_data","high_variance","incomplete_logging","weight_stable","calibration_complete"]);class _e extends Error{constructor(i){super(`Policy integrity check failed: ${i.join(", ")}`),this.reason_codes=i,this.name="PolicyIntegrityError"}}const R="53bcdfaa6d3963856e795f68af821fa51dd3e34ce9c6b549e22fd0b0aec57a80";function Ds(){return R.includes("__DEV_MANIFEST_HASH__")}const Is=`{
2  "version": "1.0.0",
3  "generated_at": "2026-01-12T19:24:06.592Z",
4  "policies": {
5    "activity_active": {
6      "policy_id": "activity_active",
7      "policy_version": "1.0.0",
8      "review_status": "reviewed",
9      "reviewed_by": "system",
10      "reviewed_at": "2026-01-03",
11      "source_locator": {
12        "kind": "doi",
13        "id": "10.1123/ijsnem.2019-0171",
14        "edition": null,
15        "section": "Activity Factor Validation"
16      },
17      "evidence_hash": "43460b8236618922f922383b63705ffbe8b740cc79c6ff88058d37eef0a33d09",
18      "assumptions": [
19        "Hard exercise 6-7 days/week",
20        "Physically demanding job or intensive training",
21        "Self-reported activity level"
22      ],
23      "variance_pct": 0.12,
24      "multiplier": 1.725
25    },
26    "activity_athlete": {
27      "policy_id": "activity_athlete",
28      "policy_version": "1.0.0",
29      "review_status": "reviewed",
30      "reviewed_by": "system",
31      "reviewed_at": "2026-01-03",
32      "source_locator": {
33        "kind": "doi",
34        "id": "10.1123/ijsnem.2019-0171",
35        "edition": null,
36        "section": "Activity Factor Validation"
37      },
38      "evidence_hash": "a7fecd0fa60585fbdcacbb7903e7c76216d3b89698fc87f4382c6b795eb0f24f",
39      "assumptions": [
40        "Professional or elite athlete",
41        "Multiple training sessions daily",
42        "Self-reported activity level"
43      ],
44      "variance_pct": 0.15,
45      "multiplier": 2
46    },
47    "activity_light": {
48      "policy_id": "activity_light",
49      "policy_version": "1.0.0",
50      "review_status": "reviewed",
51      "reviewed_by": "system",
52      "reviewed_at": "2026-01-03",
53      "source_locator": {
54        "kind": "doi",
55        "id": "10.1123/ijsnem.2019-0171",
56        "edition": null,
57        "section": "Activity Factor Validation"
58      },
59      "evidence_hash": "d832abe36f2728c3981fb79cfd9909b19619fe46816e063ace9baf509c49687c",
60      "assumptions": [
61        "Light exercise 1-3 days/week",
62        "Some walking or light activity",
63        "Self-reported activity level"
64      ],
65      "variance_pct": 0.08,
66      "multiplier": 1.375
67    },
68    "activity_moderate": {
69      "policy_id": "activity_moderate",
70      "policy_version": "1.0.0",
71      "review_status": "reviewed",
72      "reviewed_by": "system",
73      "reviewed_at": "2026-01-03",
74      "source_locator": {
75        "kind": "doi",
76        "id": "10.1123/ijsnem.2019-0171",
77        "edition": null,
78        "section": "Activity Factor Validation"
79      },
80      "evidence_hash": "91a664b2f3d61f9bc4626ce8552a23b3ea400f974e9298ba4c817d5a3d522c4a",
81      "assumptions": [
82        "Moderate exercise 3-5 days/week",
83        "Regular structured exercise",
84        "Self-reported activity level"
85      ],
86      "variance_pct": 0.1,
87      "multiplier": 1.55
88    },
89    "activity_sedentary": {
90      "policy_id": "activity_sedentary",
91      "policy_version": "1.0.0",
92      "review_status": "reviewed",
93      "reviewed_by": "system",
94      "reviewed_at": "2026-01-03",
95      "source_locator": {
96        "kind": "doi",
97        "id": "10.1123/ijsnem.2019-0171",
98        "edition": null,
99        "section": "Activity Factor Validation"
100      },
101      "evidence_hash": "dd7a5ec79985754e7c4248be3209eae95e3ef99211cc915012e73a6ec3873384",
102      "assumptions": [
103        "Little or no exercise",
104        "Desk job or sedentary occupation",
105        "Self-reported activity level"
106      ],
107      "variance_pct": 0.05,
108      "multiplier": 1.2
109    },
110    "activity_very_active": {
111      "policy_id": "activity_very_active",
112      "policy_version": "1.0.0",
113      "review_status": "reviewed",
114      "reviewed_by": "system",
115      "reviewed_at": "2026-01-03",
116      "source_locator": {
117        "kind": "doi",
118        "id": "10.1123/ijsnem.2019-0171",
119        "edition": null,
120        "section": "Activity Factor Validation"
121      },
122      "evidence_hash": "f699593e48b2b3f3c332fa2b2fed9c531cec1ea859def55d67bff293934417c5",
123      "assumptions": [
124        "Very hard exercise or physical job",
125        "Two-a-day training sessions",
126        "Self-reported activity level"
127      ],
128      "variance_pct": 0.15,
129      "multiplier": 1.9
130    },
131    "bmr_formula_variance": {
132      "policy_id": "bmr_formula_variance",
133      "policy_version": "1.0.0",
134      "review_status": "reviewed",
135      "reviewed_by": "system",
136      "reviewed_at": "2026-01-03",
137      "source_locator": {
138        "kind": "doi",
139        "id": "10.1093/ajcn/51.2.241",
140        "edition": null,
141        "section": "Results - Validation against indirect calorimetry"
142      },
143      "evidence_hash": "3b59c9ef1e439627a3523bf08419a227f6141a8006a4eb7b1f53b4e38b8a2e00",
144      "assumptions": [
145        "Applied to Mifflin-St Jeor formula only",
146        "Validation population similar to target users",
147        "Indirect calorimetry as gold standard"
148      ],
149      "variance_pct": 0.1
150    },
151    "body_fat_dexa": {
152      "policy_id": "body_fat_dexa",
153      "policy_version": "1.0.0",
154      "review_status": "reviewed",
155      "reviewed_by": "system",
156      "reviewed_at": "2026-01-03",
157      "source_locator": {
158        "kind": "doi",
159        "id": "10.1007/s00198-014-2755-z",
160        "edition": null,
161        "section": "DXA Precision Studies"
162      },
163      "evidence_hash": "77c57477222e49b664cdd1d33abcb1554fbf5a76550267c3ca076fbecc04794c",
164      "assumptions": [
165        "DEXA scan performed by qualified technician",
166        "Standardized hydration and fasting state",
167        "Recent measurement (within 30 days)"
168      ],
169      "variance_pct": 0.02
170    },
171    "body_fat_not_provided": {
172      "policy_id": "body_fat_not_provided",
173      "policy_version": "1.0.0",
174      "review_status": "reviewed",
175      "reviewed_by": "system",
176      "reviewed_at": "2026-01-03",
177      "source_locator": {
178        "kind": "internal",
179        "id": "governance/body-composition-variance",
180        "section": "Missing Data Policy"
181      },
182      "evidence_hash": "71ad48ecaa5b600803e2cbb2fd912f3ab96d333b29b0ecf321058a966e5947b1",
183      "assumptions": [
184        "Body fat percentage not provided by user",
185        "Using weight-based BMR formula (Mifflin-St Jeor)",
186        "Lean mass estimation not applicable"
187      ],
188      "variance_pct": 0.05
189    },
190    "body_fat_self_reported": {
191      "policy_id": "body_fat_self_reported",
192      "policy_version": "1.0.0",
193      "review_status": "reviewed",
194      "reviewed_by": "system",
195      "reviewed_at": "2026-01-03",
196      "source_locator": {
197        "kind": "internal",
198        "id": "governance/body-composition-variance",
199        "section": "Self-Report Accuracy"
200      },
201      "evidence_hash": "c2792e7e0511e8bfb02284fb5ba189aa7365b80334bbb9eab2387a5174852bd0",
202      "assumptions": [
203        "User estimated body fat percentage",
204        "No objective measurement method used",
205        "May include visual estimation or consumer scale"
206      ],
207      "variance_pct": 0.08
208    },
209    "composition_linear_conservative": {
210      "policy_id": "composition_linear_conservative",
211      "policy_version": "1.0.0",
212      "review_status": "reviewed",
213      "reviewed_by": "system",
214      "reviewed_at": "2026-01-03",
215      "source_locator": {
216        "kind": "internal",
217        "id": "governance/variance-composition-rationale",
218        "section": "Composition Rule Selection"
219      },
220      "evidence_hash": "09f23b00a7e938de8021f445f24697e09993062f12b74c5978b90c348ca4a3bb",
221      "assumptions": [
222        "no_independence_assumed",
223        "conservative_for_weight_loss",
224        "activity_bmr_correlation_possible"
225      ],
226      "rule": "linear_sum_conservative",
227      "capped_at": 0.25
228    },
229    "decision_point_gain": {
230      "policy_id": "decision_point_gain",
231      "policy_version": "1.0.0",
232      "review_status": "reviewed",
233      "reviewed_by": "system",
234      "reviewed_at": "2026-01-03",
235      "source_locator": {
236        "kind": "internal",
237        "id": "governance/decision-point-rationale",
238        "section": "Weight Gain Safety"
239      },
240      "evidence_hash": "1f0d9965cb46e8f3d76789e7f1c5d8f1b70e279c6cdbf8b8ebb0e82969e86feb",
241      "assumptions": [
242        "Conservative against underestimating TDEE",
243        "Prevents excessive caloric surplus",
244        "Minimizes unwanted fat gain"
245      ],
246      "decision_bound": "high"
247    },
248    "decision_point_loss": {
249      "policy_id": "decision_point_loss",
250      "policy_version": "1.0.0",
251      "review_status": "reviewed",
252      "reviewed_by": "system",
253      "reviewed_at": "2026-01-03",
254      "source_locator": {
255        "kind": "internal",
256        "id": "governance/decision-point-rationale",
257        "section": "Weight Loss Safety"
258      },
259      "evidence_hash": "603278b4de768470f72d689baf832e518bfdeb8870b541866ed904ae0aa888c6",
260      "assumptions": [
261        "Conservative against overestimating TDEE",
262        "Prevents excessive caloric restriction",
263        "Prioritizes safety over speed"
264      ],
265      "decision_bound": "low"
266    },
267    "decision_point_maintenance": {
268      "policy_id": "decision_point_maintenance",
269      "policy_version": "1.0.0",
270      "review_status": "reviewed",
271      "reviewed_by": "system",
272      "reviewed_at": "2026-01-03",
273      "source_locator": {
274        "kind": "internal",
275        "id": "governance/decision-point-rationale",
276        "section": "Maintenance Strategy"
277      },
278      "evidence_hash": "22aee26fc5112f0bb05ab3d41f4c64382e88ccf9e52316941eb5f33f0ec8f149",
279      "assumptions": [
280        "No directional bias needed",
281        "Display point represents best estimate",
282        "User can adjust based on weight trends"
283      ],
284      "decision_bound": "display"
285    }
286  }
287}
288`;let ve;try{ve=JSON.parse(Is)}catch{ve={version:"invalid",generated_at:"invalid",policies:{}}}const ui={...ve,manifest_hash:R};async function gi(s){const n=new TextEncoder().encode(s),t=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(t)).map(c=>c.toString(16).padStart(2,"0")).join("")}async function fi(){const s=await gi(Is);return ve.version==="invalid"?{valid:!1,reason_codes:["policy_integrity_fail","schema_validation_failed","manifest_parse_failed"],manifest_hash:s,expected_hash:R}:Ds()?{valid:!1,reason_codes:["policy_integrity_fail","dev_manifest_hash_in_production"],manifest_hash:s,expected_hash:R}:s!==R?(console.error(`[MetabolicBounds] Policy manifest hash mismatch!
289  Expected: ${R}
290  Computed: ${s}
291This may indicate manifest tampering, partial deploy, or stale bundle.`),{valid:!1,reason_codes:["policy_integrity_fail","manifest_hash_mismatch"],manifest_hash:s,expected_hash:R}):{valid:!0,reason_codes:[],manifest_hash:s,expected_hash:R}}let oe=null;function hi(){return Ds()?{valid:!1,reason_codes:["policy_integrity_fail","dev_manifest_hash_in_production"],manifest_hash:"",expected_hash:R}:oe||{valid:!1,reason_codes:["policy_integrity_fail","verification_not_initialized"],manifest_hash:"",expected_hash:R}}async function xi(){return oe=await fi(),oe}function Ne(){return ui}function _i(){return oe?oe.manifest_hash:R}let Je=!1,X=null;function we(){if(Je){if(X&&!X.valid)throw new _e(X.reason_codes)}else if(X=hi(),Je=!0,!X.valid)throw new _e(X.reason_codes)}function Ue(s){return typeof s.source_locator=="object"?s.source_locator:{kind:"internal",id:String(s.source_locator),section:void 0}}function Es(s){we();const n=Ne().policies[s];return n?n.variance_pct===void 0?(console.warn(`[PolicyLoader] Policy ${s} missing variance_pct`),null):{policy_id:n.policy_id,policy_version:n.policy_version,source_locator:Ue(n),evidence_hash:n.evidence_hash,variance_pct:n.variance_pct,review_status:n.review_status,reviewed_by:n.reviewed_by,reviewed_at:n.reviewed_at,assumptions:n.assumptions||[]}:null}function vi(s){we();const i=`activity_${s.toLowerCase().replace("-","_")}`,t=Ne().policies[i];return t?t.variance_pct===void 0||t.multiplier===void 0?(console.warn(`[PolicyLoader] Activity policy ${i} missing required fields`),null):{policy_id:t.policy_id,policy_version:t.policy_version,source_locator:Ue(t),evidence_hash:t.evidence_hash,variance_pct:t.variance_pct,multiplier:t.multiplier,review_status:t.review_status,reviewed_by:t.reviewed_by,reviewed_at:t.reviewed_at,assumptions:t.assumptions||[]}:null}function bi(s){we();const i=`decision_point_${s}`,t=Ne().policies[i];return t?t.decision_bound===void 0?(console.warn(`[PolicyLoader] Decision policy ${i} missing decision_bound`),null):{policy_id:t.policy_id,policy_version:t.policy_version,source_locator:Ue(t),evidence_hash:t.evidence_hash,decision_bound:t.decision_bound,assumptions:t.assumptions||[]}:null}function Ts(){we();const s="composition_linear_conservative",n=Ne().policies[s];if(!n)throw new _e(["policy_load_failed",`missing_policy:${s}`]);if(n.rule===void 0||n.capped_at===void 0)throw new _e(["policy_load_failed",`invalid_policy:${s}`,"missing_required_fields"]);return{policy_id:n.policy_id,policy_version:n.policy_version,rule:n.rule,justification:"Activity-level and BMR errors may correlate via self-report bias",assumptions:n.assumptions||[],capped_at:n.capped_at}}function yi(){return Es("bmr_formula_variance")}function ji(s){const i=`body_fat_${s}`;return Es(i)}function Ls(){return Ts()}function Ni(s,i){const n=i??Ls(),t=s.map(a=>a.applied_variance);let r;n.rule==="rss"?r=Math.sqrt(t.reduce((a,m)=>a+m*m,0)):r=t.reduce((a,m)=>a+m,0);const c=r>n.capped_at;
291return{total_variance_pct:Math.min(r,n.capped_at),uncapped_total_variance_pct:r,capped:c}}function wi(s){return{lo_multiplier:1-s,hi_multiplier:1+s}}function ki(s,i,n=.05){return s<=0?!1:(i-s)/s>=n}const W={weight:{min:20,max:500},height:{min:50,max:300},age:{min:1,max:120},bodyFat:{min:3,max:70}};function Ci(){return{evaluator_version:ce,policy_version:V,evaluated_at:new Date().toISOString()}}async function Si(s,i,n={}){const t=Ci(),{goalsEnabled:r=!0,checkIdempotence:c=!1,existingFingerprint:a}=n;if(!i.valid)return{...t,status:"failed",reason_codes:i.reason_codes,input_fingerprint:""};if(!r)return{...t,status:"skipped_not_needed",reason_codes:["user_disabled_goals"],input_fingerprint:""};const m=[];if((s.weightKg===void 0||s.weightKg<=0)&&m.push("missing_weight"),(s.heightCm===void 0||s.heightCm<=0)&&m.push("missing_height"),(s.age===void 0||s.age<=0)&&m.push("missing_age"),s.gender||m.push("missing_gender"),s.activityLevel||m.push("missing_activity_level"),m.length>0)return{...t,status:"skipped_dependency_unavailable",reason_codes:m,input_fingerprint:""};const o=[];if((s.weightKg<W.weight.min||s.weightKg>W.weight.max)&&o.push("weight_out_of_bounds"),(s.heightCm<W.height.min||s.heightCm>W.height.max)&&o.push("height_out_of_bounds"),(s.age<W.age.min||s.age>W.age.max)&&o.push("age_out_of_bounds"),s.bodyFatPct!==void 0&&(s.bodyFatPct<W.bodyFat.min||s.bodyFatPct>W.bodyFat.max)&&o.push("body_fat_out_of_bounds"),o.length>0)return{...t,status:"failed",reason_codes:o,input_fingerprint:""};const d=Ls(),l=await za(s,V,d.rule,d.policy_version);return c&&a&&l===a?{...t,status:"skipped_not_needed",reason_codes:["up_to_date"],input_fingerprint:l}:{...t,status:"ready",reason_codes:[],input_fingerprint:l}}function Me(s,i,n=""){const t=new Date().toISOString();return{envelope:{status:"failed",reason_codes:s,evaluator_version:ce,policy_version:V,evaluated_at:t,input_fingerprint:n},bmr:{display_point:0,decision_point:0,low:0,high:0},tdee:{display_point:0,decision_point:0,low:0,high:0},target_calories:{display_point:0,decision_point:0,low:0,high:0},show_range:!1,trace:zs(),calibration:We(),versions:{bounds_engine:ce,policy_version:V,manifest_hash:i},refinement_suggestions:[]}}function Pi(s,i,n,t=""){const r=new Date().toISOString();return{envelope:{status:s,reason_codes:i,evaluator_version:ce,policy_version:V,evaluated_at:r,input_fingerprint:t},bmr:{display_point:0,decision_point:0,low:0,high:0},tdee:{display_point:0,decision_point:0,low:0,high:0},target_calories:{display_point:0,decision_point:0,low:0,high:0},show_range:!1,trace:zs(),calibration:We(),versions:{bounds_engine:ce,policy_version:V,manifest_hash:n},refinement_suggestions:[]}}function zs(){return{bmr_formula:"",bmr_point:0,activity_level:"",activity_multiplier:0,goal_deficit:0,goal_direction:"maintenance",sources:[],composition:{policy_id:"unavailable",policy_version:"0.0.0",rule:"linear_sum_conservative",justification:"unavailable (bounds not computed)",assumptions:[],capped_at:0},composition_result:{total_variance_pct:0,uncapped_total_variance_pct:0,capped:!1},interval:{lo_multiplier:1,hi_multiplier:1},decision_point_policy:{policy_id:"unavailable",policy_version:"0.0.0",evidence_hash:""}}}function We(){return{status:"uncalibrated",reason_codes:["insufficient_data"],evaluated_at:new Date().toISOString(),window_days:14,data_points_available:0,data_points_required:14}}function Mi(s,i,n){switch(n){case"loss":return i.low;case"gain":return i.high;default:return s}}function Ai(s,i){const n=[],t=yi();t&&n.push({source_type:"bmr_formula",policy_id:t.policy_id,policy_version:t.policy_version,evidence_hash:t.evidence_hash,base_variance:t.variance_pct,applied_variance:t.variance_pct,reason:"Formula validation against indirect calorimetry"});const r=vi(s);r&&n.push({source_type:"activity_level",policy_id:r.policy_id,policy_version:r.policy_version,evidence_hash:r.evidence_hash,base_variance:r.variance_pct,applied_variance:r.variance_pct,reason:`Self-reported ${s} activity level`});const c=ji(i);return c&&n.push({source_type:"body_composition",policy_id:c.policy_id,policy_version:c.policy_version,evidence_hash:c.evidence_hash,base_variance:c.variance_pct,applied_variance:c.variance_pct,reason:i==="not_provided"?"Body fat not provided, using weight-based formula":`Body fat from ${i.replace("_"," ")}`}),n}function Di(s,i){const n=[];return s==="not_provided"&&n.push({id:"provide_body_fat",title:"Add body composition",description:"Providing body fat percentage enables more accurate calculations using lean mass.",impact:"medium",action_type:"provide_data"}),s==="self_reported"&&n.push({id:"measure_body_fat",title:"Get precise body composition",description:"A DEXA scan or professional measurement would reduce uncertainty significantly.",impact:"medium",action_type:"provide_data"}),i==="uncalibrated"&&n.push({id:"track_intake",title:"Track intake for 2 weeks",description:"Logging food intake and weight changes allows calibration of your personal TDEE.",impact:"high",action_type:"track_intake"}),n}async function Ii(s,i={}){const{bodyFatSource:n=s.bodyFatPct!==void 0?"self_reported":"not_provided",goalDeficit:t=0,goalDirection:r="maintenance",goalsEnabled:c=!0,checkIdempotence:a=!1,existingFingerprint:m}
291=i,o=await xi(),d=_i(),l=await Si(s,o,{goalsEnabled:c,checkIdempotence:a,existingFingerprint:m});if(l.status!=="ready")return l.status==="failed"?Me(l.reason_codes,d,l.input_fingerprint):Pi(l.status,l.reason_codes,d,l.input_fingerprint);let u;try{u=Ts()}catch{return Me(["policy_load_failed","missing_policy:composition_linear_conservative"],d,l.input_fingerprint)}const g=bi(r);if(!g)return Me(["policy_load_failed",`missing_policy:decision_point_${r}`],d,l.input_fingerprint);const y=Ca({weight:s.weightKg,height:s.heightCm,age:s.age,gender:s.gender,bodyFatPct:s.bodyFatPct,units:"metric"}),v=y.bmr,N=Sa[s.activityLevel],p=v*N,j=Ai(s.activityLevel,n),w=Ni(j,u),_=wi(w.total_variance_pct),S={display_point:Math.round(v),decision_point:Math.round(v),low:Math.round(v*_.lo_multiplier),high:Math.round(v*_.hi_multiplier)},P={display_point:Math.round(p),decision_point:Math.round(Mi(p,{low:p*_.lo_multiplier,high:p*_.hi_multiplier},r)),low:Math.round(p*_.lo_multiplier),high:Math.round(p*_.hi_multiplier)},A=P.decision_point-Math.abs(t),$={display_point:Math.round(A),decision_point:Math.round(A),low:Math.round(P.low-Math.abs(t)),high:Math.round(P.high-Math.abs(t))},me={bmr_formula:y.formula,bmr_point:v,activity_level:s.activityLevel,activity_multiplier:N,goal_deficit:t,goal_direction:r,sources:j,composition:u,composition_result:w,interval:_,decision_point_policy:{policy_id:g.policy_id,policy_version:g.policy_version,evidence_hash:g.evidence_hash}}
291,O=We(),pe=Di(n,O.status);return{envelope:l,bmr:S,tdee:P,target_calories:$,show_range:ki(P.low,P.high),trace:me,calibration:O,versions:{bounds_engine:ce,policy_version:V,manifest_hash:d},refinement_suggestions:pe}}const Ei="1.0.0",Ti={policy_id:"macro_kcal_per_gram_4_4_9",policy_version:"0.0.0-internal"},Li={protein:4,carbs:4,fat:9},zi=2;function Ae(s){return typeof s=="number"&&Number.isFinite(s)&&s>=0&&s<=100}function Fi(s){const i=[];if((!Ae(s.protein)||!Ae(s.carbs)||!Ae(s.fat))&&i.push("invalid_percent_value"),i.length===0){const n=s.protein+s.carbs+s.fat;Math.abs(n-100)>zi&&i.push("invalid_percent_sum")}return{valid:i.length===0,reason_codes:i}}async function Ri(s,i={}){const{checkIdempotence:n=!1,existingFingerprint:t}=i,r=new Date().toISOString(),c={evaluator_version:Ei,policy_version:V,evaluated_at:r},a={low:0,high:0,display_point:0,decision_point:0};if(!s)return{envelope:{...c,status:"skipped_dependency_unavailable",reason_codes:["missing_metabolic_bounds"],input_fingerprint:""},input_references:{metabolic_bounds_fingerprint:"",calorie_bounds_snapshot:a,macro_percentages:{protein:0,carbs:0,fat:0}}};const{caloriesBounds:m,metabolicBoundsFingerprint:o,macroPercentages:d}=s;if(m.low<=0||m.high<=0)return{envelope:{...c,status:"skipped_dependency_unavailable",reason_codes:["metabolic_bounds_not_ready"],input_fingerprint:""},input_references:{metabolic_bounds_fingerprint:o,calorie_bounds_snapshot:m,macro_percentages:d}};const{protein:l,carbs:u,fat:g}=d;if(l===void 0||u===void 0||g===void 0||l===null||u===null||g===null)return{envelope:{...c,status:"skipped_dependency_unavailable",reason_codes:["missing_macro_percentages"],input_fingerprint:""},input_references:{metabolic_bounds_fingerprint:o,calorie_bounds_snapshot:m,macro_percentages:{protein:0,carbs:0,fat:0}}};const y=Fi(d);if(!y.valid)return{envelope:{...c,status:"failed",reason_codes:y.reason_codes,input_fingerprint:""},input_references:{metabolic_bounds_fingerprint:o,calorie_bounds_snapshot:m,macro_percentages:d}};const v=JSON.stringify({metabolic_bounds_fp:o,calorie_bounds:{low:m.low,high:m.high,display_point:m.display_point,decision_point:m.decision_point},macro_pcts:{protein:l,carbs:u,fat:g},macro_policy:Ti,policy_version:V}),N=await Fa(v);if(n&&t&&N===t)return{envelope:{...c,status:"skipped_not_needed",reason_codes:["up_to_date"],input_fingerprint:N},input_references:{metabolic_bounds_fingerprint:o,calorie_bounds_snapshot:{low:m.low,high:m.high,display_point:m.display_point,decision_point:m.decision_point},macro_percentages:{protein:l,carbs:u,fat:g}}};const p=De(m,l,"protein"),j=De(m,u,"carbs"),w=De(m,g,"fat");return{envelope:{...c,status:"ready",reason_codes:[],input_fingerprint:N},result:{protein:p,carbs:j,fat:w},input_references:{metabolic_bounds_fingerprint:o,calorie_bounds_snapshot:{low:m.low,high:m.high,display_point:m.display_point,decision_point:m.decision_point},macro_percentages:{protein:l,carbs:u,fat:g}}}}function De(s,i,n){const t=Li[n],r=c=>Math.round(i/100*c/t);return{low:r(s.low),high:r(s.high),display_point:r(s.display_point),decision_point:r(s.decision_point)}}const Oi={1:"Basic Information",2:"Body Measurements",3:"Activity & Goals",4:"Review & Apply"},Bi={"weight-loss":{label:"Lose Weight",icon:bs,description:"Create a caloric deficit"},maintenance:{label:"Maintain",icon:ua,description:"Keep weight stable"},"muscle-gain":{label:"Build Muscle",icon:pa,description:"Slight surplus for growth"}},Vi={units:"metric",age:30,gender:"male",height:175,weight:75,bodyFatPct:void 0,activityLevel:"moderate",goal:"maintenance",targetDeficit:500,profileId:"balanced"};function He({open:s,onOpenChange:i}){const{data:n}=G(),t=rs(),[r,c]=b.useState(1),[a,m]=b.useState(()=>{const p=n?.metabolicProfile;return p?{units:p.units,age:p.age,gender:p.gender,height:p.height,weight:p.weight,bodyFatPct:p.bodyFatPct,activityLevel:p.activityLevel,goal:p.goal,targetDeficit:p.targetDeficit??500,profileId:p.profileId}:Vi}),o=b.useMemo(()=>{try{const{weightKg:p,heightCm:j}=qe(a.weight,a.height,a.units);let w=0;return a.goal==="weight-loss"?w=a.targetDeficit:a.goal==="muscle-gain"&&(w=-250),Pa({weight:p,height:j,age:a.age,gender:a.gender,bodyFatPct:a.bodyFatPct,units:"metric"},a.activityLevel,{targetDeficit:w,profileId:a.profileId})}
291catch(p){return console.error("[MetabolicGoalsWizard] Calculation error:",p),null}},[a]),d=b.useCallback(p=>{m(j=>({...j,...p}))},[]),l=b.useCallback(p=>{if(p===a.units)return;const j=Ma(a.height,a.units,p),w=Aa(a.weight,a.units,p,p==="metric"?1:0);d({units:p,height:j,weight:p==="metric"?w:Math.round(w)})},[a.units,a.height,a.weight,d]),u=b.useMemo(()=>{switch(r){case 1:return a.age>=18&&a.age<=100;case 2:return a.height>0&&a.weight>0;case 3:return!0;case 4:return o!==null;default:return!1}},[r,a,o]),g=()=>{r<4&&c(p=>p+1)},y=()=>{r>1&&c(p=>p-1)},v=async()=>{if(!o)return;const{weightKg:p,heightCm:j}=qe(a.weight,a.height,a.units),w=new Date().toISOString(),_={version:Js,updated_at:w,units:a.units,age:a.age,gender:a.gender,height:a.height,weight:a.weight,bodyFatPct:a.bodyFatPct,activityLevel:a.activityLevel,goal:a.goal,targetDeficit:a.goal==="weight-loss"?a.targetDeficit:void 0,profileId:a.profileId},S=Math.round(o.tdee.tdee);let P,A;a.goal==="weight-loss"?(A=a.targetDeficit,P=S-A):a.goal==="muscle-gain"?(A=250,P=S+A):(A=0,P=S);const $={version:qs,calculated_at:w,bmr_kcal:Math.round(o.bmr.bmr),tdee_kcal:S,target_calories_kcal:P,protein_g_recommended:Math.round(o.recommendations.proteinGrams),estimated_weekly_change_kg:o.recommendations.estimatedWeeklyLoss,macros:{protein_g:o.macros.protein,carbs_g:o.macros.
291carbs,fat_g:o.macros.fat,protein_pct:o.macros.proteinPct,carbs_pct:o.macros.carbsPct,fat_pct:o.macros.fatPct},body_composition:o.bodyComposition?{bmi:o.bodyComposition.bmi,bmiCategory:o.bodyComposition.bmiCategory,leanMassKg:o.bodyComposition.leanMass,fatMassKg:o.bodyComposition.fatMass,bodyFatPct:o.bodyComposition.bodyFatPct}:void 0},me=Te(a.age,a.gender,$.target_calories_kcal),O={calories:$.target_calories_kcal,protein:{percentage:o.macros.proteinPct,grams:o.macros.protein},carbs:{percentage:o.macros.carbsPct,grams:o.macros.carbs},fat:{percentage:o.macros.fatPct,grams:o.macros.fat},inputMode:"grams",enabled:!0,micronutrients:me},pe=a.goal==="weight-loss"?"loss":a.goal==="muscle-gain"?"gain":"maintenance",U=n?.targets||{},Ce=U.metabolic_bounds?.envelope?.input_fingerprint,f=await Ii({weightKg:p,heightCm:j,age:a.age,gender:a.gender,bodyFatPct:a.bodyFatPct,activityLevel:a.activityLevel},{bodyFatSource:a.bodyFatPct!==void 0?"self_reported":"not_provided",goalDeficit:A,goalDirection:pe,goalsEnabled:!0,checkIdempotence:!0,existingFingerprint:Ce}),h=f.envelope.status==="skipped_not_needed"&&f.envelope.reason_codes.includes("up_to_date"),k=await Ri(f.envelope.status==="ready"?{caloriesBounds:f.target_calories,metabolicBoundsFingerprint:f.envelope.input_fingerprint,macroPercentages:{protein:O.protein.percentage,carbs:O.carbs.percentage,fat:O.fat.percentage}}:null);try{const M=U.nutrition_goals,I={...U,metabolic_profile:_,metabolic_snapshot:$,nutrition_goals:{...M,...O},metabolic_macro_bounds:k};h||(I.metabolic_bounds=f),await t.mutateAsync({targets:I}),L.success(T.METABOLIC.GOALS_CALCULATED.title),i(!1)}catch(M){L.error(M instanceof Error?M.message:T.METABOLIC.SAVE_FAILED.title)}},N=js(a.profileId);return e.jsx(cs,{open:s,onOpenChange:i,children:e.jsxs(os,{size:"default",className:"max-h-[90vh] flex flex-col p-0",children:[e.jsxs(ls,{className:"p-space-lg pb-0",children:[e.jsxs(ds,{className:"flex items-center gap-space-sm",children:[e.jsx(xs,{className:"size-icon-md text-primary"}),e.jsx("span",{children:Oi[r]})]}),e.jsxs(ms,{children:["Step ",r," of 4 — Calculate personalized nutrition goals"]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-space-lg",children:[e.jsx("div",{className:"flex gap-space-xs py-space-3",children:[1,2,3,4].map(p=>e.jsx("div",{className:x("h-2 flex-1 rounded-full transition-colors duration-fast",p<=r?"bg-primary":"bg-muted")},p))}),e.jsx("div",{className:"min-h-80",children:e.jsxs("div",{className:"flex flex-col gap-space-lg py-space-md",children:[r===1&&e.jsxs("div",{className:"flex flex-col gap-space-lg",children:[e.jsxs("fieldset",{className:"flex flex-col gap-space-3",children:[e.jsx(H,{asChild:!0,children:e.jsx("legend",{children:"Measurement System"})}),e.jsxs("div",{className:"flex gap-space-3",children:[e.jsxs("label",{className:x("flex items-center gap-space-3 p-space-md rounded-xl border-2 cursor-pointer flex-1","min-h-14 touch-manipulation transition-colors duration-fast","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",a.units==="metric"?"border-primary bg-surface-positive-subtle":"border-border hover:border-primary/30 hover:bg-surface-muted"),children:[e.jsx("input",{type:"radio",name:"units",value:"metric",checked:a.units==="metric",onChange:()=>l("metric"),className:"size-icon-md accent-primary"}),e.jsx(_s,{className:x("size-icon-sm",a.units==="metric"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:x("font-medium",a.units==="metric"?"text-primary":"text-foreground"),children:"Metric"})]}),e.jsxs("label",{className:x("flex items-center gap-space-3 p-space-md rounded-xl border-2 cursor-pointer flex-1","min-h-14 touch-manipulation transition-colors duration-fast","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",a.units==="imperial"?"border-primary bg-surface-positive-subtle":"border-border hover:border-primary/30 hover:bg-surface-muted"),children:[e.jsx("input",{type:"radio",name:"units",value:"imperial",checked:a.units==="imperial",onChange:()=>l("imperial"),className:"size-icon-md accent-primary"}),e.jsx(vs,{className:x("size-icon-sm",a.units==="imperial"?"text-primary":"text-muted-foreground")}),e.jsx("span",{className:x("font-medium",a.units==="imperial"?"text-primary":"text-foreground"),children:"Imperial"})]})]}),e.jsx("p",{className:"body-caption",children:a.units==="metric"?"kg, cm":"lbs, ft/in"})]}),e.jsx(Da,{value:a.age,onChange:p=>d({age:p})}),e.jsxs("fieldset",{className:"flex flex-col gap-space-3",children:[e.jsx(H,{asChild:!0,children:e.jsx("legend",{children:"Biological Sex"})}),e.jsxs("div",{className:"flex gap-space-3",children:[e.jsxs("label",{className:x("flex items-center gap-space-3 p-space-md rounded-xl border-2 cursor-pointer flex-1","min-h-14 touch-manipulation transition-colors duration-fast","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",a.gender==="male"?"border-primary bg-surface-positive-subtle":"border-border hover:border-primary/30 hover:bg-surface-muted"),children:[e.jsx("input",{type:"radio",name:"gender",value:"male",checked:a.gender==="male",onChange:()=>d({gender:"male"}),className:"size-icon-md accent-primary"}),e.jsx("span",{className:x("font-medium",a.gender==="male"?"text-primary":"text-foreground"),children:"Male"})]}),e.jsxs("label",{className:x("flex items-center gap-space-3 p-space-md rounded-xl border-2 cursor-pointer flex-1","min-h-14 touch-manipulation transition-colors duration-fast","focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",a.gender==="female"?"border-primary bg-surface-positive-subtle":"border-border hover:border-primary/30 hover:bg-surface-muted"),children:[e.jsx("input",{type:"radio",name:"gender",value:"female",checked:a.gender==="female",onChange:()=>d({gender:"female"}),className:"size-icon-md accent-primary"}),e.jsx("span",{className:x("font-medium",a.gender==="female"?"text-primary":"text-foreground"),children:"Female"})]})]}),e.jsx("p",{className:"body-caption",children:"Used for metabolic rate calculations"})]})]}),r===2&&e.jsxs("div",{className:"flex flex-col gap-space-lg",children:[e.jsx(Ia,{value:a.height,units:a.units,onChange:p=>d({height:p}),showConversion:!0}),e.jsx(Ea,{value:a.weight,units:a.units,onChange:p=>d({weight:p}),showConversion:!0}),e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(H,{children:"Body Fat % (optional)"}),a.bodyFatPct!==void 0&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>d({bodyFatPct:void 0}),children:"Clear"})]}
291),e.jsx(Ee,{value:[a.bodyFatPct??(a.gender==="male"?20:28)],onValueChange:([p])=>d({bodyFatPct:p}),min:5,max:50,step:1,className:"w-full"}),e.jsxs("div",{className:"flex justify-between body-caption",children:[e.jsx("span",{children:"5%"}),e.jsx("span",{className:"font-medium text-foreground",children:a.bodyFatPct!==void 0?`${a.bodyFatPct}%`:"Not set (will estimate)"}),e.jsx("span",{children:"50%"})]}),e.jsx("p",{className:"body-caption",children:"Providing body fat % enables more accurate lean mass calculations"})]})]}),r===3&&e.jsxs("div",{className:"flex flex-col gap-space-lg",children:[e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsx(H,{children:"Activity Level"}),e.jsx(Ta,{value:a.activityLevel,onChange:p=>d({activityLevel:p})})]}),e.jsx(Ye,{}),e.jsxs("fieldset",{className:"flex flex-col gap-space-3",children:[e.jsx("legend",{className:"text-fluid-sm font-medium leading-none",children:"Your Goal"}),e.jsx("div",{className:"flex flex-col gap-space-sm",children:Object.entries(Bi).map(([p,j])=>{const w=j.icon,_=a.goal===p;return e.jsxs("label",{className:x("flex items-center gap-space-md p-space-md rounded-xl border-2 cursor-pointer","min-h-14 touch-manipulation","transition-colors duration-fast","focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",_?"border-primary bg-surface-positive-subtle":"border-border hover:border-primary/30 hover:bg-surface-muted"),children:[e.jsx("input",{type:"radio",name:"metabolic-goal",value:p,checked:_,onChange:()=>d({goal:p}),className:"size-icon-md accent-primary shrink-0"}),e.jsx(w,{className:x("size-icon-md shrink-0",_?"text-primary":"text-muted-foreground")}),e.jsxs("div",{className:"flex flex-col gap-space-2xs",children:[e.jsx("span",{className:x("text-fluid-sm font-medium",_?"text-primary":"text-foreground"),children:j.label}),e.jsx("span",{className:"body-caption",children:j.description})]})]},p)})})]}),a.goal==="weight-loss"&&e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsx(H,{children:"Daily Calorie Deficit"}),e.jsx(Ee,{value:[a.targetDeficit],onValueChange:([p])=>d({targetDeficit:p}),min:250,max:1e3,step:50}),e.jsxs("div",{className:"flex justify-between body-caption",children:[e.jsx("span",{children:"250 kcal (slow)"}),e.jsxs("span",{className:"font-medium text-foreground",children:[a.targetDeficit," kcal/day"]}),e.jsx("span",{children:"1000 kcal (aggressive)"})]}),e.jsxs("p",{className:"body-caption",children:["~",(a.targetDeficit*7/7716).toFixed(2)," kg/week estimated loss"]})]}),e.jsx(Ye,{}),e.jsx(di,{value:a.profileId,onChange:p=>d({profileId:p}),goal:a.goal})]}),r===4&&o&&e.jsxs("div",{className:"flex flex-col gap-space-lg",children:[e.jsxs("div",{className:"flex flex-col gap-space-sm p-space-md rounded-xl bg-surface-muted-medium text-fluid-sm border border-border/50",children:[e.jsx("div",{className:"font-medium",children:"Based on your inputs:"}),e.jsxs("div",{className:"grid grid-cols-2 gap-space-sm text-muted-foreground",children:[e.jsxs("span",{children:[a.age," years old, ",a.gender]}),e.jsxs("span",{children:[Ns(a.height,a.units)," /"," ",ws(a.weight,a.units)]}),e.jsxs("span",{className:"capitalize",children:[a.activityLevel.replace("-"," ")," activity"]}),e.jsx("span",{className:"capitalize",children:a.goal.replace("-"," ")})]})]}),e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-space-md",children:[e.jsxs("div",{className:"p-space-md rounded-xl border bg-background shadow-sm",children:[e.jsx("div",{className:"body-caption",children:"Basal Metabolic Rate"}),e.jsx("div",{className:"text-fluid-2xl font-bold text-primary",children:Math.round(o.bmr.bmr).toLocaleString()}),e.jsx("div",{className:"body-caption",children:"kcal/day"})]}),e.jsxs("div",{className:"p-space-md rounded-xl border bg-background shadow-sm",children:[e.jsx("div",{className:"body-caption",children:"Total Daily Energy"}),e.jsx("div",{className:"text-fluid-2xl font-bold text-primary",children:Math.round(o.tdee.tdee).toLocaleString()}),e.jsx("div",{className:"body-caption",children:"kcal/day"})]})]}),e.jsxs("div",{className:"p-space-md rounded-xl border-2 border-primary bg-surface-positive-subtle shadow-lg shadow-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-space-sm mb-space-sm",children:[e.jsx(B,{className:"size-icon-md text-primary"}),e.jsx("span",{className:"font-medium",children:"Your Daily Target"})]}),e.jsxs("div",{className:"text-fluid-3xl font-bold text-primary",children:[Math.round(o.tdee.tdee-(a.goal==="weight-loss"?a.targetDeficit:a.goal==="muscle-gain"?-250:0)).toLocaleStr
291ing()," ",e.jsx("span",{className:"text-fluid-base font-normal",children:"kcal"})]}),a.goal==="weight-loss"&&o.recommendations.estimatedWeeklyLoss&&e.jsxs("div",{className:"mt-space-sm body-secondary",children:["Estimated loss: ~",o.recommendations.estimatedWeeklyLoss.toFixed(2)," ","kg/week"]})]}),e.jsxs("div",{className:"flex flex-col gap-space-sm",children:[e.jsxs("div",{className:"text-fluid-sm font-medium",children:["Recommended Macros (",N.name,")"]}),e.jsx("div",{className:"grid grid-cols-1 xs:grid-cols-3 gap-space-3",children:[{name:"Protein",value:o.macros.protein,pct:o.macros.proteinPct,color:"blue"},{name:"Carbs",value:o.macros.carbs,pct:o.macros.carbsPct,color:"amber"},{name:"Fat",value:o.macros.fat,pct:o.macros.fatPct,color:"rose"}].map(p=>e.jsxs("div",{className:x("p-space-3 rounded-xl border",p.color==="blue"&&"bg-[hsl(var(--macro-protein))]/10 border-info/20",p.color==="amber"&&"bg-surface-caution-subtle border-warning/20",p.color==="rose"&&"bg-[hsl(var(--macro-fat))]/10 border-[hsl(var(--macro-fat)/0.2)]"),children:[e.jsx("div",{className:x("text-fluid-xs",p.color==="blue"&&"text-[hsl(var(--macro-protein))] dark:text-[hsl(var(--macro-protein))]",p.color==="amber"&&"text-warning dark:text-warning",p.color==="rose"&&"text-[hsl(var(--macro-fat))] dark:text-[hsl(var(--macro-fat))]"),children:p.name}),e.jsxs("div",{className:"font-bold",children:[p.value,"g"]}),e.jsxs("div",{className:"body-caption",children:[p.pct,"%"]})]},p.name))})]}),o.bodyComposition&&e.jsxs("div",{className:"p-space-3 rounded-xl bg-surface-muted-medium text-fluid-sm border border-border/50",children:[e.jsx("div",{className:"font-medium mb-space-xs",children:"Body Composition"}),e.jsxs("div",{className:"grid grid-cols-2 gap-space-sm text-muted-foreground",children:[e.jsxs("span",{children:["BMI:"," ",o.bodyComposition.bmi?.toFixed(1)??"N/A"," ","(",o.bodyComposition.bmiCategory??"N/A",")"]}),e.jsxs("span",{children:["Lean Mass:"," ",o.bodyComposition.leanMass.toFixed(1)," ","kg"]})]})]}),(()=>{const p=Math.round(o.tdee.tdee-(a.goal==="weight-loss"?a.targetDeficit:a.goal==="muscle-gain"?-250:0)),j=Te(a.age,a.gender,p);return e.jsxs("div",{className:"p-space-3 rounded-xl bg-surface-muted-medium text-fluid-sm border border-border/50",children:[e.jsx("div",{className:"font-medium mb-space-sm",children:"Micronutrient Targets (NASEM DRI)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-space-md gap-y-space-xs text-muted-foreground",children:[e.jsxs("span",{children:["Fiber: ",j.fiber_g.value,"g"]}),e.jsxs("span",{children:["Vitamin C: ",j.vitamin_c_mg?.value,"mg"]}),e.jsxs("span",{children:["Calcium: ",j.calcium_mg?.value,"mg"]}),e.jsxs("span",{children:["Iron: ",j.iron_mg?.value,"mg"]}),e.jsxs("span",{children:["Potassium: ",j.potassium_mg?.value,"mg"]}),e.jsxs("span",{children:["Sodium limit: ",j.sodium_mg?.value,"mg"]})]}),e.jsxs("p",{className:"body-caption mt-space-sm",children:["Based on NASEM DRI for ",a.age,"yo ",a.gender,", fiber scaled to ",p.toLocaleString()," ","kcal"]})]})})()]})]})]})})]}),e.jsx("div",{className:"flex-shrink-0 border-t p-space-md bg-background",children:e.jsxs("div",{className:"flex justify-between",children:[e.jsxs(C,{variant:"outline",onClick:y,disabled:r===1,className:"gap-space-sm",children:[e.jsx(ys,{className:"size-icon-sm"}),"Back"]}),r<4?e.jsxs(C,{onClick:g,disabled:!u,className:"gap-space-sm",children:["Next",e.jsx(ye,{className:"size-icon-sm"})]}):e.jsxs(C,{onClick:v,disabled:!o||t.isPending,className:"gap-space-sm shadow-lg shadow-primary/20",children:[t.isPending?e.jsx(Ve,{className:"size-icon-sm animate-spin"}):e.jsx(B,{className:"size-icon-sm"}),"Apply to My Goals"]})]})})]})})}function Gi(s){const i=[];return s.age&&i.push(`${s.age} years`),s.height&&i.push(Ns(s.height,s.units)),s.weight&&i.push(ws(s.weight,s.units)),i.join(" • ")}function $i(s){const i={sedentary:"Sedentary",light:"Light activity",moderate:"Moderate activity",active:"Active",very_active:"Very active"},n={lose:"Lose weight",maintain:"Maintain weight",gain:"Gain weight"},t=[];return s.activityLevel&&t.push(i[s.activityLevel]||s.activityLevel),s.goal&&t.push(n[s.goal]||s.goal),t.join(" • ")}function Ui(){const{user:s}=ps(),{data:i}=G(),{data:n}=J(),{data:t}=Qs(s?.id||null),r=Xs(s?.id||null),[c,a]=b.useState(!1),m=b.useMemo(()=>!i?.active_packs||!n?[]:i.active_packs.map(_=>n.find(S=>S.pack_id===_.pack_id)).filter(_=>_!==void 0),[i?.active_packs,n]),o=async()=>{try{await r.mutateAsync({forceRecompile:!0}),L.success(T.NUTRITION.POLICY_COMPILED.title)}catch(_){L.error(_ instanceof Error?_.message:T.NUTRITION.POLICY_FAILED.title)}},d=m.length>0,l=t?.stale||!i?.current_policy_hash,u=i?.metabolicProfile,g=u?.age||u?.weight||u?.height,y=i?.active_packs?.map(_=>_.pack_id)??[],v=y.some(_=>K.has(_)),N=y.some(_=>
291!K.has(_)),p=i?.nutritionGoals?.enabled??!1,j=[v,N,p].filter(Boolean).length,w=3;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:x("apple-card-elevated p-space-5 transition-all duration-normal",d&&"ring-1 ring-primary/20"),children:[e.jsxs("div",{className:"flex items-center gap-space-3",children:[e.jsx("div",{className:x("p-space-3 rounded-full",d?"bg-surface-positive-subtle":"bg-muted"),children:e.jsx(ne,{className:x("size-icon-md",d?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"apple-body font-medium text-foreground",children:"Your Profile"}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:d?`${m.length} style${m.length>1?"s":""} active`:"No styles selected"})]}),d&&e.jsx(C,{variant:l?"default":"outline",size:"sm",onClick:o,disabled:r.isPending,className:"shrink-0",children:r.isPending?e.jsx(te,{className:"size-icon-sm animate-spin"}):l?e.jsx(te,{className:"size-icon-sm"}):e.jsx(je,{className:"size-icon-sm"})})]}),e.jsxs("div",{className:"flex items-center gap-space-3 mt-space-md pt-space-md border-t border-border/50",children:[e.jsx("div",{className:x("p-space-3 rounded-full",g?"bg-secondary":"bg-muted"),children:e.jsx(_s,{className:x("size-icon-md",g?"text-foreground":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:g&&u?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"apple-body text-foreground",children:Gi(u)}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:$i(u)})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"apple-body text-foreground",children:"Body Stats"}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:"Set up for personalized goals"})]})}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>a(!0),className:"shrink-0",children:e.jsx(ga,{className:"size-icon-sm"})})]}),d&&e.jsx("div",{className:"flex flex-wrap gap-space-xs mt-space-md pt-space-md border-t border-border/50",children:m.map(_=>e.jsx(E,{variant:"secondary",className:"bg-surface-positive-subtle border border-primary/20 text-foreground text-fluid-xs",children:_.display_name},_.pack_id))}),e.jsxs("div",{className:"flex items-center gap-space-3 mt-space-md pt-space-md border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("div",{className:x("p-space-xs rounded-full",v?"bg-surface-caution-subtle":"bg-muted"),children:e.jsx(re,{className:x("h-3.5 w-3.5",v?"text-warning":"text-muted-foreground")})}),e.jsx("span",{className:x("text-fluid-xs",v?"text-foreground":"text-muted-foreground"),children:"Allergies"})]}),e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("div",{className:x("p-space-xs rounded-full",N?"bg-surface-positive-subtle":"bg-muted"),children:e.jsx(ge,{className:x("h-3.5 w-3.5",N?"text-primary":"text-muted-foreground")})}),e.jsx("span",{className:x("text-fluid-xs",N?"text-foreground":"text-muted-foreground"),children:"Styles"})]}),e.jsxs("div",{className:"flex items-center gap-space-xs",children:[e.jsx("div",{className:x("p-space-xs rounded-full",p?"bg-surface-info-subtle":"bg-muted"),children:e.jsx(B,{className:x("h-3.5 w-3.5",p?"text-info":"text-muted-foreground")})}),e.jsx("span",{className:x("text-fluid-xs",p?"text-foreground":"text-muted-foreground"),children:"Targets"})]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(E,{variant:j===w?"default":"secondary",className:"text-fluid-xs",children:[j,"/",w]})})]}),!d&&e.jsx("p",{className:"apple-caption text-muted-foreground mt-space-3 pt-space-3 border-t border-border/50",children:"Select nutrition styles below to customize how recipes are evaluated."}),l&&d&&e.jsxs("p",{className:"apple-caption text-warning mt-space-3 flex items-center gap-space-xs",children:[e.jsx(te,{className:"size-icon-xs"}),t?.reason||"Tap to apply changes"]})]}),e.jsx(He,{open:c,onOpenChange:a})]})}function Wi(s){const{metabolicProfile:i,metabolicSnapshot:n,errors:t}=s;if(i.data===null&&n.data===null)return{show:!1,severity:"info",title:"",description:""};if(t.length>0)return{show:!0,severity:"error",title:"Invalid data detected",description:`Some data couldn't be loaded: ${t.map(c=>c.field.replace(/_/g," ")).join(", ")}. Recalculate to fix.`};if(i.versionMismatch||n.versionMismatch)return{show:!0,severity:"warning",title:"Data format updated",description:"Your profile uses an older format. Recalculate to update."};if(i.data){const r=new Date(i.data.updated_at),c=new Date;if(c.setDate(c.getDate()-30),r<c)return{show:!0,severity:"info",title:"Profile may be outdated",description:`Last updated ${Math.floor((Date.now()-r.getTime())/864e5)} days ago. Consider recalculating if your metrics have changed.`}}return{show:!1,severity:"info",title:"",description:""}}const Hi={error:{bg:"bg-surface-critical-subtle border-destructive/30 text-destructive",icon:fs},warning:{bg:"bg-surface-caution-subtle border-warning/30 text-warning",icon:de},info:{bg:"bg-muted border-border text-muted-foreground",icon:fa}};function Yi({validation:s,onRecalculate:i,className:n}){const t=Wi(s);if(!t.show)return null;const{bg:r,icon:c}=Hi[t.severity];return e.jsxs("div",{className:x("stack-gap p-space-md rounded-lg border",r,n),role:"alert",children:[e.jsxs("div",{className:"flex items-start gap-space-3",children:[e.jsx(c,{className:"size-icon-md mt-space-2xs flex-shrink-0"}),e.jsxs("div",{className:"flex flex-col gap-space-xs",children:[e.jsx("p",{className:"font-medium text-fluid-sm",children:t.title}),e.jsx("p",{className:"text-fluid-xs opacity-80",children:t.description})]})]}),e.jsxs(C,{variant:t.severity==="error"?"destructive":"outline",size:"sm",onClick:i,className:"gap-space-sm flex-shrink-0",children:[e.jsx(te,{className:"size-icon-sm"}),"Recalculate"]})]})}function Qe({activePacks:s=[],currentGoals:i,onApply:n,disabled:t}){const[r,c]=b.useState(!1),a=b.useMemo(()=>Ka(s??[]),[s]);if(!s||a.status==="none")return null;const m=a.merged&&Ss(i,a.merged),o=a.warnings.length>0;return e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsxs("div",{className:"flex items-center gap-space-sm body-secondary",children:[e.jsx(hs,{className:"size-icon-sm"}),e.jsx("span",{children:a.status==="conflict"?"Macro suggestions have conflicts":"Typical macro distributions from your diets"})]}),a.status==="conflict"&&e.jsx(Ki,{mergeResult:a}),o&&a.status!=="conflict"&&e.jsx(qi,{mergeResult:a}),e.jsx("div",{className:"flex flex-wrap gap-space-sm",children:a.status==="conflict"?e.jsx(Xe,{mergeResult:a,currentGoals:i,onApply:n,disabled:t}):e.jsx(Ji,{mergeResult:a,isMatching:m??!1,onApply:n,disabled:t})}),a.status==="merged"&&a.candidates.length>1&&e.jsxs(ss,{open:r,onOpenChange:c,children:[e.jsx(as,{asChild:!0,children:e.jsxs(C,{variant:"ghost",size:"sm",className:"h-auto p-0 body-caption hover:text-foreground",children:[e.jsx(Be,{className:x("size-icon-xs mr-sp
291ace-xs transition-transform",r&&"rotate-180")}),"Or choose from individual diets"]})}),e.jsx(is,{className:"pt-space-sm",children:e.jsx("div",{className:"flex flex-wrap gap-space-sm",children:e.jsx(Xe,{mergeResult:a,currentGoals:i,onApply:n,disabled:t})})})]}),e.jsx("p",{className:"body-caption/70",children:a.status==="conflict"?"Choose one option to apply, or manually set your macros.":"Click to apply. These are informational guidelines, not strict requirements."})]})}function Ki({mergeResult:s}){return e.jsxs("div",{className:"flex items-start gap-space-sm rounded-md border border-destructive bg-surface-critical-subtle p-space-3 text-fluid-sm",children:[e.jsx(de,{className:"size-icon-sm text-destructive shrink-0 mt-space-2xs"}),e.jsxs("div",{className:"flex flex-col gap-space-xs",children:[e.jsx("p",{className:"font-medium text-destructive",children:"Your active diets have conflicting macro recommendations"}),e.jsx("ul",{className:"flex flex-col gap-space-xs body-caption",children:s.conflicts.map((i,n)=>e.jsx("li",{children:i.message},n))})]})]})}function qi({mergeResult:s}){return e.jsxs("div",{className:"flex items-start gap-space-sm rounded-md border border-warning bg-surface-caution-subtle p-space-3 text-fluid-sm",children:[e.jsx(fe,{className:"size-icon-sm text-warning shrink-0 mt-space-2xs"}),e.jsxs("div",{className:"flex flex-col gap-space-xs",children:[e.jsx("p",{className:"font-medium text-warning-foreground",children:"Some of your diets suggest different macros"}),e.jsxs("ul",{className:"flex flex-col gap-space-xs body-caption",children:[s.warnings.slice(0,2).map((i,n)=>e.jsx("li",{children:i.message},n)),s.warnings.length>2&&e.jsxs("li",{children:["+",s.warnings.length-2," more"]})]})]})]})}function Xe({mergeResult:s,currentGoals:i,onApply:n,disabled:t}){return e.jsx(e.Fragment,{children:s.candidates.map(r=>{const c=Ss(i,r.suggestion);return e.jsxs(C,{variant:c?"secondary":"outline",size:"sm",disabled:t||c,onClick:()=>n(r.suggestion),className:x("gap-space-sm transition-all",c&&"border-primary bg-surface-positive-subtle"),children:[c&&e.jsx(je,{className:"size-icon-sm text-primary"}),e.jsx("span",{className:"font-medium",children:r.pack_display_name}),e.jsx("span",{className:"body-caption",children:Ps(r.suggestion)})]},r.pack_id)})})}function Ji({mergeResult:s,isMatching:i,onApply:n,disabled:t}){if(!s.merged)return null;const r=s.status==="merged",c=s.merged.source_pack_ids.length;return e.jsxs(C,{variant:i?"secondary":"outline",size:"sm",disabled:t||i,onClick:()=>n(s.merged),className:x("gap-space-sm transition-all",i&&"border-primary bg-surface-positive-subtle"),children:[i?e.jsx(je,{className:"size-icon-sm text-primary"}):r?e.jsx(ha,{className:"size-icon-sm"}):null,e.jsx("span",{className:"font-medium",children:r?`Combined (${c} diets)`:s.candidates[0]?.pack_display_name??"Suggested"}),e.jsx("span",{className:"body-caption",children:Ps(s.merged)})]})}function Qi({metabolicBounds:s,className:i}){const{envelope:n,tdee:t,target_calories:r,trace:c}=s;if(n.status!=="ready")return null;const a=c.goal_direction==="loss",m=r.decision_point>0&&r.decision_point!==r.display_point;return e.jsxs("div",{className:x("p-space-md rounded-lg border bg-surface-info-subtle border-info/20 flex flex-col gap-space-3",i),children:[e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx(xa,{className:"size-icon-sm text-info"}),e.jsx("span",{className:"font-medium text-fluid-sm",children:"Your Personalized Range"}),e.jsxs(ze,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(fe,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"})}),e.jsx(Re,{side:"top",className:"max-w-xs",children:e.jsx("p",{className:"text-fluid-xs",children:"Your actual calorie needs may vary by ±5-10% based on individual metabolism, activity level estimation, and body composition."})})]})]}),e.jsxs("div",{className:"list-divided text-fluid-sm",children:[e.jsxs("div",{className:"content-stack-compact py-space-3 first:pt-0",children:[e.jsx("div",{className:"body-caption uppercase tracking-wide",children:"Daily Burn (TDEE)"}),e.jsxs("div",{className:"font-mono font-medium",children:[t.low.toLocaleStr
291ing(),"–",t.high.toLocaleString(),e.jsx("span",{className:"text-muted-foreground ml-space-xs",children:"kcal"})]}),e.jsxs("div",{className:"body-caption",children:["Estimated: ",t.display_point.toLocaleString()," kcal"]})]}),e.jsxs("div",{className:"content-stack-compact py-space-3 last:pb-0",children:[e.jsx("div",{className:"body-caption uppercase tracking-wide",children:"Target Calories"}),e.jsxs("div",{className:"font-mono font-medium",children:[r.low.toLocaleString(),"–",r.high.toLocaleString(),e.jsx("span",{className:"text-muted-foreground ml-space-xs",children:"kcal"})]}),e.jsxs("div",{className:"body-caption",children:["Estimated: ",r.display_point.toLocaleString()," kcal"]})]})]}),a&&m&&e.jsxs("div",{className:"flex items-start gap-space-sm p-space-sm rounded bg-surface-positive-subtle border border-primary/20",children:[e.jsx(bs,{className:"size-icon-sm text-primary mt-space-2xs shrink-0"}),e.jsxs("div",{className:"text-fluid-sm",children:[e.jsxs("span",{className:"font-medium text-primary",children:["Conservative target:"," "]}),e.jsxs("span",{className:"font-mono font-bold",children:[r.decision_point.toLocaleString()," kcal"]}),e.jsx("p",{className:"body-caption mt-space-xs",children:"Lower bound ensures reliable progress even if metabolism is at the lower end of estimates."})]})]})]})}function Ze({label:s,description:i,value:n,onChange:t,unit:r,range:c,colorClass:a,useSlider:m=!1,sliderConfig:o={min:0,max:100,step:1},inputConfig:d={min:0,max:1e3,step:1},isCustom:l,recommendedValue:u,onReset:g,caloriesInfo:y}){const v=l&&u!==void 0&&g,N=c&&c.low!==c.high;return e.jsxs("div",{className:"flex items-center gap-space-sm py-space-sm",children:[a&&e.jsx("span",{className:x("w-icon-xs h-icon-xs rounded-full shrink-0",a)}),e.jsxs("div",{className:"min-w-20 shrink-0",children:[e.jsx("span",{className:"text-fluid-sm font-medium",children:s}),i&&e.jsx("span",{className:"body-caption block sm:hidden",children:i})]}),i&&e.jsx("span",{className:"body-caption hidden sm:inline flex-shrink-0",children:i}),l!==void 0&&e.jsx(E,{variant:l?"secondary":"outline",className:x("text-fluid-xs px-space-xs py-0 shrink-0",l?"bg-surface-caution text-warning dark:bg-warning/30 dark:text-warning":"bg-surface-positive text-success dark:bg-success/30 dark:text-success/80"),children:l?"Custom":"Recommended"}),e.jsx("div",{className:"flex-1"}),v&&e.jsxs(ze,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-xs",onClick:g,children:e.jsx(_a,{className:"size-icon-xs text-muted-foreground"})})}),e.jsx(Re,{children:e.jsxs("p",{className:"text-fluid-xs",children:["Reset to ",u," ",r]})})]}),m?e.jsx(Ee,{value:[n],onValueChange:([p])=>t(p),min:o.min,max:o.max,step:o.step,className:"w-24 sm:w-32"}):e.jsx(us,{type:"number",min:d.min,max:d.max,step:d.step,value:n,onChange:p=>t(parseFloat(p.target.value)||0),fieldSize:"xs",className:"w-16 font-mono"}),e.jsxs("div",{className:"text-right shrink-0 min-w-16",children:[N?e.jsxs("span",{className:"text-fluid-sm font-mono text-foreground",children:[c.low,"–",c.high,r]}):e.jsx("span",{className:"text-fluid-sm font-mono text-muted-foreground",children:r}),y&&e.jsxs("span",{className:"body-caption ml-space-xs",children:["(",y,")"]})]})]})}const Xi=[{value:"percentage",label:"Percentage",icon:ba},{value:"grams",label:"Grams",icon:vs}],Z={protein:"bg-[hsl(var(--macro-protein))]",carbs:"bg-warning",fat:"bg-[hsl(var(--macro-fat))]"},Zi={protein:"Protein",carbs:"Carbs",fat:"Fat"},he={fiber_g:{label:"Fiber",unit:"g",min:0,max:100,step:1,description:"Helps digestion"},sodium_mg:{label:"Sodium",unit:"mg",min:0,max:5e3,step:50,description:"Daily limit"},vitamin_c_mg:{label:"Vitamin C",unit:"mg",min:0,max:2e3,step:10,description:"Immune support"},vitamin_d_iu:{label:"Vitamin D",unit:"IU",min:0,max:4e3,step:100,description:"Bone health"},calcium_mg:{label:"Calcium",unit:"mg",min:0,max:2500,step:50,description:"Strong bones"},iron_mg:{label:"Iron",unit:"mg",min:0,max:50,step:1,description:"Energy & blood"},potassium_mg:{label:"Potassium",unit:"mg",min:0,max:6e3,step:100,description:"Heart health"}};function et(){const{data:s,isLoading:i}=G(),{data:n=[]}=J(),t=rs(),[r,c]=b.useState(F),[a,m]=b.useState(!1),[o,d]=b.useState(!1),[l,u]=b.useState(["summary"]),g=s?.metabolicProfile??null,y=s?.metabolicSnapshot??null,v=s?.validation,N=b.useMemo(()=>{const h=s?.targets?.metabolic_bounds;return h?.envelope?.status==="ready"?h:null},[s?.targets]),p=b.useMemo(()=>{const h=s?.targets?.metabolic_macro_bounds;return h?.envelope?.status==="ready"&&h?.result?h:null},[s?.targets]);b.useMemo(()=>
291{if(!g)return!1;const f=new Date(g.updated_at),h=new Date;return h.setDate(h.getDate()-30),f<h},[g]);const j=b.useMemo(()=>{const h=(s?.active_packs??[]).map(k=>k.pack_id);return n.filter(k=>h.includes(k.pack_id))},[s?.active_packs,n]);b.useEffect(()=>{const f=s?.targets,h=f&&typeof f=="object"?f.nutrition_goals:void 0;let k;if(h&&typeof h=="object"&&!Array.isArray(h)){const M=Zs.safeParse(h);if(M.success)k=M.data;else{console.warn("[NutritionGoalsSection] Invalid nutrition_goals shape, using defaults:",M.error.issues);const I=(D,q,Fs)=>Math.max(q,Math.min(Fs,D)),z=(D,q)=>({percentage:D&&typeof D=="object"&&Number.isFinite(D.percentage)?I(D.percentage,0,100):q.percentage,grams:D&&typeof D=="object"&&Number.isFinite(D.grams)?I(D.grams,0,1e3):q.grams});k={calories:Number.isFinite(h.calories)?I(h.calories,0,1e4):F.calories,inputMode:h.inputMode==="percentage"||h.inputMode==="grams"?h.inputMode:F.inputMode,enabled:typeof h.enabled=="boolean"?h.enabled:F.enabled,protein:z(h.protein,F.protein),carbs:z(h.carbs,F.carbs),fat:z(h.fat,F.fat)}}}else k={...F,protein:{...F.protein},carbs:{...F.carbs},fat:{...F.fat},micronutrients:{...Q}};k.micronutrients||(k={...k,micronutrients:{...Q}}),c(k)},[s?.targets]);const w=b.useCallback(f=>{c(f),m(!0)},[]),_=f=>{const h=Math.max(500,Math.min(1e4,parseInt(f)||0));let k=aa(r,h);if(g){const M=Te(g.age,g.gender,h),I=k.micronutrients??Q,z={};for(const D of Object.keys(I)){const q=I[D];q?.source==="dri"?z[D]=M[D]:z[D]=q}k={...k,micronutrients:z}}w(k)},S=f=>{w({...r,inputMode:f})},P=(f,h)=>{const k={...r,[f]:{percentage:h,grams:ia(h,r.calories,f)}};w(k)},A=(f,h)=>{const k={...r,[f]:{grams:h,percentage:ta(h,r.calories,f)}};w(k)},$=f=>{if(y){L.info("Your goals are based on your body - diet pack suggestion shown for reference only");return}const h=Ra(r,f);w(h),L.success(`Applied: P:${f.protein_pct}% C:${f.carbs_pct}% F:${f.fat_pct}%`)},me=(f,h)=>{const k=r.micronutrients??{...Q},M=he[f],I=Math.max(M.min,Math.min(M.max,h)),z=k[f]??{value:0,enabled:!1,source:"dri"},D=z.driValue!==void 0&&I!==z.driValue;w({...r,micronutrients:{...k,[f]:{...z,value:I,source:D?"custom":"dri"}}})},O=f=>{const h=r.micronutrients??{...Q},k=h[f];k?.driValue!==void 0&&w({...r,micronutrients:{...h,[f]:{...k,value:k.driValue,source:"dri"}}})},pe=async()=>{try{const f=s?.targets||{};await t.mutateAsync({targets:{...f,nutrition_goals:r}}),m(!1),L.success(T.METABOLIC.GOALS_SAVED.title)}catch(f){L.error(f instanceof Error?f.message:T.METABOLIC.SAVE_FAILED.title)}},U=ea(r),ke=Math.abs(U)<=5,Ce=b.useMemo(()=>Object.keys(he).length,[]);return i?e.jsx("div",{className:"apple-card-elevated p-space-lg",children:e.jsx("div",{className:"flex items-center justify-center py-space-xl",children:e.jsx(Oe,{size:"lg",className:"text-primary"})})}):e.jsxs("div",{className:"apple-card-elevated",children:[e.jsxs("div",{className:"flex items-center gap-space-3 p-space-5 border-b border-border/50",children:[e.jsx("div",{className:"p-space-3 rounded-full bg-surface-positive-subtle",children:e.jsx(B,{className:"size-icon-md text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"apple-body font-medium text-foreground",children:"Daily Targets"}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:y?"Personalized for you":"Set your daily goals"})]}),e.jsx(C,{variant:y?"outline":"default",size:"sm",onClick:()=>d(!0),className:"shrink-0",children:y?e.jsx(te,{className:"size-icon-sm"}):e.jsx(ne,{className:"size-icon-sm"})})]}),e.jsxs("div",{className:"flex flex-col gap-space-md p-space-5",children:[v&&(v.needsRecalculation||!v.isFullyValid)&&e.jsx(Yi,{validation:v,onRecalculate:()=>d(!0)}),e.jsxs(gs,{type:"multiple",value:l,onValueChange:u,className:"flex flex-col gap-space-sm",children:[e.jsxs(ee,{value:"summary",className:"border rounded-lg px-space-md",children:[e.jsx(se,{className:"hover:no-underline py-space-3",children:e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx(xs,{className:"size-icon-sm text-primary"}),e.jsx("span",{className:"font-medium",children:"Your Calculated Goals"}),y&&e.jsx(E,{variant:"outline",className:"text-fluid-xs bg-surface-positive-subtle text-success dar
291k:bg-success/30 dark:text-success/80 border-success/30 dark:border-success/80",children:"Personalized"})]})}),e.jsxs(ae,{className:"flex flex-col gap-space-md pb-space-md",children:[y&&g&&e.jsxs("div",{className:"p-space-3 bg-surface-muted-medium rounded-lg text-fluid-sm border",children:[e.jsxs("p",{className:"font-medium mb-space-sm flex items-center gap-space-sm",children:[e.jsx(fe,{className:"size-icon-sm text-primary"}),"How we calculated this:"]}),e.jsxs("ul",{className:"flex flex-col gap-space-xs text-muted-foreground ml-space-lg list-disc",children:[e.jsxs("li",{children:["Your body: ",g.age," years old,"," ",g.gender]}),e.jsxs("li",{children:["Weight: ",g.weight," ",g.units==="metric"?"kg":"lbs",", Height: ",g.height," ",g.units==="metric"?"cm":"in"]}),e.jsxs("li",{children:["Activity:"," ",g.activityLevel?.replace(/-/g," ")]}),e.jsxs("li",{children:["Goal: ",g.goal?.replace(/-/g," ")]})]}),e.jsx(C,{variant:"link",size:"sm",className:"p-0 h-auto mt-space-sm text-primary",onClick:()=>d(!0),children:"Update my information →"})]}),e.jsxs("div",{className:"flex flex-col gap-space-sm",children:[e.jsx(H,{htmlFor:"calories",className:"text-fluid-base font-medium",children:"Daily Calories"}),e.jsx("p",{className:"body-caption",children:"How many calories you should eat each day"}),e.jsxs("div",{className:"flex items-center gap-space-3",children:[e.jsx(us,{id:"calories",type:"number",min:500,max:1e4,step:50,value:r.calories,onChange:f=>_(f.target.value),className:"w-32 font-mono text-fluid-lg"}),e.jsx("span",{className:"body-secondary",children:"kcal per day"})]}),g&&e.jsx("p",{className:"text-fluid-xs text-success dark:text-success/80",children:"✓ Vitamins & minerals will adjust automatically when you change calories"})]}),N&&e.jsx(Qi,{metabolicBounds:N}),e.jsxs("div",{className:"flex flex-col gap-space-sm",children:[e.jsxs("div",{className:"flex items-center justify-between text-fluid-sm",children:[e.jsx("span",{className:"font-medium",children:"Protein, Carbs & Fat"}),e.jsxs("span",{className:"text-muted-foreground",children:[r.protein.percentage,"% / ",r.carbs.percentage,"% /"," ",r.fat.percentage,"%"]})]}),e.jsxs("div",{className:"h-icon-sm rounded-full overflow-hidden flex bg-muted",children:[e.jsx("div",{className:x(Z.protein,"transition-all"),style:{width:`${r.protein?.percentage??0}%`},title:`Protein: ${r.protein.percentage}%`}),e.jsx("div",{className:x(Z.carbs,"transition-all"),style:{width:`${r.carbs?.percentage??0}%`},title:`Carbs: ${r.carbs.percentage}%`}),e.jsx("div",{className:x(Z.fat,"transition-all"),style:{width:`${r.fat?.percentage??0}%`},title:`Fat: ${r.fat.percentage}%`})]}),e.jsxs("div",{className:"flex justify-between body-caption",children:[e.jsxs("span",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:x("w-2 h-2 rounded-full",Z.protein)}),"Protein ",r.protein.grams,"g"]}),e.jsxs("span",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:""}),"Carbs ",r.carbs.grams,"g"]}),e.jsxs("span",{className:"flex items-center gap-space-xs",children:[e.jsx("span",{className:x("w-2 h-2 rounded-full",Z.fat)}),"Fat ",r.fat.grams,"g"]})]})]}),e.jsx("div",{className:x("flex items-center gap-space-sm p-space-sm rounded-lg text-fluid-sm",ke?"bg-surface-positive-subtle text-success dark:bg-success/30 dark:text-success/80":"bg-surface-caution-subtle text-warning dark:bg-surface-caution dar
291k:text-warning"),children:ke?e.jsx("span",{children:"✓ Your macros add up to 100%"}):e.jsxs("span",{children:[U>0?`${U}% remaining`:`${Math.abs(U)}% over`," ","— adjust in Macro Details below"]})})]})]}),e.jsxs(ee,{value:"macros",className:"border rounded-lg px-space-md",children:[e.jsx(se,{className:"hover:no-underline py-space-3",children:e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx(va,{className:"size-icon-sm text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Macro Details"}),e.jsx("span",{className:"body-caption",children:"Fine-tune protein, carbs & fat"})]})}),e.jsxs(ae,{className:"flex flex-col gap-space-md pb-space-md",children:[e.jsxs("div",{className:"flex flex-col gap-space-sm",children:[e.jsx(H,{children:"Show as"}),e.jsx(Oa,{items:Xi,value:r.inputMode,onValueChange:f=>S(f),size:"sm"})]}),e.jsx("div",{className:"divide-y divide-border",children:["protein","carbs","fat"].map(f=>{const h=p?.result?.[f],k=h&&h.low!==h.high;return e.jsx(Ze,{label:Zi[f],value:r.inputMode==="percentage"?r[f].percentage:r[f]?.grams??0,onChange:M=>r.inputMode==="percentage"?P(f,M):A(f,M),unit:r.inputMode==="percentage"?"%":"g",colorClass:Z[f],useSlider:r.inputMode==="percentage",sliderConfig:{min:0,max:80,step:1},inputConfig:{min:0,max:500,step:1},range:k?h:null,caloriesInfo:`${(r[f]?.grams??0)*sa[f]} kcal`},f)})})]})]}),e.jsxs(ee,{value:"micronutrients",className:"border rounded-lg px-space-md",children:[e.jsx(se,{className:"hover:no-underline py-space-3",children:e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx(ya,{className:"size-icon-sm text-success"}),e.jsx("span",{className:"font-medium",children:"Vitamins & Minerals"}),e.jsxs(E,{variant:"outline",className:"text-fluid-xs",children:[Ce," nutrients"]})]})}),e.jsxs(ae,{className:"flex flex-col gap-space-md pb-space-md",children:[e.jsx("p",{className:"body-secondary",children:g?"Recommended amounts based on your age and body.":"Track vitamins and minerals. Set up your goals above for personalized recommendations."}),e.jsx("div",{className:"divide-y divide-border",children:Object.keys(he).map(f=>{const h=he[f],M=(r.micronutrients??Q)[f]??{value:0,source:"dri"},I=M.source==="custom",z=I&&M.driValue!==void 0;return e.jsx(Ze,{label:h.label,description:h.description,value:M.value,onChange:D=>me(f,D),unit:h.unit,inputConfig:{min:h.min,max:h.max,step:h.step},isCustom:I,recommendedValue:M.driValue,onReset:z?()=>O(f):void 0},f)})})]})]}),j.length>0&&e.jsxs(ee,{value:"diet-packs",className:"border rounded-lg px-space-md",children:[e.jsx(se,{className:"hover:no-underline py-space-3",children:e.jsxs("div",{className:"flex items-center gap-space-sm",children:[e.jsx(ja,{className:"size-icon-sm text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:"Diet Suggestions"}),e.jsx("span",{className:"body-caption",children:"From your active diets"})]})}),e.jsx(ae,{className:"pb-space-md",children:y?e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsx("div",{className:"p-space-3 bg-surface-info-subtle dark:bg-surface-info rounded-lg text-fluid-sm border border-info/30 dark:border-info/30",children:e.jsxs("p",{className:"text-info dark:text-info",children:[e.jsx("strong",{children:"Your goals are personalized"})," — these diet suggestions are shown for reference only and won't change your calculated values."]})}),e.jsx(Qe,{activePacks:j,currentGoals:r,onApply:$,disabled:!0})]}):e.jsx(Qe,{activePacks:j,currentGoals:r,onApply:$,disabled:t.isPending})})]})]}),a&&e.jsxs(C,{onClick:pe,disabled:t.isPending,className:"w-full gap-space-sm",children:[t.isPending?e.jsx(Ve,{className:"size-icon-sm animate-spin"}):e.jsx(Na,{className:"size-icon-sm"}),"Save Changes"]})]}),e.jsx(He,{open:o,onOpenChange:d})]})}function st(){const{data:s,isLoading:i}=J(),{data:n,isLoading:t}=G(),r=be(),c=i||t,m=(n?.active_packs??[]).map(l=>l.pack_id),o=s?.filter(l=>K.has(l.pack_id))??[],d=(l,u)=>{r.mutate({packId:l,version:u})};return c?e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsx(xe,{className:"h-icon-lg w-3/4"}),e.jsx("div",{className:"flex flex-col",children:Array.from({length:4}).map((l,u)=>e.jsx(xe,{className:"h-16"},u))})]}):e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsxs("div",{className:"flex items-start gap-space-sm",children:[e.jsx("div",{className:"rounded-full bg-surface-critical-subtle p-space-sm",children:e.jsx(re,{className:"h-icon-md w-icon-md text-destructive"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:"Food Allergies & Intolerances"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground",children:"Select any allergies so we can filter out unsafe recipes"})]})]}
291),e.jsx("div",{className:"flex flex-col",children:o.map(l=>e.jsx($e,{pack:l,isActive:m.includes(l.pack_id),isLoading:r.isPending&&r.variables?.packId===l.pack_id,onToggle:()=>d(l.pack_id,l.version)},l.pack_id))})]})}const es=["mediterranean","keto","paleo","vegetarian","vegan","pescatarian","low-sodium","low-fodmap"];function at(){const{data:s,isLoading:i}=J(),{data:n,isLoading:t}=G(),r=be(),c=i||t,m=(n?.active_packs??[]).map(l=>l.pack_id),o=s?.filter(l=>!K.has(l.pack_id))?.sort((l,u)=>{const g=es.includes(l.pack_id),y=es.includes(u.pack_id);return g&&!y?-1:!g&&y?1:l.display_name.localeCompare(u.display_name)})?.slice(0,8)??[],d=(l,u)=>{r.mutate({packId:l,version:u})};return c?e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsx(xe,{className:"h-icon-lg w-3/4"}),e.jsx("div",{className:"grid grid-cols-2 gap-space-sm",children:Array.from({length:6}).map((l,u)=>e.jsx(xe,{className:"h-16 rounded-xl"},u))})]}):e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsxs("div",{className:"flex items-start gap-space-sm",children:[e.jsx("div",{className:"rounded-full bg-surface-positive-subtle p-space-sm",children:e.jsx(ge,{className:"h-icon-md w-icon-md text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:"Nutrition Styles"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground",children:"Choose eating patterns that match your lifestyle"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-space-sm",children:o.map(l=>{const u=m.includes(l.pack_id);return e.jsxs("button",{onClick:()=>d(l.pack_id,l.version),disabled:r.isPending,className:x("relative flex flex-col items-start gap-space-xs rounded-xl border p-space-sm text-left transition-all","hover:border-primary/50 hover:bg-accent/50",u?"border-primary/50 bg-surface-positive-subtle":"border-border bg-card"),children:[u&&e.jsx("div",{className:"absolute right-2 top-2",children:e.jsx(je,{className:"h-icon-sm w-icon-sm text-primary"})}),e.jsx("span",{className:"text-fluid-sm font-medium text-foreground pr-space-5",children:l.display_name}),l.description&&e.jsx("span",{className:"text-fluid-xs text-muted-foreground line-clamp-2",children:l.description})]},l.pack_id)})}),m.filter(l=>!K.has(l)).length>0&&e.jsxs("div",{className:"flex flex-wrap gap-space-sm pt-space-sm",children:[e.jsx("span",{className:"text-fluid-xs text-muted-foreground",children:"Selected:"}),m.filter(l=>!K.has(l)).map(l=>{const u=s?.find(g=>g.pack_id===l);return e.jsx(E,{variant:"outline",size:"xs",className:"border-primary/30 text-primary",children:u?.display_name??l},l)})]})]})}const ue=[{id:"allergies",title:"Allergies",icon:re},{id:"styles",title:"Styles",icon:ge},{id:"targets",title:"Targets",icon:B},{id:"complete",title:"Complete",icon:ne}];function it({open:s,onOpenChange:i}){const[n,t]=b.useState(0),[r,c]=b.useState(!1),{data:a}=G(),{data:m}=J(),o=a?.nutritionGoals,d=a?.active_packs?.map(v=>v.pack_id)??[],l=()=>{n<ue.length-1&&t(v=>v+1)},u=()=>{n>0&&t(v=>v-1)},g=()=>{i(!1),setTimeout(()=>t(0),300)},y=()=>{switch(n){case 0:return e.jsx(st,{});case 1:return e.jsx(at,{});case 2:return e.jsxs("div",{className:"flex flex-col gap-space-md",children:[e.jsxs("div",{className:"flex items-start gap-space-sm",children:[e.jsx("div",{className:"rounded-full bg-accent/50 p-space-sm",children:e.jsx(B,{className:"h-icon-md w-icon-md text-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-foreground",children:"Daily Nutrition Targets"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground",children:"Set your calorie and macro goals"})]})]}),o?.calories&&e.jsxs("div",{className:"rounded-xl border border-border bg-card p-space-md",children:[e.jsx("p",{className:"text-fluid-sm text-muted-foreground mb-space-sm",children:"Current targets:"}),e.jsxs("div",{className:"flex flex-wrap gap-space-sm",children:[e.jsxs(E,{variant:"secondary",children:[o.calories," kcal"]}),o.protein?.grams&&e.jsxs(E,{variant:"outline",children:[o.protein.grams,"g protein"]}),o.carbs?.grams&&e.jsxs(E,{variant:"outline",children:[o.carbs.grams,"g carbs"]}),o.fat?.grams&&e.jsxs(E,{variant:"outline",children:[o.fat.grams,"g fat"]})]})]}),e.jsxs("div",{className:"grid gap-space-sm",children:[e.jsxs(C,{variant:"default",className:"w-full justify-start",onClick:()=>c(!0),children:[e.jsx(B,{className:"mr-space-sm h-icon-sm w-icon-sm"}),"Calculate targets for me"]}),e.jsxs(C,{variant:"outline",className:"w-full justify-start",onClick:l,children:[e.jsx(ne,{className:"mr-space-sm h-icon-sm w-icon-sm"}),o?.calories?"Keep current targets":"Skip for now"]})]})]});case 3:return e.jsxs("div",{className:"flex flex-col gap-space-lg text-center",children:[e.jsx("div",{className:"mx-auto rounded-full bg-surface-positive-subtle p-space-md w-fit",children:e.jsx(ne,{className:"h-icon-xl w-icon-xl text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-fluid-lg font-semibold text-foreground",children:"You're all set!"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground mt-space-xs",children:"Your nutrition profile has been configured"})]}),e.jsxs("div",{className:"flex flex-col gap-space-sm text-left",children:[d.length>0&&e.jsxs("div",{className:"rounded-xl border border-border bg-card p-space-sm",children:[e.jsx("p",{className:"text-fluid-xs text-muted-foreground mb-space-sm",children:"Active diet preferences:"}),e.jsxs("div",{className:"flex flex-wrap gap-space-xs",children:[d.slice(0,5).map(v=>{const N=m?.find(p=>p.pack_id===v);return e.jsx(E,{variant:"secondary",size:"xs",children:N?.display_name??v.replace(/-/g," ")},v)}),d.length>5&&e.jsxs(E,{variant:"outline",size:"xs",children:["+",d.length-5," more"]})]})]}),o?.calories&&e.jsxs("div",{className:"rounded-xl border border-border bg-card p-space-sm",children:[e.jsx("p",{className:"text-fluid-xs text-muted-foreground mb-space-sm",children:"Daily target:"}),e.jsxs(E,{variant:"secondary",children:[o.calories," kcal"]})]})]})]});default:return null}};return e.jsxs(e.Fragment,{children:[e.jsx(cs,{open:s,onOpenChange:i,children:e.jsxs(os,{size:"sm",children:[e.jsxs(ls,{children:[e.jsx(ds,{children:"Qu
291ick Setup"}),e.jsx(ms,{children:"Configure your nutrition preferences in a few simple steps"})]}),e.jsx("div",{className:"flex items-center justify-center gap-space-sm py-space-sm",children:ue.map((v,N)=>{const p=v.icon,j=N===n,w=N<n;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:x("flex h-icon-xl w-icon-xl items-center justify-center rounded-full transition-colors",j&&"bg-primary text-primary-foreground",w&&"bg-surface-positive text-primary",!j&&!w&&"bg-muted text-muted-foreground"),children:e.jsx(p,{className:"h-icon-sm w-icon-sm"})}),N<ue.length-1&&e.jsx("div",{className:x("h-0.5 w-6 mx-space-xs transition-colors",w?"bg-surface-positive-subtle0":"bg-muted")})]},v.id)})}),e.jsx("div",{className:"min-h-[280px] py-space-md",children:y()}),e.jsxs("div",{className:"flex items-center justify-between pt-space-md border-t border-border",children:[n>0&&n<ue.length-1?e.jsxs(C,{variant:"ghost",size:"sm",onClick:u,children:[e.jsx(ys,{className:"mr-space-xs h-icon-sm w-icon-sm"}),"Back"]}):e.jsx("div",{}),n<ue.length-1?e.jsxs(C,{onClick:l,children:[n===2?"Skip":"Next",e.jsx(ye,{className:"ml-space-xs h-icon-sm w-icon-sm"})]}):e.jsx(C,{onClick:g,children:"Done"})]})]})}),e.jsx(He,{open:r,onOpenChange:v=>{c(v),v||t(3)}})]})}function tt(){const{data:s,isLoading:i}=J(),{data:n,isLoading:t}=G(),r=be(),c=b.useMemo(()=>s?s.filter(d=>K.has(d.pack_id)):[],[s]),a=b.useMemo(()=>n?.active_packs||[],[n?.active_packs]),m=b.useMemo(()=>new Set(a.map(d=>d.pack_id)),[a]),o=async d=>{try{await r.mutateAsync({packId:d.pack_id,version:d.version});const l=m.has(d.pack_id);L.success(l?T.DIET.PACK_REMOVED.title:T.DIET.PACK_ADDED.title,{description:d.display_name})}catch(l){L.error(l instanceof Error?l.message:T.DIET.UPDATE_FAILED.title)}};return i||t?e.jsx("div",{className:"flex items-center justify-center py-space-xl",children:e.jsx(Oe,{size:"md",className:"text-primary"})}):c.length?e.jsxs("div",{className:"flex flex-col gap-space-3",children:[e.jsxs("div",{className:"flex items-start gap-space-sm px-space-xs",children:[e.jsx(re,{className:"size-icon-sm text-warning mt-space-2xs flex-shrink-0"}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:"Select any food allergies or intolerances. Recipes containing these ingredients will be flagged."})]}),e.jsx("div",{className:"flex flex-col",children:c.map(d=>e.jsx(nt,{pack:d,isActive:m.has(d.pack_id),isLoading:r.isPending&&r.variables?.packId===d.pack_id,onToggle:()=>o(d),activePackRefs:a,allPacks:s||[]},d.pack_id))})]}):null}function nt({pack:s,isActive:i,isLoading:n,onToggle:t,activePackRefs:r,allPacks:c}){const a=As(s.pack_id,s.version,i,r,c);return e.jsx($e,{pack:s,isActive:i,isLoading:n,onToggle:t,conflictPreview:a.hasConflicts?{hasConflicts:!0,conflictNames:a.conflicts.map(m=>m.otherPackName),highestSeverity:a.highestSeverity}:void 0})}function xt(){const{user:s,loading:i}=ps(),{data:n,isLoading:t,error:r}=G(),[c,a]=b.useState(!1),[m,o]=b.useState("preferences"),d=(n?.active_packs?.length??0)>0,l=n?.nutritionGoals?.enabled??!1,u=d||l;if(i||t)return e.jsx(Se,{children:e.jsx(Pe,{spacing:"compact",container:"default",children:e.jsx(na,{})})});if(!s)return e.jsx(Rs,{to:"/signin",replace:!0});if(r)return e.jsx(Se,{children:e.jsx(Pe,{spacing:"compact",container:"default",children:e.jsxs("div",{className:"rounded-xl border border-destructive/20 bg-destructive/5 p-space-lg text-center",children:[e.jsx(re,{className:"mx-auto size-icon-xl text-destructive mb-space-md"}),e.jsx("h2",{className:"text-fluid-lg font-semibold text-foreground mb-space-sm",children:"Unable to load profile"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground mb-space-md",children:r instanceof Error?r.message:"Something went wrong loading your diet preferences."}),e.jsx(C,{variant:"outline",onClick:()=>window.location.reload(),children:"Try Again"})]})})});const g=[{value:"preferences",label:"Preferences",icon:ge},{value:"targets",label:"Daily Targets",icon:B}];return e.jsxs(Se,{children:[e.jsx(ra,{url:"/diet-preferences"}),e.jsx(ca,{data:{title:"Nutrition Preferences - Recipe Alchemy",description:"Customize your nutrition preferences and see how recipes match your needs.",url:oa("/diet-preferences"),type:"website"}}),e.jsx(Pe,{spacing:"compact",container:"default",children:e.jsxs(ts,{gap:"relaxed",children:[e.jsxs("header",{className:"text-center",children:[e.jsx("h1",{className:"apple-title-medium text-foreground",children:"Nutrition Profile"}),e.jsx("p",{className:"apple-caption text-muted-foreground mt-space-xs",children:"Personalize how recipes match your needs"})]}),!u&&e.jsxs("div",{className:"rounded-2xl border border-primary/20 bg-gradient-to-br from-primary/5 to-primary/10 p-space-lg text-center",children:[e.jsx("div",{className:"mx-auto mb-space-md w-fit roun
291ded-full bg-primary/10 p-space-3",children:e.jsx(ne,{className:"size-icon-lg text-primary"})}),e.jsx("h2",{className:"text-fluid-lg font-semibold text-foreground mb-space-sm",children:"Let's personalize your experience"}),e.jsx("p",{className:"text-fluid-sm text-muted-foreground mb-space-md max-w-sm mx-auto",children:"Set up your allergies, nutrition styles, and daily targets in just a few steps."}),e.jsxs(C,{size:"lg",onClick:()=>a(!0),children:[e.jsx(Ke,{className:"mr-space-sm size-icon-sm"}),"Get Started"]})]}),u&&e.jsx("div",{className:"flex justify-center",children:e.jsxs(C,{variant:"outline",onClick:()=>a(!0),children:[e.jsx(Ke,{className:"mr-space-sm size-icon-sm"}),"Quick Setup"]})}),e.jsx(Ui,{}),e.jsx(la,{options:g,value:m,onChange:y=>o(y),level:"L2",layoutId:"diet-prefs-nav"}),m==="preferences"&&e.jsxs(gs,{type:"multiple",defaultValue:[],className:"flex flex-col gap-space-3",children:[e.jsxs(ee,{value:"allergies",className:"apple-list-container border-0 rounded-xl overflow-hidden",children:[e.jsx(se,{className:"px-space-md py-space-3 hover:no-underline hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-center gap-space-3",children:[e.jsx("div",{className:"p-space-sm rounded-full bg-warning/10",children:e.jsx(re,{className:"size-icon-md text-warning"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"apple-body font-semibold text-foreground block",children:"Allergies & Intolerances"}),e.jsx("span",{className:"apple-caption text-muted-foreground",children:"Safety first—flag ingredients that could cause reactions"})]})]})}),e.jsxs(ae,{className:"px-space-md pb-space-md",children:[e.jsx("p",{className:"apple-caption text-muted-foreground mb-space-md leading-relaxed",children:"Here's the thing about food allergies: your immune system has decided certain proteins are the enemy, and there's no negotiating with it. Whether it's the casein in dairy triggering inflammation or the tropomyosin in shellfish causing anaphylaxis, these reactions are real and can be serious. Select your allergens below and we'll keep those ingredients far away from your plate."}),e.jsx(tt,{})]})]}),e.jsxs(ee,{value:"styles",className:"apple-list-container border-0 rounded-xl overflow-hidden",children:[e.jsx(se,{className:"px-space-md py-space-3 hover:no-underline hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-center gap-space-3",children:[e.jsx("div",{className:"p-space-sm rounded-full bg-primary/10",children:e.jsx(ge,{className:"size-icon-md text-primary"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("span",{className:"apple-body font-semibold text-foreground block",children:"Nutrition Styles"}),e.jsx("span",{className:"apple-caption text-muted-foreground",children:"Choose your approach—from Mediterranean to keto"})]})]})}),e.jsxs(ae,{className:"px-space-md pb-space-md",children:[e.jsx("p",{className:"apple-caption text-muted-foreground mb-space-md leading-relaxed",children:"Every eating pattern has its logic. Mediterranean emphasizes olive oil and fish because the research on heart health is genuinely compelling. Keto manipulates your metabolism to burn fat for fuel. Paleo asks what our ancestors ate (though the answer is more complicated than most realize). The best diet is the one you'll actually stick to. Pick what resonates with your goals and lifestyle."}),e.jsx(ti,{children:e.jsx(ci,{})})]})]})]}),m==="targets"&&e.jsxs("div",{className:"apple-list-container rounded-xl p-space-lg",children:[e.jsxs("div",{className:"flex items-center gap-space-3 mb-space-md",children:[e.jsx("div",{className:"p-space-sm rounded-full bg-info/10",children:e.jsx(B,{className:"size-icon-md text-info"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"apple-body font-semibold text-foreground",children:"Daily Targets"}),e.jsx("p",{className:"apple-caption text-muted-foreground",children:"Set your macros—the science of what your body actually needs"})]})]}),e.jsx("p",{className:"apple-caption text-muted-foreground mb-space-lg leading-relaxed",children:"Nutrition isn't about restriction—it's about optimization. Your body is essentially a biochemical reactor that needs specific inputs to run efficie
291ntly. Protein for muscle synthesis, fats for hormone production and nutrient absorption, carbs for readily available energy. The ratios matter, but so does context. Set your targets below and we'll score recipes based on how well they fit your goals."}),e.jsx(et,{})]})]})}),e.jsx(it,{open:c,onOpenChange:a})]})}export{xt 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.