1import{b as W,aW as B,cg as G,bi as Y,bj as Z,r as u,bk as k,j as t,J as S,b_ as ee,g as L,L as I,P as te,d as se,D as ae,T as re,co as M,z as R,bl as F,at as ne,y as E}from"./index-BawMCgu8.js";import{u as ie}from"./useMutation-D0Pwndul.js";import{P as oe}from"./PageHeader-CVqQ1h3V.js";import{M as le,X as ce}from"./x-circle-DDqrFxTS.js";import"./locale-en-B8Z5F_o1.js";import"./locale-zh-CN-CFdD1mPv.js";import"./locale-fr-j4CMJpfE.js";import"./locale-de-DuE2gagy.js";import"./locale-it-C6yb6RzN.js";import"./locale-ja-VjZBy5eF.js";import"./locale-ko-Cl0W-Az5.js";import"./locale-es-DwboUZze.js";import"./locale-zh-Hant-uT5aTnfX.js";import"./locale-ru-DEr1xfTZ.js";import"./locale-id-Buh3Uolz.js";import"./locale-pt-BR-CqD5J4_0.js";function Pe(){var U,P;const{t:s,i18n:q}=W(),x=B(),j=G(),z=Y(),{confirm:$,ConfirmDialogElement:A}=Z(),p=j.pathname.replace("/history",""),O=((U=j.state)==null?void 0:U.from)||p,[l,N]=u.useState(1),[f,h]=u.useState(null),[w,g]=u.useState(null),c=u.useRef(null),Q=10,{data:n,isLoading:b,error:C}=k({queryKey:["tts-tasks",l],queryFn:async()=>(await M.listTasks({type:"tts",page:l,limit:Q})).data}),_=ie({mutationFn:e=>M.deleteTask(e),onSuccess:()=>{z.invalidateQueries({queryKey:["tts-tasks"]}),R.success(s("common.deleted"))},onError:()=>{R.error(s("common.deleteFailed"))}}),y=(n==null?void 0:n.tasks)||[],m=((P=n==null?void 0:n.pagination)==null?void 0:P.totalPages)||0,H=e=>{switch(e.status){case"pending":return{icon:F,text:s("tts.statusPending"),className:"text-yellow-500",iconClassName:""};case"processing":return{icon:I,text:s("tts.statusProcessing"),className:"text-blue-500",iconClassName:"animate-spin"};case"completed":return{icon:ne,text:s("tts.statusCompleted"),className:"text-green-500",iconClassName:""};case"failed":return{icon:ce,text:s("tts.statusFailed"),className:"text-red-500",iconClassName:""};default:return{icon:F,text:e.status,className:"text-gray-500",iconClassName:""}}},K=e=>new Date(e).toLocaleDateString(q.language,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),V=async e=>{var a,i;if((a=e.output)!=null&&a.audioUrl)if(w===e.id)(i=c.current)==null||i.pause(),g(null);else{if(c.current){const r=e.output.assetId?await E.getUrl(e.output.assetId).catch(()=>e.output.audioUrl):e.output.audioUrl;c.current.src=r,c.current.play()}g(e.id)}},X=async e=>{var a;if((a=e.output)!=null&&a.audioUrl)try{const i=e.output.assetId?await E.getUrl(e.output.assetId).catch(()=>e.output.audioUrl):e.output.audioUrl,v=await(await fetch(i)).blob(),d=URL.createObjectURL(v),o=document.createElement("a");o.href=d,o.download=`tts_${Date.now()}.${e.output.format||"mp3"}`,o.click(),URL.revokeObjectURL(d)}catch{e.output.audioUrl&&window.open(e.output.audioUrl,"_blank")}},J=async e=>{await $({message:s("tts.confirmDelete"),variant:"danger"})&&_.mutate(e),h(null)};return t.jsxs("div",{className:"page-container",children:[t.jsx("audio",{ref:c,onEnded:()=>g(null),style:{display:"none"}}),t.jsx(oe,{icon:S,title:s("tts.historyTitle"),subtitle:s("tts.historySubtitle"),actions:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("button",{onClick:()=>x(O),className:"btn-secondary flex items-center gap-2",children:[t.jsx(ee,{className:"w-4 h-4"}),s("common.back")]}),t.jsxs("button",{onClick:()=>x(p),className:"btn-primary flex items-center gap-2",children:[t.jsx(L,{className:"w-4 h-4"}),s("tts.newSynthesis")]})]})}),t.jsxs("div",{className:"page-content",children:[b&&t.jsx("div",{className:"flex items-center justify-center py-20",children:t.jsx(I,{className:"w-8 h-8 animate-spin text-ui-accent"})}),C&&t.jsx("div",{className:"text-center py-20 text-red-500",children:s("common.loadFailed")}),!b&&!C&&y.length===0&&t.jsxs("div",{className:"text-center py-20",children:[t.jsx(S,{className:"w-16 h-16 mx-auto text-[var(--text-muted)] mb-4"}),t.jsx("h3",{className:"text-lg font-medium mb-2",children:s("tts.noRecords")}),t.jsx("p",{className:"text-[var(--text-muted)] mb-6",children:s("tts.createFirst")}),t.jsxs("button",{onClick:()=>x(p),className:"btn-primary inline-flex items-center gap-2",children:[t.jsx(L,{className:"w-4 h-4"}),s("tts.newSynthesis")]})]}),!b&&y.length>0&&t.jsxs("div",{className:"space-y-3",children:[y.map(e=>{var d,o,T,D;const a=H(e),i=a.icon,r=((d=e.input)==null?void 0:d.text)||"",v=r.length>80?r.slice(0,80)+"...":r;return t.jsx("div",{className:"content-card p-4 hover:border-ui-accent/50 transition-colors",children:t.jsxs("div",{className:"flex items-start gap-4",children:[t.jsx("button",{onClick:()=>V(e),disabled:e.status!=="completed"||!((o=e.output)!=null&&o.audioUrl),className:"w-12 h-12 rounded-full flex items-center justify-center flex-shrink-0 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] transition-colors disabled:opacity-50 disabled:cursor-default",children:w===e.id?t.jsx(te,{className:"w-5 h-5 text-[var(--accent-primary)]"}):t.jsx(se,{className:"w-5 h-5 text-[var(--text-secondary)]"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-start justify-between gap-4",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-sm text-[var(--text-primary)] line-clamp-2",children:r?v:e.error||"..."}),t.jsxs("div",{className:"flex items-center gap-3 mt-1 text-xs text-[var(--text-muted)]",children:[t.jsx("span",{children:e.model}),((T=e.input)==null?void 0:T.voice)&&t.jsx("span",{children:e.input.voice}),e.creditsUsed!=null&&t.jsxs("span",{children:[e.creditsUsed," credits"]})]})]}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[t.jsxs("div",{className:`flex items-center gap-1.5 text-sm ${a.className}`,children:[t.jsx(i,{className:`w-4 h-4 ${a.iconClassName}`}),t.jsx("span",{className:"hidden sm:inline",children:a.text})]}),e.status==="completed"&&((D=e.output)==null?void 0:D.audioUrl)&&t.jsx("button",{onClick:()=>X(e),className:"p-2 hover:bg-[var(--bg-tertiary)] rounded-lg transition-colors",title:s("common.download"),children:t.jsx(ae,{className:"w-4 h-4"})}),t.jsxs("div",{className:"relative",children:[t.jsx("button",{onClick:()=>h(f===e.id?null:e.id),className:"p-2 hover:bg-[var(--bg-tertiary)] rounded-lg transition-colors",children:t.jsx(le,{className:"w-4 h-4"})}),f===e.id&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>h(null)}),t.jsx("div",{className:"absolute right-0 top-full mt-1 z-20 bg-[var(--bg-secondary)] border border-ui-border rounded-lg shadow-lg py-1 min-w-[120px]",children:t.jsxs("button",{onClick:()=>J(e.id),className:"w-full px-3 py-2 text-left text-sm text-red-500 hover:bg-[var(--bg-tertiary)] flex items-center gap-2",children:[t.jsx(re,{className:"w-4 h-4"}),s("common.delete")]})})]})]})]})]}),e.status==="failed"&&e.error&&t.jsx("p",{className:"mt-2 text-sm text-red-500",children:e.error}),t.jsx("div",{className:"flex items-center gap-4 mt-2 text-xs text-[var(--text-muted)]",children:t.jsx("span",{children:K(e.createdAt)})})]})]})},e.id)}),m>1&&t.jsxs("div",{className:"flex items-center justify-center gap-3 pt-6",children:[t.jsx("button",{onClick:()=>N(e=>Math.max(1,e-1)),disabled:l===1,className:"px-4 py-2 text-sm rounded-lg bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] hover:text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:s("common.previousPage")}),t.jsxs("span",{className:"text-sm text-[var(--text-muted)] px-2",children:[l," / ",m]}),t.jsx("button",{onClick:()=>N(e=>Math.min(m,e+1)),disabled:l===m,className:"px-4 py-2 text-sm rounded-lg bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] hover:text-[var(--text-primary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:s("common.nextPage")})]})]})]}),A]})}export{Pe 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.