1import{J as ne,g as c,C as h,j as e,q as b,S as ye,E as ke,k as ve}from"./index-CEq6EAUz.js";import{B as je}from"./BlockReveal-BC1i12DB.js";import{A as U}from"./arrow-left-zgVC41dm.js";import{M as ee}from"./music-2-iOS-PdBz.js";import{F as Ne}from"./flame-DhG1FM-4.js";import{U as Ce}from"./user-round-BqDtZGW5.js";import{P as Se}from"./plus-QkdZOPFd.js";import{L as Ee}from"./link-ChCepUKM.js";import{S as Te}from"./search-CMha1ATw.js";import{M as H}from"./message-circle-NOrullP4.js";import{T as Me}from"./thumbs-up-CiuFT1m_.js";import{C as Fe}from"./chart-column-BfzgXP9h.js";import{T as Pe}from"./trash-2-HiVMG9Mx.js";import{E as Ae}from"./external-link-_xXbGX0L.js";const V={discussion:{label:"Discussion",icon:H,tone:"emerald"},track:{label:"Track Drop",icon:ke,tone:"rose"},question:{label:"Question",icon:Te,tone:"violet"},resource:{label:"Resource",icon:Ee,tone:"blue"}},oe={emerald:"border-emerald-200 bg-emerald-50 text-emerald-700",rose:"border-rose-200 bg-rose-50 text-rose-700",violet:"border-violet-200 bg-violet-50 text-violet-700",blue:"border-blue-200 bg-blue-50 text-blue-700"},ie="id,display_name,username,avatar_url,plan,verified_badge",W=`id,user_id,title,slug,body,post_type,media_url,media_type,tags,status,upvotes_count,views_count,comments_count,comments_enabled,created_at,profiles!discover_posts_user_id_fkey(${ie})`,te="id,user_id,title,slug,body,post_type,media_url,media_type,tags,status,upvotes_count,views_count,comments_count,comments_enabled,created_at",se=`id,post_id,user_id,body,status,created_at,profiles!forum_comments_user_id_fkey(${ie})`,Le="id,post_id,user_id,body,status,created_at",P=10,$e="mg_forum_posts_cache_v3";async function le(t,a="forum_post"){if(!t)return null;try{Promise.resolve(h.rpc("touch_writer_streak")).then(()=>window.dispatchEvent(new Event("mg:streak-touched"))).catch(()=>{});const{data:r,error:o}=await h.rpc("claim_generation_bonus",{p_user_id:t,p_source:a});return o&&console.warn("Forum generation bonus failed:",o.message),r||null}catch(r){return console.warn("Forum generation bonus exception:",r),null}}const qe=[{label:"Rate my hook",type:"question",title:"Rate my hook: does this feel catchy enough?",body:`I am working on a hook and want honest feedback. 2 3What hits? 4What feels generic? 5Which line should I rewrite first?`,tags:"feedback,hooks,songwriting"},{label:"Finish this verse",type:"question",title:"Help me finish this verse",body:`I have the direction, but I am stuck on the next bars. 6 7The emotion is: 8The artist/reference energy is: 9The part I need help with is:`,tags:"lyrics,feedback,verse"},{label:"Which version wins?",type:"discussion",title:"Which version is stronger?",body:`I am choosing between two versions. 10 11Version A: 12 13Version B: 14 15Which one would you keep and why?`,tags:"feedback,hooks,writing"},{label:"Beat/cadence help",type:"question",title:"What beat or cadence fits this idea?",body:`I need help matching this lyric idea to a vibe. 16 17BPM/genre if known: 18Mood: 19Reference artists: 20Where the flow feels awkward:`,tags:"cadence,beat,flow"}];function Y(t,a=70){return(t||"").toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"").slice(0,a).replace(/^-+|-+$/g,"")||"music-post"}function Re(t){const a=Date.now().toString(36),r=Y(t,80-a.length-1);return Y(`${r}-${a}`,90)}function Oe(t){const a=(t||"").trim();if(!a)return{media_url:null,media_type:null};const r=a.toLowerCase();return r.includes("youtube.com")||r.includes("youtu.be")?{media_url:a,media_type:"youtube"}:r.includes("soundcloud.com")?{media_url:a,media_type:"soundcloud"}:{media_url:a,media_type:"link"}}const De=/(?:https?:\/\/|www\.)[^\s<>"')]+/gi,Ie=["youtube.com","youtu.be","soundcloud.com","spotify.com","open.spotify.com","music.apple.com"];function Be(t){return String(t||"").match(De)||[]}function Ue(t){try{const a=t.startsWith("www.")?`https://${t}`:t,r=new URL(a).hostname.toLowerCase().replace(/^www\./,"");return Ie.some(o=>r===o||r.endsWith(`.${o}`))}catch{return!1}}function de(...t){return t.flatMap(Be).find(a=>!Ue(a))||null}function ce(t,a="Forum action failed. Refresh and try again."){const r=String((t==null?void 0:t.message)||t||""),o=r.toLowerCase();return r.includes("FORUM_BANNED")?"Posting access permanently removed.":r.includes("FORUM_LINK_NOT_ALLOWED")||o.includes("disallowed forum link")?"Only YouTube, SoundCloud, Spotify, and Apple Music links are allowed.":o.includes("link_url")||o.includes("banned_at")||o.includes("blocked_until")||o.includes("schema cache")||o.includes("has no field")?"Forum is finishing a database update. Refresh and try again in a minute.":o.includes("row-level security")?"Your session cannot post here yet. Refresh, sign in again, and try once more.":r||a}async function me(t){var o;const a=(o=(await h.auth.getSession()).data.session)==null?void 0:o.access_token;return a?(await fetch("/api/forum/warn",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({reason:t})})).json().catch(()=>null):null}function We(t){try{const a=new URL(t);if(a.hostname.includes("youtu.be"))return a.pathname.replace("/","").split("?")[0];if(a.searchParams.get("v"))return a.searchParams.get("v");const r=a.pathname.match(/\/shorts\/([^/?]+)/);if(r)return r[1];const o=a.pathname.match(/\/embed\/([^/?]+)/);if(o)return o[1]}catch{return null}return null}function ue(t){const a=Math.floor((Date.now()-new Date(t).getTime())/6e4);if(a<1)return"now";if(a<60)return`${a}m ago`;const r=Math.floor(a/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function K(t,a){return(t==null?void 0:t.username)||(t==null?void 0:t.display_name)||(a==null?void 0:a.slice(0,8))||"creator"}function z(t,a){return`/u/${a}`}function xe(t,a=1){return`${$e}:${t||"hot"}:p${a}`}function ae(t,a=1){if(typeof window>"u")return[];try{const r=window.sessionStorage.getItem(xe(t,a));if(!r)return[];const o=JSON.parse(r);return Array.isArray(o==null?void 0:o.posts)?o.posts:[]}catch{return[]}}function Ge(t,a,r=1){if(!(typeof window>"u"||!Array.isArray(a)||a.length===0))try{window.sessionStorage.setItem(xe(t,r),JSON.stringify({savedAt:Date.now(),posts:a.slice(0,P)}))}catch{}}function F(t,a=18e3){let r;return Promise.race([Promise.resolve(t).finally(()=>clearTimeout(r)),new Promise((o,p)=>{r=setTimeout(()=>p(new Error("Forum request timed out")),a)})])}function Q({profile:t}){var r;const a=(t==null?void 0:t.display_name)||(t==null?void 0:t.username)||"Creator";return e.jsx("div",{className:"grid h-12 w-12 shrink-0 place-items-center overflow-hidden rounded-xl bg-gradient-to-br from-[#12362b] to-[#0d241d] font-display text-sm font-bold text-[#7BE0B8] shadow-[inset_0_1px_0_rgba(255,255,255,0.2),0_8px_20px_-8px_rgba(15,46,36,0.5)]",children:t!=null&&t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:a,className:"h-full w-full object-cover"}):(r=a[0])==null?void 0:r.toUpperCase()})}function Je({post:t}){if(!t.media_url)return null;if(t.media_type==="youtube"){const a=We(t.media_url);if(a)return e.jsx("div",{className:"mt-4 overflow-hidden rounded-2xl border border-slate-200 bg-black shadow-sm aspect-video",children:e.jsx("iframe",{title:t.title,src:`https://www.youtube.com/embed/${a}`,className:"h-full w-full",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",allowFullScreen:!0})})}return t.media_type==="soundcloud"?e.jsx("div",{className:"mt-4 overflow-hidden rounded-2xl border border-orange-100 bg-orange-50 shadow-sm",children:e.jsx("iframe",{title:t.title,className:"h-[166px] w-full",scrolling:"no",frameBorder:"no",allow:"autoplay",src:`https://w.soundcloud.com/player/?url=${encodeURIComponent(t.media_url)}&color=%230f766e&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&show_teaser=false`})}):e.jsxs("a",{href:t.media_url,target:"_blank",rel:"noreferrer",className:"mt-4 inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-black text-slate-700 shadow-sm hover:border-emerald-300",children:["Open link ",e.jsx(Ae,{className:"h-3.5 w-3.5"})]})}function re({post:t,voted:a,onVote:r,compact:o=!1,user:p,onToggleComments:n,onDeletePost:f}){var _,j;const g=t.profiles,k=K(g,t.user_id),v=V[t.post_type]||V.discussion,x=v.icon,w=o&&((_=t.body)==null?void 0:_.length)>420?`${t.body.slice(0,420).trim()}...`:t.body,M=o?"h2":"h1";return e.jsx(ve.article,{initial:{opacity:0,y:12}
20,animate:{opacity:1,y:0},className:"group relative overflow-hidden rounded-[18px] border border-ink-900/10 bg-white shadow-[0_1px_2px_rgba(13,21,18,0.04)] transition-all duration-300 hover:-translate-y-0.5 hover:border-sf-green/40 hover:shadow-[0_16px_40px_-18px_rgba(13,21,18,0.25)]",children:e.jsx("div",{className:"p-4 sm:p-5",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:gap-5",children:[e.jsxs("div",{className:"flex items-start gap-3 sm:w-32 sm:flex-col",children:[e.jsx("button",{onClick:()=>b(z(g,t.user_id)),className:"shrink-0","aria-label":`Open ${k} profile`,children:e.jsx(Q,{profile:g})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("button",{onClick:()=>b(z(g,t.user_id)),className:"block max-w-full truncate text-sm font-black text-slate-950 hover:text-emerald-700",children:["@",k]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1.5 text-[10px] font-bold text-slate-400",children:[(g==null?void 0:g.verified_badge)&&e.jsx("span",{className:"rounded-full bg-emerald-50 px-2 py-0.5 text-[9px] font-black text-emerald-700",children:"VERIFIED"}),e.jsx("span",{children:ue(t.created_at)})]})]})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-1 text-[10px] font-black ${oe[v.tone]}`,children:[e.jsx(x,{className:"h-3 w-3"})," ",v.label]}),e.jsx("span",{className:"rounded-full border border-slate-200 bg-slate-50 px-2.5 py-1 text-[10px] font-black text-slate-500",children:"Public thread"})]}),e.jsx("button",{onClick:()=>b(`/forum/${t.slug}`),className:"block text-left",children:e.jsx(M,{className:`${o?"text-lg sm:text-xl":"text-2xl sm:text-3xl"} max-w-3xl font-display font-bold leading-tight tracking-tight text-ink-900 transition-colors group-hover:text-emerald-800`,children:t.title})}),e.jsx("div",{className:"mt-3 max-w-3xl whitespace-pre-wrap rounded-2xl border border-slate-100 bg-slate-50/80 px-4 py-3 text-sm leading-6 text-slate-600",children:w}),e.jsx(Je,{post:t}),((j=t.tags)==null?void 0:j.length)>0&&e.jsx("div",{className:"mt-4 flex flex-wrap gap-1.5",children:t.tags.slice(0,6).map(C=>e.jsxs("span",{className:"rounded-full border border-emerald-100 bg-emerald-50 px-2.5 py-1 text-[11px] font-black text-emerald-700",children:["#",C]},C))}),e.jsxs("div",{className:"mt-5 flex flex-wrap items-center gap-2 border-t border-slate-100 pt-3 text-[12px] font-bold text-slate-500",children:[e.jsxs("button",{onClick:()=>r(t),className:`inline-flex min-h-10 items-center gap-1.5 rounded-2xl border px-3 font-black transition ${a?"border-emerald-300 bg-emerald-50 text-emerald-700":"border-slate-200 bg-white hover:border-emerald-200 hover:text-emerald-700"}`,children:[e.jsx(Me,{className:`h-3.5 w-3.5 ${a?"fill-emerald-600":""}`}),t.upvotes_count||0]}),e.jsxs("span",{className:"inline-flex min-h-10 items-center gap-1 rounded-2xl border border-slate-200 bg-slate-50 px-3",children:[e.jsx(Fe,{className:"h-3.5 w-3.5"})," ",t.views_count||0," views"]}),e.jsxs("span",{className:"inline-flex min-h-10 items-center gap-1 rounded-2xl border border-slate-200 bg-slate-50 px-3",children:[e.jsx(H,{className:"h-3.5 w-3.5"})," ",t.comments_count||0," replies"]}),!o&&(p==null?void 0:p.id)===t.user_id&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>n==null?void 0:n(t),className:"inline-flex min-h-10 items-center gap-1 rounded-2xl border border-amber-200 bg-amber-50 px-3 text-amber-800",children:t.comments_enabled===!1?"Enable comments":"Disable comments"}),e.jsxs("button",{onClick:()=>f==null?void 0:f(t),className:"inline-flex min-h-10 items-center gap-1 rounded-2xl border border-red-200 bg-red-50 px-3 text-red-700",children:[e.jsx(Pe,{className:"h-3.5 w-3.5"})," Delete"]})]}),o&&e.jsx("button",{onClick:()=>b(`/forum/${t.slug}`),className:"ml-auto min-h-10 rounded-full bg-forest px-5 text-xs font-bold tracking-tight text-forest-ink shadow-[inset_0_1px_0_rgba(255,255,255,0.2),0_10px_26px_-10px_rgba(15,46,36,0.6)] transition hover:-translate-y-
20px hover:bg-forest-hover",children:"Open thread"})]})]})]})})})}function Ve({onCreated:t}){const{user:a,profile:r}=ne(),[o,p]=c.useState(!1),[n,f]=c.useState(""),[g,k]=c.useState(""),[v,x]=c.useState("discussion"),[w,M]=c.useState(""),[_,j]=c.useState(""),[C,A]=c.useState(!1),[L,E]=c.useState("");if(!a)return e.jsxs("section",{className:"overflow-hidden rounded-[26px] border border-emerald-100 bg-white shadow-xl shadow-emerald-950/5",children:[e.jsxs("div",{className:"border-b border-emerald-100 bg-gradient-to-r from-emerald-50 via-white to-cyan-50 p-5 text-center sm:p-6",children:[e.jsx("p",{className:"text-lg font-black text-slate-950",children:"Join the Melody Genie Forum"}),e.jsx("p",{className:"mx-auto mt-2 max-w-xl text-sm leading-6 text-slate-600",children:"Public threads become searchable music pages. Ask questions, post tracks, discuss lyrics, and build a creator profile that Google can discover."})]}),e.jsx("div",{className:"p-4 text-center",children:e.jsx("button",{onClick:()=>b("/signup"),className:"min-h-11 rounded-2xl bg-slate-950 px-5 text-sm font-black text-white transition hover:bg-emerald-600",children:"Create account"})})]});const R=async()=>{if(E(""),n.trim().length<4||g.trim().length<8){E("Add a stronger title and at least one useful paragraph.");return}const u=de(n,g,w);if(u){A(!0);const S=await me(`Disallowed forum link: ${u}`);A(!1),S!=null&&S.banned?E("Posting access permanently removed after 3 link warnings."):E(`Only YouTube, SoundCloud, Spotify, and Apple Music links are allowed. Warning ${(S==null?void 0:S.warning_count)||"?"}/3.`);return}A(!0);const N=Oe(w),O=_.split(",").map(S=>Y(S.trim()).replace(/-/g,"")).filter(Boolean).slice(0,6),D=Re(n),{data:G,error:T}=await h.from("discover_posts").insert({user_id:a.id,title:n.trim(),slug:D,body:g.trim(),post_type:v,media_url:N.media_url,media_type:N.media_type,tags:O}).select(W).single();if(A(!1),T){E(ce(T,"Could not publish this forum post. Refresh and try again."));return}f(""),k(""),M(""),j(""),x("discussion"),p(!1),le(a.id),t==null||t(G)},q=u=>{p(!0),x(u.type),f(u.title),k(u.body),j(u.tags),M("")};return e.jsxs("section",{className:"overflow-hidden rounded-[18px] border border-ink-900/10 bg-white/90 shadow-[inset_0_1px_0_rgba(255,255,255,0.85),0_14px_40px_-18px_rgba(13,21,18,0.18)] backdrop-blur-xl",children:[e.jsxs("button",{onClick:()=>p(!o),className:"group flex w-full items-center gap-3 border-b border-ink-900/5 p-4 text-left sm:p-5",children:[e.jsx(Q,{profile:r}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-[0.16em] text-emerald-600",children:"New thread"}),e.jsx("p",{className:"text-base font-black text-slate-950",children:"Create a public music thread"}),e.jsx("p",{className:"truncate text-sm font-semibold text-slate-500",children:"Ask for feedback, drop a track, or publish a useful creator note."})]}),e.jsx("div",{className:"grid h-11 w-11 shrink-0 place-items-center rounded-full bg-forest text-forest-ink shadow-[inset_0_1px_0_rgba(255,255,255,0.2),0_10px_26px_-10px_rgba(15,46,36,0.6)] transition group-hover:-translate-y-px",children:e.jsx(Se,{className:`h-5 w-5 transition ${o?"rotate-45":""}`})})]}),e.jsxs("div",{className:"px-4 pb-4 pt-1 sm:px-5",children:[e.jsx("p",{className:"mb-2 text-[10px] font-black uppercase tracking-[0.16em] text-slate-400",children:"Fast starts · one tap, post ready"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:qe.map(u=>e.jsx("button",{onClick:()=>q(u),className:"rounded-2xl border border-emerald-100 bg-emerald-50 px-3 py-2 text-[11px] font-black text-emerald-700 transition hover:border-emerald-200 hover:bg-white",children:u.label},u.label))})]}),o&&e.jsxs("div",{className:"space-y-4 border-t border-slate-100 p-4 sm:p-5",children:[e.jsx("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-4",children:Object.entries(V).map(([u,N])=>e.jsx("button",{onClick:()=>x(u),className:`min-h-12 rounded-2xl border px-3 text-[12px] font-black transition ${v===u?oe[N.tone]:"border-slate-200 bg-slate-50 text-slate-500 hover:border-slate-300 hover:bg-white"}`,children:N.label},u))}),e.jsx("input",{value:n,onChange:u=>f(u.target.value),maxLength:140,className:"forum-input font-black",placeholder:"Title: best trap hook structure for 2026?"}),e.jsx("textarea",{value:g,onChange:u=>k(u.target.value),rows:5,className:"forum-input min-h-40 resize-none leading-7",placeholder:"Write the post. Context, opinion, question, lyrics breakdown, production notes..."}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsx("input",{value:w,onChange:u=>M(u.target.value),className:"forum-input",placeholder:"Optional YouTube, SoundCloud, Spotify, or Apple Music link"}
20),e.jsx("input",{value:_,onChange:u=>j(u.target.value),className:"forum-input",placeholder:"Tags: rap, songwriting, feedback"})]}),L&&e.jsx("p",{className:"rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-xs font-bold text-red-600",children:L}),e.jsx("button",{onClick:R,disabled:C,className:"min-h-12 w-full rounded-full bg-forest px-4 text-sm font-bold tracking-tight text-forest-ink shadow-[inset_0_1px_0_rgba(255,255,255,0.2),0_10px_26px_-10px_rgba(15,46,36,0.6)] transition hover:-translate-y-px hover:bg-forest-hover disabled:opacity-50",children:C?"Publishing...":"Publish public thread"})]})]})}function Ye({post:t,user:a,comments:r,commentText:o,setCommentText:p,commentError:n,commentNotice:f,commentSaving:g,onSubmit:k,onDeleteComment:v}){return e.jsxs("section",{className:"overflow-hidden rounded-[26px] border border-slate-200 bg-white shadow-lg shadow-slate-200/60",children:[e.jsxs("div",{className:"border-b border-slate-100 bg-slate-50/70 p-4 sm:p-5",children:[e.jsxs("h2",{className:"flex items-center gap-2 font-display text-xl font-bold tracking-tight text-ink-900",children:[e.jsx(H,{className:"h-5 w-5 text-emerald-600"})," Replies"]}),e.jsx("p",{className:"mt-1 text-sm font-semibold text-slate-500",children:t.comments_enabled===!1?"The post owner has closed comments.":"Registered creators can join the thread."})]}),e.jsxs("div",{className:"space-y-3 p-4 sm:p-5",children:[r.length===0?e.jsx("p",{className:"rounded-2xl border border-dashed border-slate-200 bg-slate-50 p-5 text-sm font-semibold text-slate-400",children:"No comments yet."}):r.map(x=>{const w=(a==null?void 0:a.id)===x.user_id||(a==null?void 0:a.id)===t.user_id;return e.jsxs("div",{className:"flex gap-3 rounded-2xl border border-slate-100 bg-slate-50/80 p-3",children:[e.jsx(Q,{profile:x.profiles}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] font-bold text-slate-400",children:[e.jsxs("button",{onClick:()=>b(z(x.profiles,x.user_id)),className:"font-black text-slate-900 hover:text-emerald-700",children:["@",K(x.profiles,x.user_id)]}),e.jsx("span",{children:ue(x.created_at)}),w&&e.jsx("button",{onClick:()=>v(x),className:"ml-auto rounded-full border border-red-100 bg-white px-2 py-1 text-[10px] font-black text-red-600",children:"Delete"})]}),e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-sm leading-6 text-slate-700",children:x.body})]})]},x.id)}),t.comments_enabled!==!1&&e.jsx("div",{className:"rounded-2xl border border-emerald-100 bg-emerald-50/40 p-3",children:a?e.jsxs(e.Fragment,{children:[e.jsx("textarea",{value:o,onChange:x=>p(x.target.value.slice(0,2400)),rows:3,className:"forum-input min-h-24 resize-none",placeholder:"Add a useful reply..."}),n&&e.jsx("p",{className:"mt-2 rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-xs font-bold text-red-600",children:n}),f&&e.jsx("p",{className:"mt-2 rounded-xl border border-emerald-200 bg-emerald-50 px-3 py-2 text-xs font-bold text-emerald-700",children:f}),e.jsx("button",{onClick:k,disabled:g,className:"mt-3 min-h-11 w-full rounded-2xl bg-slate-950 px-4 text-xs font-black text-white transition hover:bg-emerald-600 disabled:opacity-50",children:g?"Posting...":"Post comment"})]}):e.jsx("button",{onClick:()=>b("/signup"),className:"min-h-11 w-full rounded-2xl bg-slate-950 px-4 text-xs font-black text-white transition hover:bg-emerald-600",children:"Sign up to comment"})})]})]})}function lt({slug:t=null,embedded:a=!1}){const{user:r}=ne(),[o,p]=c.useState([]),[n,f]=c.useState(null),[g,k]=c.useState(!0),[v,x]=c.useState(""),[w,M]=c.useState("hot"),[_,j]=c.useState(1),[C,A]=c.useState(0),[L,E]=c.useState(new Set),[R,q]=c.useState([]),[u,N]=c.useState([]),[O,D]=c.useState(""),[G,T]=c.useState(""),[S,J]=c.useState(""),[pe,I]=c.useState(!1),B=t?`https://melodygenie.app/forum/${t}`:"https://melodygenie.app/forum";c.useEffect(()=>{const s=n!=null&&n.title?`${n.title} | Melody Genie Forum`:"Music Forum for Lyrics, Songwriting and Creator Drops | Melody Genie",i=n!=null&&n.body?n.body.replace(/\s+/g," ").slice(0,155):"Join the Melody Genie music forum for lyric feedback, songwriting questions, YouTube and SoundCloud creator drops, artist strategy, and music discussions.";document.title=s;
20let l=document.querySelector('meta[name="description"]');l||(l=document.createElement("meta"),l.setAttribute("name","description"),document.head.appendChild(l)),l.setAttribute("content",i);let d=document.querySelector('link[rel="canonical"]');d||(d=document.createElement("link"),d.setAttribute("rel","canonical"),document.head.appendChild(d)),d.setAttribute("href",B)},[B,n]),c.useEffect(()=>{let s=!1;async function i(){k(!0),x("");try{if(t){let l=await F(h.from("discover_posts").select(W).eq("slug",t).eq("status","published").maybeSingle());if(l.error&&(l=await F(h.from("discover_posts").select(te).eq("slug",t).eq("status","published").maybeSingle())),s)return;if(f(l.data||null),p(l.data?[l.data]:[]),q([]),l.data){try{await h.rpc("increment_discover_post_view",{p_slug:t})}catch{}let d=await F(h.from("discover_posts").select(W).eq("status","published").neq("id",l.data.id).order("upvotes_count",{ascending:!1}).order("created_at",{ascending:!1}).limit(5),12e3).catch(()=>({data:[]}));s||q(d.data||[])}}else{f(null),q([]);const l=ae(w,_);l.length>0&&(p(l),x(""),k(!1));const d=(_-1)*P,m=d+P-1,y=h.from("discover_posts").select(W,{count:"exact"}).eq("status","published").range(d,m);let $=w==="new"?await F(y.order("created_at",{ascending:!1})):await F(y.order("upvotes_count",{ascending:!1}).order("created_at",{ascending:!1}));if($.error){const Z=h.from("discover_posts").select(te,{count:"exact"}).eq("status","published").range(d,m);$=w==="new"?await F(Z.order("created_at",{ascending:!1})):await F(Z.order("upvotes_count",{ascending:!1}).order("created_at",{ascending:!1}))}if(s)return;p($.data||[]),typeof $.count=="number"&&A($.count),x(""),Ge(w,$.data||[],_)}}catch(l){if(!s){const d=t?[]:ae(w,_);d.length>0?(p(d),x("")):(x(l.message||"Could not load Forum"),p([]),f(null))}}finally{s||k(!1)}}return i(),()=>{s=!0}},[t,w,_]),c.useEffect(()=>{if(!r||o.length===0)return;const s=o.map(i=>i.id);h.from("discover_post_votes").select("post_id").eq("user_id",r.id).in("post_id",s).then(({data:i})=>{E(new Set((i||[]).map(l=>l.post_id)))})},[r,o]),c.useEffect(()=>{if(!(n!=null&&n.id)){N([]);return}let s=!1;async function i(){const l=await h.from("forum_comments").select(se).eq("post_id",n.id).eq("status","published").order("created_at",{ascending:!0}).limit(80);if(!s)if(l.error){const d=await h.from("forum_comments").select(Le).eq("post_id",n.id).eq("status","published").order("created_at",{ascending:!0}).limit(80);s||N(d.data||[])}else N(l.data||[])}return i(),()=>{s=!0}},[n==null?void 0:n.id]);const he=c.useMemo(()=>{var s,i;return n?{"@context":"https://schema.org","@type":"DiscussionForumPosting",headline:n.title,text:n.body,url:B,datePublished:n.created_at,author:{"@type":"Person",name:((s=n.profiles)==null?void 0:s.display_name)||((i=n.profiles)==null?void 0:i.username)||"Melody Genie creator",url:`https://melodygenie.app/u/${K(n.profiles,n.user_id)}`},interactionStatistic:[{"@type":"InteractionCounter",interactionType:"https://schema.org/LikeAction",userInteractionCount:n.upvotes_count||0},{"@type":"InteractionCounter",interactionType:"https://schema.org/ViewAction",userInteractionCount:n.views_count||0},{"@type":"InteractionCounter",interactionType:"https://schema.org/CommentAction",userInteractionCount:n.comments_count||0}]}:{"@context":"https://schema.org","@type":"CollectionPage",name:"Melody Genie Forum",url:"https://melodygenie.app/forum",description:"Music forum for lyric feedback, songwriting questions, creator drops, and music strategy.",mainEntity:{"@type":"ItemList",itemListElement:o.slice(0,20).map((l,d)=>({"@type":"ListItem",position:d+1,url:`https://melodygenie.app/forum/${l.slug}`,name:l.title}))}}},[B,n,o]),X=async s=>{if(!r){b("/signup");return}const i=L.has(s.id);E(d=>{const m=new Set(d);return i?m.delete(s.id):m.add(s.id),m});const l=i?-1:1;p(d=>d.map(m=>m.id===s.id?{...m,upvotes_count:Math.max(0,(m.upvotes_count||0)+l)}:m)),(n==null?void 0:n.id)===s.id&&f(d=>({...d,upvotes_count:Math.max(0,(d.upvotes_count||0)+l)})),i?await h.from("discover_post_votes").delete().eq("post_id",s.id).eq("user_id",r.id):await h.from("discover_post_votes").upsert({post_id:s.id,user_id:r.id},{onConflict:"post_id,user_id"})},be=async()=>
20{if(T(""),J(""),!r){b("/signup");return}if(!(n!=null&&n.id)||n.comments_enabled===!1)return;const s=O.trim();if(s.length<2){T("Write a real comment first.");return}const i=de(s);if(i){I(!0);const y=await me(`Disallowed forum comment link: ${i}`);I(!1),y!=null&&y.banned?T("Posting access permanently removed after 3 link warnings."):T(`Only YouTube, SoundCloud, Spotify, and Apple Music links are allowed. Warning ${(y==null?void 0:y.warning_count)||"?"}/3.`);return}I(!0);const{data:l,error:d}=await h.from("forum_comments").insert({post_id:n.id,user_id:r.id,body:s}).select(se).single();if(I(!1),d){T(ce(d,"Could not post this comment. Refresh and try again."));return}N(y=>[...y,l]),D(""),f(y=>({...y,comments_count:(y.comments_count||0)+1}));const m=await le(r.id,"forum_comment");m!=null&&m.success&&Number((m==null?void 0:m.bonus_amount)||0)>0?J("Monthly forum mission complete: +3 credits added."):(m==null?void 0:m.code)==="ALREADY_CLAIMED"&&J("Comment posted. Your monthly community bonus was already claimed.")},fe=async s=>{r&&(await h.from("forum_comments").delete().eq("id",s.id),N(i=>i.filter(l=>
20l.id!==s.id)),f(i=>({...i,comments_count:Math.max(0,(i.comments_count||0)-1)})))},ge=async s=>{if(!r||r.id!==s.user_id)return;const i=s.comments_enabled===!1,{error:l}=await h.from("discover_posts").update({comments_enabled:i}).eq("id",s.id).eq("user_id",r.id);l||(f(d=>({...d,comments_enabled:i})),p(d=>d.map(m=>m.id===s.id?{...m,comments_enabled:i}:m)))},_e=async s=>{if(!r||r.id!==s.user_id||!window.confirm("Delete this forum post? This cannot be undone."))return;const{error:l}=await h.from("discover_posts").delete().eq("id",s.id).eq("user_id",r.id);l||b("/forum")},we=s=>{p(i=>[s,...i]),b(`/forum/${s.slug}`)};return e.jsxs("div",{className:a?"mx-auto max-w-6xl p-3 sm:p-5":"min-h-screen bg-porcelain [background-image:radial-gradient(circle_at_90%_8%,rgba(16,185,129,0.09),transparent_24rem),radial-gradient(circle_at_6%_30%,rgba(255,255,255,0.9),transparent_28rem)]",children:[e.jsx("script",{type:"application/ld+json",dangerouslySetInnerHTML:{__html:JSON.stringify(he)}}),!a&&e.jsx("header",{className:"sticky top-0 z-30 border-b border-slate-200/80 bg-white/90 backdrop-blur-xl",children:e.jsxs("div",{className:"mx-auto flex max-w-6xl items-center justify-between px-4 py-3 sm:px-6",children:[e.jsxs("button",{onClick:()=>b("/"),className:"inline-flex min-h-10 items-center gap-2 rounded-2xl px-2 text-sm font-black text-slate-700 hover:bg-slate-50 hover:text-slate-950",children:[e.jsx(U,{className:"h-4 w-4"})," Melody Genie"]}),e.jsx("button",{onClick:()=>r?b("/dashboard"):b("/signup"),className:"min-h-10 rounded-full bg-forest px-5 text-xs font-bold tracking-tight text-forest-ink shadow-[inset_0_1px_0_rgba(255,255,255,0.2),0_10px_26px_-10px_rgba(15,46,36,0.6)] transition hover:-translate-y-px hover:bg-forest-hover",children:r?"Dashboard":"Join"})]})}),e.jsxs("main",{className:a?"":"mx-auto max-w-6xl px-4 py-6 sm:px-6 sm:py-10",children:[!t&&e.jsxs("section",{className:"mb-8 grid gap-5 border-b border-ink-900/10 pb-8 lg:grid-cols-[minmax(0,1fr)_340px]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"mb-3 text-[10px] font-bold uppercase tracking-[0.24em] text-emerald-600",style:{fontFamily:"'JetBrains Mono', monospace"},children:"Community"}),e.jsxs(je,{blockColor:"#0E241C",stagger:.12,children:[e.jsx("span",{className:"font-display text-[30px] font-bold leading-[1.08] tracking-tighter text-ink-900 sm:text-[40px]",children:"Drop your music."}),e.jsx("span",{className:"font-display text-[30px] font-bold leading-[1.08] tracking-tighter sm:text-[40px]",children:e.jsx("em",{className:"not-italic bg-gradient-to-r from-sf-green to-sf-teal bg-clip-text text-transparent",children:"Get real feedback."})})]}),e.jsx("p",{className:"mt-4 max-w-md text-[13.5px] font-medium leading-relaxed text-ink-600",children:"Track drops, lyric feedback, songwriting questions and creator strategy â from people actually making music."}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:["Ask one specific fix","Add context before links","Reply with recording-ready advice"].map((s,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-ink-900/10 bg-white/80 px-3 py-1.5 text-[11px] font-semibold text-ink-600",children:[e.jsx("span",{className:"grid h-4 w-4 shrink-0 place-items-center rounded-full bg-sf-green/15 text-[9px] font-bold text-emerald-800",children:i+1}),s]},s))})]}),e.jsxs("div",{className:"flex flex-col justify-between rounded-[24px] p-6 text-white shadow-[0_28px_70px_-28px_rgba(8,19,15,0.55)]",style:{background:"linear-gradient(165deg,#0E241C 0%,#0B1F19 45%,#08130F 100%)"},children:[e.jsxs("div",{children:[e.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[10px] font-black uppercase tracking-wider text-amber-950",style:{background:"linear-gradient(135deg,#FDE68A,#F59E0B 55%,#B45309)",boxShadow:"0 2px 6px rgba(180,83,9,0.4), inset 0 1px 0 rgba(255,255,255,0.65)"},children:"+3 credits"}),e.jsxs("p",{className:"mt-3 font-display text-[20px] font-bold leading-snug tracking-tight",children:["Post a track or reply,",e.jsx("br",{}),"earn writing credits."]}),e.jsxs("p",{className:"mt-2 text-[12px] leading-relaxed text-white/50",children:[o.length||"Public"," threads live. Your first post or reply each month adds +3 credits to your pool â enough for a full lyric, on the house."]})]}),e.jsxs("button",{onClick:()=>{var s;return(s=document.getElementById("discover-composer"))==null?void 0:s.scrollIntoView({behavior:"smooth",block:"center"})},className:"mt-5 inline-flex w-full items-center justify-center gap-2 rounded-full py-3 text-[13px] font-black text-[#08130F] transition-transform active:scale-95",style:{background:"linear-gradient(135deg,#10B981,#34D399)"},children:[e.jsx(ee,{className:"h-4 w-4"}),"Drop a track"]})]})]}),t&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("button",{onClick:()=>b("/forum"),className:"inline-flex min-h-10 items-center gap-2 rounded-2xl border border-slate-200 bg-white px-4 text-xs font-black text-slate-700 shadow-sm hover:border-emerald-200",children:[e.jsx(U,{className:"h-3.5 w-3.5"})," Back to Forum"]}),e.jsx("button",{onClick:()=>r?b("/dashboard"):b("/signup"),className:"min-h-10 rounded-2xl bg-slate-950 px-4 text-xs font-black text-white",children:r?"Create in dashboard":"Join Melody Genie"})]}),!t&&e.jsxs("div",{id:"discover-composer",className:"mb-5 grid gap-3 lg:grid-cols-[minmax(0,1fr)_280px]",children:[e.jsx(Ve,{onCreated:we}),e.jsxs("div",{className:"rounded-[24px] border border-black/[0.09] bg-white p-5 shadow-[0_2px_10px_rgba(8,19,15,0.04)]",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-emerald-600",style:{fontFamily:"'JetBrains Mono', monospace"},children:"Better post formula"}),e.jsxs("p",{className:"mt-3 text-[13px] leading-relaxed text-slate-600",children:["The posts that get answers ask ",e.jsx("strong",{className:"text-slate-900",children:"one useful thing"}),":"]}),e.jsx("div",{className:"mt-3 space-y-2",children:['"Rate my hook"','"What beat fits this cadence?"','"Which line should I rewrite?"'].map(s=>e.jsx("p",{className:"rounded-xl bg-slate-50 px-3 py-2 text-[12px] font-semibold italic text-slate-700",children:s},s))})]})]}),!t&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-display text-lg font-bold tracking-tight text-ink-900",children:"Forum threads"}),e.jsx("p",{className:"text-xs font-medium text-ink-500",children:"Browse what creators are asking, testing, and releasing."})]}),e.jsx("div",{className:"inline-flex rounded-full border border-ink-900/10 bg-white/85 p-1 shadow-[inset_0_1px_0_rgba(255,255,255,0.8),0_1px_2px_rgba(13,21,18,0.04)] backdrop-blur",children:[{id:"hot",label:"Hot",icon:Ne},{id:"new",label:"New",icon:ye}].map(s=>e.jsxs("button",{onClick:()=>{M(s.id),j(1)},className:`inline-flex min-h-9 flex-1 items-center justify-center gap-1.5 rounded-full px-4 text-xs font-bold tracking-tight transition sm:flex-none ${w===s.id?"bg-forest text-forest-ink shadow-[0_6px_16px_-6px_rgba(15,46,36,0.45)]":"text-ink-500 hover:text-ink-900"}`,children:[e.jsx(s.icon,{className:"h-3.5 w-3.5"})," ",s.label]},s.id))})]}),e.jsx("section",{className:"space-y-4",children:g?e.jsx("div",{className:"rounded-[28px] border border-slate-200 bg-white p-10 text-center text-sm font-black text-slate-400 shadow-sm",children:"Loading forum..."}):v?e.jsxs("div",{className:"rounded-[28px] border border-red-200 bg-red-50 p-10 text-center",children:[e.jsx("h2",{className:"text-xl font-black text-slate-950",children:"Forum could not load"}),e.jsx("p",{className:"mt-2 text-sm text-red-700",children:v}),e.jsx("button",{onClick:()=>window.location.reload(),className:"mt-4 min-h-10 rounded-2xl bg-slate-950 px-4 text-xs font-black text-white",children:"Retry"})]}):t&&!n?e.jsxs("div",{className:"rounded-[28px] border border-slate-200 bg-white p-10 text-center shadow-sm",children:[e.jsx(Ce,{className:"mx-auto mb-3 h-8 w-8 text-slate-300"}),e.jsx("h2",{className:"text-xl font-black text-slate-950",children:"Thread not found"}),e.jsx("button",{onClick:()=>b("/forum"),className:"mt-4 min-h-10 rounded-2xl bg-slate-950 px-4 text-xs font-black text-white",children:"Browse Forum"})]}):t&&n?e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_320px]",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(re,{post:n,voted:L.has(n.id),onVote:X,user:r,onToggleComments:ge,onDeletePost:_e}),e.jsx(Ye,{post:n,user:r,comments:u,commentText:O,setCommentText:D,commentError:G,commentNotice:S,commentSaving:pe,onSubmit:be,onDeleteComment:fe})]}),e.jsxs("aside",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-[24px] border border-slate-200 bg-white p-4 shadow-sm",children:[e.jsx("h2",{className:"text-sm font-black text-slate-950",children:"Related posts"}),e.jsx("div",{className:"mt-3 space-y-2",children:R.length===0?e.jsx("p",{className:"text-xs font-semibold leading-5 text-slate-400",children:"More music threads will appear here as the forum grows."}):R.map(s=>e.jsxs("button",{onClick:()=>b(`/forum/${s.slug}`),className:"block w-full rounded-2xl border border-slate-100 bg-slate-50 p-3 text-left transition hover:border-emerald-200 hover:bg-white",children:[e.jsx("p",{className:"line-clamp-2 text-sm font-black leading-5 text-slate-900",children:s.title}),e.jsxs("p",{className:"mt-1 text-[10px] font-bold text-slate-400",children:[s.upvotes_count||0," likes · ",s.views_count||0," views"]})]},s.id))})]}),e.jsxs("div",{className:"rounded-[24px] border border-emerald-100 bg-emerald-50 p-4",children:[e.jsx("h2",{className:"text-sm font-black text-slate-950",children:"Forum signal"}),e.jsx("p",{className:"mt-2 text-xs font-semibold leading-6 text-slate-600",children:"Useful music questions, creator drops, and lyric feedback pages help new people discover Melody Genie from search."})]})]})]}):o.map(s=>e.jsx(re,{post:s,voted:L.has(s.id),onVote:X,compact:!t,user:r},s.id))}),!t&&!g&&C>P&&e.jsxs("nav",{className:"mt-6 flex items-center justify-center gap-1.5","aria-label":"Forum pages",children:[e.jsxs("button",{type:"button",disabled:_<=1,onClick:()=>{j(_-1),window.scrollTo({top:0,behavior:"smooth"})},className:"inline-flex min-h-9 items-center gap-1 rounded-full border border-ink-900/10 bg-white/85 px-4 text-xs font-bold tracking-tight text-ink-500 shadow-[inset_0_1px_0_rgba(255,255,255,0.8)] backdrop-blur transition hover:text-ink-900 disabled:cursor-not-allowed disabled:opacity-40",children:[e.jsx(U,{className:"h-3 w-3"})," Prev"]}),Array.from({length:Math.ceil(C/P)},(s,i)=>i+1).filter(s=>{const i=Math.ceil(C/P);return s===1||s===i||Math.abs(s-_)<=1}).map((s,i,l)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[i>0&&l[i-1]!==s-1&&e.jsx("span",{className:"text-xs font-bold text-ink-300",children:"â¦"}),e.jsx("button",{type:"button",onClick:()=>{j(s),window.scrollTo({top:0,behavior:"smooth"})},"aria-current":_===s?"page":void 0,className:`inline-flex h-9 w-9 items-center justify-center rounded-full text-xs font-bold tracking-tight transition ${_===s?"bg-forest text-forest-ink shadow-[0_6px_16px_-6px_rgba(15,46,36,0.45)]":"border border-ink-900/10 bg-white/85 text-ink-500 hover:text-ink-900"}`,children:s})]},s)),e.jsxs("button",{type:"button",disabled:_>=Math.ceil(C/P),onClick:()=>{j(_+1),window.scrollTo({top:0,behavior:"smooth"})},className:"inline-flex min-h-9 items-center gap-1 rounded-full border border-ink-900/10 bg-white/85 px-4 text-xs font-bold tracking-tight text-ink-500 shadow-[inset_0_1px_0_rgba(255,255,255,0.8)] backdrop-blur transition hover:text-ink-900 disabled:cursor-not-allowed disabled:opacity-40",children:["Next ",e.jsx(U,{className:"h-3 w-3 rotate-180"})]})]}),!t&&e.jsx("section",{className:"mt-6 rounded-[28px] border border-slate-200 bg-white p-5 shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ee,{className:"mt-0.5 h-5 w-5 text-emerald-600"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-black text-slate-950",children:"Why Forum helps Melody Genie rank"}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-slate-600",children:"Every public thread is a crawlable page around real music questions, videos, creator profiles, lyrics, and production notes. Useful threads become long-tail acquisition pages."})]})]})})]})]})}export{lt 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.