1import{u as U,b as C,c as P,j as e,P as Me}from"./index-D5yTtBfj.js";import{r as l,u as Y,d as Fe,f as Pe,h as R,i as T,e as Te}from"./react-w2_hd-Mb.js";import{H as qe,bm as ae,b2 as We,T as ee,bn as Ae,au as je,ae as De,U as Ee,$ as me,X as Q,G as ve,g as we,aJ as ie,N as ye,bo as Re,h as Oe,bk as de,a9 as K,bp as te,bh as fe,bq as ce,a8 as G,ao as xe,S as $e,aK as ge,aL as Ue,aM as Be,aO as Ge,aa as ue,aI as He,W as Ke,Q as Je,a as Ne,br as Ve,bs as _e,r as Ye,ap as Qe,aq as Xe,E as Ze,bt as et,bu as tt}from"./lucide-ZnjHBfqS.js";import{R as X,L as le,f as re,X as ne,Y as oe,T as Z,g as V,h as ke,i as st,j as at,C as lt}from"./recharts-CniQ4Sg7.js";import"./supabase-DkYWVPkI.js";const J=()=>{const{user:t}=U(),[s,d]=l.useState(null),[a,p]=l.useState(null),[c,j]=l.useState([]),[h,f]=l.useState(navigator.onLine),[w,g]=l.useState(!0),[n,r]=l.useState(0);l.useEffect(()=>{const o=()=>{f(!0),S()},m=()=>f(!1);return window.addEventListener("online",o),window.addEventListener("offline",m),()=>{window.removeEventListener("online",o),window.removeEventListener("offline",m)}},[]);const x=async()=>{if(t!=null&&t.id)try{const{count:o}=await C.from("nutritional_chat_messages").select("*",{count:"exact",head:!0}).eq("student_id",t.id).eq("sender_type","admin").eq("is_read",!1);r(o||0)}catch(o){console.error(o)}};l.useEffect(()=>{if(t!=null&&t.id){v(),x();const o=C.channel("sync_chat_unread").on("postgres_changes",{event:"INSERT",schema:"public",table:"nutritional_chat_messages",filter:`student_id=eq.${t.id}`},m=>{m.new.sender_type==="admin"&&!m.new.is_read&&r(L=>L+1)}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"nutritional_chat_messages",filter:`student_id=eq.${t.id}`},m=>{x()}).subscribe();return()=>{C.removeChannel(o)}}else g(!1)},[t==null?void 0:t.id]);const v=async()=>{g(!0);try{const{data:o}=await C.from("student_charts").select("*").eq("student_id",t.id).single();if(o)d(o),o.accepted_legal_terms&&localStorage.setItem(`pwa_legal_terms_accepted_${t.id}`,"true");else{const z={student_id:t.id,daily_calorie_target:1800,target_protein_g:100,target_carbs_g:200,target_fat_g:50,target_water_ml:2e3,current_weight_kg:65,target_weight_kg:58,accepted_legal_terms:!1};await C.from("student_charts").insert([z]),d(z)}const{data:m}=await C.from("weekly_supports").select("*").eq("student_id",t.id).order("updated_at",{ascending:!1}).limit(1).single();p(m||{week_phase:"week_1",period_label:"Week 1",weekly_tasks:[{id:"1",text_ja:"æ¯é£åã«æ°´500mlã飲ã",text_en:"Drink 500ml water before meals"},{id:"2",text_ja:"ã¿ã³ãã¯è³ªããé£ã¹ã",text_en:"Eat protein first"},{id:"3",text_ja:"æ©æ°ã確èªãã",text_en:"Check daily steps"},{id:"4",text_ja:"éåãã¼ã¿ã«30å以ä¸",text_en:"Exercise 30+ minutes"}],next_week_action_admin:""});const{data:L}=await C.from("body_composition_logs").select("*").eq("student_id",t.id).order("log_date",{ascending:!0});L&&j(L)}catch(o){console.error("Error fetching nutritional profile:",o)}finally{g(!1)}},k=async()=>{if(t!=null&&t.id)try{localStorage.setItem(`pwa_legal_terms_accepted_${t.id}`,"true"),await C.from("student_charts").update({accepted_legal_terms:!0,legal_terms_accepted_at:new Date().toISOString()}).eq("student_id",t.id),d(o=>o?{...o,accepted_legal_terms:!0}:null)}catch(o){console.error("Error accepting legal terms:",o)}},S=async()=>{try{const o=JSON.parse(localStorage.getItem("pwa_offline_meals_queue")||"[]");o.length>0&&(await C.from("daily_meal_logs").insert(o),localStorage.removeItem("pwa_offline_meals_queue"))}catch{}};return{chart:s,weeklySupport:a,bodyLogs:c,isOnline:h,isLoading:w,unreadChatCount:n,acceptLegalTerms:k,saveMealLog:async o=>{if(!(t!=null&&t.id))return;const m={...o,student_id:t.id};if(!h){const F=JSON.parse(localStorage.getItem("pwa_offline_meals_queue")||"[]");return F.push(m),localStorage.setItem("pwa_offline_meals_queue",JSON.stringify(F)),{offline:!0}}const{data:L,error:z}=await C.from("daily_meal_logs").insert([m]).select().single();if(z)throw z;return L},saveExerciseLog:async o=>{if(!(t!=null&&t.id))return;const m={...o,student_id:t.id};if(!h){const F=JSON.parse(localStorage.getItem("pwa_offline_exercise_queue")||"[]");return F.push(m),localStorage.setItem("pwa_offline_exercise_queue",JSON.stringify(F)),{offline:!0}}const{data:L,error:z}=await C.from("daily_exercise_logs").upsert([m],{onConflict:"student_id,log_date"}).select().single();if(z)throw z;return L},saveTaskCheck:async o=>{if(!(t!=null&&t.id))return;const m={...o,student_id:t.id};if(!h){const F=JSON.parse(localStorage.getItem("pwa_offline_task_queue")||"[]");return F.push(m),localStorage.setItem("pwa_offline_task_queue",JSON.stringify(F)),{offline:!0}}const{data:L,error:z}=await C.from("daily_task_checks").upsert([m],{onConflict:"student_id,log_date"}).select().single();if(z)throw z;return L},saveBodyLog:async o=>{if(t)try{const{data:m,error:L}=await C.from("body_composition_logs").insert([{student_id:t.id,log_date:new Date().toISOString().split("T")[0],day_type:"daily",weight_kg:o.weight_kg,body_fat_percent:o.body_fat_percent,muscle_mass_kg:o.muscle_mass_kg,metabolic_age:o.metabolic_age,visceral_fat_level:o.visceral_fat_level}]).select().single();m&&!L&&(j(z=>[...z,m].sort((F,O)=>new Date(F.log_date).getTime()-new Date(O.log_date).getTime())),o.weight_kg&&(await C.from("student_charts").update({current_weight_kg:o.weight_kg}).eq("student_id",t.id),d(z=>z?{...z,current_weight_kg:o.weight_kg}:null)))}catch(m){console.error(m)}},refetchProfile:v}},rt=({unreadChatCount:t=0})=>{const s=Y(),d=Fe(),{language:a,setLanguage:p,t:c}=P(),[j,h]=l.useState(!1),f=d.pathname,w=[{label:c("nutritional.nav.home"),icon:qe,path:"/app"},{label:c("nutritional.nav.meals"),icon:ae,path:"/app/meals"},{label:c("nutritional.nav.chat"),icon:We,path:"/app/chat",badge:t},{label:c("nutritional.nav.goals"),icon:ee,path:"/app/goals"},{label:c("nutritional.nav.more"),icon:Ae,action:"more"}],g=[{label:c("nutritional.nav.exercise"),icon:je,path:"/app/exercise"},{label:c("nutritional.nav.progress"),icon:De,path:"/app/progress"},{label:c("nutritional.nav.profile"),icon:Ee,path:"/app/profile"},{label:c("nutritional.nav.legal"),icon:me,path:"/app/legal"}],n=x=>{x.action==="more"?h(!j):(h(!1),s(x.path))},r=async()=>{h(!1),await C.auth.signOut(),s("/app/login")};return e.jsxs(e.Fragment,{children:[e.jsx("nav",{className:"fixed bottom-3 left-1/2 -translate-x-1/2 w-[92%] max-w-sm z-50",children:e.jsx("div",{className:"bg-white/90 backdrop-blur-2xl border border-emerald-100/80 shadow-[0_12px_40px_rgba(16,185,129,0.12)] rounded-3xl p-1.5 flex items-center justify-around",children:w.map(x=>{const k=x.action==="more"?j:f===x.path||x.path!=="/app"&&f.startsWith(x.path),S=x.icon;return e.jsxs("button",{type:"button",onClick:()=>n(x),className:`relative flex flex-col items-center justify-center py-2 px-3 rounded-2xl transition-all duration-300 active:scale-95 ${k?"text-emerald-700 bg-emerald-500/10 font-bold scale-105":"text-slate-400 hover:text-slate-700 hover:bg-slate-50"}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(S,{size:20,strokeWidth:k?2.5:1.8,className:k?"text-emerald-600":""}),x.badge&&x.badge>0?e.jsx("span",{className:"absolute -top-1.5 -right-2.5 w-4 h-4 rounded-full bg-rose-500 text-white text-[9px] font-extrabold flex items-center justify-center border-2 border-white shadow-sm animate-pulse",children:x.badge}):null]}),e.jsx("span",{className:"text-[9.5px] tracking-tight mt-1 whitespace-nowrap font-bold",children:x.label}),k&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 absolute -bottom-0.5 shadow-xs"})]},x.label)})})}),j&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-slate-950/40 backdrop-blur-md z-40 animate-fadeIn",onClick:()=>h(!1)}),e.jsxs("div",{className:"fixed bottom-20 left-1/2 -translate-x-1/2 w-[92%] max-w-sm z-50 bg-[#FAF8F5] rounded-3xl p-5 border border-emerald-100 shadow-2xl space-y-4 animate-slideUp",children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 border-b border-slate-200/60",children:[e.jsx("h3",{className:"text-xs font-extrabold text-slate-700 uppercase tracking-wider font-serif-jp",children:c("nutritional.nav.moreTitle")}),e.jsx("button",{type:"button",onClick:()=>h(!1),className:"w-8 h-8 rounded-full bg-white text-slate-400 hover:text-slate-700 border border-slate-200/60 flex items-center justify-center transition-transform active:scale-95 shadow-2xs",children:e.jsx(Q,{size:16})})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:g.map(x=>
1{const v=x.icon;return e.jsxs("button",{type:"button",onClick:()=>{h(!1),s(x.path)},className:"p-3.5 bg-white hover:bg-emerald-50/80 text-slate-700 hover:text-emerald-700 rounded-2xl border border-slate-100 hover:border-emerald-200 transition-all flex items-center gap-3 text-xs font-bold text-left active:scale-[0.98] shadow-2xs",children:[e.jsx("div",{className:"w-8 h-8 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center flex-shrink-0",children:e.jsx(v,{size:18})}),e.jsx("span",{children:x.label})]},x.path)})}),e.jsxs("div",{className:"p-3.5 bg-white rounded-2xl border border-slate-100 shadow-2xs flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 font-bold text-slate-600",children:[e.jsx(ve,{size:16,className:"text-emerald-600"}),e.jsx("span",{children:c("nutritional.nav.language")})]}),e.jsxs("div",{className:"flex gap-1 bg-slate-50 p-1 rounded-xl border border-slate-200/60",children:[e.jsx("button",{type:"button",onClick:()=>p("ja"),className:`px-3 py-1 rounded-lg text-[10px] font-bold transition-all ${a==="ja"?"bg-emerald-600 text-white shadow-2xs":"text-slate-500 hover:text-slate-800"}`,children:"æ¥æ¬èª"}),e.jsx("button",{type:"button",onClick:()=>p("en"),className:`px-3 py-1 rounded-lg text-[10px] font-bold transition-all ${a==="en"?"bg-emerald-600 text-white shadow-2xs":"text-slate-500 hover:text-slate-800"}`,children:"English"})]})]}),e.jsxs("button",{type:"button",onClick:r,className:"w-full py-3.5 bg-rose-50 hover:bg-rose-100 text-rose-600 rounded-2xl text-xs font-bold transition-all flex items-center justify-center gap-2 border border-rose-200/60 shadow-2xs active:scale-[0.98]",children:[e.jsx(we,{size:16}),e.jsx("span",{children:c("nutritional.nav.logout")})]})]})]})]})},nt=({isOpen:t,onAccept:s})=>{const{language:d,t:a}=P(),[p,c]=l.useState(!1);return t?e.jsx("div",{className:"fixed inset-0 z-[100] bg-slate-950/75 backdrop-blur-md flex items-center justify-center p-4 animate-fadeIn",children:e.jsxs("div",{className:"bg-white rounded-[2.5rem] max-w-lg w-full p-6 sm:p-8 border border-stone-100 shadow-2xl relative overflow-hidden max-h-[90vh] flex flex-col justify-between",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-2 bg-gradient-to-r from-emerald-400 via-teal-500 to-emerald-600"}),e.jsxs("div",{children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl bg-emerald-50 text-emerald-600 flex items-center justify-center mb-4 border border-emerald-100 shadow-sm",children:e.jsx(me,{size:28})}),e.jsx("h2",{className:"text-2xl font-bold text-stone-900 font-serif-jp tracking-tight",children:a("nutritional.legal.title")}),e.jsx("p",{className:"text-xs text-stone-500 font-bold uppercase tracking-widest mt-1",children:a("nutritional.legal.subtitle")}),e.jsxs("div",{className:"my-6 p-4 rounded-2xl bg-stone-50 border border-stone-200/80 text-xs text-stone-600 space-y-3 max-h-56 overflow-y-auto font-medium leading-relaxed",children:[e.jsx("p",{children:a("nutritional.legal.body")}),e.jsxs("div",{className:"p-3 bg-amber-50 rounded-xl border border-amber-200/70 text-amber-800 flex items-start gap-2",children:[e.jsx(ie,{size:16,className:"flex-shrink-0 mt-0.5"}),e.jsx("span",{children:d==="ja"?"æ¬ã¢ããªã¯å»çè¡çºã»è¨ºæã»å¦æ¹ãè¡ããã®ã§ã¯ããã¾ãããæç
ã®ããæ¹ãéé¢ä¸ã®æ¹ã¯ãå¿
ã主治å»ã«ãç¸è«ãã ããã":"This app does not provide medical treatment, diagnosis, or prescriptions. If you have any medical conditions, please consult your physician."})]}),e.jsx("p",{children:d==="ja"?"ç»é²ããããã¼ã¿ããã³åçã¯Supabaseãã©ãããã©ã¼ã ä¸ã§æ©å¯ç®¡çããããæ¬äººã¨èªå®ãããæå°ã¹ã¿ããã®ã¿ãã¢ã¯ã»ã¹ã§ãã¾ãã":"All registered data and photos are securely managed on the Supabase platform and are accessible only by you and authorized coaching staff."})]})]}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("label",{className:"flex items-center gap-3 p-3 rounded-2xl bg-stone-50 border border-stone-200/80 cursor-pointer hover:bg-stone-100 transition-colors",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:j=>c(j.target.checked),className:"w-5 h-5 rounded-lg text-emerald-600 focus:ring-emerald-500 border-stone-300"}),e.jsx("span",{className:"text-xs font-bold text-stone-700",children:a("nutritional.legal.checkbox")}
1)]}),e.jsxs("button",{type:"button",disabled:!p,onClick:s,className:`w-full py-4 rounded-2xl font-bold text-sm transition-all flex items-center justify-center gap-2 shadow-lg ${p?"bg-gradient-to-r from-emerald-500 to-teal-500 text-white shadow-emerald-500/25 hover:shadow-emerald-500/40 active:scale-[0.98]":"bg-stone-200 text-stone-400 cursor-not-allowed shadow-none"}`,children:[e.jsx(ye,{size:18}),e.jsx("span",{children:a("nutritional.legal.accept")})]})]})]})}):null},ot=({isOpen:t,onClose:s,onSelectMeal:d})=>{const{language:a,t:p}=P(),{session:c}=U(),[j,h]=l.useState([]),[f,w]=l.useState(""),[g,n]=l.useState("all"),[r,x]=l.useState(null),[v,k]=l.useState(100),[S,y]=l.useState(!1);l.useEffect(()=>{t&&b()},[t]);const b=async()=>{var N;if((N=c==null?void 0:c.user)!=null&&N.id){y(!0);try{const{data:I}=await C.from("nutritional_preset_meals").select("*").eq("is_active",!0).order("name_ja",{ascending:!0});I&&h(I)}catch(I){console.error("Error fetching presets:",I)}finally{y(!1)}}};if(!t)return null;const u=j.filter(N=>{const M=(a==="en"?N.name_en:N.name_ja).toLowerCase().includes(f.toLowerCase()),q=g==="all"||N.category===g;return M&&q}),_={all:a==="ja"?"å
¨ã¦":"All",breakfast:p("nutritional.meals.breakfast"),lunch:p("nutritional.meals.lunch"),dinner:p("nutritional.meals.dinner"),snack:p("nutritional.meals.snack")},o=r?v/(r.default_portion_g||100):1,m=r?Math.round(r.calories_kcal*o):0,L=r?Number((r.protein_g*o).toFixed(1)):0,z=r?Number((r.carbs_g*o).toFixed(1)):0,F=r?Number((r.fat_g*o).toFixed(1)):0,O=()=>{if(!r)return;const N=a==="en"?r.name_en:r.name_ja;d({name:`${N} (${v}g)`,calories:m,portion_g:v,protein_g:L,carbs_g:z,fat_g:F}),s()},A=N=>{k(I=>Math.max(10,I+N))};return e.jsx("div",{className:"fixed inset-0 z-[100] bg-slate-950/40 backdrop-blur-md flex items-center justify-center p-4 animate-fadeIn",children:e.jsxs("div",{className:"bg-[#FAF8F5] rounded-[2.5rem] max-w-lg w-full p-6 sm:p-8 border border-emerald-100/80 shadow-2xl relative flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"flex items-center justify-between pb-4 border-b border-stone-100",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-emerald-50 text-emerald-600 flex items-center justify-center",children:e.jsx(Re,{size:20})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-stone-900 font-serif-jp",children:a==="ja"?"é£åãªã¹ãããé¸ã¶":"Choose from Food List"}),e.jsx("p",{className:"text-[11px] text-stone-400 font-medium",children:a==="ja"?"飿ãé¸ãã§éã調æ´ãã¦ãã ãã":"Select a food item and adjust the amount"})]})]}),e.jsx("button",{type:"button",onClick:s,className:"w-8 h-8 rounded-full bg-stone-100 text-stone-500 hover:bg-stone-200 flex items-center justify-center",children:e.jsx(Q,{size:16})})]}),e.jsxs("div",{className:"py-4 space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Oe,{size:16,className:"absolute left-3.5 top-3.5 text-stone-400"}),e.jsx("input",{type:"text",value:f,onChange:N=>w(N.target.value),placeholder:a==="ja"?"é£æãæ¤ç´¢...":"Search food...",className:"w-full bg-stone-50 border border-stone-200 rounded-2xl py-2.5 pl-10 pr-4 text-xs font-medium outline-none focus:border-emerald-500 focus:bg-white transition-all"})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1 scrollbar-none",children:Object.entries(_).map(([N,I])=>e.jsx("button",{type:"button",onClick:()=>n(N),className:`px-3 py-1.5 rounded-xl text-xs font-bold whitespace-nowrap transition-all ${g===N?"bg-emerald-500 text-white shadow-sm":"bg-stone-100 text-stone-600 hover:bg-stone-200"}`,children:I},N))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto space-y-2 pr-1 my-2 min-h-[200px]",children:S?e.jsx("div",{className:"text-center py-10 text-stone-400 text-xs font-medium",children:a==="ja"?"飿ãèªã¿è¾¼ã¿ä¸...":"Loading foods..."}):u.length===0?e.jsx("div",{className:"text-center py-10 text-stone-400 text-xs font-medium",children:a==="ja"?"該å½ãã飿ãè¦ã¤ããã¾ãã":"No foods found matching your search"}):u.map(N=>{const I=a==="en"?N.name_en:N.name_ja,M=(r==null?void 0:r.id)===N.id;return e.jsxs("div",{onClick:()=>{x(N),k(N.default_portion_g||100)},className:`p-3.5 rounded-2xl border transition-all cursor-pointer flex items-center justify-between ${M?"bg-emerald-50/80 border-emerald-300 shadow-sm":"bg-white border-stone-100 hover:bg-stone-50"}`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-bold text-stone-800",children:I}),e.jsxs("div",{className:"text-[10px] text-stone-500 flex items-center gap-2 mt-1 font-medium",children:[e.jsxs("span",{children:[N.default_portion_g,"g"]}),e.jsx("span",{children:"â¢"}),e.jsxs("span",{className:"text-amber-600 font-bold flex items-center gap-0.5",children:[e.jsx(de,{size:10}
1)," ",N.calories_kcal," kcal"]}),e.jsx("span",{children:"â¢"}),e.jsxs("span",{children:["P:",N.protein_g,"g C:",N.carbs_g,"g F:",N.fat_g,"g"]})]})]}),M&&e.jsx("div",{className:"w-6 h-6 rounded-full bg-emerald-500 text-white flex items-center justify-center",children:e.jsx(K,{size:14})})]},N.id)})}),r&&e.jsxs("div",{className:"pt-4 border-t border-slate-200/80 space-y-4 animate-fadeIn",children:[e.jsxs("div",{className:"bg-emerald-50/80 border border-emerald-200/80 rounded-2xl p-3.5 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-extrabold text-emerald-700 uppercase tracking-wider block",children:a==="ja"?"追å ãããã«ããªã¼":"Calculated Intake"}),e.jsxs("span",{className:"text-xl font-extrabold text-emerald-700 tabular-nums",children:[m," ",e.jsx("span",{className:"text-xs font-bold",children:"kcal"})]})]}),e.jsxs("div",{className:"text-[11px] font-bold text-slate-600 bg-white/80 px-3 py-1.5 rounded-xl border border-emerald-100 flex items-center gap-2",children:[e.jsxs("span",{children:["P: ",L,"g"]}),e.jsx("span",{className:"text-slate-300",children:"|"}),e.jsxs("span",{children:["C: ",z,"g"]}),e.jsx("span",{className:"text-slate-300",children:"|"}),e.jsxs("span",{children:["F: ",F,"g"]})]})]}),e.jsxs("div",{className:"bg-white p-4 rounded-2xl border border-slate-200/80 space-y-2.5 shadow-2xs",children:[e.jsx("label",{className:"text-xs font-extrabold text-slate-700 uppercase tracking-wider block",children:a==="ja"?"åéã»éã (g)":"Amount (grams)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>A(-50),className:"h-11 px-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 font-extrabold text-xs rounded-xl active:scale-95 transition-all border border-slate-200/80",children:"-50g"}),e.jsx("button",{type:"button",onClick:()=>A(-10),className:"h-11 px-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 font-extrabold text-xs rounded-xl active:scale-95 transition-all border border-slate-200/80",children:"-10g"})]}),e.jsx("div",{className:"relative flex-1",children:e.jsx("input",{type:"number",value:v,onChange:N=>k(Math.max(10,Number(N.target.value))),className:"w-full h-11 bg-slate-50 border border-slate-300 rounded-xl px-2 text-center text-base font-extrabold text-slate-900 outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all tabular-nums"})}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:()=>A(10),className:"h-11 px-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 font-extrabold text-xs rounded-xl active:scale-95 transition-all border border-slate-200/80",children:"+10g"}),e.jsx("button",{type:"button",onClick:()=>A(50),className:"h-11 px-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 font-extrabold text-xs rounded-xl active:scale-95 transition-all border border-slate-200/80",children:"+50g"})]})]})]}),e.jsxs("button",{type:"button",onClick:O,className:"w-full h-14 bg-gradient-to-r from-emerald-500 via-teal-500 to-emerald-600 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-extrabold text-sm shadow-lg shadow-emerald-500/25 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:[e.jsx(te,{size:18,strokeWidth:2.5}),e.jsx("span",{children:a==="ja"?"é£äºã«è¿½å ãã":"Add to Meal"})]})]})]})})},it=(t,s=1200,d=.8)=>new Promise((a,p)=>{if(t.size<200*1024){a(t);return}const c=new FileReader;c.readAsDataURL(t),c.onload=j=>{var f;const h=new Image;h.src=(f=j.target)==null?void 0:f.result,h.onload=()=>{const w=document.createElement("canvas");let g=h.width,n=h.height;g>s&&(n=Math.round(n*s/g),g=s),w.width=g,w.height=n;const r=w.getContext("2d");if(!r){a(t);return}r.drawImage(h,0,0,g,n),w.toBlob(x=>{a(x||t)},"image/jpeg",d)},h.onerror=()=>a(t)},c.onerror=()=>a(t)}),Se=({currentPhotoUrl:t,onPhotoUploaded:s,onRemovePhoto:d})=>{const{language:a}=P(),[p,c]=l.useState(!1),[j,h]=l.useState(null),f=l.useRef(null),w=l.useRef(null),g=async n=>{var x;const r=(x=n.target.files)==null?void 0:x[0];if(r){if(!r.type.startsWith("image/")){h(a==="ja"?"æå¹ãªç»åãã¡ã¤ã«ã鏿ãã¦ãã ãã (JPG, PNG, WebP)":"Please select a valid image file (JPG, PNG, WebP)");return}if(r.size>15*1024*1024){h(a==="ja"?"åçã¯15MB以ä¸ã«ãã¦ãã ãã":"Photo must be under 15
1MB");return}c(!0),h(null);try{const v=await it(r,1200,.8),k=new File([v],`meal_${Date.now()}.jpg`,{type:"image/jpeg"}),y=`meals/${`${Date.now()}_${Math.random().toString(36).substring(2,9)}.jpg`}`,{error:b}=await C.storage.from("meal-photos").upload(y,k,{cacheControl:"3600",upsert:!0});if(b)throw b;const{data:u}=C.storage.from("meal-photos").getPublicUrl(y);s(u.publicUrl)}catch(v){console.error("Error uploading photo:",v);const k=URL.createObjectURL(r);s(k)}finally{c(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"file",ref:f,onChange:g,accept:"image/*",capture:"environment",className:"hidden"}),e.jsx("input",{type:"file",ref:w,onChange:g,accept:"image/*",className:"hidden"}),t?e.jsxs("div",{className:"relative rounded-2xl overflow-hidden border border-stone-200 shadow-sm group max-h-48 bg-black/5 flex items-center justify-center",children:[e.jsx("img",{src:t,alt:a==="ja"?"é£äºã®åç":"Meal photo",className:"w-full h-44 object-cover rounded-2xl"}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity flex flex-col items-center justify-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{var n;return(n=f.current)==null?void 0:n.click()},className:"p-2.5 bg-white text-stone-800 rounded-full shadow-md hover:bg-stone-100",title:a==="ja"?"ã«ã¡ã©ã§æ®ãç´ã":"Retake with Camera",children:e.jsx(fe,{size:16})}),e.jsx("button",{type:"button",onClick:()=>{var n;return(n=w.current)==null?void 0:n.click()},className:"p-2.5 bg-white text-stone-800 rounded-full shadow-md hover:bg-stone-100",title:a==="ja"?"ã¢ã«ãã ããé¸ã³ç´ã":"Choose different from Gallery",children:e.jsx(ce,{size:16})}),d&&e.jsx("button",{type:"button",onClick:d,className:"p-2.5 bg-rose-500 text-white rounded-full shadow-md hover:bg-rose-600",title:a==="ja"?"åçãåé¤":"Remove Photo",children:e.jsx(Q,{size:16})})]})})]}):e.jsx("div",{className:"flex flex-col gap-2",children:p?e.jsxs("div",{className:"w-full py-6 border-2 border-dashed border-emerald-300 rounded-2xl bg-emerald-50/30 flex flex-col items-center justify-center gap-2 text-emerald-600",children:[e.jsx(G,{size:24,className:"animate-spin"}),e.jsx("span",{className:"text-xs font-bold",children:a==="ja"?"åçãã¢ãããã¼ãä¸...":"Uploading photo..."})]}):e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{var n;return(n=f.current)==null?void 0:n.click()},className:"py-4 border border-stone-200 hover:border-emerald-500 rounded-2xl bg-stone-50 hover:bg-emerald-50/50 transition-all flex flex-col items-center justify-center gap-2 group text-stone-600 hover:text-emerald-700 shadow-sm",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-white shadow-sm flex items-center justify-center group-hover:scale-110 transition-transform",children:e.jsx(fe,{size:20,className:"text-emerald-500"})}),e.jsx("span",{className:"text-[11px] font-bold",children:a==="ja"?"åçãæ®å½±":"Take Photo"})]}),e.jsxs("button",{type:"button",onClick:()=>{var n;return(n=w.current)==null?void 0:n.click()},className:"py-4 border border-stone-200 hover:border-blue-500 rounded-2xl bg-stone-50 hover:bg-blue-50/50 transition-all flex flex-col items-center justify-center gap-2 group text-stone-600 hover:text-blue-700 shadow-sm",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-white shadow-sm flex items-center justify-center group-hover:scale-110 transition-transform",children:e.jsx(ce,{size:20,className:"text-blue-500"})}),e.jsx("span",{className:"text-[11px] font-bold",children:a==="ja"?"ã¢ã«ãã ãã":"From Gallery"})]})]})}),j&&e.jsx("p",{className:"text-[11px] font-bold text-rose-500 mt-2 text-center",children:j})]})},dt=()=>{const{user:t}=U(),{t:s}=P(),[d,a]=l.useState([]),[p,c]=l.useState(""),[j,h]=l.useState(""),[f,w]=l.useState(!1),[g,n]=l.useState(!1),r=l.useRef(null);l.useEffect(()=>{t!=null&&t.id&&(k(),S(),v())},[t==null?void 0:t.id]),l.useEffect(()=>{x()},[d]);const x=()=>{var b;(b=r.current)==null||b.scrollIntoView({behavior:"smooth"})},v=async()=>
1{if(t!=null&&t.id)try{await C.from("nutritional_chat_messages").update({is_read:!0}).eq("student_id",t.id).eq("sender_type","admin").eq("is_read",!1)}catch(b){console.error(b)}},k=async()=>{try{const{data:b}=await C.from("nutritional_chat_messages").select("*").eq("student_id",t.id).order("created_at",{ascending:!0});b&&a(b)}catch(b){console.error(b)}},S=()=>{const b=C.channel("realtime_chat").on("postgres_changes",{event:"INSERT",schema:"public",table:"nutritional_chat_messages",filter:`student_id=eq.${t.id}`},u=>{u.new.sender_type==="admin"&&!u.new.is_read&&(v(),u.new.is_read=!0),a(_=>_.some(o=>o.id===u.new.id)?_:[..._,u.new])}).subscribe();return()=>{C.removeChannel(b)}},y=async b=>{if(b&&b.preventDefault(),!(!p.trim()&&!j)){n(!0);try{const u={student_id:t.id,sender_type:"student",message_text:p.trim(),attachment_url:j||null,is_read:!1},{data:_,error:o}=await C.from("nutritional_chat_messages").insert([u]).select().single();if(o)throw o;_&&(a(m=>[...m,_]),c(""),h(""),w(!1))}catch(u){console.error(u)}finally{n(!1)}}};return e.jsxs("div",{className:"flex flex-col h-[calc(100vh-120px)] max-w-lg mx-auto bg-[#FAF8F5] animate-fadeIn overflow-hidden",children:[e.jsx("div",{className:"bg-white border-b border-emerald-100/80 p-4 flex items-center justify-between flex-shrink-0 shadow-xs",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-emerald-50 text-emerald-600 border border-emerald-200/60 flex items-center justify-center font-bold",children:e.jsx(xe,{size:20})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-bold text-slate-900 font-serif-jp",children:s("nutritional.chat.title")}),e.jsx("p",{className:"text-[10px] text-slate-400 font-medium",children:s("nutritional.chat.subtitle")})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-3.5 bg-[#FAF8F5]",children:[d.map(b=>{const u=b.sender_type==="student";return e.jsx("div",{className:`flex ${u?"justify-end":"justify-start"}`,children:e.jsxs("div",{className:`max-w-[80%] p-3.5 rounded-2xl text-xs space-y-1.5 shadow-xs ${u?"bg-gradient-to-br from-emerald-500 to-teal-600 text-white rounded-br-none":"bg-white border border-emerald-100 text-slate-800 rounded-bl-none"}`,children:[b.attachment_url&&e.jsx("img",{src:b.attachment_url,alt:"Attachment",className:"w-full max-h-48 object-cover rounded-xl border border-white/20"}),b.message_text&&e.jsx("p",{className:"font-medium whitespace-pre-wrap leading-relaxed",children:b.message_text}),e.jsx("span",{className:`text-[9px] block text-right font-medium ${u?"text-emerald-100":"text-slate-400"}`,children:new Date(b.created_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})},b.id)}),e.jsx("div",{ref:r})]}),f&&e.jsx("div",{className:"p-3 bg-white border-t border-emerald-100 flex-shrink-0 animate-fadeIn",children:e.jsx(Se,{currentPhotoUrl:j,onPhotoUploaded:b=>h(b),onRemovePhoto:()=>h("")})}),e.jsxs("form",{onSubmit:y,className:"p-3 bg-white border-t border-emerald-100 flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>w(!f),className:`p-2.5 rounded-xl border transition-all ${j?"bg-emerald-50 text-emerald-600 border-emerald-200":"bg-slate-50 text-slate-400 border-slate-200 hover:text-slate-700"}`,children:e.jsx(ce,{size:18})}),e.jsx("input",{type:"text",value:p,onChange:b=>c(b.target.value),placeholder:s("nutritional.chat.placeholder"),className:"flex-1 bg-slate-50 border border-slate-200 rounded-xl px-4 py-2.5 text-xs font-medium outline-none focus:border-emerald-500 focus:bg-white transition-all"}),e.jsx("button",{type:"submit",disabled:g||!p.trim()&&!j,className:"p-2.5 bg-emerald-500 hover:bg-emerald-600 disabled:opacity-40 text-white rounded-xl shadow-md shadow-emerald-500/20 transition-all flex items-center justify-center",children:g?e.jsx(G,{size:18,className:"animate-spin"}):e.jsx($e,{size:18})})]})]})},ct=({onClose:t,onSave:s,initialWeight:d=65})=>{const{language:a}=P(),[p,c]=l.useState(d.toString()),[j,h]=l.useState(""),[f,w]=l.useState(""),[g,n]=l.useState(""),[r,x]=l.useState(""),[v,k]=l.useState(""),[S,y]=l.useState(""),[b,u]=l.useState(!1),_=async o=>{o.preventDefault(),u(!0),await s({weight_kg:Number(p),body_fat_percent:Number(j),muscle_mass_kg:Number(f),metabolic_age:Number(g),visceral_fat_level:Number(r),bone_mass_kg:v?Number(v):null,water_percent:S?Number(S):null}),u(!1),t()};return e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-950/40 backdrop-blur-md",onClick:t}),e.jsxs("div",{className:"relative bg-[#FAF8F5] border border-emerald-100/80 w-full max-w-md rounded-[2.5rem] p-6 sm:p-8 shadow-2xl animate-slideUp overflow-y-auto max-h-[85vh]",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 sticky top-0 bg-[#FAF8F5] z-10 pb-2 border-b border-slate-100",children:[e.jsx("h3",{className:"text-xl font-extrabold text-slate-800",children:a==="ja"?"ä½çµæãè¨é²":"Log Body Stats"}),e.jsx("button",{onClick:t,className:"w-8 h-8 rounded-full bg-white border border-slate-200/60 text-slate-400 hover:text-slate-700 flex items-center justify-center transition-transform active:scale-95 shadow-2xs",children:e.jsx(Q,{size:18})})]}),e.jsxs("form",{onSubmit:_,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"ä½é (kg)":"Weight (kg)"}),e.jsx("input",{type:"number",step:"0.1",required:!0,value:p,onChange:o=>c(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"ä½èèªç (%)":"Body Fat (%)"}),e.jsx("input",{type:"number",step:"0.1",required:!0,value:j,onChange:o=>h(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"çèé (kg)":"Muscle Mass (kg)"}),e.jsx("input",{type:"number",step:"0.1",required:!0,value:f,onChange:o=>w(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"骨é (kg)":"Bone Mass (kg)"}
1),e.jsx("input",{type:"number",step:"0.1",value:v,onChange:o=>k(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"æ°´åé (%)":"Water (%)"}),e.jsx("input",{type:"number",step:"0.1",value:S,onChange:o=>y(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"ä½å
å¹´é½¢ (æ³)":"Metabolic Age"}),e.jsx("input",{type:"number",required:!0,value:g,onChange:o=>n(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 mb-1",children:a==="ja"?"å
èèèªã¬ãã«":"Visceral Fat Level"}),e.jsx("input",{type:"number",step:"0.1",required:!0,value:r,onChange:o=>x(o.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-xl px-4 py-3 text-sm font-bold focus:ring-2 focus:ring-emerald-500 focus:outline-none"})]}),e.jsx("button",{type:"submit",disabled:b,className:"w-full mt-6 bg-gradient-to-r from-emerald-500 to-teal-500 text-white font-bold py-4 rounded-xl shadow-lg active:scale-95 transition-transform flex items-center justify-center gap-2",children:b?a==="ja"?"ä¿åä¸...":"Saving...":e.jsxs(e.Fragment,{children:[e.jsx(K,{size:20}),a==="ja"?"ä¿åãã":"Save Entry"]})})]})]})]})},xt=()=>{const{user:t}=U(),{language:s}=P(),[d,a]=l.useState({gender:"female",age:"",height:"",weight:"",targetWeight:"",months:"3",activityLevel:"1.5"}),[p,c]=l.useState(!1),[j,h]=l.useState(!1),f=g=>{const{name:n,value:r}=g.target;(n==="activityLevel"||n==="gender"||/^\d*$/.test(r))&&a(x=>({...x,[n]:r}))},w=async g=>{if(g.preventDefault(),!t)return;c(!0);const{age:n,height:r,weight:x,targetWeight:v,months:k,gender:S,activityLevel:y}=d,b=parseInt(n,10),u=parseInt(r,10),_=parseInt(x,10),o=parseInt(v,10),m=parseInt(k,10),L=parseFloat(y);if([b,u,_,o,m].some(E=>isNaN(E)||E<=0)){alert(s==="ja"?"ãã¹ã¦ã®é
ç®ã«æ£ããæ°å¤ãå
¥åãã¦ãã ããã":"Please enter valid numbers for all fields."),c(!1);return}let z;S==="male"?z=10*_+6.25*u-5*b+5:z=10*_+6.25*u-5*b-161;const A=(_-o)*7200/(m*30),N=z*L;let I=Math.round(N-A);S==="female"&&I<1200&&(I=1200),S==="male"&&I<1500&&(I=1500);const M=o*2,q=Math.round(I*.25/9),$=I-(M*4+q*9),B=Math.round($/4),D=_*35;try{await C.from("student_charts").update({gender:S,age:b,height_cm:u,current_weight_kg:_,target_weight_kg:o,daily_calorie_target:I,target_protein_g:M,target_fat_g:q,target_carbs_g:B>0?B:50,target_water_ml:D}).eq("student_id",t.id),h(!0)}catch(E){console.error(E),alert("Error saving data")}finally{c(!1)}};return j?e.jsxs("div",{className:"min-h-[100dvh] bg-[#FAF8F5] flex flex-col items-center justify-center p-6 text-center animate-fadeIn z-50 fixed inset-0",children:[e.jsx("div",{className:"w-20 h-20 bg-emerald-100 text-emerald-500 rounded-full flex items-center justify-center mb-6 shadow-sm mx-auto",children:e.jsx(ye,{size:40})}),e.jsx("h2",{className:"text-2xl font-bold font-serif-jp text-slate-800 mb-4",children:s==="ja"?"åæè¨å®ãå®äºãã¾ããï¼":"Setup Complete!"}),e.jsx("p",{className:"text-sm font-medium text-slate-600 leading-relaxed mb-8 max-w-sm mx-auto",children:s==="ja"?"ããªãã®ç®æ¨ã«åãããäºåã®è¨ºæçµæã
1çæããã¾ãããã¤ã³ã¹ãã©ã¯ã¿ã¼ããã®å
容ã確èªããããªãã®åå¥ã®ç¶æ³ã«åããã¦èª¿æ´ãè¡ãã¾ãã":"An estimated pre-diagnosis has been generated successfully for your initial goals. Your instructor will evaluate this data and fine-tune it according to your individual needs."}),e.jsx("button",{onClick:()=>window.location.href="/app",className:"w-full max-w-xs bg-slate-900 text-white py-4 rounded-2xl font-bold shadow-md hover:bg-slate-800 transition-colors mx-auto",children:s==="ja"?"ããã·ã¥ãã¼ãã¸é²ã":"Go to Dashboard"})]}):e.jsx("div",{className:"min-h-[100dvh] bg-[#FAF8F5] flex flex-col items-center justify-center p-6 fixed inset-0 z-50 overflow-y-auto",children:e.jsxs("div",{className:"w-full max-w-md bg-white rounded-3xl shadow-sm border border-slate-100 p-8 my-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-12 h-12 bg-emerald-100 text-emerald-600 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(ge,{size:24})}),e.jsx("h2",{className:"text-2xl font-bold font-serif-jp text-slate-800",children:s==="ja"?"åæè¨ºæ":"Initial Diagnosis"}),e.jsx("p",{className:"text-xs text-slate-400 font-medium mt-2",children:s==="ja"?"ããªãã®ç®æ¨ã«åããã¦è¨ç®ãã¾ã":"Let's calculate your targets"})]}),e.jsxs("form",{onSubmit:w,className:"space-y-4",children:[e.jsxs("div",{className:"flex bg-slate-50 p-1 rounded-xl",children:[e.jsxs("button",{type:"button",onClick:()=>a(g=>({...g,gender:"female"})),className:`flex-1 py-2 text-sm font-bold flex items-center justify-center gap-2 rounded-lg transition-colors ${d.gender==="female"?"bg-white text-emerald-600 shadow-sm":"text-slate-400"}`,children:[e.jsx(Ue,{size:16})," ",s==="ja"?"女æ§":"Female"]}),e.jsxs("button",{type:"button",onClick:()=>a(g=>({...g,gender:"male"})),className:`flex-1 py-2 text-sm font-bold flex items-center justify-center gap-2 rounded-lg transition-colors ${d.gender==="male"?"bg-white text-emerald-600 shadow-sm":"text-slate-400"}`,children:[e.jsx(Be,{size:16})," ",s==="ja"?"ç·æ§":"Male"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(ee,{size:16})}),e.jsx("input",{type:"text",name:"age",value:d.age,onChange:f,placeholder:s==="ja"?"å¹´é½¢":"Age",className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300",required:!0})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(Ge,{size:16})}),e.jsx("input",{type:"text",name:"height",value:d.height,onChange:f,placeholder:s==="ja"?"èº«é· (cm)":"Height (cm)",className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300",required:!0})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(ue,{size:16})}),e.jsx("input",{type:"text",name:"weight",value:d.weight,onChange:f,placeholder:s==="ja"?"ç¾å¨ä½é (kg)":"Weight (kg)",className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300",required:!0})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(ee,{size:16})}),e.jsx("input",{type:"text",name:"targetWeight",value:d.targetWeight,onChange:f,placeholder:s==="ja"?"ç®æ¨ä½é (kg)":"Target Weight",className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300",required:!0})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(He,{size:16})}),e.jsx("input",{type:"text",name:"months",value:d.months,onChange:f,placeholder:s==="ja"?"ç®æ¨æé (ã¶æ)":"Months to Goal",className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300",required:!0})]}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400",children:e.jsx(Ke,{size:16})}),e.jsxs("select",{name:"activityLevel",value:d.activityLevel,onChange:f,className:"w-full bg-slate-50 border border-slate-100 p-3 pl-10 rounded-xl font-bold text-slate-700 outline-none focus:border-emerald-300 cursor-pointer appearance-none",children:[e.jsx("option",{value:"1.2",children:s==="ja"?"ã»ã¼éåããªã":"Sedentary"}),e.jsx("option",{value:"1.5",children:s==="ja"?"軽ãéå":"Light Activity"}),e.jsx("option",{value:"1.75",children:s==="ja"?"ä¸ç¨åº¦ã®éå":"Moderate Activity"}),e.jsx("option",{value:"2.0",children:s==="ja"?"æ¿ããéå":"Very Active"})]})]}),e.jsxs("button",{type:"submit",disabled:p,className:"w-full bg-slate-900 text-white py-4 rounded-xl font-bold shadow-md hover:bg-slate-800 transition-colors flex items-center justify-center gap-2 mt-6 disabled:opacity-50",children:[p?e.jsx(G,{size:18,className:"animate-spin"}):e.jsx(ge,{size:18}),s==="ja"?"診æãçæãã":"Generate Diagnosis"]})]})]})})},mt=()=>{const t=Y(),{language:s,t:d}=P(),[a,p]=l.useState(""),[c,j]=l.useState(""),[h,f]=l.useState(""),[w,g]=l.useState(!1),n=async r=>{r.preventDefault(),g(!0),f("");try{const{error:x}=await C.auth.signInWithPassword({email:a,password:c});if(x)throw x;t("/app")}catch(x){f(x.message||(s==="ja"?"ãã°ã¤ã³ã«å¤±æãã¾ãã":"Login failed"))}finally{g(!1)}};return e.jsxs("div",{className:"min-h-[100dvh] bg-[#FAF8F5] flex flex-col justify-center px-6 safe-area-inset relative overflow-hidden",children:[e.jsx("div",{className:"absolute -top-32 -left-32 w-80 h-80 bg-emerald-200/30 rounded-full blur-3xl pointer-events-none"}),e.jsx("div",{className:"absolute -bottom-32 -right-32 w-80 h-80 bg-teal-200/30 rounded-full blur-3xl pointer-events-none"}),e.jsxs("div",{className:"max-w-sm mx-auto w-full space-y-8 relative z-10",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("div",{className:"w-18 h-18 mx-auto rounded-[1.5rem] bg-gradient-to-br from-emerald-500 via-teal-500 to-emerald-600 text-white flex items-center justify-center shadow-xl shadow-emerald-500/20 border border-emerald-400/30",children:e.jsx(de,{size:32,strokeWidth:2.5})}),e.jsxs("div",{className:"pt-2",children:[e.jsx("span",{className:"text-emerald-600 font-extrabold text-[10px] tracking-[0.2em] uppercase block",children:"Diet Academy"}),e.jsx("h1",{className:"text-2xl font-extrabold text-slate-900 tracking-tight",children:d("nutritional.appTitle")})]})]}),h&&e.jsxs("div",{className:"bg-rose-50 text-rose-600 p-4 rounded-2xl text-xs font-bold flex items-center gap-2 border border-rose-200/80 shadow-2xs animate-fadeIn",children:[e.jsx(ie,{size:16,className:"shrink-0"}),e.jsx("span",{children:h})]}),e.jsxs("div",{className:"bg-white/90 backdrop-blur-xl border border-emerald-100/70 p-7 rounded-[2.5rem] shadow-[0_20px_50px_rgba(16,185,129,0.06)] space-y-5",children:[e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-1",children:s==="ja"?"ã¡ã¼ã«ã¢ãã¬ã¹":"Email"}),e.jsx("input",{type:"email",value:a,onChange:r=>p(r.target.value),className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl py-3.5 px-4 text-sm font-medium outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all shadow-2xs text-slate-800",placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-1",children:s==="ja"?"ãã¹ã¯ã¼ã":"Password"}),e.jsx("input",{type:"password",value:c,onChange:r=>j(r.target.value),className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl py-3.5 px-4 text-sm font-medium outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all shadow-2xs text-slate-800",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",required:!0})]}),e.jsx("button",{type:"submit",disabled:w,className:"w-full py-4 bg-gradient-to-r from-emerald-500 via-teal-500 to-emerald-600 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-extrabold text-sm shadow-lg shadow-emerald-500/25 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:w?e.jsx(G,{className:"animate-spin",size:18}):e.jsx("span",{children:s==="ja"?"ãã°ã¤ã³":"Sign In"})})]}),e.jsx("div",{className:"text-center pt-1 border-t border-slate-100",children:e.jsx("button",{type:"button",onClick:()=>t("/app/register"),className:"text-xs font-extrabold text-emerald-600 hover:text-emerald-700 active:scale-95 transition-all pt-2",children:s==="ja"?"æ°è¦ç»é²ã¯ãã¡ã":"Create New Account"})})]})]})]})},ut=()=>{const t=Y(),{language:s}=P(),[d,a]=l.useState(""),[p,c]=l.useState(""),[j,h]=l.useState(""),[f,w]=l.useState(""),[g,n]=l.useState(!1),r=async x=>{x.preventDefault(),n(!0),w("");try{const{data:v,error:k}=await C.auth.signUp({email:p,password:j,options:{data:{full_name:d}}});if(k)throw k;v.user&&(await C.from("profiles").upsert([{id:v.user.id,full_name:d,role:"student",created_at:new Date().toISOString()}]),await C.from("student_charts").upsert([{student_id:v.user.id}])),t("/app")}catch(v){w(v.message||(s==="ja"?"ç»é²ã«å¤±æãã¾ãã":"Registration failed"))}finally{n(!1)}};return e.jsxs("div",{className:"min-h-[100dvh] bg-[#FAF8F5] flex flex-col justify-center px-6 safe-area-inset relative overflow-hidden",children:[e.jsx("div",{className:"absolute -top-32 -left-32 w-80 h-80 bg-emerald-200/30 rounded-full blur-3xl pointer-events-none"}),e.jsx("div",{className:"absolute -bottom-32 -right-32 w-80 h-80 bg-teal-200/30 rounded-full blur-3xl pointer-events-none"}),e.jsxs("div",{className:"max-w-sm mx-auto w-full space-y-8 relative z-10",children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("div",{className:"w-18 h-18 mx-auto rounded-[1.5rem] bg-gradient-to-br from-emerald-500 via-teal-500 to-emerald-600 text-white flex items-center justify-center shadow-xl shadow-emerald-500/20 border border-emerald-400/30",children:e.jsx(de,{size:32,strokeWidth:2.5})}),e.jsxs("div",{className:"pt-1",children:[e.jsx("h2",{className:"text-2xl font-extrabold text-slate-900 tracking-tight",children:s==="ja"?"æ°è¦ä¼å¡ç»é²":"Create Account"}
1),e.jsx("p",{className:"text-xs text-slate-400 font-medium mt-1",children:s==="ja"?"ã¢ããªã¨ã³ã¼ã¹ã®çµ±åã¢ã¯ã»ã¹":"Unified app and course access"})]})]}),f&&e.jsxs("div",{className:"bg-rose-50 text-rose-600 p-4 rounded-2xl text-xs font-bold flex items-center gap-2 border border-rose-200/80 shadow-2xs animate-fadeIn",children:[e.jsx(ie,{size:16,className:"shrink-0"}),e.jsx("span",{children:f})]}),e.jsxs("div",{className:"bg-white/90 backdrop-blur-xl border border-emerald-100/70 p-7 rounded-[2.5rem] shadow-[0_20px_50px_rgba(16,185,129,0.06)] space-y-5",children:[e.jsxs("form",{onSubmit:r,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-1",children:s==="ja"?"ãåå":"Full Name"}),e.jsx("input",{type:"text",value:d,onChange:x=>a(x.target.value),className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl py-3.5 px-4 text-sm font-medium outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all shadow-2xs text-slate-800",placeholder:s==="ja"?"å±±ç°å¤ªé":"John Doe",required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-1",children:s==="ja"?"ã¡ã¼ã«ã¢ãã¬ã¹":"Email"}),e.jsx("input",{type:"email",value:p,onChange:x=>c(x.target.value),className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl py-3.5 px-4 text-sm font-medium outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all shadow-2xs text-slate-800",placeholder:"[email protected]",required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-1",children:s==="ja"?"ãã¹ã¯ã¼ã":"Password"}),e.jsx("input",{type:"password",value:j,onChange:x=>h(x.target.value),className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl py-3.5 px-4 text-sm font-medium outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all shadow-2xs text-slate-800",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢",minLength:6,required:!0})]}),e.jsx("button",{type:"submit",disabled:g,className:"w-full py-4 bg-gradient-to-r from-emerald-500 via-teal-500 to-emerald-600 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-extrabold text-sm shadow-lg shadow-emerald-500/25 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:g?e.jsx(G,{className:"animate-spin",size:18}):e.jsx("span",{children:s==="ja"?"ç»é²ãã":"Register"})})]}),e.jsx("div",{className:"text-center pt-1 border-t border-slate-100",children:e.jsx("button",{type:"button",onClick:()=>
1t("/app/login"),className:"text-xs font-extrabold text-emerald-600 hover:text-emerald-700 active:scale-95 transition-all pt-2",children:s==="ja"?"ã¢ã«ã¦ã³ãããæã¡ã®æ¹ã¯ãã°ã¤ã³":"Already have an account? Sign In"})})]})]})]})},ht=()=>{var L,z,F,O,A;const t=Y(),{user:s}=U(),{language:d,t:a}=P(),{chart:p,weeklySupport:c,bodyLogs:j}=J(),[h,f]=l.useState(0),[w,g]=l.useState(0),[n,r]=l.useState([]),[x,v]=l.useState(!1),k=new Date().toISOString().split("T")[0],S=Te.useMemo(()=>{if(!j||j.length===0)return!0;const N=j[j.length-1];return(new Date().getTime()-new Date(N.log_date).getTime())/(1e3*3600*24)>=7},[j]);l.useEffect(()=>{s!=null&&s.id&&y()},[s==null?void 0:s.id]);const y=async()=>{try{const{data:N}=await C.from("daily_meal_logs").select("total_calories").eq("student_id",s.id).eq("log_date",k);N&&f(N.reduce((D,E)=>D+(Number(E.total_calories)||0),0));const I=(p==null?void 0:p.daily_calorie_target)||1800,M=new Date;M.setDate(M.getDate()-6);const q=M.toISOString().split("T")[0],{data:$}=await C.from("daily_meal_logs").select("log_date, total_calories").eq("student_id",s.id).gte("log_date",q).order("log_date",{ascending:!0});if($){const D={};$.forEach(H=>{D[H.log_date]=(D[H.log_date]||0)+(Number(H.total_calories)||0)});const E=Object.keys(D).map(H=>{const se=new Date(H);return{dateStr:`${se.getMonth()+1}/${se.getDate()}`,actual:D[H],target:I}});r(E)}const{data:B}=await C.from("daily_exercise_logs").select("water_ml").eq("student_id",s.id).eq("log_date",k).maybeSingle();B&&g(B.water_ml||0)}catch(N){console.error(N)}},b=(p==null?void 0:p.daily_calorie_target)||1800,u=Math.min(100,Math.round(h/b*100)),_=(p==null?void 0:p.target_water_ml)||2e3,o=Math.min(100,Math.round(w/_*100)),m=({percent:N,color:I,size:M=56})=>{const q=(M-8)/2,$=2*Math.PI*q,B=$-N/100*$;return e.jsxs("svg",{width:M,height:M,className:"transform -rotate-90",children:[e.jsx("circle",{cx:M/2,cy:M/2,r:q,fill:"none",stroke:"currentColor",strokeWidth:"4",className:"text-slate-100"}),e.jsx("circle",{cx:M/2,cy:M/2,r:q,fill:"none",stroke:I,strokeWidth:"4.5",strokeLinecap:"round",strokeDasharray:$,strokeDashoffset:B,className:"transition-all duration-700 ease-out"})]})};return e.jsxs("div",{className:"pb-32 pt-2 px-4 max-w-lg mx-auto space-y-5 animate-fadeIn safe-area-inset",children:[e.jsxs("div",{className:"flex items-center justify-between pt-3 pb-1 px-1",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-extrabold text-slate-400 tracking-widest uppercase block",children:a("nutritional.dash.welcome")}),e.jsx("h2",{className:"text-xl font-extrabold text-slate-900 tracking-tight",children:((L=s==null?void 0:s.user_metadata)==null?void 0:L.full_name)||"Member"})]}),e.jsx("button",{type:"button",onClick:()=>t("/app/profile"),className:"w-11 h-11 rounded-2xl bg-gradient-to-br from-emerald-500 via-teal-500 to-emerald-600 text-white flex items-center justify-center text-sm font-extrabold shadow-md shadow-emerald-500/20 active:scale-95 transition-transform border border-emerald-400/30",children:((F=(z=s==null?void 0:s.user_metadata)==null?void 0:z.full_name)==null?void 0:F.charAt(0))||"M"})]}),e.jsxs("div",{className:"bg-gradient-to-r from-emerald-500 via-teal-500 to-emerald-600 rounded-[2rem] p-5 shadow-lg shadow-emerald-500/15 relative overflow-hidden border border-emerald-400/20",children:[e.jsx("div",{className:"absolute top-0 right-0 w-36 h-36 bg-white/10 rounded-full -translate-y-16 translate-x-16 blur-xs pointer-events-none"}),e.jsxs("div",{className:"relative z-10 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] font-black tracking-widest text-emerald-100 uppercase opacity-90 block mb-0.5",children:a("nutritional.dash.phase")}),e.jsx("h3",{className:"text-xl font-bold text-white font-serif-jp tracking-tight drop-shadow-xs",children:(c==null?void 0:c.period_label)||(d==="ja"?"æºåæé":"Prep Phase")})]}),e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-white/15 backdrop-blur-md flex items-center justify-center text-white border border-white/20",children:e.jsx(ee,{size:26})})]})]}),S&&e.jsxs("div",{onClick:()=>t("/app/progress"),className:"bg-gradient-to-r from-amber-50/90 to-orange-50/80 border border-amber-200/80 rounded-[1.75rem] p-4 flex items-center justify-between shadow-xs cursor-pointer active:scale-[0.98] transition-transform hover:border-amber-300",children:[e.jsxs("div",{className:"flex gap-3.5 items-center",children:[e.jsx("div",{className:"w-10 h-10 rounded-2xl bg-amber-100 text-amber-600 flex items-center justify-center flex-shrink-0 shadow-2xs",children:e.jsx(ue,{size:20})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-xs font-extrabold text-amber-900",children:d==="ja"?"ä½çµæãè¨é²ãã¾ããã":"Time to log your body stats"}),e.jsx("p",{className:"text-[10px] text-amber-700/90 font-medium mt
1-0.5",children:d==="ja"?"7æ¥ä»¥ä¸çµéãã¦ãã¾ããã¿ãããã¦å
¥åã":"It's been over 7 days. Tap to update."})]})]}),e.jsx(Ne,{size:18,className:"text-amber-500 shrink-0"})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] p-5 border border-slate-100/80 shadow-[0_8px_30px_rgb(0,0,0,0.03)] space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-xs font-extrabold text-slate-800 tracking-wide uppercase",children:d==="ja"?"ã«ããªã¼æ¨ç§» (7æ¥é)":"7-Day Calorie Trend"}),e.jsx("button",{onClick:()=>v(!0),className:"p-1.5 bg-slate-50 text-slate-400 hover:text-emerald-600 hover:bg-emerald-50 rounded-xl transition-all active:scale-95 border border-slate-100",children:e.jsx(Ve,{size:15})})]}),n.length===0?e.jsx("div",{className:"py-6 text-center text-xs font-medium text-slate-400 leading-relaxed bg-slate-50/50 rounded-2xl border border-dashed border-slate-200/80",children:d==="ja"?"é£äºãè¨é²ããã¨ãããã«é²è¡ç¶æ³ã®ã°ã©ãã表示ããã¾ãã":"The progress chart will be displayed here as you record your daily meals."}):e.jsx("div",{className:"h-36 w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(le,{data:n,margin:{top:5,right:5,left:-25,bottom:0},children:[e.jsx(re,{strokeDasharray:"3 3",vertical:!1,stroke:"#f1f5f9"}),e.jsx(ne,{dataKey:"dateStr",tick:{fontSize:10,fill:"#94a3b8",fontWeight:600},axisLine:!1,tickLine:!1}),e.jsx(oe,{tick:{fontSize:10,fill:"#94a3b8",fontWeight:600},axisLine:!1,tickLine:!1}),e.jsx(Z,{contentStyle:{borderRadius:"16px",border:"none",boxShadow:"0 10px 25px -5px rgba(0,0,0,0.1)"},labelStyle:{fontWeight:"bold",color:"#1e293b",marginBottom:"4px"},itemStyle:{fontSize:"12px",fontWeight:"bold"}}),e.jsx(V,{type:"monotone",dataKey:"actual",name:d==="ja"?"æå":"Intake",stroke:"#10b981",strokeWidth:3.5,dot:{r:4,fill:"#10b981",strokeWidth:0}}),e.jsx(V,{type:"monotone",dataKey:"target",name:d==="ja"?"ç®æ¨":"Target",stroke:"#f59e0b",strokeWidth:2,strokeDasharray:"4 4",dot:!1})]})})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-white rounded-[2rem] p-4.5 border border-slate-100/80 shadow-[0_8px_30px_rgb(0,0,0,0.03)] space-y-3 relative overflow-hidden hover:shadow-md transition-all",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("span",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider",children:a("nutritional.dash.calories")})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(m,{percent:u,color:"#f59e0b"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(de,{size:16,className:"text-amber-500"})})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xl font-extrabold text-slate-900 tabular-nums",children:h}),e.jsxs("div",{className:"text-[9px] text-slate-400 font-bold",children:[a("nutritional.dash.target")," ",b]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] p-4.5 border border-slate-100/80 shadow-[0_8px_30px_rgb(0,0,0,0.03)] space-y-3 relative overflow-hidden hover:shadow-md transition-all",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("span",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider",children:a("nutritional.dash.water")})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(m,{percent:o,color:"#3b82f6"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(_e,{size:16,className:"text-blue-500"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-xl font-extrabold text-slate-900 tabular-nums",children:[w,e.jsx("span",{className:"text-xs font-bold text-slate-400 ml-0.5",children:"ml"})]}),e.jsxs("div",{className:"text-[9px] text-slate-400 font-bold",children:[a("nutritional.dash.target")," ",_,"ml"]})]})]})]})]}),((O=c==null?void 0:c.weekly_reflection_admin)==null?void 0:O.trim())&&e.jsxs("div",{className:"bg-gradient-to-br from-blue-50/80 to-indigo-50/40 rounded-[1.75rem] p-5 border border-blue-200/60 shadow-2xs space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-extrabold text-blue-800",children:[e.jsx(xe,{size:15,className:"text-blue-500"}),e.jsx("span",{children:d==="ja"?"ã³ã¼ãããã®æ¯ãè¿ã":"1-Week Reflection"})]}),e.jsx("p",{className:"text-xs text-blue-950/80 font-medium leading-relaxed whitespace-pre-wrap",children:c.weekly_reflection_admin})]}),((A=c==null?void 0:c.next_week_action_admin)==null?void 0:A.trim())&&e.jsxs("div",{className:"bg-gradient-to-br from-emerald-50/80 to-teal-50/40 rounded-[1.75rem] p-5 border border-emerald-200/60 shadow-2xs space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-extrabold text-emerald-800",children:[e.jsx(xe,{size:15,className:"text-emerald-500"}),e.jsx("span",{children:a("nutritional.dash.coachTipsTitle")})]}),e.jsx("p",{className:"text-xs text-emerald-950/80 font-medium leading-relaxed whitespace-pre-wrap",children:c.next_week_action_admin})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>t("/app/meals"),className:"p-4.5 bg-white rounded-[2rem] border border-slate-100/80 shadow-[0_8px_30px_rgb(0,0,0,0.03)] hover:shadow-md active:scale-[0.97] transition-all text-left space-y-3 group relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-3.5 right-3.5 w-7 h-7 bg-slate-50 text-slate-400 rounded-full flex items-center justify-center group-hover:bg-amber-100 group-hover:text-amber-600 transition-colors shadow-2xs",children:e.jsx(te,{size:15,strokeWidth:3})}),e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-amber-50 text-amber-500 flex items-center justify-center group-active:scale-110 transition-transform shadow-2xs border border-amber-100/60",children:e.jsx(ae,{size:22})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-extrabold text-slate-800",children:a("nutritional.dash.quickMeal")}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium mt
1-0.5",children:a("nutritional.meals.quickPreset")})]})]}),e.jsxs("button",{type:"button",onClick:()=>t("/app/goals"),className:"p-4.5 bg-white rounded-[2rem] border border-slate-100/80 shadow-[0_8px_30px_rgb(0,0,0,0.03)] hover:shadow-md active:scale-[0.97] transition-all text-left space-y-3 group relative overflow-hidden",children:[e.jsx("div",{className:"absolute top-3.5 right-3.5 w-7 h-7 bg-slate-50 text-slate-400 rounded-full flex items-center justify-center group-hover:bg-emerald-100 group-hover:text-emerald-600 transition-colors shadow-2xs",children:e.jsx(te,{size:15,strokeWidth:3})}),e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-emerald-50 text-emerald-600 flex items-center justify-center group-active:scale-110 transition-transform shadow-2xs border border-emerald-100/60",children:e.jsx(ee,{size:22})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-extrabold text-slate-800",children:a("nutritional.dash.quickGoals")}),e.jsx("div",{className:"text-[10px] text-slate-400 font-medium mt-0.5",children:"⯠/ â³ / Ã"})]})]})]}),x&&e.jsxs("div",{className:"fixed inset-0 z-[100] bg-white flex flex-col animate-fadeIn",children:[e.jsxs("div",{className:"p-4 flex items-center justify-between border-b border-slate-100 safe-area-inset-top bg-white",children:[e.jsx("h4",{className:"text-lg font-bold text-slate-800",children:d==="ja"?"ã«ããªã¼æ¨ç§» (7æ¥é)":"7-Day Calorie Trend"}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 bg-slate-50 text-slate-500 rounded-full hover:bg-slate-100 transition-colors focus:outline-none",children:e.jsx(Q,{size:20})})]}),e.jsx("div",{className:"flex-1 p-4 bg-slate-50",children:n.length===0?e.jsx("div",{className:"flex items-center justify-center h-full text-sm font-medium text-slate-400",children:d==="ja"?"ãã¼ã¿ãããã¾ãã":"No data available"}):e.jsx(X,{width:"100%",height:"80%",children:e.jsxs(le,{data:n,margin:{top:20,right:20,left:-10,bottom:20},children:[e.jsx(re,{strokeDasharray:"3 3",vertical:!1,stroke:"#e2e8f0"}),e.jsx(ne,{dataKey:"dateStr",tick:{fontSize:12,fill:"#64748b"},axisLine:!1,tickLine:!1,dy:10}),e.jsx(oe,{tick:{fontSize:12,fill:"#64748b"},axisLine:!1,tickLine:!1,dx:-10}),e.jsx(Z,{contentStyle:{borderRadius:"16px",border:"none",boxShadow:"0 10px 15px -3px rgb(0 0 0 / 0.1)"},labelStyle:{fontWeight:"bold",color:"#1e293b",marginBottom:"4px"},itemStyle:{fontSize:"14px",fontWeight:"bold",padding:"2px 0"}}),e.jsx(ke,{wrapperStyle:{paddingTop:"20px"}}),e.jsx(V,{type:"monotone",dataKey:"actual",name:d==="ja"?"æåã«ããªã¼":"Intake (kcal)",stroke:"#10b981",strokeWidth:4,dot:{r:5,fill:"#10b981",strokeWidth:0},activeDot:{r:8}}),e.jsx(V,{type:"monotone",dataKey:"target",name:d==="ja"?"ç®æ¨ã«ããªã¼":"Target (kcal)",stroke:"#f59e0b",strokeWidth:3,strokeDasharray:"6 6",dot:!1})]})})})]})]})},bt=()=>{const{t,language:s}=P(),{saveMealLog:d}=J(),{user:a}=U(),p=Y(),[c,j]=l.useState("lunch"),[h,f]=l.useState([]),[w,g]=l.useState(""),[n,r]=l.useState(!1),[x,v]=l.useState(""),[k,S]=l.useState(""),[y,b]=l.useState(new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})),[u,_]=l.useState(""),[o,m]=l.useState(""),[L,z]=l.useState(""),[F,O]=l.useState(!1),[A,N]=l.useState(""),[I,M]=l.useState([]),[q,$]=l.useState(!1),[B,D]=l.useState(!1),[E,H]=l.useState({}),se=i=>{H(W=>({...W,[i]:!W[i]}))};l.useEffect(()=>{a!=null&&a.id&&he()},[a==null?void 0:a.id]);const he=async()=>{try{const{data:i}=await C.from("daily_meal_logs").select("*").eq("student_id",a.id).order("created_at",{ascending:!1}).limit(10);i&&M(i)}catch(i){console.error(i)}},be=h.reduce((i,W)=>i+W.calories,0),Ce=()=>{x.trim()&&(f(i=>[...i,{name:x.trim(),calories:Number(k)||0,portion_g:100,protein_g:0,carbs_g:0,fat_g:0}]),v(""),S(""))},ze=i=>{f(W=>W.filter((pe,Le)=>Le!==i))},Ie=async()=>{if(!(h.length===0&&!w)){O(!0);try{await d({log_date:new Date().toISOString().split("T")[0],meal_type:c,logged_time:y,items:h,total_calories:be,photo_url:w||null,with_whom:u,location:o,mood:L}),N(t("nutritional.meals.saveSuccess")||(s==="ja"?"è¨é²ãä¿åãã¾ãã":"Saved successfully")),f([]),g(""),_(""),m(""),z(""),b(new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",hour12:!1})),he(),D(!0),setTimeout(()=>{D(!1),p("/app")}
1,2500)}catch(i){console.error(i)}finally{O(!1)}}};return e.jsxs("div",{className:"pb-32 animate-fadeIn bg-[#FAF8F5] min-h-screen",children:[e.jsxs("div",{className:"sticky top-0 z-40 bg-white/90 backdrop-blur-xl border-b border-slate-100 px-4 py-4 flex items-center justify-between shadow-2xs safe-area-inset-top",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>p("/app"),className:"p-2 -ml-2 text-slate-500 hover:text-slate-800 transition-colors active:scale-95",children:e.jsx(Ne,{className:"rotate-180",size:24})}),e.jsx("h2",{className:"text-lg font-extrabold text-slate-900",children:t("nutritional.meals.title")})]}),e.jsxs("div",{className:"text-[11px] font-bold text-amber-600 bg-amber-50 border border-amber-200/60 px-3 py-1.5 rounded-full tabular-nums shadow-xs",children:[be," kcal"]})]}),e.jsxs("div",{className:"px-4 py-6 max-w-lg mx-auto space-y-6",children:[A&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200/60 text-emerald-800 p-4 rounded-2xl text-xs font-bold flex items-center gap-2 animate-fadeIn shadow-xs",children:[e.jsx(K,{size:16,className:"shrink-0"}),e.jsx("span",{children:A})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] p-5 shadow-xs border border-slate-100/50 space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-800 tracking-wide uppercase",children:t("nutritional.meals.photoLabel")}),w&&e.jsx("span",{className:"text-[10px] font-bold text-emerald-500 bg-emerald-50 px-2 py-1 rounded-md",children:"Attached"})]}),e.jsx(Se,{currentPhotoUrl:w,onPhotoUploaded:i=>g(i),onRemovePhoto:()=>g("")})]}),e.jsx("div",{className:"h-px bg-slate-50"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-800 tracking-wide uppercase",children:s==="ja"?"é£äºã®ç¨®é¡ã¨æé":"Meal & Time"}),e.jsx("input",{type:"time",value:y,onChange:i=>b(i.target.value),className:"bg-slate-50 border border-slate-200 rounded-xl px-3 py-1.5 text-xs font-bold outline-none focus:border-emerald-500 text-slate-700 shadow-inner"})]}),e.jsx("div",{className:"flex gap-2 overflow-x-auto scrollbar-none py-1 px-0.5",children:[{key:"breakfast",label:t("nutritional.meals.breakfast")},{key:"lunch",label:t("nutritional.meals.lunch")},{key:"dinner",label:t("nutritional.meals.dinner")},{key:"snack",label:t("nutritional.meals.snack")},{key:"other",label:t("nutritional.meals.other")}].map(i=>e.jsx("button",{type:"button",onClick:()=>j(i.key),className:`flex-shrink-0 px-4 py-2.5 text-[11px] font-bold rounded-2xl transition-all whitespace-nowrap active:scale-95 shadow-sm ${c===i.key?"bg-slate-800 text-white shadow-md":"bg-slate-50 text-slate-500 border border-slate-100 hover:bg-slate-100"}`,children:i.label},i.key))})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] p-5 shadow-xs border border-slate-100/50 space-y-4",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-800 tracking-wide uppercase",children:t("nutritional.meals.itemsList")}),h.length===0?e.jsxs("div",{className:"py-8 bg-slate-50 rounded-2xl border border-dashed border-slate-200 flex flex-col items-center justify-center text-center space-y-2",children:[e.jsx(ae,{size:24,className:"text-slate-300"}),e.jsx("p",{className:"text-xs font-bold text-slate-400",children:t("nutritional.meals.emptyItems")})]}):e.jsx("div",{className:"space-y-2",children:h.map((i,W)=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-2xl bg-slate-50 border border-slate-100 text-xs group transition-all hover:border-slate-200",children:[e.jsx("span",{className:"font-bold text-slate-700",children:i.name}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"font-bold text-amber-600 tabular-nums bg-amber-50 px-2 py-1 rounded-lg",children:[i.calories," kcal"]}),e.jsx("button",{onClick:()=>ze(W),className:"text-slate-300 hover:text-red-500 p-1 bg-white rounded-full shadow-sm transition-colors",children:e.jsx(Q,{size:14})})]})]},W))}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsxs("button",{type:"button",onClick:()=>r(!0),className:"w-full py-3.5 px-4 bg-emerald-50/80 hover:bg-emerald-100/80 text-emerald-700 rounded-2xl font-extrabold text-xs border border-emerald-200/80 transition-all flex items-center justify-center gap-2 shadow-2xs active:scale-[0.98]",children:[e.jsx(ae,{size:16,className:"text-emerald-600"}),e.jsx("span",{children:t("nutritional.meals.quickPreset")})]}),e.jsxs("div",{className:"space-y-1.5 pt-2 border-t border-slate-100",children:[e.jsx("span",{className:"text-[10px] font-extrabold text-slate-400 uppercase tracking-wider block ml-0.5",children:s==="ja"?"æå
¥åã§é£åã追å ":"Or add custom item"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x,onChange:i=>v(i.target.value),placeholder:s==="ja"?"é£åå (ä¾: ãã«ãã)":"Food name",className:"flex-1 min-w-0 bg-slate-50/80 border border-slate-200/80 rounded-2xl px-3.5 py-3 text-xs font-bold outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all text-slate-800 placeholder:text-slate-400"}),e.jsxs("div",{className:"relative w-24 shrink-0",children:[e.jsx("input",{type:"number",value:k,onChange:i=>S(i.target.value),placeholder:"0",className:"w-full bg-slate-50/80 border border-slate-200/80 rounded-2xl pl-3 pr-8 py-3 text-xs font-bold text-slate-800 text-right outline-none focus:border-emerald-500 focus:bg-white focus:ring-4 focus:ring-emerald-500/10 transition-all tabular-nums placeholder:text-slate-400"}),e.jsx("span",{className:"absolute right-2.5 top-3.5 text-[10px] font-extrabold text-slate-400",children:"kcal"})]}),e.jsx("button",{type:"button",onClick:Ce,disabled:!x.trim(),className:"h-11 w-11 shrink-0 flex items-center justify-center bg-slate-900 disabled:opacity-30 disabled:bg-slate-300 text-white rounded-2xl font-bold active:scale-95 transition-all shadow-2xs",children:e.jsx(te,{size:18,strokeWidth:2.5})})]})]})]})]}),e.jsxs("div",{className:"bg-white rounded-[2rem] p-5 shadow-xs border border-slate-100/50 space-y-6",children:[e.jsx("span",{className:"text-xs font-extrabold text-slate-800 tracking-wide uppercase",children:s==="ja"?"ã³ã³ããã¹ã (ä»»æ)":"Context (Optional)"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase ml-1",children:s==="ja"?"誰ã¨ï¼":"With whom?"}),e.jsx("div",{className:"flex gap-2 mt-1.5 overflow-x-auto scrollbar-none py-1 px-0.5",children:[{val:"alone",label:s==="ja"?"ä¸äººã§":"Alone"},{val:"family",label:s==="ja"?"å®¶æ":"Family"},{val:"friends",label:s==="ja"?"å人":"Friends"},{val:"colleagues",label:s==="ja"?"åå":"Colleagues"},{val:"other",label:s==="ja"?"ãã®ä»":"Other"}].map(i=>e.jsx("button",{type:"button",onClick:()=>_(u===i.val?"":i.val),className:`flex-shrink-0 px-3.5 py-2 text-[11px] font-bold rounded-xl transition-all shadow-sm ${u===i.val?"bg-amber-100 text-amber-700 border-amber-200 border":"bg-slate-50 text-slate-500 border border-slate-100 hover:bg-slate-100"}`,children:i.label},i.val))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase ml-1",children:s==="ja"?"ã©ãã§ï¼":"Where?"}),e.jsx("div",{className:"flex gap-2 mt-1.5 overflow-x-auto scrollbar-none py-1 px-0.5",children:[{val:"home",label:s==="ja"?"èªå®
":"Home"},{val:"restaurant",label:s==="ja"?"å¤é£":"Restaurant"},{val:"work",label:s==="ja"?"è·å ´":"Work"},{val:"on_the_go",label:s==="ja"?"ç§»åä¸":"On the go"},{val:"other",label:s==="ja"?"ãã®ä»":"Other"}].map(i=>e.jsx("button",{type:"button",onClick:()=>m(o===i.val?"":i.val),className:`flex-shrink-0 px-3.5 py-2 text-[11px] font-bold rounded-xl transition-all shadow-sm ${o===i.val?"bg-emerald-100 text-emerald-700 border-emerald-200 border":"bg-slate-50 text-slate-500 border border-slate-100 hover:bg-slate-100"}`,children:i.label},i.val))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase ml-1",children:s==="ja"?"æ°åã¯ï¼":"Mood?"}),e.jsx("div",{className:"flex gap-2 mt-1.5",children:[{val:"great",emoji:"ð"},{val:"good",emoji:"ð"},{val:"normal",emoji:"ð"},{val:"bad",emoji:"ð"}].map(i=>e.jsx("button",{type:"button",onClick:()=>z(L===i.val?"":i.val),className:`flex-1 py-2 border rounded-xl text-xl transition-all ${L===i.val?"bg-blue-50 border-blue-200 shadow-sm scale-110":"bg-slate-50 border-slate-100 grayscale opacity-50 hover:grayscale-0 hover:opacity-100"}`,children:i.emoji},i.val))})]})]})]}),I.length>0&&e.jsxs("div",{className:"pt-4 pb-12",children:[e.jsxs("button",{type:"button",onClick:()=>$(!q),className:"flex items-center justify-between w-full bg-white p-4 rounded-2xl shadow-sm border border-slate-100 text-xs font-extrabold text-slate-700 transition-all active:scale-[0.98]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-slate-100 flex items-center justify-center",children:e.jsx(Ye,{size:14,className:"text-slate-500"})}),s==="ja"?"æè¿ã®é£äºå±¥æ´ (Recent Meals)":"Recent Meals"]}
1),q?e.jsx(Qe,{size:18,className:"text-slate-400"}):e.jsx(Xe,{size:18,className:"text-slate-400"})]}),q&&e.jsx("div",{className:"mt-3 space-y-3",children:I.map(i=>e.jsxs("div",{className:"bg-white border border-slate-100 rounded-2xl p-4 shadow-sm text-xs animate-fadeIn",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-slate-50 pb-2",children:[e.jsxs("h4",{className:"font-bold text-slate-800 uppercase",children:[i.meal_type," ",e.jsxs("span",{className:"text-[10px] text-slate-400 ml-1",children:[i.log_date," (",i.logged_time,")"]})]}),e.jsxs("span",{className:"font-extrabold text-amber-600 bg-amber-50 px-2 py-1 rounded-md",children:[i.total_calories," kcal"]})]}),(i.with_whom||i.location||i.mood)&&e.jsxs("div",{className:"flex gap-3 text-[10px] font-bold text-slate-500 pt-2 pb-2",children:[i.with_whom&&e.jsxs("span",{children:["ð¥ ",i.with_whom]}),i.location&&e.jsxs("span",{children:["ð ",i.location]}),i.mood&&e.jsx("span",{children:i.mood==="great"?"ð":i.mood==="good"?"ð":i.mood==="normal"?"ð":i.mood==="bad"?"ð":"ð¤"})]}),i.items&&i.items.length>0&&e.jsx("div",{className:"space-y-1 py-1",children:i.items.map((W,pe)=>e.jsxs("div",{className:"flex justify-between text-slate-600 font-medium",children:[e.jsxs("span",{children:["⢠",W.name]}),e.jsxs("span",{className:"font-bold",children:[W.calories," kcal"]})]},pe))}),i.photo_url&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-slate-50",children:[e.jsx("button",{type:"button",onClick:()=>se(i.id),className:"flex items-center gap-1.5 text-[10px] font-bold text-slate-500 bg-slate-50 hover:bg-slate-100 px-3 py-1.5 rounded-lg transition-all active:scale-95",children:E[i.id]?e.jsxs(e.Fragment,{children:[e.jsx(Ze,{size:14})," ",s==="ja"?"åçãé ã":"Hide"]}):e.jsxs(e.Fragment,{children:[e.jsx(et,{size:14})," ",s==="ja"?"åçãè¦ã":"View Photo"]})}),E[i.id]&&e.jsx("img",{src:i.photo_url,alt:"Meal",className:"w-full h-40 object-cover rounded-xl border border-slate-100 mt-2 animate-fadeIn shadow-sm"})]})]},i.id))})]})]}),(h.length>0||!!w)&&e.jsx("div",{className:"fixed bottom-24 left-0 right-0 z-40 px-4 pointer-events-none flex justify-center safe-area-inset-bottom animate-slideUp",children:e.jsx("div",{className:"w-full max-w-sm pointer-events-auto",children:e.jsx("button",{type:"button",disabled:F,onClick:Ie,className:"w-full h-14 bg-gradient-to-r from-emerald-500 via-teal-500 to-emerald-600 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-extrabold text-sm shadow-[0_16px_40px_rgba(16,185,129,0.35)] transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:F?e.jsx(G,{size:20,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(K,{size:18,strokeWidth:2.5}),e.jsx("span",{children:t("nutritional.meals.saveBtn")})]})})})}),e.jsx(ot,{isOpen:n,onClose:()=>r(!1),onSelectMeal:i=>f(W=>[...W,i])}),B&&e.jsxs("div",{className:"fixed inset-0 z-[100] flex flex-col items-center justify-center bg-gradient-to-br from-emerald-500 to-teal-600 text-white animate-in fade-in zoom-in duration-300",children:[e.jsx("div",{className:"w-24 h-24 bg-white/20 backdrop-blur-sm rounded-full flex items-center justify-center mb-6 shadow-[0_0_40px_rgba(255,255,255,0.2)]",children:e.jsx(K,{size:48,className:"text-white drop-shadow-md",strokeWidth:3})}),e.jsx("h2",{className:"text-2xl font-bold font-serif-jp tracking-wide drop-shadow-md mb-2",children:s==="ja"?"å
±æãã¦ããã¦ãããã¨ãï¼":"Thank y
1ou for sharing!"}),e.jsx("p",{className:"text-emerald-100 font-medium",children:s==="ja"?"è¨é²ãä¿åããã¾ãã":"Your meal was successfully logged"})]})]})},pt=()=>{const{t,language:s}=P(),{saveExerciseLog:d}=J(),{user:a}=U(),[p,c]=l.useState(6e3),[j,h]=l.useState(""),[f,w]=l.useState(""),[g,n]=l.useState(1500),[r,x]=l.useState(!1),[v,k]=l.useState(""),[S,y]=l.useState(null),[b,u]=l.useState([]);l.useEffect(()=>{a!=null&&a.id&&_()},[a==null?void 0:a.id]);const _=async()=>{try{const{data:m}=await C.from("daily_exercise_logs").select("*").eq("student_id",a.id).order("log_date",{ascending:!1}).limit(7);m&&u(m)}catch(m){console.error(m)}},o=async()=>{x(!0);try{const m={log_date:new Date().toISOString().split("T")[0],steps_count:Number(p)||0,strength_training:j,other_exercise:f,water_ml:Number(g)||0};await d(m),k(s==="ja"?"ç´ æ´ãããã§ãï¼å
±æãã¦ããã ããããã¨ããããã¾ãã":"Great job! Thank you for sharing."),y(m),_(),c(""),h(""),w(""),n(""),setTimeout(()=>k(""),5e3)}catch(m){console.error(m)}finally{x(!1)}};return e.jsxs("div",{className:"pb-28 pt-4 px-4 max-w-lg mx-auto space-y-5 animate-fadeIn safe-area-inset",children:[e.jsx("h2",{className:"text-lg font-extrabold text-slate-900",children:t("nutritional.exercise.title")}),v&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200/60 text-emerald-800 p-4 rounded-2xl text-xs font-bold flex items-center gap-2 animate-fadeIn",children:[e.jsx(K,{size:16}),e.jsx("span",{children:v})]}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-2xl bg-amber-50 text-amber-500 flex items-center justify-center",children:e.jsx(tt,{size:22})}),e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:t("nutritional.exercise.steps")})]}),e.jsx("input",{type:"number",value:p,onChange:m=>c(m.target.value===""?"":Number(m.target.value)),className:"w-full bg-slate-50 border border-slate-200 rounded-2xl py-3.5 px-4 text-lg font-extrabold text-slate-800 outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10 tabular-nums"})]}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-2xl bg-emerald-50 text-emerald-500 flex items-center justify-center",children:e.jsx(je,{size:22})}),e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:t("nutritional.exercise.strength")})]}),e.jsx("textarea",{rows:3,value:j,onChange:m=>h(m.target.value),placeholder:s==="ja"?"ä¾: ã¹ã¯ã¯ãã 30kg à 10å (3ã»ãã)":"e.g. Squat 30kg à 10 reps (3 sets)",className:"w-full bg-slate-50 border border-slate-200 rounded-2xl p-3.5 text-xs font-medium outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10"}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider block mb-1.5",children:t("nutritional.exercise.otherEx")}),e.jsx("input",{type:"text",value:f,onChange:m=>w(m.target.value),placeholder:s==="ja"?"ä¾: ã¦ã©ã¼ãã³ã° 30å":"e.g. Walking 30 mins",className:"w-full bg-slate-50 border border-slate-200 rounded-2xl py-3 px-4 text-xs font-medium outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10"})]})]}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-11 h-11 rounded-2xl bg-blue-50 text-blue-500 flex items-center justify-center",children:e.jsx(_e,{size:22})}),e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:t("nutritional.exercise.waterLog")})]}),e.jsx("input",{type:"number",step:"100",value:g,onChange:m=>n(m.target.value===""?"":Number(m.target.value)),className:"w-full bg-slate-50 border border-slate-200 rounded-2xl py-3.5 px-4 text-lg font-extrabold text-slate-800 outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10 tabular-nums"})]}),e.jsx("button",{type:"button",disabled:r,onClick:o,className:"w-full py-4 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-bold text-sm shadow-lg shadow-emerald-500/20 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:r?e.jsx(G,{size:18,className:"animate-spin"}):e.jsx("span",{children:t("nutritional.exercise.saveBtn")})}),S&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200 rounded-[1.5rem] p-5 shadow-xs space-y-3 animate-fadeIn mt-6",children:[e.jsx("h3",{className:"text-xs font-bold text-emerald-800",children:s==="ja"?"仿¥ã®è¨é² (éä¿¡æ¸ã¿):":"Today's Log (Submitted):"}),e.jsxs("div",{className:"text-xs text-emerald-700 space-y-1.5 font-medium",children:[e.jsxs("p",{children:["ð£ ",s==="ja"?"æ©æ°":"Steps",": ",e.jsx("span",{className:"font-bold",children:S.steps_count})]}),e.jsxs("p",{children:["ð§ ",s==="ja"?"æ°´å":"Water",": ",e.jsxs("span",{className:"font-bold",children:[S.water_ml,"ml"]})]}),S.strength_training&&e.jsxs("p",{children:["ðï¸ ",s==="ja"?"çãã¬":"Strength",": ",e.jsx("span",{className:"font-bold",children:S.strength_training})]}),S.other_exercise&&e.jsxs("p",{children:["ð ",s==="ja"?"ãã®ä»":"Other",": ",e.jsx("span",{className:"font-bold",children:S.other_exercise})]})]})]}),b.length>0&&e.jsxs("div",{className:"mt-8 space-y-4",children:[e.jsx("h3",{className:"text-sm font-extrabold text-slate-800",children:s==="ja"?"æè¿ã®å±¥æ´":"Recent History"}),b.map(m=>e.jsxs("div",{className:"bg-white border border-slate-100 rounded-[1.5rem] p-5 shadow-xs space-y-3",children:[e.jsx("h4",{className:"text-xs font-bold text-slate-600 border-b border-slate-100 pb-2",children:m.log_date}),e.jsxs("div",{className:"text-xs text-slate-700 space-y-1.5 font-medium",children:[e.jsxs("p",{children:["ð£ ",s==="ja"?"æ©æ°":"Steps",": ",e.jsx("span",{className:"font-bold",children:m.steps_count})]}),e.jsxs("p",{children:["ð§ ",s==="ja"?"æ°´å":"Water",": ",e.jsxs("span",{className:"font-bold",children:[m.water_ml,"ml"]})]}),m.strength_training&&e.jsxs("p",{children:["ðï¸ ",s==="ja"?"çãã¬":"Strength",": ",e.jsx("span",{className:"font-bold",children:m.strength_training})]}),m.other_exercise&&e.jsxs("p",{children:["ð ",s==="ja"?"ãã®ä»":"Other",": ",e.jsx("span",{className:"font-bold",children:m.other_exercise})]})]})]},m.id))]})]})}
1,ft=()=>{const{t,language:s}=P(),{chart:d,bodyLogs:a,saveBodyLog:p}=J(),{user:c}=U(),[j,h]=l.useState(!1),[f,w]=l.useState([]);l.useEffect(()=>{c!=null&&c.id&&g()},[c==null?void 0:c.id]);const g=async()=>{try{const{data:u}=await C.from("daily_meal_logs").select("log_date, items").eq("student_id",c.id).order("log_date",{ascending:!1}).limit(7);u&&w(u)}catch(u){console.error(u)}},n=a&&a.length>0?a[0]:null,r=a&&a.length>0?a[a.length-1]:null,x=[{key:"weight",label:t("nutritional.progress.weight"),day1:(n==null?void 0:n.weight_kg)||(d==null?void 0:d.current_weight_kg)||"-",day7:(r==null?void 0:r.weight_kg)||"-",unit:"kg"},{key:"bodyFat",label:t("nutritional.progress.bodyFat"),day1:(n==null?void 0:n.body_fat_percent)||"-",day7:(r==null?void 0:r.body_fat_percent)||"-",unit:"%"},{key:"muscle",label:t("nutritional.progress.muscle"),day1:(n==null?void 0:n.muscle_mass_kg)||"-",day7:(r==null?void 0:r.muscle_mass_kg)||"-",unit:"kg"},{key:"age",label:t("nutritional.progress.age"),day1:(n==null?void 0:n.metabolic_age)||"-",day7:(r==null?void 0:r.metabolic_age)||"-",unit:s==="ja"?"æ³":"yrs"},{key:"visceral",label:t("nutritional.progress.visceral"),day1:n!=null&&n.visceral_fat_level?`Lv.${n.visceral_fat_level}`:"-",day7:r!=null&&r.visceral_fat_level?`Lv.${r.visceral_fat_level}`:"-",unit:""}],v=(a==null?void 0:a.map(u=>({date:u.log_date.slice(5),weight:u.weight_kg,bodyFat:u.body_fat_percent})))||[];let k=0,S=0,y=0;f.forEach(u=>{u.items&&Array.isArray(u.items)&&u.items.forEach(_=>{k+=Number(_.protein_g)||0,S+=Number(_.carbs_g)||0,y+=Number(_.fat_g)||0})});const b=[{name:s==="ja"?"ã¿ã³ãã¯è³ª (P)":"Protein",value:Math.round(k),color:"#3b82f6"},{name:s==="ja"?"çæ°´åç© (C)":"Carbs",value:Math.round(S),color:"#f59e0b"},{name:s==="ja"?"è質 (F)":"Fat",value:Math.round(y),color:"#ef4444"}].filter(u=>u.value>0);return e.jsxs("div",{className:"pb-28 pt-4 px-4 max-w-lg mx-auto space-y-5 animate-fadeIn safe-area-inset",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-extrabold text-slate-900",children:t("nutritional.progress.title")}),e.jsxs("button",{onClick:()=>h(!0),className:"bg-emerald-50 text-emerald-600 px-3 py-1.5 rounded-full text-[10px] font-bold border border-emerald-200/60 shadow-sm active:scale-95 flex items-center gap-1",children:[e.jsx(te,{size:14}),s==="ja"?"è¨é²ãã":"Log Stats"]})]}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ue,{size:20,className:"text-emerald-500"}),e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:t("nutritional.progress.day1vs7")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-3 py-2 text-[9px] font-bold text-slate-400 uppercase tracking-wider",children:[e.jsx("span",{children:s==="ja"?"ææ¨":"Metric"}),e.jsx("span",{className:"text-center",children:s==="ja"?"åå":"First"}),e.jsx("span",{className:"text-center",children:s==="ja"?"ææ°":"Latest"})]}),x.map(u=>e.jsxs("div",{className:"grid grid-cols-3 gap-2 px-3 py-3 rounded-xl bg-slate-50/80 border border-slate-100 text-xs",children:[e.jsx("span",{className:"font-bold text-slate-700",children:u.label}),e.jsxs("span",{className:"text-center font-bold text-slate-600 tabular-nums",children:[u.day1," ",u.unit]}),e.jsxs("span",{className:"text-center font-extrabold text-emerald-600 tabular-nums",children:[u.day7," ",u.unit]})]},u.key))]})]}),b.length>0&&e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:s==="ja"?"PFCãã©ã³ã¹ (ç´è¿7æ¥é)":"PFC Balance (Last 7 Days)"}),e.jsx("div",{className:"h-48 w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(st,{children:[e.jsx(at,{data:b,cx:"50%",cy:"50%",innerRadius:60,outerRadius:80,paddingAngle:5,dataKey:"value",children:b.map((u,_)=>e.jsx(lt,{fill:u.color},`cell-${_}`))}),e.jsx(Z,{contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(ke,{iconType:"circle",wrapperStyle:{fontSize:"10px"}})]})})})]}),v.length>0&&e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:s==="ja"?"ä½éæ¨ç§»":"Weight Trend"}),e.jsx("div",{className:"h-48 w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(le,{data:v,margin:{top:5,right:5,bottom:5,left:-25},children:[e.jsx(re,{strokeDasharray:"3 3",vertical:!1,stroke:"#f1f5f9"}),e.jsx(ne,{dataKey:"date",tick:{fontSize:10,fill:"#94a3b8"}
1,axisLine:!1,tickLine:!1}),e.jsx(oe,{tick:{fontSize:10,fill:"#94a3b8"},axisLine:!1,tickLine:!1,domain:["dataMin - 2","dataMax + 2"]}),e.jsx(Z,{contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(V,{type:"monotone",dataKey:"weight",stroke:"#10b981",strokeWidth:3,dot:{fill:"#10b981",strokeWidth:2,r:4},activeDot:{r:6}})]})})})]}),v.length>0&&e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsx("h3",{className:"text-xs font-bold text-slate-800",children:s==="ja"?"ä½èèªçæ¨ç§»":"Body Fat Trend"}),e.jsx("div",{className:"h-48 w-full",children:e.jsx(X,{width:"100%",height:"100%",children:e.jsxs(le,{data:v,margin:{top:5,right:5,bottom:5,left:-25},children:[e.jsx(re,{strokeDasharray:"3 3",vertical:!1,stroke:"#f1f5f9"}),e.jsx(ne,{dataKey:"date",tick:{fontSize:10,fill:"#94a3b8"},axisLine:!1,tickLine:!1}),e.jsx(oe,{tick:{fontSize:10,fill:"#94a3b8"},axisLine:!1,tickLine:!1,domain:["dataMin - 1","dataMax + 1"]}),e.jsx(Z,{contentStyle:{borderRadius:"12px",border:"none",boxShadow:"0 4px 6px -1px rgb(0 0 0 / 0.1)"}}),e.jsx(V,{type:"monotone",dataKey:"bodyFat",stroke:"#f59e0b",strokeWidth:3,dot:{fill:"#f59e0b",strokeWidth:2,r:4},activeDot:{r:6}})]})})})]}),j&&e.jsx(ct,{onClose:()=>h(!1),onSave:p,initialWeight:d==null?void 0:d.current_weight_kg})]})},gt=()=>{const{t,language:s}=P(),{weeklySupport:d,saveTaskCheck:a}=J(),[p,c]=l.useState({}),[j,h]=l.useState(""),[f,w]=l.useState(""),[g,n]=l.useState(!1),[r,x]=l.useState(""),v=(d==null?void 0:d.weekly_tasks)||[{id:"1",text_ja:"æ¯é£åã«æ°´500mlã飲ã",text_en:"Drink 500ml water before meals"},{id:"2",text_ja:"ã¿ã³ãã¯è³ªããé£ã¹ã",text_en:"Eat protein first"},{id:"3",text_ja:"æ©æ°ã確èªãã",text_en:"Check daily steps"}],k=(y,b)=>{c(u=>({...u,[y]:b}))},S=async()=>{n(!0);try{await a({log_date:new Date().toISOString().split("T")[0],week_phase:(d==null?void 0:d.week_phase)||"week_1",task_ratings:p,reflection_memo:j,question_to_admin:f}),x(t("nutritional.meals.saveSuccess")),setTimeout(()=>x(""),3e3)}catch(y){console.error(y)}finally{n(!1)}};return e.jsxs("div",{className:"pb-28 pt-4 px-4 max-w-lg mx-auto space-y-5 animate-fadeIn safe-area-inset",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-extrabold text-slate-900",children:t("nutritional.goals.title")}),e.jsx("p",{className:"text-[10px] text-slate-400 font-medium mt-1",children:t("nutritional.goals.ratingDesc")})]}),r&&e.jsxs("div",{className:"bg-emerald-50 border border-emerald-200/60 text-emerald-800 p-4 rounded-2xl text-xs font-bold flex items-center gap-2 animate-fadeIn",children:[e.jsx(K,{size:16}),e.jsx("span",{children:r})]}),e.jsx("div",{className:"space-y-2.5",children:v.map((y,b)=>{const u=p[y.id];return e.jsxs("div",{className:"bg-white rounded-[1.25rem] p-4 border border-slate-100 shadow-xs flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-xs font-bold text-slate-800 flex-1 leading-snug",children:s==="ja"?y.text_ja||y.text_en:y.text_en||y.text_ja}),e.jsx("div",{className:"flex gap-1.5 flex-shrink-0",children:["circle","triangle","cross"].map(_=>{const o={circle:"â¯",triangle:"â³",cross:"Ã"},m={circle:u==="circle"?"bg-emerald-500 text-white shadow-md shadow-emerald-500/25":"bg-slate-100 text-slate-500",triangle:u==="triangle"?"bg-amber-500 text-white shadow-md shadow-amber-500/25":"bg-slate-100 text-slate-500",cross:u==="cross"?"bg-rose-500 text-white shadow-md shadow-rose-500/25":"bg-slate-100 text-slate-500"};return e.jsx("button",{type:"button",onClick:()=>k(y.id,_),className:`w-10 h-10 rounded-xl font-extrabold text-sm transition-all active:scale-90 flex items-center justify-center ${m[_]}`,children:o[_]},_)})})]},y.id||b)})}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-700 block mb-1.5",children:t("nutritional.goals.memoPlaceholder")}),e.jsx("textarea",{rows:3,value:j,onChange:y=>h(y.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-2xl p-3.5 text-xs font-medium outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold text-slate-700 block mb-1.5",children:t("nutritional.goals.questionPlaceholder")}),e.jsx("textarea",{rows:2,value:f,onChange:y=>w(y.target.value),className:"w-full bg-slate-50 border border-slate-200 rounded-2xl p-3.5 text-xs font-medium outline-none focus:border-emerald-500 focus:ring-2 focus:ring-emerald-500/10"})]})]}),e.jsx("button",{type:"button",disabled:g,onClick:S,className:"w-full py-4 bg-gradient-to-r from-emerald-500 to-teal-500 hover:from-emerald-600 hover:to-teal-600 text-white rounded-2xl font-bold text-sm shadow-lg shadow-emerald-500/20 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:g?e.jsx(G,{size:18,className:"animate-spin"}):e.jsx("span",{children:t("nutritional.goals.saveBtn")})})]})},jt=()=>{var j,h,f;
1const t=Y(),{user:s}=U(),{language:d,setLanguage:a,t:p}=P();J();const c=async()=>{await C.auth.signOut(),t("/app/login")};return e.jsxs("div",{className:"pb-28 pt-4 px-4 max-w-lg mx-auto space-y-5 animate-fadeIn safe-area-inset",children:[e.jsx("h2",{className:"text-lg font-extrabold text-slate-900",children:p("nutritional.nav.profile")}),e.jsx("div",{className:"bg-white rounded-[1.5rem] p-6 border border-slate-100 shadow-xs space-y-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-gradient-to-br from-emerald-500 to-teal-600 text-white font-bold flex items-center justify-center text-xl shadow-lg shadow-emerald-500/20",children:((h=(j=s==null?void 0:s.user_metadata)==null?void 0:j.full_name)==null?void 0:h.charAt(0))||"M"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-extrabold text-slate-900",children:((f=s==null?void 0:s.user_metadata)==null?void 0:f.full_name)||"Member"}),e.jsx("p",{className:"text-xs text-slate-400 font-medium",children:s==null?void 0:s.email})]})]})}),e.jsxs("div",{className:"bg-white rounded-[1.5rem] p-5 border border-slate-100 shadow-xs flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5 font-bold text-xs text-slate-700",children:[e.jsx(ve,{size:18,className:"text-emerald-500"}),e.jsx("span",{children:p("nutritional.nav.language")})]}),e.jsxs("div",{className:"flex gap-1.5 bg-slate-100 p-1 rounded-xl",children:[e.jsx("button",{type:"button",onClick:()=>a("ja"),className:`px-3 py-1.5 rounded-lg text-[10px] font-bold transition-all active:scale-95 ${d==="ja"?"bg-slate-900 text-white shadow-sm":"text-slate-500"}`,children:"æ¥æ¬èª"}),e.jsx("button",{type:"button",onClick:()=>a("en"),className:`px-3 py-1.5 rounded-lg text-[10px] font-bold transition-all active:scale-95 ${d==="en"?"bg-slate-900 text-white shadow-sm":"text-slate-500"}`,children:"English"})]})]}),e.jsxs("button",{type:"button",onClick:c,className:"w-full py-4 bg-rose-50 active:bg-rose-100 text-rose-600 rounded-2xl font-bold text-xs border border-rose-200/60 transition-all active:scale-[0.98] flex items-center justify-center gap-2",children:[e.jsx(we,{size:16}),e.jsx("span",{children:p("nutritional.nav.logout")})]})]})},vt=()=>{const{language:t,t:s}=P();return e.jsx("div",{className:"p-4 pb-24 animate-fadeIn max-w-lg mx-auto",children:e.jsxs("div",{className:"bg-white p-6 rounded-[2rem] border border-slate-100 shadow-[0_8px_30px_rgb(0,0,0,0.04)] min-h-[60vh] space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4 border-b border-slate-100 pb-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-emerald-50 text-emerald-600 flex items-center justify-center shadow-sm",children:e.jsx(me,{size:24})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900 font-serif-jp tracking-tight",children:s("nutritional.legal.title")}),e.jsx("p",{className:"text-[10px] text-slate-400 font-bold uppercase tracking-widest mt-1",children:s("nutritional.legal.subtitle")})]})]}),e.jsxs("div",{className:"text-xs text-slate-600 space-y-4 font-medium leading-relaxed",children:[e.jsx("p",{children:s("nutritional.legal.body")}),e.jsxs("div",{className:"p-4 bg-amber-50 rounded-2xl border border-amber-200/70 text-amber-800 flex items-start gap-3",children:[e.jsx(ie,{size:18,className:"flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"text-xs font-bold leading-relaxed",children:t==="ja"?"æ¬ã¢ããªã¯å»çè¡çºã»è¨ºæã»å¦æ¹ãè¡ããã®ã§ã¯ããã¾ãããæç
ã®ããæ¹ãéé¢ä¸ã®æ¹ã¯ãå¿
ã主治å»ã«ãç¸è«ãã ããã":"This app does not provide medical treatment, diagnosis, or prescriptions. If you have any medical conditions, please consult your physician."})]}),e.jsx("p",{className:"p-4 bg-slate-50 rounded-2xl border border-slate-200/70",children:t==="ja"?"ç»é²ããããã¼ã¿ããã³åçã¯Supabaseãã©ãããã©ã¼ã ä¸ã§æ©å¯ç®¡çããããæ¬äººã¨èªå®ãããæå°ã¹ã¿ããã®ã¿ãã¢ã¯ã»ã¹ã§ãã¾ãã":"All registered data and photos are securely managed on the Supabase platform and are accessible only by you and authorized coaching staff."})]})]})})},St=()=>{var r,x;const{session:t,isLoading:s}=U(),{language:d}
1=P(),{chart:a,acceptLegalTerms:p,unreadChatCount:c,isLoading:j}=J(),[h,f]=l.useState(null);if(l.useEffect(()=>{var k;if(!((k=t==null?void 0:t.user)!=null&&k.id)){f(!0);return}(async()=>{try{const S=t.user.id,{data:y}=await C.from("profiles").select("role").eq("id",S).maybeSingle();if((y==null?void 0:y.role)==="admin"||(y==null?void 0:y.role)==="staff"){f(!0);return}const{data:b}=await C.from("enrollments").select("course_id").eq("student_id",S);if(!b||b.length===0){f(!1);return}const u=b.map(o=>o.course_id),{data:_}=await C.from("courses").select("id").in("id",u).eq("has_app_access",!0);f(!!_&&_.length>0)}catch{f(!1)}})()},[(r=t==null?void 0:t.user)==null?void 0:r.id]),l.useEffect(()=>{window.location.pathname.startsWith("/app")&&localStorage.setItem("pwa_last_location",window.location.pathname)},[]),s||t&&j||t&&h===null)return e.jsx("div",{className:"min-h-[100dvh] flex items-center justify-center bg-[#FAF8F5]",children:e.jsx(G,{className:"animate-spin text-emerald-500",size:32})});const w=window.location.pathname.endsWith("/login")||window.location.pathname.endsWith("/register");if(t&&h===!1&&!w)return e.jsx("div",{className:"min-h-[100dvh] bg-[#FAF8F5] flex flex-col items-center justify-center p-6 text-center",children:e.jsxs("div",{className:"max-w-md w-full bg-white rounded-3xl p-8 border border-stone-200 shadow-xl space-y-6 animate-fadeIn",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-amber-50 text-amber-600 flex items-center justify-center mx-auto border border-amber-200",children:e.jsx(Je,{size:32})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-extrabold text-stone-900 font-serif-jp",children:d==="ja"?"ã¢ããªå©ç¨æ¨©éãããã¾ãã":"App Access Not Included"}),e.jsx("p",{className:"text-xs text-stone-500 font-medium leading-relaxed mt-2",children:d==="ja"?"ãåè¬ä¸ã®ã³ã¼ã¹ã«ã¯ã¢ããªï¼/appï¼ã®å©ç¨æ¨©éãå«ã¾ãã¦ãã¾ãããã¢ããªå©ç¨å¯¾è±¡ã®ã³ã¼ã¹ããåè¬ããã ãããäºåå±ã«ãåãåãããã ããã":"Your current course enrollment does not include access to the Nutritional App (/app). Please check your course plan or contact support."})]}),e.jsx("button",{onClick:()=>window.location.href="/member-area",className:"w-full py-3.5 bg-stone-900 hover:bg-stone-800 text-white rounded-2xl font-bold text-sm shadow-md transition-all active:scale-95",children:d==="ja"?"åè¬çãã¤ãã¼ã¸ã«æ»ã":"Back to Student Portal"})]})});const g=(x=t==null?void 0:t.user)!=null&&x.id?localStorage.getItem(`pwa_legal_terms_accepted_${t.user.id}`)==="true"||((a==null?void 0:a.accepted_legal_terms)??!1):!1,n=t&&a&&!a.height_cm;return e.jsxs("div",{className:"min-h-[100dvh] bg-[#FAF8F5] text-slate-800 selection:bg-emerald-500 selection:text-white flex flex-col",children:[e.jsx(nt,{isOpen:!!(t&&a&&!g&&!n),onAccept:p}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs(Pe,{children:[e.jsx(R,{path:"/login",element:e.jsx(mt,{})}),e.jsx(R,{path:"/register",element:e.jsx(ut,{})}),e.jsx(R,{path:"/onboarding",element:t?e.jsx(xt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(ht,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/meals",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(bt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/exercise",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(pt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/progress",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(ft,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/goals",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(gt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/chat",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(dt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/profile",element:t?n?e.jsx(T,{to:"/app/onboarding",replace:!0}):e.jsx(jt,{}):e.jsx(T,{to:"/app/login",replace:!0})}),e.jsx(R,{path:"/legal",element:t?e.jsx(vt,{}):e.jsx(T,{to:"/app/login",replace:!0})})]})}),t&&!n&&e.jsx(rt,{unreadChatCount:c}
1),e.jsx(Me,{})]})};export{St as NutritionalAppMain,St as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.