// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later // @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c import{n as e,r as t}from"./rolldown-runtime-QTnfLwEv.js";import{F as n,Gt as r,J as i,Kn as a,N as o,Ot as s,Ri as c,Tr as l,ln as u,mt as d,on as f,qi as p}from"./lucide-icons-BdRF0moN.js";import{t as m}from"./jsx-runtime-By8HlURe.js";import{f as h,t as g}from"./dist-DQ82bf9M.js";import{h as _,t as v}from"./useQuery-rCAlChE8.js";import{t as y}from"./useMutation-CgsR0O-3.js";import{G as ee,U as te,W as ne}from"./EmbeddedNote-BKfkvcrg.js";import{t as re}from"./useAppContext-Ughdk2-Z.js";import{r as b}from"./react-intl-eZirkCBg.js";import{l as x,p as S,s as C,t as w}from"./useCurrentUser-C6OJJlWo.js";import{t as T}from"./utils-BFSTDHdM.js";import{t as E}from"./button-Cs26nq0r.js";import{t as D}from"./useNostrPublish-CrMjnYm4.js";import{n as O,o as k,r as ie,t as ae}from"./avatar--oX_CTF4.js";import{n as A,s as oe,u as se}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as ce}from"./useProfileUrl-DoFhqUUR.js";import{r as j}from"./BioContent-BjUPDB1O.js";import{t as le}from"./input-CM5Fnyvy.js";import{a as ue,n as de,r as M,t as fe}from"./dropdown-menu-ug3FLSAW.js";import{t as N}from"./skeleton-CVls4GW9.js";import{n as pe}from"./ComposeDialogContent-YxhSZA-Y.js";import{a as me,c as he,l as ge,n as _e,t as ve}from"./dialog-C3CFmras.js";import{t as ye}from"./textarea-B93xm6Zg.js";import{E as be,F as xe,I as Se,P as Ce,S as we,c as Te,d as P,g as Ee,h as De,i as Oe,l as ke,n as Ae,p as je,s as Me,w as Ne,y as Pe}from"./EmbeddedPost-Bb-ngBHS.js";import{t as Fe}from"./timeAgo-BXjjbyXp.js";import{t as Ie}from"./getDisplayName-B6lnEGRj.js";import{t as Le}from"./useLinkPreview-CqNF97jn.js";import{t as Re}from"./badge-eEdLlpTp.js";import{t as ze}from"./formatNumber-D1ols1S-.js";import{c as Be}from"./LayoutContext-CjQBLGO-.js";import{r as F}from"./NoteCard-COwLfrJJ.js";import{t as Ve}from"./useFeedSettings-DkFDaYIY.js";import{t as He}from"./SubHeaderBar-BYwNp4Nc.js";import{t as I}from"./label-BBIj2Nkw.js";import{t as Ue}from"./checkbox-CM1MZiSJ.js";import{o as L,r as We,w as Ge,y as Ke}from"./index-CYEZWNq6.js";import{a as qe,i as R,o as z,t as B}from"./bookstr-BBZy-aJu.js";var V=t(p(),1),H=m(),Je=3;function U({roots:e}){return(0,H.jsx)(`div`,{children:e.map(e=>(0,H.jsx)(W,{node:e,depth:0},e.event.id))})}function Ye({roots:e}){let[t,n]=(0,V.useState)(!1);return e.length===0?null:(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`flex items-center gap-2 px-4 py-3 w-full text-left text-sm text-muted-foreground hover:text-foreground transition-colors group border-b border-border`,children:[(0,H.jsx)(d,{className:`size-4 shrink-0`}),(0,H.jsx)(`span`,{className:`group-hover:underline`,children:t?(0,H.jsx)(b,{id:`thread.floodHide`,defaultMessage:`Hide {count} {count, plural, one {reply} other {replies}} marked as spam`,values:{count:e.length}}):(0,H.jsx)(b,{id:`thread.floodShow`,defaultMessage:`…and {count} other {count, plural, one {reply} other {replies}} marked as spam`,values:{count:e.length}})})]}),t&&(0,H.jsx)(U,{roots:e})]})}function W({node:e,depth:t,depthless:n}){let[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)(!1),s=e.children.length>0,c=e.hiddenChildren?.length??0;if(!n&&t>=Je&&s&&!r)return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(F,{event:e.event,threaded:!0}),(0,H.jsx)(K,{count:G(e),onClick:()=>i(!0),isLast:!0})]});if(!s)return(0,H.jsx)(F,{event:e.event,zapAsReply:pe.has(e.event.kind)});let l=n||r;return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(F,{event:e.event,threaded:!0}),c>0&&!a&&(0,H.jsx)(K,{count:c,onClick:()=>o(!0)}),a&&e.hiddenChildren.map(e=>(0,H.jsx)(F,{event:e.event,threaded:!0,threadedLineClassName:`bg-primary/30`},e.event.id)),e.children.map(e=>(0,H.jsx)(W,{node:e,depth:t+1,depthless:l},e.event.id))]})}function G(e){let t=0;for(let n of e.children)t+=1+G(n);return t}function K({count:e,onClick:t,isLast:n}){return(0,H.jsxs)(`button`,{onClick:t,className:T(`flex items-center gap-3 px-4 pt-0 pb-2.5 w-full hover:bg-secondary/30 transition-colors group`,n&&`border-b border-border`),children:[(0,H.jsxs)(`div`,{className:`flex flex-col items-center w-10`,children:[(0,H.jsx)(`div`,{className:`w-0.5 flex-1 mb-1 bg-foreground/20`}),(0,H.jsx)(`div`,{className:`size-1.5 rounded-full bg-foreground/30 my-0.5`}),(0,H.jsx)(`div`,{className:`size-1.5 rounded-full bg-foreground/20 my-0.5`}),(0,H.jsx)(`div`,{className:`size-1.5 rounded-full bg-foreground/10 my-0.5`})]}),(0,H.jsxs)(`span`,{className:`text-sm text-primary font-medium group-hover:underline`,children:[`Show `,e,` more `,e===1?`reply`:`replies`]})]})}function q({replies:e,focusedEventId:t}){return(0,H.jsx)(`div`,{children:e.map(({reply:e,firstSubReply:n})=>(0,H.jsxs)(`div`,{children:[(0,H.jsx)(F,{event:e,threaded:!!n,highlight:e.id===t}),n&&(0,H.jsx)(F,{event:n,threadedLast:!0,highlight:n.id===t})]},e.id))})}function Xe(e){let{nostr:t}=g();return v({queryKey:[`book-reviews`,e],queryFn:async({signal:n})=>{let r=await t.query([{kinds:[B.BOOK_REVIEW],"#d":[`isbn:${e}`],limit:100}],{signal:AbortSignal.any([n,AbortSignal.timeout(5e3)])}),i=[];for(let e of r){if(!z(e))continue;let t=R(e);t&&i.push({event:e,review:t})}return i.sort((e,t)=>t.event.created_at-e.event.created_at)},enabled:!!e,staleTime:120*1e3})}function Ze(e){let{nostr:t}=g(),{user:n}=w();return v({queryKey:[`user-book-review`,e,n?.pubkey],queryFn:async({signal:r})=>{if(!n)return null;let i=(await t.query([{kinds:[B.BOOK_REVIEW],authors:[n.pubkey],"#d":[`isbn:${e}`],limit:1}],{signal:AbortSignal.any([r,AbortSignal.timeout(3e3)])})).filter(z);if(i.length===0)return null;let a=R(i[0]);return a?{event:i[0],review:a}:null},enabled:!!n&&!!e})}function Qe(){let e=_(),{user:t}=w(),{mutateAsync:n}=D();return y({mutationFn:async e=>{if(!t)throw Error(`User not logged in`);let r=[[`d`,`isbn:${e.isbn}`],[`k`,`isbn`]];return e.rating!==void 0&&r.push([`rating`,e.rating.toString()]),e.contentWarning&&r.push([`content-warning`,e.contentWarning]),n({kind:B.BOOK_REVIEW,content:e.content,tags:r})},onSuccess:(n,r)=>{e.invalidateQueries({queryKey:[`book-reviews`,r.isbn]}),e.invalidateQueries({queryKey:[`user-book-review`,r.isbn,t?.pubkey]}),e.invalidateQueries({queryKey:[`book-feed`]})}})}function J({isbn:e,children:t}){let[n,r]=(0,V.useState)(!1),{data:i}=Ze(e);return(0,H.jsxs)(ve,{open:n,onOpenChange:r,children:[(0,H.jsx)(ge,{asChild:!0,children:t}),(0,H.jsxs)(_e,{className:`max-w-lg`,children:[(0,H.jsx)(me,{children:(0,H.jsx)(he,{children:i?`Edit Review`:`Write a Review`})}),(0,H.jsx)($e,{isbn:e,existingReview:i?.review,onClose:()=>r(!1)})]})]})}function $e({isbn:e,existingReview:t,onClose:n}){let{user:r}=w(),{toast:a}=C(),[o,s]=(0,V.useState)(t?.content??``),[c,l]=(0,V.useState)(t?.rating===void 0?0:Math.round(t.rating*5)),[u,d]=(0,V.useState)(!!t?.contentWarning),[f,p]=(0,V.useState)(t?.contentWarning??``),{mutate:m,isPending:h}=Qe();return r?(0,H.jsxs)(`form`,{onSubmit:r=>{if(r.preventDefault(),!o.trim()&&c===0){a({title:`Please provide either a written review or a rating`,variant:`destructive`});return}let i={isbn:e,content:o.trim(),rating:c>0?c/5:void 0,contentWarning:u&&f.trim()?f.trim():void 0};m(i,{onSuccess:()=>{a({title:t?`Review updated`:`Review published`}),n?.()},onError:()=>{a({title:`Failed to publish review`,variant:`destructive`})}})},className:`space-y-5`,children:[(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(I,{children:`Rating (optional)`}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`div`,{className:`flex`,children:[...[,,,,,]].map((e,t)=>(0,H.jsx)(`button`,{type:`button`,onClick:()=>l(t+1),className:`p-0.5 hover:scale-110 transition-transform`,children:(0,H.jsx)(i,{className:T(`size-7`,t0&&(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[c,`/5`]}),(0,H.jsx)(E,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>l(0),children:`Clear`})]})]})]}),(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(I,{htmlFor:`review-content`,children:`Review (optional)`}),(0,H.jsx)(ye,{id:`review-content`,placeholder:`Share your thoughts about this book...`,value:o,onChange:e=>s(e.target.value),rows:5})]}),(0,H.jsxs)(`div`,{className:`space-y-3`,children:[(0,H.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,H.jsx)(Ue,{id:`spoiler`,checked:u,onCheckedChange:e=>d(e===!0)}),(0,H.jsx)(I,{htmlFor:`spoiler`,className:`text-sm cursor-pointer`,children:`This review contains spoilers`})]}),u&&(0,H.jsxs)(`div`,{className:`space-y-2`,children:[(0,H.jsx)(I,{htmlFor:`warning-message`,children:`Spoiler warning message`}),(0,H.jsx)(le,{id:`warning-message`,placeholder:`e.g., Major plot points discussed`,value:f,onChange:e=>p(e.target.value)})]})]}),(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,H.jsx)(E,{type:`button`,variant:`outline`,onClick:n,children:`Cancel`}),(0,H.jsx)(E,{type:`submit`,disabled:h,children:h?`Publishing...`:t?`Update Review`:`Publish Review`})]})]}):null}var et={light:80,moderate:160,heavy:280},tt={light:50,moderate:100,heavy:180};function nt(e,t,n){let r=n===`heavy`?14:n===`moderate`?10:7,i=n===`heavy`?8:n===`moderate`?5:3;return{x:Math.random()*(e+100)-50,y:Math.random()*t*-1-20,speed:r+Math.random()*i,length:n===`heavy`?18+Math.random()*12:10+Math.random()*10,opacity:.15+Math.random()*.2,drift:n===`heavy`?1.5+Math.random():.5+Math.random()*.8}}function rt(e,t,n){let r=n===`heavy`?2.5:n===`moderate`?2:1.5,i=n===`heavy`?3:n===`moderate`?2.5:2;return{x:Math.random()*(e+60)-30,y:Math.random()*t*-1-10,speed:.5+Math.random()*(n===`heavy`?1.8:n===`moderate`?1.2:.8),radius:r+Math.random()*i,opacity:.4+Math.random()*.4,wobbleAmp:.3+Math.random()*.8,wobbleFreq:.01+Math.random()*.02,wobblePhase:Math.random()*Math.PI*2}}var it=(0,V.memo)(function({type:e,intensity:t}){let n=(0,V.useRef)(null),r=(0,V.useRef)(0),i=(0,V.useRef)([]),a=(0,V.useRef)([]),o=(0,V.useRef)(0);return(0,V.useEffect)(()=>{let s=n.current;if(!s||!e)return;let c=s.getContext(`2d`);if(!c)return;function l(){s&&(s.width=window.innerWidth,s.height=window.innerHeight)}l(),window.addEventListener(`resize`,l);let u=s.width,d=s.height;if(e===`rain`){let e=et[t];i.current=[];for(let n=0;ns.height+20&&(e.y=-e.length-Math.random()*40,e.x=Math.random()*(s.width+100)-50),e.x>s.width+50&&(e.x=-50),c.beginPath(),c.moveTo(e.x,e.y),c.lineTo(e.x+e.drift*.5,e.y+e.length),c.strokeStyle=`rgba(174, 194, 224, ${e.opacity})`,c.lineWidth=1.2,c.lineCap=`round`,c.stroke();r.current=requestAnimationFrame(f)}}function p(){if(!(!s||!c)){c.clearRect(0,0,s.width,s.height),o.current++;for(let e of a.current){e.y+=e.speed,e.x+=Math.sin(o.current*e.wobbleFreq+e.wobblePhase)*e.wobbleAmp,e.y>s.height+10&&(e.y=-e.radius*2-Math.random()*30,e.x=Math.random()*(s.width+60)-30),e.x>s.width+30?e.x=-30:e.x<-30&&(e.x=s.width+30),c.beginPath(),c.arc(e.x,e.y,e.radius,0,Math.PI*2);let t=c.createRadialGradient(e.x,e.y,0,e.x,e.y,e.radius);t.addColorStop(0,`rgba(255, 255, 255, ${e.opacity})`),t.addColorStop(.5,`rgba(230, 238, 255, ${e.opacity*.6})`),t.addColorStop(1,`rgba(210, 225, 250, 0)`),c.fillStyle=t,c.fill()}r.current=requestAnimationFrame(p)}}return e===`rain`?r.current=requestAnimationFrame(f):r.current=requestAnimationFrame(p),()=>{cancelAnimationFrame(r.current),window.removeEventListener(`resize`,l),i.current=[],a.current=[]}},[e,t]),e?(0,H.jsx)(`canvas`,{ref:n,className:`pointer-events-none fixed inset-0 z-[100]`,"aria-hidden":`true`}):null});function Y(e,t,n){let{nostr:r}=g(),{store:i}=S(),a=e&&typeof e!=`string`&&!(e instanceof URL)?e:void 0,o=e instanceof URL?e.toString():typeof e==`string`?e:e?.id,s=a?.kind,c=a?.pubkey,l=a?.tags.find(([e])=>e===`d`)?.[1]??``,u=(0,V.useMemo)(()=>{if(o!==void 0){if(s===void 0)return{type:`external`,value:o};if(h.addressable(s)||h.replaceable(s)){let e=h.addressable(s)?l:``;return{type:`addr`,coord:`${s}:${c}:${e}`,id:o}}return{type:`event`,id:o}}},[o,s,c,l]),d=(0,V.useCallback)(e=>at(e,u),[u]);return v({queryKey:[`nostr`,`comments`,o,t,n??[]],queryFn:async({signal:e})=>{if(!u)throw Error(`root is required`);let a=[1111,1244,...n??[]],o=[];switch(u.type){case`external`:o.push({kinds:a,"#I":[u.value]},{kinds:a,"#i":[u.value]});break;case`addr`:o.push({kinds:a,"#A":[u.coord]},{kinds:a,"#a":[u.coord]}),u.id&&o.push({kinds:a,"#E":[u.id]});break;case`event`:o.push({kinds:a,"#E":[u.id]},{kinds:a,"#e":[u.id]});break}if(typeof t==`number`)for(let e of o)e.limit=t;let s=AbortSignal.any([e,AbortSignal.timeout(5e3)]),[c,l]=await Promise.all([i.query(o,{signal:e}).catch(()=>[]),r.query(o,{signal:s})]);return[...new Map([...c,...l].map(e=>[e.id,e])).values()]},select:d,enabled:!!e})}function X(e,t){return e.tags.find(([e])=>e===t)?.[1]}function at(e,t){let n=new Map;for(let t of e){let e=X(t,`e`);if(!e)continue;let r=n.get(e);r?r.push(t):n.set(e,[t])}let r=(e,t)=>e.created_at-t.created_at;return{allComments:e,topLevelComments:e.filter(e=>{if(!t)return!1;switch(t.type){case`external`:return X(e,`i`)===t.value;case`addr`:return X(e,`a`)===t.coord||!!t.id&&X(e,`e`)===t.id;case`event`:return X(e,`e`)===t.id}}).sort((e,t)=>t.created_at-e.created_at),getDescendants:e=>{let t=[],i=new Set([e]),a=[e];for(;a.length;)for(let e of n.get(a.pop())??[])i.has(e.id)||(i.add(e.id),t.push(e),a.push(e.id));return t.sort(r)},getDirectReplies:e=>[...n.get(e)??[]].sort(r)}}var ot=e({ExternalContentPage:()=>ct,ExternalContentView:()=>Z});function st({content:e,onComment:t,commentCount:a}){let{user:o}=w(),{toast:c}=C(),d=e.value,{addToSidebar:f,removeFromSidebar:p,orderedItems:m}=Ve(),h=m.includes(d),g=(0,V.useCallback)(()=>{f(d),c({title:`Added to sidebar`})},[d,f,c]),_=(0,V.useCallback)(()=>{p(d),c({title:`Removed from sidebar`})},[d,p,c]),[v,y]=(0,V.useState)(!1);return(0,H.jsxs)(`div`,{className:`flex items-center gap-1 px-4 py-2 border-b border-border`,children:[(0,H.jsxs)(`button`,{className:`flex items-center gap-1.5 p-2 rounded-full transition-colors text-muted-foreground hover:text-sky-500 hover:bg-sky-500/10`,title:`Comment`,onClick:t,children:[(0,H.jsx)(u,{className:`size-5`}),a>0&&(0,H.jsx)(`span`,{className:`text-sm tabular-nums`,children:ze(a)})]}),(0,H.jsx)(je,{content:e}),(0,H.jsx)(`button`,{className:`flex items-center gap-1.5 p-2 rounded-full transition-colors text-muted-foreground hover:text-accent hover:bg-accent/10`,title:`Share to feed`,onClick:()=>y(!0),children:(0,H.jsx)(s,{className:`size-5`})}),e.type===`isbn`&&o&&(0,H.jsx)(J,{isbn:e.value.replace(`isbn:`,``),children:(0,H.jsx)(`button`,{className:`flex items-center gap-1.5 p-2 rounded-full transition-colors text-muted-foreground hover:text-amber-500 hover:bg-amber-500/10`,title:`Write a review`,children:(0,H.jsx)(i,{className:`size-5`})})}),(0,H.jsx)(`div`,{className:`flex-1`}),(0,H.jsxs)(fe,{children:[(0,H.jsx)(ue,{asChild:!0,children:(0,H.jsx)(`button`,{className:`p-2 rounded-full transition-colors text-muted-foreground hover:text-primary hover:bg-primary/10`,title:`More`,children:(0,H.jsx)(l,{className:`size-5`})})}),(0,H.jsx)(de,{align:`end`,className:`w-52`,children:h?(0,H.jsxs)(M,{onClick:_,className:`gap-3`,children:[(0,H.jsx)(n,{className:`size-4`}),`Remove from sidebar`]}):(0,H.jsxs)(M,{onClick:g,className:`gap-3`,children:[(0,H.jsx)(r,{className:`size-4`}),`Add to sidebar`]})})]}),v&&(0,H.jsx)(P,{open:v,onOpenChange:y,initialContent:d,title:`Share to feed`})]})}function ct(){let{"*":e}=se(),t=oe();return(0,H.jsx)(Z,{uri:(0,V.useMemo)(()=>{if(!e)return``;if(!e.includes(`://`))try{return decodeURIComponent(e)}catch{return e}return e+t.search},[e,t.search])})}function Z({uri:e,focusedEventId:t}){let{config:n}=re(),r=(0,V.useMemo)(()=>e?xe(e):null,[e]),i=r?.type===`url`?r.value:null,{data:o}=Le(i),s=(0,V.useMemo)(()=>i?ee(i):null,[i]),l=(0,V.useMemo)(()=>i?ne(i):null,[i]),{data:u}=Ee(s?null:l),d=s??u?.wikipediaTitle??null,{data:f}=De(d),p=(0,V.useMemo)(()=>i?te(i):null,[i]),{data:m}=Pe((0,V.useMemo)(()=>p?p.kind===`multiverse`?{kind:`multiverse`,multiverseId:p.multiverseId}:{kind:`set`,set:p.set,number:p.number,lang:p.lang}:null,[p])),h=f?.title??m?.name??o?.title,g=h??(r?Ce(r):`External Content`);Ge({title:r?h?`${h} | ${n.appName}`:Se(r,n.appName):`External Content | ${n.appName}`});let _=(0,V.useMemo)(()=>{if(!(!r||r.type!==`url`))try{return new URL(r.value)}catch{return}},[r]),v=(0,V.useMemo)(()=>{if(!(!r||r.type===`url`))return r.value},[r]),y=_??v,{isMuted:b}=Ke(),{data:x,isLoading:S}=Y(y,500),C=(0,V.useMemo)(()=>[...(x?.topLevelComments??[]).filter(e=>!b(e))].sort((e,t)=>r?.type===`iso3166`?t.created_at-e.created_at:e.created_at-t.created_at).map(e=>({reply:e,firstSubReply:(x?.getDirectReplies(e.id)??[])[0]})),[x,b,r?.type]),[w,E]=(0,V.useState)(!1),D=(0,V.useCallback)(()=>E(!0),[]),{data:O}=ke(r?.type===`iso3166`?r.code:null),k=(0,V.useMemo)(()=>O?Te(O.weatherCode):null,[O]);return Be({showFAB:!0,onFabClick:D}),!r||!e?(0,H.jsx)(We,{}):(0,H.jsxs)(`main`,{className:``,children:[k?.type&&(0,H.jsx)(it,{type:k.type,intensity:k.intensity}),(0,H.jsxs)(`div`,{className:`flex items-center gap-4 px-4 pt-4 pb-5`,children:[(0,H.jsx)(A,{to:r.type===`isbn`?`/books`:d?`/wikipedia`:`/`,className:T(`p-2 rounded-full hover:bg-secondary transition-colors`,r.type!==`isbn`&&!d&&`sidebar:hidden`),children:(0,H.jsx)(c,{className:`size-5`})}),(0,H.jsx)(`h1`,{className:`text-xl font-bold truncate`,children:g})]}),(0,H.jsxs)(`div`,{className:`px-4 space-y-6 pb-4`,children:[r.type===`url`&&(0,H.jsx)(Me,{url:r.value}),r.type===`isbn`&&(0,H.jsx)(Ae,{isbn:r.value}),r.type===`iso3166`&&(0,H.jsx)(Oe,{code:r.code}),r.type===`bitcoin-tx`&&(0,H.jsx)(Ne,{txid:r.txid}),r.type===`bitcoin-address`&&(0,H.jsx)(we,{address:r.address}),r.type===`unknown`&&(0,H.jsxs)(`div`,{className:`rounded-2xl border border-border p-5 text-center`,children:[(0,H.jsx)(a,{className:`size-8 mx-auto mb-2 text-muted-foreground/40`}),(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground break-all`,children:r.value})]})]}),(0,H.jsx)(st,{content:r,onComment:D,commentCount:C.length}),y&&(0,H.jsx)(P,{event:y,open:w,onOpenChange:E}),r.type===`isbn`?(0,H.jsx)(ut,{isbn:r.value.replace(`isbn:`,``),commentRoot:y,orderedReplies:C,commentsLoading:S,focusedEventId:t}):(0,H.jsx)(Q,{commentRoot:y,orderedReplies:C,commentsLoading:S,focusedEventId:t})]})}function Q({commentRoot:e,orderedReplies:t,commentsLoading:n,focusedEventId:r}){return(0,H.jsxs)(H.Fragment,{children:[e&&(0,H.jsx)(be,{compact:!0,replyTo:e}),(0,H.jsx)(`div`,{children:n?(0,H.jsx)($,{}):t.length>0?(0,H.jsx)(q,{replies:t,focusedEventId:r}):(0,H.jsx)(lt,{})})]})}function $(){return(0,H.jsx)(`div`,{className:`divide-y divide-border`,children:Array.from({length:3}).map((e,t)=>(0,H.jsx)(`div`,{className:`px-4 py-3`,children:(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[(0,H.jsx)(N,{className:`size-10 rounded-full shrink-0`}),(0,H.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(N,{className:`h-4 w-20`}),(0,H.jsx)(N,{className:`h-3 w-28`})]}),(0,H.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,H.jsx)(N,{className:`h-4 w-full`}),(0,H.jsx)(N,{className:`h-4 w-3/4`})]})]})]})},t))})}function lt(){return(0,H.jsxs)(`div`,{className:`py-12 text-center text-muted-foreground text-sm`,children:[(0,H.jsx)(f,{className:`size-12 mx-auto mb-4 opacity-30`}),(0,H.jsx)(`p`,{className:`text-lg font-medium mb-2`,children:`No comments yet`}),(0,H.jsx)(`p`,{children:`Be the first to share your thoughts about this!`})]})}function ut({isbn:e,commentRoot:t,orderedReplies:n,commentsLoading:r,focusedEventId:a}){let{user:o}=w(),{data:s=[],isLoading:c}=Xe(e),[l,u]=(0,V.useState)(`comments`),d=n.length,f=s.length;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(He,{children:[(0,H.jsx)(L,{label:`Comments${d>0?` (${d})`:``}`,active:l===`comments`,onClick:()=>u(`comments`)}),(0,H.jsx)(L,{label:`Reviews${f>0?` (${f})`:``}`,active:l===`reviews`,onClick:()=>u(`reviews`)})]}),(0,H.jsx)(`div`,{style:{height:20}}),l===`comments`?(0,H.jsx)(Q,{commentRoot:t,orderedReplies:n,commentsLoading:r,focusedEventId:a}):(0,H.jsxs)(H.Fragment,{children:[o&&(0,H.jsx)(`div`,{className:`px-4 py-3 border-b border-border`,children:(0,H.jsx)(J,{isbn:e,children:(0,H.jsxs)(E,{variant:`outline`,className:`w-full`,children:[(0,H.jsx)(i,{className:`size-4 mr-2`}),`Write a Review`]})})}),c?(0,H.jsx)($,{}):s.length>0?(0,H.jsx)(`div`,{className:`divide-y divide-border`,children:s.map(({event:e,review:t})=>(0,H.jsx)(dt,{event:e,review:t},e.id))}):(0,H.jsxs)(`div`,{className:`py-12 text-center text-muted-foreground text-sm`,children:[(0,H.jsx)(i,{className:`size-12 mx-auto mb-4 opacity-30`}),(0,H.jsx)(`p`,{className:`text-lg font-medium mb-2`,children:`No reviews yet`}),(0,H.jsx)(`p`,{children:`Be the first to review this book!`})]})]})]})}function dt({event:e,review:t}){let n=x(e.pubkey),r=n.data?.metadata,a=k(r),s=Ie(r,e.pubkey),c=ce(e.pubkey,r),[l,u]=(0,V.useState)(!1),d=t.rating===void 0?0:qe(t.rating),f=!!t.contentWarning;return(0,H.jsx)(`div`,{className:`px-4 py-3`,children:(0,H.jsxs)(`div`,{className:`flex gap-3`,children:[n.isLoading?(0,H.jsx)(N,{className:`size-10 rounded-full shrink-0`}):(0,H.jsx)(j,{pubkey:e.pubkey,asChild:!0,children:(0,H.jsx)(A,{to:c,className:`shrink-0`,children:(0,H.jsxs)(ae,{shape:a,className:`size-10`,children:[(0,H.jsx)(ie,{src:r?.picture,alt:s}),(0,H.jsx)(O,{className:`bg-primary/20 text-primary text-sm`,children:s[0]?.toUpperCase()})]})})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(j,{pubkey:e.pubkey,asChild:!0,children:(0,H.jsx)(A,{to:c,className:`font-semibold text-sm hover:underline`,children:s})}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Fe(e.created_at)})]}),t.rating!==void 0&&(0,H.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[[...[,,,,,]].map((e,t)=>(0,H.jsx)(i,{className:T(`size-3.5`,tu(!0),children:`Show Review`})]}):(0,H.jsxs)(`div`,{className:`mt-2`,children:[f&&(0,H.jsxs)(Re,{variant:`outline`,className:`text-orange-600 border-orange-200 dark:border-orange-800 mb-2`,children:[(0,H.jsx)(o,{className:`size-3 mr-1`}),`Contains Spoilers`]}),t.content?(0,H.jsx)(`p`,{className:`text-sm whitespace-pre-wrap break-words`,children:t.content}):(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground italic`,children:`Rating only, no written review`})]})]})]})})}export{q as a,Ye as i,Z as n,U as o,Y as r,ot as t}; // @license-end