1import{r as c,j as e,B as p,bU as A,u as U,bA as H,s as f,bf as I,D as R,a as $,b as z,c as M,d as Y,aT as G,e as Q,aI as W,M as J,al as S,Y as k,bC as K,an as V,bD as X,h as Z,b8 as ee,O as se,_ as te,$ as ae,p as re,bm as ne}from"./index-CaerIkuo.js";import{R as ie}from"./ReportContentModal-Bb7TWXUr.js";import{S as le}from"./settings-V_F8uSjm.js";import{G as ce}from"./globe-e0je1JXL.js";import{L as oe}from"./lock-DiMUa0TS.js";import"./useModeration-BGXgO8aE.js";import"./useActionRateLimit-tiS7LNyw.js";function de({userId:s,currentUserId:a,variant:o="ghost",size:t="sm",showLabel:h=!0}){const[m,d]=c.useState(!1);return!a||a===s?null:e.jsxs(e.Fragment,{children:[e.jsxs(p,{variant:o,size:t,className:"gap-1.5 text-muted-foreground hover:text-destructive",onClick:u=>{u.stopPropagation(),d(!0)},children:[e.jsx(A,{className:"w-4 h-4"}),h&&e.jsx("span",{children:"Report User"})]}),e.jsx(ie,{open:m,onOpenChange:d,contentType:"profile",contentId:s})]})}function me(){const{user:s}=U(),{toast:a}=H(),[o,t]=c.useState(!1),[h,m]=c.useState([]),d=c.useCallback(async()=>{if(!(s!=null&&s.id))return[];t(!0);try{const{data:r,error:n}=await f.from("user_blocks").select("*").eq("blocker_id",s.id).order("created_at",{ascending:!1});if(n)throw n;return m(r||[]),r||[]}catch(r){return console.error("Error fetching blocked users:",r),[]}finally{t(!1)}},[s==null?void 0:s.id]),u=c.useCallback(async(r,n)=>{if(!(s!=null&&s.id))return!1;if(s.id===r)return a({title:"Cannot block yourself",variant:"destructive"}),!1;try{const{error:i}=await f.from("user_blocks").insert({blocker_id:s.id,blocked_id:r,reason:n||null});if(i){if(i.code==="23505")return a({title:"User already blocked",variant:"destructive"}),!1;throw i}return a({title:"User blocked"}),await d(),!0}catch(i){return a({title:"Error blocking user",description:i.message,variant:"destructive"}),!1}},[s==null?void 0:s.id,a,d]),x=c.useCallback(async r=>{if(!(s!=null&&s.id))return!1;try{const{error:n}=await f.from("user_blocks").delete().eq("blocker_id",s.id).eq("blocked_id",r);if(n)throw n;return a({title:"User unblocked"}),await d(),!0}catch(n){return a({title:"Error unblocking user",description:n.message,variant:"destructive"}),!1}},[s==null?void 0:s.id,a,d]),j=c.useCallback(async r=>{if(!(s!=null&&s.id))return!1;try{const{data:n,error:i}=await f.rpc("is_blocked",{blocker_id:s.id,blocked_id:r});if(i)throw i;return n||!1}catch(n){return console.error("Error checking block status:",n),!1}},[s==null?void 0:s.id]);return{loading:o,blockedUsers:h,fetchBlockedUsers:d,blockUser:u,unblockUser:x,isUserBlocked:j}}function ue({userId:s,username:a,variant:o="ghost",size:t="sm",showLabel:h=!0}){const{user:m}=U(),{blockUser:d}=me(),[u,x]=c.useState(!1),[j,r]=c.useState(!1);if(!m||m.id===s)return null;const n=async()=>{r(!0);const i=await d(s);r(!1),i&&x(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs(p,{variant:o,size:t,className:"gap-1.5 text-muted-foreground hover:text-destructive",onClick:i=>{i.stopPropagation(),x(!0)},children:[e.jsx(I,{className:"w-4 h-4"}),h&&e.jsx("span",{children:"Block User"})]}),e.jsx(R,{open:u,onOpenChange:x,children:e.jsxs($,{className:"sm:max-w-md",children:[e.jsxs(z,{children:[e.jsxs(M,{children:["Block ",a||"this user","?"]}),e.jsx(Y,{children:"When you block someone:"})]}),e.jsxs("ul",{className:"text-sm space-y-2 py-4",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"â¢"}),e.jsx("span",{children:"They won't be able to see your posts or profile"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"â¢"}),e.jsx("span",{children:"You won't see their posts or profile"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"â¢"}),e.jsx("span",{children:"They won't be notified that you blocked them"})]})]}),e.jsxs(G,{children:[e.jsx(p,{variant:"outline",onClick:()=>x(!1),children:"Cancel"}),e.jsxs(p,{variant:"destructive",onClick:n,disabled:j,children:[j&&e.jsx(Q,{className:"w-4 h-4 mr-2 animate-spin"}),"Block"]})]})]})})]})}function xe({shelf:s,itemCount:a,isOwner:o}){return e.jsx(ee,{to:s.is_public&&s.public_slug?`/shelf/${s.public_slug}`:o?"/library":"#",children:e.jsx(se,{className:"h-full hover:shadow-md transition-shadow cursor-pointer",children:e.jsxs(te,{children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(ae,{className:"text-lg font-serif",children:s.name}),o&&e.jsx(re,{variant:s.is_public?"default":"secondary",className:"gap-1",children:s.is_public?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-3 h-3"})," Public"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-3 h-3"})," Private"]})})]}),s.description&&e.jsx(ne,{className:"line-clamp-2",children:s.description}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:[a," ",a===1?"item":"items"]})]})})})}function ve(){const{username:s}=W(),{user:a}=U(),o=J(),[t,h]=c.useState(null),[m,d]=c.useState([]),[u,x]=c.useState(new Map),[j,r]=c.useState(!0),[n,i]=c.useState(null),[g,L]=c.useState(!1);c.useEffect(()=>{s&&P()},[s,a]);const P=async()=>{r(!0),i(null);try{const{data:l,error:b}=await f.from("public_profiles").select("user_id, username, display_name, avatar_url, bio").eq("username",s==null?void 0:s.toLowerCase()).single();if(b||!l){i("User not found"),r(!1);return}h(l);const D=(a==null?void 0:a.id)===l.user_id;L(D);let C=f.from("bookshelves").select("id, name, description, is_public, public_slug, content_type").eq("user_id",l.user_id).order("sort_order",{ascending:!0});D||(C=C.eq("is_public",!0));const{data:v}=await C;if(d(v||[]),v&&v.length>0){const O=v.map(N=>N.name),{data:E}=await f.from("saved_content").select("shelf_name").eq("user_id",l.user_id).in("shelf_name",O);if(E){const N=new Map;
1E.forEach(T=>{const q=N.get(T.shelf_name)||0;N.set(T.shelf_name,q+1)}),x(N)}}}catch(l){console.error("Error fetching profile:",l),i("Something went wrong")}finally{r(!1)}};if(j)return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(S,{}),e.jsxs("main",{className:"container mx-auto px-4 py-8 pt-24 max-w-4xl",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx(k,{className:"w-20 h-20 rounded-full"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{className:"h-8 w-48"}),e.jsx(k,{className:"h-4 w-32"})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[...Array(4)].map((l,b)=>e.jsx(k,{className:"h-32"},b))})]})]});if(n)return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(S,{}),e.jsx("main",{className:"container mx-auto px-4 py-8 pt-24 max-w-4xl text-center",children:e.jsxs("div",{className:"max-w-md mx-auto space-y-4",children:[e.jsx("h1",{className:"text-2xl font-serif font-medium",children:"User Not Found"}),e.jsx("p",{className:"text-muted-foreground",children:n}),e.jsxs(p,{variant:"outline",onClick:()=>o("/"),children:[e.jsx(K,{className:"w-4 h-4 mr-2"}),"Go Home"]})]})})]});const y=(t==null?void 0:t.display_name)||`@${t==null?void 0:t.username}`,B=m.filter(l=>l.is_public).length,F=Array.from(u.values()).reduce((l,b)=>l+b,0),w=`${y} | Trovable`,_=(t==null?void 0:t.bio)||`${y}'s content library on Trovable.`;return e.jsxs(e.Fragment,{children:[e.jsxs(V,{children:[e.jsx("title",{children:w}),e.jsx("meta",{name:"description",content:_}),e.jsx("meta",{property:"og:title",content:w}),e.jsx("meta",{property:"og:description",content:_}),e.jsx("meta",{property:"og:type",content:"profile"}),e.jsx("meta",{name:"twitter:card",content:"summary"}),e.jsx("meta",{name:"twitter:title",content:w}),e.jsx("meta",{name:"twitter:description",content:_})]}),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(S,{}),e.jsxs("main",{className:"container mx-auto px-4 py-8 pt-24 max-w-4xl",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-8",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-secondary flex items-center justify-center overflow-hidden shrink-0",children:t!=null&&t.avatar_url?e.jsx("img",{src:t.avatar_url,alt:"",className:"w-full h-full object-cover"}):e.jsx(X,{className:"w-8 h-8 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h1",{className:"text-2xl font-serif font-medium",children:y}),g&&e.jsxs(p,{variant:"ghost",size:"sm",onClick:()=>o("/profile"),className:"gap-1",children:[e.jsx(le,{className:"w-4 h-4"}),"Edit"]}),!g&&(t==null?void 0:t.user_id)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ue,{userId:t.user_id,username:t==null?void 0:t.username,showLabel:!1,size:"icon"}),e.jsx(de,{userId:t.user_id,currentUserId:(a==null?void 0:a.id)||null,showLabel:!1,size:"icon"})]})]}),e.jsxs("p",{className:"text-muted-foreground mb-2",children:["@",t==null?void 0:t.username]}),(t==null?void 0:t.bio)&&e.jsx("p",{className:"text-sm mb-3",children:t.bio}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[B," public ",B===1?"shelf":"shelves"," ⢠",F," items"]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-serif font-medium flex items-center gap-2",children:[e.jsx(Z,{className:"w-5 h-5"}),g?"Your Shelves":"Public Shelves"]}),m.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:m.map(l=>e.jsx(xe,{shelf:l,itemCount:u.get(l.name)||0,isOwner:g},l.id))}):e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:g?"You haven't created any shelves yet.":"This user hasn't shared any shelves yet."})]}),!a&&e.jsxs("div",{className:"mt-12 p-6 rounded-xl bg-gradient-to-r from-primary/10 to-accent/10 text-center",children:[e.jsx("h2",{className:"text-xl font-serif font-medium mb-2",children:"Start your own library on Trovable"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Organize and share your favorite content."}),e.jsx(p,{onClick:()=>o("/auth"),children:"Sign Up Free"})]})]})]})]})}export{ve 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.