import{a as z,b as c,u as M,k as U,r as d,j as t,l as W,c as j,m as V,E as J,f as Z,d as P,i as Q,s as X}from"./index-CUDottTv.js";import{B as E}from"./badge-BOfEUuSW.js";import"./textarea-DAwdLdON.js";import{D as Y}from"./data-table-A2Iq_hk5.js";import{K as S,T as ee}from"./metric-card-DE3zVnFg.js";import{S as te}from"./status-dot-C1nxHZIG.js";import{D as se}from"./download-CwvkYJyJ.js";import{M as re}from"./message-square-Dwj0jRjI.js";import{D as oe}from"./dollar-sign-BDj484XE.js";import{C as ne}from"./clock-CmDPWLyG.js";import{S as ae}from"./square-C1plLKPb.js";import{P as ie}from"./play-Cx2BEZVZ.js";import"./sparkline-BYGr_Iny.js";import"./minus-BzY257S7.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const le=z("Eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ce=z("FolderKanban",[["path",{d:"M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z",key:"1fr9dc"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M12 10v2",key:"hh53o1"}],["path",{d:"M16 10v6",key:"1d6xys"}]]),L=[{id:"7d",label:"Last 7d"},{id:"30d",label:"Last 30d"},{id:"90d",label:"Last 90d"},{id:"all",label:"All"}];function de(r){const s=new Date;return s.setDate(s.getDate()-r),s.toISOString().split("T")[0]}function ue(){return new Date().toISOString().split("T")[0]}function T(r){return r==="all"?{}:{start:de(r==="7d"?7:r==="30d"?30:90),end:ue()}}function C(r){return`$${(r/1e6).toFixed(2)}`}function R(r){if(r<1)return"0m";if(r<60)return`${Math.round(r)}m`;const s=Math.floor(r/60),o=Math.round(r%60);return o>0?`${s}h ${o}m`:`${s}h`}function xe(r){return r?new Date(r).toLocaleDateString():"-"}function me(){const r=new Date().getHours();return r<12?"Good morning":r<17?"Good afternoon":"Good evening"}function A(r,s){const o=r.runtime_apps?JSON.parse(r.runtime_apps):[],a=Z(s,{runtimescopeProject:r.runtimescope_project??void 0,runtimeApps:o.length?o:void 0,name:r.name});return a.some(i=>i.isConnected)?"live":r.sdk_installed||a.length>0?"installed":"not-installed"}const pe={live:{label:"Live",variant:"green"},installed:{label:"SDK",variant:"blue"},"not-installed":{label:"-",variant:"default"}},ge=d.memo(function({projectId:s}){const o=P(u=>{var f;return((f=u.servers.get(s))==null?void 0:f.status)??"idle"}),a=o==="running"||o==="starting",i=async u=>{u.stopPropagation(),a?await Q(s):(P.getState().setOptimisticStarting(s),await X(s))};return t.jsx("button",{type:"button",onClick:i,className:j("inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium transition-colors cursor-pointer",a?"bg-green-500/15 text-green-400 hover:bg-red-500/15 hover:text-red-400":"bg-bg-surface text-text-muted hover:bg-bg-hover"),title:a?"Stop dev server":"Start dev server",children:a?t.jsxs(t.Fragment,{children:[t.jsx(ae,{size:10}),o==="starting"?"Starting...":"Stop"]}):t.jsxs(t.Fragment,{children:[t.jsx(ie,{size:10}),"Start"]})})});function fe(r){return[{key:"name",header:"Project",sortable:!0,render:s=>{const o=s,a=A(o,r);return t.jsxs("div",{className:"flex items-center gap-2",children:[a==="live"&&t.jsx(te,{color:"green",size:"sm",pulse:!0}),t.jsx("span",{className:"font-medium text-text-primary truncate max-w-[200px]",children:o.name})]})}},{key:"category",header:"Category",width:"110px",sortable:!0,render:s=>{const o=s.category;return o?t.jsx(E,{variant:"purple",size:"sm",children:o}):t.jsx("span",{className:"text-text-muted text-xs",children:"-"})}},{key:"session_count",header:"Sessions",width:"90px",sortable:!0,render:s=>t.jsx("span",{className:"tabular-nums",children:s.session_count})},{key:"total_messages",header:"Messages",width:"90px",sortable:!0,render:s=>t.jsx("span",{className:"tabular-nums text-text-secondary",children:s.total_messages.toLocaleString()})},{key:"total_cost",header:"Cost",width:"90px",sortable:!0,render:s=>t.jsx("span",{className:"tabular-nums font-medium",children:C(s.total_cost)})},{key:"total_active_minutes",header:"Active Time",width:"100px",sortable:!0,render:s=>t.jsx("span",{className:"tabular-nums text-text-secondary",children:R(s.total_active_minutes)})},{key:"last_session_at",header:"Last Session",width:"110px",sortable:!0,render:s=>t.jsx("span",{className:"text-text-secondary text-xs",children:xe(s.last_session_at)})},{key:"sdk_status",header:"SDK",width:"70px",render:s=>{const a=A(s,r),i=pe[a];return a==="not-installed"?t.jsx("span",{className:"text-text-muted text-xs",children:"-"}):t.jsx(E,{variant:i.variant,size:"sm",children:i.label})}},{key:"dev_server",header:"Dev",width:"90px",render:s=>{const o=s;return o.path?t.jsx(ge,{projectId:o.id}):t.jsx("span",{className:"text-text-muted text-xs",children:"-"})}}]}function Ee(){const r=c(e=>e.projects),s=c(e=>e.sessionStats),o=c(e=>e.projectSummaries),a=c(e=>e.projectSummariesLoading),i=c(e=>e.hideEmptySessions),u=c(e=>e.sessionDateRange),f=c(e=>e.setSessionDateRange),F=c(e=>e.setHideEmptySessions),N=M(e=>e.projects),k=U(e=>e.activeWorkspaceId),b=d.useMemo(()=>k?new Set(r.filter(e=>e.workspaceId===k).map(e=>e.id)):null,[r,k]),$=d.useMemo(()=>b?r.filter(e=>b.has(e.id)):r,[r,b]),m=d.useMemo(()=>b?o.filter(e=>b.has(e.id)):o,[o,b]),[n,_]=d.useState(null),K=d.useMemo(()=>{const{start:e,end:l}=u;if(!e&&!l)return"all";for(const x of L){const y=T(x.id);if(y.start===e&&y.end===l)return x.id}return"custom"},[u]),H=d.useCallback(e=>{f(T(e))},[f]),D=d.useCallback((e,l)=>{const x={...u,[e]:l||void 0};f(x)},[u,f]);d.useEffect(()=>{c.getState().fetchProjects(),c.getState().fetchSessionStats(),c.getState().fetchProjectSummaries(),c.getState().fetchCategories()},[]);const p=d.useMemo(()=>n?n==="__none"?m.filter(e=>!e.category):m.filter(e=>e.category===n):m,[m,n]),v=d.useMemo(()=>{const e=n?p:null;if(e){const l=e.reduce((g,h)=>g+h.session_count,0),x=e.reduce((g,h)=>g+h.total_cost,0),y=e.reduce((g,h)=>g+h.total_active_minutes,0);return{totalSessions:l,totalCostMicro:x,totalMinutes:y}}return s?{totalSessions:s.totalSessions,totalCostMicro:s.totalCostMicrodollars,totalMinutes:s.totalActiveMinutes}:{totalSessions:0,totalCostMicro:0,totalMinutes:0}},[n,p,s]),I=d.useCallback(()=>{const e=new URLSearchParams,{start:l,end:x}=u;if(l&&e.set("start_date",l),x&&e.set("end_date",x),i&&e.set("hide_empty","true"),n){const g=p.map(h=>h.id);g.length>0&&e.set("project_ids",g.join(","))}const y=`/api/pm/projects/export-csv?${e.toString()}`;window.open(y,"_blank")},[u,i,n,p]),G=C(v.totalCostMicro),O=R(v.totalMinutes),B=v.totalSessions>0?C(v.totalCostMicro/v.totalSessions):"$0.00",w=c(e=>e.categories),q=d.useMemo(()=>fe(N),[N]);return t.jsx("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:t.jsx("div",{className:"flex-1 overflow-y-auto",children:t.jsxs("div",{className:"p-6 space-y-5",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[t.jsxs("div",{children:[t.jsxs("h1",{className:"text-xl font-bold text-text-primary",children:[me(),", Edwin"]}),t.jsxs("p",{className:"text-[13px] text-text-tertiary mt-0.5",children:["Here's what's happening across your ",$.length," projects"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:I,className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium bg-bg-surface text-text-secondary hover:bg-bg-hover transition-colors cursor-pointer",children:[t.jsx(se,{size:12}),"Export CSV"]}),t.jsxs("button",{type:"button",onClick:()=>F(!i),className:j("inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium transition-colors cursor-pointer",i?"bg-amber-500/15 text-amber-400":"bg-bg-surface text-text-muted hover:bg-bg-hover"),children:[i?t.jsx(W,{size:12}):t.jsx(le,{size:12}),i?"Empty sessions hidden":"Show all sessions"]})]})]}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[t.jsx("div",{className:"flex items-center gap-1.5",children:L.map(e=>t.jsx("button",{type:"button",onClick:()=>H(e.id),className:j("px-3 py-1 rounded-full text-xs font-medium transition-colors cursor-pointer",K===e.id?"bg-accent text-text-inverse":"bg-bg-surface text-text-secondary hover:bg-bg-hover"),children:e.label},e.id))}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[t.jsx(V,{size:14,className:"text-text-tertiary"}),t.jsx("input",{type:"date",value:u.start??"",onChange:e=>D("start",e.target.value),className:"h-7 px-2 rounded bg-bg-input text-text-primary text-xs border border-border-strong focus:border-border-hover focus:outline-none"}),t.jsx("span",{className:"text-text-tertiary text-xs",children:"to"}),t.jsx("input",{type:"date",value:u.end??"",onChange:e=>D("end",e.target.value),className:"h-7 px-2 rounded bg-bg-input text-text-primary text-xs border border-border-strong focus:border-border-hover focus:outline-none"})]})]}),t.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[t.jsx(S,{icon:re,label:"Total Sessions",value:v.totalSessions.toLocaleString(),footerLabel:"Across all projects"}),t.jsx(S,{icon:oe,label:"Total Cost",value:G,footerLabel:"API usage cost"}),t.jsx(S,{icon:ne,label:"Active Time",value:O,footerLabel:"Total active time"}),t.jsx(S,{icon:ee,label:"Avg Cost/Session",value:B,footerLabel:"Per session average"})]}),w.length>0&&t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsxs("button",{type:"button",onClick:()=>_(null),className:j("px-3 py-1 rounded-full text-xs font-medium transition-colors cursor-pointer",n===null?"bg-accent text-text-inverse":"bg-bg-surface text-text-secondary hover:bg-bg-hover"),children:["All (",m.length,")"]}),w.map(e=>{const l=m.filter(x=>x.category===e).length;return t.jsxs("button",{type:"button",onClick:()=>_(n===e?null:e),className:j("px-3 py-1 rounded-full text-xs font-medium transition-colors cursor-pointer",n===e?"bg-accent text-text-inverse":"bg-bg-surface text-text-secondary hover:bg-bg-hover"),children:[e," (",l,")"]},e)}),m.some(e=>!e.category)&&t.jsxs("button",{type:"button",onClick:()=>_(n==="__none"?null:"__none"),className:j("px-3 py-1 rounded-full text-xs font-medium transition-colors cursor-pointer",n==="__none"?"bg-accent text-text-inverse":"bg-bg-surface text-text-muted hover:bg-bg-hover"),children:["Uncategorized (",m.filter(e=>!e.category).length,")"]})]}),p.length===0&&!a?t.jsx(J,{icon:t.jsx(ce,{size:32}),title:n?"No projects in this category":"No projects yet",description:n?"Try selecting a different category.":"Projects will appear here once they are created."}):t.jsx("div",{className:"rounded-lg border border-border-strong overflow-hidden bg-bg-surface",children:t.jsx(Y,{columns:q,data:p,onRowClick:e=>{const l=e;M.getState().selectPmProject(l.id)},emptyMessage:a?"Loading projects...":"No projects found",defaultSort:{key:"total_cost",direction:"desc"}})}),t.jsxs("div",{className:"text-xs text-text-tertiary",children:[p.length," project",p.length!==1?"s":"",n?" (filtered)":""]})]})})})}export{Ee as HomePage};
