1import{r as F,j as e}from"./react-core-C8fV_NsC.js";import{d as R,e as $,L as k}from"./router-query-BGj4wlm5.js";import{y as E,H as P,v as S,a7 as L,a8 as z,I as T}from"./index-BJ2snL0V.js";import{u as O,e as X,A as q,B as y,C as _}from"./AppHeader-Gk9z1gy0.js";import{t as d,c as Y,g as A,e as H,m as D,a as N,b as U,R as B,d as K}from"./RestartAllowanceNotice-DuXof85G.js";import{A as Q,a as G,b as V,c as J,d as W,e as Z,f as ee,g as te,h as se}from"./alert-dialog-C0K_d6Cp.js";import{P as ae}from"./plus-BJDtKDI1.js";import{L as M}from"./loader-circle-a_TSJMxf.js";import{C as ne}from"./circle-check-CoYwZnFY.js";import"./ui-heavy-ltr3QpaI.js";import"./clerk-DN3aFtnr.js";import"./App-n5S5yqlg.js";function w(t,s){const a=d(t),o=d(s),n=a.getTime()-o.getTime();return n<0?-1:n>0?1:n}function re(t){return Y(t,Date.now())}function ie(t,s){const a=d(t),o=d(s),n=a.getFullYear()-o.getFullYear(),u=a.getMonth()-o.getMonth();return n*12+u}function oe(t){return s=>{const o=(t?Math[t]:Math.trunc)(s);return o===0?0:o}}function le(t,s){return+d(t)-+d(s)}function ce(t){const s=d(t);return s.setHours(23,59,59,999),s}function de(t){const s=d(t),a=s.getMonth();return s.setFullYear(s.getFullYear(),a+1,0),s.setHours(23,59,59,999),s}function ue(t){const s=d(t);return+ce(s)==+de(s)}function fe(t,s){const a=d(t),o=d(s),n=w(a,o),u=Math.abs(ie(a,o));let m;if(u<1)m=0;else{a.getMonth()===1&&a.getDate()>27&&a.setDate(30),a.setMonth(a.getMonth()-n*u);let r=w(a,o)===-n;ue(d(t))&&u===1&&w(t,o)===1&&(r=!1),m=n*(u-Number(r))}return m===0?0:m}function me(t,s,a){const o=le(t,s)/1e3;return oe(a?.roundingMethod)(o)}function he(t,s,a){const o=U(),n=a?.locale??o.locale??H,u=2520,m=w(t,s);if(isNaN(m))throw new RangeError("Invalid time value");const r=Object.assign({},a,{addSuffix:a?.addSuffix,comparison:m});let i,h;m>0?(i=d(s),h=d(t)):(i=d(t),h=d(s));const f=me(h,i),j=(A(h)-A(i))/1e3,c=Math.round((f-j)/60);let b;if(c<2)return a?.includeSeconds?f<5?n.formatDistance("lessThanXSeconds",5,r):f<10?n.formatDistance("lessThanXSeconds",10,r):f<20?n.formatDistance("lessThanXSeconds",20,r):f<40?n.formatDistance("halfAMinute",0,r):f<60?n.formatDistance("lessThanXMinutes",1,r):n.formatDistance("xMinutes",1,r):c===0?n.formatDistance("lessThanXMinutes",1,r):n.formatDistance("xMinutes",c,r);if(c<45)return n.formatDistance("xMinutes",c,r);if(c<90)return n.formatDistance("aboutXHours",1,r);if(c<D){const x=Math.round(c/60);return n.formatDistance("aboutXHours",x,r)}else{if(c<u)return n.formatDistance("xDays",1,r);if(c<N){const x=Math.round(c/D);return n.formatDistance("xDays",x,r)}else if(c<N*2)return b=Math.round(c/N),n.formatDistance("aboutXMonths",b,r)}if(b=fe(h,i),b<12){const x=Math.round(c/N);return n.formatDistance("xMonths",x,r)}else{const x=b%12,v=Math.trunc(b/12);return x<3?n.formatDistance("aboutXYears",v,r):x<9?n.formatDistance("overXYears",v,r):n.formatDistance("almostXYears",v+1,r)}}function xe(t,s){return he(t,re(t),s)}function Te(){const[,t]=R(),[s,a]=F.useState("active"),{data:o,isLoading:n}=E({query:{queryKey:T(),refetchInterval:i=>i.state.data?.some(f=>f.status==="active"&&f.tasks.some(j=>j.status==="queued"||j.status==="running"))?1e4:!1}}),u=O(),m=X(),r=o?.filter(i=>i.status===s)??[];return e.jsxs("div",{className:"min-h-[100dvh] flex flex-col bg-[#FFF8F3]",children:[e.jsx(q,{}),e.jsxs("main",{className:"flex-1 max-w-5xl w-full mx-auto px-4 sm:px-6 lg:px-8 py-10",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-bitter text-3xl font-bold text-[#1A1A1A]",children:"Projects"}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Assign deep research tasks to your ROARANGE.ai Advisorâ¢."})]}),e.jsxs(y,{onClick:()=>t("/projects/new"),className:"bg-[#F53805] hover:bg-[#D63104] text-white rounded-full px-6 font-semibold shadow-md whitespace-nowrap","data-testid":"button-new-project",children:[e.jsx(ae,{size:18,className:"mr-2"}),"Assign work"]})]}),e.jsx("div",{className:"flex items-center gap-2 mb-6 border-b border-[#E8E0D8]",children:["active","completed","archived"].map(i=>e.jsx("button",{onClick:()=>a(i),className:`px-4 py-3 text-sm font-semibold capitalize tracking-wide transition-colors border-b-2 -mb-px ${s===i?"border-[#F53805] text-[#F53805]":"border-transparent text-gray-500 hover:text-[#1A1A1A]"}`,"data-testid":`filter-${i}`,children:i},i))}),n?e.jsx("div",{className:"space-y-4",children:[1,2,3].map(i=>
1e.jsx("div",{className:"h-32 bg-white border border-[#E8E0D8] rounded-2xl animate-pulse"},i))}):r.length===0?e.jsxs("div",{className:"bg-white rounded-3xl border border-dashed border-[#E8E0D8] p-12 text-center",children:[e.jsx(P,{size:32,className:"mx-auto text-[#F53805] mb-4 opacity-50"}),e.jsxs("h3",{className:"font-bitter text-xl font-bold text-[#1A1A1A] mb-2",children:["No ",s," projects"]}),e.jsx("p",{className:"text-gray-600 max-w-md mx-auto mb-6",children:s==="active"?"Assign research, due diligence, or market analysis to Ari while you focus on the business.":`You have no ${s} projects.`}),s==="active"&&e.jsx(y,{onClick:()=>t("/projects/new"),variant:"outline",className:"border-[#F53805] text-[#F53805] rounded-full hover:bg-[#FFF8F3]",children:"Start your first project"})]}):e.jsx("div",{className:"space-y-4",children:r.map(i=>e.jsx(ge,{project:i,billing:u,usage:m,onViewBilling:()=>t("/billing")},i.id))})]})]})}function ge({project:t,billing:s,usage:a,onViewBilling:o}){const n=$(),{toast:u}=S(),m=L(),[r,i]=F.useState(!1),h=t.tasks.length,f=t.tasks.filter(l=>l.status==="ready").length,j=t.tasks.filter(l=>l.status==="running").length,c=t.tasks.filter(l=>l.status==="queued").length,b=t.tasks.filter(l=>l.status==="failed").length,x=t.tasks.filter(l=>l.status==="needs_input").length,v=h===0?0:Math.round(f/h*100),g=t.tasks.filter(l=>l.status==="ready"),I=async()=>{if(!(g.length===0||r)){i(!0);try{const l=g.map(C=>C.id),p=await m.mutateAsync({id:t.id,data:{taskIds:l}});await n.invalidateQueries({queryKey:T()}),p.skippedTaskIds.length===0?u({title:"Project restarted",description:`${p.restartedTaskIds.length} task${p.restartedTaskIds.length===1?"":"s"} moved to Active using ${p.aiMessagesUsed} AI message${p.aiMessagesUsed===1?"":"s"}.`}):p.restartedTaskIds.length>0?u({title:`${p.restartedTaskIds.length} of ${l.length} tasks restarted`,description:`${p.skippedTaskIds.length} task${p.skippedTaskIds.length===1?" was":"s were"} no longer eligible and were not queued. ${p.aiMessagesUsed} AI message${p.aiMessagesUsed===1?" was":"s were"} used.`,variant:"destructive"}):u({title:"Project could not restart",description:`No tasks were restarted and ${p.aiMessagesUsed} AI messages were used.`,variant:"destructive"})}catch(l){u({title:"Project could not restart",description:l instanceof Error?l.message:"No tasks were queued. Please refresh and try again.",variant:"destructive"})}finally{i(!1)}}};return e.jsx("article",{className:"bg-white border border-[#E8E0D8] rounded-2xl p-5 md:p-6 hover:shadow-lg hover:border-[#F53805]/40 transition-all group","data-testid":`project-card-${t.id}`,children:e.jsxs("div",{className:"flex flex-col md:flex-row md:items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h2",{className:"font-bitter text-xl font-bold truncate",children:e.jsx(k,{href:`/projects/${t.id}`,className:"text-[#1A1A1A] group-hover:text-[#F53805] transition-colors",children:t.title})}),t.status==="active"&&x>0?e.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full bg-orange-100 text-orange-800 text-xs font-bold uppercase tracking-wider border border-orange-200",children:"Action Needed"}):t.status==="active"&&(j>0||c>0)?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full bg-[#FFF8F3] text-[#F53805] text-xs font-bold uppercase tracking-wider border border-[#F53805]/20",children:[e.jsx(M,{size:12,className:"animate-spin"})," In progress"]}):null]}),e.jsx("p",{className:"text-gray-600 text-sm line-clamp-2 mb-4 leading-relaxed",children:t.objective}),e.jsxs("div",{className:"flex items-center gap-4 text-xs font-medium text-gray-500",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(z,{size:14})," Created ",xe(new Date(t.createdAt),{addSuffix:!0})]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ne,{size:14,className:f===h&&h>0?"text-green-600":""}),f,"/",h," tasks ready"]}),x>0&&e.jsxs("span",{className:"text-orange-700 font-bold",children:[x," waiting"]}),b>0&&e.jsxs("span",{className:"text-red-600 font-bold",children:[b," failed"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4 md:w-48 shrink-0 justify-end md:justify-center",children:[t.status==="active"&&e.jsxs("div",{className:"flex-1 max-w-[120px]",children:[e.jsxs("div",{className:"flex justify-between text-xs font-bold mb-1",children:[e.jsx("span",{className:"text-gray-500",children:"Progress"}),e.jsxs("span",{className:"text-[#1A1A1A]",children:[v,"%"]})]}),e.jsx("div",{className:"h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[#F53805] rounded-full transition-all duration-500",style:{width:`${v}%`}})})]}),t.status==="completed"&&g.length>0&&e.jsxs(Q,{children:[e.jsx(G,{asChild:!0,children:e.jsxs(y,{type:"button",onClick:()=>{a.refetch(),s.refetch()},disabled:r,className:"bg-[#F53805] hover:bg-[#D63104] text-white rounded-full whitespace-nowrap","data-testid":`button-run-project-again-${t.id}`,children:[r?e.jsx(M,{size:16,className:"mr-2 animate-spin"}):e.jsx(B,{size:16,className:"mr-2"}),"Run again · ",g.length," message",g.length===1?"":"s"]})}
1),e.jsxs(V,{className:"rounded-3xl border-[#E8E0D8]",children:[e.jsxs(J,{children:[e.jsx(W,{className:"font-bitter text-xl",children:"Run this Project again?"}),e.jsxs(Z,{className:"text-gray-600",children:[g.length," completed task",g.length===1?"":"s"," will restart and use exactly ",g.length," AI message",g.length===1?"":"s",". Tasks that are no longer eligible will not be queued."]})]}),e.jsx(K,{billing:s.data,usage:a.data,restartCount:g.length,isChecking:a.isFetching,isError:a.isError,onRetry:()=>{a.refetch()},onViewBilling:o}),e.jsxs(ee,{children:[e.jsx(te,{disabled:r,children:"Keep completed"}),e.jsx(se,{onClick:I,disabled:r||a.isFetching||!a.data,className:"bg-[#F53805] text-white hover:bg-[#D63104]",children:r?"Restartingâ¦":`Restart ${g.length} ${g.length===1?"task":"tasks"}`})]})]})]}),e.jsx(k,{href:`/projects/${t.id}`,"aria-label":`Open ${t.title}`,className:"inline-flex h-9 w-9 items-center justify-center rounded-full text-gray-400 hover:bg-[#FFF8F3] hover:text-[#F53805] transition-colors shrink-0",children:e.jsx(_,{size:20})})]})]})})}export{Te 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.