1import{r as e,j as t}from"./vendor-react-BfgFmtGS.js";import{MainLayout as s}from"./MainLayout-B-JwvN1-.js";import{PageHeader as r}from"./PageHeader-BnvONm3p.js";import{a,u as o}from"./useAuth-DynbexoK.js";import{supabase as i}from"./supabase-client-2CObC91N.js";import{B as d}from"./button-CYJdLL_L.js";import{I as l}from"./input-Cv-gXlbe.js";import{T as n}from"./textarea-DHiKxIHY.js";import{a as c}from"./runtime-utils-GN4cODRt.js";import{w as u}from"./dbMetrics-D5Q8D3iF.js";import{C as m}from"./chevron-up-BtWriVc7.js";import{P as p}from"./plus-O3w64FuI.js";import{L as x}from"./loader-circle-fXsKc0TP.js";import{A as f}from"./arrow-right-Dak2rshg.js";import{S as h}from"./search-D_LVchoc.js";import{P as g}from"./panels-top-left-BHGx6Njw.js";import{M as b}from"./message-square-B-K6T96l.js";import{f as j}from"./vendor-date-CJZoUMEw.js";import{C as v}from"./circle-x-A3821ztC.js";import{c as w}from"./createLucideIcon-D9HkCDkl.js";import{C as N}from"./clock-BF-8ZufU.js";import{C as y}from"./circle-check-DpwBxCoL.js";const _=w("CirclePlay",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polygon",{points:"10 8 16 12 10 16 10 8",key:"1cimsy"}]]);function q(){const{user:w,isAuthenticated:q}=a(),{toast:C}=o(),[S,k]=e.useState([]),[L,P]=e.useState(!0),[A,E]=e.useState(""),[F,R]=e.useState(!1),[B,D]=e.useState(!1),[I,M]=e.useState({title:"",description:""}),[Y,H]=e.useState("all"),[O,T]=e.useState(0),[z,K]=e.useState(!0),[U,V]=e.useState(!1);e.useEffect(()=>{T(0),W(0,!1)},[null==w?void 0:w.id,Y]);const W=async(e=0,t=!1)=>{try{t?V(!0):P(!0);let s=i.from("feature_requests").select("id, title, description, status, user_id, created_at");"all"!==Y&&(s=s.eq("status",Y));const r=50*e,a=r+50-1;let o=i.from("feature_requests").select("id",{count:"exact",head:!0});"all"!==Y&&(o=o.eq("status",Y));const[{data:d,error:l},n]=await u("feature_requests_page",()=>Promise.all([s.order("created_at",{ascending:!1}).range(r,a),o]));if(l)throw l;const c=(d||[]).map(e=>e.id),{data:m,error:p}=await u("feature_votes_page",()=>i.from("feature_votes").select("request_id, user_id").in("request_id",c));if(p)throw p;const x=(d||[]).map(e=>{const t=(null==m?void 0:m.filter(t=>t.request_id===e.id))||[];return{...e,status:["pending","in-review","planned","in-progress","completed","declined"].includes(e.status)?e.status:"pending",vote_count:t.length,has_voted:!!(null==m?void 0:m.find(t=>t.request_id===e.id&&t.user_id===(null==w?void 0:w.id)))}});x.sort((e,t)=>t.vote_count-e.vote_count),k(e=>t?[...e,...x]:x),T(e);const f=(null==n?void 0:n.count)||0;K(a+1<f)}catch(s){C({title:"Error",description:"Failed to load requests",variant:"error"})}finally{P(!1),V(!1)}},G=e=>{switch(e){case"completed":return t.jsx(y,{className:"w-3.5 h-3.5 text-success"});case"planned":return t.jsx(N,{className:"w-3.5 h-3.5 text-primary"});case"in-progress":return t.jsx(_,{className:"w-3.5 h-3.5 text-amber-500"});case"declined":return t.jsx(v,{className:"w-3.5 h-3.5 text-destructive"});case"in-review":return t.jsx(h,{className:"w-3.5 h-3.5 text-blue-500"});default:return t.jsx(b,{className:"w-3.5 h-3.5 text-muted-foreground"})}},J=S.filter(e=>e.title.toLowerCase().includes(A.toLowerCase())||e.description.toLowerCase().includes(A.toLowerCase()));return t.jsx(s,{children:t.jsxs("div",{className:"max-w-4xl mx-auto p-6 space-y-8 pb-32",children:[t.jsxs("div",{className:"flex flex-col md:flex-row md:items-end justify-between gap-6",children:[t.jsx(r,{title:"Feature Requests",description:"Help us shape the future of Echo. Suggest new ideas and upvote your favorites."}),t.jsxs(d,{onClick:()=>D(!B),className:"rounded-2xl h-12 px-6 bg-primary hover:bg-primary/90 font-bold gap-2 self-start md:self-auto",children:[B?t.jsx(m,{className:"w-4 h-4"}):t.jsx(p,{className:"w-4 h-4"}),B?"Cancel":"Submit New Post"]})]}),B&&t.jsx("div",{className:"bg-card border border-border/50 rounded-[2rem] p-8 shadow-float animate-in fade-in slide-in-from-top-4 duration-500",children:t.jsxs("form",{onSubmit:async e=>{if(e.preventDefault(),I.title.trim()){R(!0);try{const{error:e}=await i.from("feature_requests").insert([{...I,user_id:null==w?void 0:w.id}]);if(e)throw e;C({title:"Success!",description:"Your feature request has been posted."}),M({title:"",description:""}),D(!1),W()}catch(t){C({title:"Post failed",description:t.message,variant:"error"})}finally{R(!1)}}},className:"space-y-6",children:[t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground ml-1",children:"Title"}),t.jsx(l,{placeholder:"Briefly describe what you'd like to see...",value:I.title,onChange:e=>M({...I,title:e.target.value}),className:"bg-muted/30 border-none rounded-2xl h-14 text-lg font-medium px-6"})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground ml-1",children:"Description"}
1),t.jsx(n,{placeholder:"Add more details about how it should work...",value:I.description,onChange:e=>M({...I,description:e.target.value}),className:"bg-muted/30 border-none rounded-2xl min-h-[150px] resize-none px-6 py-4"})]}),t.jsxs(d,{type:"submit",disabled:F||!I.title,className:"w-full h-14 rounded-2xl bg-primary hover:bg-primary/90 font-bold text-lg gap-2",children:[F?t.jsx(x,{className:"w-5 h-5 animate-spin"}):t.jsx(f,{className:"w-5 h-5"}),"Post Request"]})]})}),t.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[t.jsxs("div",{className:"relative flex-1 group",children:[t.jsx(h,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground transition-colors group-focus-within:text-primary"}),t.jsx(l,{placeholder:"Search for requests...",value:A,onChange:e=>E(e.target.value),className:"bg-card border-border/50 rounded-2xl h-12 pl-11 pr-4 shadow-soft"})]}),t.jsx("div",{className:"flex gap-2 overflow-x-auto pb-2 md:pb-0 scrollbar-hide",children:["all","planned","in-progress","completed"].map(e=>t.jsx("button",{onClick:()=>H(e),className:c("px-4 py-2 rounded-xl text-xs font-bold whitespace-nowrap transition-all border",Y===e?"bg-primary border-primary text-white shadow-glow":"bg-card border-border/50 text-muted-foreground hover:bg-muted/50"),children:e.charAt(0).toUpperCase()+e.slice(1).replace("-"," ")},e))})]}),t.jsx("div",{className:"space-y-4",children:L?t.jsxs("div",{className:"py-20 flex flex-col items-center gap-4 text-muted-foreground",children:[t.jsx(x,{className:"w-10 h-10 animate-spin opacity-20"}),t.jsx("p",{className:"text-sm font-medium",children:"Crunching the data..."})]}):0===J.length?t.jsxs("div",{className:"py-20 text-center space-y-4",children:[t.jsx("div",{className:"p-6 rounded-full bg-muted/20 w-fit mx-auto",children:t.jsx(g,{className:"w-12 h-12 text-muted-foreground/30"})}),t.jsx("h3",{className:"text-xl font-bold",children:"No requests found"}),t.jsx("p",{className:"text-muted-foreground max-w-xs mx-auto text-sm",children:"Be the first to suggest something new for the future of Echo."})]}):t.jsxs(t.Fragment,{children:[J.map(e=>t.jsxs("div",{className:"group flex gap-6 bg-card border border-border/50 rounded-3xl p-6 shadow-soft hover:shadow-float transition-all hover:scale-[1.01]",children:[t.jsxs("button",{onClick:()=>(async(e,t)=>{if(q)try{if(t){const{error:t}=await i.from("feature_votes").delete().eq("request_id",e).eq("user_id",null==w?void 0:w.id);if(t)throw t}else{const{error:t}=await i.from("feature_votes").insert([{request_id:e,user_id:null==w?void 0:w.id}]);if(t)throw t}W()}catch(s){C({title:"Vote failed",description:s.message,variant:"error"})}else C({title:"Sign in required",description:"Please log in to upvote features."})})(e.id,e.has_voted),className:c("flex flex-col items-center justify-center w-14 h-20 rounded-2xl border transition-all",e.has_voted?"bg-primary/10 border-primary/30 text-primary shadow-soft":"bg-muted/30 border-transparent text-muted-foreground hover:bg-muted/50 hover:border-border/50"),children:[t.jsx(m,{className:c("w-6 h-6 transition-transform",e.has_voted&&"animate-bounce")}),t.jsx("span",{className:"text-sm font-bold mt-1",children:e.vote_count})]}),t.jsxs("div",{className:"flex-1 space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("h3",{className:"text-lg font-bold text-foreground group-hover:text-primary transition-colors",children:e.title}),t.jsxs("div",{className:c("flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-bold uppercase tracking-wider","completed"===e.status&&"bg-success/10 text-success border border-success/20","planned"===e.status&&"bg-primary/10 text-primary border border-primary/20","in-progress"===e.status&&"bg-amber-500/10 text-amber-500 border border-amber-500/20","in-review"===e.status&&"bg-blue-500/10 text-blue-500 border border-blue-500/20","declined"===e.status&&"bg-destructive/10 text-destructive border border-destructive/20","pending"===e.status&&"bg-muted/50 text-muted-foreground border border-border/50"),children:[G(e.status),e.status.replace("-"," ")]})]}),t.jsx("p",{className:"text-muted-foreground text-[13px] leading-relaxed line-clamp-3",children:e.description})]}),t.jsxs("div",{className:"flex items-center gap-4 text-[11px] font-medium text-muted-foreground pt-1",children:[t.jsxs("div",{className:"flex items-center gap-1.5 bg-muted/30 px-2 py-1 rounded-lg",children:[t.jsx(b,{className:"w-3.5 h-3.5"}),t.jsx("span",{children:"Feature Request"})]}),t.jsx("span",{children:"â¢"}),t.jsx("span",{children:j(new Date(e.created_at),{addSuffix:!0})})]})]})]},e.id)),z&&t.jsx("div",{className:"pt-2",children:t.jsx(d,{variant:"outline",className:"w-full rounded-2xl",onClick:()=>
1W(O+1,!0),disabled:U,children:U?"Loadingâ¦":"Load more requests"})})]})})]})})}export{q 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.