1import{j as e,m as R}from"./framer-CaZKyxF5.js";import{r as i}from"./react-core-I1an5Yvj.js";import{L as b}from"./router-hu0_X6IN.js";import{s as M,B as y,c as q,S as f}from"./index-CgQCMZLE.js";import{u as H}from"./useAuth-BQd42a4W.js";import{N as z}from"./Navigation-DEd5xZwB.js";import{C as _,c as k,a as B,b as D}from"./card-C-2cYgJJ.js";import{B as w}from"./badge-QiKVKfib.js";import{l as $}from"./localHistory-CqsEthJw.js";import{a as I,p as T}from"./analysisUtils-DQj38vNR.js";import{o as L,c as W,W as F,e as Q,C as O,q as Y}from"./lucide-DPOR83NI.js";import"./supabase-LX2YIkpS.js";import"./query-C2oTuvQ4.js";import"./useCredits-B9xejI4m.js";import"./index-CCpchn4D.js";import"./Combination-DWOYKpRr.js";import"./productFacts-D2ONJNuD.js";const K=i.memo(function({eyebrow:t="Your first quest",title:n,subtitle:r,steps:o,action:p,footnote:h}){return e.jsxs(R.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.5,ease:[.22,1,.36,1]},className:"mx-auto w-full max-w-2xl rounded-3xl border border-slate-200 bg-white/80 backdrop-blur p-8 sm:p-10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(L,{className:"h-3.5 w-3.5 text-blue-600","aria-hidden":!0}),e.jsx("span",{className:"font-mono text-[11px] font-semibold tracking-[0.18em] text-blue-600 uppercase",children:t})]}),e.jsx("h2",{className:"font-serif text-[26px] sm:text-3xl lg:text-[34px] leading-[1.15] text-slate-900 mb-3",children:n}),r?e.jsx("p",{className:"text-slate-500 text-[15px] leading-[1.65] mb-8 max-w-lg",children:r}):null,e.jsx("ol",{className:"space-y-3 mb-8",children:o.map((d,m)=>e.jsxs(R.li,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},transition:{delay:.15+m*.08,duration:.4},className:"flex items-center gap-3 rounded-xl border border-slate-100 bg-slate-50/60 px-4 py-3",children:[e.jsx("span",{className:`flex h-6 w-6 items-center justify-center rounded-full text-[11px] font-mono font-semibold ${d.done?"bg-blue-600 text-white":"bg-white border border-slate-200 text-slate-500"}`,"aria-hidden":!0,children:d.done?e.jsx(W,{className:"h-3.5 w-3.5"}):m+1}),e.jsx("span",{className:"flex-1 text-[14px] text-slate-700",children:d.label}),d.reward?e.jsx("span",{className:"font-mono text-[10px] font-semibold uppercase tracking-tight text-blue-600 bg-blue-50 px-2 py-1 rounded-md",children:d.reward}):null]},d.label))}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3",children:[p,h?e.
1jsx("span",{className:"text-[12px] text-slate-400 font-serif italic",children:h}):null]})]})}),v=a=>Array.isArray(a)?a.filter(t=>typeof t=="string"):[],V=a=>new Date(a).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),J=a=>{const t=Date.parse(a);return Number.isNaN(t)?0:Math.floor(t/6e4)},U=a=>{const t=a.original_post.trim(),n=a.category?.trim()??"",r=a.style_tone?.trim()??"";return`${t}|${n}|${r}|${J(a.created_at)}`},S=a=>[...a].sort((t,n)=>{const r=Date.parse(n.created_at),o=Date.parse(t.created_at);return Number.isNaN(r)&&Number.isNaN(o)?0:Number.isNaN(r)?1:Number.isNaN(o)?-1:r-o}),X=(a,t)=>{const n=new Map,r=o=>{n.set(U(o),o)};return t.forEach(r),a.forEach(r),S(Array.from(n.values()))},Z=({isGuest:a})=>e.jsx(K,{eyebrow:a?"Start local":"Build your library",title:a?"No enhancements saved on this device yet.":"Your library is empty - let's fix that.",subtitle:a?"Enhance one post to start a local history. Sign in and everything syncs across devices forever.":"Every post you enhance lands here with its virality score, risks, and quick wins - a proper archive of your voice.",steps:a?[{label:"Enhance your first post (no signup needed)",reward:"Free"},{label:"Sign in to sync your library across devices",reward:"+5 posts"},{label:"Watch your virality curve rise week over week"}]:[{label:"Paste or write a rough post",reward:"+1 streak"},{label:"Pick a tone - professional, punchy, story-first"},{label:"We save the diagnostics so you can re-run anytime",reward:"Auto-sync"}],action:e.jsx(b,{to:"/enhance",children:e.jsx(y,{className:"rounded-lg bg-blue-600 px-5 font-semibold shadow-sm hover:bg-blue-700",children:"Enhance your first post â"})}),footnote:a?"Sign in later - your local history won't be lost.":void 0}),G=()=>e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:Array.from({length:4}).map((a,t)=>e.jsxs(_,{className:"border-0 bg-white/80 shadow-lg",children:[e.jsxs(B,{className:"space-y-3",children:[e.jsx(f,{className:"h-4 w-24"}),e.jsx(f,{className:"h-5 w-32"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsx(f,{className:"h-3 w-full"}),e.jsx(f,{className:"h-3 w-4/5"}),e.jsx(f,{className:"h-3 w-2/3"})]})]},t))}),ge=()=>{const{user:a}=H(),[t,n]=i.useState([]),[r,o]=i.useState(!0),[p,h]=i.useState(null),d=i.useRef(!0),m=i.useCallback(s=>{d.current&&s()},[]),C=i.useCallback(s=>({id:s.id,original_post:s.original_post,enhanced_platforms:s.enhanced_platforms,category:s.category,style_tone:s.style_tone,virality_score:s.virality_score,insights:s.insights??[],view_reasons:s.view_reasons??[],quick_wins:s.quick_wins??[],created_at:s.created_at}),[]),N=i.useCallback(async()=>{m(()=>{o(!0),h(null)});const l=$(a?.id).map(C);if(!a){m(()=>{n(S(l)),o(!1)});return}try{const{data:x,error:g}=await M.from("post_enhancements").select("id, original_post, enhanced_platforms, category, style_tone, virality_score, insights, view_reasons, quick_wins, created_at").eq("user_id",a.id).order("created_at",{ascending:!1}).limit(50);if(g)throw g;const u=(x??[]).map(c=>({id:c.id,original_post:c.original_post,enhanced_platforms:c.enhanced_platforms??{},category:c.category,style_tone:c.style_tone,virality_score:c.virality_score,insights:v(c.insights),view_reasons:v(c.view_reasons),quick_wins:v(c.quick_wins),created_at:c.created_at})),A=X(u,l);m(()=>{n(A),h(null)})}catch(x){console.error("Post history query failed",x),m(()=>{l.length?(n(S(l)),h(null)):(n([]),h("Failed to load enhancement history. Please try again."))})}finally{m(()=>{o(!1)})}},[a,C,m]);i.useEffect(()=>{N()},[N]),i.useEffect(()=>()=>{d.current=!1},[]);const j=!a,P=j?"Review enhancements saved on this device. Sign in to sync them securely across sessions.":"Track every AI upgrade you've generated and the tailored insights we delivered.",E=i.useMemo(()=>t.map(s=>{const l=typeof s.virality_score=="number"?Math.round(s.virality_score):0,x=T(l||60),g=Object.entries(s.enhanced_platforms||{}).filter(([,u])=>!!u).map(([u])=>I(u));return{...s,normalizedScore:l,palette:x,platformBadges:g}}),[t]);return e.jsxs("div",{className:"min-h-screen flex flex-col bg-gradient-to-b from-white via-sky-50 to-white",children:[e.jsx(z,{}),e.jsx("main",{className:"flex-grow",role:"main","aria-labelledby":"history-title",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-8 px-4 py-12 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex flex-col gap-6 rounded-3xl border border-blue-100/80 bg-white/90 p-6 shadow-xl sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs(w,{className:"w-fit gap-1 bg-blue-600/10 text-blue-700",children:[e.jsx(F,{className:"h-3.5 w-3.5","aria-hidden":"true"})," Post enhancer"]}
1),e.jsxs("div",{children:[e.jsx("h1",{id:"history-title",className:"text-3xl font-bold tracking-tight text-slate-900 sm:text-4xl",children:"Post enhancement history"}),e.jsx("p",{className:"max-w-2xl text-sm text-slate-500 sm:text-base",children:P})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[j&&e.jsx(b,{to:"/auth",children:e.jsx(y,{variant:"outline",className:"rounded-full border-blue-600/40 text-blue-700 hover:bg-blue-50",children:"Sign in to sync"})}),e.jsxs(y,{variant:"secondary",onClick:N,disabled:r,className:"rounded-full border border-slate-200 bg-white text-slate-700 hover:bg-slate-100",children:[r?e.jsx(Q,{className:"mr-2 h-4 w-4 animate-spin"}):null,r?"Refreshing":"Refresh"]}),e.jsx(b,{to:"/enhance",children:e.jsx(y,{className:"rounded-full bg-blue-600 px-6 font-semibold shadow-lg hover:bg-blue-700",children:"New enhancement"})})]})]}),r&&e.jsx(G,{}),!r&&p&&e.jsx(_,{className:"border border-rose-200 bg-rose-50/80",children:e.jsxs(k,{className:"flex items-center gap-3 py-6 text-sm text-rose-600",children:[e.jsx(O,{className:"h-5 w-5"}),p]})}),!r&&!p&&t.length===0&&e.jsx(Z,{isGuest:j}),!r&&!p&&E.length>0&&e.jsx("div",{className:"grid gap-6 lg:grid-cols-2",children:E.map(s=>e.jsxs(_,{className:"border-0 bg-white/90 shadow-2xl",children:[e.jsxs(B,{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(w,{className:"rounded-full bg-blue-600/10 text-blue-700",children:s.category||"Category"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx(Y,{className:"h-3.5 w-3.5"}),V(s.created_at)]})]}),e.jsx(D,{className:"text-xl font-semibold text-slate-900",children:s.style_tone||"Custom tone"}),s.platformBadges.length?e.jsx("div",{className:"flex flex-wrap gap-2",children:s.platformBadges.map(l=>e.jsx(w,{variant:"outline",className:"rounded-full border-blue-200 text-xs text-blue-700",children:l},l))}):null]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsx("p",{className:"text-sm font-medium text-slate-500",children:"Virality potential"}),e.jsx("span",{className:q("text-3xl font-bold",s.palette.text),children:s.normalizedScore||"--"})]}),e.jsx("div",{className:"h-2 w-full overflow-hidden rounded-full bg-slate-100",children:e.jsx("div",{className:q("h-full rounded-full",s.palette.progress),style:{width:`${Math.min(Math.max(s.normalizedScore,0),100)}%`}})})]})]}),e.jsxs(k,{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.2em] text-slate-500",children:"Original post"}),e.jsx("p",{className:"rounded-2xl border border-dashed border-slate-200 bg-slate-50/70 p-4 text-sm leading-relaxed text-slate-700 whitespace-pre-wrap",children:s.original_post})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[s.view_reasons?.length?e.jsxs("div",{className:"space-y-3 rounded-2xl border border-amber-100 bg-amber-50/60 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.25em] text-amber-600",children:"Risks spotted"}),e.jsx("ul",{className:"space-y-2 text-sm text-amber-700",children:s.view_reasons.slice(0,3).map((l,x)=>e.jsxs("li",{children:["⢠",l]},x))})]}):null,s.quick_wins?.length?e.jsxs("div",{className:"space-y-3 rounded-2xl border border-emerald-100 bg-emerald-50/60 p-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.25em] text-emerald-600",children:"Quick wins"}),e.jsx("ul",{className:"space-y-2 text-sm text-emerald-700",children:s.quick_wins.slice(0,3).map((l,x)=>e.jsxs("li",{children:["⢠",l]},x))})]}):null]}),e.jsxs(b,{to:"/enhance",state:{prefillPost:s.original_post,prefillCategory:s.category,prefillTone:s.style_tone},className:"inline-flex items-center gap-2 text-sm font-semibold text-blue-600 hover:text-blue-700",children:[e.jsx(L,{className:"h-4 w-4"})," Re-enhance this post"]})]})]},s.id))})]})})]})};export{ge 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.