import{c as b,r as p,u as J,j as s,L as k,_ as K,t as y}from"./index-qMrAuFFG.js";import{s as d,P as Q,a as X}from"./phase-bar-Cra2ethh.js";import{A as Y}from"./alert-message-DBiN770l.js";import{P as Z,B as h,I as ss,S as es,a as ts,b as as,c as ls,d as x}from"./loading-PETOxw4W.js";import{P as F,d as rs,e as is,f as L,g as m,h as ns,i as u,D as cs,a as os,E as ds,b as hs,c as D,T as xs}from"./table-BTToAg72.js";import{g as ms,h as us,i as js}from"./queries-B0q6a4VE.js";import"./refresh-cw-BtfCr9OP.js";import"./clock-Dmcvs345.js";/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const gs=[["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"}]],ps=b("Eye",gs);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ks=[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]],ys=b("Filter",ks);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const fs=[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],Ns=b("Search",fs);function Is(){const[f,R]=p.useState(""),[N,v]=p.useState("all"),[l,j]=p.useState(1),[n]=p.useState(10),{t:e,i18n:w}=J(),A=w.resolvedLanguage??w.language??"en-US",$={page:l,pageSize:n,...f&&{name:f},...N!=="all"&&{status:N}},{data:r,isLoading:B,error:z}=ms($),S=us(),V=js(),T=(r==null?void 0:r.items)||[],g=(r==null?void 0:r.total)||0,q=t=>{t==="all"?v("all"):d.options.includes(t)&&v(t),j(1)},H=t=>{R(t),j(1)},O=t=>new Date(t).toLocaleString(A),U=async t=>{if(window.confirm(e("tasks.list.deleteConfirm")))try{await S.mutateAsync(t),y.success(e("tasks.list.deleteSuccess"))}catch(a){y.error(e("tasks.list.deleteFailed")),console.error("Delete task error:",a)}},W=async(t,a)=>{try{const i=e(`tasks.detail.phases.${a}.label`,{defaultValue:a});await V.mutateAsync({id:t,phase:a},{onSuccess:()=>{y.success(e("tasks.list.retrySuccess",{phase:i}))},onError:c=>{const o=c instanceof Error?c.message:void 0;y.error(o?e("tasks.list.retryFailedWithReason",{reason:o}):e("tasks.list.retryFailed"))}})}catch(i){console.error(i)}};return s.jsxs(Z,{loading:B,loadingText:e("tasks.list.loading"),children:[s.jsxs("div",{className:"flex justify-between items-center mb-6",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:e("tasks.list.title")}),s.jsx("p",{className:"text-gray-600 mt-1",children:e("tasks.list.subtitle")})]}),s.jsx(k,{to:"/tasks/create",children:s.jsxs(h,{children:[s.jsx(F,{className:"w-4 h-4 mr-2"}),e("tasks.list.create")]})})]}),s.jsx("div",{className:"mb-6",children:s.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[s.jsx("div",{className:"flex-1",children:s.jsxs("div",{className:"relative",children:[s.jsx(Ns,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4"}),s.jsx(ss,{placeholder:e("tasks.list.searchPlaceholder"),value:f,onChange:t=>H(t.target.value),className:"pl-10"})]})}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsxs(es,{value:N,onValueChange:q,children:[s.jsxs(ts,{children:[s.jsx(ys,{className:"w-4 h-4 mr-2"}),s.jsx(as,{})]}),s.jsxs(ls,{children:[s.jsx(x,{value:"all",children:e("tasks.status.all")}),s.jsx(x,{value:d.enum.waiting,children:e("tasks.status.waiting")}),s.jsx(x,{value:d.enum.running,children:e("tasks.status.running")}),s.jsx(x,{value:d.enum.success,children:e("tasks.status.success")}),s.jsx(x,{value:d.enum.failed,children:e("tasks.status.failed")})]})]})})]})}),z&&s.jsx(Y,{title:e("tasks.list.error.title"),content:e("tasks.list.error.description"),className:"mb-6"}),s.jsx("div",{className:"bg-white rounded-lg shadow-sm border overflow-hidden",children:T.length>0?s.jsxs(rs,{children:[s.jsx(is,{children:s.jsxs(L,{children:[s.jsx(m,{children:e("tasks.list.table.name")}),s.jsx(m,{children:e("tasks.list.table.path")}),s.jsx(m,{className:"text-center",children:e("tasks.list.table.phase")}),s.jsx(m,{children:e("tasks.list.table.createdAt")}),s.jsx(m,{className:"text-right",children:e("tasks.list.table.actions")})]})}),s.jsx(ns,{children:T.map(t=>{var i,c,o,P,C,E,I,M,_;const a=(c=(i=t.job.config.source)==null?void 0:i.storagePath)==null?void 0:c.split("/").slice(-1)[0];return s.jsxs(L,{children:[s.jsx(u,{children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"w-4 h-4",children:s.jsx(K,{type:((o=a==null?void 0:a.split("."))==null?void 0:o.length)>1?void 0:"folder",path:(P=t.job.config.source)==null?void 0:P.storagePath})}),s.jsx(k,{to:"/tasks/$taskId",params:{taskId:String(t.id)},className:"font-medium text-gray-900 hover:text-blue-600 hover:underline",children:t.name})]})}),s.jsx(u,{children:(I=(E=(C=t.job)==null?void 0:C.config)==null?void 0:E.source)!=null&&I.storagePath?s.jsx("div",{className:"max-w-xs",children:s.jsx("code",{className:"truncate text-xs p-1 rounded block",title:(M=t.job.config.source)==null?void 0:M.storagePath,children:(_=t.job.config.source)==null?void 0:_.storagePath})}):s.jsx("span",{className:"text-gray-400",children:"-"})}),s.jsx(u,{children:s.jsx(Q,{task:t,onRetry:G=>W(t.id,G),className:"flex-shrink-0 justify-center"})}),s.jsx(u,{className:"text-sm text-gray-500",children:O(t.created_at)}),s.jsx(u,{className:"text-right",children:s.jsxs(cs,{children:[s.jsx(os,{asChild:!0,children:s.jsx(h,{variant:"ghost",size:"sm",children:s.jsx(ds,{className:"w-4 h-4"})})}),s.jsxs(hs,{align:"end",children:[s.jsx(D,{asChild:!0,children:s.jsxs(k,{to:"/tasks/$taskId",params:{taskId:String(t.id)},children:[s.jsx(ps,{className:"w-4 h-4 mr-2"}),e("tasks.list.actions.view")]})}),s.jsxs(D,{className:"text-red-600",onClick:()=>U(t.id),disabled:S.isPending,children:[s.jsx(xs,{className:"w-4 h-4 mr-2"}),e("tasks.list.actions.delete")]})]})]})})]},t.id)})})]}):s.jsxs("div",{className:"text-center py-12",children:[s.jsx(X,{className:"mx-auto h-12 w-12 text-gray-400"}),s.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:e("tasks.list.empty.title")}),s.jsx("p",{className:"mt-1 text-sm text-gray-500",children:e("tasks.list.empty.description")}),s.jsx("div",{className:"mt-6",children:s.jsx(k,{to:"/tasks/create",children:s.jsxs(h,{children:[s.jsx(F,{className:"w-4 h-4 mr-2"}),e("tasks.list.create")]})})})]})}),g>n&&s.jsxs("div",{className:"flex items-center justify-between mt-6",children:[s.jsx("div",{className:"text-sm text-gray-700",children:e("tasks.list.pagination.summary",{start:(l-1)*n+1,end:Math.min(l*n,g),total:g})}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(h,{variant:"outline",onClick:()=>j(l-1),disabled:l===1,children:e("tasks.list.pagination.prev")}),s.jsx(h,{variant:"outline",onClick:()=>j(l+1),disabled:l*n>=g,children:e("tasks.list.pagination.next")})]})]})]})}export{Is as component};
