PageSourceSearch

https://twinforgefit.ai/assets/ProgressPage-CXD9C-Rh.js

js twinforgefit.ai collected 2026-10-05 14:31:24 UTC 142,941 bytes, 22 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/BodyStudio-na_YPJqN.js","assets/motion-CghpQXKE.js","assets/router-epi9CWfp.js","assets/TwinStage-SXvS1dQ4.js","assets/heat-zone-adapter-C2YVEJFC.js","assets/morph-normals-CfRh6rQ9.js","assets/index-_-9kgWZ5.js","assets/supabase-CTBn71hm.js","assets/index-DgO36s-g.css","assets/measures-DMn_ZQvM.js","assets/viewer-registry-DLIcBGr7.js","assets/ForgeSlider-iXSNs5BQ.js","assets/person-standing-CbQIQ0U1.js","assets/list-1-Xww0iC.js","assets/SurfaceHeading-D49e6FSi.js","assets/CardHeading-CcXctmQj.js","assets/resolved-daily-health-Dvckn8ID.js","assets/InfoTooltip-DShv0ozk.js","assets/ForgeIcon-PBV6eFDW.js","assets/useBodyScansRealtime-D6lGht3t.js","assets/useGamification-Cy0lwjhY.js","assets/useSocialRefresh-BNPqaImu.js","assets/useRuntimeFeatureFlag-Q8wV5kQ1.js","assets/useBodyScanTwin-CjDga_ah.js","assets/skin-tone-resolver-Ce3X9VDi.js","assets/TwinBoundary-DDPI3cVE.js","assets/twin-preview-sex-Bx9ptNuF.js","assets/SectionBoundary-BkSrDADb.js","assets/arrow-up-C3EWNZgG.js","assets/chevron-right-WmA4jE3-.js","assets/camera-C5hhbOmw.js","assets/refrigerator-0UrXF6wH.js","assets/book-open-DsRVbYI6.js","assets/clipboard-list-DG_CFVS0.js","assets/shopping-cart-CgHY1ePD.js","assets/addDays-aYYkHh1o.js","assets/isAfter-B-iHa5hT.js","assets/IconButton-CB6iDVTq.js","assets/clipboard-iQ7AojFJ.js","assets/calendar-DrNo2-T3.js","assets/download-B5AFaDgs.js","assets/share-2-BXojvhlh.js","assets/trending-down-Cd0TvuSZ.js","assets/plus-DSuB3LTj.js","assets/chevron-up-J_GnXi8C.js","assets/integration-return-EAN6N-3A.js","assets/charts-BVCHgq9e.js","assets/droplets-CSUMabu5.js","assets/TwinPreviewStage-e7NNtZpZ.js"])))=>i.map(i=>d[i]);
2import{c as rt,d0 as qs,c$ as Ks,cZ as Xs,dj as Vs,dk as Zs,dl as dt,d8 as X,U as at,s as U,l as Re,bm as nt,f as js,r as _s,dm as Gt,u as We,B as we,_ as kt,dn as Js,c8 as Qs,a5 as er,ay as G,bO as vs,dp as tr,bs as Ne,n as sr,T as rr,S as ws,dq as ar,G as Ns,N as St,cO as V,X as tt,E as st,a3 as jt,Y as nr,m as ir,b7 as or,a8 as Ut,am as lr,a9 as cr,aw as Yt,aA as dr,aa as zt,bL as ur,cz as mr,dr as hr,b8 as xr,cB as fr,cE as pr,cD as qt,ds as gr,dt as Ve,du as br,dv as yr,dw as jr,cj as ks}from"./index-_-9kgWZ5.js";import{j as e,m as K,A as je}from"./motion-CghpQXKE.js";import{r as c}from"./router-epi9CWfp.js";import{u as Ss,S as Kt,i as ut,E as _r}from"./SurfaceHeading-D49e6FSi.js";import{d as vr,e as wr,b as Xt,f as Nr,g as mt,h as kr,t as Sr,T as Mr}from"./heat-zone-adapter-C2YVEJFC.js";import{B as ht,a as Cr,I as Fr,S as Vt}from"./InfoTooltip-DShv0ozk.js";import{P as Rr}from"./resolved-daily-health-Dvckn8ID.js";import{u as Er}from"./useBodyScansRealtime-D6lGht3t.js";import{u as Lr}from"./useGamification-Cy0lwjhY.js";import{u as Dr}from"./useRuntimeFeatureFlag-Q8wV5kQ1.js";import{u as Tr,a as Pr}from"./useBodyScanTwin-CjDga_ah.js";import{r as $r,a as Ar,b as Br}from"./skin-tone-resolver-Ce3X9VDi.js";import{T as Or}from"./TwinBoundary-DDPI3cVE.js";import{a as Zt}from"./twin-preview-sex-Bx9ptNuF.js";import{p as Hr}from"./viewer-registry-DLIcBGr7.js";import{m as Ir,a as Wr}from"./measures-DMn_ZQvM.js";import{c as ne,f as Y,b as Jt,M as Gr,D as Ur}from"./CardHeading-CcXctmQj.js";import{A as Yr,S as _t}from"./SectionBoundary-BkSrDADb.js";import{A as zr}from"./arrow-up-C3EWNZgG.js";import{C as qr}from"./chevron-right-WmA4jE3-.js";import{F as ge}from"./ForgeIcon-PBV6eFDW.js";import{C as Ie}from"./camera-C5hhbOmw.js";import{R as Kr}from"./refrigerator-0UrXF6wH.js";import{B as Xr}from"./book-open-DsRVbYI6.js";import{C as Vr}from"./clipboard-list-DG_CFVS0.js";import{S as Zr}from"./shopping-cart-CgHY1ePD.js";import{a as Jr}from"./addDays-aYYkHh1o.js";import{i as Qr}from"./isAfter-B-iHa5hT.js";import{I as Ms}from"./IconButton-CB6iDVTq.js";import{c as ea}from"./clipboard-iQ7AojFJ.js";import{C as Qt}from"./calendar-DrNo2-T3.js";import{D as ta}from"./download-B5AFaDgs.js";import{S as es}from"./share-2-BXojvhlh.js";import{T as Ee}from"./trending-down-Cd0TvuSZ.js";import{P as sa}from"./plus-DSuB3LTj.js";import{C as ra}from"./chevron-up-J_GnXi8C.js";import"./integration-return-EAN6N-3A.js";import{R as aa,A as na,C as ia,X as oa,Y as la,T as ca,b as da,a as ua}from"./charts-BVCHgq9e.js";import{D as ma}from"./droplets-CSUMabu5.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"19ca80bcc68db376b793c8a886be03b6d5ea8a5c"};var s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="0d377958-cb8b-467c-a666-735cc8a6e5de",t._sentryDebugIdIdentifier="sentry-dbid-0d377958-cb8b-467c-a666-735cc8a6e5de")}catch{}})();/**
3 * @license lucide-react v0.344.0 - ISC
4 *
5 * This source code is licensed under the ISC license.
6 * See the LICENSE file in the root directory of this source tree.
7 */const ha=rt("Bone",[["path",{d:"M17 10c.7-.7 1.69 0 2.5 0a2.5 2.5 0 1 0 0-5 .5.5 0 0 1-.5-.5 2.5 2.5 0 1 0-5 0c0 .81.7 1.8 0 2.5l-7 7c-.7.7-1.69 0-2.5 0a2.5 2.5 0 0 0 0 5c.28 0 .5.22.5.5a2.5 2.5 0 1 0 5 0c0-.81-.7-1.8 0-2.5Z",key:"w610uw"}]]);/**
8 * @license lucide-react v0.344.0 - ISC
9 *
10 * This source code is licensed under the ISC license.
11 * See the LICENSE file in the root directory of this source tree.
12 */const xa=rt("Bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);/**
13 * @license lucide-react v0.344.0 - ISC
14 *
15 * This source code is licensed under the ISC license.
16 * See the LICENSE file in the root directory of this source tree.
17 */const fa=rt("GitBranch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]);/**
18 * @license lucide-react v0.344.0 - ISC
19 *
20 * This source code is licensed under the ISC license.
21 * See the LICENSE file in the root directory of this source tree.
22 */const vt=rt("Percent",[["line",{x1:"19",x2:"5",y1:"5",y2:"19",key:"1x9vlm"}],["circle",{cx:"6.5",cy:"6.5",r:"2.5",key:"4mh3h7"}],["circle",{cx:"17.5",cy:"17.5",r:"2.5",key:"1mdrzq"}]]);function pa(t,s){const[r,n]=qs(t,s.start,s.end);return{start:r,end:n}}function ga(t,s){const{start:r,end:n}=pa(s?.in,t);let a=+r>+n;const o=a?+r:+n,i=a?n:r;i.setHours(0,0,0,0);let l=1;const d=[];for(;+i<=o;)d.push(Ks(r,i)),i.setDate(i.getDate()+l),i.setHours(0,0,0,0);return a?d.reverse():d}function ba(t,s){return Xs(t,s?.in).getDate()}function ya(t,s,r){return Jr(t,-27,r)}function ja(){return e.jsxs(Vs,{children:[e.jsx(Zs,{columns:3,count:3,cardHeight:"h-24"}),e.jsxs(dt,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(X,{className:"h-4 w-24"}),e.jsx(X,{className:"h-3 w-20"})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(X,{className:"h-32 w-24 rounded-lg"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-surface-solid/50 rounded-lg p-3 space-y-1",children:[e.jsx(X,{className:"h-3 w-10"}),e.jsx(X,{className:"h-5 w-14"})]}),e.jsxs("div",{className:"bg-surface-solid/50 rounded-lg p-3 space-y-1",children:[e.jsx(X,{className:"h-3 w-14"}),e.jsx(X,{className:"h-5 w-10"})]})]}),e.jsx(X,{className:"h-9 w-full rounded-lg"})]})]})]}),e.jsxs(dt,{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 roun
22ded"}),e.jsx(X,{className:"h-4 w-32"})]})}),e.jsx(X,{className:"h-28 w-full rounded-lg mb-3"}),e.jsx("div",{className:"grid grid-cols-3 gap-2 pt-3 border-t border-white/5",children:[0,1,2].map(t=>e.jsxs("div",{className:"text-center space-y-1",children:[e.jsx(X,{className:"h-5 w-14 mx-auto"}),e.jsx(X,{className:"h-3 w-10 mx-auto"})]},t))})]}),e.jsxs(dt,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4 rounded"}),e.jsx(X,{className:"h-4 w-36"})]}),e.jsx(X,{className:"h-4 w-16"})]}),e.jsx(X,{className:"h-24 w-full rounded-lg"})]})]})}function _a({beforeImage:t,afterImage:s,beforeLabel:r,afterLabel:n,className:a=""}){const[o,i]=c.useState(50),l=r?`du ${r}`:"avant",d=n?`du ${n}`:"après",u=Math.round(o),h=`Photo ${l} visible à ${u} %, photo ${d} visible à ${100-u} %`,x=f=>{const w={ArrowLeft:-1,ArrowDown:-1,ArrowRight:1,ArrowUp:1}[f.key];if(w!==void 0){f.preventDefault(),i(g=>Math.min(100,Math.max(0,Math.round(g)+w)));return}(f.key==="Home"||f.key==="End")&&(f.preventDefault(),i(f.key==="Home"?0:100))};return e.jsxs("div",{className:`relative w-full aspect-[3/4] overflow-hidden rounded-xl focus-within:ring-2 focus-within:ring-accent ${a}`,children:[e.jsx("div",{className:"absolute inset-0",children:e.jsx("img",{src:s,alt:`Photo ${d}`,className:"w-full h-full object-cover",draggable:!1})}),e.jsx("div",{className:"absolute inset-0 overflow-hidden",style:{width:`${o}%`},children:e.jsx("img",{src:t,alt:`Photo ${l}`,className:"w-full h-full object-cover",style:{width:o>0?`${100/(o/100)}%`:"100%",maxWidth:"none"},draggable:!1})}),e.jsx("input",{type:"range",min:0,max:100,step:1,value:u,"aria-label":`Comparer la photo ${l} et la photo ${d}`,"aria-valuetext":h,onChange:f=>i(Number(f.target.value)),onKeyDown:x,className:"absolute inset-x-0 top-1/2 z-20 h-11 w-full -translate-y-1/2 cursor-ew-resize opacity-0"}),e.jsx("div",{className:"pointer-events-none absolute bottom-0 top-0 w-1 bg-white shadow-lg",style:{left:`${o}%`,transform:"translateX(-50%)"},"aria-hidden":"true",children:e.jsx("div",{className:"absolute left-1/2 top-1/2 flex h-11 w-11 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-white shadow-xl",children:e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",className:"text-slate-800",children:e.jsx("path",{d:"M6 10L3 7M3 7L6 4M3 7H8M14 10L17 7M17 7L14 4M17 7H12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",transform:"rotate(90 10 10)"})})})}),r&&e.jsx("div",{className:"absolute bottom-3 left-3 px-2 py-1 rounded bg-black/60 text-white text-xs font-medium",children:r}),n&&e.jsx("div",{className:"absolute bottom-3 right-3 px-2 py-1 rounded bg-black/60 text-white text-xs font-medium",children:n})]})}function va(t,s=30){const{profile:r}=at(),n=Ss(t,r?.timezone,s);return{weights:c.useMemo(()=>n.data.flatMap(o=>o.body&&typeof o.body.metrics.weight_kg=="number"?[{logged_at:o.body.observed_at,weight_kg:o.body.metrics.weight_kg,source:o.body.source}]:[]),[n.data]),loading:n.loading,error:n.error,refetch:n.refresh}}function wa(t){const[s,r]=c.useState([]),[n,a]=c.useState(!0),[o,i]=c.useState(null),l=c.useRef(!0);c.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const d=c.useCallback(async()=>{if(!t){a(!1);return}i(null);try{const{data:u,error:h}=await U.from("body_scans").select("scanned_at, estimated_body_fat_pct").eq("user_id",t).not("estimated_body_fat_pct","is",null).order("scanned_at",{ascending:!0}).limit(20);if(!l.current)return;h?i(h.message):u&&r(u.filter(x=>x.estimated_body_fat_pct!==null))}catch(u){l.current&&i(u instanceof Error?u.message:"Erreur inattendue")}finally{l.current&&a(!1)}},[t]);return c.useEffect(()=>{d()},[d]),{data:s,loading:n,error:o,refetch:d}}function Na(t){const[s,r]=c.useState([]),[n,a]=c.useState(!0),[o,i]=c.useState(null),l=c.useRef(!0);c.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const d=c.useCallback(async()=>{if(!t){a(!1);return}i(null);try{const{data:u,error:h}=await U.from("body_scans").select("scanned_at, waist_cm, estimated_waist_cm, estimated_waist_hip_ratio, waist_hip_ratio_risk").eq("user_id",t).order("scanned_at",{ascending:!0}).limit(20);if(!l.current)return;
22if(h){i(h.message);return}if(u){const x=u.map(f=>({scanned_at:f.scanned_at,waist_cm:f.waist_cm??f.estimated_waist_cm,estimated_waist_hip_ratio:f.estimated_waist_hip_ratio,waist_hip_ratio_risk:f.waist_hip_ratio_risk})).filter(f=>f.waist_cm!=null&&f.waist_cm>0);r(x)}}catch(u){l.current&&i(u instanceof Error?u.message:"Erreur inattendue")}finally{l.current&&a(!1)}},[t]);return c.useEffect(()=>{d()},[d]),{data:s,loading:n,error:o,refetch:d}}const I=150,ka=68,Sa=6,Ma={neck:38,shoulders:110,chest:95,waist:80,hips:95,bicep:32,forearm:27,thigh:54,calf:36},Ca={neck:32,shoulders:98,chest:90,waist:70,hips:100,bicep:26,forearm:22,thigh:56,calf:35};function Fa(t,s){return t/Math.PI/2*s}function Ra(t,s="male"){const r=s==="female"?Ca:Ma,n={neck:t.neck??r.neck,shoulders:t.shoulders??r.shoulders,chest:t.chest??r.chest,waist:t.waist??r.waist,hips:t.hips??r.hips,bicepL:t.bicepLeft??r.bicep,bicepR:t.bicepRight??r.bicep,forearm:t.forearm??r.forearm,thighL:t.thighLeft??r.thigh,thighR:t.thighRight??r.thigh,calfL:t.calfLeft??r.calf,calfR:t.calfRight??r.calf},o=Math.max(n.shoulders,n.hips,n.chest)/Math.PI/2,i=ka/o,l=v=>Fa(v,i),d=l(n.hips),u=Sa/2,h=d-u,x=u+h/2,f=l(n.thighL),b=l(n.thighR),w=Math.max(f,b),g=w>0?Math.min(1,h/2/w):1;return{scale:i,neckHW:l(n.neck),shoulderHW:l(n.shoulders),chestHW:l(n.chest),waistHW:l(n.waist),hipHW:d,bicepLHW:l(n.bicepL),bicepRHW:l(n.bicepR),forearmHW:l(n.forearm),thighLHW:f*g,thighRHW:b*g,calfLHW:l(n.calfL)*g,calfRHW:l(n.calfR)*g,legOffset:x}}function Mt(t,s=.38){if(t.length<2)return"";const r=a=>a.toFixed(1);let n=`M${r(t[0][0])},${r(t[0][1])}`;for(let a=0;a<t.length-1;a++){const[o,i]=t[a],[l,d]=t[a+1],u=d-i,h=Math.abs(u)*s,x=u>=0?1:-1;n+=` C${r(o)},${r(i+x*h)} ${r(l)},${r(d-x*h)} ${r(l)},${r(d)}`}return n}function Ct(t,s=.38){if(t.length<2)return"";const r=a=>a.toFixed(1);let n="";for(let a=0;a<t.length-1;a++){const[o,i]=t[a],[l,d]=t[a+1],u=d-i,h=Math.abs(u)*s,x=u>=0?1:-1;n+=` C${r(o)},${r(i+x*h)} ${r(l)},${r(d-x*h)} ${r(l)},${r(d)}`}return n}const Ea=["M150,16","C136,16 126,28 126,42","C126,56 136,66 150,66","C164,66 174,56 174,42","C174,28 164,16 150,16Z"].join(" ");function La(t,s="male"){const r=s==="female"?.7:.75,n=s==="female"?1:.98,a=[{y:68,hw:t.neckHW*.55},{y:74,hw:t.neckHW},{y:84,hw:t.shoulderHW*r},{y:95,hw:t.shoulderHW},{y:112,hw:t.chestHW*.96},{y:130,hw:t.chestHW},{y:155,hw:(t.chestHW+t.waistHW)/2},{y:178,hw:t.waistHW},{y:194,hw:(t.waistHW+t.hipHW)/2},{y:210,hw:t.hipHW},{y:228,hw:t.hipHW*n},{y:250,hw:t.hipHW*.78}],o=a.map(u=>[I+u.hw,u.y]),i=a.slice().reverse().map(u=>[I-u.hw,u.y]);let l=Mt(o);const d=i[0];return l+=` L${d[0].toFixed(1)},${d[1].toFixed(1)}`,l+=Ct(i),l+="Z",l}function ts(t,s){const r=s==="right",n=r?I+t.legOffset:I-t.legOffset,a=r?t.thighRHW:t.thighLHW,o=r?t.calfRHW:t.calfLHW,i=a*.68+o*.32,l=o*.55,d=o*.65,u=[{y:239,hw:a*1.06},{y:250,hw:a*1.03},{y:260,hw:a},{y:282,hw:a*.97},{y:298,hw:i+1.5},{y:312,hw:i},{y:326,hw:i-1},{y:342,hw:o+1.5},{y:356,hw:o},{y:375,hw:o*.82},{y:395,hw:l+1.5},{y:408,hw:l},{y:422,hw:l*.92},{y:430,hw:d}],h=u.map(g=>r?[n+g.hw,g.y]:[n-g.hw,g.y]),x=u.slice().reverse().map(g=>r?[n-g.hw,g.y]:[n+g.hw,g.y]);let f=Mt(h);const b=h[h.length-1],w=x[0];return f+=` C${b[0].toFixed(1)},${(b[1]+4).toFixed(1)} ${w[0].toFixed(1)},${(w[1]+4).toFixed(1)} ${w[0].toFixed(1)},${w[1].toFixed(1)}`,f+=Ct(x),f+="Z",f}function ss(t,s){const r=s==="right",n=r?t.bicepRHW:t.bicepLHW,a=t.forearmHW,o=a*.62,i=a*.5,l=r?I+t.shoulderHW-3:I-t.shoulderHW+3,d=r?l-5:l+5,u=[{cx:l,y:91,hw:n*.6},{cx:l,y:100,hw:n*.8},{cx:l,y:114,hw:n*.95},{cx:l,y:132,hw:n},{cx:r?l-1:l+1,y:156,hw:(n+a)/2},{cx:r?l-2:l+2,y:175,hw:a},{cx:r?d+1:d-1,y:196,hw:o},{cx:d,y:212,hw:i}],h=u.map(g=>r?[g.cx+g.hw,g.y]:[g.cx-g.hw,g.y]),x=u.slice().reverse().map(g=>r?[g.cx-g.hw,g.y]:[g.cx+g.hw,g.y]);let f=Mt(h,.35);const b=h[h.length-1],w=x[0];return f+=` C${b[0].toFixed(1)},${(b[1]+5).toFixed(1)} ${w[0].toFixed(1)},${(w[1]+5).toFixed(1)} ${w[0].toFixed(1)},${w[1].toFixed(1)}`,f+=Ct(x,.35),f+="Z",f}const Cs={developed:8,développé:8,developpe:8,strong:8,fort:8,moderate:5,modéré:5,modere:5,medium:5,moyen:5,average:5,underdeveloped:2,"sous-développé":2,"sous-developpe":2,weak:2,faible:2,poor:2},Da={low:"low",faible:"low",basse:"low",bas:"low",moderate:"moderate",modéré:"moderate",modere:"moderate",modérée:"moderate",moderee:"moderate",moye
22n:"moderate",moyenne:"moderate",medium:"moderate",high:"high",élevé:"high",eleve:"high",élevée:"high",elevee:"high",haute:"high",haut:"high"};function wt(t){if(typeof t=="number")return t<=0?null:t>=7?"developed":t>=4?"moderate":"underdeveloped";if(typeof t=="string"){const s=t.toLowerCase().trim(),r=Cs[s];if(r!==void 0)return wt(r);const n=parseFloat(s);if(!isNaN(n))return wt(n)}return null}function Ta(t){return typeof t!="string"?null:Da[t.toLowerCase().trim()]??null}const Pa={developed:{color:"#2ECC71",label:"Développé"},moderate:{color:"#F5A623",label:"Moyen"},underdeveloped:{color:"#E74C3C",label:"À renforcer"}},$a={low:{color:"#2ECC71",label:"Faible"},moderate:{color:"#F5A623",label:"Modérée"},high:{color:"#E74C3C",label:"Élevée"}},Aa=[{key:"shoulders",label:"Épaules"},{key:"arms",label:"Bras"},{key:"chest",label:"Poitrine"},{key:"back",label:"Dos"},{key:"legs",label:"Jambes"}],Ba=[{key:"abdomen",label:"Abdomen"},{key:"hips",label:"Hanches"},{key:"thighs",label:"Cuisses"},{key:"arms",label:"Bras"}];function Oa(t,s){const r=[],n=[],a=s??null;if(!a)return{blobs:r,legend:n};const o=d=>I+d*(t.shoulderHW-3),i=d=>I+d*t.legOffset,l={shoulders:[{cx:I-t.shoulderHW*.78,cy:96,r:t.shoulderHW*.5,color:""},{cx:I+t.shoulderHW*.78,cy:96,r:t.shoulderHW*.5,color:""}],arms:[{cx:o(-1)-2,cy:152,r:22,color:""},{cx:o(1)+2,cy:152,r:22,color:""}],chest:[{cx:I,cy:124,r:t.chestHW*.8,color:""}],back:[],legs:[{cx:i(-1),cy:290,r:30,color:""},{cx:i(1),cy:290,r:30,color:""},{cx:i(-1)-1,cy:366,r:20,color:""},{cx:i(1)+1,cy:366,r:20,color:""}]};for(const d of Aa){const u=wt(a[d.key]);if(!u)continue;const h=Pa[u];n.push({key:d.key,label:d.label,color:h.color,levelLabel:h.label});for(const x of l[d.key]??[])r.push({...x,color:h.color})}return{blobs:r,legend:n}}function Ha(t,s){const r=[],n=[],a=s??null;if(!a)return{blobs:r,legend:n};const o=d=>I+d*(t.shoulderHW-3),i=d=>I+d*t.legOffset,l={abdomen:[{cx:I,cy:180,r:t.waistHW*1.05,color:""}],hips:[{cx:I,cy:212,r:t.hipHW*.9,color:""}],thighs:[{cx:i(-1),cy:285,r:27,color:""},{cx:i(1),cy:285,r:27,color:""}],arms:[{cx:o(-1)-2,cy:150,r:19,color:""},{cx:o(1)+2,cy:150,r:19,color:""}]};for(const d of Ba){const u=Ta(a[d.key]);if(!u)continue;const h=$a[u];n.push({key:d.key,label:d.label,color:h.color,levelLabel:h.label});for(const x of l[d.key]??[])r.push({...x,color:h.color})}return{blobs:r,legend:n}}const Ia=1;function Wa(t){const s=[{label:"Biceps",left:t.bicepLeft,right:t.bicepRight},{label:"Cuisses",left:t.thighLeft,right:t.thighRight},{label:"Mollets",left:t.calfLeft,right:t.calfRight}],r=[];for(const n of s){if(n.left==null||n.right==null)continue;
22const a=Math.round(Math.abs(n.left-n.right)*10)/10;a>=Ia&&r.push({label:n.label,deltaCm:a})}return r}function Ga(t){if(!t||typeof t!="object")return null;const s=t,r={};for(const n of["shoulders","arms","chest","back","legs"]){const a=s[n];if(typeof a=="number"&&a>0)r[n]=a;else if(typeof a=="string"){const o=a.toLowerCase().trim(),i=Cs[o];if(i!==void 0)r[n]=i;else{const l=parseFloat(a);!isNaN(l)&&l>0&&(r[n]=l)}}}return Object.keys(r).length>0?r:null}function Ua(t){const s=Object.values(t).filter(r=>r!=null);return s.length===0?0:s.reduce((r,n)=>r+n,0)/s.length}function Ya(t){const[s,r]=c.useState([]),[n,a]=c.useState(!0),[o,i]=c.useState(null),l=c.useRef(!0);c.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const d=c.useCallback(async()=>{if(!t){a(!1);return}i(null);try{const{data:u,error:h}=await U.from("body_scans").select("scanned_at, muscle_assessment").eq("user_id",t).not("muscle_assessment","is",null).order("scanned_at",{ascending:!0}).limit(20);if(!l.current)return;if(h){i(h.message);return}if(u){const x=u.map(f=>{const b=Ga(f.muscle_assessment);return b?{scanned_at:f.scanned_at,assessment:b,average:Ua(b)}:null}).filter(f=>f!==null);r(x)}}catch(u){l.current&&i(u instanceof Error?u.message:"Erreur inattendue")}finally{l.current&&a(!1)}},[t]);return c.useEffect(()=>{d()},[d]),{data:s,loading:n,error:o,refetch:d}}const za=1,qa=1500,Ka=3e4;function rs(t,s="front",r=!0){const[n,a]=c.useState(null),[o,i]=c.useState(!1),[l,d]=c.useState(null),u=c.useRef(null),h=c.useRef(null),x=c.useRef(!0);c.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const f=c.useCallback(()=>{u.current&&(URL.revokeObjectURL(u.current),u.current=null)},[]),b=c.useCallback(async()=>{if(!t||!r){f(),a(null),i(!1);return}h.current?.abort();const w=new AbortController;h.current=w;const g=setTimeout(()=>w.abort(),Ka);f(),a(null),i(!0),d(null);const v=za+1;for(let m=0;m<v;m++){if(w.signal.aborted||!x.current||m>0&&(await new Promise(y=>{const p=setTimeout(y,qa*m);w.signal.addEventListener("abort",()=>clearTimeout(p),{once:!0})}),w.signal.aborted||!x.current))return;try{const{data:{session:y}}=await U.auth.getSession();if(!y||w.signal.aborted||!x.current)return;const p=await fetch(`https://chvmzsawxhcwzgwywqam.supabase.co/functions/v1/body-photo-decrypt?scan_id=${t}&type=${s}`,{headers:{Authorization:`Bearer ${y.access_token}`},signal:w.signal});if(w.signal.aborted||!x.current)return;if(!p.ok)throw new Error(`Erreur ${p.status}`);const R=await p.blob();if(w.signal.aborted||!x.current)return;f();const N=URL.createObjectURL(R);u.current=N,a(N),i(!1),clearTimeout(g);return}catch(y){if(w.signal.aborted||!x.current){clearTimeout(g);return}if(m===v-1){clearTimeout(g);const p=y instanceof Error?y.message:"Erreur inattendue";Re.error("useDecryptedPhoto failed",y),d(p),i(!1)}}}},[t,s,r,f]);return c.useEffect(()=>(b(),()=>{h.current?.abort(),u.current&&(URL.revokeObjectURL(u.current),u.current=null)}),[b]),{url:n,loading:o,error:l,refetch:b}}function Xa(t){const[s,r]=c.useState([]),[n,a]=c.useState([]),[o,i]=c.useState(!0),[l,d]=c.useState(null),[u,h]=c.useState(null),x=c.useRef(!0),f=c.useRef(new Set);c.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const b=c.useCallback(async()=>{if(t){i(!0),d(null);try{const[y,p]=await Promise.all([U.from("injury_tracking").select("id, injury_name, body_area, injury_type, severity, status, contra_indicated_movements, recommended_exercises, reported_at, resolved_at").eq("user_id",t).in("status",["active","recovering","monitoring"]).order("reported_at",{ascending:!1}),U.from("pain_logs").select("id, injury_id, body_area, pain_level, context, affects_training, logged_at").eq("user_id",t).gte("logged_at",new Date(Date.now()-2592e6).toISOString()).order("logged_at",{ascending:!1}).limit(50)]);if(!x.current)return;if(y.error)throw y.error;if(p.error)throw p.error;const R=y.data||[];R.forEach(N=>f.current.add(N.id)),r(R),a(p.data||[])}catch(y){x.current&&d(y instanceof Error?y.message:"Erreur de chargement")}finally{x.current&&i(!1)}}},[t]);c.useEffect(()=>{b()},[b]),nt({table:"injury_tracking",userId:t,onInsert:c.useCallback(y=>{if(!x.current)return;const p=y;p&&!f.current.has(p.id)&&(f.current.add(p.id),h({injuryId:p.id,injuryName:p.injury_name,bodyArea:p.body_area,detectedAt:new Date().toISOString()})),b()},[b]),onUpdate:c.useCallback(()=>{b()},[b])});const w=c.useCallback(async y=>{if(!t)return;const{error:p}=await U.from("injury_tracking").insert({user_id:t,...y,status:"active"});if(p)throw p;await b()},[t,b]),g=c.useCallback(async(y,p)=>{if(!t)return;const R={status:p};p==="resolved"&&(R.resolved_at=new Date().toISOString());const{error:N}=await U.from("injury_tracking").update(R).eq("id",y).eq("user_id",t);if(N)throw N;await b()},[t,b]),v=c.useCallback(async y=>{if(!t)return;const{error:p}=await U.from("pain_logs").insert({user_id:t,...y});if(p)throw p;await b()},[t,b]),m=c.useCallback(()=>h(null),[]);return{injuries:s,painLogs:n,loading:o,error:l,alloyAlert:u,dismissAlloyAlert:m,addInjury:w,updateInjuryStatus:g,addPainLog:v,refetch:b}}function Va(t,s,r){const n={...t};
22for(const[a,o]of Object.entries(s))n[a]===o&&(Object.prototype.hasOwnProperty.call(r,a)?n[a]=r[a]:delete n[a]);return n}async function Za(t,s,r,n,a){const o={...t,[s]:r};a(()=>o);let i=!1;try{return i=await n(o),i}finally{i||a(l=>Va(l,o,t))}}const xt={neck:"neck_cm",shoulders:"shoulder_cm",chest:"chest_cm",waist:"waist_cm",hips:"hips_cm",bicepLeft:"bicep_left_cm",bicepRight:"bicep_right_cm",forearm:"forearm_cm",thighLeft:"thigh_left_cm",thighRight:"thigh_right_cm",calfLeft:"calf_left_cm",calfRight:"calf_right_cm"},Fs={neck:"neck_cm",shoulders:"shoulder_cm",chest:"chest_cm",waist:"waist_cm",hips:"hips_cm",forearm:"forearm_cm",bicepLeft:"bicep_left_cm",bicepRight:"bicep_right_cm",thighLeft:"thigh_left_cm",thighRight:"thigh_right_cm",calfLeft:"calf_left_cm",calfRight:"calf_right_cm"};function Ja(t,s){return t?Object.entries(s).every(([r,n])=>{const a=Fs[r];return a!=null&&t[a]===n}):!1}function Qa({userId:t,latestScan:s,measurementOverride:r,heightCm:n,weightKg:a,bodyFatPct:o,appendOnly:i=!1,onSaved:l}){const[d,u]=c.useState(!1),[h,x]=c.useState({}),[f,b]=c.useState(null),w=js();c.useEffect(()=>{x({}),b(null)},[s?.id,t]),c.useEffect(()=>{!f||!Ja(r,f)||(x(_=>Object.fromEntries(Object.entries(_).filter(([S,k])=>f[S]===void 0||f[S]!==k))),b(null))},[f,r]);const g=c.useCallback((_,S)=>{x(k=>({...k,[_]:S}))},[]),v=c.useCallback((_,S)=>{if(_ in S)return S[_];const k=Fs[_];if(k&&r?.[k]!=null)return r[k];if(!s)return null;const L=xt[_];return L?s[L]:null},[s,r]),m=c.useCallback(_=>v(_,h),[h,v]),y=c.useCallback(()=>({chest:m("chest"),waist:m("waist"),hips:m("hips"),shoulders:m("shoulders"),neck:m("neck"),forearm:m("forearm"),bicepLeft:m("bicepLeft"),bicepRight:m("bicepRight"),thighLeft:m("thighLeft"),thighRight:m("thighRight"),calfLeft:m("calfLeft"),calfRight:m("calfRight")}),[m]),p=Object.keys(h).length>0,R=c.useMemo(()=>new Set(Object.keys(h)),[h]),N=c.useCallback(async _=>{if(!t||Object.keys(_).length===0)return!1;u(!0);try{if(Object.values(_).every(S=>!Number.isFinite(S)||S<=0))return w.error("Aucune modification valide"),!1;if(s&&i){const S={...r??{}},k=(D,$)=>{$!=null&&Number.isFinite($)&&$>0&&(S[D]=$)};k("height_cm",n??null),k("weight_kg",a??s.weight_kg),k("body_fat_pct",o??s.estimated_body_fat_pct),k("neck_cm",v("neck",_)),k("shoulder_cm",v("shoulders",_)),k("chest_cm",v("chest",_)),k("waist_cm",v("waist",_)),k("hips_cm",v("hips",_)),k("forearm_cm",v("forearm",_)),k("bicep_left_cm",v("bicepLeft",_)),k("bicep_right_cm",v("bicepRight",_)),k("thigh_left_cm",v("thighLeft",_)),k("thigh_right_cm",v("thighRight",_)),k("calf_left_cm",v("calfLeft",_)),k("calf_right_cm",v("calfRight",_));const{error:L}=await U.rpc("append_body_measurement_override",{p_body_scan_id:s.id,p_measurements:S});if(L)throw L}else if(s){const S={};for(const[E,C]of Object.entries(_)){const H=xt[E];H&&C>0&&(S[H]=C)}const k=S.waist_cm??s.waist_cm,L=S.hips_cm??s.hips_cm;k&&L&&L>0&&(S.estimated_waist_hip_ratio=Math.round(k/L*100)/100);const D=S,{error:$}=await U.from("body_scans").update(D).eq("id",s.id);if($)throw $}else{const S={};for(const[D,$]of Object.entries(_)){const E=xt[D];E&&$>0&&(S[E]=$)}const k={user_id:t,scanned_at:new Date().toISOString(),...S,analysis_version:"manual_input",pre_validation_passed:!0},{error:L}=await U.from("body_scans").insert(k);if(L)throw L}return w.success("Mensurations enregistrées"),s&&i?b(_):(x({}),b(null)),l(),!0}catch(S){const k=S??{};return _s("body-measurements","measurement_save_failed",{path:s&&i?"override":s?"legacy_update":"first_entry",fields:Object.keys(_).join(","),code:typeof k.code=="string"?k.code:null,message:S instanceof Error?S.message:typeof k.message=="string"?k.message:String(S)}),w.error("Erreur lors de la sauvegarde"),!1}finally{u(!1)}},[t,s,n,a,o,i,r,v,w,l]),F=c.useCallback(()=>N(h),[h,N]),M=c.useCallback((_,S)=>Za(h,_,S,N,x),[h,N]);return{saving:d,hasEdits:p,edits:h,editedFields:R,handleMeasurementChange:g,handleSave:F,saveMeasurement:M,getMeasurementProps:y}}function en(t){const[s,r]=c.useState({resolvedUserId:void 0,timeline:[],comparisons:[]}),[n,a]=c.useState(!!t),o=c.useRef(!0),i=c.useRef(0),l=c.useRef(t);l.current=t,c.useEffect(()=>(o.current=!0,()=>{o.current=!1,i.current+=1}),[]);const d=c.useCallback(async()=>{const h=t;if(l.current!==h)return;const x=++i.current,f=()=>o.current&&x===i.current&&l.current===h;if(r({resolvedUserId:h,timeline:[],comparisons:[]}),a(!!h),!h){f()&&a(!1);return}try{const b=new Date;b.setDate(b.getDate()-28);const w=b.toISOString(),[g,v,m,y]=await Promise.all([U.from("xp_logs").select("id, action, description, xp_earned, earned_at").eq("user_id",h).in("action",["rank_promotion","personal_record","weight_milestone","weight_goal"]).gte
22("earned_at",w).order("earned_at",{ascending:!1}).limit(20),U.from("coaching_decision_log").select("id, decision_type, decision_made, created_at").eq("user_id",h).eq("decision_type","phase_transition").gte("created_at",w).order("created_at",{ascending:!1}).limit(5),U.from("daily_recaps").select("compliance_score, calories_in, calories_target, steps, sleep_quality, active_minutes").eq("user_id",h).gte("recap_date",new Date(Date.now()-7*864e5).toISOString().split("T")[0]).order("recap_date",{ascending:!1}),U.from("daily_recaps").select("compliance_score, calories_in, calories_target, steps, sleep_quality, active_minutes").eq("user_id",h).gte("recap_date",new Date(Date.now()-35*864e5).toISOString().split("T")[0]).lte("recap_date",new Date(Date.now()-28*864e5).toISOString().split("T")[0]).order("recap_date",{ascending:!1})]);if(!f())return;const p=[];if(g.data)for(const _ of g.data){const S={rank_promotion:"rank_promotion",personal_record:"personal_record",weight_milestone:"weight_milestone",weight_goal:"weight_milestone"};p.push({id:_.id,type:S[_.action]||"personal_record",label:_.action==="rank_promotion"?"Promotion":_.action==="personal_record"?"Record personnel":"Objectif poids",description:_.description||_.action,date:_.earned_at,xp:_.xp_earned})}const R=_=>{const S=_.match(/Transition from (\w+) to (\w+)/i);if(S){const k=Gt(S[1])||S[1],L=Gt(S[2])||S[2];return`${k} → ${L}`}return _||"Transition de phase"};if(v.data)for(const _ of v.data){const S=_;p.push({id:S.id,type:"phase_change",label:"Phase coaching",description:R(S.decision_made||""),date:S.created_at})}p.sort((_,S)=>new Date(S.date).getTime()-new Date(_.date).getTime());const N=[],F=m.data||[],M=y.data||[];if(F.length>=3&&M.length>=3){const _=C=>C.length?Math.round(C.reduce((H,A)=>H+A,0)/C.length):0,S=_(F.map(C=>Number(C.compliance_score||0))),k=_(M.map(C=>Number(C.compliance_score||0)));S>k&&k>0&&N.push({metric:"compliance",label:"Score compliance",current:S,previous:k,unit:"%",changePct:Math.round((S-k)/k*100)});const L=_(F.map(C=>Number(C.steps||0))),D=_(M.map(C=>Number(C.steps||0)));L>D&&D>0&&N.push({metric:"steps",label:"Pas quotidiens",current:L,previous:D,unit:"",changePct:Math.round((L-D)/D*100)});const $=_(F.map(C=>Number(C.active_minutes||0))),E=_(M.map(C=>Number(C.active_minutes||0)));$>E&&E>0&&N.push({metric:"active_minutes",label:"Minutes actives",current:$,previous:E,unit:"min",changePct:Math.round(($-E)/E*100)})}r({resolvedUserId:h,timeline:p.slice(0,10),comparisons:N})}catch{}finally{f()&&a(!1)}},[t]);c.useEffect(()=>{d()},[d]);const u=s.resolvedUserId===t;return{timeline:u?s.timeline:[],comparisons:u?s.comparisons:[],loading:!!t&&(n||!u),refetch:d}}function tn(t){const[s,r]=c.useState({ownerId:t??null,profile:null}),[n,a]=c.useState(!0),[o,i]=c.useState(null),l=c.useRef(!0),d=c.useRef(0);c.useEffect(()=>(l.current=!0,()=>{l.current=!1}),[]);const u=c.useCallback(async()=>{const x=++d.current;if(!t){l.current&&(r({ownerId:null,profile:null}),i(null),a(!1));return}r({ownerId:t,profile:null}),a(!0),i(null);try{const{data:f,error:b}=await U.from("user_profiles").select("first_name, gender, height_cm, daily_calorie_target, protein_target_g, carbs_target_g, fats_target_g, hydration_target_ml, session_duration_min, current_weight_kg, target_weight_kg, target_body_fat_pct, withings_connected, withings_last_sync, pregnancy_status, avoid_calorie_display, eating_disorder_history, avoid_weight_language, pregnancy_trimester, due_date, objective, timezone").eq("user_id",t).maybeSingle();if(!l.current||x!==d.current)return;if(b){r({ownerId:t,profile:null}),i(b.message);return}r({ownerId:t,profile:f??null})}catch(f){l.current&&x===d.current&&(r({ownerId:t,profile:null}),i(f instanceof Error?f.message:"Erreur inattendue"))}finally{l.current&&x===d.current&&a(!1)}},[t]);c.useEffect(()=>{u()},[u]);const h=s.ownerId===(t??null);return{profile:h?s.profile:null,loading:!!t&&(n||!h),error:h?o:null,refetch:u}}function sn(t,s=7){const[r,n]=c.useState([]),[a,o]=c.useState(!!t),[i,l]=c.useState(null),[d,u]=c.useState(void 0),h=c.useRef(!0),x=c.useRef(0),f=c.useRef(t);f.current=t,c.useEffect(()=>(h.current=!0,()=>{h.current=!1,x.current+=1}),[]);const b=c.useCallback(async()=>{const w=t;if(!h.current||f.current!==w)return;const g=++x.current,v=()=>h.current&&g===x.current&&f.current===w;if(u(w),n([]),o(!!w),l(null),!w){v()&&o(!1);return}try{const m=new Date;m.setDate(m.getDate()-s);const{data:y,error:p}=await U.from("daily_recaps").select("id, recap_date, calories_in, calories_out, compliance_score, coach_message, steps, training_completed").eq("user_id",w).gte("recap_date",m.toISOString().split("T")[0]).order("recap_date",{ascending:!1});if(!v())return;if(p){l(p.message);return}n(y??[])}catch(m){v()&&l(m instanceof Error?m.message:"Erreur inattendue")}finally{v()&&o(!1)}},[t,s]);return c.useEffect(()=>{b()},[b]),nt({table:"daily_recaps",userId:t,events:["INSERT","UPDATE"],onAny:()=>{b()}}),d!==t?{recaps:[],loading:!!t,error:null,refetch:b}:{recaps:r,loading:a,error:i,refetch:b}}const ft={avgComplianceScore:0,avgNutritionScore:0,avgActivityScore:0,totalMealsLogged:0,avgSteps:0,avgActiveMinutes:0,avgSleepQuality:0,avgSleepDurationMin:0,trainingDaysCount:0,recaps:[]};function rn(t){const[s,r]=c.useState(ft),[n,a]=c.useState(!!t),[o,i]=c.useState(null),[l,d]=c.useState(void 0),u=c.useRef(!0),h=c.useRef(0),x=c.useRef(t);x.current=t,c.useEffect(()=>(u.current=!0,()=>{u.current=!1,h.current+=1}),[]);const f=c.useCallback(async()=>{const b=t;if(!u.current||x.current!==b)return;const w=++h.current,g=()=>u.current&&w===h.current&&x.current===b;if(d(b),r(ft),a(!!b),i(null),!b){g()&&a(!1);return}try{const v=new Date;v.setDate(v.getDate()-7);const{data:m,error:y}=await U.from("daily_recaps").select("recap_date, compliance_score, nutrition_score, activity_score, meals_logged, steps, active_minutes, sleep_quality, sleep_duration_min, training_completed").eq("user_id",b).gte("recap_date",v.toISOString().split("T")[0]).order("recap_date",{ascending:!0});if(!g())return;if(y){i(y.message);return}if(m&&m.length>0){const p=m.length,R=k=>k.reduce((L,D)=>L+(D??0),0),N=m.map(k=>
22k.compliance_score),F=m.map(k=>k.nutrition_score),M=m.map(k=>k.activity_score),_=m.map(k=>k.sleep_quality).filter(k=>k!==null),S=m.map(k=>k.sleep_duration_min).filter(k=>k!==null);r({avgComplianceScore:Math.round(R(N)/p),avgNutritionScore:Math.round(R(F)/p),avgActivityScore:Math.round(R(M)/p),totalMealsLogged:R(m.map(k=>k.meals_logged)),avgSteps:Math.round(R(m.map(k=>k.steps))/p),avgActiveMinutes:Math.round(R(m.map(k=>k.active_minutes))/p),avgSleepQuality:_.length>0?Math.round(R(_)/_.length):0,avgSleepDurationMin:S.length>0?Math.round(R(S)/S.length):0,trainingDaysCount:m.filter(k=>k.training_completed).length,recaps:m})}}catch(v){g()&&i(v instanceof Error?v.message:"Erreur inattendue")}finally{g()&&a(!1)}},[t]);return c.useEffect(()=>{f()},[f]),nt({table:"daily_recaps",userId:t,events:["INSERT","UPDATE"],onAny:()=>{f()}}),l!==t?{progress:ft,loading:!!t,error:null,refetch:f}:{progress:s,loading:n,error:o,refetch:f}}const an="id, user_id, predicted_at, objective, target_weight_kg, current_weight_kg, current_rate_kg_per_week, projected_date_optimistic, projected_date_realistic, projected_date_pessimistic, projected_date_best_week, confidence_score, data_points_used, data_completeness, extra_training_days, factors, status, message_fr, period_source, body_fat_current_pct, compliance_trend, previous_projected_date, explanation, what_if_date";function nn(t){const[s,r]=c.useState(null),[n,a]=c.useState(!1),[o,i]=c.useState(null),[l,d]=c.useState(!!t),[u,h]=c.useState(null),[x,f]=c.useState(void 0),b=c.useRef(!0),w=c.useRef(0),g=c.useRef(t);g.current=t,c.useEffect(()=>(b.current=!0,()=>{b.current=!1,w.current+=1}),[]);const v=c.useCallback(async()=>{const y=t,p=++w.current,R=()=>b.current&&p===w.current&&g.current===y;
22if(f(y),r(null),a(!1),i(null),d(!!y),h(null),!y){R()&&d(!1);return}try{const{data:N,error:F}=await U.from("goal_predictions").select(an).eq("user_id",y).order("predicted_at",{ascending:!1}).limit(1).maybeSingle();if(!R())return;if(F){Re.warn("goal_predictions read failed",F),h(F.message);return}N?(r(N),a(!1),i(null)):(r(null),a(!0),i(null))}catch(N){R()&&h(N instanceof Error?N.message:"Erreur inattendue")}finally{R()&&d(!1)}},[t]);c.useEffect(()=>{v()},[v]),nt({table:"goal_predictions",userId:t,events:["INSERT"],onAny:()=>{v()}});const m=x===t;return{prediction:m?s:null,insufficientData:m?n:!1,insufficientDetails:m?o:null,loading:l||!m,error:m?u:null,refetch:v}}const on=t=>typeof t=="number"&&Number.isFinite(t)&&t>0;function Rs(t){const s=t[0],r=t.find(n=>on(n.estimated_body_fat_pct));return{value:r?r.estimated_body_fat_pct:null,scannedAt:r?.scanned_at??null,onLatestScan:!!(s&&r&&s===r)}}function as(t){return t==null?"—":t.toLocaleString("fr-FR",{minimumFractionDigits:1,maximumFractionDigits:1})}function ln(t,s){return!s||t.onLatestScan?null:t.value==null?"Pas encore mesurée":"Non mesurée sur le dernier scan"}function Es(t,s=90){const{profile:r}=at(),n=Ss(t,r?.timezone,s),a=c.useMemo(()=>n.data.flatMap(o=>{const i=o.body;return!i||typeof i.metrics.weight_kg!="number"?[]:[{logged_at:i.observed_at,weight_kg:i.metrics.weight_kg,body_fat_pct:i.metrics.body_fat_percent??null,lean_mass_kg:i.metrics.lean_mass_kg??null,muscle_mass_kg:i.metrics.muscle_mass_kg??null,water_pct:i.metrics.water_percent??null,bone_mass_kg:i.metrics.bone_mass_kg??null,fat_mass_kg:i.metrics.fat_mass_kg??null,source:i.source}]}),[n.data]);return{data:a,latest:a[a.length-1]??null,loading:n.loading,error:n.error,refetch:n.refresh}}function cn(t){const s=typeof t.date_of_birth=="string"?Date.parse(t.date_of_birth):NaN;return["avoid_weight_language","avoid_calorie_display","eating_disorder_history","pregnancy_breastfeeding"].some(r=>t[r]===!0)||["pregnant","postpartum"].includes(String(t.pregnancy_status))||["exclusive","mixed"].includes(String(t.breastfeeding_status))||Number.isFinite(s)&&Date.now()-s<18*365.25*864e5}const ns=t=>({scopeKey:t,draft:void 0,automatic:null,saving:!1,error:null,savedNotice:!1}),is=(t,s)=>t?.volume===s?.volume&&t?.definition===s?.definition;function dn({scopeKey:t,saved:s,onSave:r,onReturnToToday:n,atToday:a}){const[o,i]=c.useState(()=>ns(t)),l=o.scopeKey===t?o:ns(t);o.scopeKey!==t&&i(l);const d=c.useRef(t);d.current=t;const u=c.useRef(null),h=l.draft===void 0?s:l.draft,x=h??l.automatic,f=!is(h,s),b=c.useCallback(m=>{if(!a||h!==null||d.current!==t)return;const y={version:"muscle_appearance_v1",volume:m.applied.BodyBodybuilderSize??0,definition:m.applied.BodyBodybuilderDetails??0};i(p=>p.scopeKey!==t||is(p.automatic,y)?p:{...p,automatic:y})},[a,h,t]),w=m=>{l.saving||(n(),i(y=>({...y,draft:m,error:null,savedNotice:!1})))},g=()=>{l.saving||(n(),i(m=>({...m,draft:void 0,error:null,savedNotice:!1})))},v=async()=>{if(!(!f||u.current===t)){u.current=t,i(m=>({...m,saving:!0,error:null}));try{await r(h),d.current===t&&i(m=>({...m,draft:void 0,saving:!1,savedNotice:!0}))}catch{d.current===t&&i(m=>({...m,saving:!1,error:"La sauvegarde a échoué. Tes réglages restent visibles ; réessaie."}))}finally{u.current===t&&(u.current=null)}}};return{appearance:h,values:x,automatic:l.automatic,dirty:f,saving:l.saving,error:l.error,savedNotice:l.savedNotice,observe:b,change:w,cancel:g,save:v}}const pt="#3B82F6",os="#2ECC71",Oe="#F5A623",gt="#06B6D4",un={"#2ECC71":"zoneGlowGood","#F5A623":"zoneGlowMid","#E74C3C":"zoneGlowLow"};function mn(t,s){const r=I+s.legOffset,n=I-s.legOffset,a=I+s.shoulderHW-3,o=I-s.shoulderHW+3,i=t.editedFields,l=[{label:"Cou",field:"neck",value:t.neck,dotX:I+s.neckHW,dotY:74,labelY:74,side:"right",color:pt,edited:i?.has("neck")},{label:"Épaules",field:"shoulders",value:t.shoulders,dotX:I-s.shoulderHW,dotY:95,labelY:95,side:"left",color:pt,edited:i?.has("shoulders")},{label:"Poitrine",field:"chest",value:t.chest,dotX:I+s.chestHW,dotY:130,labelY:130,side:"right",color:pt,edited:i?.has("chest")},{label:"Biceps G",field:"bicepLeft",value:t.bicepLeft,dotX:o-s.bicepLHW,dotY:132,labelY:132,side:"left",color:gt,edited:i?.has("bicepLeft")},{label:"Biceps D",field:"bicepRight",value:t.bicepRight,dotX:a+s.bicepRHW,dotY:132,labelY:132,side:"right",color:gt,edited:i?.has("bicepRight")},{label:"Avant-bras",field:"forearm",value:t.forearm,dotX:o-s.forearmHW,dotY:175,labelY:175,side:"left",color:gt,edited:i?.has("forearm")},{label:"Taille",field:"waist",value:t.waist,dotX:I+s.waistHW,dotY:178,labelY:178,side:"right",color:os,edited:i?.has("waist")}
22,{label:"Hanches",field:"hips",value:t.hips,dotX:I-s.hipHW,dotY:210,labelY:210,side:"left",color:os,edited:i?.has("hips")},{label:"Cuisse G",field:"thighLeft",value:t.thighLeft,dotX:n-s.thighLHW,dotY:282,labelY:282,side:"left",color:Oe,edited:i?.has("thighLeft")},{label:"Cuisse D",field:"thighRight",value:t.thighRight,dotX:r+s.thighRHW,dotY:282,labelY:282,side:"right",color:Oe,edited:i?.has("thighRight")},{label:"Mollet G",field:"calfLeft",value:t.calfLeft,dotX:n-s.calfLHW,dotY:356,labelY:356,side:"left",color:Oe,edited:i?.has("calfLeft")},{label:"Mollet D",field:"calfRight",value:t.calfRight,dotX:r+s.calfRHW,dotY:356,labelY:356,side:"right",color:Oe,edited:i?.has("calfRight")}];return hn(l.filter(d=>d.value!=null))}function hn(t){const r=t.map(n=>({...n}));for(const n of["left","right"]){const a=r.filter(o=>o.side===n).sort((o,i)=>o.dotY-i.dotY);for(let o=1;o<a.length;o++){const i=a[o-1],l=a[o];l.labelY-i.labelY<26&&(l.labelY=i.labelY+26)}}return r}const xn="M11.4 1.6a1.3 1.3 0 0 1 1.8 0l1.2 1.2a1.3 1.3 0 0 1 0 1.8L5.2 14H2v-3.2L11.4 1.6Z";function fn({point:t,editable:s,editing:r,onStartEdit:n,onChangeValue:a,onStopEdit:o}){const i=t.side==="left",l=i?8:292,d=i?46:254,u=i?"start":"end",h=r===t.field,x=48,f=18,b=i?l:l-x,w=t.labelY-2,g=t.edited?"#FFFFFF":t.color;return e.jsxs("g",{style:{cursor:s?"pointer":"default"},onClick:s&&!h?()=>n(t.field):void 0,children:[e.jsx("line",{x1:t.dotX,y1:t.dotY,x2:d,y2:t.labelY,stroke:t.color,strokeWidth:"0.5",strokeDasharray:"3,2",opacity:"0.5"}),e.jsx("circle",{cx:t.dotX,cy:t.dotY,r:"3.5",fill:t.color,opacity:"0.9"}),e.jsx("circle",{cx:t.dotX,cy:t.dotY,r:"6",fill:"none",stroke:t.color,strokeWidth:"0.5",opacity:"0.3"}),e.jsx("text",{x:l,y:t.labelY-5,textAnchor:u,className:"fill-[#6B7280] font-sans text-[8px]",children:t.label}),h?e.jsx("foreignObject",{x:b,y:w,width:x+24,height:f+4,children:e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx("input",{type:"text",inputMode:"decimal",autoFocus:!0,defaultValue:t.value??"",onBlur:v=>{const m=parseFloat(v.currentTarget.value);!isNaN(m)&&m>0&&a(t.field,m),o()},onKeyDown:v=>{if(v.key==="Enter"){const m=parseFloat(v.currentTarget.value);!isNaN(m)&&m>0&&a(t.field,m),o()}else v.key==="Escape"&&o()},style:{width:x,height:f,background:"rgba(30,30,40,0.9)",border:`1px solid ${t.color}`,borderRadius:4,color:t.color,fontSize:11,fontWeight:700,fontFamily:"Space Grotesk, sans-serif",padding:"0 4px",outline:"none",textAlign:i?"left":"right"}}),e.jsx("span",{className:"text-[9px] text-[#6B7280]",children:"cm"})]})}):e.jsxs("g",{children:[e.jsxs("text",{x:l,y:t.labelY+8,textAnchor:u,fill:g,className:"font-display text-[11px] font-bold",children:[t.value," cm"]}),s&&e.jsx("g",{transform:`translate(${i?l+42:l-50}, ${t.labelY-1})`,opacity:"0.45",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 16 16",children:e.jsx("path",{d:xn,fill:t.color})})})]})]})}function pn({mode:t,hasMuscle:s,hasFat:r,onChange:n}){const a=[{id:"measure",label:"Mensurations"},...s?[{id:"muscle",label:"Muscle"}]:[],...r?[{id:"fat",label:"Graisse"}]:[]];return a.length<2?null:e.jsx("div",{className:"flex justify-center mb-2",children:e.jsx("div",{className:"inline-flex gap-1 rounded-xl border border-white/10 bg-black/30 p-1",children:a.map(o=>e.jsx("button",{type:"button",onClick:()=>n(o.id),className:`px-3 py-1 rounded-lg text-xs font-medium transition-colors ${t===o.id?"bg-accent/20 text-accent":"text-text-tertiary hover:text-text-secondary"}`,children:o.label},o.id))})})}function gn(t){const[s,r]=c.useState(null),[n,a]=c.useState(t.initialView??"measure"),o=t.hideMeasurements?"measure":n,i=We(),l=t.gender==="female"?"female":"male",{chest:d,waist:u,hips:h,shoulders:x,neck:f,forearm:b,bicepLeft:w,bicepRight:g,thighLeft:v,thighRight:m,calfLeft:y,calfRight:p}=t,R=c.useMemo(()=>Ra({chest:d,waist:u,hips:h,shoulders:x,neck:f,forearm:b,bicepLeft:w,bicepRight:g,thighLeft:v,thighRight:m,calfLeft:y,calfRight:p},l),[d,u,h,x,f,b,w,g,v,m,y,p,l]),N=c.useMemo(()=>({torso:La(R,l),leftLeg:ts(R,"left"),rightLeg:ts(R,"right"),leftArm:ss(R,"left"),rightArm:ss(R,"right")}),[R,l]),F=mn(t,R),M=c.useMemo(()=>Oa(R,t.muscleAssessment),[R,t.muscleAssessment]),_=c.useMemo(()=>Ha(R,t.fatDistribution),[R,t.fatDistribution]),S=c.useMemo(()=>Wa({bicepLeft:w,bicepRight:g,thighLeft:v,thighRight:m,calfLeft:y,calfRight:p}),[w,g,v,m,y,p]);if(F.length===0)return null;
22const k=o==="muscle"?M:o==="fat"?_:null,L={fill:"url(#bodyFill)",strokeWidth:0},D={fill:"url(#bodyFill)",stroke:"url(#bodyStroke)",strokeWidth:1.1,strokeLinejoin:"round"},$=(C,H)=>{t.onMeasurementChange?.(C,H)},E=C=>{r(null),a(C)};return e.jsxs("div",{className:"relative w-full",children:[!t.hideMeasurements&&e.jsx(pn,{mode:o,hasMuscle:M.legend.length>0,hasFat:_.legend.length>0,onChange:E}),!t.hideMeasurements&&o==="measure"&&t.editable&&!t.hasEdits&&!s&&e.jsx("div",{className:"text-center mb-1",children:e.jsxs("span",{className:"text-xs text-text-tertiary inline-flex items-center gap-1.5",children:[e.jsx(Rr,{size:10,className:"opacity-60"}),"Appuie sur une valeur pour la modifier"]})}),e.jsxs("svg",{viewBox:"0 0 300 450",className:"h-auto max-h-[480px] w-full",children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"bodyFill",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(59,130,246,0.13)"}),e.jsx("stop",{offset:"40%",stopColor:"rgba(6,182,212,0.09)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(245,166,35,0.08)"})]}),e.jsxs("linearGradient",{id:"bodyStroke",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(96,165,250,0.85)"}),e.jsx("stop",{offset:"50%",stopColor:"rgba(34,211,238,0.75)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(245,166,35,0.7)"})]}),e.jsxs("linearGradient",{id:"scanLineGrad",x1:"0",y1:"0",x2:"1",y2:"0",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(6,182,212,0)"}),e.jsx("stop",{offset:"50%",stopColor:"rgba(6,182,212,0.85)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(6,182,212,0)"})]}),e.jsxs("filter",{id:"holoGlow",x:"-30%",y:"-30%",width:"160%",height:"160%",children:[e.jsx("feGaussianBlur",{stdDeviation:"2.4",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]}),e.jsx("pattern",{id:"holoGrid",width:"26",height:"26",patternUnits:"userSpaceOnUse",children:e.jsx("path",{d:"M26 0 H0 V26",fill:"none",stroke:"rgba(96,140,220,0.10)",strokeWidth:"1"})}),e.jsxs("radialGradient",{id:"gridFade",cx:"50%",cy:"45%",r:"65%",children:[e.jsx("stop",{offset:"55%",stopColor:"#FFFFFF"}),e.jsx("stop",{offset:"100%",stopColor:"#000000"})]}),e.jsx("mask",{id:"gridMask",children:e.jsx("rect",{width:"300",height:"450",fill:"url(#gridFade)"})}),e.jsxs("radialGradient",{id:"zoneGlowGood",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(46,204,113,0.7)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(46,204,113,0)"})]}),e.jsxs("radialGradient",{id:"zoneGlowMid",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(245,166,35,0.65)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(245,166,35,0)"})]}),e.jsxs("radialGradient",{id:"zoneGlowLow",children:[e.jsx("stop",{offset:"0%",stopColor:"rgba(231,76,60,0.6)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(231,76,60,0)"})]}),e.jsx("clipPath",{id:"legClip",children:e.jsx("rect",{x:"0",y:"252",width:"300",height:"200"})})]}),e.jsx("rect",{width:"300",height:"450",fill:"url(#holoGrid)",mask:"url(#gridMask)"}),e.jsxs("g",{filter:"url(#holoGlow)",children:[e.jsx("path",{d:Ea,...D}),e.jsx("path",{d:N.leftArm,...L}),e.jsx("path",{d:N.rightArm,...L}),e.jsx("path",{d:N.torso,...D}),e.jsx("path",{d:N.leftLeg,...L}),e.jsx("path",{d:N.rightLeg,...L}),e.jsx("path",{d:N.leftLeg,fill:"none",stroke:"url(#bodyStroke)",strokeWidth:"0.7",strokeLinejoin:"round",clipPath:"url(#legClip)"}),e.jsx("path",{d:N.rightLeg,fill:"none",stroke:"url(#bodyStroke)",strokeWidth:"0.7",strokeLinejoin:"round",clipPath:"url(#legClip)"})]}),k&&e.jsx("g",{className:"mix-blend-screen",children:k.blobs.map((C,H)=>e.jsx("circle",{cx:C.cx,cy:C.cy,r:C.r,fill:`url(#${un[C.color]??"zoneGlowMid"})`},H))}),!i&&e.jsx(K.rect,{x:18,width:264,height:2,fill:"url(#scanLineGrad)",initial:{y:20,opacity:0},animate:{y:[20,432,20],opacity:.9},transition:{y:{duration:7.2,repeat:1/0,ease:"easeInOut"},opacity:{duration:.8}}}),!t.hideMeasurements&&o==="measure"&&F.map(C=>e.jsx(fn,{point:C,editable:t.editable,editing:s,onStartEdit:r,onChangeValue:$,onStopEdit:()=>r(null)},C.label))]}),k&&k.legend.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap justify-center gap-x-4 gap-y-1.5 px-1",children:k.legend.map(C=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-text-secondary",children:[e.jsx("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:C.color}}),C.label,e.jsx("span",{style:{color:C.color},children:C.levelLabel})]},C.key))}),o==="muscle"&&S.length>0&&e.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:S.map(C=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg px-3 py-2 text-xs",style:{background:"rgba(245,166,35,0.08)",border:"1px solid rgba(245,166,35,0.25)",color:Oe},children:["⚠️ Asymétrie ",C.label," G/D · Δ ",String(C.deltaCm).replace(".",",")," cm"]},C.label))}),e.jsx(je,{children:!t.hideMeasurements&&t.editable&&t.hasEdits&&t.onSave&&e.jsx(K.div,{className:"mt-2 px-4",initial:{opacity:0,y:8}
22,animate:{opacity:1,y:0},exit:{opacity:0,y:8},transition:{duration:.2},children:e.jsx(we,{variant:"primary",size:"sm",fullWidth:!0,loading:t.saving,onClick:t.onSave,children:"Enregistrer les modifications"})})})]})}const bn=["neck","shoulders","chest","waist","hips","bicepL","bicepR","forearm","thighL","thighR","calfL","calfR"],yn=new Intl.DateTimeFormat("fr-FR",{day:"numeric",month:"short",year:"numeric"});function ls(t){return yn.format(t).replace(".","")}const te=t=>typeof t=="number"&&Number.isFinite(t)&&t>0?t:null;function jn(t){return{neck:te(t.neck_cm)??void 0,shoulders:te(t.shoulder_cm)??void 0,chest:te(t.chest_cm)??void 0,waist:te(t.waist_cm)??te(t.estimated_waist_cm)??void 0,hips:te(t.hips_cm)??void 0,bicepL:te(t.bicep_left_cm)??void 0,bicepR:te(t.bicep_right_cm)??void 0,forearm:te(t.forearm_cm)??void 0,thighL:te(t.thigh_left_cm)??void 0,thighR:te(t.thigh_right_cm)??void 0,calfL:te(t.calf_left_cm)??void 0,calfR:te(t.calf_right_cm)??void 0}}function cs(t,s){return t==null||s==null?null:+(t*(1-s/100)).toFixed(1)}function _n({scans:t,targetDate:s,targetWeightKg:r,targetBodyFatPct:n,now:a=new Date}){const o=t.filter(g=>g.scanned_at&&!Number.isNaN(Date.parse(g.scanned_at))).map(g=>({scan:g,date:new Date(g.scanned_at)})).sort((g,v)=>g.date.getTime()-v.date.getTime());if(o.length===0)return{points:[],uToday:0,todayDate:a,hasPast:!1,hasFuture:!1,targetDate:null,firstScanDate:null};const i=o[0].date,l=o[o.length-1].date,d=a>l?a:l,u=!!(s&&s.getTime()>d.getTime()),x=(u?s:d).getTime()-i.getTime(),f=g=>x<=0?0:Math.min(1,Math.max(0,(g.getTime()-i.getTime())/x)),b=f(d),w=o.map(({scan:g,date:v},m)=>{const y=te(g.weight_kg),p=te(g.estimated_body_fat_pct);return{u:f(v),label:m===o.length-1?"aujourd'hui":ls(v),date:v,weightKg:y,bodyFatPct:p,leanKg:cs(y,p),measured:!0,measurements:jn(g)}});if(u&&s){const g=w[w.length-1],v=r??g.weightKg,m=n??g.bodyFatPct;w.push({u:1,label:ls(s),date:s,weightKg:v,bodyFatPct:m,leanKg:cs(v,m),measured:!1,measurements:g.measurements})}return{points:w,uToday:b,todayDate:d,hasPast:o.length>1&&l.getTime()-i.getTime()>0,hasFuture:u,targetDate:u?s:null,firstScanDate:i}}function vn(t,s){let r=-1;for(let a=0;a<t.points.length;a+=1)t.points[a].measured&&(r=a);if(r<0)return t;const n={...t.points[r].measurements};for(const a of bn){const o=s[a];typeof o=="number"&&Number.isFinite(o)&&o>0&&(n[a]=o)}return{...t,points:t.points.map((a,o)=>o===r||!a.measured&&a.u>=t.uToday?{...a,measurements:{...n}}:a)}}const Ze=(t,s,r)=>t==null||s==null?t??s:t+(s-t)*r;function Ft(t,s){const r=t.points;if(r.length===0)return null;const n=Math.min(1,Math.max(0,s));if(r.length===1){const f=r[0];return{u:n,phase:"présent",weightKg:f.weightKg,bodyFatPct:f.bodyFatPct,leanKg:f.leanKg,measurements:f.measurements,dateLabel:f.label,onMilestone:!0}}let a=r[0],o=r[r.length-1];if(n<=a.u)o=a;else if(n>=o.u)a=o;else for(let f=0;f<r.length-1;f+=1)if(n>=r[f].u&&n<=r[f+1].u){a=r[f],o=r[f+1];break}const i=o.u===a.u?0:(n-a.u)/(o.u-a.u),l=i<.5?a:o,d=i<.06||i>.94,u=n<t.uToday-1e-6?"passé":n<=t.uToday+1e-6?"présent":"projeté",h={},x=new Set([...Object.keys(a.measurements),...Object.keys(o.measurements)]);for(const f of x){const b=Ze(a.measurements[f]??null,o.measurements[f]??null,i);b!=null&&(h[f]=b)}return{u:n,phase:u,weightKg:Ze(a.weightKg,o.weightKg,i),bodyFatPct:Ze(a.bodyFatPct,o.bodyFatPct,i),leanKg:Ze(a.leanKg,o.leanKg,i),measurements:h,dateLabel:d?l.label:`vers ${l.label}`,onMilestone:d}}function wn(t,s){if(!t.hasFuture||!t.targetDate||t.uToday>=1)return 0;const r=Math.max(0,(s-t.uToday)/(1-t.uToday)),n=(t.targetDate.getTime()-t.todayDate.getTime())/(1e3*60*60*24*30.44);return r*Math.max(0,n)}const io={passé:{label:"scan réel",color:"#2ECC71",border:"rgba(46,204,113,0.35)",background:"rgba(46,204,113,0.10)"},présent:{label:"mesuré",color:"#2ECC71",border:"rgba(46,204,113,0.35)",background:"rgba(46,204,113,0.10)"},projeté:{label:"projeté",color:"#60A5FA",border:"rgba(96,165,250,0.4)",background:"rgba(96,165,250,0.12)"}};function oo(t){return typeof t=="number"&&Number.isFinite(t)?t.toFixed(1).replace(".",","):"—"}function ds(t){return typeof t!="number"||!Number.isFinite(t)||Math.abs(t)<.05?"—":`${t>0?"+":""}${t.toFixed(1).replace(".",",")}`}function Nn(t){if(!t)return null;const s=t.factors??null,r=t.current_rate_kg_per_week;return!s&&(r==null||!Number.isFinite(r))?null:{rateKgPerWeek:Number.isFinite(r)?r:null,factors:s?{nutrition:s.nutrition,training:s.training,activity:s.activity,sleep:s.sleep,compliance:s.compliance}:void 0,confidence:t.confidence_score??null,completeness:t.data_completeness??null}}function kn(t,s,r,n){const a=(t.scenarios??[]).filter(i=>!i.indisponible&&i.horizons?.length);if(!a.length)return null;if(r==null&&n==null)return{key:(a.find(l=>l.k==="actuel")??a[0]).k,gapKg:0,outOfReach:!1};let o=null;for(const i of a){const l=i.horizons.reduce((x,f)=>
22Math.abs(f.months-s)<Math.abs(x.months-s)?f:x),d=r!=null?Math.abs(l.weightKg-r):0,u=n!=null?Math.abs(l.bfPct-n)*.7:0,h=d+u;(!o||h<o.gapKg)&&(o={key:i.k,gapKg:h,outOfReach:!1})}return o?{...o,outOfReach:o.gapKg>4}:null}async function Sn(t,s,r,n,a){const i=(await kt(()=>import("./morph-solver-CwnUfQeC.js"),[])).projectBody({sex:t.sex,heightCm:t.heightCm,weightKg:t.weightKg,bfPct:t.bodyFatPct,leanKg:t.weightKg*(1-t.bodyFatPct/100),vals:t.vals},s,{});return kn(i,r,n,a)}function Mn(t,s,r,n){return`${t??"anonymous"}:${s??"no-scan"}:${r??"unresolved"}:${Ir(n)}`}function Ls(t,s){t.scopeKey!==s&&(t.scopeKey=s,t.requestId+=1)}function Cn(t,s){return Ls(t,s),t.requestId+=1,{scopeKey:t.scopeKey,requestId:t.requestId}}function Fn(t,s){return t.scopeKey===s.scopeKey&&t.requestId===s.requestId}function lo(t,s){return t==="ready"&&s}function co(t){t?.seek(0)}function Rn(t,s,r){s(t),r?.seekToToday()}const En=100;function Ln(t,s){return typeof s!="number"||!Number.isFinite(s)||s<1||typeof t!="number"||!Number.isFinite(t)?null:Math.round(Math.min(En,Math.max(0,t)))}function Dn(t){return t>=70?"haute":t>=40?"moyenne":"faible"}const uo={optimiste:"#2ECC71",réaliste:"#F5A623",prudent:"#9CA3AF"},mo={optimiste:"Optimiste",réaliste:"Réaliste",prudent:"Prudent"};function bt(t){if(!t)return null;const s=/^\d{4}-\d{2}-\d{2}$/.test(t),r=new Date(s?`${t}T12:00:00Z`:t);return Number.isNaN(r.getTime())?null:r}function Tn(t){return[{key:"optimiste",date:bt(t?.projected_date_optimistic)},{key:"réaliste",date:bt(t?.projected_date_realistic)},{key:"prudent",date:bt(t?.projected_date_pessimistic)}]}const Pn=new Intl.DateTimeFormat("fr-FR",{day:"numeric",month:"long",year:"numeric"}),ho=new Intl.DateTimeFormat("fr-FR",{month:"short"});function $n(t,s){const r=Ln(t,s);if(r===null)return null;const n=Dn(r);return{text:n,className:n==="haute"?"text-success":n==="moyenne"?"text-accent":"text-text-secondary"}}function An(t){return t==null?"Points de données non renseignés":`${t} point${t>1?"s":""} de données`}const Bn={haute:"success",moyenne:"accent"},us="Ton twin 3D";function On({prediction:t,loading:s,error:r,insufficientData:n,qualitative:a,unavailableReason:o=null,onRetry:i}){const l=Tn(t).find(u=>u.key==="réaliste")?.date??null;if(s)return e.jsx(Js,{announce:!0});if(r)return e.jsxs("div",{"data-projection-banner":!0,className:"px-4 pb-3 pt-3.5",role:"alert",children:[e.jsx("h2",{className:"text-sm font-medium text-text-primary",children:"Projection corporelle indisponible"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-text-secondary",children:"Impossible de relire ta dernière projection pour le moment."}),e.jsx(Qs,{onRetry:i,className:"mt-3"})]});if(a)return e.jsx("div",{"data-projection-banner":!0,children:e.jsx(Kt,{level:3,title:us,subtitle:"Ta trajectoire se lit autrement : Alloy suit tes sensations, tes habitudes et tes séances, sans date ni poids."})});if(n||!l)return e.jsx("div",{"data-projection-banner":!0,children:e.jsx(Kt,{level:3,title:us,subtitle:o??"Tes prochains scans et suivis permettront à Alloy d’estimer une trajectoire."})});const d=$n(t?.confidence_score,t?.data_points_used);return e.jsxs("div",{"data-projection-banner":!0,className:"px-4 pb-3 pt-3.5",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.13em] text-accent",children:"Objectif · scénario réaliste"}),e.jsx("h2",{className:"mt-1.5 font-display text-2xl font-bold leading-tight tracking-[-0.02em] text-text-primary",children:Pn.format(l)}
22),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5","data-projection-badges":!0,children:[d&&e.jsxs(ht,{size:"md",tone:Bn[d.text]??"neutral",children:["Confiance ",d.text]}),e.jsx(ht,{size:"md",children:An(t?.data_points_used)}),e.jsx(ht,{size:"md",icon:er,children:"Chaque semaine"})]})]})}const Hn=.5,ms=t=>({scopeKey:t,target:null,drafts:{},saving:!1,error:null});function In({scopeKey:t,saved:s,onSave:r,onReturnToToday:n}){const[a,o]=c.useState(()=>ms(t)),i=a.scopeKey===t?a:ms(t);a.scopeKey!==t&&o(i);const l=c.useRef(t);l.current=t;const{target:d,drafts:u,saving:h,error:x}=i,f=c.useMemo(()=>d?d.rows.filter(N=>{const F=u[N.saveKey];return F!=null&&!(Number.isFinite(F)&&F>=N.min&&F<=N.max)}):[],[d,u]),b=c.useMemo(()=>{if(!d)return s;const N={...s};let F=!1;for(const M of d.rows){const _=u[M.saveKey];_==null||!Number.isFinite(_)||_<M.min||_>M.max||_!==s[M.field]&&(N[M.field]=_,F=!0)}return F?N:s},[d,u,s]),w=b!==s,g=d!=null&&f.length===0&&d.rows.some(N=>u[N.saveKey]!=null),v=c.useCallback(N=>{!N||i.saving||(n(),o(F=>({...F,target:N,error:null,drafts:Object.fromEntries(N.rows.map(M=>[M.saveKey,s[M.field]??null]))})))},[n,s,i.saving]),m=c.useCallback(()=>{o(N=>N.saving?N:{...N,target:null,drafts:{},error:null})},[]),y=c.useCallback((N,F)=>{o(M=>M.saving?M:{...M,drafts:{...M.drafts,[N.saveKey]:F}})},[]),p=c.useCallback((N,F)=>{o(M=>{if(M.saving)return M;const _=M.drafts[N.saveKey];if(_==null)return M;const S=Math.min(N.max,Math.max(N.min,+(_+F).toFixed(1)));return{...M,drafts:{...M.drafts,[N.saveKey]:S}}})},[]),R=c.useCallback(async()=>{if(!d||!g||i.saving)return;const N=d.rows.filter(M=>{const _=u[M.saveKey];return _!=null&&_!==s[M.field]});if(N.length===0){m();return}o(M=>({...M,saving:!0,error:null}));const F=t;for(const M of N){const _=await r(M.saveKey,u[M.saveKey]);if(l.current!==F)return;if(!_){o(S=>({...S,saving:!1,error:"L’enregistrement a échoué. Ta saisie reste là ; réessaie."}));return}}l.current===F&&o(M=>({...M,target:null,drafts:{},saving:!1,error:null}))},[d,g,i.saving,u,s,r,m,t]);return{target:d,drafts:u,preview:b,dirty:w,savable:g,saving:h,error:x,invalidRows:f,open:v,close:m,set:y,nudge:p,save:R,step:Hn}}function Wn(t,s,r,n){if(r)return"Projeté";if(n)return"Mesuré";const a=t.points.filter(d=>d.measured&&d.bodyFatPct!=null),o=a.filter(d=>d.u<s-1e-6),i=a.filter(d=>d.u>s+1e-6);if(o.length>0&&i.length>0)return"Estimé entre deux jalons";const l=o[o.length-1];return l?`Dernière mesure : ${l.label}`:"Estimé"}const Fe=268,He=62;function Je(t,s,r,n,a,o){const l=[];for(let d=0;d<=34;d+=1){const u=a+(o-a)*(d/34),h=Ft(t,u),x=h?s(h):null;x!=null&&l.push(`${(u*Fe).toFixed(1)},${(He-(x-r)/(n-r)*He).toFixed(1)}`)}return l.length>1?`M${l.join(" L")}`:""}function Gn({model:t,u:s,qualitative:r}){const n=c.useMemo(()=>Ft(t,s),[t,s]),a=t.points[0]??null,o=c.useMemo(()=>n?.bodyFatPct!=null?100-n.bodyFatPct:null,[n]),i=a?.bodyFatPct!=null?100-a.bodyFatPct:null;if(r||!n||n.bodyFatPct==null)return null;const l=t.hasFuture?1:t.uToday,d=t.points.map(p=>p.bodyFatPct!=null?100-p.bodyFatPct:null),u=t.points.map(p=>p.bodyFatPct),h=(p,R)=>{const N=p.filter(_=>_!=null);if(!N.length)return[0,1];const F=Math.min(...N)-R,M=Math.max(...N)+R;return[F,M===F?F+1:M]},[x,f]=h(d,1.5),[b,w]=h(u,1.5),g=p=>p.leanKg&&p.weightKg?p.leanKg/p.weightKg*100:null,v=p=>p.bodyFatPct,m=a?`depuis ${a.label}`:"",y=t.points.some(p=>p.measured&&Math.abs(p.u-n.u)<1e-6);return e.jsxs(G,{animated:!1,"data-body-composition":!0,children:[e.jsx(ne,{className:"mb-2",eyebrow:"Composition corporelle",title:"Masse maigre contre gras",action:e.jsxs("span",{className:"inline-flex items-center gap-2.5",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-text-secondary",children:[e.jsx("span",{className:"h-[2px] w-2 rounded-full bg-[#2ECC71]"}),"maigre"]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs text-text-secondary",children:[e.jsx("span",{className:"h-[2px] w-2 rounded-full bg-[#FF6B35]"}),"gras"]})]})}),e.jsxs("p",{className:"mb-3 text-xs leading-relaxed text-text-secondary","data-composition-date":!0,children:[n.dateLabel," ·"," ",Wn(t,n.u,n.phase==="projeté",y)]}),e.jsx("p",{className:"mb-3 text-xs leading-relaxed text-text-secondary",children:"La masse maigre comprend les muscles, mais aussi les os, les organes et l’eau."}),e.jsxs("div",{className:"mb-3 flex gap-2",children:[e.jsxs("div",{className:"flex-1 rounded-[14px] border border-[#2ECC71]/20 bg-[#2ECC71]/[0.08] px-2.5 py-2.5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.08em] text-[#2ECC71]",children:"Masse maigre"}),e.jsxs("div",{className:"mt-1",children:[e.jsx("span",{className:"font-display text-[22px] font-bold text-text-primary",children:o!=null?o.toFixed(1).replace(".",","):"—"}),e.jsx("span",{className:"text-xs text-text-secondary",children:" %"})]}),e.jsx("div",{className:"font-display text-xs text-text-secondary",children:o!=null&&i!=null?`${ds(o-i)} ${m}`:m})]}),e.jsxs("div",{className:"flex-1 rounded-[14px] border border-[#FF6B35]/20 bg-[#FF6B35]/[0.08] px-2.5 py-2.5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.08em] text-[#FF6B35]",children:"Masse grasse"}),e.jsxs("div",{className:"mt-1",children:[e.jsx("span",{className:"font-display text-[22px] font-bold text-text-primary",children:n.bodyFatPct.toFixed(1).replace(".",",")}),e.jsx("span",{className:"text-xs text-text-secondary",children:" %"})]}),e.jsx("div",{className:"font-display text-xs text-text-secondary",children:a?.bodyFatPct!=null?`${ds(n.bodyFatPct-a.bodyFatPct)} ${m}`:m})]})]}),e.jsxs("svg",{viewBox:`0 0 ${Fe} ${He}`,width:"100%",height:82,className:"block overflow-visible","aria-hidden":"true",children:[e.jsx("line",{x1:(t.uToday*Fe).toFixed(1),y1:0,x2:(t.uToday*Fe).toFixed(1),y2:He,stroke:"rgba(245,166,35,0.45)",strokeWidth:1,strokeDasharray:"2 3"}),e.jsx("path",{d:Je(t,g,x,f,0,t.uToday),fill:"none",stroke:"#2ECC71",strokeWidth:2.2,strokeLinecap:"round"}),e.jsx("path",{d:Je(t,g,x,f,t.uToday,l),fill:"none",stroke:"#2ECC71",strokeWidth:2.2,strokeDasharray:"3 3",opacity:.75,strokeLinecap:"round"}),e.jsx("path",{d:Je(t,v,b,w,0,t.uToday),fill:"none",stroke:"#FF6B35",
22strokeWidth:2.2,strokeLinecap:"round"}),e.jsx("path",{d:Je(t,v,b,w,t.uToday,l),fill:"none",stroke:"#FF6B35",strokeWidth:2.2,strokeDasharray:"3 3",opacity:.75,strokeLinecap:"round"}),e.jsx("line",{x1:(s*Fe).toFixed(1),y1:-6,x2:(s*Fe).toFixed(1),y2:He+4,stroke:"#E5E7EB",strokeWidth:1,opacity:.55})]}),e.jsxs("div",{className:"mt-1 flex justify-between font-display text-xs",children:[e.jsx("span",{className:"text-text-tertiary",children:t.points[0]?.label??""}),e.jsx("span",{className:"text-accent",children:"auj."}),e.jsx("span",{className:"text-[#60A5FA]",children:t.hasFuture?t.points[t.points.length-1]?.label:""})]})]})}function Qe({label:t,actual:s,planned:r,color:n}){const a=r>0?Math.min(s/r*100,150):0,o=r>0?Math.round(s/r*100):0;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:t}),e.jsxs("span",{className:"text-xs text-text-tertiary",children:[s," / ",r," ",e.jsxs("span",{className:"text-text-tertiary/60",children:["(",o,"%)"]})]})]}),e.jsxs("div",{className:"h-2 bg-surface-solid rounded-full overflow-hidden relative",children:[e.jsx("div",{className:"absolute top-0 left-0 h-full rounded-full opacity-20",style:{width:"100%",backgroundColor:n}}),e.jsx(K.div,{className:"h-full rounded-full relative z-10",style:{backgroundColor:n},initial:{width:0},animate:{width:`${Math.min(a,100)}%`},transition:{duration:.8,ease:"easeOut"}})]})]})}function Un({days:t}){const s=t.slice(-7);return s.length===0?null:e.jsx("div",{className:"flex items-end gap-1 h-8",children:s.map((r,n)=>{const a=r.plan_vs_actual?.adherence_pct??0,o=Math.max(a*.8,4),i=a>=80?"#10B981":a>=50?"#F5A623":"#EF4444";return e.jsx(K.div,{className:"flex-1 rounded-sm",style:{backgroundColor:i,minHeight:4},initial:{height:0},animate:{height:o},transition:{duration:.5,delay:n*.05},title:`${r.recap_date}: ${a}%`},r.recap_date||n)})})}function Yn({recaps:t}){const s=t.filter(i=>i.plan_vs_actual);if(s.length===0)return null;const r=s[0],n=r.plan_vs_actual,a=n.adherence_pct,o=a>=80?"text-success":a>=50?"text-warning":"text-error";return e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-4",reserveHelp:!0,eyebrow:"Nutrition",title:"Plan contre réalisé",action:e.jsxs("div",{className:`text-lg font-bold ${o}`,children:[a,"%"]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Qe,{label:"Calories",actual:r.calories_in,planned:n.planned_calories,color:"#F5A623"}),e.jsx(Qe,{label:"Proteines",actual:r.proteins_g??0,planned:n.planned_proteins_g,color:"#10B981"}),e.jsx(Qe,{label:"Glucides",actual:r.carbs_g??0,planned:n.planned_carbs_g,color:"#F59E0B"}),e.jsx(Qe,{label:"Lipides",actual:r.fats_g??0,planned:n.planned_fats_g,color:"#EF4444"})]}),s.length>1&&e.jsxs("div",{className:"mt-4 pt-3 border-t border-border",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("span",{className:"text-xs text-text-tertiary flex items-center gap-1",children:[e.jsx(vs,{className:"w-3 h-3"}),"Adherence 7 derniers jours"]})}),e.jsx(Un,{days:s.slice(0,7).reverse()})]})]})}const hs={rank_promotion:{icon:ws,color:"#F5A623"},personal_record:{icon:rr,color:"#FFCC02"},streak_milestone:{icon:sr,color:"#FF6B35"},weight_milestone:{icon:Ne,color:"#2ECC71"},phase_change:{icon:fa,color:"#3B82F6"}},xs=["discovery","habit_building","autonomy","deepening","maintenance"];function zn(t){const s=Date.now()-new Date(t).getTime(),r=Math.floor(s/864e5);if(r===0)return"Aujourd'hui";if(r===1)return"Hier";if(r<7)return`Il y a ${r}j`;const n=Math.floor(r/7);return n===1?"Il y a 1 sem.":`Il y a ${n} sem.`}function qn(t){if(!t)return[];const s=xs.indexOf(t);return s===-1?[]:xs.slice(s+1,s+3).map(r=>{const n=ar(r);return{key:r,forgeName:n.forgeName,description:n.description}})}function Kn({timeline:t,comparisons:s,coachingPhase:r,level:n}){if(t.length===0&&s.length===0)return null;const a=qn(r),o=n!=null?tr(n):null;return e.jsxs(G,{padding:"md",className:"space-y-4",children:[e.jsx(ne,{reserveHelp:!0,eyebrow:"Progression",title:"Ton parcours"}),s.length>0&&e.jsx("div",{className:"grid grid-cols-1 gap-2",children:s.slice(0,3).map(i=>e.jsxs(K.div,{initial:{opacity:0,x:-10}
22,animate:{opacity:1,x:0},className:"flex items-center gap-3 rounded-xl bg-success/5 border border-success/10 px-3 py-2.5",children:[e.jsx(zr,{className:"w-3.5 h-3.5 text-success flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-text-primary truncate",children:i.label}),e.jsxs("p",{className:"text-xs text-text-tertiary",children:[i.previous.toLocaleString(),i.unit," → ",i.current.toLocaleString(),i.unit]})]}),e.jsxs("span",{className:"text-sm font-bold text-success whitespace-nowrap",children:["+",i.changePct,"%"]})]},i.metric))}),t.length>0&&e.jsxs("div",{className:"relative pl-4",children:[e.jsx("div",{className:"absolute left-[7px] top-2 bottom-2 w-px bg-border"}),e.jsx("div",{className:"space-y-3",children:t.slice(0,6).map((i,l)=>{const d=hs[i.type]||hs.personal_record,u=d.icon;return e.jsxs(K.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:l*.05},className:"relative flex items-start gap-3",children:[e.jsx("div",{className:"absolute -left-4 top-1 w-3.5 h-3.5 rounded-full bg-surface border-2 border-border z-10 flex items-center justify-center",children:e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-text-tertiary"})}),e.jsxs("div",{className:"flex-1 min-w-0 ml-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{className:"w-3.5 h-3.5 flex-shrink-0",style:{color:d.color}}),e.jsx("span",{className:"text-sm font-medium text-text-primary truncate",children:i.label}),e.jsx("span",{className:"text-[10px] text-text-tertiary ml-auto whitespace-nowrap",children:zn(i.date)})]}),e.jsx("p",{className:"text-xs text-text-secondary mt-0.5 line-clamp-1",children:i.description})]})]},i.id)})})]}),(a.length>0||o)&&e.jsxs("div",{className:"pt-2 border-t border-white/5",children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-text-tertiary mb-2.5",children:"Prochaines etapes"}),e.jsxs("div",{className:"space-y-2",children:[a.map((i,l)=>e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center flex-shrink-0 text-[9px] font-bold",style:{background:`rgba(245,166,35,${.12-l*.04})`,border:`1px solid rgba(245,166,35,${.2-l*.06})`,color:`rgba(245,166,35,${.8-l*.2})`},children:l+1}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"text-xs font-medium text-text-secondary",children:i.forgeName}),e.jsx("span",{className:"text-[10px] text-text-tertiary",children:i.description})]}),l<a.length-1&&e.jsx(qr,{className:"w-3 h-3 text-text-tertiary opacity-30 flex-shrink-0"})]},i.key)),o&&e.jsxs("div",{className:"flex items-center gap-2.5 mt-0.5",children:[e.jsx(ws,{className:"w-3.5 h-3.5 flex-shrink-0 opacity-40",style:{color:"#F5A623"}}),e.jsxs("span",{className:"text-xs text-text-tertiary",children:["Prochain rang :"," ",e.jsx("span",{className:"font-medium text-text-secondary",children:o.name}),e.jsxs("span",{className:"ml-1 text-[10px]",children:["(Nv. ",o.minLevel,")"]})]})]})]})]})]})}function Xn(t){return[{icon:vs,theme:"gold",value:t?.total_meals_scanned??0,label:"Repas"},{icon:Ns,theme:"ember",value:t?.total_trainings_completed??0,label:"Trainings"},{icon:Ie,theme:"aqua",value:t?.total_body_scans??0,label:"Body scans"},{icon:Kr,theme:"verdant",value:t?.total_fridge_scans??0,label:"Frigos"},{icon:Xr,theme:"rose",value:t?.total_recipes_generated??0,label:"Recettes"},{icon:Vr,theme:"gold",value:t?.total_meal_plans_generated??0,label:"Plans"},{icon:Zr,theme:"verdant",value:t?.total_shopping_lists_generated??0,label:"Courses"},{icon:St,theme:"ember",value:t?.total_activities_logged??0,label:"Activités"}]}function Vn({gamification:t,animationVariants:s}){const r=Xn(t),n=s?K.div:"div",a=s?{variants:s}:{};return e.jsx(n,{...a,children:e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-4",reserveHelp:!0,eyebrow:"Depuis le début",title:"Statistiques globales"}),e.jsx("div",{className:"grid grid-cols-4 gap-3",children:r.map((o,i)=>e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-1.5 w-fit",children:e.jsx(ge,{icon:o.icon,theme:o.theme,size:"sm"})}),e.jsx("div",{className:"text-base font-bold text-text-primary",children:o.value}),e.jsx("div",{className:"text-[10px] text-text-tertiary leading-tight",children:o.label})]},i))})]})})}function Zn({recaps:t}){const[s,r]=c.useState(null),n=We(),a=new Date,o=ya(a),i=ga({start:o,end:a}),l=[],d=i[0].getDay(),u=d===0?6:d-1;for(let m=0;m<u;m++)l.push(null);
22i.forEach(m=>l.push(m));const h=new Set(i.map(m=>Y(m,"yyyy-MM-dd"))),x=new Set(t.filter(m=>m.compliance_score!==null&&h.has(m.recap_date)).map(m=>m.recap_date)).size,f=m=>{const y=Y(m,"yyyy-MM-dd");return t.find(R=>R.recap_date===y)?.compliance_score??null},b=(m,y)=>y?"border-white/10 bg-transparent text-text-tertiary":m===null?"border-white/15 bg-surface-elevated text-text-primary":m>=80?"border-success/80 bg-success/25 text-text-primary":m>=60?"border-success/60 bg-success/15 text-text-primary":m>=40?"border-warning/70 bg-warning/20 text-text-primary":"border-error/60 bg-error/15 text-text-primary",w=m=>m===null?"text-text-tertiary":m>=80?"text-emerald-500":m>=60?"text-emerald-400":m>=40?"text-amber-500":"text-red-500",g=m=>m===null?"Pas de données":m>=80?"Excellente journée":m>=60?"Bonne journée":m>=40?"Journée moyenne":"Journée difficile",v=(m,y)=>{if(s&&ut(s.date,m)){r(null);return}r({date:m,score:y})};return e.jsxs("div",{className:"space-y-3 heatmap-container relative",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"text-xs text-text-secondary",children:[e.jsx("span",{className:"font-mono-numbers font-semibold text-text-primary",children:x})," ","jours actifs sur ",e.jsx("span",{className:"font-mono-numbers",children:"28"})]})}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:["L","M","M","J","V","S","D"].map((m,y)=>e.jsx("div",{className:"h-5 text-[11px] font-medium text-text-tertiary text-center flex items-center justify-center",children:m},y))}),e.jsx("div",{className:"grid grid-cols-7 gap-1","data-heatmap-grid":!0,children:l.map((m,y)=>{if(m===null)return e.jsx("div",{className:"min-h-11","aria-hidden":"true"},`empty-${y}`);const p=f(m),R=ut(m,a),N=Qr(Jt(m),Jt(a)),F=s!==null&&ut(s.date,m),M=ba(m),_=g(p),S=Y(m,"EEEE d MMMM yyyy",{locale:V});return e.jsxs("button",{type:"button","data-heatmap-day":Y(m,"yyyy-MM-dd"),disabled:N,"aria-label":`${S} : ${_}${p!==null?`, ${p} %`:""}`,"aria-pressed":F,"aria-current":R?"date":void 0,className:`relative flex min-h-11 w-full min-w-0 flex-col items-center justify-center rounded-md border font-bold focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent ${b(p,N)} ${R?"ring-1 ring-accent":""} ${F?"z-10 ring-2 ring-text-primary":""} ${N?"cursor-default border-dashed":"cursor-pointer"}`,onClick:()=>!N&&v(m,p),children:[e.jsx("span",{className:"font-mono-numbers text-xs leading-none",children:M}),R&&e.jsx("span",{className:"absolute bottom-1 h-1 w-1 rounded-full bg-accent","aria-hidden":"true"})]},Y(m,"yyyy-MM-dd"))})}),e.jsx("div",{"aria-live":"polite","aria-atomic":"true",children:e.jsx(je,{children:s&&e.jsxs(K.div,{initial:n?!1:{opacity:0,y:8},animate:n?void 0:{opacity:1,y:0},exit:n?void 0:{opacity:0,y:8},transition:{duration:n?0:.2},className:"mt-2 flex items-center justify-between rounded-xl border border-border bg-surface-elevated px-3 py-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("span",{className:"text-xs font-medium capitalize text-text-primary",children:Y(s.date,"EEEE d MMMM",{locale:V})}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:g(s.score)})]}),e.jsx("div",{className:`font-mono-numbers text-lg font-bold ${w(s.score)}`,children:s.score!==null?`${s.score}%`:"--"})]})})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 text-[10px] text-text-tertiary mt-1",children:[e.jsx("span",{className:"font-mono-numbers",children:"<40%"}),e.jsx("div",{className:"w-4 h-4 rounded-sm bg-red-500/30"}),e.jsx("span",{className:"font-mono-numbers",children:"40-60%"}),e.jsx("div",{className:"w-4 h-4 rounded-sm bg-amber-500/50"}),e.jsx("span",{className:"font-mono-numbers",children:"60-80%"}),e.jsx("div",{className:"w-4 h-4 rounded-sm bg-emerald-500/60"}),e.jsx("span",{className:"font-mono-numbers",children:">80%"}),e.jsx("div",{className:"w-4 h-4 rounded-sm bg-emerald-500"})]})]})}function se(t,s=1,r={}){const n=t.toLocaleString("fr-FR",{minimumFractionDigits:s,maximumFractionDigits:s});return r.signed&&t>0&&n!==se(0,s)?`+${n}`:n}function ie({label:t,before:s,after:r,unit:n,inverse:a=!1}){if(s==null||r==null)return null;const o=r-s,i=o>0,l=a?o<0:o>0;return e.jsxs("div",{className:"flex items-center justify-between py-2",children:[e.jsx("span",{className:"text-sm text-text-secondary",children:t}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-tertiary",children:se(s)}),e.jsx("span",{className:"text-text-tertiary",children:"→"}),e.jsxs("span",{className:"text-sm font-medium text-text-primary",children:[se(r),n]}),o!==0&&e.jsxs("div",{className:`flex items-center gap-0.5 text-xs px-1.5 py-0.5 rounded ${l?"bg-success/20 text-success":"bg-error/20 text-error"}`,children:[l?e.jsx(Ee,{className:"w-3 h-3"}):e.jsx(Ne,{className:"w-3 h-3"}),i?"+":"",se(o)]})]})]})}function Jn({scans:t,userId:s,onClose:r,className:n="",qualitative:a=!1}){const[o,i]=c.useState(t.length>1?t.length-1:0),[l,d]=c.useState(0),[u,h]=c.useState(null),[x,f]=c.useState(!1),[b,w]=c.useState(null),g=We(),v=`before-scan-${c.useId().replace(/:/g,"")}`,m=`after-scan-${c.useId().replace(/:/g,"")}`,y=t[o],p=t[l],{url:R,loading:N}
22=rs(y?.id,"front",!!y?.photo_front_url),{url:F,loading:M}=rs(p?.id,"front",!!p?.photo_front_url),_=N||M,S=async()=>{if(s){f(!0);try{const E=await nr("comparison-image",{method:"POST",body:{user_id:s,scan_id_1:y.id,scan_id_2:p.id},retry:!1,timeoutMs:6e4});E.success&&E.comparison_image_url&&w(E.comparison_image_url)}catch(E){Re.error("Failed to generate comparison:",E)}finally{f(!1)}}},k=()=>{if(!b)return;const E=document.createElement("a");E.href=b,E.download=`twinforge-comparison-${Date.now()}.svg`,document.body.appendChild(E),E.click(),document.body.removeChild(E)},L=async()=>{if(b)if(navigator.share)try{await navigator.share({title:"Ma transformation TwinForge",text:"Regarde ma progression !",url:b})}catch(E){Re.warn("[bodyScanComparison.share] share rejected, falling back to clipboard",E),await D()}else await D()},D=async()=>{b&&(await ea(b)||Re.warn("[bodyScanComparison.share] clipboard unavailable"))};if(t.length<2)return e.jsx(G,{padding:"lg",className:`text-center ${n}`,children:e.jsx("p",{className:"text-text-secondary",children:"Il faut au moins 2 body scans pour comparer ta progression."})});const $=R&&F;return e.jsxs("div",{className:`space-y-4 ${n}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-medium text-text-primary",children:"Comparaison"}),r&&e.jsx(Ms,{icon:tt,label:"Fermer la comparaison",onClick:r})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative",children:[e.jsxs("button",{type:"button",onClick:()=>h(u==="before"?null:"before"),"aria-expanded":u==="before","aria-controls":v,className:"flex min-h-11 w-full items-center justify-between rounded-lg bg-surface px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{className:"w-4 h-4 text-text-tertiary"}),e.jsx("span",{className:"text-text-primary",children:Y(new Date(y.scanned_at),"d MMM yyyy",{locale:V})})]}),e.jsx(st,{className:`w-4 h-4 text-text-tertiary transition-transform ${u==="before"?"rotate-180":""}`})]}),e.jsx(je,{children:u==="before"&&e.jsx(K.div,{id:v,initial:g?!1:{opacity:0,y:-10},animate:g?void 0:{opacity:1,y:0},exit:g?void 0:{opacity:0,y:-10},transition:{duration:g?0:.2},className:"absolute top-full left-0 right-0 mt-1 bg-surface-elevated rounded-lg shadow-xl border border-border z-10 max-h-40 overflow-y-auto",children:t.map((E,C)=>e.jsxs("button",{type:"button",onClick:()=>{i(C),h(null),w(null)},disabled:C===l,className:`min-h-11 w-full px-3 py-2 text-left text-sm transition-colors ${C===o?"bg-accent/20 text-accent":C===l?"text-text-tertiary cursor-not-allowed":"text-text-secondary hover:bg-surface"}`,children:[Y(new Date(E.scanned_at),"d MMM yyyy",{locale:V}),!a&&E.weight_kg!=null&&e.jsxs("span",{className:"ml-2 text-text-tertiary",children:["(",E.weight_kg,"kg)"]})]},E.id))})})]}),e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"text-text-tertiary",children:"→"})}),e.jsxs("div",{className:"flex-1 relative",children:[e.jsxs("button",{type:"button",onClick:()=>h(u==="after"?null:"after"),"aria-expanded":u==="after","aria-controls":m,className:"flex min-h-11 w-full items-center justify-between rounded-lg bg-surface px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{className:"w-4 h-4 text-text-tertiary"}),e.jsx("span",{className:"text-text-primary",children:Y(new Date(p.scanned_at),"d MMM yyyy",{locale:V})})]}),e.jsx(st,{className:`w-4 h-4 text-text-tertiary transition-transform ${u==="after"?"rotate-180":""}`})]}),e.jsx(je,{children:u==="after"&&e.jsx(K.div,{id:m,initial:g?!1:{opacity:0,y:-10},animate:g?void 0:{opacity:1,y:0},exit:g?void 0:{opacity:0,y:-10},transition:{duration:g?0:.2},className:"absolute top-full left-0 right-0 mt-1 bg-surface-elevated rounded-lg shadow-xl border border-border z-10 max-h-40 overflow-y-auto",children:t.map((E,C)=>e.jsxs("button",{type:"button",onClick:()=>{d(C),h(null),w(null)},disabled:C===o,className:`min-h-11 w-full px-3 py-2 text-left text-sm transition-colors ${C===l?"bg-accent/20 text-accent":C===o?"text-text-tertiary cursor-not-allowed":"text-text-secondary hover:bg-surface"}`,children:[Y(new Date(E.scanned_at),"d MMM yyyy",{locale:V}),!a&&E.weight_kg!=null&&e.jsxs("span",{className:"ml-2 text-text-tertiary",children:["(",E.weight_kg,"kg)"]})]},E.id))})})]})]}),_?e.jsx("div",{className:"aspect-[3/4] rounded-xl bg-surface flex items-center justify-center",children:e.jsx(jt,{className:"h-8 w-8 animate-spin text-text-tertiary motion-reduce:animate-none"})}):$?e.jsx(K.div,{initial:g?!1:{opacity:0}
22,animate:g?void 0:{opacity:1},transition:{duration:g?0:.3},children:e.jsx(_a,{beforeImage:R,afterImage:F,beforeLabel:Y(new Date(y.scanned_at),"d MMM",{locale:V}),afterLabel:Y(new Date(p.scanned_at),"d MMM",{locale:V})})},`${y.id}-${p.id}`):e.jsx("div",{className:"aspect-[3/4] rounded-xl bg-surface flex items-center justify-center",children:e.jsx("p",{className:"text-text-tertiary text-sm text-center px-4",children:"Photos non disponibles pour ces scans"})}),!a&&e.jsxs(G,{padding:"md",className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium text-text-primary mb-2",children:"Progression des mesures"}),e.jsx(ie,{label:"Poids",before:y.weight_kg,after:p.weight_kg,unit:"kg",inverse:!0}),e.jsx(ie,{label:"Masse grasse",before:y.estimated_body_fat_pct,after:p.estimated_body_fat_pct,unit:"%",inverse:!0}),e.jsx(ie,{label:"Tour de taille",before:y.waist_cm,after:p.waist_cm,unit:"cm",inverse:!0}),e.jsx(ie,{label:"Hanches",before:y.hips_cm,after:p.hips_cm,unit:"cm",inverse:!0}),e.jsx(ie,{label:"Poitrine",before:y.chest_cm,after:p.chest_cm,unit:"cm"}),e.jsx(ie,{label:"Épaules",before:y.shoulder_cm,after:p.shoulder_cm,unit:"cm"})]}),!a&&(y.bicep_left_cm!=null||p.bicep_left_cm!=null||y.thigh_left_cm!=null||p.thigh_left_cm!=null)&&e.jsxs(G,{padding:"md",className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium text-text-primary mb-2",children:"Membres"}),e.jsx(ie,{label:"Biceps G",before:y.bicep_left_cm,after:p.bicep_left_cm,unit:"cm"}),e.jsx(ie,{label:"Biceps D",before:y.bicep_right_cm,after:p.bicep_right_cm,unit:"cm"}),e.jsx(ie,{label:"Cuisse G",before:y.thigh_left_cm,after:p.thigh_left_cm,unit:"cm"}),e.jsx(ie,{label:"Cuisse D",before:y.thigh_right_cm,after:p.thigh_right_cm,unit:"cm"}),e.jsx(ie,{label:"Mollet G",before:y.calf_left_cm,after:p.calf_left_cm,unit:"cm"}),e.jsx(ie,{label:"Mollet D",before:y.calf_right_cm,after:p.calf_right_cm,unit:"cm"})]}),!a&&(y.muscle_assessment||p.muscle_assessment)&&e.jsxs(G,{padding:"md",className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium text-text-primary mb-2",children:"Développement musculaire"}),["shoulders","arms","chest","back","legs"].map(E=>{const C={developed:8,développé:8,developpe:8,strong:8,fort:8,moderate:5,modéré:5,modere:5,medium:5,moyen:5,average:5,underdeveloped:2,"sous-développé":2,"sous-developpe":2,weak:2,faible:2,poor:2},H=B=>{if(B==null)return null;if(typeof B=="number")return B;if(typeof B=="string"){const Z=C[B.toLowerCase().trim()];if(Z!==void 0)return Z;const O=parseFloat(B);return isNaN(O)?null:O}return null},A=y.muscle_assessment?.[E],de=p.muscle_assessment?.[E],j=H(A),P=H(de),T={shoulders:"Épaules",arms:"Bras",chest:"Poitrine",back:"Dos",legs:"Jambes"};return e.jsx(ie,{label:T[E],before:j,after:P,unit:"/10"},E)})]}),s&&!a&&e.jsx("div",{className:"space-y-3",children:b?e.jsxs(e.Fragment,{children:[e.jsx(G,{padding:"md",className:"overflow-hidden",children:e.jsx("img",{src:b,alt:"Comparaison body scan",className:"w-full rounded-lg"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(we,{variant:"secondary",onClick:k,className:"flex-1",children:[e.jsx(ta,{className:"w-4 h-4 mr-2"}),"Telecharger"]}),e.jsxs(we,{variant:"secondary",onClick:L,className:"flex-1",children:[e.jsx(es,{className:"w-4 h-4 mr-2"}),"Partager"]})]})]}):e.jsx(we,{variant:"secondary",onClick:S,disabled:x,className:"w-full",children:x?e.jsxs(e.Fragment,{children:[e.jsx(jt,{className:"mr-2 h-4 w-4 animate-spin motion-reduce:animate-none"}),"Generation en cours..."]}):e.jsxs(e.Fragment,{children:[e.jsx(es,{className:"w-4 h-4 mr-2"}),"Générer l’image de comparaison"]})})})]})}function Nt({scanId:t,type:s="front",alt:r="Body scan",className:n="",placeholderClassName:a="",onClick:o}){const[i,l]=c.useState(null),[d,u]=c.useState(!0),[h,x]=c.useState(!1),f=c.useRef(null);return c.useEffect(()=>{let b=!1;return(async()=>{u(!0),x(!1);try{const{data:{session:g}}=await U.auth.getSession();if(!g||b)return;const v=await fetch(`https://chvmzsawxhcwzgwywqam.supabase.co/functions/v1/body-photo-decrypt?scan_id=${t}&type=${s}`,{headers:{Authorization:`Bearer ${g.access_token}`}});if(!v.ok||b){b||x(!0);return}const m=await v.blob();f.current&&URL.revokeObjectURL(f.current);const y=URL.createObjectURL(m);f.current=y,b||l(y)}catch(g){b||(Re.error("[decryptedImage.fetch] threw",g,{scanId:t}),x(!0))}finally{b||u(!1)}})(),()=>{b=!0,f.current&&(URL.revokeObjectURL(f.current),f.current=null)}},[t,s]),d?e.jsx("div",{className:`flex items-center justify-center bg-surface ${a}`,children:e.jsx(jt,{className:"h-5 w-5 animate-spin text-text-tertiary motion-reduce:animate-none"})}):h||!i?e.jsx("div",{className:`flex items-center justify-center bg-surface ${a}`,children:e.jsx(Ie,{className:"w-6 h-6 text-text-tertiary"})}):e.jsx("img",{src:i,alt:r,className:n,onClick:o,draggable:!1})}const Me=["epaule_gauche","epaule_droite","coude_gauche","coude_droite","poignet_gauche","poignet_droite","dos_haut","dos_bas","hanche_gauche","hanche_droite","genou_gauche","genou_droite","cheville_gauche","cheville_droite","cou","pied_gauche","pied_droite"],Ce={epaule_gauche:"Epaule gauche",epaule_droite:"Epaule droite",coude_gauche:"Coude gauche",coude_droite:"Coude droite",poignet_gauche:"Poignet gauche",poignet_droite:"Poignet droit",dos_haut:"Haut du dos",dos_bas:"Bas du dos",hanche_gauche:"Hanche gauche",hanche_droite:"Hanche droite",genou_gauche:"Genou gauche",genou_droite:"Genou droit",cheville_gauche:"Cheville gauche",cheville_droite:"Cheville droite",cou:"Cou",pied_gauche:"Pied gauche",pied_droite:"Pied droit"},Qn=[{value:"strain",label:"Tension musculaire"},{value:"sprain",label:"Entorse"},{value:"tendinitis",label:"Tendinite"},{value:"chronic_pain",label:"Douleur chronique"},{value:"post_surgery",label:"Post-operatoire"},{value:"fracture",label:"Fracture"}],$e={active:{label:"Actif",color:"text-red-400",bg:"bg-red-500/15"},recovering:{label:"Recuperation",color:"text-amber-400",bg:"bg-amber-500/15"},monitoring:{label:"Surveillance",color:"text-sky-400",bg:"bg-sky-500/15"},resolved:{label:"Resolu",color:"text-emerald-400",bg:"bg-emerald-500/15"}};function Ae(t){return t<=3?"text-emerald-400":t<=6?"text-amber-400":"text-red-400"}function fs(t){return t<=3?"bg-emerald-400":t<=6?"bg-amber-400":"bg-red-400"}function ei({injuries:t,painLogs:s,alloyAlert:r,onDismissAlloyAlert:n,onAddInjury:a,onUpdateStatus:o,onAddPainLog:i}
22){const l=We(),d=`injury-tracker-${c.useId().replace(/:/g,"")}`,u=`${d}-injury-form`,h=`${d}-injury-name`,x=`${d}-injury-area`,f=`${d}-injury-type`,b=`${d}-injury-severity`,w=`${d}-pain-form`,g=`${d}-pain-injury`,v=`${d}-pain-area`,m=`${d}-pain-level`,y=`${d}-pain-context`,p=`${d}-pain-affects-training`,[R,N]=c.useState(!1),[F,M]=c.useState(!1),[_,S]=c.useState(null),[k,L]=c.useState(!1),[D,$]=c.useState({injury_name:"",body_area:Me[0],injury_type:"strain",severity:5}),[E,C]=c.useState({injury_id:null,body_area:Me[0],pain_level:3,context:"",affects_training:!1}),H=async()=>{if(D.injury_name.trim()){L(!0);try{await a(D),N(!1),$({injury_name:"",body_area:Me[0],injury_type:"strain",severity:5})}finally{L(!1)}}},A=async()=>{L(!0);try{await i({...E,injury_id:E.injury_id||null,context:E.context||void 0}),M(!1),C({injury_id:null,body_area:Me[0],pain_level:3,context:"",affects_training:!1})}finally{L(!1)}},de=j=>s.filter(P=>P.injury_id===j).slice(0,5);return e.jsx("div",{className:"space-y-4",children:e.jsxs(G,{padding:"md",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsx(ne,{eyebrow:"Blessures",title:"Suivi des blessures"}),e.jsxs("div",{className:"flex w-full gap-2 min-[360px]:w-auto",children:[e.jsxs("button",{type:"button",onClick:()=>{M(!0),N(!1)},"aria-expanded":F,"aria-controls":w,className:"flex min-h-11 flex-1 items-center justify-center gap-1 rounded-lg bg-amber-500/10 px-2.5 py-1.5 text-xs font-medium text-amber-400 transition-colors hover:bg-amber-500/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400 min-[360px]:flex-none",children:[e.jsx(St,{className:"w-3 h-3"}),"Douleur"]}),e.jsxs("button",{type:"button",onClick:()=>{N(!0),M(!1)},"aria-expanded":R,"aria-controls":u,className:"flex min-h-11 flex-1 items-center justify-center gap-1 rounded-lg bg-accent/10 px-2.5 py-1.5 text-xs font-medium text-accent transition-colors hover:bg-accent/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent min-[360px]:flex-none",children:[e.jsx(sa,{className:"w-3 h-3"}),"Blessure"]})]})]}),e.jsx(je,{children:r&&e.jsx(K.div,{initial:l?!1:{opacity:0,height:0},animate:l?void 0:{opacity:1,height:"auto"},exit:l?void 0:{opacity:0,height:0},transition:{duration:l?0:.2},className:"overflow-hidden mb-3",children:e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-xl bg-amber-500/10 border border-amber-500/25",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-amber-500/20 flex items-center justify-center flex-shrink-0 mt-0.5",children:e.jsx(xa,{className:"w-3.5 h-3.5 text-amber-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold text-amber-300",children:"Mis a jour par Alloy"}),e.jsxs("p",{className:"text-xs text-amber-200/80 mt-0.5",children:["Alloy a detecte : ",e.jsx("span",{className:"font-medium",children:r.injuryName}),r.bodyArea&&r.bodyArea!=="unknown"&&e.jsxs(e.Fragment,{children:[" — ",Ce[r.bodyArea]||r.bodyArea]})]}),e.jsx("p",{className:"text-[10px] text-amber-300/60 mt-1",children:Y(new Date(r.detectedAt),"d MMM 'a' HH:mm",{locale:V})})]}),n&&e.jsx("button",{type:"button",onClick:n,"aria-label":"Fermer l'alerte Alloy",className:"flex h-11 w-11 flex-shrink-0 items-center justify-center rounded-lg hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-400",children:e.jsx(tt,{className:"w-3.5 h-3.5 text-amber-400/60"})})]})},"alloy-alert")}),e.jsx(je,{children:R&&e.jsx(K.div,{initial:l?!1:{opacity:0,height:0},animate:l?void 0:{opacity:1,height:"auto"},exit:l?void 0:{opacity:0,height:0},transition:{duration:l?0:.2},className:"overflow-hidden",children:e.jsxs("div",{id:u,className:"mb-4 space-y-3 rounded-xl bg-surface-secondary p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-text-primary",children:"Nouvelle blessure"}),e.jsx("button",{type:"button",onClick:()=>N(!1),"aria-label":"Fermer le formulaire de blessure",className:"flex h-11 w-11 items-center justify-center rounded-lg hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:e.jsx(tt,{className:"w-4 h-4 text-text-tertiary"})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:h,className:"mb-1 block text-[11px] text-text-tertiary",children:"Nom"}),e.jsx("input",{id:h,type:"text",placeholder:"Nom (ex: tendinite rotulienne)",value:D.injury_name,onChange:j=>$(P=>({...P,injury_name:j.target.value})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus:border-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:x,className:"text-[11px] text-text-tertiary mb-1 block",children:"Zone"}),e.jsx("select",{id:x,value:D.body_area,onChange:j=>$(P=>({...P,body_area:j.target.value})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:Me.map(j=>e.jsx("option",{value:j,children:Ce[j]},j))})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:f,className:"text-[11px] text-text-tertiary mb-1 block",children:"Type"}
22),e.jsx("select",{id:f,value:D.injury_type,onChange:j=>$(P=>({...P,injury_type:j.target.value})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:Qn.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{htmlFor:b,className:"text-[11px] text-text-tertiary",children:"Severite"}),e.jsxs("span",{className:`text-sm font-bold ${Ae(D.severity)}`,children:[D.severity,"/10"]})]}),e.jsx("input",{id:b,type:"range",min:1,max:10,value:D.severity,"aria-valuetext":`${D.severity} sur 10`,onChange:j=>$(P=>({...P,severity:Number(j.target.value)})),className:"h-11 w-full accent-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"})]}),e.jsx(we,{onClick:H,loading:k,size:"sm",fullWidth:!0,variant:"primary",className:"min-h-11",children:"Enregistrer la blessure"})]})})}),e.jsx(je,{children:F&&e.jsx(K.div,{initial:l?!1:{opacity:0,height:0},animate:l?void 0:{opacity:1,height:"auto"},exit:l?void 0:{opacity:0,height:0},transition:{duration:l?0:.2},className:"overflow-hidden",children:e.jsxs("div",{id:w,className:"mb-4 space-y-3 rounded-xl bg-surface-secondary p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-text-primary",children:"Signaler une douleur"}),e.jsx("button",{type:"button",onClick:()=>M(!1),"aria-label":"Fermer le formulaire de douleur",className:"flex h-11 w-11 items-center justify-center rounded-lg hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:e.jsx(tt,{className:"w-4 h-4 text-text-tertiary"})})]}),t.length>0&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:g,className:"text-[11px] text-text-tertiary mb-1 block",children:"Blessure liee (optionnel)"}),e.jsxs("select",{id:g,value:E.injury_id||"",onChange:j=>C(P=>({...P,injury_id:j.target.value||null,body_area:j.target.value&&t.find(T=>T.id===j.target.value)?.body_area||P.body_area})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsx("option",{value:"",children:"Aucune"}),t.map(j=>e.jsxs("option",{value:j.id,children:[j.injury_name," (",Ce[j.body_area]||j.body_area,")"]},j.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:v,className:"text-[11px] text-text-tertiary mb-1 block",children:"Zone"}),e.jsx("select",{id:v,value:E.body_area,onChange:j=>C(P=>({...P,body_area:j.target.value})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:Me.map(j=>e.jsx("option",{value:j,children:Ce[j]},j))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{htmlFor:m,className:"text-[11px] text-text-tertiary",children:"Niveau de douleur"}),e.jsxs("span",{className:`text-sm font-bold ${Ae(E.pain_level)}`,children:[E.pain_level,"/10"]})]}),e.jsx("input",{id:m,type:"range",min:1,max:10,value:E.pain_level,"aria-valuetext":`${E.pain_level} sur 10`,onChange:j=>C(P=>({...P,pain_level:Number(j.target.value)})),className:"h-11 w-full accent-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:y,className:"mb-1 block text-[11px] text-text-tertiary",children:"Contexte (optionnel)"}),e.jsx("input",{id:y,type:"text",placeholder:"Contexte (ex: pendant le squat, au reveil...)",value:E.context,onChange:j=>C(P=>({...P,context:j.target.value})),className:"min-h-11 w-full rounded-lg border border-border bg-surface px-3 py-2 text-sm text-text-primary focus:border-accent/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent"})]}),e.jsxs("label",{htmlFor:p,className:"flex min-h-11 cursor-pointer items-center gap-2",children:[e.jsx("input",{id:p,type:"checkbox",checked:E.affects_training,onChange:j=>C(P=>({...P,affects_training:j.target.checked})),className:"w-4 h-4 rounded accent-accent"}),e.jsx("span",{className:"text-xs text-text-secondary",children:"Empeche l'entrainement"})]}),e.jsx(we,{onClick:A,loading:k,size:"sm",fullWidth:!0,variant:"primary",className:"min-h-11",children:"Enregistrer la douleur"})]})})}),t.length===0&&s.length===0&&e.jsxs("div",{className:"text-center py-6",children:[e.jsx(ir,{className:"w-8 h-8 text-text-tertiary mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm text-text-tertiary",children:"Aucune blessure ou douleur signalée"}),e.jsx("p",{className:"text-xs text-text-tertiary mt-1",children:"Signale tes douleurs pour qu’Alloy adapte tes séances"})]}),t.map(j=>{const P=_===j.id,T=de(j.id),B=$e[j.status]||$e.active,Z=`${d}-injury-${j.id}`;return e.jsxs(K.div,{layout:!0,className:"bg-surface-secondary rounded-xl overflow-hidden mb-2 last:mb-0",children:[e.jsxs("button",{type:"button",onClick:()=>S(P?null:j.id),"aria-expanded":P,"aria-controls":Z,className:"flex min-h-11 w-full items-center gap-3 p-3 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-text-primary truncate",children:j.injury_name}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full font-medium ${B.color} ${B.bg}`,children:B.label})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-text-tertiary",children:[e.jsx("span",{children:Ce[j.body_area]||j.body_area}),e.jsxs("span",{className:"flex items-center gap-1",children:["Sev."," ",e.jsx("span",{className:`font-bold ${Ae(j.severity)}`,children:j.severity}),"/10"]}),e.jsx("span",{children:Y(new Date(j.reported_at),"d MMM",{locale:V})})]})]}),P?e.jsx(ra,{className:"w-4 h-4 text-text-tertiary"}):e.jsx(st,{className:"w-4 h-4 text-text-tertiary"})]}),e.jsx(je,{children:P&&e.jsx(K.div,{id:Z,initial:l?!1:{opacity:0,height:0},animate:l?void 0:{opacity:1,height:"auto"},exit:l?void 0:{opacity:0,height:0},transition:{duration:l?0:.2},className:"overflow-hidden",children:e.jsxs("div",{className:"px-3 pb-3 space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:["recovering","monitoring","resolved"].filter(O=>O!==j.status).map(O=>e.jsxs("button",{type:"button",onClick:()=>o(j.id,O),className:`flex min-h-11 items-center gap-1 rounded-lg px-3 py-2 text-[11px] font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent ${$e[O].bg} ${$e[O].color} hover:opacity-80`,children:[O==="resolved"&&e.jsx(or,{className:"w-3 h-3"}),$e[O].label]},O))}),T.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] text-text-tertiary mb-1.5 font-medium",children:"Historique douleur"}),e.jsx("div",{className:"space-y-1.5",children:T.map(O=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-16 flex items-center gap-1",children:[e.jsx("div",{className:`h-1.5 rounded-full ${fs(O.pain_level)}`,style:{width:`${O.pain_level*10}%`}}),e.jsx("span",{className:`text-[10px] font-bold ${Ae(O.pain_level)}`,children:O.pain_level})]}),e.jsx("span",{className:"text-[10px] text-text-tertiary flex-1 truncate",children:O.context||"-"}),e.jsx("span",{className:"text-[10px] text-text-tertiary",children:Y(new Date(O.logged_at),"d/MM",{locale:V})})]},O.id))})]})]})})})]},j.id)}),s.filter(j=>!j.injury_id).length>0&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border",children:[e.jsx("p",{className:"text-[11px] text-text-tertiary mb-2 font-medium",children:"Douleurs non liees"}),e.jsx("div",{className:"space-y-1.5",children:s.filter(j=>!j.injury_id).slice(0,5).map(j=>e.jsxs("div",{className:"flex items-center gap-2 bg-surface-secondary rounded-lg px-2.5 py-1.5",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:Ce[j.body_area]||j.body_area}),e.jsxs("div",{className:"flex-1 flex items-center gap-1",children:[e.jsx("div",{className:`h-1.5 rounded-full ${fs(j.pain_level)}`,style:{width:`${j.pain_level*10}%`,maxWidth:60}}),e.jsx("span",{className:`text-[10px] font-bold ${Ae(j.pain_level)}`,children:j.pain_level})]}),j.context&&e.jsx("span",{className:"text-[10px] text-text-tertiary truncate max-w-[80px]",children:j.context}),e.jsx("span",{className:"text-[10px] text-text-tertiary",children:Y(new Date(j.logged_at),"d/MM",{locale:V})})]},j.id))})]})]})})}const ti="body-photos",si="body-comparisons",ri=["front","side","back"];function ai(t,s,r){return`${t}/${s}_${r}.enc`}function ni(t,s){return`${t}/morph/${s}.png`}function ii(t,s){return{photos:ri.map(r=>ai(t,s,r)),morph:[ni(t,s)]}}function oi(t=!1){const{user:s}=at(),r=t?void 0:s?.id,{weights:n,loading:a,error:o,refetch:i}=va(r,60),{scans:l,loading:d,error:u,refetch:h}=Tr(s?.id),{profile:x,loading:f,error:b,refetch:w}=tn(s?.id),{data:g,loading:v,error:m,refetch:y}=wa(r),{data:p,loading:R,error:N,refetch:F}=Na(r),{data:M,loading:_,error:S,refetch:k}=Ya(r),{data:L,latest:D,error:$}=Es(!t&&x?.withings_connected?r:void 0,90),{injuries:E,painLogs:C,addInjury:H,updateInjuryStatus:A,addPainLog:de,alloyAlert:j,dismissAlloyAlert:P,error:T}=Xa(s?.id),Z=d||f||!t&&(a||v||R||_),W=[...t?[]:[o],u,b,...t?[]:[m,N,S,$],T].filter(
22Boolean)[0]||null,z=()=>{t||i(),h(),w(),t||(y(),F(),k())},ue=n.length>0?Number(n[n.length-1].weight_kg):null,oe=n.length>0?Number(n[0].weight_kg):null,ke=ue&&oe?ue-oe:null,be=g.length>0?g[g.length-1].estimated_body_fat_pct:null,ye=g.length>0?g[0].estimated_body_fat_pct:null,re=be!=null&&ye!=null?be-ye:null,me=p.length>0?p[p.length-1].waist_cm:null,_e=p.length>0?p[0].waist_cm:null,le=me!=null&&_e!=null?me-_e:null,fe=p.length>0?p[p.length-1].waist_hip_ratio_risk:null,he=M.length>0?M[M.length-1].assessment:null,J=M.length>0?M[0].average:null,xe=M.length>0?M[M.length-1].average:null,ce=xe!=null&&J!=null?xe-J:null,Q=x?.pregnancy_status,q={isPregnant:Q==="pregnant",hideBodyMetrics:Ut(x)||Q==="pregnant"||Q==="postpartum",isGainObjective:x?.objective==="gain_muscle",isLoseBellyObjective:x?.objective==="lose_belly",avoidWeight:Ut(x),pregnancyTrimester:x?.pregnancy_trimester??null,dueDate:x?.due_date??null,targetWeight:x?.target_weight_kg??null,targetBodyFat:x?.target_body_fat_pct??null},ve=q.dueDate?Math.max(0,Math.ceil((new Date(q.dueDate).getTime()-Date.now())/(1e3*60*60*24))):null,ee=l[0],De=ee?.fat_distribution??null,Ge=x?.gender??null,ae=ee&&(ee.chest_cm!=null||ee.waist_cm!=null||ee.hips_cm!=null||ee.bicep_left_cm!=null||ee.bicep_right_cm!=null||ee.thigh_left_cm!=null||ee.thigh_right_cm!=null||ee.calf_left_cm!=null||ee.neck_cm!=null||ee.shoulder_cm!=null),Ue=n.length>0||l.length>0||g.length>0;return{user:s,weights:n,scans:l,bodyFatData:g,waistData:p,muscleHistory:M,compositionData:L,latestComposition:D,injuries:E,painLogs:C,addInjury:H,updateInjuryStatus:A,addPainLog:de,alloyAlert:j,dismissAlloyAlert:P,refetchScans:h,loading:Z,pageError:W,handleRetry:z,currentWeight:ue,startWeight:oe,weightChange:ke,currentBodyFat:be,startBodyFat:ye,bodyFatChange:re,currentWaist:me,startWaist:_e,waistChange:le,latestWaistRisk:fe,currentMuscleAvg:xe,muscleChange:ce,latestMuscleAssessment:he,latestFatDistribution:De,gender:Ge,heightCm:x?.height_cm??null,flags:q,dueDateCountdown:ve,latestScan:ee,hasMeasurements:ae,hasAnyData:Ue,withingsConnected:x?.withings_connected??!1}}function li({scan:t,onViewScan:s,onDeleteScan:r,hideMeasurements:n=!1}){const a=Y(new Date(t.scanned_at),"d MMM yyyy",{locale:V});return e.jsxs(G,{padding:"sm",className:"min-w-[130px]",children:[e.jsxs("div",{className:"text-xs text-text-tertiary mb-2 flex items-center justify-between gap-1",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(lr,{className:"w-3 h-3","aria-hidden":"true"}),a]}),e.jsx(Ms,{icon:cr,label:`Supprimer le scan du ${a}`,onClick:()=>r(t),tone:"error",className:"-mr-2 -mt-2"})]}),t.photo_front_url?e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":`Voir la photo du scan du ${a}`,className:"mb-2 block min-h-11 w-full aspect-[3/4] overflow-hidden rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",onClick:()=>s(t.id),children:e.jsx(Nt,{scanId:t.id,className:"w-full h-full object-cover",placeholderClassName:"w-full h-full rounded-lg"})}):e.jsx("div",{className:"w-full aspect-[3/4] bg-surface rounded-lg flex items-center justify-center mb-2",children:e.jsx(Ie,{className:"w-6 h-6 text-text-tertiary","aria-hidden":"true"})}),!n&&e.jsxs("div",{className:"space-y-1",children:[t.weight_kg!=null&&e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-tertiary",children:"Poids"}),e.jsxs("span",{className:"text-text-primary font-medium",children:[t.weight_kg.toLocaleString("fr-FR")," kg"]})]}),t.estimated_body_fat_pct!=null&&e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-text-tertiary",children:"Masse grasse"}),e.jsxs("span",{className:"text-text-primary font-medium",children:[se(t.estimated_body_fat_pct)," %"]})]})]})]})}const ci={shoulders:"Épaules",arms:"Bras",chest:"Pectoraux",back:"Dos",legs:"Jambes"},di={shoulders:"bg-sky-400",arms:"bg-rose-400",chest:"bg-amber-400",back:"bg-emerald-400",legs:"bg-violet-400"},ui={shoulders:"text-sky-400",arms:"text-rose-400",chest:"text-amber-400",back:"text-emerald-400",legs:"text-violet-400"},Be={low:{label:"Risque faible",color:"text-success",bg:"bg-success/10",border:"border-success/20"},moderate:{label:"Risque modéré",color:"text-amber-400",bg:"bg-amber-400/10",border:"border-amber-400/20"},high:{label:"Risque élevé",color:"text-error",bg:"bg-error/10",border:"border-error/20"}};function Ds({assessment:t,compact:s=!1}){const r=["shoulders","arms","chest","back","legs"].filter(n=>t[n]!=null);return r.length===0?null:e.jsx("div",{className:s?"space-y-1.5":"space-y-2",children:r.map(n=>{const a=t[n],o=Math.min(100,Math.max(0,a/10*100));return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`${s?"text-[10px]":"text-xs"} text-text-tertiary w-16 shrink-0`,children:ci[n]}),e.jsx("div",{className:"flex-1 bg-surface-secondary rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${di[n]}`,style:{width:`${o}%`}})}),e.jsx("span",{className:`${s?"text-[10px]":"text-xs"} font-medium ${ui[n]} w-8 text-right`,children:a.toFixed(1)})]},n)})})}const Ts={text:{tertiary:"#6B7280"},grid:"rgba(255, 255, 255, 0.06)"},mi={background:"rgba(18, 18, 28, 0.95)",border:"1px solid rgba(255, 255, 255, 0.08)",borderRadius:12,boxShadow:"0 8px 32px rgba(0, 0, 0, 0.5)",padding:"8px 12px",fontSize:12,color:"#FFFFFF"},ps={tick:{fill:Ts.text.tertiary,fontSize:11}
22,axisLine:!1,tickLine:!1},hi={strokeDasharray:"3 3",stroke:Ts.grid,vertical:!1};function Le({data:t,targetValue:s,targetLabel:r="Objectif",color:n,gradientId:a,height:o=140,valueFormatter:i=l=>l.toFixed(0)}){const[l,d]=c.useState(!1);c.useEffect(()=>{const x=requestAnimationFrame(()=>d(!0));return()=>cancelAnimationFrame(x)},[]);const{domainMin:u,domainMax:h}=c.useMemo(()=>{if(t.length<2)return{domainMin:0,domainMax:100};const x=t.map(v=>v.value),f=Math.min(...x,s??1/0),b=Math.max(...x),g=(b-f||1)*.1;return{domainMin:Math.max(0,f-g),domainMax:b+g}},[t,s]);return t.length<2?e.jsx("div",{className:"flex items-center justify-center bg-surface/50 rounded-xl",style:{height:o},children:e.jsx("p",{className:"text-text-tertiary text-sm text-center px-4",children:"Pas assez de données pour afficher le graphique"})}):l?e.jsx(aa,{width:"100%",height:o,minHeight:1,children:e.jsxs(na,{data:t,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:a,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:n,stopOpacity:.3}),e.jsx("stop",{offset:"100%",stopColor:n,stopOpacity:0})]})}),e.jsx(ia,{...hi}),e.jsx(oa,{dataKey:"date",...ps,tickFormatter:x=>Y(new Date(x),"d MMM",{locale:V})}),e.jsx(la,{domain:[u,h],...ps,tickFormatter:i}),e.jsx(ca,{contentStyle:mi,formatter:x=>[i(Number(x)||0),""],labelFormatter:x=>Y(new Date(String(x)),"d MMM yyyy",{locale:V})}),s!=null&&e.jsx(da,{y:s,stroke:"#10B981",strokeDasharray:"5 5",label:{value:r,position:"right",fill:"#10B981",fontSize:11}}),e.jsx(ua,{type:"monotone",dataKey:"value",stroke:n,fill:`url(#${a})`,strokeWidth:2,dot:{stroke:n,fill:n,r:4},activeDot:{stroke:n,fill:n,r:5}})]})}):e.jsx("div",{style:{height:o,minHeight:o}})}function xi({weights:t,currentWeight:s,targetWeight:r,isPregnant:n}){const a=s&&r?se(Math.abs(s-r)):null,o=t.map(i=>({date:i.logged_at,value:Number(i.weight_kg)}));return e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-3",eyebrow:n?"Grossesse":"Poids",title:n?"Suivi de poids":"Évolution du poids"}),e.jsx(Le,{data:o,targetValue:n?void 0:r,color:n?"rgb(236, 72, 153)":"rgb(6, 182, 212)",gradientId:"weightGradientBody"}),n?e.jsx("div",{className:"mt-3 pt-3 border-t border-border",children:e.jsx("p",{className:"text-xs text-text-tertiary text-center",children:"La prise de poids pendant la grossesse est normale et necessaire. Ton medecin te guidera sur la fourchette adaptee."})}):e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-3 pt-3 border-t border-border",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-primary",children:s?`${s} kg`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Actuel"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-success",children:r?`${r} kg`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Objectif"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-secondary",children:a?`${a} kg`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Restant"})]})]})]})}function fi({bodyFatData:t,currentBodyFat:s,startBodyFat:r,bodyFatChange:n,targetBodyFat:a}){const o=t.map(i=>({date:i.scanned_at,value:Number(i.estimated_body_fat_pct)}));return e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-3",eyebrow:"Composition",title:"Évolution de la masse grasse",action:n!==null&&e.jsxs("div",{className:`flex items-center gap-1 text-sm ${n<0?"text-success":"text-error"}`,children:[n<0?e.jsx(Ee,{className:"w-4 h-4"}):e.jsx(Ne,{className:"w-4 h-4"}),n>0?"+":"",se(n),"%"]})}),e.jsx(Le,{data:o,targetValue:a,targetLabel:"Objectif",color:"rgb(249, 115, 22)",gradientId:"bodyFatGradientBody",height:110,valueFormatter:i=>`${i.toFixed(0)}%`}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-3 pt-3 border-t border-border",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-primary",children:s?`${se(s)}%`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Actuel"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-success",children:a?`${a}%`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Objectif"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-secondary",children:r?`${se(r)}
22%`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Initial"})]})]})]})}function gs({waistData:t,currentWaist:s,startWaist:r,waistChange:n,latestWaistRisk:a,isLoseBellyObjective:o}){const i=t.map(l=>({date:l.scanned_at,value:l.waist_cm}));return e.jsxs(G,{padding:"md",className:o?"border-success/30 bg-gradient-to-br from-success/5 via-transparent to-transparent":"",children:[e.jsx(ne,{className:"mb-3",eyebrow:o?"Tour de taille · ton objectif":"Tour de taille",title:"Évolution du tour de taille",action:n!==null&&e.jsxs("div",{className:`flex items-center gap-1 text-sm ${n<0?"text-success":"text-amber-400"}`,children:[n<0?e.jsx(Ee,{className:"w-4 h-4"}):e.jsx(Ne,{className:"w-4 h-4"}),n>0?"+":"",se(n)," cm"]})}),e.jsx(Le,{data:i,color:"rgb(16, 185, 129)",gradientId:"waistGradientBody",height:110,valueFormatter:l=>`${l.toFixed(0)} cm`}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-3 pt-3 border-t border-border",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-primary",children:s?`${s.toFixed(0)} cm`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Actuel"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:`text-base font-bold ${n!==null&&n<0?"text-success":"text-text-secondary"}`,children:n!==null?`${n>0?"+":""}${se(n)} cm`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Evolution"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-secondary",children:r?`${r.toFixed(0)} cm`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Initial"})]})]}),a&&e.jsxs("div",{className:`mt-3 pt-3 border-t border-border flex items-center gap-2 px-3 py-2 rounded-lg ${Be[a].bg} ${Be[a].border} border`,children:[e.jsx(St,{className:`w-3.5 h-3.5 flex-shrink-0 ${Be[a].color}`}),e.jsxs("span",{className:`text-xs font-medium ${Be[a].color}`,children:["Rapport taille/hanches : ",Be[a].label]})]})]})}function bs({muscleHistory:t,currentMuscleAvg:s,muscleChange:r,latestMuscleAssessment:n,isGainObjective:a}){const o=t.map(i=>({date:i.scanned_at,value:i.average}));return e.jsxs(G,{padding:"md",className:a?"border-rose-400/30 bg-gradient-to-br from-rose-400/5 via-transparent to-transparent":"",children:[e.jsx(ne,{className:"mb-3",eyebrow:a?"Musculature · ton objectif":"Musculature",title:"Évolution musculaire",action:r!==null&&e.jsxs("div",{className:`flex items-center gap-1 text-sm ${r>0?"text-success":"text-text-secondary"}`,children:[r>0?e.jsx(Ne,{className:"w-4 h-4"}):e.jsx(Ee,{className:"w-4 h-4"}),r>0?"+":"",se(r)]})}),t.length>=2&&e.jsx(Le,{data:o,color:"rgb(251, 113, 133)",gradientId:"muscleGradientBody",height:100,valueFormatter:i=>`${se(i)}/10`}),n&&e.jsxs("div",{className:"mt-3 pt-3 border-t border-border",children:[e.jsx("p",{className:"text-xs text-text-tertiary mb-2 font-medium",children:"Bilan par zone (dernier scan)"}),e.jsx(Ds,{assessment:n})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mt-3 pt-3 border-t border-border",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-base font-bold text-text-primary",children:s!=null?`${se(s)}/10`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Score actuel"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:`text-base font-bold ${r!==null&&r>0?"text-success":"text-text-secondary"}`,children:r!==null?`${r>0?"+":""}${se(r)}`:"--"}),e.jsx("div",{className:"text-xs text-text-tertiary",children:"Progression"})]})]})]})}function pi({compositionData:t,latestComposition:s}){return e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-4",eyebrow:"Balance Withings",title:"Composition corporelle"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-4",children:[e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(vt,{className:"w-3.5 h-3.5 text-amber-400"}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:"Masse grasse"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[s.body_fat_pct?.toFixed(1)??"--",e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"%"})]}),s.fat_mass_kg&&e.jsxs("div",{className:"text-[10px] text-text-tertiary mt-0.5",children:[s.fat_mass_kg.toFixed(1)," kg"]})]}),e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ns,{className:"w-3.5 h-3.5 text-rose-400"}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:"Masse musculaire"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[s.muscle_mass_kg?.toFixed(1)??"--",e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"kg"})]})]}),e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ma,{className:"w-3.5 h-3.5 text-sky-400"}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:"Hydratation"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[s.water_pct?.toFixed(1)??"--",e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"%"})]})]}),e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ha,{className:"w-3.5 h-3.5 text-slate-300"}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:"Masse osseuse"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[s.bone_mass_kg?.toFixed(1)??"--",e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"kg"})]})]})]}),t.length>=2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-3",children:[e.jsx("p",{className:"text-xs text-text-tertiary mb-2 font-medium",children:"Tendance masse grasse / musculaire (90j)"}),e.jsx(Le,{data:t.filter(r=>r.body_fat_pct!==null).map(r=>({date:r.logged_at,value:r.body_fat_pct}
22)),color:"rgb(251, 191, 36)",gradientId:"compositionFatGradient",height:100,valueFormatter:r=>`${r.toFixed(0)}%`})]}),t.some(r=>r.muscle_mass_kg!==null)&&e.jsxs("div",{className:"border-t border-border pt-3 mt-3",children:[e.jsx("p",{className:"text-xs text-text-tertiary mb-2 font-medium",children:"Masse musculaire (kg)"}),e.jsx(Le,{data:t.filter(r=>r.muscle_mass_kg!==null).map(r=>({date:r.logged_at,value:r.muscle_mass_kg})),color:"rgb(251, 113, 133)",gradientId:"compositionMuscleGradient",height:100,valueFormatter:r=>`${r.toFixed(1)}kg`})]})]})]})}function gi({qualitative:t}){const s=oi(t),{user:r,weights:n,scans:a,bodyFatData:o,waistData:i,muscleHistory:l,compositionData:d,latestComposition:u,injuries:h,painLogs:x,addInjury:f,updateInjuryStatus:b,addPainLog:w,alloyAlert:g,dismissAlloyAlert:v,refetchScans:m,loading:y,pageError:p,handleRetry:R,currentWeight:N,weightChange:F,currentBodyFat:M,startBodyFat:_,bodyFatChange:S,currentWaist:k,startWaist:L,waistChange:D,latestWaistRisk:$,currentMuscleAvg:E,muscleChange:C,latestMuscleAssessment:H,flags:A,dueDateCountdown:de,latestScan:j,hasAnyData:P,withingsConnected:T}=s,B=Rs(a),Z=ln(B,a.length>0),[O,W]=c.useState(null),[z,ue]=c.useState(!1),[oe,ke]=c.useState(null),be=js(),ye=async()=>{if(!oe)return;const re=oe,me=ti,_e=si,le=[re.photo_front_url,re.photo_back_url,re.photo_side_url].filter(
22Boolean),fe=[re.comparison_image_url].filter(Boolean),he=le.map(Q=>{const q=Q.split(`/${me}/`);return q[q.length-1]}).filter(Boolean),J=fe.map(Q=>{const q=Q.split(`/${_e}/`);return q[q.length-1]}).filter(Boolean),xe=r?.id??re.user_id;if(xe){const Q=ii(xe,re.id);he.push(...Q.photos.filter(q=>!he.includes(q))),J.push(...Q.morph.filter(q=>!J.includes(q)))}for(const[Q,q]of[[me,he],[_e,J]]){if(!q.length)continue;const{error:ve}=await U.storage.from(Q).remove(q);ve&&_s("body-measurements","body_scan_storage_cleanup_failed",{bucket:Q,remaining_objects:q.length,error:ve.message})}const{error:ce}=await U.from("body_scans").delete().eq("id",re.id);if(ce)throw be.error("Erreur lors de la suppression"),ce;be.success("Scan supprimé"),m()};return e.jsxs("div",{className:"space-y-4",children:[p?e.jsx(_r,{compact:!0,message:p,onRetry:R}):y?e.jsx(ja,{}):e.jsxs(e.Fragment,{children:[A.isPregnant&&e.jsxs(G,{padding:"lg",className:"bg-gradient-to-r from-pink-500/10 via-transparent to-rose-500/10 border-pink-500/20",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx(ne,{eyebrow:"Grossesse",title:"Suivi de grossesse"}),e.jsxs("p",{className:"mt-1 text-sm text-text-secondary",children:[t?"En cours":A.pregnancyTrimester?`Trimestre ${A.pregnancyTrimester}`:"En cours",!t&&de!==null&&` - J-${de}`]})]}),!t&&A.pregnancyTrimester&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-xs text-text-tertiary",children:[e.jsx("span",{children:"T1"}),e.jsx("span",{children:"T2"}),e.jsx("span",{children:"T3"})]}),e.jsx("div",{className:"relative h-2 bg-surface-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"absolute h-full bg-gradient-to-r from-pink-400 to-rose-400 rounded-full transition-all duration-700",style:{width:`${A.pregnancyTrimester/3*100}%`}})})]})]}),j&&e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-4",eyebrow:`Body scan · ${Y(new Date(j.scanned_at),"d MMM yyyy",{locale:V})}`,title:"Dernier scan"}),e.jsxs("div",{className:"flex gap-4",children:[j.photo_front_url?e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":`Voir la photo du scan du ${Y(new Date(j.scanned_at),"d MMM yyyy",{locale:V})}`,className:"h-36 min-h-11 w-28 flex-shrink-0 overflow-hidden rounded-xl ring-1 ring-white/10 transition-all hover:ring-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",onClick:()=>W(j.id),children:e.jsx(Nt,{scanId:j.id,className:"w-full h-full object-cover",placeholderClassName:"w-full h-full"})}):e.jsx("div",{className:"w-28 h-36 bg-surface rounded-xl flex items-center justify-center flex-shrink-0 ring-1 ring-white/10",children:e.jsx(Ie,{className:"w-6 h-6 text-text-tertiary"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[!t&&!A.hideBodyMetrics&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(Yt,{className:"w-4 h-4 text-text-tertiary"}),e.jsx("span",{className:"text-[11px] text-text-tertiary",children:"Poids"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[j.weight_kg!=null?j.weight_kg.toLocaleString("fr-FR"):"—",e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"kg"})]})]}),e.jsxs("div",{className:"bg-surface-secondary rounded-xl p-3","data-body-fat-tile":!0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(vt,{className:"w-4 h-4 text-text-tertiary"}),e.jsx("span",{className:"text-xs text-text-tertiary",children:"Masse grasse"})]}),e.jsxs("div",{className:"text-lg font-bold text-text-primary",children:[as(B.value),e.jsx("span",{className:"text-xs font-normal text-text-tertiary ml-1",children:"%"})]}),Z&&e.jsx("p",{className:"mt-0.5 text-xs text-text-tertiary",children:Z})]})]}),a.length>=2&&e.jsx(we,{type:"button",variant:"secondary",fullWidth:!0,onClick:()=>ue(!0),"aria-haspopup":"dialog","aria-expanded":z,icon:e.jsx(Yr,{className:"h-4 w-4","aria-hidden":"true"}),children:"Comparer mes photos"})]})]}),!t&&H&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border",children:[e.jsx("p",{className:"mb-3 text-xs font-medium text-text-tertiary",children:"Bilan musculaire"}),e.jsx(Ds,{assessment:H,compact:!0})]})]}),P&&!t&&!A.avoidWeight&&e.jsxs("div",{className:`grid gap-3 ${A.hideBodyMetrics?"grid-cols-2":"grid-cols-3"}`,children:[e.jsxs(G,{padding:"md",className:"text-center flex flex-col items-center",children:[e.jsx(ge,{icon:Yt,theme:"aqua",size:"sm",className:"mb-2"}),e.jsx("div",{className:"text-xl font-bold text-text-primary",children:N?N.toLocaleStr
22ing("fr-FR"):"—"}),e.jsx("div",{className:"text-xs text-text-tertiary mt-0.5",children:"kg actuel"})]}),!A.hideBodyMetrics&&e.jsxs(G,{padding:"md",className:"text-center flex flex-col items-center",children:[e.jsx(ge,{icon:vt,theme:"flame",size:"sm",className:"mb-2"}),e.jsx("div",{className:"text-xl font-bold text-text-primary","data-body-fat-summary":!0,children:as(B.value)}),e.jsx("div",{className:"text-xs text-text-tertiary mt-0.5",children:"Masse grasse (%)"}),Z&&e.jsx("div",{className:"mt-0.5 text-xs leading-tight text-text-tertiary",children:Z})]}),e.jsxs(G,{padding:"md",className:"text-center flex flex-col items-center",children:[A.isPregnant?e.jsx(ge,{icon:dr,theme:"rose",size:"sm",className:"mb-2"}):F===null||Math.abs(F)<.05?e.jsx(ge,{icon:Gr,theme:"aqua",size:"sm",className:"mb-2"}):A.isGainObjective?F!==null&&F>0?e.jsx(ge,{icon:Ne,theme:"verdant",size:"sm",className:"mb-2"}):e.jsx(ge,{icon:Ee,theme:"gold",size:"sm",className:"mb-2"}):F!==null&&F<0?e.jsx(ge,{icon:Ee,theme:"verdant",size:"sm",className:"mb-2"}):e.jsx(ge,{icon:Ne,theme:"flame",size:"sm",className:"mb-2"}),e.jsx("div",{"data-weight-change":!0,className:`text-xl font-bold ${A.isPregnant?"text-pink-400":F===null||Math.abs(F)<.05?"text-text-primary":A.isGainObjective?F>0?"text-success":"text-amber-400":F<0?"text-success":"text-error"}`,children:F!==null?`${F>.05?"+":""}${F.toLocaleString("fr-FR",{minimumFractionDigits:1,maximumFractionDigits:1})}`:"—"}),e.jsx("div",{className:"text-xs text-text-tertiary mt-0.5",children:A.isPregnant?"kg (normal)":"Évolution (kg)"})]})]}),!t&&A.isLoseBellyObjective&&i.length>0&&e.jsx(gs,{waistData:i,currentWaist:k,startWaist:L,waistChange:D,latestWaistRisk:$,isLoseBellyObjective:!0}),!t&&n.length>0&&e.jsx(xi,{weights:n,currentWeight:N,targetWeight:A.targetWeight,isPregnant:A.isPregnant}),!t&&A.isGainObjective&&l.length>0&&e.jsx(bs,{muscleHistory:l,currentMuscleAvg:E,muscleChange:C,latestMuscleAssessment:H,isGainObjective:!0}),!t&&o.length>0&&e.jsx(fi,{bodyFatData:o,currentBodyFat:M,startBodyFat:_,bodyFatChange:S,targetBodyFat:A.targetBodyFat}),!t&&!A.isLoseBellyObjective&&i.length>0&&e.jsx(gs,{waistData:i,currentWaist:k,startWaist:L,waistChange:D,latestWaistRisk:$,isLoseBellyObjective:!1}),!t&&!A.isGainObjective&&l.length>0&&e.jsx(bs,{muscleHistory:l,currentMuscleAvg:E,muscleChange:C,latestMuscleAssessment:H,isGainObjective:!1}),!t&&T&&u&&e.jsx(pi,{compositionData:d,latestComposition:u}),e.jsx(ei,{injuries:h,painLogs:x,alloyAlert:g,onDismissAlloyAlert:v,onAddInjury:f,onUpdateStatus:b,onAddPainLog:w}),a.length>0&&e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-3",eyebrow:"Body scan",title:"Historique des scans",action:!t&&e.jsxs("span",{className:"text-xs text-text-tertiary",children:[a.length," scan",a.length>1?"s":""]})}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 -mx-2 px-2",children:a.map(re=>e.jsx(li,{scan:re,hideMeasurements:t,onViewScan:W,onDeleteScan:ke},re.id))})]}),(!P||t&&a.length===0)&&e.jsx(Cr,{density:"inline",state:"contextual_empty",title:"Aucun scan enregistré",description:"Ton premier scan apparaîtra ici après ton check-in avec Alloy.",theme:"aqua",icon:Ie})]}),e.jsx(zt,{open:O!==null,onClose:()=>W(null),title:"Photo du scan",maxWidthClassName:"sm:max-w-2xl",children:e.jsx("div",{className:"flex min-h-0 items-center justify-center p-4",children:O&&e.jsx(Nt,{scanId:O,className:"max-h-[70dvh] max-w-full rounded-lg object-contain",placeholderClassName:"w-64 h-80 rounded-lg"})})}),e.jsx(Ur,{isOpen:!!oe,onClose:()=>ke(null),onConfirm:ye,title:"Supprimer ce scan corporel",description:"Ce scan et toutes les photos associees seront definitivement supprimes."}),e.jsx(zt,{open:z&&a.length>=2,onClose:()=>ue(!1),title:"Comparaison",maxWidthClassName:"sm:max-w-4xl",children:e.jsx("div",{className:"p-4",children:a.length>=2&&e.jsx(Jn,{scans:a,userId:r?.id,qualitative:t})})})]})}function et({label:t,helpKey:s,children:r}){return e.jsx(_t,{label:t,children:e.jsx(Fr,{helpKey:s,children:r})})}function bi({recaps:t,timeline:s,comparisons:r,coachingPhase:n,level:a,gamification:o,qualitative:i,bodyComposition:l}){const[d,u]=c.useState(!1),h=!i&&l&&Ft(l.model,l.u)?.bodyFatPct!=null,x=i?"Scans et blessures":h?"Composition, scans, blessures et courbes":"Scans, blessures et courbes";return e.jsxs(e.Fragment,{children:[e.jsx("section",{className:"rounded-[20px] border border-white/[0.06] bg-surface-solid",children:e.jsxs("button",{type:"button",onClick:()=>u(!0),"aria-haspopup":"dialog","aria-expanded":d,className:"flex min-h-11 w-full items-center gap-3 px-3.5 py-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent",children:[e.jsxs("span",{className:"flex-1",children:[e.jsx("span",{className:"block text-[13.5px] font-medium text-text-primary",children:"Détails"}),e.jsx("span",{className:"block text-[10.5px] text-text-tertiary",children:x})]}),e.jsx(st,{className:`h-4 w-4 flex-none text-text-tertiary transition-transform ${d?"rotate-180":""}`,"aria-hidden":"true"})]})}),e.jsx(ur,{open:d,onClose:()=>u(!1),title:"Détails",eyebrow:x,children:e.jsxs("div",{className:"space-y-4 px-3.5 pb-4 pt-4",children:[h&&l&&e.jsx(_t,{label:"Composition corporelle",resetKeys:[d],children:e.jsx(Gn,{model:l.model,u:l.u,qualitative:i})}
22),e.jsx(_t,{label:x,resetKeys:[d],children:e.jsx(gi,{qualitative:i})}),!i&&e.jsxs(e.Fragment,{children:[e.jsx(et,{label:"Plan contre réalisé",helpKey:"progress.planVsActual",children:e.jsx(Yn,{recaps:t})}),(s.length>0||r.length>0)&&e.jsx(et,{label:"Progression dans le temps",helpKey:"progress.temporal",children:e.jsx(Kn,{timeline:s,comparisons:r,coachingPhase:n,level:a})}),e.jsx(et,{label:"Suivi de régularité",helpKey:"progress.heatmap",children:e.jsxs(G,{padding:"md",children:[e.jsx(ne,{className:"mb-4",reserveHelp:!0,eyebrow:"28 derniers jours",title:"Suivi de régularité"}),e.jsx(Zn,{recaps:t})]})}),e.jsx(et,{label:"Statistiques globales",helpKey:"progress.globalStats",children:e.jsx(Vn,{gamification:o})})]})]})})]})}const ys=ks(async()=>({default:(await kt(async()=>{const{BodyStudio:t}=await import("./BodyStudio-na_YPJqN.js");return{BodyStudio:t}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47]))).BodyStudio}),{reload:()=>{}}),yt=ks(async()=>({default:(await kt(async()=>{const{TwinPreviewStage:t}=await import("./TwinPreviewStage-e7NNtZpZ.js");return{TwinPreviewStage:t}},__vite__mapDeps([48,1,2,25,3,4,5,6,7,8,9,10,26]))).TwinPreviewStage}),{reload:()=>{}});function yi(){const{user:t,profile:s,loading:r}=at(),n=We(),a=!s||s.avoid_weight_language!==!1||s.eating_disorder_history!==!1||s.avoid_calorie_display!==!1||cn(s),o=a?void 0:t?.id,i=Lr(o),l=r&&!s,d=rn(o),u=sn(o,28),{scans:h,loading:x,error:f,refetch:b}=Er(t?.id),w=nn(o),g=en(o),v=a?null:i.gamification,m=a?!1:i.loading,y=a?null:i.error,p=i.refetch,R=a?[]:d.progress.recaps,N=a?!1:d.loading,F=a?null:d.error,M=d.refetch,_=a?[]:u.recaps,S=a?!1:u.loading,k=a?null:u.error,L=u.refetch,D=a?null:w.prediction,$=a?!1:w.insufficientData,E=a?!1:w.loading,C=a?null:w.error,H=w.refetch,A=a?[]:g.timeline,de=a?[]:g.comparisons,{enabled:j,loading:P}=Dr("body_twin_3d_v2",t?.id),T=h[0],B=Pr(t?.id,T?.id,j),Z=j&&B.loading,O=j?B.error:null,W=c.useMemo(()=>vr(),[]),z=Zt(j?B.twin?.base_model:null,s?.gender),[ue,oe]=c.useState(0),[ke,be]=c.useState("Tout"),ye=c.useRef(null),re={wear:!0,cap:!0,sock:!1},me=Es(a?void 0:t?.id,90),le=(me.latest&&(!T||Date.parse(me.latest.logged_at)>Date.parse(T.scanned_at))?me.latest?.weight_kg:null)??T?.weight_kg??s?.current_weight_kg??null,fe=T?.estimated_body_fat_pct??null,he=Qa({userId:t?.id,latestScan:T,measurementOverride:j?B.measurementOverride:null,heightCm:s?.height_cm,weightKg:le,bodyFatPct:fe,appendOnly:j,onSaved:()=>{b(),j&&B.refresh()}}),J=c.useMemo(()=>wr(Xt(T,s?.height_cm,le),he.getMeasurementProps()),[T,s?.height_cm,le,he]),xe=c.useMemo(()=>Nr(T,s),[T,s]),ce=Mn(t?.id,T?.id,z,J),[Q,q]=c.useState({scopeKey:ce,state:"idle"}),ve=c.useRef({scopeKey:ce,requestId:0});Ls(ve.current,ce);const ee=Q.scopeKey===ce?Q.state:"idle",De=D?.projected_date_realistic??null,Ge=c.useMemo(()=>_n({scans:h,targetDate:a||!De?null:new Date(De),targetWeightKg:a?null:s?.target_weight_kg??null,targetBodyFatPct:a?null:s?.target_body_fat_pct??null}),[h,De,a,s?.target_weight_kg,s?.target_body_fat_pct]),ae=c.useMemo(()=>vn(Ge,J),[Ge,J]);c.useEffect(()=>{oe(ae.uToday)},[ae.uToday]);const Ue=c.useCallback(()=>{Rn(ae.uToday,oe,ye.current)},[ae.uToday]),Rt=In({scopeKey:`${t?.id}:${T?.id}:${z}`,saved:J,onSave:he.saveMeasurement,onReturnToToday:Ue}),it=dn({scopeKey:`${t?.id}:${T?.id}:${z}`,saved:mt(B.twin?.muscle_appearance_override),onSave:B.saveMuscleAppearance,onReturnToToday:Ue,atToday:Math.abs(ue-ae.uToday)<1e-6}),Et=(j?$r(B.twin):null)??Ar(kr(T)),Lt=Br(Et),Dt=Lt.hex,Ps=Et!==null,$s=c.useCallback(async Us=>{const Ht=ve.current,It=Cn(Ht,ce),Ke=()=>Fn(Ht,It),Xe=zs=>{Ke()&&q({scopeKey:It.scopeKey,state:zs})},ct=Nn(D);if(!ct||!z||!ae.hasFuture||le==null||fe==null){Xe("unavailable");return}Xe("preparing");const Wt=await Sn({sex:z,heightCm:s?.height_cm??170,weightKg:le,bodyFatPct:fe,vals:Wr(z,J)},ct,wn(ae,1),s?.target_weight_kg??null,s?.target_body_fat_pct??null);if(!Ke())return;if(!Wt){Xe("unavailable");return}const Ys=await Us.preresolve(Wt.key,ct,Ke);Ke()&&Xe(Ys==="ok"?"ready":"unavailable")},[D,z,ae,le,fe,s?.height_cm,s?.target_weight_kg,s?.target_body_fat_pct,J,ce]),As=m||l||N||S,Tt=v?.level??1,Bs=v?.total_xp??0,Os=!(Tt>1||Bs>0||R.length>0||_.length>0)&&!T?f:null,Hs=[y,F,k,Os].find(Boolean)??null,Is=c.useCallback(()=>{p(),M(),L(),b(),H()},[p,M,L,b,H]),Pt=a?null:T?le==null?"Ton poids n’est pas encore mesuré.":fe==null?Rs(h).value!=null?"Ta masse grasse n’a pas été mesurée sur ton dernier scan : la projection attend un scan qui la mesure.":"Ta composition corporelle n’est pas encore mesurée.":!s?.objective&&!D?.objective?"Ton objectif corporel n’est pas encore renseigné.":ae.hasFuture?z?null:"Le twin 3D n’a pas encore de morphologie de référence.":"Pas encore de projection : elle se calcule chaque dimanche.":"Envoie trois photos à Alloy — face, profil, dos : ton twin prendra tes vraies mesures.",Ye=x||P||!!(T&&Z),Se=mr(t?.id,s),ze=c.useRef(),qe=f||(T?O:null);!Ye&&!qe&&(ze.current=Se);const pe=Ye&&ze.current!==Se,Te=T?z?"measured":"repair":a?"protected":"empty",Pe=br[Te],Ws=hr(Se),$t=c.useId();c.useEffect(()=>{ys.preload(),yt.preload()},[]);const ot=Zt(null,s?.gender),At=j&&W.eligible;c.useEffect(()=>{!At||!ot||Hr({sex:ot,dpr:W.maxPixelRatio,idle:W.idle})},[At,ot,W]);const Bt={prediction:T?D:null,loading:a||!x&&!T?!1:pe||E||Z,error:a?null:C??O,insufficientData:$,qualitative:a,onRetry:()=>{H(),j&&B.refresh()}},Gs=!P&&!Z&&!O,Ot=e.jsx(gn,{...Sr(J),gender:z,muscleAssessment:a?null:T?.muscle_assessment,initialView:"measure",hideMeasurements:a}),lt=!W.eligible&&W.reason?Mr[W.reason]:null;return xr({title:"Progression",subtitle:"Ton corps et ta trajectoire"}),e.jsx("div",{className:"bg-background",children:e.jsx(K.div,{variants:fr,initial:n?!1:"hidden",animate:"visible",className:"mx-auto max-w-lg",children:e.jsxs(e.Fragment,{children:[e.jsx(pr,{name:"progress-body",scope:Se,minHeight:yr+12,pending:pe,resolved:!Ye&&!qe,variant:pe?void 0:Te,children:e.jsx(Vt,{loading:!1,loadingFallback:null,refreshing:Ye&&!pe,error:ze.current===Se?null:qe,refreshError:ze.current===Se?qe:null,onRetry:()=>{b(),j&&B.refresh()},errorTitle:"Twin corporel indisponible",errorMessage:"Impossible de charger ton twin pour le moment.",children:e.jsxs(K.div,{variants:qt,className:"pt-3",children:[e.jsxs("section",{"data-body-card":pe?"pending":Te,"data-body-studio":!pe&&Te==="measured"?"":void 0,className:!pe&&Te==="repair"?"mx-3.5 overflow-hidden rounded-[22px] border border-blue-400/20 bg-surface-solid":gr,"aria-labelledby":$t,children:[e.jsx("h2",{id:$t,className:"sr-only",children:"Ton corps et sa trajectoire"}),e.jsx(On,{...Bt,unavailableReason:Pt}),pe?e.jsx(Ve,{height:Ws,announce:!0}):T?z?e.jsx(c.Suspense,{fallback:e.jsx(Ve,{height:Pe,announce:!0}),children:e.jsx(Or,{resetKeys:[t?.id,T.id,z],fallback:e.jsx("div",{className:"px-3.5",children:Ot}),children:e.jsx(ys,{ref:ye,entityKey:`${t?.id??"anonymous"}:${T.id}`,sex:z,enabled:j&&W.eligible,model:ae,u:ue,onSeekU:oe,measurements:J,previewMeasurements:Rt.preview,hideMeasurements:a,muscleSignal:xe,muscleAppearance:it.appearance,onAppearance:it.observe,skinTone:Lt,wear:re,maxPixelRatio:W.maxPixelRatio,idle:W.idle,ineligibleReason:lt,fallback:Ot,projectionState:ee,projectionUnavailableReason:Pt,onPrepareProjection:$s,projection:Bt,measurementEditor:Rt,muscleEditor:it,group:ke,onGroupChange:be,saving:he.s
22aving,muscleControlsAvailable:j&&W.eligible})})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-white/[0.06] px-4 pt-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-accent",children:"Twin corporel · scan mesuré"}),e.jsx("h2",{className:"mt-1 font-display text-base font-bold text-text-primary",children:"Ta base 3D reste à finaliser"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-text-secondary",children:"Ton scan est conservé. Confirme Homme ou Femme dans l’onboarding pour reconstruire ton morph sans base arbitraire."})]}),e.jsx(c.Suspense,{fallback:e.jsx(Ve,{height:Pe,announce:!0,className:"px-3 pb-3 pt-3"}),children:e.jsx(yt,{entityKey:`${t?.id??"anonymous"}:${T.id}:repair`,storedSex:j?B.twin?.base_model:null,profileGender:s?.gender,measurements:J,muscleSignal:xe,muscleAppearance:mt(B.twin?.muscle_appearance_override),render:"holo",enabled:j&&W.eligible,maxPixelRatio:W.maxPixelRatio,idle:W.idle,ineligibleReason:lt,skinToneHex:Dt,height:Pe,label:"Base 3D à finaliser",className:"px-3 pb-3 pt-3",repairReturnTo:"/progress"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(c.Suspense,{fallback:e.jsx(Ve,{height:Pe,announce:!0}),children:e.jsx(yt,{entityKey:`${t?.id??"anonymous"}:progress:no-scan`,storedSex:null,profileGender:s?.gender,muscleSignal:xe,muscleAppearance:mt(B.twin?.muscle_appearance_override),measurements:Xt(null,s?.height_cm,s?.current_weight_kg),render:"skin",skinToneHex:Dt,enabled:j&&W.eligible,maxPixelRatio:W.maxPixelRatio,idle:W.idle,ineligibleReason:lt,height:Pe,frameWholeBody:!0,label:"Aperçu 3D générique, non mesuré",repairReturnTo:"/progress"})}),e.jsx("p",{className:"px-4 pb-3 text-center text-xs text-text-secondary",children:"Aperçu non mesuré"})]})]}),!pe&&T&&z&&!Ps&&e.jsx("p",{className:"mx-3.5 mt-2 rounded-xl border border-blue-400/20 bg-blue-400/[0.07] px-3 py-2.5 text-sm leading-relaxed text-text-secondary",role:"status",children:"Carnation par défaut : ton twin porte une teinte médiane jusqu’à ton premier scan."})]})})}),e.jsx(Vt,{loading:As,error:Hs,loadingFallback:e.jsx("div",{className:"px-3.5 pb-[18px] pt-3.5",children:e.jsx(jr,{})}),onRetry:Is,errorTitle:"Progression indisponible",errorMessage:"Impossible de charger tes repères de progression pour le moment.",children:e.jsx("div",{className:"flex flex-col gap-3 px-3.5 pb-[18px] pt-3.5",children:e.jsx(K.div,{variants:qt,children:e.jsx(bi,{bodyComposition:Gs&&!a&&ae.points.length>0?{model:ae,u:ue}:void 0,recaps:_,timeline:A,comparisons:de,coachingPhase:s?.coaching_phase,level:Tt,gamification:v,qualitative:a})})})})]})})})}const xo=Object.freeze(Object.defineProperty({__proto__:null,ProgressPage:yi},Symbol.toStringTag,{value:"Module"}));export{ho as M,io as P,uo as S,ds as a,co as b,oo as c,Tn as d,mo as e,xo as f,lo as i,wn as m,Ft as s};

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.