1import{_ as Te}from"./pdf-u_OiRbVB.js";import{i as J,a as A,j as e,l as $,r as y,s as p,ao as he,X as Ae,P as oe,n as pe,v as Pe,V as Me,W as ee,ac as fe,a2 as V,B as Z,t as Le,ap as qe,aT as ze,e as z,a0 as $e,E as Re,o as Oe,a5 as ye,a9 as be,bT as _e,a1 as Be,c as se,bU as He}from"./index-B5dEHq60.js";import{D as le}from"./DashboardLayout-D-nb-1ga.js";import{C as We}from"./coins-DMitHQTg.js";import{D as Ue}from"./download-Chr56nXu.js";import{S as Ie}from"./share-2-D521axUV.js";import{T as Ge}from"./trending-down-CRp4wYhM.js";import{T as ke}from"./target-Dq1sT9Sp.js";import{L as Y}from"./lock-whfmVE_Z.js";import{T as ae}from"./trophy-hEZowlON.js";import{C as ve}from"./clock-BSJdbc4i.js";import{c as je,d as we,e as Ne,f as Se}from"./dialog-CBP0E7sd.js";import{P as Ke,a as Ve,b as Ye}from"./popover-BeqUoNwZ.js";import{E as Ze}from"./ellipsis-DCoCvh7Q.js";import{C as Je}from"./Combination-D5ZSvGLO.js";import{S as Xe}from"./send-DakV1okm.js";import{R as Qe}from"./rocket-CQBt_iy7.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 et=J("Bookmark",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]]);/** 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 tt=J("Flag",[["path",{d:"M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z",key:"i9b6wo"}],["line",{x1:"4",x2:"4",y1:"22",y2:"15",key:"1cm3nv"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const X=J("Flame",[["path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z",key:"96xj49"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const Ce=J("Mountain",[["path",{d:"m8 3 4 8 5-5 5 15H2L8 3z",key:"otkl63"}]]),st=({creditsBalance:t,currentStreak:s=0,percentile:r,onShare:c,onSaveImage:n})=>{const{t:l}=A("community"),d=u=>{var o;(o=document.getElementById(u))==null||o.scrollIntoView({behavior:"smooth",block:"start"})},m=r!=null?l("topBar.rank",{pct:Math.max(1,Math.round(100-r))}):"â";return e.jsxs("header",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-6 pb-5 border-b border-gray-200/80 dark:border-neutral-800",children:[e.jsxs("div",{className:"flex items-baseline gap-2.5 flex-wrap",children:[e.jsx("h1",{className:"text-[18px] font-semibold tracking-[-0.02em] text-gray-900 dark:text-gray-100",children:l("topBar.title")}),e.jsx("span",{className:"text-[13px] text-gray-500 dark:text-gray-400",children:l("topBar.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>d("rewards-section"),className:"inline-flex items-center gap-1.5 rounded-full bg-gray-100 dark:bg-neutral-800 px-3 py-1.5 transition-colors hover:bg-gray-200 dark:hover:bg-neutral-700",children:[e.jsx(We,{className:"w-3.5 h-3.5 text-amber-500"}),e.jsx("span",{className:"text-[13px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:t.toLocaleString("de-DE")}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:l("topBar.credits")})]}),e.jsxs("button",{onClick:()=>d("streak-section"),className:"inline-flex items-center gap-1.5 rounded-full bg-gray-100 dark:bg-neutral-800 px-3 py-1.5 transition-colors hover:bg-gray-200 dark:hover:bg-neutral-700",children:[e.jsx(X,{className:"w-3.5 h-3.5 text-orange-500"}),e.jsx("span",{className:"text-[13px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:s}),e.jsx("span",{className:"text-[11px] text-gray-500 dark:text-gray-400",children:l("topBar.days")})]}),e.jsxs("button",{onClick:()=>d("mountain-section"),className:"hidden md:inline-flex items-center gap-1.5 rounded-full bg-gray-100 dark:bg-neutral-800 px-3 py-1.5 transition-colors hover:bg-gray-200 dark:hover:bg-neutral-700",children:[e.jsx(Ce,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:"text-[13px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:m})]}),n&&e.jsxs("button",{onClick:n,className:"inline-flex items-center gap-1.5 rounded-full bg-gray-100 dark:bg-neutral-800 px-3.5 py-1.5 text-[12px] font-medium text-gray-700 dark:text-gray-300 transition-colors hover:bg-gray-200 dark:hover:bg-neutral-700",children:[e.jsx(Ue,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:l("topBar.image")})]}),c&&e.jsxs("button",{onClick:c,className:"inline-flex items-center gap-1.5 rounded-full bg-gray-900 dark:bg-gray-100 px-3.5 py-1.5 text-[12px] font-medium text-white dark:text-gray-900 transition-all hover:bg-gray-800 dark:hover:bg-white hover:-translate-y-[0.5px]",children:[e.jsx(Ie,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:l("topBar.share")})]})]})]})},ie=14,ce=t=>`${t.getFullYear()}
21-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`,at=()=>{const{t}=A("community"),{user:s}=$(),[r,c]=y.useState({current_streak:0,best_streak:0,segments:Array(ie).fill("empty")});y.useEffect(()=>{s&&n()},[s]);const n=async()=>{if(!s)return;const{data:l}=await p.from("activity_logs").select("created_at").eq("user_id",s.id).order("created_at",{ascending:!1}).limit(500),d=new Set;(l||[]).forEach(x=>{d.add(ce(new Date(x.created_at)))});const m=new Date;m.setHours(0,0,0,0);const u=[];for(let x=ie-1;x>=0;x--){const i=new Date(m);i.setDate(m.getDate()-x),u.push(d.has(ce(i))?"full":"empty")}const o=Array.from(d).map(x=>{const[i,g,f]=x.split("-").map(Number);return new Date(i,g-1,f)}).sort((x,i)=>i.getTime()-x.getTime());let h=0,a=0;if(o.length>0){const x=o[0],i=new Date(m);if(i.setDate(m.getDate()-1),x.getTime()===m.getTime()||x.getTime()===i.getTime()){let f=x;for(const v of o)if(v.getTime()===f.getTime())h++,f=new Date(f),f.setDate(f.getDate()-1);else if(v.getTime()<f.getTime())break}let g=1;a=1;for(let f=1;f<o.length;f++){const v=o[f-1].getTime()-o[f].getTime();Math.abs(v-864e5)<36e5?(g++,g>a&&(a=g)):g=1}a=Math.max(a,h)}c({current_streak:h,best_streak:a,segments:u})};return e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-gradient-to-br from-amber-50/70 to-white dark:from-amber-950/20 dark:to-neutral-900 p-5 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-amber-500 flex items-center justify-center",children:e.jsx(X,{className:"w-4 h-4 text-white"})}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100",children:t("streak.title")}),r.current_streak>0&&e.jsx("span",{className:"ml-auto inline-flex items-center text-[11px] font-medium px-2 py-0.5 rounded-full bg-amber-100 dark:bg-amber-900/40 text-amber-700",children:t("streak.active")})]}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-[44px] leading-none font-semibold tabular-nums tracking-[-0.03em] text-gray-900 dark:text-gray-100",children:r.current_streak}),e.jsx("span",{className:"text-[13px] text-gray-500 dark:text-gray-400",children:t("streak.days")})]}),e.jsx("div",{className:"flex gap-1 h-1.5",children:r.segments.map((l,d)=>e.jsx("div",{className:"flex-1 rounded-sm",style:{background:l==="full"?"#f59e0b":l==="partial"?"#fcd34d":"#f0f0f2"}},d))}),e.jsxs("p",{className:"text-[13px] text-gray-600 dark:text-gray-300 leading-snug",children:[r.current_streak>0?t("streak.keepGoing"):t("streak.start"),r.best_streak>0&&e.jsxs(e.Fragment,{children:[" ",t("streak.bestLabel")," ",e.jsx("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:t("streak.bestDays",{count:r.best_streak})})]})]})]})},de=[{key:"viralScore",tKey:"viral",color:"#0a0a0a"},{key:"hookScore",tKey:"hook",color:"#7c3aed"},{key:"pacingScore",tKey:"pacing",color:"#06b6d4"}],rt=(t,s)=>{const r=t.filter(c=>c[s]!==null).map(c=>c[s]);return r.length===0?null:r.reduce((c,n)=>c+n,0)/r.length},nt=(t,s)=>{const r=t.filter(u=>u[s]!==null);if(r.length<2)return null;const c=Math.floor(r.length/2),n=r.slice(0,c).map(u=>u[s]),l=r.slice(c).map(u=>u[s]),d=n.reduce((u,o)=>u+o,0)/n.length,m=l.reduce((u,o)=>u+o,0)/l.length;return d===0?null:(m-d)/d*100},ot=({values:t,color:s})=>{if(t.length<2)return null;const r=380,c=130,n=10,l=Math.min(...t),m=Math.max(...t)-l||1,u=(r-20)/(t.length-1),o=t.map((i,g)=>({x:10+g*u,y:n+(c-n*2)-(i-l)/m*(c-n*2)})),h=`M${o[0].x},${o[0].y}`+o.slice(1).map(i=>` L${i.x},${i.y}`).join(""),a=`${h} L${o[o.length-1].x},${c} L${o[0].x},${c} Z`,x=o[o.length-1];return e.jsxs("svg",{viewBox:`0 0 ${r} ${c}`,className:"w-full",style:{height:140},preserveAspectRatio:"none",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`fill-${s.slice(1)}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:s,stopOpacity:"0.1"}),e.jsx("stop",{offset:"100%",stopColor:s,stopOpacity:"0"})]})}),e.jsx("path",{d:a,fill:`url(#fill-${s.slice(1)})`}),e.jsx("path",{d:h,fill:"none",stroke:s,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),o.slice(0,-1).map((i,g)=>e.jsx("circle",{cx:i.x,cy:i.y,r:"2.5",fill:"white",stroke:s,strokeWidth:"1.5"},g)),e.jsx("circle",{cx:x.x,cy:x.y,r:"4",fill:s})]})},lt=()=>{const{user:t}=$(),{t:s}=A("community"),[r,c]=y.useState([]),[n,l]=y.useState(!0),[d,m]=y.useState("viralScore");y.useEffect(()=>{t&&u()},[t]);const u=async()=>
21{if(!t)return;l(!0);const i=new Date;i.setDate(i.getDate()-90);const[{data:g},{data:f}]=await Promise.all([p.from("tiktok_accounts").select("id").eq("user_id",t.id),p.from("instagram_accounts").select("id").eq("user_id",t.id)]),v=(g||[]).map(N=>N.id),F=(f||[]).map(N=>N.id),[_,C,E]=await Promise.all([v.length>0?p.from("videos").select("deep_analysis_data, analysis_completed_at").in("tiktok_account_id",v).eq("is_deep_analyzed",!0).gte("analysis_completed_at",i.toISOString()).order("analysis_completed_at",{ascending:!0}):Promise.resolve({data:[]}),p.from("uploaded_videos").select("deep_analysis_data, analysis_completed_at").eq("user_id",t.id).eq("is_deep_analyzed",!0).gte("analysis_completed_at",i.toISOString()).order("analysis_completed_at",{ascending:!0}),F.length>0?p.from("instagram_videos").select("deep_analysis_data, analysis_completed_at").in("instagram_account_id",F).eq("is_deep_analyzed",!0).gte("analysis_completed_at",i.toISOString()).order("analysis_completed_at",{ascending:!0}):Promise.resolve({data:[]})]),k=[..._.data||[],...C.data||[],...E.data||[]].sort((N,S)=>new Date(N.analysis_completed_at).getTime()-new Date(S.analysis_completed_at).getTime()).filter(N=>N.deep_analysis_data).map(N=>{var b,L,D,w,B;const S=N.deep_analysis_data,P=(S==null?void 0:S.categories)||{},R=O=>O!=null?Math.min(10,Math.max(0,O)):null;return{date:N.analysis_completed_at||"",hookScore:R(((b=S==null?void 0:S.hook_analysis)==null?void 0:b.overall_hook_score)??((L=P==null?void 0:P.hook)==null?void 0:L.score)??null),viralScore:R(((D=S==null?void 0:S.viral_score_breakdown)==null?void 0:D.final_viral_score)??(S==null?void 0:S.viralScore)??null),pacingScore:R(((w=S==null?void 0:S.pacing_dynamics)==null?void 0:w.pacing_score)??((B=P==null?void 0:P.pacing)==null?void 0:B.score)??null)}});c(k),l(!1)},o=r.filter(i=>i[d]!==null).map(i=>i[d]),h=rt(r,d),a=nt(r,d),x=de.find(i=>i.key===d).color;return e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900 p-5 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:s("scoreTrends.title")}),e.jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-0.5",children:s("scoreTrends.last90days")})]}),h!=null&&e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-[28px] font-semibold tabular-nums tracking-[-0.03em] text-gray-900 dark:text-gray-100 leading-none",children:h.toFixed(1)}),a!=null&&e.jsxs("span",{className:`inline-flex items-center gap-0.5 text-[11px] font-semibold px-1.5 py-0.5 rounded-full ${a>=0?"bg-emerald-50 dark:bg-emerald-950/40 text-emerald-700":"bg-rose-50 dark:bg-rose-950/40 text-rose-700"}`,children:[a>=0?e.jsx(he,{className:"w-2.5 h-2.5"}):e.jsx(Ge,{className:"w-2.5 h-2.5"}),a>=0?"+":"",Math.round(a),"%"]})]})]}),e.jsx("div",{className:"flex gap-1.5",children:de.map(i=>e.jsx("button",{onClick:()=>m(i.key),className:`text-[11px] font-medium px-2.5 py-1 rounded-full transition-colors ${d===i.key?"bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900":"bg-gray-100 dark:bg-neutral-800 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-neutral-700"}`,children:s(`scoreTrends.${i.tKey}`)},i.key))}),n?e.jsx("div",{className:"h-[140px] flex items-center justify-center text-[12px] text-gray-400 dark:text-gray-500",children:s("scoreTrends.loading")}):o.length<2?e.jsx("div",{className:"h-[140px] flex items-center justify-center text-center text-[12px] text-gray-400 dark:text-gray-500",children:s("scoreTrends.needMore")}):e.jsx(ot,{values:o,color:x})]})},G=({isOpen:t,onClose:s,title:r,children:c,maxWidth:n="lg"})=>{const{t:l}=A();if(y.useEffect(()=>(t?document.body.style.overflow="hidden":document.body.style.overflow="unset",()=>{document.body.style.overflow="unset"}),[t]),y.useEffect(()=>{const m=u=>{u.key==="Escape"&&s()};return t&&document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[t,s]),!t)return null;const d={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl",xl:"max-w-4xl","2xl":"max-w-6xl"};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-start justify-center px-4 sm:px-6 py-24 overflow-y-auto",children:[e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm",onClick:s}),e.jsxs("div",{className:`relative bg-white rounded-2xl shadow-2xl w-full ${d[n]} flex flex-col`,children:[r&&e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[e.jsx("h2",{className:"text-xl sm:text-2xl font-bold text-gray-900",children:r}),e.jsx("button",{onClick:s,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors","aria-label":l("common:states.modalClose"),children:e.jsx(Ae,{className:"w-5 h-5 text-gray-600"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:c})]})]})},it=[{target_metric:"hook_score_8",target_value:5,icon:Pe},{target_metric:"video_views_100k",target_value:1,icon:he},{target_metric:"streak_30",target_value:30,icon:X},{target_metric:"avg_viral_7",target_value:7,icon:Me},{target_metric:"analysis_count",target_value:10,icon:ee},{target_metric:"weekly_posts",target_value:5,icon:ee}],ct=async(t,s)=>{var h;if(s.length===0)return s;const[{data:r},{data:c}]=await Promise.all([p.from("tiktok_accounts").select("id").eq("user_id",t),p.from("instagram_accounts").select("id").eq("user_id",t)]),n=(r||[]).map(a=>a.id),l=(c||[]).map(a=>a.id),d=new Set(s.map(a=>a.target_metric)),m={},u=[];
21if(d.has("streak_30")&&u.push(Promise.resolve(p.from("user_streaks").select("current_streak").eq("user_id",t).maybeSingle()).then(({data:a})=>{m.streak_30=(a==null?void 0:a.current_streak)||0})),d.has("analysis_count")){const a=n.length>0?Promise.resolve(p.from("videos").select("*",{count:"exact",head:!0}).in("tiktok_account_id",n).eq("is_deep_analyzed",!0)):Promise.resolve({count:0}),x=Promise.resolve(p.from("uploaded_videos").select("*",{count:"exact",head:!0}).eq("user_id",t).eq("is_deep_analyzed",!0)),i=l.length>0?Promise.resolve(p.from("instagram_videos").select("*",{count:"exact",head:!0}).in("instagram_account_id",l).eq("is_deep_analyzed",!0)):Promise.resolve({count:0});u.push(Promise.all([a,x,i]).then(([g,f,v])=>{m.analysis_count=(g.count||0)+(f.count||0)+(v.count||0)}))}if(d.has("hook_score_8")){const a=n.length>0?Promise.resolve(p.from("videos").select("*",{count:"exact",head:!0}).in("tiktok_account_id",n).eq("is_deep_analyzed",!0).gte("viral_score",8)):Promise.resolve({count:0}),x=Promise.resolve(p.from("uploaded_videos").select("deep_analysis_data").eq("user_id",t).eq("is_deep_analyzed",!0).not("deep_analysis_data","is",null)),i=l.length>0?Promise.resolve(p.from("instagram_videos").select("*",{count:"exact",head:!0}).in("instagram_account_id",l).eq("is_deep_analyzed",!0).gte("viral_score",8)):Promise.resolve({count:0});
21u.push(Promise.all([a,x,i]).then(([g,f,v])=>{const F=(f.data||[]).filter(_=>{var j;const C=_.deep_analysis_data;return(((j=C==null?void 0:C.viral_score_breakdown)==null?void 0:j.final_viral_score)??(C==null?void 0:C.viralScore)??0)>=8}).length;m.hook_score_8=(g.count||0)+F+(v.count||0)}))}if(d.has("video_views_100k")){const a=n.length>0?Promise.resolve(p.from("videos").select("*",{count:"exact",head:!0}).in("tiktok_account_id",n).gte("views",1e5)):Promise.resolve({count:0}),x=l.length>0?Promise.resolve(p.from("instagram_videos").select("*",{count:"exact",head:!0}).in("instagram_account_id",l).gte("view_count",1e5)):Promise.resolve({count:0});u.push(Promise.all([a,x]).then(([i,g])=>{m.video_views_100k=(i.count||0)+(g.count||0)}))}if(d.has("avg_viral_7")){const a=n.length>0?Promise.resolve(p.from("videos").select("viral_score").in("tiktok_account_id",n).eq("is_deep_analyzed",!0).not("viral_score","is",null)):Promise.resolve({data:[]}),x=Promise.resolve(p.from("uploaded_videos").select("deep_analysis_data").eq("user_id",t).eq("is_deep_analyzed",!0).not("deep_analysis_data","is",null)),i=l.length>0?Promise.resolve(p.from("instagram_videos").select("viral_score").in("instagram_account_id",l).eq("is_deep_analyzed",!0).not("viral_score","is",null)):Promise.resolve({data:[]});
21u.push(Promise.all([a,x,i]).then(([g,f,v])=>{const F=(g.data||[]).map(j=>j.viral_score).filter(Boolean),_=(f.data||[]).map(j=>{var N;const k=j.deep_analysis_data;return((N=k==null?void 0:k.viral_score_breakdown)==null?void 0:N.final_viral_score)??(k==null?void 0:k.viralScore)??null}).filter(Boolean),C=(v.data||[]).map(j=>j.viral_score).filter(Boolean),E=[...F,..._,...C];m.avg_viral_7=E.length>0?Math.round(E.reduce((j,k)=>j+k,0)/E.length*10)/10:0}))}if(d.has("weekly_posts")){const a=new Date;a.setDate(a.getDate()-7);const x=n.length>0?Promise.resolve(p.from("videos").select("*",{count:"exact",head:!0}).in("tiktok_account_id",n).gte("created_at",a.toISOString())):Promise.resolve({count:0}),i=l.length>0?Promise.resolve(p.from("instagram_videos").select("*",{count:"exact",head:!0}).in("instagram_account_id",l).gte("created_at",a.toISOString())):Promise.resolve({count:0});u.push(Promise.all([x,i]).then(([g,f])=>{m.weekly_posts=(g.count||0)+(f.count||0)}))}await Promise.all(u);const o=s.map(a=>({...a,current_value:m[a.target_metric]??a.current_value}));for(const a of o)a.current_value!==((h=s.find(x=>x.id===a.id))==null?void 0:h.current_value)&&p.from("user_goals").update({current_value:a.current_value}).eq("id",a.id).then(()=>{});return o},dt=()=>{const{t}=A("community"),{user:s}=$(),[r,c]=y.useState([]),[n,l]=y.useState(!1);y.useEffect(()=>{s&&d()},[s]);const d=async()=>{if(!s)return;const{data:o}=await p.from("user_goals").select("*").eq("user_id",s.id).eq("status","active").order("created_at",{ascending:!1}).limit(3);if(o){const h=await ct(s.id,o);c(h)}},m=async o=>{s&&(await p.from("user_goals").insert({user_id:s.id,title:t(`goals.templates.${o.target_metric}.title`),description:t(`goals.templates.${o.target_metric}.description`),target_metric:o.target_metric,target_value:o.target_value,current_value:0,status:"active"}),l(!1),d())},u=r.filter(o=>o.current_value>=o.target_value).length;return e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900 p-5 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gray-900 dark:bg-gray-100 flex items-center justify-center",children:e.jsx(ke,{className:"w-4 h-4 text-white dark:text-gray-900"})}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100",children:t("goals.title")}),e.jsxs("span",{className:"ml-auto text-[11px] text-gray-500 dark:text-gray-400 tabular-nums",children:[u," / ",Math.max(r.length,1)]})]}),r.length===0?e.jsxs("div",{className:"flex flex-col items-start gap-2 py-2",children:[e.jsx("p",{className:"text-[13px] text-gray-500 dark:text-gray-400",children:t("goals.empty")}),e.jsxs("button",{onClick:()=>l(!0),className:"inline-flex items-center gap-1 text-[12px] font-medium text-gray-900 dark:text-gray-100 hover:underline",children:[e.jsx(oe,{className:"w-3.5 h-3.5"})," ",t("goals.setGoal")]})]}):e.jsxs("div",{className:"flex flex-col gap-3",children:[r.map(o=>{const h=Math.min(100,Math.round(o.current_value/o.target_value*100)),a=h>=100;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-4 h-4 rounded-[5px] flex items-center justify-center transition-colors ${a?"bg-gray-900 dark:bg-gray-100 border-2 border-gray-900 dark:border-gray-100":"border-2 border-gray-300 dark:border-neutral-600 bg-white dark:bg-neutral-900"}`,children:a&&e.jsx(pe,{className:"w-2.5 h-2.5 text-white dark:text-gray-900",strokeWidth:3})}),e.jsx("span",{className:`text-[13px] flex-1 truncate ${a?"line-through text-gray-400 dark:text-gray-500":"text-gray-900 dark:text-gray-100"}`,title:o.title,children:o.title}),e.jsxs("span",{className:"text-[10px] text-gray-400 dark:text-gray-500 tabular-nums shrink-0",children:[o.current_value,"/",o.target_value]})]}),e.jsx("div",{className:"ml-[22px] h-[3px] rounded-full bg-gray-100 dark:bg-neutral-800 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${a?"bg-gray-900 dark:bg-gray-100":"bg-indigo-500"}`,style:{width:`${h}%`}})})]},o.id)}),r.length<3&&e.jsxs("button",{onClick:()=>l(!0),className:"inline-flex items-center gap-1 text-[11px] font-medium text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 self-start",children:[e.jsx(oe,{className:"w-3 h-3"})," ",t("goals.anotherGoal")]})]}),e.jsx(G,{isOpen:n,onClose:()=>l(!1),title:t("goals.modalTitle"),maxWidth:"md",children:e.jsx("div",{className:"space-y-2",children:it.map((o,h)=>{const a=o.icon;return e.jsxs("button",{onClick:()=>m(o),className:"w-full text-left p-4 rounded-xl bg-gray-50 dark:bg-neutral-800/50 hover:bg-gray-100 dark:hover:bg-neutral-800 transition-colors flex items-start gap-3",children:[e.jsx(a,{className:"w-4 h-4 mt-0.5 flex-shrink-0 text-gray-700 dark:text-gray-300"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-medium text-gray-900 dark:text-gray-100",children:t(`goals.templates.${o.target_metric}.title`)}),e.jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-0.5",children:t(`goals.templates.${o.target_metric}.description`)})]})]},h)})})})]})},K=["#16a34a","#0ea5e9","#f59e0b","#f97316","#7c3aed","#3b82f6","#ec4899","#ef4444"],mt=()=>{const{t}=A("community"),{user:s}=$(),[r,c]=y.useState([]),[n,l]=y.useState([]),[d,m]=y.useState(!1);y.useEffect(()=>{s&&u()},[s]);const u=async()=>
21{if(!s)return;const[{data:i},{data:g}]=await Promise.all([p.from("community_achievements").select("*").order("created_at"),p.from("user_achievements").select("achievement_id, unlocked_at").eq("user_id",s.id)]);i&&c(i),g&&l(g)},o=i=>n.some(g=>g.achievement_id===i),h=n.length,a=r.length,x=r.slice(0,12);return e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900 p-5 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-[15px] font-semibold text-gray-900 dark:text-gray-100",children:t("achievements.title")}),e.jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-0.5",children:t("achievements.unlockedOf",{unlocked:h,total:a})})]}),a>12&&e.jsxs("button",{onClick:()=>m(!0),className:"inline-flex items-center gap-0.5 text-[12px] font-medium text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100",children:[t("achievements.all")," ",e.jsx(fe,{className:"w-3 h-3"})]})]}),e.jsx("div",{className:"grid grid-cols-3 sm:grid-cols-6 gap-2",children:x.length===0?Array.from({length:12}).map((i,g)=>e.jsx("div",{className:"aspect-square rounded-xl bg-gray-50 dark:bg-neutral-800/50 border border-gray-200/60 dark:border-neutral-700/60 opacity-50 flex items-center justify-center",children:e.jsx(Y,{className:"w-3.5 h-3.5 text-gray-300 dark:text-gray-600"})},g)):x.map((i,g)=>{const f=o(i.id),v=K[g%K.length];return e.jsxs("button",{className:`group relative aspect-square rounded-xl border flex flex-col items-center justify-center p-1.5 transition-all ${f?"bg-white dark:bg-neutral-900 border-gray-200/80 dark:border-neutral-700 hover:-translate-y-0.5 hover:shadow-sm":"bg-gray-50 dark:bg-neutral-800/40 border-gray-200/40 dark:border-neutral-800 opacity-45"}`,title:`${i.title}${f?"":t("achievements.lockedSuffix")}`,children:[e.jsx("div",{className:"w-6 h-6 rounded-[7px] flex items-center justify-center text-white text-[14px] mb-1",style:{background:f?v:"#a1a1a6"},children:f?i.icon:e.jsx(Y,{className:"w-3 h-3"})}),e.jsx("span",{className:"text-[9px] font-medium leading-tight text-center text-gray-900 dark:text-gray-100 line-clamp-2 px-0.5",children:i.title})]},i.id)})}),e.jsx(G,{isOpen:d,onClose:()=>m(!1),title:t("achievements.modalTitle"),maxWidth:"lg",children:e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:r.map((i,g)=>{const f=o(i.id),v=K[g%K.length];return e.jsxs("div",{className:`p-3 rounded-xl border ${f?"bg-white dark:bg-neutral-900 border-gray-200/80 dark:border-neutral-700":"bg-gray-50 dark:bg-neutral-800/40 border-gray-200/40 dark:border-neutral-800 opacity-60"}`,children:[e.jsx("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center text-white text-[18px] mb-2",style:{background:f?v:"#a1a1a6"},children:f?i.icon:e.jsx(Y,{className:"w-4 h-4"})}),e.jsx("p",{className:"text-[12px] font-semibold text-gray-900 dark:text-gray-100",children:i.title}),e.jsx("p",{className:"text-[11px] text-gray-500 dark:text-gray-400 mt-1 leading-snug line-clamp-2",children:i.description}),e.jsxs("div",{className:"flex items-center justify-between mt-2 pt-2 border-t border-gray-100 dark:border-neutral-800",children:[e.jsx("span",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:f?t("achievements.unlocked"):i.rarity}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] text-gray-500 dark:text-gray-400",children:["+",i.credit_reward," ",e.jsx(V,{className:"w-2.5 h-2.5"})]})]})]},i.id)})})})]})},ut=["month","week","alltime"],me=({active:t,onClick:s,children:r})=>e.jsx("button",{onClick:s,className:`inline-flex items-center text-[11px] font-medium px-2.5 py-1 rounded-full transition-colors ${t?"bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900":"bg-gray-100 dark:bg-neutral-800 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-neutral-700"}`,children:r}),xt=({percentile:t,loading:s,period:r,onPeriodChange:c,nicheFilter:n,onNicheFilterToggle:l,niche:d,currentUserRank:m})=>{const{t:u}=A("community"),o=t===null,h=t??100,a=Math.max(1,Math.min(100,h));let x;a<=5?x=60:a<=20?x=60+(a-5)/15*40:a<=50?x=100+(a-20)/30*50:x=150+(a-50)/50*50;const i=260;return e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:ut.map(g=>e.jsx(me,{active:r===g,onClick:()=>
21c(g),children:u(`mountain.range.${g}`)},g))}),d&&e.jsx(me,{active:n,onClick:l,children:n?`· ${d}`:u("mountain.niche")})]}),s?e.jsx("div",{className:"h-[220px] flex items-center justify-center text-[13px] text-gray-500 dark:text-gray-400",children:u("mountain.calculating")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mt-3",children:[e.jsxs("svg",{viewBox:"0 0 420 240",className:"w-full",style:{height:220},xmlns:"http://www.w3.org/2000/svg",children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"mtnBg",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#a1a1a6",stopOpacity:"0.35"}),e.jsx("stop",{offset:"100%",stopColor:"#a1a1a6",stopOpacity:"0.15"})]}),e.jsxs("linearGradient",{id:"mtnFg",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#0a0a0a",stopOpacity:"0.85"}),e.jsx("stop",{offset:"100%",stopColor:"#0a0a0a",stopOpacity:"0.5"})]})]}),e.jsx("path",{d:"M 0 240 L 50 175 L 120 130 L 200 95 L 290 145 L 360 105 L 420 165 L 420 240 Z",fill:"url(#mtnBg)"}),e.jsx("path",{d:"M 0 240 L 40 210 L 110 150 L 180 90 L 240 50 L 310 110 L 380 175 L 420 200 L 420 240 Z",fill:"url(#mtnFg)"}),[{y:200,labelKey:"bottom50"},{y:150,labelKey:"top50"},{y:100,labelKey:"top20"},{y:60,labelKey:"top5"}].map(({y:g,labelKey:f})=>e.jsxs("g",{children:[e.jsx("line",{x1:20,y1:g,x2:400,y2:g,stroke:"#0a0a0a",strokeOpacity:"0.08",strokeDasharray:"3 4"}),e.jsx("text",{x:20,y:g-4,fontSize:8.5,fontWeight:500,fill:"#86868b",fontFamily:"Inter, sans-serif",children:u(`mountain.bands.${f}`)})]},g)),!o&&e.jsxs("g",{children:[e.jsx("circle",{cx:i,cy:x,r:11,fill:"#0a0a0a",fillOpacity:.18}),e.jsx("circle",{cx:i,cy:x,r:6,fill:"#0a0a0a"}),e.jsx("circle",{cx:i,cy:x,r:2.5,fill:"#ffffff"})]})]}),!o&&e.jsxs("div",{className:"absolute top-[80px] right-2 sm:right-6 bg-white dark:bg-neutral-900 border border-gray-200/80 dark:border-neutral-800 rounded-[10px] px-3 py-2 shadow-md",children:[e.jsx("div",{className:"text-[11px] text-gray-400 dark:text-gray-500",children:u("mountain.youAreIn")}),e.jsx("div",{className:"text-[22px] font-semibold tracking-[-0.02em] tabular-nums text-gray-900 dark:text-gray-100 leading-tight",children:u("mountain.topPct",{pct:Math.round(h)})}),m!=null&&e.jsx("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 tabular-nums",children:u("mountain.rank",{rank:m})})]})]}),e.jsx("p",{className:"mt-3 max-w-[420px] text-[13px] leading-[1.55] text-gray-600 dark:text-gray-300",children:o?e.jsx(e.Fragment,{children:u("mountain.newUser")}):e.jsxs(e.Fragment,{children:[u("mountain.activeAs")," ",e.jsxs("span",{className:"font-semibold text-gray-900 dark:text-gray-100",children:[Math.round(100-h),"%"]})," ",u("mountain.allCreators")," ",n&&d?u("mountain.inNiche",{niche:d}):""," â"," ",u(`mountain.period.${r}`),"."]})})]})]})},gt=60,ht=({achievementsCount:t,longestStreak:s,consistencyRate:r,timeInHookzy:c})=>{const{t:n}=A("community"),l=[{icon:ae,label:n("standing.achievements"),value:String(t),sub:n("standing.achievementsSub",{total:gt})},{icon:X,label:n("standing.longestStreak"),value:String(s),sub:n("standing.daysInRow")},{icon:ke,label:n("standing.consistency"),value:`${Math.round(r)}%`,sub:n("standing.last30days")},{icon:ve,label:n("standing.timeInHookzy"),value:`${Math.floor(c/60)}h`,sub:new Date().toLocaleDateString("de-DE",{month:"long",year:"numeric"})}];return e.jsx("div",{className:"grid grid-cols-2 gap-3",children:l.map((d,m)=>{const u=d.icon;return e.jsxs("div",{className:"rounded-xl bg-gray-50 dark:bg-neutral-800/50 p-3.5 flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(u,{className:"w-3.5 h-3.5 text-gray-500 dark:text-gray-400"}),e.jsx("span",{className:"text-[11px] font-medium text-gray-500 dark:text-gray-400",children:d.label})]}),e.jsx("div",{className:"text-[22px] font-semibold tabular-nums tracking-[-0.02em] text-gray-900 dark:text-gray-100 leading-tight",children:d.value}),e.jsx("div",{className:"text-[11px] text-gray-400 dark:text-gray-500 -mt-0.5",children:d.sub})]},m)})})},pt={1:"â ",2:"â¡",3:"â¢"}
21,ue=[["#f97316","#ec4899"],["#3b82f6","#06b6d4"],["#10b981","#0ea5e9"],["#7c3aed","#ec4899"],["#0ea5e9","#6366f1"],["#ec4899","#a855f7"],["#16a34a","#0ea5e9"],["#dc2626","#f59e0b"],["#0ea5e9","#10b981"],["#f59e0b","#dc2626"]],ft=t=>{let s=0;for(let r=0;r<t.length;r++)s=(s<<5)-s+t.charCodeAt(r)|0;return Math.abs(s)},yt=t=>ue[ft(t)%ue.length],bt=({entries:t,currentUserId:s,currentUserScore:r,currentUserRank:c})=>{const{t:n}=A("community"),[l,d]=y.useState("all");return t.length===0?e.jsx("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900 p-8 text-center text-[13px] text-gray-500 dark:text-gray-400",children:n("top10.empty")}):e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-white dark:bg-neutral-900 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 border-b border-gray-200/80 dark:border-neutral-800",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4 text-amber-500"}),e.jsx("h3",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100",children:n("top10.title")})]}),e.jsx("div",{className:"flex gap-1",children:["all","niche"].map(m=>e.jsx("button",{onClick:()=>d(m),className:`text-[11px] font-medium px-2.5 py-1 rounded-full transition-colors ${l===m?"bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900":"bg-gray-100 dark:bg-neutral-800 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-neutral-700"}`,children:n(m==="all"?"top10.all":"top10.myNiche")},m))})]}),e.jsxs("div",{children:[t.slice(0,10).map((m,u)=>{const o=u+1,h=m.user_id===s,[a,x]=yt(m.user_id),i=o<=3;return e.jsxs("div",{className:`flex items-center gap-3 px-5 py-3 border-b border-gray-200/60 dark:border-neutral-800/80 last:border-b-0 ${h?"bg-gray-50/60 dark:bg-neutral-800/30":""}`,children:[e.jsx("div",{className:"w-7 flex items-center justify-center shrink-0",children:i?e.jsx("span",{className:"text-[15px] font-bold text-amber-500",children:pt[o]}):e.jsx("span",{className:"text-[13px] font-bold text-gray-400 dark:text-gray-500 tabular-nums",children:o})}),e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-[11px] font-semibold text-white shrink-0",style:{background:`linear-gradient(135deg, ${a}, ${x})`},children:h?"D":m.user_id.slice(0,1).toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100 truncate",children:h?n("top10.you"):n("top10.creator",{rank:o})}),h&&e.jsx("span",{className:"inline-flex items-center text-[9px] font-semibold px-1.5 py-0.5 rounded-full bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900 uppercase tracking-wider",children:n("top10.youBadge")})]}),e.jsx("div",{className:"text-[11px] text-gray-500 dark:text-gray-400 tabular-nums mt-0.5",children:n("top10.achievements",{count:m.achievements_count})})]}),e.jsxs("div",{className:"text-right shrink-0 w-20",children:[e.jsx("div",{className:"text-[13px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:Math.round(m.score).toLocaleString("de-DE")}),e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:n("top10.score")})]})]},m.user_id)}),c&&c>10&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-center py-1 text-gray-300 dark:text-gray-600 text-[10px]",children:"···"}),e.jsxs("div",{className:"flex items-center gap-3 px-5 py-3 border-t border-gray-200/80 dark:border-neutral-800 bg-gray-50/60 dark:bg-neutral-800/30",children:[e.jsx("div",{className:"w-7 flex items-center justify-center shrink-0",children:e.jsxs("span",{className:"text-[13px] font-bold text-gray-700 dark:text-gray-300 tabular-nums",children:["#",c]})}),e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-[11px] font-semibold text-white shrink-0 bg-gradient-to-br from-violet-600 to-fuchsia-600",children:"D"}),e.jsx("div",{className:"flex-1",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100",children:n("top10.you")}),e.jsx("span",{className:"inline-flex items-center text-[9px] font-semibold px-1.5 py-0.5 rounded-full bg-gray-900 dark:bg-gray-100 text-white dark:text-gray-900 uppercase tracking-wider",children:n("top10.youBadge")})]})}),e.jsxs("div",{className:"text-right shrink-0 w-20",children:[e.jsx("div",{className:"text-[13px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:Math.round(r).toLocaleStr
21ing("de-DE")}),e.jsx("div",{className:"text-[10px] text-gray-400 dark:text-gray-500",children:n("top10.score")})]})]})]})]})]})},_t=["trending","following","niche","new"],kt=({activeFilter:t,onFilterChange:s})=>{const{t:r}=A("community");return e.jsx("div",{className:"flex gap-1.5 overflow-x-auto pb-1",children:_t.map(c=>e.jsx("button",{onClick:()=>s(c),className:"whitespace-nowrap transition-all",style:{padding:"5px 12px",borderRadius:999,fontSize:12,fontWeight:500,background:t===c?"#1D1D1F":"#F5F5F7",color:t===c?"#FFFFFF":"#6E6E73"},children:r(`feedFilter.${c}`)},c))})},vt=({onOpen:t,userName:s})=>{var m,u;const{userName:r,avatarUrl:c,user:n}=$(),{t:l}=A("community"),d=r||s||((m=n==null?void 0:n.email)==null?void 0:m.split("@")[0])||l("compose.defaultName");return e.jsxs("div",{className:"flex items-center gap-2.5 mb-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 text-xs font-semibold overflow-hidden",style:{background:c?void 0:"#F3E8FF",color:"#9333EA"},children:c?e.jsx("img",{src:c,className:"w-full h-full object-cover",alt:""}):(u=d[0])==null?void 0:u.toUpperCase()}),e.jsx("button",{onClick:t,className:"flex-1 text-left transition-colors hover:bg-[#EDEDF0]",style:{background:"#F5F5F7",borderRadius:999,padding:"8px 14px",fontSize:13,color:"#8E8E93"},children:l("compose.prompt",{name:d})})]})},jt=[{key:"discussion",icon:e.jsx(Le,{className:"w-4 h-4"})},{key:"tip",icon:e.jsx(qe,{className:"w-4 h-4"})},{key:"video_card",icon:e.jsx(ee,{className:"w-4 h-4"})},{key:"feedback_request",icon:e.jsx(ze,{className:"w-4 h-4"})},{key:"milestone",icon:e.jsx(ae,{className:"w-4 h-4"})}],wt=({open:t,onClose:s,onPostCreated:r})=>{const{user:c}=$(),{t:n}=A("community"),[l,d]=y.useState("discussion"),[m,u]=y.useState(""),[o,h]=y.useState(""),[a,x]=y.useState(!1),i=async()=>{if(!o.trim()||!c)return;x(!0);const{data:g}=await p.from("user_community_profiles").select("niche").eq("user_id",c.id).maybeSingle(),f={text:o.trim()};m.trim()&&(f.title=m.trim());const{error:v}=await p.from("community_posts").insert({author_id:c.id,type:l,content:f,niche:(g==null?void 0:g.niche)||null});v?z.error(n("composeModal.toast.error")):(z.success(n("composeModal.toast.published")),await p.from("credit_transactions").insert({user_id:c.id,amount:1,reason:"community_post"}),u(""),h(""),d("discussion"),s(),r()),x(!1)};return e.jsx(je,{open:t,onOpenChange:g=>!g&&s(),children:e.jsxs(we,{className:"max-w-lg",children:[e.jsx(Ne,{children:e.jsx(Se,{className:"text-base",children:n("composeModal.title")})}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:jt.map(g=>e.jsxs("button",{onClick:()=>d(g.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-colors border ${l===g.key?"bg-purple-50 dark:bg-purple-950/40 text-purple-700 border-purple-200 dark:border-purple-900":"bg-white dark:bg-neutral-900 text-gray-600 dark:text-gray-400 border-gray-200 dark:border-neutral-800 hover:bg-gray-50 dark:hover:bg-neutral-800/50"}`,children:[g.icon," ",n(`composeModal.types.${g.key}.label`)]},g.key))}),e.jsx("input",{value:m,onChange:g=>u(g.target.value),placeholder:n("composeModal.titlePlaceholder"),className:"w-full text-sm border border-gray-200 dark:border-neutral-800 rounded-lg px-3 py-2 focus:outline-none focus:border-purple-300 mt-2"}),e.jsx("textarea",{value:o,onChange:g=>h(g.target.value),placeholder:n("composeModal.textPlaceholder"),rows:5,className:"w-full text-sm border border-gray-200 dark:border-neutral-800 rounded-lg px-3 py-2 focus:outline-none focus:border-purple-300 resize-none"}),e.jsx(Z,{onClick:i,disabled:!o.trim()||a,className:"w-full bg-purple-600 hover:bg-purple-700",children:n(a?"composeModal.publishing":"composeModal.publish")})]})})},Nt=({open:t,onClose:s,postId:r,commentId:c})=>{const{user:n}=$(),{t:l}=A("community"),d=l("report.reasons",{returnObjects:!0}),[m,u]=y.useState(null),[o,h]=y.useState(!1),a=async()=>{!m||!n||(h(!0),await p.from("post_reports").insert({user_id:n.id,post_id:r||null,comment_id:c||null,reason:m}),z.success(l("report.thanks")),h(!1),u(null),s())};return e.jsx(je,{open:t,onOpenChange:x=>!x&&s(),children:e.jsxs(we,{className:"max-w-sm",children:[e.jsx(Ne,{children:e.jsx(Se,{className:"text-base",children:l("report.title")})}),e.jsx("div",{className:"space-y-2 mt-2",children:d.map(x=>e.jsx("button",{onClick:()=>u(x),className:`w-full text-left px-3 py-2 rounded-lg text-sm transition-colors ${m===x?"bg-purple-50 dark:bg-purple-950/40 text-purple-700 border border-purple-200 dark:border-purple-900":"bg-gray-50 dark:bg-neutral-800/50 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-neutral-800 border border-transparent"}`,children:x},x))}),e.jsx(Z,{onClick:a,disabled:!m||o,className:"w-full mt-3 bg-red-500 hover:bg-red-600",children:l(o?"report.submitting":"report.submit")})]})})},St=({postId:t,postAuthorId:s,likesCount:r,commentsCount:c,isLiked:n,isBookmarked:l,onLikeToggle:d,onBookmarkToggle:m,onHideUser:u,isFeedbackPost:o})=>{const[h,a]=y.useState(!1),{t:x}=A("community");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between pt-2.5",style:{borderTop:"0.5px solid #E5E5EA"},children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("button",{onClick:d,className:"flex items-center gap-1 transition-colors",style:{color:n?"#F97066":"#8E8E93",fontSize:12},children:[e.jsx($e,{className:`w-3.5 h-3.5 ${n?"fill-current":""}`}),r>0&&e.jsx("span",{children:r})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:m,style:{color:l?"#9333EA":"#C7C7CC"},children:e.jsx(et,{className:`w-3.5 h-3.5 ${l?"fill-current":""}`})}),e.jsxs(Ke,{children:[e.jsx(Ve,{asChild:!0,children:e.jsx("button",{style:{color:"#C7C7CC"},children:e.jsx(Ze,{className:"w-3.5 h-3.5"})})}),e.jsxs(Ye,{className:"w-40 p-1",align:"end",children:[e.jsxs("button",{onClick:()=>a(!0),className:"w-full flex items-center gap-2 px-3 py-2 text-xs hover:bg-gray-50 dark:hover:bg-neutral-800/50 rounded-md",style:{color:"#6E6E73"},children:[e.jsx(tt,{className:"w-3 h-3"})," ",x("postActions.report")]}),e.jsxs("button",{onClick:u,className:"w-full flex items-center gap-2 px-3 py-2 text-xs hover:bg-gray-50 dark:hover:bg-neutral-800/50 rounded-md",style:{color:"#6E6E73"},children:[e.jsx(Re,{className:"w-3 h-3"})," ",x("postActions.hide")]})]})]})]})]}),e.jsx(Nt,{open:h,onClose:()=>a(!1),postId:t})]})},xe=["#9333EA","#F97066","#14B8A6","#38BDF8","#F59E0B","#EF4444"],Ct=t=>{let s=0;for(let r=0;r<t.length;r++)s=t.charCodeAt(r)+((s<<5)-s);return xe[Math.abs(s)%xe.length]},Et=({postId:t,visible:s,commentsCount:r,onCommentAdded:c})=>{const{user:n}=$(),{t:l}=A("community"),[d,m]=y.useState([]),[u,o]=y.useState(""),[h,a]=y.useState(!1),[x,i]=y.useState(!1),[g,f]=y.useState(!1);y.useEffect(()=>{s&&x&&!g&&v()},[s,x]);const v=async()=>{const{data:_}=await p.from("post_comments").select("*").eq("post_id",t).order("created_at",{ascending:!0}).limit(50);if(_){const C=[...new Set(_.map(k=>k.author_id))],{data:E}=C.length>0?await p.from("users").select("id, email, full_name, avatar_url").in("id",C):{data:[]},j=new Map((E||[]).map(k=>[k.id,k]));m(_.map(k=>{var N,S,P,R;return{...k,author_name:((N=j.get(k.author_id))==null?void 0:N.full_name)||((P=(S=j.get(k.author_id))==null?void 0:S.email)==null?void 0:P.split("@")[0])||l("comments.anonymous"),author_avatar:((R=j.get(k.author_id))==null?void 0:R.avatar_url)||null}})),f(!0)}},F=async()=>{!u.trim()||!n||h||(a(!0),await p.from("post_comments").insert({post_id:t,author_id:n.id,text:u.trim()}),o(""),a(!1),f(!1),i(!0),v(),c==null||c(),_e(n.id).catch(()=>{}))};return!s&&r===0?null:e.jsxs("div",{className:"mt-2.5",children:[r>0&&e.jsxs("button",{onClick:()=>i(!x),className:"flex items-center gap-1 mb-2 transition-colors hover:opacity-80",style:{fontSize:12,fontWeight:500,color:"#9333EA"},children:[x?e.jsx(Je,{className:"w-3 h-3"}):e.jsx(Oe,{className:"w-3 h-3"}),x?l("comments.hide"):l("comments.show",{count:r})]}),e.jsx("div",{style:{maxHeight:x?400:0,overflow:x?"auto":"hidden",transition:"max-height 0.3s ease"},children:e.jsx("div",{className:"space-y-2.5 mb-2.5",children:d.map(_=>{var E,j;const C=Ct(_.author_name||"");return e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-full flex-shrink-0 overflow-hidden flex items-center justify-center",style:{background:_.author_avatar?void 0:C},children:_.author_avatar?e.jsx("img",{src:_.author_avatar,className:"w-full h-full object-cover",alt:""}):e.jsx("span",{className:"text-[9px] font-semibold text-white",children:(j=(E=_.author_name)==null?void 0:E[0])==null?void 0:j.toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{style:{fontSize:11,fontWeight:600,color:"#1D1D1F"},children:_.author_name}
21),e.jsx("span",{style:{fontSize:10,color:"#8E8E93"},children:ye(new Date(_.created_at),{addSuffix:!0,locale:be})})]}),e.jsx("p",{style:{fontSize:12,color:"#3A3A3C",marginTop:1},children:_.text})]})]},_.id)})})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{value:u,onChange:_=>o(_.target.value),onKeyDown:_=>_.key==="Enter"&&!_.shiftKey&&F(),placeholder:l("comments.placeholder"),className:"flex-1 text-xs focus:outline-none",style:{background:"#F5F5F7",borderRadius:999,padding:"6px 12px",color:"#1D1D1F"}}),e.jsx("button",{onClick:F,disabled:!u.trim()||h,className:"disabled:opacity-30 transition-opacity",style:{color:"#9333EA"},children:e.jsx(Xe,{className:"w-3.5 h-3.5"})})]})]})},ge=["#9333EA","#F97066","#14B8A6","#38BDF8","#F59E0B","#EF4444","#8B5CF6","#06B6D4"],Dt=t=>{let s=0;for(let r=0;r<t.length;r++)s=t.charCodeAt(r)+((s<<5)-s);return ge[Math.abs(s)%ge.length]},Ft=({post:t,onLike:s,onBookmark:r,onHideUser:c,isOwnPost:n})=>{var v,F,_,C,E,j,k;const{t:l}=A("community"),[d,m]=y.useState(t.comments_count),u=Dt(t.author_name),o=t.type==="feedback_request",h=t.type==="milestone",a=t.type==="tip",x=t.niche||null,i=(v=t.content)==null?void 0:v.follower_count,g=x?`${x}${i?` · ${i}`:""}`:null,f=o?{label:l("postCard.feedbackWanted"),bg:"#FFF7ED",color:"#C2410C"}:a?{label:l("postCard.tip"),bg:"#F0FDF4",color:"#16A34A"}:null;return e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-sm p-4",style:{marginBottom:12,border:"1px solid #F2F2F7"},children:[e.jsxs("div",{className:"flex items-start justify-between mb-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-[34px] h-[34px] rounded-full overflow-hidden flex-shrink-0 flex items-center justify-center",style:{background:t.author_avatar?void 0:u},children:t.author_avatar?e.jsx("img",{src:t.author_avatar,className:"w-full h-full object-cover",alt:""}):e.jsx("span",{className:"text-xs font-semibold text-white",children:(F=t.author_name)==null?void 0:F.slice(0,2).toUpperCase()})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{style:{fontSize:13,fontWeight:500,color:"#1D1D1F"},children:t.author_name}),g&&e.jsx("span",{style:{fontSize:10,color:"#8E8E93",background:"#F5F5F7",padding:"1px 6px",borderRadius:999},children:g})]}),e.jsx("span",{style:{fontSize:11,color:"#8E8E93"},children:ye(new Date(t.created_at),{addSuffix:!0,locale:be})})]})]}),f&&e.jsx("span",{style:{fontSize:11,fontWeight:500,color:f.color,background:f.bg,padding:"2px 8px",borderRadius:999},children:f.label})]}),e.jsxs("div",{className:"mb-2.5",children:[((_=t.content)==null?void 0:_.title)&&e.jsx("p",{style:{fontSize:14,fontWeight:600,color:"#1D1D1F",marginBottom:4},children:t.content.title}),a&&((C=t.content)!=null&&C.text)?e.jsx("div",{style:{borderLeft:"3px solid #16A34A",paddingLeft:12},children:e.jsx("p",{style:{fontSize:13,color:"#1D1D1F",whiteSpace:"pre-wrap"},children:t.content.text})}):(E=t.content)!=null&&E.text?e.jsx("p",{style:{fontSize:13,color:"#1D1D1F",whiteSpace:"pre-wrap"},children:t.content.text}):null,h&&((j=t.content)==null?void 0:j.achievement_name)&&e.jsxs("div",{className:"mt-2.5 p-3.5 rounded-xl",style:{background:"#FAFAFA",borderLeft:"3px solid #9333EA"},children:[e.jsx("p",{style:{fontSize:11,fontWeight:500,color:"#9333EA",letterSpacing:"0.05em",marginBottom:6},children:l("postCard.achievementUnlocked")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center text-xl",style:{background:"#9333EA"},children:t.content.achievement_icon||"ð"}),e.jsxs("div",{children:[e.jsx("p",{style:{fontSize:15,fontWeight:500,color:"#1D1D1F"},children:t.content.achievement_name}),t.content.achievement_description&&e.jsx("p",{style:{fontSize:12,color:"#6E6E73"},children:t.content.achievement_description})]})]})]}),(t.type==="video_card"||t.type==="feedback_request")&&((k=t.content)==null?void 0:k.video_title)&&e.jsxs("div",{className:"mt-2.5 flex items-center gap-3 p-3 rounded-xl",style:{background:"#F5F5F7",borderLeft:o?"3px solid #F97066":void 0},children:[e.jsx("div",{className:"flex-shrink-0 rounded-lg overflow-hidden flex items-center justify-center",style:{width:52,height:70,background:"#E5E5EA"},children:t.content.video_thumbnail?e.jsx("img",{src:t.content.video_thumbnail,className:"w-full h-full object-cover",alt:""}):e.jsx(Be,{className:"w-5 h-5",style:{color:"#8E8E93"}})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{style:{fontSize:13,fontWeight:500,color:"#1D1D1F"},className:"truncate",children:t.content.video_title}),e.jsx("div",{className:"flex items-center gap-1.5 mt-1.5 flex-wrap",children:t.content.video_score&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold",style:{background:o&&parseFloat(t.content.viral_score||"0")<5?"#FEE2E2":"white",color:o&&parseFloat(t.content.viral_score||"0")<5?"#DC2626":"#9333EA"},children:l("postCard.viral",{score:t.content.viral_score||t.content.video_score})}),t.content.hook_score&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold",style:{background:"white",color:"#1D1D1F"},children:l("postCard.hook",{score:t.content.hook_score})})]})}),t.content.view_count&&e.jsx("p",{style:{fontSize:11,color:"#8E8E93",marginTop:4},children:l("postCard.views",{count:t.content.view_count})})]}),t.type==="video_card"&&e.jsx("span",{style:{fontSize:12,fontWeight:500,color:"#9333EA",flexShrink:0},children:l("postCard.analysis")})]})]}),e.jsx(St,{postId:t.id,postAuthorId:t.author_id,likesCount:t.likes_count,commentsCount:d,isLiked:t.isLiked,isBookmarked:t.isBookmarked,onLikeToggle:()=>s(t.id),onBookmarkToggle:()=>r(t.id),onHideUser:()=>c(t.author_id),isFeedbackPost:o}),e.jsx(Et,{postId:t.id,visible:!0,commentsCount:d,onCommentAdded:()=>m(N=>N+1)})]})},Tt=20,At=()=>{const{user:t}=$(),{t:s}=A("community"),[r,c]=y.useState("trending"),[n,l]=y.useState([]),[d,m]=y.useState(!0),[u,o]=y.useState(!1),[h,a]=y.useState(new Set),[x,i]=y.useState(new Set),[g,f]=y.useState(new Set),[v,F]=y.useState(new Set),[_,C]=y.useState(null),[E,j]=y.useState("");y.useEffect(()=>{t&&k()},[t]),y.useEffect(()=>{t&&N()},[t,r,h,x,_]);const k=async()=>{var I,T,q;if(!t)return;const[b,L,D,w,B,O]=await Promise.all([p.from("user_hides").select("hidden_user_id").eq("user_id",t.id),p.from("user_follows").select("following_id").eq("follower_id",t.id),p.from("post_like
21s").select("post_id").eq("user_id",t.id),p.from("post_bookmarks").select("post_id").eq("user_id",t.id),p.from("user_community_profiles").select("niche").eq("user_id",t.id).maybeSingle(),p.from("users").select("full_name").eq("id",t.id).maybeSingle()]);a(new Set((b.data||[]).map(M=>M.hidden_user_id))),i(new Set((L.data||[]).map(M=>M.following_id))),f(new Set((D.data||[]).map(M=>M.post_id))),F(new Set((w.data||[]).map(M=>M.post_id))),C(((I=B.data)==null?void 0:I.niche)||null),j(((T=O.data)==null?void 0:T.full_name)||((q=t.email)==null?void 0:q.split("@")[0])||"")},N=async()=>{if(!t)return;m(!0);let b=p.from("community_posts").select("*").eq("hidden",!1).limit(Tt);if(r==="trending"){const T=new Date;T.setDate(T.getDate()-7),b=b.gte("created_at",T.toISOString()).order("likes_count",{ascending:!1})}else if(r==="following"){const T=[...x];if(T.length===0){l([]),m(!1);return}b=b.in("author_id",T).order("created_at",{ascending:!1})}else r==="niche"?(_&&(b=b.eq("niche",_)),b=b.order("created_at",{ascending:!1})):b=b.order("created_at",{ascending:!1});const{data:L}=await b;if(!L){l([]),m(!1);return}const D=L.filter(T=>!h.has(T.author_id)),w=[...new Set(D.map(T=>T.author_id))],B=w.length>0?await p.from("users").select("id, email, full_name, avatar_url").in("id",w):{data:[]},O=new Map((B.data||[]).map(T=>[T.id,T])),I=D.map(T=>{var q,M,H,W;return{...T,author_name:((q=O.get(T.author_id))==null?void 0:q.full_name)||((H=(M=O.get(T.author_id))==null?void 0:M.email)==null?void 0:H.split("@")[0])||s("feed.anonymous"),author_avatar:((W=O.get(T.author_id))==null?void 0:W.avatar_url)||null,isLiked:g.has(T.id),isBookmarked:v.has(T.id)}});l(I),m(!1)},S=async b=>{if(!t)return;g.has(b)?(await p.from("post_likes").delete().eq("user_id",t.id).eq("post_id",b),f(D=>{const w=new Set(D);return w.delete(b),w}),l(D=>D.map(w=>w.id===b?{...w,isLiked:!1,likes_count:Math.max(0,w.likes_count-1)}:w))):(await p.from("post_likes").insert({user_id:t.id,post_id:b}),f(D=>new Set(D).add(b)),l(D=>D.map(w=>w.id===b?{...w,isLiked:!0,likes_count:w.likes_count+1}:w)))},P=async b=>{if(!t)return;v.has(b)?(await p.from("post_bookmarks").delete().eq("user_id",t.id).eq("post_id",b),F(D=>{const w=new Set(D);return w.delete(b),w}),l(D=>D.map(w=>w.id===b?{...w,isBookmarked:!1}:w))):(await p.from("post_bookmarks").insert({user_id:t.id,post_id:b}),F(D=>new Set(D).add(b)),l(D=>D.map(w=>w.id===b?{...w,isBookmarked:!0}:w)))},R=async b=>{t&&(await p.from("user_hides").insert({user_id:t.id,hidden_user_id:b}),a(L=>new Set(L).add(b)),l(L=>L.filter(D=>D.author_id!==b)),z.success(s("feed.userHidden")))};return e.jsxs("div",{children:[e.jsx(kt,{activeFilter:r,onFilterChange:c}),e.jsx("div",{className:"mt-4",children:e.jsx(vt,{onOpen:()=>o(!0),userName:E})}),e.jsx(wt,{open:u,onClose:()=>o(!1),onPostCreated:N}),d?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(se,{className:"w-5 h-5 animate-spin",style:{color:"#8E8E93"}})}):n.length===0?e.jsxs("div",{className:"text-center py-10",children:[e.jsx("p",{className:"text-2xl mb-2",children:"ð¬"}),e.jsx("p",{style:{fontSize:13,color:"#8E8E93"},children:s(r==="following"?"feed.emptyFollowing":"feed.empty")})]}):e.jsx("div",{children:n.map(b=>e.jsx(Ft,{post:b,onLike:S,onBookmark:P,onHideUser:R,isOwnPost:b.author_id===(t==null?void 0:t.id)},b.id))})]})},Pt=["Comedy","Education","Gaming","Lifestyle","Beauty","Fitness","Food","Fashion","Tech","Travel","Music","Dance","Business","Finance","Health","Motivation","DIY","Sports","Pets","Kunst & Kreativ","Nachrichten","Sonstiges"],Mt=({isOpen:t,onClose:s})=>{const{user:r}=$(),{t:c}=A("community"),[n,l]=y.useState(1),[d,m]=y.useState(null),u=async()=>{!r||!d||(await p.from("user_community_profiles").upsert({user_id:r.id,niche:d,onboarding_completed:!0,credits_balance:0},{onConflict:"user_id"}),s())};return e.jsx(G,{isOpen:t,onClose:()=>{},title:"",maxWidth:"md",children:e.jsxs("div",{className:"text-center",children:[n===1&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-16 h-16 bg-purple-100 dark:bg-purple-900/40 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(Ce,{className:"w-8 h-8 text-purple-600"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-gray-100 mb-2",children:c("onboarding.welcomeTitle")}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-6",children:c("onboarding.welcomeText")}),e.jsx(Z,{onClick:()=>l(2),className:"bg-purple-600 hover:bg-purple-700 text-white",children:c("onboarding.start")})]}),n===2&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-gray-100 mb-2",children:c("onboarding.chooseNiche")}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-4",children:c("onboarding.chooseNicheSub")}),e.jsx("div",{className:"grid grid-cols-3 gap-2 mb-6 max-h-64 overflow-y-auto",children:Pt.map(o=>e.jsx("button",{onClick:()=>m(o),className:`px-3 py-2 rounded-xl text-sm font-medium border transition-all ${d===o?"bg-purple-600 text-white border-purple-600":"bg-white dark:bg-neutral-900 text-gray-700 dark:text-gray-300 border-gray-200 dark:border-neutral-800 hover:border-purple-300"}`,children:o},o))}),e.jsx(Z,{onClick:u,disabled:!d,className:"bg-purple-600 hover:bg-purple-700 text-white disabled:opacity-50",children:c("onboarding.confirm")})]})]})})},Lt=[{id:"extra_analysis",icon:"ð¬",creditCost:10,available:!0}
21,{id:"custom_badge",icon:"ð
",creditCost:25,available:!1},{id:"priority_support",icon:"â¡",creditCost:50,available:!1}],qt=({creditsBalance:t,onCreditsChange:s})=>{const{user:r}=$(),{t:c}=A("community"),[n,l]=y.useState(!1),[d,m]=y.useState(null),[u,o]=y.useState(!1),h=async a=>{if(!(!r||n||!a.available)){if(t<a.creditCost){z.error(c("rewards.toast.notEnough"));return}l(!0);try{await p.from("credit_transactions").insert({user_id:r.id,amount:-a.creditCost,reason:`reward_redeem:${a.id}`}),await p.from("user_community_profiles").update({credits_balance:t-a.creditCost}).eq("user_id",r.id),a.id==="extra_analysis"&&await p.from("usage_tracking").insert({user_id:r.id,action_type:"deep_analysis",action_count:-1}),s(),z.success(c("rewards.toast.unlocked")),m(null)}catch{z.error(c("rewards.toast.error"))}l(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-white dark:bg-neutral-900 rounded-2xl shadow-sm p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4",style:{color:"#9333EA"}}),e.jsx("span",{style:{fontSize:13,fontWeight:500,color:"#1D1D1F"},children:c("rewards.creditsLabel",{count:t})})]}),e.jsxs("button",{onClick:()=>o(!0),className:"flex items-center gap-0.5 transition-opacity hover:opacity-80",style:{fontSize:11,fontWeight:500,color:"#9333EA"},children:[c("rewards.howToEarn")," ",e.jsx(fe,{className:"w-3 h-3"})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:Lt.map(a=>e.jsxs("button",{onClick:()=>a.available&&m(a),disabled:!a.available,className:"flex items-center gap-2.5 p-3 rounded-xl text-left transition-colors",style:{background:a.available?"#F5F5F7":"#FAFAFA",opacity:a.available?1:.5,cursor:a.available?"pointer":"default"},children:[e.jsx("span",{className:"text-xl flex-shrink-0",style:{filter:a.available?"none":"grayscale(1)"},children:a.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{style:{fontSize:12,fontWeight:500,color:"#1D1D1F"},className:"truncate",children:c(`rewards.items.${a.id}.title`)}),e.jsx("div",{className:"flex items-center gap-1 mt-0.5",children:a.available?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-2.5 h-2.5",style:{color:"#9333EA"}}),e.jsx("span",{style:{fontSize:11,fontWeight:600,color:"#9333EA"},children:a.creditCost})]}):e.jsxs("span",{className:"flex items-center gap-0.5",style:{fontSize:10,color:"#8E8E93"},children:[e.jsx(Y,{className:"w-2.5 h-2.5"})," ",c("rewards.comingSoon")]})})]})]},a.id))})]}),e.jsx(G,{isOpen:!!d,onClose:()=>m(null),title:d?c(`rewards.items.${d.id}.title`):"",maxWidth:"sm",children:d&&e.jsxs("div",{className:"text-center py-4",children:[e.jsx("span",{className:"text-4xl block mb-3",children:d.icon}),e.jsx("p",{style:{fontSize:13,color:"#6E6E73",marginBottom:16},children:c(`rewards.items.${d.id}.description`)}),e.jsx("button",{onClick:()=>h(d),disabled:t<d.creditCost||n,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm font-semibold text-white transition-colors disabled:opacity-50",style:{background:t>=d.creditCost?"#9333EA":"#C7C7CC"},children:n?e.jsx(se,{className:"w-3.5 h-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5"}),c("rewards.redeem",{count:d.creditCost})]})})]})}),e.jsx(G,{isOpen:u,onClose:()=>o(!1),title:c("rewards.earnTitle"),maxWidth:"sm",children:e.jsx("div",{className:"space-y-2 py-2",children:[{key:"analyze",credits:"+2"},{key:"achievement",credits:"+5"},{key:"post",credits:"+1"},{key:"goal",credits:"+3"},{key:"streak",credits:"+5"}].map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg",style:{background:"#F5F5F7"},children:[e.jsx("span",{style:{fontSize:13,color:"#1D1D1F"},children:c(`rewards.earn.${a.key}`)}),e.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#9333EA"},children:a.credits})]},a.key))})})]})},zt=()=>{var E;const{user:t}=$(),{t:s}=A("community"),[r,c]=y.useState([]),[n,l]=y.useState(new Map),[d,m]=y.useState(!0),[u,o]=y.useState(null);y.useEffect(()=>{t&&h()},[t]);const h=async()=>
21{if(!t)return;const j=new Date().toISOString(),[k,N]=await Promise.all([p.from("challenges").select("*").eq("is_active",!0).gte("end_date",j).order("start_date",{ascending:!0}),p.from("challenge_participants").select("challenge_id, progress, completed").eq("user_id",t.id)]);c(k.data||[]);const S=new Map;(N.data||[]).forEach(P=>S.set(P.challenge_id,P)),l(S),m(!1)},a=async j=>{if(!t||u)return;o(j);const{error:k}=await p.from("challenge_participants").insert({challenge_id:j,user_id:t.id});k?k.code==="23505"?z.info(s("challenge.toast.already")):z.error(s("challenge.toast.failed")):(z.success(s("challenge.toast.joined")),l(N=>new Map(N).set(j,{challenge_id:j,progress:0,completed:!1}))),o(null)},x=j=>{const k=new Date(j).getTime()-Date.now();if(k<=0)return s("challenge.ended");const N=Math.floor(k/(1e3*60*60*24)),S=Math.floor(k%(1e3*60*60*24)/(1e3*60*60));return N>0?s("challenge.endsInDays",{count:N})+(S>0?s("challenge.hoursSuffix",{hours:S}):""):s("challenge.endsInHours",{count:S})};if(d)return e.jsx("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-gradient-to-br from-violet-50/60 to-white dark:from-violet-950/20 dark:to-neutral-900 p-5 flex items-center justify-center min-h-[160px]",children:e.jsx(se,{className:"w-5 h-5 animate-spin text-gray-400 dark:text-gray-500"})});const i=r[0],g=i?n.get(i.id):null,f=!!g,v=g==null?void 0:g.completed,F=(g==null?void 0:g.progress)||0,_=((E=i==null?void 0:i.condition)==null?void 0:E.target)||1,C=Math.min(100,F/_*100);return e.jsxs("div",{className:"rounded-2xl border border-gray-200/80 dark:border-neutral-800 bg-gradient-to-br from-violet-50/60 to-white dark:from-violet-950/20 dark:to-neutral-900 p-5 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-violet-600 flex items-center justify-center",children:e.jsx(Qe,{className:"w-4 h-4 text-white"})}),e.jsx("span",{className:"text-[13px] font-semibold text-gray-900 dark:text-gray-100",children:s("challenge.title")}),i&&e.jsx("span",{className:"ml-auto inline-flex items-center text-[11px] font-medium px-2 py-0.5 rounded-full bg-violet-100 dark:bg-violet-900/40 text-violet-700",children:s("challenge.credits",{count:i.reward.credits})})]}),i?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-[13px] text-gray-700 dark:text-gray-300 leading-[1.5]",children:i.title}),e.jsxs("div",{className:"flex items-center justify-between -mb-1",children:[e.jsx("span",{className:"text-[11px] text-gray-400 dark:text-gray-500",children:s("challenge.progress")}),e.jsxs("span",{className:"text-[11px] font-semibold tabular-nums text-gray-900 dark:text-gray-100",children:[F," / ",_]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-gray-100 dark:bg-neutral-800 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-violet-600 transition-all duration-500",style:{width:`${C}%`}})}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-gray-400",children:[e.jsx(ve,{className:"w-3 h-3"}),e.jsx("span",{children:x(i.end_date)})]}),!f&&e.jsx("button",{onClick:()=>a(i.id),disabled:u===i.id,className:"self-start text-[12px] font-medium text-violet-700 dark:text-violet-400 hover:underline disabled:opacity-50",children:u===i.id?s("challenge.joining"):s("challenge.join")}),v&&e.jsxs("span",{className:"self-start inline-flex items-center gap-1 text-[12px] font-medium text-emerald-700 dark:text-emerald-400",children:[e.jsx(pe,{className:"w-3.5 h-3.5"})," ",s("challenge.done")]})]}):e.jsx("p",{className:"text-[13px] text-gray-500 dark:text-gray-400",children:s("challenge.none")})]})},$t=t=>t.achievements_count*5+t.videos_analyzed*2+t.streak_days*1+t.consistency_rate*20+t.goals_completed*3+Math.min(t.helpful_comments,30)*1,te=()=>{const t=new Date;return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`},Rt=async t=>{const{data:s}=await p.from("activity_logs").select("created_at").eq("user_id",t).order("created_at",{ascending:!1}).limit(200);if(!s||s.length===0)return{current:0,best:0};const r=new Set;
21s.forEach(h=>{const a=new Date(h.created_at);r.add(`${a.getFullYear()}-${a.getMonth()}-${a.getDate()}`)});const c=Array.from(r).map(h=>{const[a,x,i]=h.split("-").map(Number);return new Date(a,x,i)}).sort((h,a)=>a.getTime()-h.getTime());let n=0;const l=new Date;l.setHours(0,0,0,0);const d=new Date(l);d.setDate(d.getDate()-1);const m=new Date(c[0]);if(m.setHours(0,0,0,0),m.getTime()===l.getTime()||m.getTime()===d.getTime()){let h=new Date(m);for(const a of c){const x=new Date(a);if(x.setHours(0,0,0,0),x.getTime()===h.getTime())n++,h=new Date(h),h.setDate(h.getDate()-1);else if(x.getTime()<h.getTime())break}}let u=1,o=1;for(let h=1;h<c.length;h++){const a=c[h-1].getTime()-c[h].getTime();Math.abs(a-864e5)<36e5?(o++,u=Math.max(u,o)):o=1}return{current:n,best:Math.max(n,u)}},Ot=async t=>{var C;const s=te(),r=new Date;r.setDate(1),r.setHours(0,0,0,0);const{data:c}=await p.from("tiktok_accounts").select("id").eq("user_id",t),n=(c||[]).map(E=>E.id),[l,d,m,u,o,h]=await Promise.all([p.from("user_achievements").select("*",{count:"exact",head:!0}).eq("user_id",t),n.length>0?p.from("videos").select("*",{count:"exact",head:!0}).in("tiktok_account_id",n).eq("is_deep_analyzed",!0).gte("analysis_completed_at",r.toISOString()):Promise.resolve({count:0}),p.from("uploaded_videos").select("*",{count:"exact",head:!0}).eq("user_id",t).eq("is_deep_analyzed",!0).gte("analysis_completed_at",r.toISOString()),Rt(t),p.from("user_goals").select("*",{count:"exact",head:!0}).eq("user_id",t).eq("status","completed"),p.from("user_community_profiles").select("niche").eq("user_id",t).maybeSingle()]),x=new Date().getDate(),i=u.current,g=x>0?Math.min(i/x,1):0,f={achievements_count:l.count||0,videos_analyzed:(d.count||0)+(m.count||0),streak_days:i,consistency_rate:g,goals_completed:o.count||0,helpful_comments:0,total_score:0};f.total_score=$t(f);const v=((C=h.data)==null?void 0:C.niche)||null;await p.from("hookzy_scores").upsert({user_id:t,month:s,score:f.total_score,niche:v,achievements_count:f.achievements_count,videos_analyzed:f.videos_analyzed,streak_days:f.streak_days,consistency_rate:f.consistency_rate,goals_completed:f.goals_completed,helpful_comments:f.helpful_comments},{onConflict:"user_id,month"});const{data:F}=await p.from("hookzy_scores").select("score").eq("month",s);let _=null;if(f.videos_analyzed>=3){if(F&&F.length>1){const E=F.map(k=>k.score).sort((k,N)=>N-k),j=E.indexOf(f.total_score)+1;_=Math.round(j/E.length*100)}else _=1;await p.from("hookzy_scores").update({percentile:_}).eq("user_id",t).eq("month",s)}return{score:f.total_score,percentile:_,breakdown:f}},Bt=async(t,s)=>{let r=p.from("hookzy_scores").select("user_id, score, achievements_count").eq("month",t).order("score",{ascending:!1}).limit(10);s&&(r=r.eq("niche",s));const{data:c}=await r;return c||[]},U=({children:t})=>e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-gray-400 mb-3",children:t}),ns=()=>{const{t}=A("community"),{user:s}=$(),[r,c]=y.useState(null),[n,l]=y.useState(!0),[d,m]=y.useState(!1),[u,o]=y.useState(null),[h,a]=y.useState(!0),[x,i]=y.useState("month"),[g,f]=y.useState(!1),[v,F]=y.useState(null),[_,C]=y.useState([]),[E,j]=y.useState(!0),[k,N]=y.useState(null),[S,P]=y.useState(0),[R,b]=y.useState({current_streak:0,best_streak:0}),[L,D]=y.useState(0);y.useEffect(()=>{s&&w()},[s]),y.useEffect(()=>{!s||n||B()},[s,x,g,n]);const w=async()=>{if(!s)return;l(!0);const{data:q}=await p.from("user_community_profiles").select("*").eq("user_id",s.id).maybeSingle();q?(c(q),q.onboarding_completed||m(!0)):(m(!0),await p.from("user_community_profiles").insert({user_id:s.id,credits_balance:0,onboarding_completed:!1}),c({credits_balance:0})),l(!1)},B=async()=>{if(!s)return;a(!0);const q=await He(s.id);b({current_streak:q.current,best_streak:q.best}),await _e(s.id);const M=await Ot(s.id);F(M.breakdown),o(M.percentile),P(M.breakdown.achievements_count);const H=new Date;H.setDate(1),H.setHours(0,0,0,0);const{count:W}=await p.from("activity_logs").select("*",{count:"exact",head:!0}).eq("user_id",s.id).gte("created_at",H.toISOString());D((W||0)*5);const Q=g&&(r==null?void 0:r.niche)||null,Ee=await Bt(te(),Q);C(Ee);const De=te(),{data:re}=await p.from("hookzy_scores").select("user_id, score").eq("month",De).order("score",{ascending:!1});if(re){const ne=re.findIndex(Fe=>Fe.user_id===s.id);N(ne>=0?ne+1:null)}a(!1)},O=()=>{m(!1),w()},I=()=>{z.success(t("hub.toast.shareSoon"))},T=async()=>{try{const q=document.getElementById("mountain-card");if(!q)return;const{toPng:M}=await Te(async()=>{const{toPng:Q}=await import("./index-xVp0PEHv.js");return{toPng:Q}},[]),H=await M(q,{quality:.95,pixelRatio:2}),W=document.createElement("a");W.download="hookzy-standing.png",W.href=H,W.click(),z.success(t("hub.toast.imageSaved"))}catch{z.error(t("hub.toast.imageError"))}};return n?e.jsx(le,{children:e.jsx("div",{className:"flex items-center justify-center h-64 text-sm text-gray-500 dark:text-gray-400",children:t("hub.loading")})}):e.jsx(le,{children:e.jsxs("div",{className:"tabular-nums",children:[e.jsx(Mt,{isOpen:d,onClose:O}),e.jsx(st,{creditsBalance:(r==null?void 0:r.credits_balance)||0,currentStreak:R.current_streak,percentile:u,onShare:I,onSaveImage:T}),e.jsxs("section",{className:"mb-6",children:[e.jsx(U,{children:t("hub.bands.standing")}
21),e.jsx("div",{id:"mountain-card",className:"bg-white dark:bg-neutral-900 border border-gray-200/80 dark:border-neutral-800 rounded-2xl overflow-hidden",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1.3fr_1fr]",children:[e.jsx("div",{id:"mountain-section",className:"p-6 lg:p-7 bg-gradient-to-b from-gray-50/60 to-white dark:from-neutral-900 dark:to-neutral-900",children:e.jsx(xt,{percentile:u,loading:h,period:x,onPeriodChange:i,nicheFilter:g,onNicheFilterToggle:()=>f(!g),niche:r==null?void 0:r.niche,currentUserRank:k})}),e.jsxs("div",{className:"p-6 lg:p-7 border-t lg:border-t-0 lg:border-l border-gray-200/80 dark:border-neutral-800",children:[e.jsx(U,{children:t("hub.bands.thisMonth")}),e.jsx(ht,{achievementsCount:S,longestStreak:R.best_streak,consistencyRate:v!=null&&v.consistency_rate?Math.round(v.consistency_rate*100):0,timeInHookzy:L})]})]})})]}),e.jsxs("section",{className:"mb-6",children:[e.jsx(U,{children:t("hub.bands.today")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3.5",id:"streak-section",children:[e.jsx(at,{}),e.jsx(dt,{}),e.jsx(zt,{})]})]}),e.jsxs("section",{className:"mb-6",children:[e.jsx(U,{children:t("hub.bands.progress")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[1fr_1.2fr] gap-3.5",children:[e.jsx(lt,{}),e.jsx(mt,{})]})]}),e.jsxs("section",{className:"mb-6",children:[e.jsx(U,{children:t("hub.bands.top10")}),e.jsx(bt,{entries:_,currentUserId:(s==null?void 0:s.id)||"",expanded:E,onToggle:()=>j(!E),currentUserScore:(v==null?void 0:v.total_score)||0,currentUserRank:k})]}),e.jsxs("section",{className:"mb-6",children:[e.jsx(U,{children:t("hub.bands.community")}),e.jsx(At,{})]}),e.jsxs("section",{className:"mb-6",id:"rewards-section",children:[e.jsx(U,{children:t("hub.bands.rewards")}),e.jsx(qt,{creditsBalance:(r==null?void 0:r.credits_balance)||0,onCreditsChange:w})]})]})})};export{ns as CommunityHubPage};
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.