1import{aB as T,aG as A,u as L,e as O,z as $,r as n,E as M,s as r,j as e,A as P,aC as N,aN as Q,ao as K,ap as R,aq as I,ar as B,as as u,at as _,K as F,au as V,g as U,L as G,t as J,J as Y,av as Z,T as H,ad as W,M as X,aL as v,a as ee,Y as se,a9 as te,Z as ae,Q as re,h as d,a6 as ie,ay as oe}from"./index-BOoZFuWa.js";import{C as w,E as le}from"./extend-expiry-sheet-C_V3fBHM.js";import{C as ne}from"./clock-5RgofYM8.js";function me(){const{id:t}=T({from:"/app/posts/$id"}),{from:x}=A({from:"/app/posts/$id"}),{user:i}=L();O();const o=$(),[C,f]=n.useState(!1),[k,c]=n.useState(!1),[z,h]=n.useState(!1),[S,j]=n.useState(!1),{data:s,isLoading:g}=M({queryKey:["post",t],queryFn:async()=>{const{data:a}=await r.from("posts").select("id,user_id,caption,media_url,media_urls,blurhash,blurhashes,media_type,thumbnail_url,location_label,price_cents,is_portfolio,created_at,expires_at").eq("id",t).maybeSingle();if(!a)return null;const{data:l}=await r.from("profiles").select("id,display_name,handle,avatar_url").eq("id",a.user_id).maybeSingle(),{count:q}=await r.from("post_comments").select("id",{count:"exact",head:!0}).eq("post_id",t);return{post:a,profile:l,commentCount:q??0}}});async function E(){if(!s?.post||!await re({title:s.post.is_portfolio?"Delete this offer?":"Delete this service?",message:"This can't be undone.",confirmLabel:"Delete",danger:!0}))return;const{error:a}=await r.rpc("soft_delete_post",{_post_id:s.post.id});if(a)return d.error(a.message);d.success("Post deleted"),o.invalidateQueries({queryKey:["feed"]}),o.invalidateQueries({queryKey:["user-posts"]}),o.invalidateQueries({queryKey:["profile-stats"]}),N("/app/profile")}async function D(){if(!s?.post||!ie(i))return;const a=await oe({title:"Report",message:"Tell us what's wrong.",placeholder:"Reason",confirmLabel:"Report",multiline:!0});if(!a)return;const{error:l}=await r.from("reports").insert({reporter_id:i.id,reason:a,target_user_id:s.post.user_id,target_post_id:s.post.id,details:`Post: ${s.post.id}`});if(l)return d.error(l.message);d.success("Reported")}const b=!!i&&s?.post&&i.id===s.post.user_id,y=s?.post?.is_portfolio?"Offer":"Service",p=s?.post?.expires_at?new Date(s.post.expires_at):null,m=p?p.getTime()<Date.now():!1;return e.jsxs("div",{className:"mx-auto max-w-md",children:[e.jsxs("header",{className:"safe-top px-4 py-3 flex items-center gap-3",children:[e.jsx("button",{onClick:()=>N(x==="portfolio"||x==="profile"?"/app/profile":"/app"),"aria-label":"Back",className:"size-9 rounded-full bg-card shadow-soft flex items-center justify-center",children:e.jsx(P,{className:"size-4"})}),e.jsx("h1",{className:"font-display font-semibold text-lg flex-1",children:y}),e.jsx("button",{onClick:()=>j(!0),className:"size-9 rounded-full bg-card shadow-soft flex items-center justify-center","aria-label":"Share",children:e.jsx(Q,{className:"size-4"})}),e.jsxs(K,{children:[e.jsx(R,{asChild:!0,children:e.jsx("button",{className:"size-9 rounded-full bg-card shadow-soft flex items-center justify-center","aria-label":"More options",children:e.jsx(I,{className:"size-4"})})}),e.jsx(B,{align:"end",className:"w-44",children:b?e.jsxs(e.Fragment,{children:[e.jsxs(u,{onClick:()=>c(!0),children:[e.jsx(_,{className:"size-4 me-2"})," Edit"]}),e.jsxs(u,{onClick:E,className:"text-destructive focus:text-destructive",children:[e.jsx(F,{className:"size-4 me-2"})," Delete"]})]}):e.jsxs(u,{onClick:D,children:[e.jsx(V,{className:"size-4 me-2"})," Report"]})})]})]}),g&&e.jsx("div",{className:"py-10 flex justify-center",children:e.jsx(U,{className:"size-5 animate-spin text-primary"})}),!g&&!s&&e.jsx("p",{className:"px-5 py-10 text-center text-sm text-muted-foreground",children:"Post not found."}),s&&e.jsxs("div",{className:"pb-10",children:[e.jsx("div",{className:"px-5",children:e.jsxs(G,{to:"/app/profile/$id",params:{id:s.profile?.id},className:"flex items-center gap-3",children:[s.profile?.avatar_url?e.jsx("img",{src:J(s.profile.avatar_url,40),alt:"",className:"size-10 rounded-full object-cover"}):e.jsx("div",{className:"size-10 rounded-full bg-secondary text-xs font-semibold flex items-center justify-center",children:(s.profile?.display_name||"?").slice(0,2).toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-sm",children:s.profile?.display_name||"Buddy"}),s.profile?.handle&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["@",s.profile.handle]})]})]})}),e.jsx("div",{className:"mt-3 bg-black",children:s.post.media_type==="video"?e.jsx("div",{className:"w-full aspect-square bg-black",children:e.jsx(Y,{src:s.post.media_url,fit:"
1contain"})}):e.jsx(Z,{urls:Array.isArray(s.post.media_urls)&&s.post.media_urls.length?s.post.media_urls:[s.post.media_url],hashes:Array.isArray(s.post.blurhashes)&&s.post.blurhashes.length?s.post.blurhashes:s.post.blurhash?[s.post.blurhash]:void 0,alt:s.post.caption??"post"})}),e.jsxs("div",{className:"px-5 mt-4",children:[e.jsxs("div",{className:"rounded-3xl bg-card border border-border shadow-soft p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2 mb-1",children:e.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider px-2 py-0.5 rounded-full bg-primary-soft text-primary",children:y})}),s.post.caption&&e.jsx("p",{className:"text-base font-semibold leading-snug text-foreground",children:s.post.caption})]}),s.post.is_portfolio&&s.post.price_cents!=null&&e.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 text-base font-bold rounded-2xl bg-gradient-warm text-primary-foreground px-3 py-1.5 shadow-soft",children:[e.jsx(H,{className:"size-3.5"}),W(s.post.price_cents)]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5 pt-1 border-t border-border/60",children:[s.post.location_label&&e.jsxs("p",{className:"text-xs text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(X,{className:"size-3.5 text-primary/70 shrink-0"}),e.jsx("span",{className:"truncate",children:s.post.location_label})]}),e.jsxs("p",{className:"text-xs text-muted-foreground inline-flex items-center gap-1.5",children:[e.jsx(w,{className:"size-3.5 text-primary/70 shrink-0"}),"Posted ",v(s.post.created_at)]}),p&&e.jsxs("p",{className:`text-xs inline-flex items-center gap-1.5 font-medium ${m?"text-destructive":"text-muted-foreground"}`,children:[e.jsx(ne,{className:`size-3.5 shrink-0 ${m?"text-destructive":"text-primary/70"}`}),m?"Expired on":"Expires"," ",v(s.post.expires_at)]})]}),e.jsxs("button",{onClick:()=>f(!0),className:"w-full inline-flex items-center justify-center gap-2 rounded-2xl bg-gradient-warm text-primary-foreground px-4 py-2.5 text-sm font-semibold shadow-soft active:scale-[0.99] transition",children:[e.jsx(ee,{className:"size-4"})," View comments · ",s.commentCount]})]}),b&&e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsxs("button",{onClick:()=>c(!0),className:"flex-1 inline-flex items-center justify-center gap-2 rounded-2xl bg-card border border-border px-3 py-2.5 text-sm font-semibold",children:[e.jsx(_,{className:"size-4"})," Edit"]}),e.jsxs("button",{onClick:()=>h(!0),className:"flex-1 inline-flex items-center justify-center gap-2 rounded-2xl bg-gradient-warm text-primary-foreground px-3 py-2.5 text-sm font-semibold",children:[e.jsx(w,{className:"size-4"})," Extend expiry"]})]})]})]}),C&&e.jsx(se,{postId:t,onClose:()=>f(!1)}),k&&e.jsx(te,{itemType:"post",itemId:t,onClose:()=>c(!1),onSaved:()=>o.invalidateQueries({queryKey:["post",t]})}),z&&e.jsx(le,{itemType:"post",itemId:t,itemTitle:s?.post?.caption??void 0,onClose:()=>h(!1)}),e.jsx(ae,{open:S,onClose:()=>j(!1),url:typeof window<"u"?`${window.location.origin}/app/posts/${t}`:`https://tbuddy.app/app/posts/${t}`,title:s?.post?.is_portfolio?"offer":"service",filename:`post-${t}.png`})]})}export{me as component};
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.