1import{Q as U,r as i,j as e,a as w,g as _,d as x,m as Z,s as h,I as y,p as ee,D as se,H as R,b as T,e as A,f as E,h as ae,c as M,L as D,A as ne,U as te,V as re,B as H,W as ie,Y as oe,_ as ce,$ as O,T as V,M as W,a0 as P,a1 as J,a2 as le}from"./index-D3v-3Oo3.js";import{S as Q}from"./sunrise-BSEE3BU3.js";import{L as de}from"./log-in-CjYsyJR-.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const me=U("BellOff",[["path",{d:"M8.7 3A6 6 0 0 1 18 8a21.3 21.3 0 0 0 .6 5",key:"o7mx20"}],["path",{d:"M17 17H3s3-2 3-9a4.67 4.67 0 0 1 .3-1.7",key:"16f1lm"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ue=U("ChevronLeft",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);function he(t){const b="=".repeat((4-t.length%4)%4),f=(t+b).replace(/-/g,"+").replace(/_/g,"/"),g=atob(f),k=new Uint8Array(g.length);for(let d=0;d<g.length;++d)k[d]=g.charCodeAt(d);return k}function ge(){const[t,b]=i.useState(!1),[f,g]=i.useState("default"),[k,d]=i.useState(!1),[p,C]=i.useState(!1);i.useEffect(()=>{const o="serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;b(o),o&&(g(Notification.permission),navigator.serviceWorker.getRegistration("/coach365-sw.js").then(async r=>{if(!r)return;const j=await r.pushManager.getSubscription();d(!!j)}))},[]);const L=async()=>{C(!0);try{const{data:o,error:r}=await h.functions.invoke("coach365-push-subscribe",{method:"GET"});if(r)throw r;const j=o==null?void 0:o.vapid_public_key;if(!j)throw new Error("Notifications non encore configurées (VAPID manquant). Réessaie bientôt.");const n=await Notification.requestPermission();if(g(n),n!=="granted"){y({title:"Notifications refusées",description:"Tu peux changer ça dans les réglages du navigateur."});return}const S=await navigator.serviceWorker.register("/coach365-sw.js",{scope:"/coach365/"});await navigator.serviceWorker.ready;const v=he(j),q=await S.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength)}),{error:u}=await h.functions.invoke("coach365-push-subscribe",{body:{action:"subscribe",subscription:q.toJSON(),user_agent:navigator.userAgent}});if(u)throw u;d(!0),y({title:"Notifications activées ð",description:"Tu recevras ta capsule chaque matin à 7h."})}catch(o){y({title:"Erreur",description:o.message??"Impossible d'activer les notifications",variant:"destructive"})}finally{C(!1)}},l=async()=>{C(!0);try{const o=await navigator.serviceWorker.getRegistration("/coach365-sw.js"),r=await(o==null?void 0:o.pushManager.getSubscription());r&&(await h.functions.invoke("coach365-push-subscribe",{body:{action:"unsubscribe",endpoint:r.endpoint}}),await r.unsubscribe()),d(!1),y({title:"Notifications désactivées"})}catch(o){y({title:"Erreur",description:o.message,variant:"destructive"})}finally{C(!1)}};return t?k?e.jsxs(w,{variant:"outline",size:"sm",onClick:l,disabled:p,children:[p?e.jsx(_,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(x,{className:"h-3.5 w-3.5 mr-1.5"}),"Notifications actives"]}):e.jsxs(w,{variant:"outline",size:"sm",onClick:L,disabled:p||f==="denied",children:[p?e.jsx(_,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Z,{className:"h-3.5 w-3.5 mr-1.5"}),f==="denied"?"Notifications bloquées":"Activer les rappels matin"]}):e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-2",children:[e.jsx(me,{className:"h-3.5 w-3.5"})," Notifications non supportées sur ce navigateur."]})}const xe={mindset:"bg-amber-500/10 text-amber-600 border-amber-500/30",neurosciences:"bg-violet-500/10 text-violet-600 border-violet-500/30",habitudes:"bg-emerald-500/10 text-emerald-600 border-emerald-500/30",vente:"bg-rose-500/10 text-rose-600 border-rose-500/30",energie:"bg-orange-500/10 text-orange-600 border-orange-500/30",ia:"bg-sky-500/10 text-sky-600 border-sky-500/30",frequences:"bg-fuchsia-500/10 text-fuchsia-600 border-fuchsia-500/30"};function je(){const{session:t,loading:b}=ee(),f=se(),[g,k]=i.useState(!0),[d,p]=i.useState(!1),[C,L]=i.useState(!0),[l,o]=i.useState(null),[r,j]=i.useState(null),[n,S]=i.useState({morning_done:!1,challenge_done:!1,evening_done:!1,mood:null,energy:null,reflection_note:""}),[v,q]=i.useState(""),[u,I]=i.useState(!1),[$,z]=i.useState("morning");i.useEffect(()=>
11{!b&&!t&&f("/login?next=/coach365/app")},[b,t,f]),i.useEffect(()=>{if(!t)return;let s=!1;return(async()=>{try{const{data:a,error:c}=await h.functions.invoke("coach365-check-subscription");if(s)return;if(c)throw c;p(!!(a!=null&&a.subscribed))}catch(a){console.error("[coach365] check-sub error",a),p(!1)}finally{s||k(!1)}})(),()=>{s=!0}},[t]);const F=i.useCallback(async()=>{if(t!=null&&t.user){L(!0);try{const{data:s}=await h.from("coach365_user_progress").select("*").eq("user_id",t.user.id).maybeSingle();let a=(s==null?void 0:s.current_day)??1;s||(await h.from("coach365_user_progress").insert({user_id:t.user.id,current_day:1}),a=1),j(s??{current_day:1,current_streak:0,longest_streak:0,total_check_ins:0,last_check_in_date:null});const{data:c}=await h.from("coach365_capsules").select("*").eq("day_number",a).maybeSingle();o(c);const N=new Date().toISOString().slice(0,10),{data:m}=await h.from("coach365_check_ins").select("*").eq("user_id",t.user.id).eq("check_in_date",N).maybeSingle();m&&(S({morning_done:m.morning_done,challenge_done:m.challenge_done,evening_done:m.evening_done,mood:m.mood,energy:m.energy,reflection_note:m.reflection_note}),q(m.reflection_note??""))}catch(s){console.error("[coach365] loadDay error",s)}finally{L(!1)}}},[t]);i.useEffect(()=>{d&&F()},[d,F]);const B=async(s,a)=>{if(!(!l||!t)){I(!0);try{const c={...n,[s]:!0,...(a==null?void 0:a.mood)!==void 0?{mood:a.mood}:{},...(a==null?void 0:a.energy)!==void 0?{energy:a.energy}:{},...(a==null?void 0:a.note)!==void 0?{reflection_note:a.note}:{}},{data:N,error:m}=await h.rpc("coach365_record_check_in",{p_capsule_id:l.id,p_day_number:l.day_number,p_morning_done:c.morning_done,p_challenge_done:c.challenge_done,p_evening_done:c.evening_done,p_mood:c.mood,p_energy:c.energy,p_note:c.reflection_note});if(m)throw m;S(c),N&&typeof N=="object"&&j(X=>({...X??{last_check_in_date:null},...N})),y({title:s==="morning_done"?"ð
Capsule lue":s==="challenge_done"?"ð¯ Défi accepté":"ð Check-in enregistré",description:"Bravo. à demain."})}catch(c){const N=c instanceof Error?c.message:String(c);y({title:"Erreur",description:N,variant:"destructive"})}finally{I(!1)}}};if(b||g)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-amber-50 via-rose-50 to-violet-50",children:e.jsx(_,{className:"h-8 w-8 animate-spin text-amber-600"})});if(!t)return null;if(!d)return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-amber-50 via-rose-50 to-violet-50 flex items-center justify-center p-6",children:[e.jsxs(R,{children:[e.jsx("title",{children:"Coach365 â Abonnement requis"}),e.jsx("meta",{name:"robots",content:"noindex"}),e.jsx("link",{rel:"manifest",href:"/coach365-manifest.json"}),e.jsx("meta",{name:"theme-color",content:"#f59e0b"}),e.jsx("meta",{name:"apple-mobile-web-app-capable",content:"yes"}),e.jsx("meta",{name:"apple-mobile-web-app-title",content:"Coach365"})]}),e.jsxs(T,{className:"max-w-md",children:[e.jsx(A,{children:e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-5 w-5 text-amber-600"}),"Abonnement Coach365 requis"]})}),e.jsxs(M,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"L'app quotidienne est réservée aux membres Coach365. Démarre ton essai 7 jours gratuit (sans CB)."}),e.jsx(w,{asChild:!0,className:"w-full bg-gradient-to-r from-amber-500 to-rose-500",children:e.jsxs(D,{to:"/coach365",children:["Voir les formules ",e.jsx(ne,{className:"ml-2 h-4 w-4"})]})})]})]})]});if(C||!l)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-amber-50 via-rose-50 to-violet-50",children:e.jsx(_,{className:"h-8 w-8 animate-spin text-amber-600"})});const K=n.morning_done&&n.challenge_done&&n.evening_done,G=xe[l.theme]??"bg-muted text-foreground border-border",Y=r?Math.round(r.current_day/365*100):0;return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-amber-50 via-rose-50 to-violet-50",children:[e.jsxs(R,{children:[e.jsxs("title",{children:["Coach365 â Jour ",l.day_number," / 365"]}),e.jsx("meta",{name:"robots",content:"noindex"}
11),e.jsx("link",{rel:"manifest",href:"/coach365-manifest.json"}),e.jsx("meta",{name:"theme-color",content:"#f59e0b"}),e.jsx("meta",{name:"apple-mobile-web-app-capable",content:"yes"}),e.jsx("meta",{name:"apple-mobile-web-app-title",content:"Coach365"})]}),e.jsxs("div",{className:"max-w-3xl mx-auto p-4 sm:p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs(D,{to:"/coach365",className:"text-sm text-muted-foreground hover:text-foreground inline-flex items-center gap-1",children:[e.jsx(ue,{className:"h-4 w-4"})," Coach365"]}),e.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 font-semibold text-orange-600",children:[e.jsx(te,{className:"h-4 w-4"})," ",(r==null?void 0:r.current_streak)??0]}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-muted-foreground",children:[e.jsx(re,{className:"h-4 w-4"})," ",(r==null?void 0:r.longest_streak)??0]})]})]}),e.jsx("div",{className:"mb-4 flex justify-end",children:e.jsx(ge,{})}),e.jsx(T,{className:"mb-4 border-2 shadow-lg backdrop-blur bg-white/80",children:e.jsxs(A,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx(H,{variant:"outline",className:G,children:l.theme}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Jour ",l.day_number," / 365 · ",l.duration_minutes," min"]})]}),e.jsx(E,{className:"text-2xl",children:l.title})]}),K&&e.jsxs(H,{className:"bg-emerald-500 text-white",children:[e.jsx(x,{className:"h-3 w-3 mr-1"})," Journée complète"]})]}),e.jsx(ie,{value:Y,className:"mt-3 h-1.5"})]})}),e.jsxs(oe,{value:$,onValueChange:s=>
11z(s),children:[e.jsxs(ce,{className:"grid w-full grid-cols-3 bg-white/60 backdrop-blur",children:[e.jsxs(O,{value:"morning",className:"gap-1",children:[e.jsx(Q,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Matin"}),n.morning_done&&e.jsx(x,{className:"h-3 w-3 text-emerald-600"})]}),e.jsxs(O,{value:"challenge",className:"gap-1",children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Défi"}),n.challenge_done&&e.jsx(x,{className:"h-3 w-3 text-emerald-600"})]}),e.jsxs(O,{value:"evening",className:"gap-1",children:[e.jsx(W,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Soir"}),n.evening_done&&e.jsx(x,{className:"h-3 w-3 text-emerald-600"})]})]}),e.jsx(P,{value:"morning",children:e.jsxs(T,{className:"bg-white/80 backdrop-blur",children:[e.jsx(A,{children:e.jsxs(E,{className:"flex items-center gap-2 text-amber-700",children:[e.jsx(Q,{className:"h-5 w-5"})," Capsule du matin"]})}),e.jsxs(M,{className:"space-y-4",children:[e.jsx("p",{className:"text-base leading-relaxed whitespace-pre-line",children:l.morning_capsule}),e.jsx(w,{onClick:()=>B("morning_done"),disabled:u||n.morning_done,className:"w-full bg-amber-500 hover:bg-amber-600",children:n.morning_done?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"mr-2 h-4 w-4"})," Capsule lue"]}):u?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:["J'ai lu â passer au défi ",e.jsx(J,{className:"ml-2 h-4 w-4"})]})})]})]})}),e.jsx(P,{value:"challenge",children:e.jsxs(T,{className:"bg-white/80 backdrop-blur",children:[e.jsx(A,{children:e.jsxs(E,{className:"flex items-center gap-2 text-rose-700",children:[e.jsx(V,{className:"h-5 w-5"})," Défi du jour"]})}),e.jsxs(M,{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border border-rose-200 bg-rose-50/60 p-4",children:e.jsx("p",{className:"text-base leading-relaxed",children:l.daily_challenge})}),e.jsx(w,{onClick:()=>B("challenge_done"),disabled:u||n.challenge_done,className:"w-full bg-rose-500 hover:bg-rose-600",children:n.challenge_done?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"mr-2 h-4 w-4"})," Défi accompli"]}):u?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:["C'est fait ",e.jsx(J,{className:"ml-2 h-4 w-4"})]})})]})]})}),e.jsx(P,{value:"evening",children:e.jsxs(T,{className:"bg-white/80 backdrop-blur",children:[e.jsx(A,{children:e.jsxs(E,{className:"flex items-center gap-2 text-violet-700",children:[e.jsx(W,{className:"h-5 w-5"})," Check-in du soir"]})}),e.jsxs(M,{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-violet-200 bg-violet-50/60 p-4",children:[e.jsx("p",{className:"text-sm font-medium text-violet-900 mb-1",children:"Question du soir"}),e.jsx("p",{className:"text-base",children:l.evening_reflection})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Humeur du jour"}),e.jsx("div",{className:"flex justify-between gap-2",children:[1,2,3,4,5].map(s=>e.jsx("button",{onClick:()=>S(a=>({...a,mood:s})),className:`flex-1 py-3 rounded-lg border-2 text-2xl transition ${n.mood===s?"border-violet-500 bg-violet-100":"border-border hover:border-violet-300"}`,type:"button",children:["ð","ð","ð","ð","ð"][s-1]},s))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Ãnergie"}),e.jsx("div",{className:"flex justify-between gap-2",children:[1,2,3,4,5].map(s=>e.jsx("button",{onClick:()=>S(a=>({...a,energy:s})),className:`flex-1 py-2 rounded-lg border-2 text-sm font-semibold transition ${n.energy===s?"border-orange-500 bg-orange-100 text-orange-700":"border-border hover:border-orange-300 text-muted-foreground"}`,type:"button",children:s},s))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Ta réflexion (optionnelle)"}),e.jsx(le,{value:v,onChange:s=>q(s.target.value),placeholder:"Quelques mots pour toi-mêmeâ¦",rows:3})]}),e.jsx(w,{onClick:()=>B("evening_done",{mood:n.mood??void 0,energy:n.energy??void 0,note:v}),disabled:u||n.evening_done||n.mood===null,className:"w-full bg-violet-600 hover:bg-violet-700",children:n.evening_done?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"mr-2 h-4 w-4"})," Bonne nuit"]}):u?e.jsx(_,{className:"h-4 w-4 animate-spin"}):e.jsx(e.Fragment,{children:"Valider mon check-in"})})]})]})})]}),!t&&e.jsx("div",{className:"mt-6 text-center",children:e.jsx(w,{asChild:!0,variant:"outline",children:e.jsxs(D,{to:"/login?next=/coach365/
11app",children:[e.jsx(de,{className:"mr-2 h-4 w-4"})," Se connecter"]})})})]})]})}export{je 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.