// @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{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{C as t,Hn as n,a as r,ai as i,bt as a,ci as o,li as s,qi as c}from"./lucide-icons-BdRF0moN.js";import{t as l}from"./jsx-runtime-By8HlURe.js";import{u}from"./esm-CRVqHnq2.js";import{l as d}from"./useCurrentUser-C6OJJlWo.js";import{t as f}from"./utils-BFSTDHdM.js";import{t as p}from"./FallbackImage-Dlnc8809.js";import"./input-CM5Fnyvy.js";import{i as m,r as h,t as g}from"./popover-Dw5E1auH.js";import{t as _}from"./extraKinds-BydAXtVV.js";import{t as v}from"./sidebarItems-BFr7FKBa.js";import"./separator-CWY6Ovdb.js";import"./useUserLists-zSWA8dQn.js";import{K as y}from"./index-CYEZWNq6.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./select-DRTcxeFR.js";var D=e(c(),1);function O(){let e=[];for(let t of _)if(t.subKinds)for(let n of t.subKinds)e.push({value:String(n.kind),label:`${n.label} (${n.kind})`,description:n.description,parentId:t.id,icon:v[t.id]});else e.push({value:String(t.kind),label:`${t.label} (${t.kind})`,description:t.description,parentId:t.id,icon:v[t.id]});let t=new Set;return e.filter(e=>t.has(e.value)?!1:(t.add(e.value),!0))}function k(e){let t=e.kinds;return!Array.isArray(t)||t.length===0?[]:t.map(String)}var A=l();function j(){let e=(0,D.useRef)(null),t=(0,D.useRef)(null),n=(0,D.useRef)(null),[r,i]=(0,D.useState)(!1),[a,o]=(0,D.useState)(!1),s=(0,D.useCallback)(()=>{let t=e.current;t&&(i(t.scrollTop>0),o(t.scrollTop+t.clientHeight{if(n.current?.disconnect(),n.current=null,e.current=t,!t)return;let r=new ResizeObserver(s);r.observe(t),n.current=r,s()},[s]),l=(0,D.useCallback)(()=>{t.current&&=(clearInterval(t.current),null)},[]),u=(0,D.useCallback)(n=>{l(),t.current=setInterval(()=>{let t=e.current;if(!t)return l();t.scrollBy({top:n===`up`?-8:8}),s(),(n===`up`?t.scrollTop<=0:t.scrollTop+t.clientHeight>=t.scrollHeight-1)&&l()},16)},[s,l]);return(0,D.useEffect)(()=>l,[l]),{refCallback:c,canScrollUp:r,canScrollDown:a,onScroll:s,startScroll:u,stopScroll:l}}function M({direction:e,onMouseEnter:t,onMouseLeave:n}){return(0,A.jsx)(`button`,{className:`flex cursor-default items-center justify-center py-0.5 w-full shrink-0 text-muted-foreground hover:text-foreground`,onMouseEnter:t,onMouseLeave:n,children:e===`up`?(0,A.jsx)(i,{className:`size-3.5`}):(0,A.jsx)(o,{className:`size-3.5`})})}function N({icon:e,label:t,active:n,onClick:r}){return(0,A.jsxs)(`button`,{onClick:r,className:f(`w-full flex items-center gap-2 px-2.5 py-1.5 text-xs transition-colors text-left`,n?`bg-primary/10 text-primary`:`hover:bg-secondary/60 text-foreground`),children:[e?(0,A.jsx)(e,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,A.jsx)(`span`,{className:`size-3.5 shrink-0`}),(0,A.jsx)(`span`,{className:`truncate`,children:t}),n&&(0,A.jsx)(s,{className:`size-3 shrink-0 ml-auto text-primary`})]})}function P({value:e,options:t,onChange:i}){let[s,c]=(0,D.useState)(!1),[l,u]=(0,D.useState)(``),{refCallback:d,canScrollUp:p,canScrollDown:_,onScroll:v,startScroll:y,stopScroll:b}=j(),x=(0,D.useMemo)(()=>{let e=l.toLowerCase().trim();return e?t.filter(t=>t.label.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.value.includes(e)):t},[t,l]),S=e===`all`||e===`custom`?null:t.find(t=>t.value===e),C=S?.icon,w=e=>{i(e),c(!1),u(``)};return(0,A.jsxs)(g,{open:s,onOpenChange:e=>{c(e),e||u(``)},children:[(0,A.jsx)(m,{asChild:!0,children:(0,A.jsxs)(`button`,{className:f(`w-full h-8 px-2.5 rounded-md border bg-secondary/50 text-xs flex items-center gap-1.5 text-left transition-colors hover:bg-secondary border-border`,s&&`border-ring ring-1 ring-ring`),children:[C?(0,A.jsx)(C,{className:`size-3.5 shrink-0 text-muted-foreground`}):(0,A.jsx)(n,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,A.jsx)(`span`,{className:`flex-1 truncate`,children:e===`all`?`All`:e===`custom`?`Custom...`:S?.label??e}),(0,A.jsx)(o,{className:`size-3 shrink-0 text-muted-foreground`})]})}),(0,A.jsxs)(h,{align:`start`,side:`bottom`,className:`w-56 p-0 flex flex-col overflow-hidden`,style:{maxHeight:`min(280px, var(--radix-popover-content-available-height, 280px))`},children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2.5 py-2 border-b border-border shrink-0`,children:[(0,A.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,A.jsx)(`input`,{className:`flex-1 text-base md:text-xs bg-transparent outline-none placeholder:text-muted-foreground`,placeholder:`Search kinds...`,value:l,onChange:e=>u(e.target.value),autoFocus:!0}),l&&(0,A.jsx)(`button`,{onClick:()=>u(``),className:`text-muted-foreground hover:text-foreground`,children:(0,A.jsx)(r,{className:`size-3`})})]}),p&&(0,A.jsx)(M,{direction:`up`,onMouseEnter:()=>y(`up`),onMouseLeave:b}),(0,A.jsxs)(`div`,{ref:d,className:`overflow-y-auto flex-1 min-h-0`,onScroll:v,children:[!l&&(0,A.jsx)(N,{icon:null,label:`All kinds`,active:e===`all`,onClick:()=>w(`all`)}),x.map(t=>(0,A.jsx)(N,{icon:t.icon??null,label:t.label,active:e===t.value,onClick:()=>w(t.value)},t.value)),(!l||`custom`.includes(l.toLowerCase()))&&(0,A.jsx)(N,{icon:n,label:`Custom kind...`,active:e===`custom`,onClick:()=>w(`custom`)}),x.length===0&&l&&(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground text-center py-4`,children:`No kinds match`})]}),_&&(0,A.jsx)(M,{direction:`down`,onMouseEnter:()=>y(`down`),onMouseLeave:b})]})]})}function F({selectedKinds:e,options:t,onChange:i}){let[c,l]=(0,D.useState)(!1),[u,d]=(0,D.useState)(``),{refCallback:p,canScrollUp:_,canScrollDown:v,onScroll:y,startScroll:b,stopScroll:x}=j(),S=(0,D.useMemo)(()=>{let e=u.toLowerCase().trim();return e?t.filter(t=>t.label.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.value.includes(e)):t},[t,u]),C=e.length===0,w=t=>{e.includes(t)?i(e.filter(e=>e!==t)):i([...e,t])},T=()=>{i([]),l(!1),d(``)},E=(0,D.useMemo)(()=>C?`All kinds`:e.length===1?t.find(t=>t.value===e[0])?.label??`Kind ${e[0]}`:`${e.length} kinds selected`,[C,e,t]);return(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsxs)(g,{open:c,onOpenChange:e=>{l(e),e||d(``)},children:[(0,A.jsx)(m,{asChild:!0,children:(0,A.jsxs)(`button`,{className:f(`w-full h-9 px-3 rounded-lg border bg-secondary/50 text-sm flex items-center gap-2 text-left transition-colors hover:bg-secondary border-border`,c&&`border-ring ring-1 ring-ring`),children:[(0,A.jsx)(n,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,A.jsx)(`span`,{className:`flex-1 truncate`,children:E}),(0,A.jsx)(o,{className:`size-3.5 shrink-0 text-muted-foreground`})]})}),(0,A.jsxs)(h,{align:`start`,side:`bottom`,className:`w-[--radix-popover-trigger-width] min-w-64 p-0 flex flex-col overflow-hidden`,style:{maxHeight:`min(320px, var(--radix-popover-content-available-height, 320px))`},children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2.5 border-b border-border shrink-0`,children:[(0,A.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`}),(0,A.jsx)(`input`,{className:`flex-1 text-base md:text-sm bg-transparent outline-none placeholder:text-muted-foreground`,placeholder:`Search kinds...`,value:u,onChange:e=>d(e.target.value),autoFocus:!0}),u&&(0,A.jsx)(`button`,{onClick:()=>d(``),className:`text-muted-foreground hover:text-foreground`,children:(0,A.jsx)(r,{className:`size-3.5`})})]}),_&&(0,A.jsx)(M,{direction:`up`,onMouseEnter:()=>b(`up`),onMouseLeave:x}),(0,A.jsxs)(`div`,{ref:p,className:`overflow-y-auto flex-1 min-h-0`,onScroll:y,children:[!u&&(0,A.jsxs)(`button`,{onClick:T,className:f(`w-full flex items-center gap-2.5 px-3 py-2 text-sm transition-colors text-left`,C?`bg-primary/10 text-primary`:`hover:bg-secondary/60 text-foreground`),children:[(0,A.jsx)(`span`,{className:`size-4 shrink-0`}),(0,A.jsx)(`span`,{className:`flex-1 truncate`,children:`All kinds`}),C&&(0,A.jsx)(s,{className:`size-3.5 shrink-0 ml-auto text-primary`})]}),S.map(t=>{let n=e.includes(t.value),r=t.icon;return(0,A.jsxs)(`button`,{onClick:()=>w(t.value),className:f(`w-full flex items-center gap-2.5 px-3 py-2 text-sm transition-colors text-left`,n?`bg-primary/10 text-primary`:`hover:bg-secondary/60 text-foreground`),children:[(0,A.jsx)(`div`,{className:f(`size-4 shrink-0 rounded border flex items-center justify-center transition-colors`,n?`bg-primary border-primary`:`border-border bg-background`),children:n&&(0,A.jsx)(s,{className:`size-3 text-primary-foreground`})}),r?(0,A.jsx)(r,{className:`size-4 shrink-0 text-muted-foreground`}):(0,A.jsx)(`span`,{className:`size-4 shrink-0`}),(0,A.jsx)(`span`,{className:`flex-1 truncate`,children:t.label})]},t.value)}),S.length===0&&u&&(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-6`,children:`No kinds match`})]}),v&&(0,A.jsx)(M,{direction:`down`,onMouseEnter:()=>b(`down`),onMouseLeave:x}),e.length>0&&(0,A.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-t border-border shrink-0`,children:[(0,A.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.length,` selected`]}),(0,A.jsx)(`button`,{onClick:()=>{l(!1),d(``)},className:`text-xs font-medium text-primary hover:text-primary/80 transition-colors`,children:`Done`})]})]})]}),e.length>0&&(0,A.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>{let n=t.find(t=>t.value===e),i=n?.icon,a=n?n.label:`Kind ${e}`;return(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 pl-2 pr-1 py-0.5 rounded-full bg-secondary border border-border text-xs max-w-[180px]`,children:[i&&(0,A.jsx)(i,{className:`size-3 shrink-0 text-muted-foreground`}),(0,A.jsx)(`span`,{className:`truncate`,children:a}),(0,A.jsx)(`button`,{onClick:()=>w(e),className:`shrink-0 size-4 flex items-center justify-center rounded-full text-muted-foreground hover:text-foreground hover:bg-secondary-foreground/10 transition-colors`,"aria-label":`Remove ${a}`,children:(0,A.jsx)(r,{className:`size-3`})})]},e)})})]})}function I({value:e,options:t,onChange:n,size:r=`sm`}){let i=t.length>3;return(0,A.jsx)(`div`,{className:f(`rounded-lg border border-border overflow-hidden`,i?`grid grid-cols-2`:`flex`),children:t.map(({value:t,label:a,icon:o})=>(0,A.jsxs)(`button`,{onClick:()=>n(t),className:f(`flex items-center justify-center font-medium transition-colors`,r===`sm`?`py-1.5 gap-1 text-xs`:`py-2 gap-1.5 text-sm`,!i&&`flex-1`,e===t?`bg-primary text-primary-foreground`:`bg-secondary/40 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,A.jsx)(o,{className:`size-3.5 shrink-0`}),a]},t))})}function L({lists:e,followPacks:t,value:n,onSelectPubkeys:r,className:i}){return e.length>0||t.length>0?(0,A.jsxs)(E,{value:n,onValueChange:n=>{let i=[];n.startsWith(`set:`)?i=e.find(e=>e.id===n.slice(4))?.pubkeys??[]:n.startsWith(`pack:`)&&(i=t.find(e=>e.id===n.slice(5))?.pubkeys??[]),i.length>0&&r(i)},children:[(0,A.jsx)(C,{className:f(`w-full bg-secondary/50 h-8 text-base md:text-xs`,i),children:(0,A.jsx)(T,{placeholder:`Or choose a list...`})}),(0,A.jsxs)(S,{children:[e.length>0&&(0,A.jsxs)(w,{children:[t.length>0&&(0,A.jsx)(b,{children:`Lists`}),e.map(e=>(0,A.jsxs)(x,{value:`set:${e.id}`,children:[e.title,` (`,e.pubkeys.length,`)`]},`set:${e.id}`))]}),t.length>0&&(0,A.jsxs)(w,{children:[e.length>0&&(0,A.jsx)(b,{children:`Follow Packs`}),t.map(e=>(0,A.jsxs)(x,{value:`pack:${e.id}`,children:[e.title,` (`,e.pubkeys.length,`)`]},`pack:${e.id}`))]})]})]}):null}function R({pubkey:e,onRemove:n}){let i=d((0,D.useMemo)(()=>{if(/^[0-9a-f]{64}$/i.test(e))return e;try{let t=u.decode(e);return t.type===`npub`?t.data:e}catch{return e}},[e])),a=i.data?.metadata?.name||i.data?.metadata?.display_name||e.slice(0,10)+`...`,o=i.data?.metadata?.picture;return(0,A.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 pl-1.5 pr-1 py-0.5 rounded-full bg-secondary border border-border text-xs max-w-[160px]`,children:[(0,A.jsx)(p,{src:o,className:`size-4 rounded-full shrink-0 object-cover`,decoding:`async`,fallback:(0,A.jsx)(t,{className:`size-3 shrink-0 text-muted-foreground`})}),(0,A.jsx)(`span`,{className:`truncate`,children:a}),(0,A.jsx)(`button`,{onClick:n,className:`shrink-0 text-muted-foreground hover:text-foreground transition-colors`,"aria-label":`Remove`,children:(0,A.jsx)(r,{className:`size-3`})})]})}function z({onCommit:e}){return(0,A.jsx)(y,{placeholder:`Search by name or npub...`,onSelect:(0,D.useCallback)(t=>{let n=t.metadata.name||t.metadata.display_name||t.pubkey.slice(0,16)+`...`;e(t.pubkey,n)},[e]),hideCountry:!0,inputClassName:`rounded-lg bg-secondary/50 border border-border focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0 text-base md:text-sm h-9`,className:`w-full`})}export{F as a,k as c,L as i,z as n,I as o,P as r,O as s,R as t}; // @license-end