1import{q as D,n as A,r as f,j as e}from"./vendor-ahVw9cdH.js";import{A as v}from"./AppBreadcrumb-DQQeh5xA.js";import{bi as C,er as M,es as I,aX as j,a5 as y,a6 as g,S,V as N,q as b,et as k,dx as T,bZ as _,aW as $,bd as E,bN as H,bP as L,bQ as R,bR as B,bS as F,bT as K,bU as P,bV as U,en as w,a4 as q,az as z}from"./index-DXi0I5ak.js";import{A as V}from"./AIAssistantTrigger-C4Hxq-OR.js";import"./breadcrumb-C59QT_kB.js";import"./radix--pSzM2y8.js";import"./supabase-DYrB2Yg5.js";import"./charts-CSweoJhv.js";import"./query-CeIq2NOR.js";import"./forms-Cc1FL3tT.js";const G=m=>{const r=m.split(` 2`),s=[];let c=!1,a=[],o="";const n=()=>{if(a.length>0){const t=a.join(` 3`).replace(/^>\s*/gm,"").trim();s.push(e.jsx("div",{className:"my-3 p-3 bg-violet-500/10 border-l-3 border-violet-500 rounded-r-md",children:e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsx(w,{className:"h-4 w-4 text-violet-500 mt-0.5 shrink-0"}),e.jsx("div",{className:"text-sm space-y-1",children:d(t)})]})},o)),a=[],c=!1}};return r.forEach((t,i)=>{const l=`line-${i}`;if(t.match(/^>\s*/)){c||(c=!0,o=l),a.push(t);return}else c&&n();if(t.match(/^[-]{3,}$/)){s.push(e.jsx("hr",{className:"my-4 border-border/50"},l));return}const x=t.match(/^(key insight|takeaway|action|tip|exercise|try this)[:]\s*(.*)/i);if(x){s.push(e.jsx("div",{className:"my-3 p-3 bg-amber-500/10 border-l-3 border-amber-500 rounded-r-md",children:e.jsxs("div",{className:"flex gap-2 items-start",children:[e.jsx(w,{className:"h-4 w-4 text-amber-500 mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs font-semibold text-amber-600 dark:text-amber-400 uppercase tracking-wide",children:x[1]}),e.jsx("p",{className:"text-sm mt-1",children:d(x[2])})]})]})},l));return}const u=t.match(/^###\s+(.*)$/);if(u){s.push(e.jsx("h3",{className:"text-base font-semibold text-foreground mt-4 mb-2 first:mt-0",children:d(u[1])},l));return}const p=t.match(/^##\s+(.*)$/);if(p){s.push(e.jsx("h2",{className:"text-lg font-semibold text-foreground mt-4 mb-2 first:mt-0",children:d(p[1])},l));return}if(t.match(/^[âââââ]\s+/)||t.match(/^[-*]\s+\[.\]\s+/)){const h=t.replace(/^[âââââ]\s+/,"").replace(/^[-*]\s+\[.\]\s+/,"");s.push(e.jsxs("div",{className:"flex gap-2 my-1.5 items-start",children:[e.jsx(q,{className:"h-3.5 w-3.5 text-violet-500 mt-0.5 shrink-0"}),e.jsx("span",{className:"text-sm",children:d(h)})]},l));return}if(t.match(/^[-*]\s+/)){const h=t.replace(/^[-*]\s+/,"");s.push(e.jsxs("div",{className:"flex gap-2.5 my-1.5 items-start pl-1",children:[e.jsx("span",{className:"text-violet-500 font-bold mt-px",children:"â¢"}),e.jsx("span",{className:"text-sm leading-relaxed",children:d(h)})]},l));return}if(t.match(/^\d+\.\s+/)){const h=t.match(/^(\d+)\.\s+(.*)$/);h&&s.push(e.jsxs("div",{className:"flex gap-2.5 my-1.5 items-start pl-1",children:[e.jsxs("span",{className:"text-violet-500 font-semibold text-sm min-w-[1.25rem]",children:[h[1],"."]}),e.jsx("span",{className:"text-sm leading-relaxed",children:d(h[2])})]},l));return}if(t.trim()===""){s.push(e.jsx("div",{className:"h-2"},l));return}s.push(e.jsx("p",{className:"my-1.5 text-sm leading-relaxed text-foreground/90",children:d(t)},l))}),n(),s},d=m=>{const r=[];let s=m,c=0;for(;s.length>0;){const a=s.match(/^(.*?)([+-]?\d+\.?\d*)\s*(SG|strokes?(?:\s+per\s+round)?)/i);if(a&&a[1]!==void 0){a[1]&&r.push(d(a[1]));const l=parseFloat(a[2])>=0;r.push(e.jsxs("span",{className:z("font-semibold",l?"text-emerald-600 dark:text-emerald-400":"text-red-600 dark:text-red-400"),children:[a[2]," ",a[3]]},c++)),s=s.slice(a[0].length);continue}const o=s.match(/^(.*?)\*\*(.+?)\*\*(.*)/s);if(o){o[1]&&r.push(d(o[1])),r.push(e.jsx("strong",{className:"font-semibold text-foreground",children:o[2]},c++)),s=o[3];continue}const n=s.match(/^(.*?)\*(.+?)\*(.*)/s);if(n){n[1]&&r.push(n[1]),r.push(e.jsx("em",{className:"italic",children:n[2]},c++)),s=n[3];continue}const t=s.match(/^(.*?)(\d{1,3}%)(.*)/s);if(t){t[1]&&r.push(t[1]),r.push(e.jsx("span",{className:"font-semibold text-violet-600 dark:text-violet-400",children:t[2]},c++)),s=t[3];continue}r.push(s);break}return r.length===1?r[0]:e.jsx(e.Fragment,{children:r})};function ae(){const{noteId:m}=D(),r=A(),{userId:s,sessionReady:c}=C(),a=s??void 0,[o,n]=f.useState(!1),t=M();f.useEffect(()=>{c&&!s&&r("/auth")},[c,s,r]);const{data:i,isLoading:l,error:x}=I(m,a),u=f.useMemo(()=>i!=null&&i.content?G(i.content):null,[i==null?void 0:i.content]),p=async()=>{!i||!a||(t.mutate({noteId:i.id,playerId:a},{onSuccess:()=>{r("/activity?tab=diary")}}),n(!1))};return l||!a?e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity"},{label:"Diary",href:"/activity?tab=diary"},{label:"Loading..."}]}),e.jsx(j,{className:"h-8 w-48"}),e.jsx(j,{className:"h-48 w-full"})]}):x||!i?e.jsxs("div",{className:"space-y-4",children:[e.jsx(v,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity"},{label:"Diary",href:"/activity?tab=diary"},{label:"Not Found"}]}),e.jsx(y,{children:e.jsxs(g,{className:"py-8 text-center",children:[e.jsx(S,{className:"h-8 w-8 mx-auto text-destructive mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"Note not found"}),e.jsx(N,{variant:"outline",className:"mt-4",onClick:()=>r("/activity?tab=diary"),children:"Back to Diary"})]})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(v,{items:[{label:"Home",href:"/dashboard"},{label:"Activity",href:"/activity"},{label:"Diary",href:"/activity?tab=diary"},{label:b(new Date(i.saved_at),"MMM d, yyyy")}]}),e.jsx(V,{variant:"inline",contextType:"saved_coach_note",contextKey:`saved_note_${i.id}`,pageTitle:`Saved coach note â ${b(new Date(i.saved_at),"MMM d, yyyy")}`,viewerRole:"player",ctaLabel:"Explore this note",description:"Ask the Assistant to help you turn this note into action.",contextData:{noteId:i.id,savedAt:i.saved_at},keyInsightsScope:a?{scope:"aggregate",userId:a}:void 0}),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(k,{className:"h-6 w-6 text-violet-600 dar
3k:text-violet-400"}),"Saved Coach Note"]}),e.jsx("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(T,{className:"h-4 w-4"}),b(new Date(i.saved_at),"MMMM d, yyyy ⢠h:mm a")]})})]}),e.jsx(N,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>n(!0),children:e.jsx(_,{className:"h-5 w-5"})})]}),e.jsxs(y,{children:[e.jsx($,{children:e.jsxs(E,{className:"text-base flex items-center gap-2",children:[e.jsx(k,{className:"h-4 w-4 text-violet-600 dark:text-violet-400"}),"Coach Insight"]})}),e.jsx(g,{children:e.jsx("div",{className:"space-y-0.5",children:u})})]}),e.jsx(H,{open:o,onOpenChange:n,children:e.jsxs(L,{children:[e.jsxs(R,{children:[e.jsx(B,{children:"Delete saved note?"}),e.jsx(F,{children:"This action cannot be undone. The note will be permanently removed from your diary."})]}),e.jsxs(K,{children:[e.jsx(P,{children:"Cancel"}),e.jsx(U,{onClick:p,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})})]})}export{ae 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.