import{bc as N,bb as k,aY as o,aT as t,a2 as S,V as w,a as C,aE as R,a4 as D,E,J as I,c as p,i as h,U as A,u as L,aR as U,b9 as x}from"./chunk-02oqS8tD.js";import{b4 as u,ar as y}from"./chunk-B8Q4vgLh.js";import{C as $}from"./chunk-D4UWVV5_.js";import"./chunk-x_Z6cwvR.js";function O(){const a=N(s=>s.go),c=k(s=>s.projectId),[m,i]=o.useState("loading"),[l,g]=o.useState([]),[r,f]=o.useState(""),n=o.useCallback(async()=>{i("loading");try{g(await u.list()),i("ready")}catch{i("error")}},[]);o.useEffect(()=>{n()},[n]);const j=o.useMemo(()=>{const s=r.trim().toLowerCase();return l.filter(e=>e.projectId===void 0||c==null||e.projectId===c).filter(e=>s===""||e.name.toLowerCase().includes(s)||(e.startUrl??"").toLowerCase().includes(s)).sort((e,d)=>d.updatedAt-e.updatedAt)},[l,r,c]),v=async s=>{const e={...s,id:y("wf"),name:`${s.name} (copy)`,steps:s.steps.map(d=>({...d,id:y("step")})),createdAt:Date.now(),updatedAt:Date.now()};await u.upsert(e),await n(),x.success(`Duplicated as “${e.name}”`)},b=async s=>{await u.remove(s.id),await n(),x.info(`Deleted “${s.name}”`)};return t.jsx(S,{title:"Workflows",subtitle:"Replay a recorded journey and keep the evidence.",onBack:()=>a(U("tools")),actions:t.jsxs(p,{size:"sm",className:"h-7",onClick:()=>a({name:"recorder"}),children:[t.jsx(h,{className:"h-3 w-3"}),"Record"]}),sticky:l.length>3?t.jsxs("div",{className:"relative",children:[t.jsx(A,{className:"absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),t.jsx(L,{value:r,onChange:s=>f(s.target.value),placeholder:"Filter workflows",className:"h-7 pl-7 text-xs"})]}):void 0,children:t.jsx(w,{children:t.jsx(C,{status:m==="loading"?"loading":m==="error"?"error":"ready",data:j,onRetry:()=>void n(),loadingLabel:"Loading workflows…",empty:t.jsx(E,{icon:I,title:r.trim()===""?"No workflows yet.":`Nothing matches “${r}”`,description:r.trim()===""?"Record your first browser workflow. Every replay after that captures screenshots, console and network logs, and the environment it ran in.":void 0,action:r.trim()===""?t.jsxs(p,{size:"sm",className:"h-7",onClick:()=>a({name:"recorder"}),children:[t.jsx(h,{className:"h-3 w-3"}),"Start recording"]}):void 0}),children:s=>t.jsx("div",{className:"space-y-1.5",children:s.map(e=>t.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-stroke/70 px-2.5 py-2 dark:border-stroke/25",children:[t.jsxs("button",{type:"button",onClick:()=>a({name:"workflow-detail",workflowId:e.id}),className:"min-w-0 flex-1 text-left",children:[t.jsx("span",{className:"block truncate text-[11px] font-semibold",children:e.name}),t.jsxs("span",{className:"block truncate text-[9.5px] text-muted-foreground",children:[String(e.steps.length)," step",e.steps.length===1?"":"s",e.startUrl?` · ${T(e.startUrl)}`:""," · ",R(e.updatedAt)]})]}),t.jsx("button",{type:"button",onClick:()=>void v(e),title:"Duplicate",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-stroke/20 hover:text-foreground",children:t.jsx($,{className:"h-3 w-3"})}),t.jsx("button",{type:"button",onClick:()=>void b(e),title:"Delete",className:"shrink-0 rounded p-1 text-muted-foreground hover:bg-alert-orange/15 hover:text-alert-orange",children:t.jsx(D,{className:"h-3 w-3"})})]},e.id))})})})})}function T(a){try{return new URL(a).host}catch{return a.slice(0,30)}}export{O as WorkflowsScreen};
//# sourceMappingURL=chunk-CPlDGn7o.js.map
