import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{B as t,G as n,O as r,U as i,h as a,m as o,p as s,q as c,v as l}from"./semantic-ui-react-m4AAKEby.js";import{c as u,f as d,m as f}from"./react-vendor-dEvHdx-C.js";import{i as p,o as m,s as h}from"./users-C26XYwcc.js";import{t as g}from"./PlaceholderSegment-C39R3tC3.js";var _=d(),v=()=>(0,_.jsx)(`div`,{className:`users-picture-placeholder ui small image`,children:(0,_.jsx)(s,{name:`camera`,size:`big`})}),y=({presence:e})=>(0,_.jsx)(s,{color:{Away:`yellow`,Online:`green`}[e]||`grey`,name:`circle`}),b=({hasFreeUploadSlot:e})=>(0,_.jsx)(s,{color:e?`green`:`red`,name:e?`check`:`close`}),x=({address:e,description:t,hasPicture:n,picture:r,port:i,presence:o,queueLength:s,uploadSlots:c,username:l})=>(0,_.jsxs)(a,{children:[n?(0,_.jsx)(a.Image,{size:`small`,src:`data:image;base64,${r}`}):(0,_.jsx)(v,{}),(0,_.jsxs)(a.Content,{children:[(0,_.jsxs)(a.Header,{as:`a`,children:[(0,_.jsx)(y,{presence:o}),l]}),(0,_.jsxs)(a.Meta,{children:[`Free Upload Slot: `,(0,_.jsx)(b,{hasFreeUploadSlot:!0}),`, Total Upload Slots: `,c,`, Queue Length: `,s,`, IP Address: `,e,`, Port: `,i]}),(0,_.jsx)(a.Description,{children:t||`No user info.`})]})]}),S=e(f()),C=()=>{let e=u(),d=(0,S.useRef)(),[f,v]=(0,S.useState)(),[y,b]=(0,S.useState)(),[C,w]=(0,S.useState)(void 0),[{error:T,fetching:E},D]=(0,S.useState)({error:void 0,fetching:!1}),O=e=>{d.current.inputRef.current.value=e},k=()=>{d.current.focus()},A=()=>{i(c),w(void 0),v(void 0),O(``),k()},j=e=>e.key===`Escape`?A():``;return(0,S.useLayoutEffect)(()=>{document.removeEventListener(`keyup`,j,!1)},[]),(0,S.useEffect)(()=>{document.addEventListener(`keyup`,j,!1);let n=e.state?.user||t(`slskr-active-user`);n!==void 0&&(w(n),O(n))},[]),(0,S.useEffect)(()=>{(async()=>{if(C){D({error:void 0,fetching:!0});try{let[e,t,r]=await Promise.all([m({username:C}),h({username:C}),p({username:C})]);n(c,C),v({...e.data,...t.data,...r.data}),D({error:void 0,fetching:!1})}catch(e){D({error:e,fetching:!1})}}})()},[C]),(0,_.jsxs)(`div`,{className:`users-container`,children:[(0,_.jsxs)(r,{className:`users-segment`,raised:!0,children:[(0,_.jsx)(`div`,{className:`users-segment-icon`,children:(0,_.jsx)(s,{name:`users`,size:`big`})}),(0,_.jsx)(o,{action:!E&&(f==null?{"aria-label":`Search for user`,icon:`search`,onClick:()=>w(y),title:`Search for user`}:{"aria-label":`Clear selected user`,color:`red`,icon:`x`,onClick:A,title:`Clear selected user`}),className:`users-input`,disabled:E,input:(0,_.jsx)(`input`,{"data-lpignore":`true`,disabled:!!f||E,placeholder:`Username`,type:`search`}),loading:E,onChange:e=>b(e.target.value),onKeyUp:e=>e.key===`Enter`?w(y):``,placeholder:`Username`,ref:d,size:`big`})]}),E?(0,_.jsx)(l,{active:!0,className:`search-loader`,inline:`centered`,size:`big`}):(0,_.jsx)(`div`,{children:T?(0,_.jsxs)(`span`,{children:[`Failed to retrieve information for `,C]}):f==null?(0,_.jsx)(g,{caption:`No user info to display`,icon:`users`}):(0,_.jsx)(r,{className:`users-user`,raised:!0,children:(0,_.jsx)(a.Group,{children:(0,_.jsx)(x,{...f})})})})]})};export{C as default};