PageSourceSearch

https://mindgolf.ai/assets/DiaryDetail-DsVUWqlt.js

js mindgolf.ai collected 2026-10-05 14:52:37 UTC 29,090 bytes, 9 lines download raw bytes

1import{r as A,j as e,q as me,n as ne}from"./vendor-ahVw9cdH.js";import{A as $}from"./AppBreadcrumb-DQQeh5xA.js";import{Z as xe,O as T,d0 as ue,dM as he,dN as fe,dO as ge,dP as pe,ah as K,be as je,bf as ye,bg as ee,bh as se,R as M,cC as te,dz as Ne,dx as ie,V as f,q as W,iE as ve,iF as be,iG as _e,c1 as ae,eq as we,a5 as p,aW as N,bd as v,a6 as j,a7 as L,af as y,b8 as q,iH as H,bb as F,ac as B,ep as E,bi as ke,fx as Ce,aX as U,S as re,du as De,bZ as Se,b0 as Ae,b1 as Te,b3 as Me,b4 as Le,bN as Pe,bP as Re,bQ as ze,bR as Ee,bS as Ie,bT as qe,bU as Ge,bV as Ke,fz as Fe,bA as G,iv as Be}from"./index-DXi0I5ak.js";import{u as X,a as Oe}from"./query-CeIq2NOR.js";import{g as $e,D as He}from"./diary-utils-uSqDg-av.js";import{A as Ue}from"./AILoadingIndicator-iQITGPSS.js";import{a as Qe,b as Ve}from"./useExternalSGImport-DBeOARlz.js";import{Z as I}from"./zap-FPBcTry6.js";import{T as Ze}from"./TierLegend-eS4dvAPO.js";import{A as le}from"./arrow-up-8F0XduxV.js";import{A as ce}from"./arrow-down-B36Nnym0.js";import{M as We}from"./minus-D7WxUA4j.js";import{L as Xe}from"./leaf-2DQtBW2z.js";import"./breadcrumb-C59QT_kB.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./forms-Cc1FL3tT.js";import"./elite-sg-applicability-CWAcEzPE.js";import"./golf-stat-tiers-B_t78XU2.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 Ye=xe("Link2Off",[["path",{d:"M9 17H7A5 5 0 0 1 7 7",key:"10o201"}],["path",{d:"M15 7h2a5 5 0 0 1 4 8",key:"1d3206"}],["line",{x1:"8",x2:"12",y1:"12",y2:"12",key:"rvw6j4"}],["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}]]);function Je(s,r){return X({queryKey:["diary-entry",s,r],queryFn:async()=>{var o;if(!s||!r)return null;const{data:n,error:l}=await T.from("diary_entries").select(`
7          *,
8          insights:diary_insights(*)
9        `).eq("id",s).eq("player_id",r).single();if(l)throw console.error("[useDiaryEntry] Error fetching entry:",l),l;if(!n)return null;const a=((o=n.insights)==null?void 0:o[0])||null;return{...n,insights:a?{...a,top_signals:a.top_signals,recurring_themes_scored:a.recurring_themes_scored,mental_triggers_scored:a.mental_triggers_scored,behavioral_patterns_scored:a.behavioral_patterns_scored,diary_kpis:a.diary_kpis,commitment_modifiers:a.commitment_modifiers,emotions_modifiers:a.emotions_modifiers,focus_modifiers:a.focus_modifiers}:null}},enabled:!!s&&!!r,staleTime:1e3*60*5})}function es({open:s,onOpenChange:r,externalSGId:n,externalDate:l,externalCourseName:a,onLink:o,isLinking:d}){const[m,w]=A.useState("rounds"),{data:D}=ue(),g=D==null?void 0:D.id,{data:S=[],isLoading:_}=X({queryKey:["rounds-for-linking",g],queryFn:async()=>{if(!g)return[];const{data:i,error:u}=await T.from("rounds").select("id, start_time, course_name").eq("player_id",g).order("start_time",{ascending:!1}).limit(20);if(u)throw u;return i||[]},enabled:!!g&&s}),{data:t=[],isLoading:b}=X({queryKey:["reflections-for-linking",g],queryFn:async()=>{if(!g)return[];const{data:i,error:u}=await T.from("diary_entries").select("id, created_at, text_content, entry_type").eq("player_id",g).order("created_at",{ascending:!1}).limit(20);if(u)throw u;return i||[]},enabled:!!g&&s}),P=i=>{o({externalSGId:n,roundId:i,matchMethod:"manual"})},x=i=>{o({externalSGId:n,diaryEntryId:i,matchMethod:"manual"})},k=i=>{try{return W(new Date(i),"MMM d, yyyy")}catch{return i}},C=(i,u=50)=>i?i.length>u?i.slice(0,u)+"...":i:"No description";return e.jsx(he,{open:s,onOpenChange:r,children:e.jsxs(fe,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsxs(pe,{className:"flex items-center gap-2",children:[e.jsx(K,{className:"h-5 w-5"}),"Link Strokes Gained Data"]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Linking: ",e.jsx("strong",{children:a||"Unknown Course"})," (",k(l),")"]})]}),e.jsxs(je,{value:m,onValueChange:i=>w(i),children:[(S.length>0||t.length>0)&&e.jsxs(ye,{className:"grid w-full grid-cols-2",children:[e.jsx(ee,{value:"rounds",children:"Rounds"}),e.jsx(ee,{value:"reflections",children:"Reflections"})]}),e.jsx(se,{value:"rounds",className:"mt-4",children:_?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(M,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):S.length===0?e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:"No rounds available to link"}):e.jsx(te,{className:"h-[300px]",children:e.jsx("div",{className:"space-y-2 pr-4",children:S.map(i=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ne,{className:"h-3 w-3 text-muted-foreground"}),i.course_name||"Unknown Course"]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ie,{className:"h-3 w-3"}),k(i.start_time)]})]}),e.jsx(f,{size:"sm",variant:"outline",onClick:()=>P(i.id),disabled:d,children:d?e.jsx(M,{className:"h-4 w-4 animate-spin"}):"Link"})]},i.id))})})}),e.jsx(se,{value:"reflections",className:"mt-4",children:b?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(M,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.length===0?e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:"No reflections available to link"}):e.jsx(te,{className:"h-[300px]",children:e.jsx("div",{className:"space-y-2 pr-4",children:t.map(i=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"space-y-1 flex-1 mr-3",children:[e.jsx("div",{className:"text-sm font-medium",children:i.entry_type||"Reflection"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:k(i.created_at)}),e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-1",children:C(i.text_content)})]}),e.jsx(f,{size:"sm",variant:"outline",onClick:()=>x(i.id),disabled:d,children:d?e.jsx(M,{className:"h-4 w-4 animate-spin"}):"Link"})]},i.id))})})})]})]})})}const R=s=>s==null?"—":`${s>=0?"+":""}${s.toFixed(2)}`,ss=s=>{switch(s){case"auto_date":return{label:"Auto-linked",tooltip:"Automatically matched by date and course name"};case"pre_linked":return{label:"Pre-linked",tooltip:"Linked before recording started"};case"manual":return{label:"CSV Import",tooltip:"Imported from CSV file"};case"app_integration":return{label:"Auto-synced",tooltip:"Automatically synced from connected golf app"};default:return{label:"Linked",tooltip:"Linked to external SG data"}}},ts=(s,r)=>{if(!r||!s.length)return s;const n=new Date(r);return s.filter(l=>{const a=new Date(l.round_date);return Math.abs(n.getTime()-a.getTime())/(1e3*60*60*24)<=7}).sort((l,a)=>{const o=Math.abs(new Date(r).getTime()-new Date(l.round_date).getTime()),d=Math.abs(new Date(r).getTime()-new Date(a.round_date).getTime());return o-d})};function as({roundId:s,diaryEntryId:r,roundDate:n,variant:l="compact"}){const[a,o]=A.useState(!1),{data:d,isLoading:m}=ve(s),{data:w,isLoading:D}=be(r),{data:g,isLoading:S}=_e(),_=Qe(),t=Ve(),b=s?d:w,P=s?m:D,x=ts(g||[],n),k=()=>
9{b!=null&&b.matchId&&t.mutate(b.matchId)},C=i=>{_.mutate(i,{onSuccess:()=>{o(!1)}})};if(P||S)return null;if(b){const i=b.externalSG,u=ss("manual");return l==="compact"?e.jsxs("div",{className:"flex items-center justify-between gap-2 p-3 rounded-lg bg-primary/5 border border-primary/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"SG Total:"})]}),e.jsx(we,{value:i.sg_total,size:"sm",className:"text-lg"})]}):e.jsxs(p,{className:"border-primary/20",children:[e.jsx(N,{className:"pb-2",children:e.jsxs(v,{className:"text-sm flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4 text-primary"}),"Linked Strokes Gained"]})}),e.jsxs(j,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"}),e.jsx("p",{className:"font-mono text-lg font-semibold",children:R(i.sg_total)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Off Tee"}),e.jsx("p",{className:"font-mono",children:R(i.sg_off_tee)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Approach"}),e.jsx("p",{className:"font-mono",children:R(i.sg_approach)})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Putting"}),e.jsx("p",{className:"font-mono",children:R(i.sg_putting)})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(L,{variant:"outline",className:"text-xs gap-1",children:[e.jsx(y,{className:"h-3 w-3"}),u.label]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["from ",i.external_source]})]}),e.jsxs(f,{variant:"ghost",size:"sm",className:"text-muted-foreground hover:text-destructive",onClick:k,disabled:t.isPending,children:[t.isPending?e.jsx(M,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(Ye,{className:"h-4 w-4 mr-1"}),"Unlink"]})]})]})]})}return x.length===0?null:l==="compact"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-muted/50 border border-dashed",children:[e.jsx(I,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex-1",children:e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:x.length})," Strokes Gained record",x.length!==1?"s":""," available to link"]})}),e.jsxs(f,{variant:"outline",size:"sm",className:"shrink-0 gap-1",onClick:()=>o(!0),children:[e.jsx(K,{className:"h-3 w-3"}),"Link"]})]}),x[0]&&e.jsx(es,{open:a,onOpenChange:o,externalSGId:x[0].id,externalDate:x[0].round_date,externalCourseName:x[0].course_name,onLink:i=>C({...i,roundId:i.roundId||s,diaryEntryId:i.diaryEntryId||r}),isLinking:_.isPending})]}):e.jsxs(p,{className:"border-dashed",children:[e.jsx(N,{className:"pb-2",children:e.jsxs(v,{className:"text-sm flex items-center gap-2 text-muted-foreground",children:[e.jsx(I,{className:"h-4 w-4"}),"Link Strokes Gained Data"]})}),e.jsxs(j,{children:[e.jsxs("p",{className:"text-sm text-muted-foreground mb-3",children:[x.length," Strokes Gained record",x.length!==1?"s":""," available near this date"]}),e.jsx("div",{className:"space-y-2",children:x.slice(0,3).map(i=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:i.course_name||"Unknown course"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[i.round_date," • ",R(i.sg_total)," SG"]})]}),e.jsxs(f,{variant:"outline",size:"sm",className:"gap-1",onClick:()=>{C({externalSGId:i.id,roundId:s,diaryEntryId:r,matchMethod:"manual"})},disabled:_.isPending,children:[_.isPending?e.jsx(M,{className:"h-3 w-3 animate-spin"}):e.jsx(K,{className:"h-3 w-3"}),"Link"]})]},i.id))})]})]})}function rs({score:s}){const r=Math.round(s),n=q(r);return e.jsxs(p,{children:[e.jsx(N,{className:"pb-2",children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-primary"}),"Reflection Mental Score"]})}),e.jsxs(j,{className:"flex flex-col items-center py-4",children:[e.jsx("div",{className:"w-32 h-32 rounded-full flex items-center justify-center border-8",style:{borderColor:n},children:e.jsxs("span",{className:"text-3xl font-bold",style:{color:n},children:[r,e.jsx("span",{className:"text-base",children:"%"})]})}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Based on this reflection"})]})]})}function Q({label:s,value:r,color:n,icon:l}){const a=Math.max(-1,Math.min(1,r)),o=Math.abs(a)*50,d=a>=0,m=d?"+":"";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"flex items-center gap-1.5 font-medium",style:{color:n},children:[l,s]}),e.jsxs("span",{className:"font-bold tabular-nums",style:{color:n},children:[m,a.toFixed(2)]})]}),e.jsxs("div",{className:"relative h-2 rounded-full bg-muted overflow-hidden",children:[e.jsx("div",{className:"absolute top-0 bottom-0 left-1/2 w-px bg-border"}),e.jsx("div",{className:"absolute top-0 bottom-0 rounded-full",style:{backgroundColor:n,width:`${o}%`,left:d?"50%":`${50-o}%`}})]})]})}function ns({kpis:s}){const r=s.commitment??null,n=s.emotions??null,l=s.focus??null;return r===null&&n===null&&l===null?null:e.jsxs(p,{children:[e.jsxs(N,{className:"pb-2",children:[e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-primary"}),"KPI Impact"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"How this reflection nudges each KPI"})]}),e.jsxs(j,{className:"space-y-4",children:[r!==null&&e.jsx(Q,{label:"Commitment",value:r,color:H.commitment,icon:e.jsx(y,{className:"h-3.5 w-3.5"})}),n!==null&&e.jsx(Q,{label:"Emotions",value:n,color:H.emotions,icon:e.jsx(F,{className:"h-3.5 w-3.5"})}),l!==null&&e.jsx(Q,{label:"Focus",value:l,color:H.focus,icon:e.jsx(B,{className:"h-3.5 w-3.5"})})]})]})}function z({label:s,value:r,icon:n,inverted:l=!1}){const a=Math.round(r*10),o=l?100-a:a,d=q(o);return e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[n," ",s]}),e.jsxs("div",{className:"text-lg font-bold",style:{color:d},children:[a,"%"]})]})}function is({ratio:s,themes:r}){const n=s!=null,l=r&&r.length>0;if(!n&&!l)return null;const a=n?Math.round((s||0)*100):null,o=a!==null?q(a):void 0;return e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4 text-primary"}),"Self-Talk"]})}),e.jsxs(j,{className:"space-y-4",children:[n&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Positive Self-Talk Ratio"}),e.jsxs("div",{className:"text-2xl font-bold",style:{color:o},children:[a,"%"]})]}),l&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground mb-2",children:"Themes"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.map((d,m)=>e.jsxs(L,{variant:"secondary",className:"gap-1",children:[e.jsx(E,{className:"h-3 w-3"}),d]},m))})]})]})]})}function V({title:s,prefix:r,scored:n,fallback:l}){const a=n&&n.length>0,o=l&&l.length>0;return!a&&!o?null:e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-muted-foreground mb-2",children:s}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a?n.map((d,m)=>e.jsxs(L,{variant:"outline",className:"gap-1",style:{borderColor:q(d.score),color:q(d.score)},children:[r?`${r} `:"",d.text,e.jsxs("span",{className:"text-[10px] opacity-75",children:["(",d.score,"%)"]})]},m)):l.map((d,m)=>e.jsxs(L,{variant:"outline",children:[r?`${r} `:"",d]},m))})]})}function ls({themesScored:s,themesFallback:r,triggersScored:n,triggersFallback:l,patternsScored:a,patternsFallback:o}){return s&&s.length>0||r&&r.length>0||n&&n.length>0||l&&l.length>0||a&&a.length>0||o&&o.length>0?e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-primary"}),"Patterns, Triggers & Themes"]})}),e.jsxs(j,{className:"space-y-4",children:[e.jsx(V,{title:"Themes",scored:s,fallback:r}),e.jsx(V,{title:"Triggers",prefix:"⚡",scored:n,fallback:l}
9),e.jsx(V,{title:"Patterns",scored:a,fallback:o}),e.jsx("div",{className:"pt-4 mt-2 border-t",children:e.jsx(Ze,{})})]})]}):null}function Z({label:s,icon:r,value:n}){const l=n??0,a=l>.01,o=l<-.01,d=a?"text-green-600 dark:text-green-400":o?"text-red-600 dark:text-red-400":"text-muted-foreground",m=a?le:o?ce:We,w=a?"+":"";return e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[r," ",s]}),e.jsxs("div",{className:`text-lg font-bold flex items-center gap-1 ${d}`,children:[e.jsx(m,{className:"h-4 w-4"}),w,l.toFixed(2)]})]})}function cs({commitment:s,emotions:r,focus:n}){const l=(s==null?void 0:s.modifier)??null,a=(r==null?void 0:r.modifier)??null,o=(n==null?void 0:n.modifier)??null;return(l===null||Math.abs(l)<.01)&&(a===null||Math.abs(a)<.01)&&(o===null||Math.abs(o)<.01)?null:e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-primary"}),"KPI Modifiers"]})}),e.jsxs(j,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(Z,{label:"Commitment",icon:e.jsx(y,{className:"h-3 w-3"}),value:l}),e.jsx(Z,{label:"Emotions",icon:e.jsx(F,{className:"h-3 w-3"}),value:a}),e.jsx(Z,{label:"Focus",icon:e.jsx(B,{className:"h-3 w-3"}),value:o})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:"Net impact of this reflection on each KPI (signed delta)."})]})]})}const os=s=>{switch(s){case"commitment":return e.jsx(y,{className:"h-3 w-3"});case"emotions":return e.jsx(F,{className:"h-3 w-3"});case"focus":return e.jsx(B,{className:"h-3 w-3"});default:return e.jsx(y,{className:"h-3 w-3"})}},ds=s=>{switch(s){case"commitment":return"Commitment";case"emotions":return"Emotions";case"focus":return"Focus";default:return s}},ms=s=>{switch(s){case"emotional_marker":return"Emotion";case"self_talk":return"Self-Talk";case"recurring_theme":return"Pattern";case"mental_trigger":return"Trigger";case"behavioral_pattern":return"Behavior";case"lifestyle_factor":return"Lifestyle";case"anticipatory_anxiety":return"Anxiety";default:return s}};function xs({signal:s}){const r=ne(),n=s.impact==="positive";return e.jsxs("div",{className:"py-3 border-b border-border/50 last:border-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx(L,{variant:"outline",className:"text-[10px] px-1 py-0",children:ms(s.signal_category)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground italic",children:['"',s.signal_text,'"']}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(f,{variant:"ghost",size:"sm",className:"h-auto py-1 px-2 text-xs font-medium text-violet-600 dark:text-violet-400 hover:bg-violet-50 dark:hover:bg-violet-950/30",onClick:()=>r(`/contributor/${s.contributor_key}`),children:s.contributor_label}),e.jsxs("div",{className:`flex items-center gap-1 px-2 py-1 rounded ${n?"bg-green-50 dark:bg-green-950/30 text-green-700 dark:text-green-400":"bg-red-50 dark:bg-red-950/30 text-red-700 dark:text-red-400"}`,children:[os(s.kpi),e.jsx("span",{className:"text-xs font-medium",children:ds(s.kpi)}),n?e.jsx(le,{className:"h-3 w-3"}):e.jsx(ce,{className:"h-3 w-3"})]})]})]})}const Ps=()=>{const{entryId:s}=me(),r=ne(),n=Oe(),{userId:l}=ke(),a=l??void 0,[o,d]=A.useState(!1),[m,w]=A.useState(!1),[D,g]=A.useState(!1),[S,_]=A.useState(!1),{data:t,isLoading:b,error:P}=Je(s,a),{register:x}=Ce();A.useEffect(()=>{if(s)return x(`diary-${s}`,{contextType:"diary_entry",contextKey:`diary_${s}`,pageTitle:"Reflection detail",viewerRole:"player",contextData:{entryId:s,entryDate:t==null?void 0:t.entry_date,entryType:t==null?void 0:t.entry_type,roundId:(t==null?void 0:t.round_id)??null}})},[s,t==null?void 0:t.entry_date,t==null?void 0:t.round_id,x]);const k=async()=>{if(t){g(!0);try{await T.from("diary_entries").update({processing_status:"processing"}).eq("id",t.id);const{error:h}=await T.functions.invoke("analyze-diary-entry",{body:{diary_entry_id:t.id}});if(h)throw h;G.success("Reflection analyzed successfully!"),n.invalidateQueries({queryKey:["diary-entry",s]}),n.invalidateQueries({queryKey:["diary-entries"]}),n.invalidateQueries({queryKey:["diary-insights-summary",a]}),n.invalidateQueries({queryKey:["diary-collection-tiers",a]})}catch(h){console.error("Error processing diary entry:",h),G.error("Failed to analyze reflection"),await T.from("diary_entries").update({processing_status:"draft",error_message:String(h)}).eq("id",t.id)}finally{g(!1)}}},C=()=>{_(!0)},i=async()=>
9{if(t){w(!0);try{const{error:h}=await T.from("diary_entries").delete().eq("id",t.id);if(h)throw h;G.success("Reflection deleted"),n.invalidateQueries({queryKey:["diary-entries"]}),n.invalidateQueries({queryKey:["diary-insights-summary",a]}),r("/activity?tab=lifestyle")}catch(h){console.error("Error deleting diary entry:",h),G.error("Failed to delete reflection")}finally{w(!1),d(!1)}}};if(b||!a)return e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity?tab=lifestyle"},{label:"Loading..."}]}),e.jsx(U,{className:"h-8 w-48"}),e.jsx(U,{className:"h-48 w-full"}),e.jsx(U,{className:"h-32 w-full"})]});if(P||!t)return e.jsxs("div",{className:"space-y-4",children:[e.jsx($,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity?tab=lifestyle"},{label:"Not Found"}]}),e.jsx(p,{children:e.jsxs(j,{className:"py-8 text-center",children:[e.jsx(re,{className:"h-8 w-8 mx-auto text-destructive mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"Reflection not found"}),e.jsx(f,{variant:"outline",className:"mt-4",onClick:()=>r("/activity?tab=lifestyle"),children:"Back to Activity"})]})})]});const u=$e(t.entry_type),O=t.text_content||t.transcribed_text||"",c=t.insights,Y=(c==null?void 0:c.top_signals)||[],oe=t.processing_status==="draft",J=t.processing_status==="processing"||D;return e.jsxs("div",{className:"space-y-6",children:[e.jsx($,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity?tab=lifestyle"},{label:`Reflection — ${W(new Date(t.entry_date),"MMM d, yyyy")}`}]}),e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(De,{className:"h-6 w-6 text-primary"}),"Reflection Detail"]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 flex-wrap",children:[e.jsxs("span",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(ie,{className:"h-4 w-4"}),W(new Date(t.entry_date),"MMMM d, yyyy")]}),e.jsxs(L,{variant:u.variant,className:"text-xs gap-1",children:[e.jsx("span",{children:u.icon}),u.label]}),t.round_id&&e.jsxs(L,{variant:"outline",className:"text-xs gap-1 cursor-pointer",onClick:()=>r(`/rounds/${t.round_id}`),children:[e.jsx(K,{className:"h-3 w-3"}),"View Round"]}),e.jsx(He,{processingStatus:t.processing_status})]})]}),e.jsx(f,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>d(!0),children:e.jsx(Se,{className:"h-5 w-5"})})]}),(oe||J)&&e.jsx("div",{className:"bg-gradient-to-r from-violet-500 via-purple-500 to-blue-500 p-[2px] rounded-xl",children:e.jsxs(p,{className:"border-0 rounded-xl bg-background",children:[e.jsx(N,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"h-5 w-5 text-violet-500"}),e.jsx(v,{className:"text-base font-semibold",children:"MindGolf Assistant"})]})}),e.jsx(j,{className:"space-y-4",children:J?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ue,{phase:"reflection"}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:"Analyzing your activity for mental patterns and insights..."}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(f,{variant:"outline",onClick:C,className:"gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),"Continue Activity"]})})]}):t.source_thread_id?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your activity is in progress. Continue the conversation to add more — analysis runs only when you click Complete & Save."}),e.jsx("div",{className:"flex justify-center",children:e.jsxs(f,{variant:"outline",onClick:C,className:"gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),"Continue Activity"]})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Start Assistant Analysis to extract mental patterns, emotional signals, and personalized insights from your activity."}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(f,{onClick:k,variant:"ai",className:"gap-2",children:[e.jsx(y,{className:"h-4 w-4"}),"Process & Analyze"]}),e.jsxs(f,{variant:"outline",onClick:C,className:"gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),"Continue Activity"]})]})]})})]})}),e.jsx(as,{diaryEntryId:t.id,roundDate:t.entry_date,variant:"compact"}),e.jsx(p,{children:e.jsxs(Ae,{children:[e.jsx(N,{className:"pb-0",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{className:"text-base",children:"Activity Content"}),e.jsx(Te,{asChild:!0,children:e.jsxs(f,{variant:"ghost",size:"sm",className:"gap-1 text-xs text-muted-foreground",children:["Read more",e.jsx(Me,{className:"h-3 w-3"})]})})]})}),e.jsxs(j,{className:"pt-3",children:[e.jsx("div",{className:"bg-muted/50 rounded-lg p-4",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap line-clamp-3",children:O})}),e.jsx(Le,{children:O.length>150&&e.jsx("div",{className:"bg-muted/50 rounded-lg p-4 mt-2",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:O})})})]})]})}),c&&t.processing_status==="analyzed"&&c.diary_mental_score!==null&&c.diary_mental_score!==void 0&&e.jsx(rs,{score:Number(c.diary_mental_score)}),c&&t.processing_status==="analyzed"&&c.diary_kpis&&e.jsx(ns,{kpis:c.diary_kpis}),c&&t.processing_status==="analyzed"&&(c.emotional_state||c.confidence_level||c.motivation_level||c.energy_level||c.stress_level!==null)&&e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-primary"}),"Mental Snapshot"]})}),e.jsx(j,{children:e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:[c.emotional_state!=null&&e.jsx(z,{label:"Emotional State",value:c.emotional_state,icon:e.jsx(F,{className:"h-3 w-3"})}),c.confidence_level!=null&&e.jsx(z,{label:"Confidence",value:c.confidence_level,icon:e.jsx(B,{className:"h-3 w-3"})}),c.motivation_level!=null&&e.jsx(z,{label:"Motivation",value:c.motivation_level,icon:e.jsx(I,{className:"h-3 w-3"})}),c.energy_level!=null&&e.jsx(z,{label:"Energy",value:c.energy_level,icon:e.jsx(I,{className:"h-3 w-3"})}),c.stress_level!=null&&e.jsx(z,{label:"Calm",value:10-c.stress_level,icon:e.jsx(Xe,{className:"h-3 w-3"})})]})})]}),c&&t.processing_status==="analyzed"&&e.jsx(is,{ratio:c.self_talk_positive_ratio,themes:c.self_talk_themes}),c&&t.processing_status==="analyzed"&&e.jsx(ls,{themesScored:c.recurring_themes_scored,themesFallback:c.recurring_themes,triggersScored:c.mental_triggers_scored,triggersFallback:c.mental_triggers,patternsScored:c.behavioral_patterns_scored,patternsFallback:c.behavioral_patterns}),c&&t.processing_status==="analyzed"&&e.jsx(cs,{commitment:c.commitment_modifiers,emotions:c.emotions_modifiers,focus:c.focus_modifiers}),Y.length>0&&t.processing_status==="analyzed"&&e.jsxs(p,{children:[e.jsx(N,{children:e.jsxs(v,{className:"text-base flex items-center gap-2",children:[e.jsx(I,{className:"h-4 w-4 text-primary"}),"Mental Signals"]})}),e.jsx(j,{children:e.jsx("div",{className:"space-y-0",children:Y.map((h,de)=>e.jsx(xs,{signal:h},de))})})]}),t.processing_status==="error"&&t.error_message&&e.jsx(p,{className:"border-destructive",children:e.jsxs(j,{className:"py-4",children:[e.jsxs("div",{className:"text-sm text-destructive flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4"}),t.error_message]}),e.jsx(f,{variant:"outline",size:"sm",className:"mt-3",onClick:k,children:"Retry Analysis"})]})}),e.jsx(Pe,{open:o,onOpenChange:d,children:e.jsxs(Re,{children:[e.jsxs(ze,{children:[e.jsx(Ee,{children:"Delete Reflection?"}),e.jsx(Ie,{children:"This will permanently delete this reflection and all its insights. This action cannot be undone."})]}),e.jsxs(qe,{children:[e.jsx(Ge,{children:"Cancel"}),e.jsxs(Ke,{onClick:i,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:m,children:[m?e.jsx(M,{className:"h-4 w-4 animate-spin mr-2"}):null,"Delete"]})]})]})}),a&&e.jsx(Fe,{open:S,onOpenChange:_,diaryEntryId:t.id,onReflectionFinalized:h=>{h==="cancelled"?r("/activity?tab=lifestyle"):n.invalidateQueries({queryKey:["diary-entry",s]})},payload:{contextType:"diary_reflection",contextKey:"default",pageTitle:"Activity",viewerRole:"player",contextData:{userId:a,diaryEntryId:t.id}}})]})};export{Ps 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.