1import{u as z,r as l,j as e}from"./vendor-react-CRjcqf0H.js";import{aL as _,aM as u,I as o,aE as A,d as h,V as $,z as M,c as H}from"./index-Cf8GSBcF.js";import"./vendor-qr-DWdCg0v2.js";import"./vendor-zustand-B0lUetZc.js";import"./vendor-lucide-MdFy7Nkg.js";const I=[{label:"Contacts",glyph:"ð¥",to:"/contacts"},{label:"Stories",glyph:"ðï¸",to:"/stories/compose"},{label:"Mini-Apps",glyph:"ð§©",to:"/discover"},{label:"Stickers",glyph:"ðº",to:"/stickers"}],C={users:[],miniapps:[],stories:[],localApps:[],groups:[]};function L(n,t){return n.filter(a=>a.name.toLowerCase().includes(t)||a.username.toLowerCase().includes(t)).slice(0,4).map(a=>({id:a.id,name:a.name,username:a.username,emoji:a.emoji,about:a.about}))}function F(n){return{users:n.users.map(t=>({id:t.id,name:t.name||t.yshi_id||"User",emoji:t.emoji,yshi_id:t.yshi_id,is_bot:t.is_bot})),miniapps:n.miniapps.map(t=>({id:t.id,username:t.slug||t.id,name:t.name,glyph:t.glyph||"ð§©",hue:t.hue??210,category:t.category||"Mini Program"})),stories:n.stories.filter(t=>{var a;return!!((a=t.author)!=null&&a.id)}).map(t=>{var a,c;return{id:t.id,authorId:t.author.id,name:((a=t.author)==null?void 0:a.name)||"User",emoji:(c=t.author)==null?void 0:c.emoji,text:t.text||""}}),groups:(n.groups??[]).map(t=>({id:t.id,name:t.title||t.username,username:t.username,emoji:t.emoji,member_count:t.member_count??0}))}}function D(){const n=z(),t=_(s=>s.miniapps),[a,c]=l.useState(""),[S,j]=l.useState([]),[R,g]=l.useState(C),b=l.useRef(null),r=a.trim().toLowerCase();l.useEffect(()=>{u.recentSearches().then(s=>j(s.map(i=>i.query))).catch(()=>{})},[]);const E=s=>{const i=s.trim();i&&(j(d=>[i,...d.filter(x=>x!==i)]),u.addRecentSearch(i))};l.useEffect(()=>()=>{var s;(s=b.current)==null||s.abort()},[]),l.useEffect(()=>{if(!r){g(C);return}const s=L(t,r),i=setTimeout(()=>{var x;(x=b.current)==null||x.abort();const d=new AbortController;b.current=d,u.search(r,void 0,d.signal).then(p=>g({...F(p),localApps:s})).catch(p=>{p instanceof DOMException&&p.name==="AbortError"||g({...C,localApps:s})})},250);return()=>clearTimeout(i)},[r,t]);const{users:N,localApps:y,miniapps:k,stories:v,groups:w}=R;return e.jsxs("div",{className:"flex h-full flex-col bg-bg",children:[e.jsxs("div",{className:"flex items-center gap-1 px-3 pt-safe",children:[e.jsxs("div",{className:"form-focus-shell my-2 flex h-9 flex-1 items-center gap-2 rounded-xl bg-surface-2 px-3 text-ink-3",children:[e.jsx(o,{name:"search",size:17,strokeWidth:2.2}),e.jsx("input",{autoFocus:!0,value:a,onChange:s=>c(s.target.value),onKeyDown:s=>{s.key==="Enter"&&a.trim()&&E(a.trim())},placeholder:"Search",className:"w-full bg-transparent text-body text-ink placeholder:text-ink-3 focus:outline-none"}),a&&e.jsx("button",{onClick:()=>c(""),className:"press text-ink-3","aria-label":"Clear search",children:e.jsx(o,{name:"x",size:16})})]}),e.jsx("button",{onClick:()=>n(-1),className:"press px-2 text-body font-semibold text-brand-500",children:"Cancel"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto no-scrollbar",children:[!r&&e.jsxs(e.Fragment,{children:[e.jsx(A,{children:"Search Fokawa"}),e.jsx("div",{className:"flex flex-wrap gap-2 px-4",children:I.map(s=>e.jsxs("button",{onClick:()=>n(s.to),className:"press flex items-center gap-1.5 rounded-full bg-surface px-3.5 py-2 text-footnote font-medium text-ink shadow-soft",children:[e.jsx("span",{children:s.glyph}),s.label]},s.label))}),S.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pb-1.5 pt-6",children:[e.jsx("h2",{className:"text-caption font-semibold uppercase tracking-wider text-ink-3",children:"Recent"}),e.jsx("button",{onClick:()=>{j([]),u.clearRecentSearches()},className:"press text-ink-3","aria-label":"Clear recent searches",children:e.jsx(o,{name:"more",size:18})})]}),e.jsx("div",{className:"mx-3 overflow-hidden rounded-2xl bg-surface shadow-soft",children:S.map(s=>e.jsxs("button",{onClick:()=>c(s),className:"press flex w-full items-center gap-3 px-4 py-3 text-left active:bg-surface-2 hairline-b",children:[e.jsx(o,{name:"history",size:18,className:"text-ink-3"}),e.jsx("span",{className:"flex-1 text-body text-ink",children:s}),e.jsx(o,{name:"more",size:16,className:"text-ink-3"})]},s))})]})]}),r&&e.jsxs("div",{className:"py-2",children:[N.length===0&&y.length===0&&k.length===0&&v.length===0&&w.length===0&&e.jsxs("p",{className:"px-4 py-10 text-center text-label text-ink-3",children:['No results for "',a,'"']}),y.length>0&&e.jsx(m,{title:"Mini-Apps",children:y.map(s=>e.jsxs("button",{onClick:()=>n(`/miniapp/${s.username.toLowerCase()}`),className:"press flex w-full items-center gap-3 px-4 py-2.5 text-left active:bg-surface-2",children:[e.jsx(h,{name:s.name,emoji:s.emoji,size:40,roun
1ded:10}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-ink",children:f(s.name,r)}),e.jsxs("p",{className:"truncate text-caption text-ink-3",children:["@",s.username,s.about?` · ${s.about}`:""]})]})]},s.id))}),N.length>0&&e.jsx(m,{title:"Contacts",children:N.map(s=>e.jsxs("button",{onClick:()=>n(`/contact/${s.yshi_id||s.id}`),className:"press flex w-full items-center gap-3 px-4 py-2.5 text-left active:bg-surface-2",children:[e.jsx(h,{name:s.name,size:40,rounded:10}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("p",{className:"truncate text-body font-medium text-ink",children:f(s.name,r)}),s.verified&&e.jsx($,{size:15,className:"shrink-0"})]}),e.jsxs("p",{className:"truncate text-caption text-ink-3",children:["@",s.yshi_id]})]})]},s.id))}),k.length>0&&e.jsx(m,{title:"Mini Programs",children:k.map(s=>{const i=M(s.hue);return e.jsxs("button",{onClick:()=>n(`/miniapp/${s.username}`),className:"press flex w-full items-center gap-3 px-4 py-2.5 text-left active:bg-surface-2",children:[e.jsx("span",{className:"grid h-10 w-10 place-items-center rounded-xl text-lg",style:{backgroundImage:`linear-gradient(135deg, ${i.from}, ${i.to})`},children:s.glyph}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-ink",children:f(s.name,r)}),e.jsx("p",{className:"truncate text-caption text-ink-3",children:s.category})]})]},s.id)})}),v.length>0&&e.jsx(m,{title:"Stories",children:v.map(s=>e.jsxs("button",{onClick:()=>n(`/stories/${s.authorId}?story=${encodeURIComponent(s.id)}`),className:"press flex w-full items-start gap-3 px-4 py-2.5 text-left active:bg-surface-2",children:[e.jsx(h,{name:s.name,size:40,rounded:10}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-label font-medium text-ink",children:s.name}),e.jsx("p",{className:"line-clamp-2 text-footnote text-ink-2",children:s.text})]})]},s.id))}),w.length>0&&e.jsx(m,{title:"Groups",children:w.map(s=>e.jsxs("button",{onClick:()=>n(`/group/${s.username}`),className:"press flex w-full items-center gap-3 px-4 py-2.5 text-left active:bg-surface-2",children:[e.jsx(h,{name:s.emoji??s.name,size:40,rounded:10}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-body font-medium text-ink",children:f(s.name,r)}),e.jsxs("p",{className:"truncate text-caption text-ink-3",children:["@",s.username," · ",(s.member_count??0).toLocaleString()," members"]})]})]},s.id))})]})]})]})}function m({title:n,children:t}){return e.jsxs("div",{className:"mb-2",children:[e.jsx(A,{children:n}),e.jsx("div",{className:"mx-3 overflow-hidden rounded-2xl bg-surface shadow-soft",children:t})]})}function f(n,t){const a=n.toLowerCase().indexOf(t);return a<0?n:e.jsxs(e.Fragment,{children:[n.slice(0,a),e.jsx("span",{className:H("text-brand-500"),children:n.slice(a,a+t.length)}),n.slice(a+t.length)]})}export{D as Search};
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.