1import{j as e}from"./ui-core-DEHpBUmL.js";import{r as x}from"./react-vendor-D7O0s2RJ.js";import{A as D}from"./AppLayout-CJRjLLEx.js";import{u as v,b as B,c as M}from"./query-CfEavOJr.js";import{c as P,s as h,u as Q,L as A}from"./index-DuGElqdX.js";import{P as E,C as K,a as L,A as z}from"./AssetDetailSheet-BvJOEu-5.js";import{C as R}from"./CreatePostDialog-Dsg_BZr5.js";import{B as y}from"./button-D44ZxqjE.js";import{B as U}from"./alert-dialog-CbjmaYHC.js";import{c as f}from"./utils-CYEZs_Ov.js";import{Z as N}from"./zap-PCcNaFwl.js";import{X as Z}from"./x-BueX9NmG.js";import{B as q}from"./BottomNavigation-B5JBeg27.js";import{P as j}from"./plus-2GQOD5Kt.js";import{T as X}from"./dropdown-menu-BiVW9EQD.js";import"./StackedLogo-BmOzNVaP.js";import"./router-XIi5lS70.js";import"./avatar-CYmdTALx.js";import"./menu-CCkFoYeQ.js";import"./layout-dashboard-Cs9dSoED.js";import"./package-DMmJG_MY.js";import"./vault-BrJD73iq.js";import"./chart-column-CeO3dV3i.js";import"./sheet-NOm2zPm8.js";import"./supabase-Bp5Zm6xC.js";import"./input-BpWbQ41b.js";import"./send-DzJrwbA8.js";import"./dialog-U76Vm26x.js";import"./trash-2-pPihq4oX.js";import"./trending-up-8twQhD5J.js";import"./trending-down-BdJ4-13e.js";import"./dollar-sign-BokwCqsL.js";import"./textarea-B_pYfprA.js";import"./label-DFYXCCVq.js";import"./useCreatePost-CBPiqisk.js";import"./arrow-left-B98utZvR.js";import"./arrow-right-BTM3o_Cf.js";import"./charts-DZ3tuanS.js";import"./house-zS_IS9YV.js";import"./user-DdyzQdqL.js";import"./chevron-right-DjzViJgm.js";import"./check-Di371o6N.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 G=P("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/** 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 F=P("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"}]]);async function H(t){let s=h.from("posts").select("*");t==="for-sale"&&(s=s.eq("is_for_sale",!0)),t==="trending"?s=s.limit(100):s=s.order("created_at",{ascending:!1}).limit(50);const{data:n,error:r}=await s;if(r)throw r;if(!n||n.length===0)return[];const d=[...new Set(n.map(o=>o.user_id))],{data:i}=await h.from("users").select("id, first_name, last_name, handle, username, profile_image_url").in("id",d),c=new Map(i?.map(o=>[o.id,o])||[]);let a=n.map(o=>({...o,author:c.get(o.user_id)||null}));return t==="trending"&&(a.sort((o,u)=>u.like_count+u.comment_count+u.save_count-(o.like_count+o.comment_count+o.save_count)),a=a.slice(0,50)),a}function J(t){return v({queryKey:["vault-feed",t],queryFn:()=>H(t),staleTime:3e4})}function W(t){return t==null?null:t>=1e6?`$${(t/1e6).toFixed(1)}M`:t>=1e3?`$${(t/1e3).toFixed(1)}K`:`$${t.toFixed(0)}`}function S(t){const s=new Date(t).getTime()-Date.now();if(s<=0)return"Expired";const n=Math.floor(s/36e5),r=Math.floor(s%36e5/6e4);return n>0?`${n}h ${r}m left`:`${r}m left`}function T({question:t,vote:s,onVote:n,isSubmitting:r}){const[d,i]=x.useState(()=>S(t.ends_at)),c=!!s,a=t.vote_count_a+t.vote_count_b,o=a>0?Math.round(t.vote_count_a/a*100):50,u=100-o;return x.useEffect(()=>{const l=setInterval(()=>i(S(t.ends_at)),6e4);return()=>clearInterval(l)},[t.ends_at]),e.jsxs("div",{className:"bg-card border border-border rounded-xl overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 pb-2",children:[t.asset_image_url?e.jsx("img",{src:t.asset_image_url,alt:t.asset_name,className:"h-12 w-12 rounded-lg object-cover border border-border"}):e.jsx("div",{className:"h-12 w-12 rounded-lg bg-muted flex items-center justify-center text-muted-foreground text-lg font-bold",children:t.asset_name[0]?.toUpperCase()||"A"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:t.asset_name}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.asset_type&&e.jsx(U,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:t.asset_type}),t.asset_value!=null&&e.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:W(t.asset_value)}),t.asset_change_percent!=null&&e.jsxs("span",{className:f("text-xs font-medium",t.asset_change_percent>=0?"text-green-600":"text-red-500"),children:[t.asset_change_percent>=0?"+":"",t.asset_change_percent.toFixed(1),"%"]})]})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground font-mono shrink-0",children:d})]}),e.jsx("p",{className:"px-4 py-2 text-sm font-medium text-foreground",children:t.question_text}),e.jsx("div",{className:"px-4 pb-4 space-y-2",children:c?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"relative h-10 rounded-lg overflow-hidden bg-muted border border-border",children:[e.jsx("div",{className:f("absolute inset-y-0 left-0 transition-all duration-700 rounded-lg",s.selected_option==="a"?"bg-primary/20":"bg-muted"),style:{width:`${o}%`}}),e.jsxs("div",{className:"relative flex items-center justify-between px-3 h-full",children:[e.jsxs("span",{className:f("text-xs font-semibold",s.selected_option==="a"?"text-primary":"text-muted-foreground"),children:[t.option_a," ",s.selected_option==="a"&&"â"]}),e.jsxs("span",{className:"text-xs font-bold text-foreground",children:[o,"%"]})]})]}),e.jsxs("div",{className:"relative h-10 rounded-lg overflow-hidden bg-muted border border-border",children:[e.jsx("div",{className:f("absolute inset-y-0 left-0 transition-all duration-700 rounded-lg",s.selected_option==="b"?"bg-destructive/20":"bg-muted"),style:{width:`${u}%`}}),e.jsxs("div",{className:"relative flex items-center justify-between px-3 h-full",children:[e.jsxs("span",{className:f("text-xs font-semibold",s.selected_option==="b"?"text-destructive":"text-muted-foreground"),children:[t.option_b," ",s.selected_option==="b"&&"â"]}),e.jsxs("span",{className:"text-xs font-bold text-foreground",children:[u,"%"]})]})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground text-center",children:[a," vote",a!==1?"s":""]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{disabled:r,onClick:()=>n(t.id,"a"),className:"flex-1 min-h-[52px] rounded-lg bg-primary/10 hover:bg-primary/20 border border-primary/20 text-primary font-semibold text-sm transition-all active:scale-[0.98] disabled:opacity-50",children:t.option_a}),e.jsx("button",{disabled:r,onClick:()=>n(t.id,"b"),className:"flex-1 min-h-[52px] rounded-lg bg-destructive/10 hover:bg-destructive/20 border border-destructive/20 text-destructive font-semibold text-sm transition-all active:scale-[0.98] disabled:opacity-50",children:t.option_b})]})})]})}function _(){return v({queryKey:["signal-questions-active"],queryFn:async()=>{const t=new Date().toISOString(),{data:s,error:n}=await h.from("signal_questions").select("*").eq("is_active",!0).gt("ends_at",t).order("starts_at",{ascending:!0}).limit(5);if(n)throw n;return s||[]},staleTime:3e4})}function w(t){const{user:s}=Q();return v({queryKey:["signal-votes",s?.id,t],queryFn:async()=>
11{if(!s||t.length===0)return[];const{data:n,error:r}=await h.from("signal_votes").select("*").eq("user_id",s.id).in("question_id",t);if(r)throw r;return n||[]},enabled:!!s&&t.length>0,staleTime:3e4})}function V(){const t=B();return M({mutationFn:async({questionId:s,selectedOption:n})=>{const{data:r,error:d}=await h.rpc("submit_signal_vote",{p_question_id:s,p_selected_option:n});if(d)throw d;return r},onSuccess:()=>{t.invalidateQueries({queryKey:["signal-questions-active"]}),t.invalidateQueries({queryKey:["signal-votes"]})}})}function Y(){const{data:t=[]}=_(),s=t.map(a=>a.id),{data:n=[]}=w(s),r=new Set(n.map(a=>a.question_id)),d=t.length>0&&t.every(a=>r.has(a.id)),i=t.length>0,c=t.filter(a=>!r.has(a.id)).length;return{questions:t,votes:n,votedIds:r,hasCompletedAll:d,hasActiveQuestions:i,remainingCount:c}}function ee({open:t,onClose:s,onComplete:n}){const{data:r=[]}=_(),d=r.map(l=>l.id),{data:i=[]}=w(d),c=V(),a=new Set(i.map(l=>l.question_id)),o=r.slice(0,3),u=o.length>0&&o.every(l=>a.has(l.id));return x.useEffect(()=>{if(u){const l=setTimeout(n,600);return()=>clearTimeout(l)}},[u,n]),t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm",children:e.jsxs("div",{className:"w-full max-w-md mx-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-5 w-5 text-primary"}),e.jsx("h2",{className:"text-lg font-bold text-foreground",children:"Signals"})]}),e.jsx(y,{variant:"ghost",size:"icon",onClick:s,className:"h-8 w-8",children:e.jsx(Z,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-5",children:"Today's community market read."}),e.jsx("div",{className:"space-y-3",children:o.map(l=>e.jsx(T,{question:l,vote:i.find(p=>p.question_id===l.id),onVote:(p,g)=>c.mutate({questionId:p,selectedOption:g}),isSubmitting:c.isPending},l.id))}),!u&&e.jsx("button",{onClick:s,className:"w-full mt-4 text-sm text-muted-foreground hover:text-foreground transition-colors py-2",children:"Skip for now"})]})}):null}function te(){const{data:t=[],isLoading:s}=_(),n=t.map(i=>i.id),{data:r=[]}=w(n),d=V();return s?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):t.length===0?e.jsxs("div",{className:"text-center py-20 space-y-3",children:[e.jsx("div",{className:"h-16 w-16 mx-auto rounded-full bg-muted flex items-center justify-center",children:e.jsx(N,{className:"h-7 w-7 text-muted-foreground"})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"No active signals"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-xs mx-auto",children:"New signals are published daily. Check back soon."})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Today's community market read."}),t.map(i=>e.jsx(T,{question:i,vote:r.find(c=>c.question_id===i.id),onVote:(c,a)=>d.mutate({questionId:c,selectedOption:a}),isSubmitting:d.isPending},i.id))]})}const se=[{key:"signals",label:"Signals",icon:N},{key:"trending",label:"Trending",icon:F},{key:"recent",label:"Recent",icon:G},{key:"for-sale",label:"For Sale",icon:X}];function Ue(){const[t,s]=x.useState("trending"),{data:n=[],isLoading:r}=J(t),[d,i]=x.useState(!1),[c,a]=x.useState(null),[o,u]=x.useState(null),[l,p]=x.useState(null),[g,b]=x.useState(!1),{hasActiveQuestions:C,hasCompletedAll:k}=Y();x.useEffect(()=>
11{C&&!k&&b(!0)},[C,k]);const I=x.useCallback(()=>{b(!1),s("trending")},[]),O=x.useCallback(()=>{b(!1)},[]),$=t!=="signals";return e.jsxs(D,{children:[e.jsxs("div",{className:"max-w-lg mx-auto px-4 py-4 pb-24 md:pb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"text-xl font-bold text-foreground",children:"Vault"}),e.jsxs(y,{size:"sm",onClick:()=>i(!0),className:"gap-1.5",children:[e.jsx(j,{className:"h-4 w-4"})," Post"]})]}),e.jsx("div",{className:"flex gap-1 bg-muted/50 rounded-lg p-1 mb-5",children:se.map(m=>e.jsxs("button",{onClick:()=>s(m.key),className:f("flex-1 flex items-center justify-center gap-1.5 py-2 rounded-md text-sm font-medium transition-all",t===m.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:[e.jsx(m.icon,{className:"h-3.5 w-3.5"}),m.label]},m.key))}),t==="signals"&&e.jsx(te,{}),$&&e.jsx(e.Fragment,{children:r?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(A,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n.length===0?e.jsxs("div",{className:"text-center py-20 space-y-3",children:[e.jsx("div",{className:"h-16 w-16 mx-auto rounded-full bg-muted flex items-center justify-center",children:e.jsx(F,{className:"h-7 w-7 text-muted-foreground"})}),e.jsx("h3",{className:"text-lg font-semibold text-foreground",children:"No posts yet"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-xs mx-auto",children:"Be the first to share an asset in the Vault."}),e.jsxs(y,{onClick:()=>i(!0),className:"mt-2 gap-1.5",children:[e.jsx(j,{className:"h-4 w-4"})," Create Post"]})]}):e.jsx("div",{className:"space-y-4",children:n.map(m=>e.jsx(E,{post:m,onCommentClick:a,onPostClick:u,onAssetClick:p},m.id))})})]}),e.jsx("button",{onClick:()=>i(!0),className:"fixed bottom-20 right-4 md:hidden h-14 w-14 rounded-full bg-primary text-primary-foreground shadow-lg flex items-center justify-center z-40",children:e.jsx(j,{className:"h-6 w-6"})}),e.jsx(ee,{open:g,onClose:O,onComplete:I}),e.jsx(R,{open:d,onOpenChange:i}),e.jsx(K,{postId:c,open:c!==null,onOpenChange:m=>!m&&a(null)}),e.jsx(L,{post:o,open:o!==null,onOpenChange:m=>!m&&u(null),onCommentClick:a}),e.jsx(z,{post:l,open:l!==null,onOpenChange:m=>!m&&p(null)}),e.jsx(q,{})]})}export{Ue 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.