1import{j as e}from"./radix-vendor-jJEH7Opp.js";import{u as se,s as h,a_ as L,al as v,ao as te,ap as re,z as ae,F as ne,G as le,I as oe,B as D,C as ce,b as $,c as R,d as I,aj as w,j as ie,H as de,ay as me}from"./index-BbaQI6wv.js";import{r as n,j as xe,L as U,d as ue}from"./react-vendor-DavDn-3-.js";import{B as P}from"./badge-B-F-NJvr.js";import{P as pe}from"./PageLoader-BX2ITfe0.js";import{E as he}from"./EditPriceCheckDialog-DUF6WInp.js";import{T as S}from"./thumbs-up-DWscXjEG.js";import{T as M}from"./thumbs-down-BgyQaajv.js";import{E as fe}from"./eye-HovhrcRn.js";import{P as ge}from"./pencil-CnYHJD5x.js";import{T as be}from"./trash-2-CZzoNV4H.js";import"./supabase-vendor-ZaDmUqc0.js";import"./input-D7-aDAe7.js";import"./textarea-DQ3S4qXL.js";import"./label-Ke7BZdlL.js";import"./listings-DVfK52_X.js";import"./CategorySpecsStep-BR7TuMtL.js";import"./chevron-left-BTL2Q5D8.js";import"./calendar-CVjrC9sq.js";const E=d=>{const c=Date.now()-new Date(d).getTime(),x=Math.floor(c/6e4);if(x<1)return"just now";if(x<60)return`${x}m ago`;const f=Math.floor(x/60);if(f<24)return`${f}h ago`;const m=Math.floor(f/24);return m<7?`${m}d ago`:`${Math.floor(m/7)}w ago`},z={open:{label:"Open",cls:"bg-emerald-600 text-white"},closed:{label:"Closed",cls:"bg-muted text-muted-foreground"},removed:{label:"Removed",cls:"bg-muted text-muted-foreground"}},je=()=>{const{user:d}=se(),[c,x]=n.useState([]),[f,m]=n.useState(!0),[i,u]=n.useState(null),[y,k]=n.useState(null),[H,j]=n.useState(null),[g,O]=n.useState("all"),[_,T]=xe(),[G,K]=n.useState({}),[Q,V]=n.useState({}),[q,J]=n.useState({}),[A,B]=n.useState(!1),b=n.useCallback(async()=>{if(!d){m(!1);return}m(!0);const{data:s}=await h.from("price_checks").select("*").eq("user_id",d.id).neq("status","removed").order("created_at",{ascending:!1});x(s??[]),m(!1)},[d]);n.useEffect(()=>{b()},[b]),n.useEffect(()=>{const s=_.get("manage");if(s&&c.some(a=>a.id===s)){u(s);const a=new URLSearchParams(_);a.delete("manage"),T(a,{replace:!0})}},[c,_,T]),n.useEffect(()=>{if(!i)return;let s=!1;return(async()=>{B(!0);const[{data:a},{data:l}]=await Promise.all([h.from("price_check_suggestions").select("*").eq("price_check_id",i).order("up_count",{ascending:!1}).order("created_at",{ascending:!1}),h.from("price_check_comments").select("*").eq("price_check_id",i).is("removed_at",null).order("like_count",{ascending:!1}).order("created_at",{ascending:!1})]),p=a??[],r=l??[],t=Array.from(new Set([...p.map(o=>o.user_id),...r.map(o=>o.user_id)])),N={};if(t.length){const{data:o}=await h.from("profiles").select("user_id, display_name, avatar_url").in("user_id",t);(o??[]).forEach(ee=>{const C=ee;N[C.user_id]={name:C.display_name||"Community member",avatar:C.avatar_url??void 0}})}s||(K(o=>({...o,[i]:p})),V(o=>({...o,[i]:r})),J(o=>({...o,...N})),B(!1))})(),()=>{s=!0}},[i]);const W=async s=>{const{error:a}=await h.from("price_checks").update({status:"removed"}).eq("id",s);if(a){w.error("Failed to delete");return}w.success("Price Check removed"),j(null),u(null),b()},X=async(s,a)=>{const l=a==="closed"?"open":"closed",{error:p}=await h.from("price_checks").update({status:l}).eq("id",s);if(p){w.error(l==="closed"?"Failed to archive":"Failed to reopen");return}w.success(l==="closed"?"Price Check archived":"Price Check reopened"),b()},Y={all:c.length,open:c.filter(s=>s.status==="open").length,archived:c.filter(s=>s.status==="closed").length},F=c.filter(s=>g==="open"?s.status==="open":g==="archived"?s.status==="closed":!0),Z=["all","open","archived"];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between pb-3 gap-2",children:[e.jsx("div",{className:"flex gap-1.5 overflow-x-auto scrollbar-none",children:Z.map(s=>e.jsxs("button",{onClick:()=>O(s),className:`flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-semibold transition-colors ${g===s?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground hover:text-foreground"}`,children:[s.charAt(0).toUpperCase()+s.slice(1),e.jsx("span",{className:"ml-1 text-[10px] opacity-70",children:Y[s]})]},s))}),e.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[c.length," total"]})]}),e.jsx("div",{className:"space-y-3 pb-8",children:f?e.jsx(pe,{label:"Loading your price checksâ¦"}):F.length===0?e.jsxs("div",{className:"text-center py-16",children:[e.jsx(L,{className:"w-12 h-12 text-muted-foreground
1/30 mx-auto mb-3"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:g==="all"?"No price checks yet":`No ${g} price checks`}),e.jsx(U,{to:"/price-check/new",className:"mt-3 inline-block text-sm font-semibold text-primary hover:underline",children:"Post Price Check"})]}):F.map(s=>{const a=z[s.status]??z.open,l=s.comment_count??0;return e.jsx("div",{className:"bg-card rounded-xl border border-border shadow-sm transition-colors",children:e.jsxs("button",{type:"button",onClick:()=>u(s.id),className:"w-full text-left p-4 hover:bg-muted/30 transition-colors rounded-xl",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(P,{className:`text-[9px] font-bold px-1.5 py-0 h-4 ${a.cls}`,children:a.label}),e.jsx(P,{variant:"outline",className:"text-[9px] font-medium px-1.5 py-0 h-4",children:s.category}),e.jsxs(P,{className:"bg-primary/10 text-primary text-[9px] font-bold px-1.5 py-0 h-4 border-primary/20",children:[e.jsx(L,{className:"w-2.5 h-2.5 mr-0.5"})," Price Check"]})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:E(s.created_at)})]}),e.jsx("h3",{className:"font-heading font-bold text-sm text-card-foreground mt-2 leading-snug break-words",children:s.title}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2 break-words",children:s.description}),e.jsxs("div",{className:"flex items-center gap-3 mt-3 flex-wrap",children:[s.quoted_price!=null&&e.jsxs("span",{className:"text-xs font-bold text-primary",children:["Quoted ",v(Number(s.quoted_price))]}),s.location_text&&e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(te,{className:"w-2.5 h-2.5"})," ",s.location_text]})]}),e.jsxs("div",{className:"flex items-center justify-between mt-3 pt-3 border-t border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-[10px] flex items-center gap-1 text-muted-foreground",children:[e.jsx(re,{className:"w-3 h-3"})," ",l," thoughts"]}),e.jsxs("span",{className:"text-[10px] flex items-center gap-1 text-muted-foreground",children:[e.jsx(S,{className:"w-3 h-3"})," ",s.quote_up_count??0]}),e.jsxs("span",{className:"text-[10px] flex items-center gap-1 text-muted-foreground",children:[e.jsx(M,{className:"w-3 h-3"})," ",s.quote_down_count??0]})]}),e.jsx("span",{className:"text-[10px] font-semibold text-primary",children:"Manage"})]})]})},s.id)})}),e.jsx(ae,{open:!!i,onOpenChange:s=>{s||(u(null),j(null))},children:e.jsx(ne,{side:"bottom",className:"rounded-t-2xl max-h-[85vh] overflow-y-auto",children:(()=>{const s=c.find(r=>r.id===i);if(!s)return null;const a=G[s.id]??[],l=Q[s.id]??[],p=H===s.id;return e.jsxs(e.Fragment,{children:[e.jsx(le,{children:e.jsx(oe,{className:"text-base pr-6 line-clamp-2 break-words text-left",children:s.title})}),p?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-foreground",children:"Delete this Price Check? This can't be undone."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"outline",className:"flex-1",onClick:()=>j(null),children:"Cancel"}),e.jsx(D,{variant:"destructive",className:"flex-1",onClick:()=>W(s.id),children:"Delete"})]})]}):e.jsxs("div",{className:"flex flex-col gap-4 mt-2",children:[e.jsxs("div",{className:"order-2 space-y-1.5",children:[e.jsxs(U,{to:`/price-check/${s.id}`,onClick:()=>u(null),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-card border border-border hover:border-primary/40 hover:bg-muted/40 transition-colors",children:[e.jsx(fe,{className:"w-4 h-4 text-primary shrink-0"}),e.jsx("span",{className:"text-sm font-semibold text-foreground flex-1 text-left",children:"View"})]}),e.jsxs("button",{type:"button",onClick:()=>{u(null),k(s)},className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-card border border-border hover:border-primary/40 hover:bg-muted/40 transition-colors",children:[e.jsx(ge,{className:"w-4 h-4 text-blue-500 shrink-0"}),e.jsx("span",{className:"text-sm font-semibold text-foreground flex-1 text-left",children:"Edit"})]}),e.jsxs("button",{type:"button",onClick:()=>X(s.id,s.status),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-card border border-border hover:border-primary/40 hover:bg-muted/40 transition-colors",children:[e.jsx(ce,{className:"w-4 h-4 text-emerald-500 shrink-0"}),e.jsx("span",{className:"text-sm font-semibold text-foreground flex-1 text-left",children:s.status==="closed"?"Reopen":"Archive"})]}),e.jsxs("button",{type:"button",onClick:()=>j(s.id),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-card border border-destructive/30 hover:bg-destructive/5 transition-colors",children:[e.jsx(be,{className:"w-4 h-4 text-destructive shrink-0"}),e.jsx("span",{className:"text-sm font-semibold text-destructive flex-1 text-left",children:"Delete"})]})]}
1),e.jsxs("div",{className:"order-1 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide mb-2",children:[a.length," Suggested price",a.length!==1?"s":""]}),A&&a.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground italic",children:"Loadingâ¦"}):a.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground italic",children:"No price suggestions yet."}):e.jsx("div",{className:"space-y-2",children:a.map(r=>{const t=q[r.user_id],N=r.amount_min===r.amount_max?v(Number(r.amount_min)):`${v(Number(r.amount_min))} â ${v(Number(r.amount_max))}`;return e.jsxs("div",{className:"bg-muted/40 border border-border rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{className:"w-7 h-7 ring-1 ring-border",children:[t!=null&&t.avatar?e.jsx(R,{src:t.avatar,alt:t.name}):null,e.jsx(I,{className:"bg-primary/10 text-primary text-[10px] font-semibold",children:((t==null?void 0:t.name)??"M").slice(0,2).toUpperCase()})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-xs font-semibold text-foreground truncate",children:(t==null?void 0:t.name)??"Member"})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:E(r.created_at)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-bold text-primary",children:N}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(S,{className:"w-3 h-3"})," ",r.up_count]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(M,{className:"w-3 h-3"})," ",r.down_count]})]})]}),r.note&&e.jsx("p",{className:"text-xs text-muted-foreground leading-relaxed break-words",children:r.note})]},r.id)})})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide mb-2",children:[l.length," Thought",l.length!==1?"s":""]}),A&&l.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground italic",children:"Loadingâ¦"}):l.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground italic",children:"No thoughts yet."}):e.jsx("div",{className:"space-y-2",children:l.map(r=>{const t=q[r.user_id];return e.jsxs("div",{className:"bg-muted/40 border border-border rounded-xl p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{className:"w-7 h-7 ring-1 ring-border",children:[t!=null&&t.avatar?e.jsx(R,{src:t.avatar,alt:t.name}):null,e.jsx(I,{className:"bg-primary/10 text-primary text-[10px] font-semibold",children:((t==null?void 0:t.name)??"M").slice(0,2).toUpperCase()})]}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-xs font-semibold text-foreground truncate",children:(t==null?void 0:t.name)??"Member"})}),e.jsx("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:E(r.created_at)})]}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed break-words whitespace-pre-wrap",children:r.body}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground pt-1 border-t border-border",children:[e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(S,{className:"w-3 h-3"})," Fair ",r.like_count]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx(M,{className:"w-3 h-3"})," Unfair ",r.dislike_count]}),e.jsxs("span",{className:"flex items-center gap-0.5",children:["â Helpful ",r.helpful_count]})]})]},r.id)})})]})]})]})]})})()})}),y&&e.jsx(he,{open:!!y,onOpenChange:s=>{s||k(null)},priceCheck:y,onSaved:()=>{k(null),b()}})]})},Re=()=>{const d=ue();return ie({title:"My Price Checks | Breez",description:"Manage the Price Checks you've posted on Breez.",noindex:!0}),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(de,{}),e.jsx("div",{className:"bg-card border-b border-border",children:e.jsx("div",{className:"max-w-5xl mx-auto px-4 py-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("h1",{className:"font-heading font-extrabold text-xl text-foreground",children:"My Price Checks"})}),e.jsxs(D,{size:"sm",className:"gap-1.5 h-8",onClick:()=>d("/price-check/new"),children:[e.jsx(me,{className:"w-3.5 h-3.5"}),"Post Price Check"]})]})})}),e.jsx("div",{className:"max-w-5xl mx-auto px-4 py-5",children:e.jsx(je,{})})]})};export{Re 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.