1import{u as M,j as e,t as z,b as be,V as ie,v as ye}from"./index-CzUdFIfx.js";import{a5 as oe,a as i,J as le,n as G,g as K,D as je,l as se,aJ as ne,o as Ne}from"./lucide-B3R938yJ.js";import{c as ke}from"./PageShell-DioJZOca.js";import{A as W,C as ce,a as Ie,m as J}from"./ChatThread-NkVbZS9p.js";import"./mediaUrl-BJVXrBr9.js";const Ce=t=>t?`@${String(t).replace(/^@/,"")}`:"",_e=t=>{if(!t)return"";const n=(Date.now()-new Date(t).getTime())/1e3;return n<60?"now":n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`},ae={draft:"border-amber-300 text-amber-700",live:"border-emerald-300 text-emerald-700",paused:"border-[var(--border-default)] text-[var(--text-muted)]"},$e={proof_review:"Proof waiting for your review",appeal:"Appealing a decision",quote_proposed:"Sent you a quote",quote_received:"Proposed a price",accepted_waiting:"Accepted â delivering",accepted_deliver:"You accepted â deliver to finish",needs_changes:"Changes requested â their move",needs_changes_mine:"Changes requested â your move",chatting:"New message",discussing:"In conversation",in_review:"Reviewing your proof",appeal_sent:"Your appeal is in review",paid:"Paid",paid_mine:"You were paid",rejected:"Closed as rejected",rejected_mine:"Not approved",declined:"Declined the invite",expired:"Invite expired",update:"Sent an update",admin_update:"Chesto sent an update",claim_support:"Chesto support thread",seat_claimed:"Reserved a seat â no proof yet",seat_finalized:"Seat finalized"},Se=({member:t,selected:n,onSelect:r})=>{const c=M(),d=!!(t.threadId||t.counterparty?.userId),x=t.actionOwner==="you",a=$e[t.state]||"Open the conversation";return e.jsxs("button",{type:"button",disabled:!d,onClick:()=>d&&r(t),className:`grid w-full grid-cols-[32px_1fr_auto] items-center gap-2.5 py-2 pl-6 text-left transition ${n?"text-[var(--accent)] shadow-[inset_2px_0_0_var(--accent)]":d?"hover:bg-[var(--control-hover)]":"cursor-default opacity-75"}`,children:[e.jsx(W,{url:t.counterparty?.avatar,name:t.counterparty?.name,seed:t.counterparty?.handle||t.counterparty?.userId||t.threadId,size:32}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13.5px] font-medium leading-tight text-[var(--text-primary)]",children:t.counterparty?.name||c("Worker")}),t.counterparty?.handle&&e.jsx("span",{className:"truncate text-[11px] text-[var(--text-muted)]",children:Ce(t.counterparty.handle)}),x&&e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--accent)]"})]}),e.jsx("span",{className:"mt-0.5 block truncate text-[12px] leading-snug text-[var(--text-muted)]",children:c(a)})]}),e.jsx("span",{className:"self-start pt-0.5 font-mono text-[10.5px] text-[var(--text-muted)]",children:_e(t.activityAt)})]})},Re=({node:t,expanded:n,onToggle:r,onSelectMember:c,selectedMemberKey:d,memberKeyOf:x})=>{const a=M(),p=t.members.length>0;return e.jsxs("div",{className:"border-b border-[var(--border-subtle)]",children:[e.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center gap-2 py-2.5 text-left transition hover:bg-[var(--control-hover)]",children:[e.jsx(oe,{className:`h-3.5 w-3.5 shrink-0 text-[var(--text-muted)] transition-transform ${n?"rotate-0":"-rotate-90"}`}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium leading-tight text-[var(--text-primary)]",children:t.title}),e.jsx("span",{className:"mt-0.5 block truncate text-[11.5px] text-[var(--text-muted)]",children:t.counts.needsYou>0?a("{count} need you",{count:t.counts.needsYou}):p?a("{count} people",{count:t.counts.people}):a("No conversations yet")})]}),t.lifecycle&&t.lifecycle!=="live"&&e.jsx("span",{className:`shrink-0 rounded-full border px-2 py-0.5 text-[10px] uppercase tracking-[0.08em] ${ae[t.lifecycle]||ae.paused}`,children:t.lifecycle}),t.counts.needsYou>0&&e.jsx("span",{className:"shrink-0 rounded-full bg-[var(--accent)] px-1.5 py-0.5 font-mono text-[10px] font-semibold leading-none text-white",children:t.counts.needsYou})]}),n&&p&&e.jsx("div",{className:"pb-1.5",children:t.members.map((m,h)=>e.jsx(Se,{member:m,selected:x(m)===d,onSelect:c},m.threadId||`${m.counterparty?.userId||"anon"}-${h}`))}),n&&!p&&e.jsx("p",{className:"pb-3 pl-6 text-[12px] text-[var(--text-muted)]",children:a("When someone claims or submits, they appear here.")})]})},re=({children:t,n})=>e.jsxs("div",{className:"pb-1 pt-4 text-[11px] font-semibold uppercase tracking-[0.14em] text-[var(--text-muted)]",children:[t," ",e.jsx("span",{className:"font-mono opacity-70",children:n})]}),Te=({tree:t,expandedIds:n,onToggleNode:r,onSelectMember:c,selectedMemberKey:d,memberKeyOf:x,query:a=""})=>{const p=M(),m=g=>a?[g.title,...g.members.flatMap(I=>
1[I.counterparty?.name,I.counterparty?.handle])].filter(Boolean).join(" ").toLowerCase().includes(a):!0,h=(t?.publishing||[]).filter(m),u=(t?.working||[]).filter(m);if(!h.length&&!u.length)return null;const f=g=>e.jsx(Re,{node:g,expanded:n.has(g.taskId)||!!a,onToggle:()=>r(g.taskId),onSelectMember:j=>c(j,g),selectedMemberKey:d,memberKeyOf:x},g.taskId);return e.jsxs(e.Fragment,{children:[h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(re,{n:h.length,children:p("Publishing")}),h.map(f)]}),u.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(re,{n:u.length,children:p("Working on")}),u.map(f)]})]})},H="mx-auto w-full max-w-[820px]",Le=({thread:t,onBack:n,onOpenTask:r})=>{const c=M(),[d,x]=i.useState(null),[a,p]=i.useState(""),m=t?.taskId||"",h=async()=>{try{const f=await z.getOne(m,{forceRefresh:!0});x((f.taskClaim?.messages||[]).filter(J)),p("")}catch(f){p(f.message||"Conversation could not be loaded."),x([])}};if(i.useEffect(()=>{x(null),p(""),m&&h()},[m]),!t)return null;const u=async f=>{await z.sendClaimMessage(m,f),await h()};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-[var(--border-subtle)] px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:`${H} flex items-center gap-3 py-4`,children:[e.jsx("button",{type:"button",onClick:n,className:"grid h-9 w-9 shrink-0 place-items-center rounded-full text-[var(--text-muted)] hover:bg-[var(--control-hover)] lg:hidden","aria-label":c("Back to conversations"),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(W,{name:"Chesto Support",seed:t.taskId,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"truncate text-[16px] font-semibold leading-tight text-[var(--text-primary)]",children:c("Chesto Support")}),e.jsx("p",{className:"mt-0.5 truncate text-[13px] text-[var(--text-muted)]",children:t.taskTitle})]}),e.jsxs("button",{type:"button",onClick:()=>r(t),className:"inline-flex shrink-0 items-center gap-1.5 text-xs font-semibold text-[var(--text-muted)] hover:text-[var(--accent)]",children:[c("Open task")," ",e.jsx(G,{className:"h-3.5 w-3.5"})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 sm:px-6 lg:px-8",children:e.jsx("div",{className:H,children:d===null?e.jsxs("div",{className:"flex items-center gap-2 py-12 text-sm text-[var(--text-muted)]",children:[e.jsx(K,{className:"h-4 w-4 animate-spin"})," ",c("Loading conversationâ¦")]}):a?e.jsx("p",{className:"py-12 text-sm text-[var(--danger)]",children:a}):d.length===0?e.jsx("p",{className:"py-12 text-sm text-[var(--text-muted)]",children:c("No messages yet.")}):e.jsx("div",{className:"py-6",children:e.jsx(ce,{messages:d,viewerRole:"worker",counterparty:{name:"Chesto Support"}})})})}),e.jsx("div",{className:"border-t border-[var(--border-subtle)] px-4 py-4 sm:px-6 lg:px-8",children:e.jsx("div",{className:H,children:e.jsx(Ie,{onSend:u,placeholder:c("Reply to Chesto Supportâ¦"),allowImages:!1,disabled:d===null||!!a},t.id)})})]})},de=15e3,ue=t=>t?`@${String(t).replace(/^@/,"")}`:"",Me=t=>t?.counterparty?.name||"them";function Ee(t){const n=Me(t);switch(t.state){case"proof_review":return"Proof is waiting for your review.";case"appeal":return`${n} is appealing a decision.`;case"quote_proposed":return`${n} countered at $${Number(t.quotedUsdc||0).toFixed(0)}.`;case"accepted_waiting":return`Accepted â waiting for ${n} to deliver.`;case"needs_changes":return`Changes requested â waiting on ${n}.`;case"discussing":return"In conversation.";case"chatting":return`${n} replied.`;case"paid":return`Done â paid $${Number(t.reward||0).toFixed(2)}.`;case"rejected":return"This one was closed as rejected.";case"declined":return`${n} declined this invite.`;case"in_review":return`Waiting for ${n} to review your proof.`;case"appeal_sent":return"Your appeal is being reviewed.";case"needs_changes_mine":return`${n} asked for changes â your move.`;case"update":return`${n} sent an update on this task.`;case"admin_update":return"Chesto admin sent an update on this task.";case"paid_mine":return`Done â you were paid $${Number(t.reward||0).toFixed(2)}.`;case"rejected_mine":return"Your submission was not approved.";
1case"accepted_deliver":return"You accepted â deliver to finish.";case"quote_received":return`${n} proposed $${Number(t.quotedUsdc||0).toFixed(0)}.`;case"expired":return"This invite expired.";case"action_access":return"Your Action access changed.";case"action_invitation":return"An Action invitation is waiting for your decision.";case"claim_support":return"Chesto support thread on this task.";default:return"Open the conversation."}}function xe(t){if(!t?.deadlineAt)return null;const n=new Date(t.deadlineAt).getTime()-Date.now();if(n<=0)return{text:`${Math.max(1,Math.round(-n/36e5))}h overdue`,hot:!0};const r=Math.floor(n/36e5);return{text:r>=1?`${r}h left to review`:`${Math.max(1,Math.round(n/6e4))}m left to review`,hot:!1}}const Ye=t=>{if(!t)return"";const n=(Date.now()-new Date(t).getTime())/1e3;return n<60?"now":n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`},Ae=t=>{if(!t)return null;const n=new Date(t);if(Number.isNaN(n.getTime()))return null;const r=n.getTime()<=Date.now();return{expired:r,text:r?"The update window has expired.":`Update by ${n.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}. Your slot is held until then.`}},F=({thread:t,selected:n,onSelect:r})=>{const c=xe(t.sla),d=t.isAppeal||c?.hot;return e.jsxs("button",{type:"button",onClick:()=>r(t),className:`grid w-full grid-cols-[40px_1fr_auto] items-center gap-3 border-b border-[var(--border-subtle)] py-2.5 text-left transition ${n?"text-[var(--accent)] shadow-[inset_2px_0_0_var(--accent)]":"hover:bg-[var(--control-hover)]"}`,children:[e.jsx(W,{url:t.counterparty?.avatar,name:t.counterparty?.name,seed:t.counterparty?.handle||t.taskId}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-medium leading-tight text-[var(--text-primary)]",children:t.counterparty?.name||"Conversation"}),t.counterparty?.handle&&e.jsx("span",{className:"truncate text-[11px] font-normal text-[var(--text-muted)]",children:ue(t.counterparty.handle)}),d&&e.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-[var(--accent)]"})]}),e.jsx("span",{className:"mt-0.5 block truncate text-[12.5px] leading-snug text-[var(--text-muted)]",children:t.reviewInstruction?.reason||t.lastMessage?.text||t.taskTitle})]}),e.jsx("span",{className:"self-start pt-0.5 font-mono text-[11px] text-[var(--text-muted)]",children:Ye(t.activityAt)})]})},B=({children:t,n})=>e.jsxs("div",{className:"pb-1 pt-4 text-[11px] font-semibold uppercase tracking-[0.14em] text-[var(--text-muted)]",children:[t," ",e.jsx("span",{className:"font-mono opacity-70",children:n})]}),V="mx-auto w-full max-w-[820px]",De=({conversation:t,onBack:n,onOpenTask:r,onOpenChat:c,onConversationChanged:d})=>{const x=M(),[a,p]=i.useState(null),[m,h]=i.useState(!1),[u,f]=i.useState(""),g=i.useRef(null),j=t?.id||"",I=t?.role||"",R=t?.source||"",E=t?.submissionId||"",O=t?.taskId||"";if(i.useEffect(()=>{if(!j)return;let b=!0;if(p(null),f(""),h(!0),["notification","action_invitation"].includes(R))return p({viewerRole:"system",messages:t.messages||[]}),h(!1),t.notificationId&&t.unread&&ie.markNotificationRead(t.notificationId).then(()=>Promise.resolve(d?.()).catch(()=>{})).catch(()=>{}),()=>{b=!1};let N=!1;const L=async({initial:_=!1}={})=>{if(!N){N=!0;try{const v=R==="public"?await ye.getMessages(E).then(S=>({viewerRole:S.role||I,messages:(S.messages||[]).filter(J)})):await z.markPrivateAssignmentRead(O).then(S=>({viewerRole:S.readerRole==="actor"?"worker":S.readerRole||I,messages:(S.actorResponse?.messages||[]).filter(J)}));if(!b)return;p(v),f(""),_&&R==="private"&&Promise.resolve(d?.()).catch(()=>{})}catch(v){b&&_&&f(v.message||"Conversation could not be loaded.")}finally{N=!1,b&&h(!1)}}};L({initial:!0});const y=()=>{R==="public"&&document.visibilityState==="visible"&&L()},k=window.setInterval(y,de);return window.addEventListener("focus",y),document.addEventListener("visibilitychange",y),()=>{b=!1,window.clearInterval(k),window.removeEventListener("focus",y),document.removeEventListener("visibilitychange",y)}},[j,I,R,E,O,d]),i.useEffect(()=>{g.current?.scrollIntoView({block:"end"})},[a?.messages?.length]),!t)return e.jsx("div",{className:"grid flex-1 place-items-center text-[14px] text-[var(--text-muted)]",children:x("Select a conversation")});const Y=a?.messages||[],T=xe(t.sla),C=t.reviewInstruction||null,$=Ae(C?.expiresAt);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-b border-[var(--border-subtle)] px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:`${V} flex items-center gap-3 py-4`,children:[e.jsx("button",{type:"button",onClick:n,className:"grid h-9 w-9 shrink-0 place-items-center rounded-full text-[var(--text-muted)] hover:bg-[var(--control-hover)] lg:hidden","aria-label":x("Back to conversations"),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(W,{url:t.counterparty?.avatar,name:t.counterparty?.name,seed:t.counterparty?.handle||t.taskId,size:44}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("h3",{className:"truncate text-[16px] font-semibold leading-tight tracking-[-0.01em] text-[var(--text-primary)]",children:t.counterparty?.name}),t.counterparty?.handle&&e.jsx("span",{className:"truncate text-xs text-[var(--text-muted)]",children:ue(t.counterparty.handle)})]}),t.link?e.jsxs("button",{type:"button",onClick:()=>r(t),className:"mt-0.5 block max-w-full truncate text-left text-[13px] text-[var(--text-muted)] transition hover:text-[var(--accent)] hover:underline",title:x("Open the linked task"),children:[t.taskTitle,t.reward>0?` · $${Number(t.reward).toFixed(2)}`:""]}):e.jsxs("p",{className:"mt-0.5 truncate text-[13px] text-[var(--text-muted)]",children:[t.taskTitle,t.reward>0?` · $${Number(t.reward).toFixed(2)}`:""]})]}),t.link&&e.jsxs("button",{type:"button",onClick:()=>r(t),className:"inline-flex shrink-0 items-center gap-1.5 text-xs font-semibold text-[var(--text-muted)] hover:text-[var(--accent)]",children:[["notification","action_invitation"].includes(t.source)?"Open":"Open task"," ",e.jsx(G,{className:"h-3.5 w-3.5"})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:V,children:[e.jsxs("div",{className:"border-b border-[var(--border-subtle)] pb-5 pt-6",children:[e.jsx("p",{className:"font-serif text-[19px] leading-[1.4] tracking-[-0.01em] text-[var(--text-primary)]",children:Ee(t)}),T&&e.jsx("p",{className:`mt-1.5 text-[12px] ${T.hot?"text-[var(--accent)]":"text-[var(--text-muted)]"}`,children:T.text})]}),C&&e.jsx("div",{className:"border-b border-[var(--border-subtle)] py-6",children:e.jsxs("div",{className:"border-l-2 border-[var(--accent)] pl-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.14em] text-[var(--accent)]",children:C.kind==="changes_required"?"What needs to change":"Why it was not approved"}),e.jsx("p",{className:"mt-2 max-w-[680px] text-[14px] leading-relaxed text-[var(--text-primary)]",children:C.reason}),$&&e.jsx("p",{className:`mt-2 text-[12px] ${$.expired?"text-[var(--danger)]":"text-[var(--text-muted)]"}`,children:$.text}),e.jsxs("button",{type:"button",onClick:()=>r(t),className:"mt-4 inline-flex items-center gap-1.5 text-[13px] font-semibold text-[var(--accent)] hover:underline",children:[C.kind==="changes_required"?"Update proof":"Open task"," ",e.jsx(G,{className:"h-3.5 w-3.5"})]})]})}),m?e.jsxs("div",{className:"flex items-center gap-2 py-12 text-sm text-[var(--text-muted)]",children:[e.jsx(K,{className:"h-4 w-4 animate-spin"})," ",x("Loading conversationâ¦")]}):u?e.jsx("p",{className:"py-12 text-sm text-[var(--danger)]",children:u}):Y.length===0&&!C?e.jsx("p",{className:"py-12 text-sm text-[var(--text-muted)]",children:x("No messages yet. Start the conversation below.")}):Y.length>0?e.jsxs("div",{className:"py-6",children:[e.jsx(ce,{messages:Y,viewerRole:a?.viewerRole||t.role,counterparty:t.counterparty}),e.jsx("div",{ref:g})]}):null]})}),t.counterparty?.userId&&!["notification","action_invitation"].includes(t.source)&&e.jsx("div",{className:"border-t border-[var(--border-subtle)] px-4 py-4 sm:px-6 lg:px-8",children:e.jsx("div",{className:V,children:e.jsxs("button",{type:"button",onClick:()=>c?.(t.counterparty.userId),className:"inline-flex items-center gap-2 rounded-full border border-[var(--border-default)] px-4 py-2 text-[13px] font-semibold text-[var(--text-primary)] transition hover:border-[var(--accent)] hover:text-[var(--accent)]",children:[e.jsx(Ne,{className:"h-4 w-4"}),x("Chat with {name} in the Ocean",{name:t.counterparty?.name||"them"})]})})})]})},Ue=()=>{const t=M(),n=be(),[r,c]=i.useState(null),[d,x]=i.useState(!0),[a,p]=i.useState(null),[m,h]=i.useState(!1),[u,f]=i.useState(""),[g,j]=i.useState(!1),[I,R]=i.useState([]),[E,O]=i.useState("tasks"),[Y,T]=i.useState(()=>new Set),C=i.useRef(!1),$=i.useRef(0),b=i.useCallback(async({initial:s=!1}={})=>{const l=++$.current;s&&x(!0);try{const o=await ie.getThreads();if(l!==$.current)return;c(o);const D=[...o.groups?.needsYou||[],...o.groups?.waiting||[],...o.groups?.done||[]];!C.current&&o.tree&&(C.current=!0,T(new Set([...(o.tree.publishing||[]).filter(w=>w.counts.needsYou>0).map(w=>w.taskId),...(o.tree.working||[]).filter(w=>w.counts.needsYou>0).map(w=>w.taskId)])));const Z=s&&typeof window<"u"?new URLSearchParams(window.location.search):null,U=Z?.get("c")||null,ee=Z?.get("user")||null;if(ee){n(`/chat?with=${encodeURIComponent(ee)}`,{replace:!0});return}const te=!!(U&&D.some(w=>w.id===U));te&&j(!0),p(w=>te?U:w&&D.some(we=>we.id===w)?w:typeof window<"u"&&window.matchMedia("(min-width: 1024px)").matches&&D[0]?.id||null)}catch{l===$.current&&s&&c({groups:{needsYou:[],waiting:[],done:[]},summary:{}})}finally{l===$.current&&x(!1)}},[n]);i.useEffect(()=>{b({initial:!0});const s=()=>{document.visibilityState==="visible"&&b()},l=window.setInterval(s,de);return window.addEventListener("focus",s),document.addEventListener("visibilitychange",s),(
1)=>{window.clearInterval(l),window.removeEventListener("focus",s),document.removeEventListener("visibilitychange",s)}},[b]);const N=i.useMemo(()=>{const s=r?.groups||{};return[...s.needsYou||[],...s.waiting||[],...s.done||[]]},[r]),L=N.find(s=>s.id===a)||null,y=r?.groups||{needsYou:[],waiting:[],done:[]},k=i.useMemo(()=>{const s=u.trim().toLowerCase(),l=o=>!s||[o.counterparty?.name,o.counterparty?.handle,o.taskTitle,o.lastMessage?.text,o.reviewInstruction?.reason].filter(Boolean).join(" ").toLowerCase().includes(s);return{needsYou:y.needsYou.filter(l),waiting:y.waiting.filter(l),done:y.done.filter(l)}},[y.done,y.needsYou,y.waiting,u]),_=i.useMemo(()=>u.trim()?[]:I.map(s=>N.find(l=>l.id===s)).filter(s=>s&&s.actionOwner!=="you"),[N,u,I]),v=i.useMemo(()=>{if(!_.length)return k;const s=new Set(_.map(o=>o.id)),l=o=>o.filter(D=>!s.has(D.id));return{needsYou:l(k.needsYou),waiting:l(k.waiting),done:l(k.done)}},[k,_]),S=k.needsYou.length+k.waiting.length+k.done.length,Q=m||!!u.trim(),pe=i.useCallback(({keepVisible:s=!1}={})=>(s&&a&&R(l=>[a,...l.filter(o=>o!==a)].slice(0,5)),b()),[b,a]),X=s=>{if(!s?.link)return;const l=s.role!=="worker"&&s.source==="private"&&s.contractId?`${s.link}?thread=${s.taskId}`:s.link;n(l)},A=s=>{p(s.id),j(!0)},me=s=>{s.threadId?(p(s.threadId),j(!0)):s.counterparty?.userId&&n(`/chat?with=${encodeURIComponent(s.counterparty.userId)}`)},he=s=>T(l=>{const o=new Set(l);return o.has(s)?o.delete(s):o.add(s),o}),fe=s=>s.threadId||(s.counterparty?.userId?`u:${s.counterparty.userId}`:null),ge=a,q=u.trim().toLowerCase(),P=i.useMemo(()=>N.filter(s=>["notification","action_invitation"].includes(s.source)).filter(s=>!q||[s.taskTitle,s.lastMessage?.text].filter(Boolean).join(" ").toLowerCase().includes(q)),[N,q]),ve=!((r?.tree?.publishing?.length||0)+(r?.tree?.working?.length||0));return e.jsx(ke,{className:"flex flex-col",children:d?e.jsx("div",{className:"grid flex-1 place-items-center py-32 text-[var(--text-muted)]",children:e.jsx(K,{className:"h-5 w-5 animate-spin"})}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col lg:grid lg:grid-cols-[minmax(320px,380px)_1fr]",children:[e.jsxs("aside",{className:`${g?"hidden lg:flex":"flex"} min-h-0 flex-col border-[var(--border-subtle)] lg:border-r`,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 pb-1 pt-5",children:[e.jsx("div",{className:"flex items-center gap-3",children:[["tasks",t("Tasks")],["queue",t("Queue")]].map(([s,l])=>e.jsx("button",{type:"button",onClick:()=>O(s),className:`text-[11px] font-semibold uppercase tracking-[0.16em] transition ${E===s?"text-[var(--text-primary)]":"text-[var(--text-muted)] hover:text-[var(--text-primary)]"}`,children:l},s))}),e.jsx("button",{type:"button",onClick:()=>b(),className:"grid h-8 w-8 place-items-center rounded-full text-[var(--text-muted)] transition hover:bg-[var(--control-hover)] hover:text-[var(--text-primary)]","aria-label":t("Refresh"),children:e.jsx(je,{className:"h-[14px] w-[14px]"})})]}),e.jsxs("label",{className:"mx-5 mt-3 flex items-center gap-2 border-b border-[var(--border-default)] pb-2 focus-within:border-[var(--accent)]",children:[e.jsx(se,{className:"h-4 w-4 shrink-0 text-[var(--text-muted)]"}),e.jsx("input",{value:u,onChange:s=>f(s.target.value),placeholder:t("Find a user or conversation"),className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--text-primary)] outline-none focus-visible:outline-none placeholder:text-[var(--text-muted)]"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 pb-6 lg:pb-3",children:E==="tasks"?e.jsxs(e.Fragment,{children:[ve&&P.length===0&&e.jsxs("div",{className:"grid place-items-center gap-2.5 py-24 text-center text-[var(--text-muted)]",children:[e.jsx(ne,{className:"h-7 w-7 opacity-70",strokeWidth:1.5}),e.jsx("p",{className:"text-[14px]",children:t("Nothing here yet.")}),e.jsx("p",{className:"max-w-[240px] text-[12.5px] leading-relaxed",children:t("Tasks you publish or work on appear here, with every conversation under them.")})]}),e.jsx(Te,{tree:r?.tree,expandedIds:Y,onToggleNode:he,onSelectMember:me,selectedMemberKey:ge,memberKeyOf:fe,query:q}),P.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(B,{n:P.length,children:t("Updates")}),P.map(s=>e.jsx(F,{thread:s,selected:s.id===a,onSelect:A},s.id))]})]}):e.jsxs(e.Fragment,{children:[N.length===0&&e.jsxs("div",{className:"grid place-items-center gap-2.5 py-24 text-center text-[var(--text-muted)]",children:[e.jsx(ne,{className:"h-7 w-7 opacity-70",strokeWidth:1.5}),e.jsx("p",{className:"text-[14px]",children:t("Nothing waiting on you.")}),e.jsx("p",{className:"max-w-[240px] text-[12.5px] leading-relaxed",children:t("When a creator replies or a worker submits proof, it will appear here.")})]}),N.length>0&&S===0&&e.jsxs("div",{className:"grid place-items-center gap-2 py-20 text-center text-[var(--text-muted)]",children:[e.jsx(se,{className:"h-6 w-6 opacity-70"}),e.jsxs("p",{className:"text-sm",children:["No conversations match â",u.trim(),"â."]})]}),_.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(B,{n:_.length,children:t("Current")}),_.map(s=>e.jsx(F,{thread:s,selected:s.id===a,onSelect:A},s.id))]}),v.needsYou.length>0&&e.jsx(B,{n:v.needsYou.length,children:t("Needs you")}),v.needsYou.map(s=>e.jsx(F,{thread:s,selected:s.id===a,onSelect:A},s.id)),v.waiting.length>0&&e.jsx(B,{n:v.waiting.length,children:t("Waiting on them")}),v.waiting.map(s=>e.jsx(F,{thread:s,selected:s.id===a,onSelect:A},s.id)),(u.trim()?v.done.length>0:r?.summary?.done>0)&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>h(s=>!s),className:"mt-3 flex w-full items-center gap-1.5 py-2 text-[11px] font-semibold uppercase tracking-[0.12em] text-[var(--text-muted)]",children:[e.jsx(oe,{className:`h-3.5 w-3.5 transition-transform ${Q?"rotate-0":"-rotate-90"}`}
1)," ",t("Done")," ",e.jsx("span",{className:"font-mono normal-case",children:u.trim()?v.done.length:r.summary.done})]}),Q&&v.done.map(s=>e.jsx("div",{className:"opacity-70",children:e.jsx(F,{thread:s,selected:s.id===a,onSelect:A})},s.id))]})]})})]}),e.jsx("section",{className:`${g?"flex":"hidden"} min-h-0 flex-1 flex-col lg:flex`,children:L?.source==="claim"?e.jsx(Le,{thread:L,onBack:()=>j(!1),onOpenTask:X}):e.jsx(De,{conversation:L,onBack:()=>j(!1),onOpenTask:X,onOpenChat:s=>n(`/chat?with=${encodeURIComponent(s)}`),onConversationChanged:pe})})]})})};export{Ue 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.