1import{r as S,j as e}from"./vendor-react-CuUun9aL.js";import{C as T,a as L,e as k,b as q,c as I}from"./card-khC1k9a2.js";import{B as N,s as w,i as B,J as d}from"./index-CffYHF1C.js";import{B as R}from"./badge-tBo3c1at.js";import{P as E}from"./progress-Dknxqpks.js";import{T as $,a as H,b as u,c as l,d as P,e as r}from"./table-Bf8kae7D.js";import{a as Q,u as C}from"./vendor-query-Ch735aT_.js";import"./vendor-supabase-V01cKGWO.js";import"./vendor-radix-DHc79Ej6.js";import"./vendor-router-CIKCSSKp.js";import"./vendor-icons-9tdgZqZ8.js";const D={handwritten:"Hand-written policy / sales / FAQ",destination_facts:"Destination factsheets",visa_notes:"Visa notes",news:"Indexed content",route_verdict:"Route verdicts"},Y=()=>{var b,j,y,v;const m=Q(),[n,h]=S.useState(!1),x=C({queryKey:["eva-arabic-coverage"],queryFn:async()=>{const{data:t,error:a}=await w.rpc("knowledge_translation_coverage",{_language:"ar"});if(a)throw a;return t??[]},refetchInterval:n?5e3:!1}),s=C({queryKey:["eva-arabic-state"],queryFn:async()=>{const{data:t,error:a}=await w.from("knowledge_translation_state").select("status, paused_reason, last_run_at, last_batch_size, translated_total, failed_total").eq("id","default").maybeSingle();if(a)throw a;return t},refetchInterval:n?5e3:!1}),i=x.data??[],c=i.reduce((t,a)=>t+Number(a.total),0),g=i.reduce((t,a)=>t+Number(a.translated),0),A=i.reduce((t,a)=>t+Number(a.pending),0),p=c>0?Math.round(g/c*100):0,f=async(t=!1)=>{h(!0);try{const{data:a,error:_}=await B("translate-knowledge",{body:{language:"ar",limit:40,resume:t}});if(_)throw _;a!=null&&a.paused?d.error(`Translation paused: ${a.pausedReason??"gateway blocked the request"}`):d.success(`Translated ${(a==null?void 0:a.translated)??0} entr${(a==null?void 0:a.translated)===1?"y":"ies"} â ${(a==null?void 0:a.remaining)??0} left`)}catch(a){d.error(a instanceof Error?a.message:"Translation run failed")}
1finally{h(!1),m.invalidateQueries({queryKey:["eva-arabic-coverage"]}),m.invalidateQueries({queryKey:["eva-arabic-state"]})}},o=((b=s.data)==null?void 0:b.status)??"idle";return e.jsxs(T,{children:[e.jsx(L,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{children:"Arabic coverage"}),e.jsxs(q,{children:["Pre-translated Arabic answers are served straight from the database â no AI call, no cost.",e.jsx("br",{}),e.jsx("span",{className:"font-medium text-foreground",children:"Cost-saving mode:"})," the backfill cron is paused. Arabic is translated on demand the first time a visitor asks, then cached forever. Use the buttons below only when you are ready to spend AI credits on bulk translation."]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{variant:o==="paused"?"destructive":"secondary",children:o}),e.jsx(N,{size:"sm",onClick:()=>f(!1),disabled:n,title:"Spends AI credits (~0.007 per entry)",children:n?"Translatingâ¦":"Run one batch (uses AI credits)"}),o==="paused"&&e.jsx(N,{size:"sm",variant:"outline",onClick:()=>f(!0),disabled:n,title:"Clears the pause and translates one batch using AI credits",children:"Resume (uses AI credits)"})]})]})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex justify-between text-sm",children:[e.jsxs("span",{children:[g.toLocaleString()," of ",c.toLocaleString()," entries in Arabic"]}),e.jsxs("span",{className:"font-medium",children:[p,"%"]})]}),e.jsx(E,{value:p}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[A.toLocaleString()," pending",(j=s.data)!=null&&j.failed_total?` · ${s.data.failed_total} failed`:"",(y=s.data)!=null&&y.last_run_at?` · last run ${new Date(s.data.last_run_at).toLocaleString()}`:""]}),((v=s.data)==null?void 0:v.paused_reason)&&e.jsx("p",{className:"mt-1 text-xs text-destructive",children:s.data.paused_reason})]}),e.jsxs($,{children:[e.jsx(H,{children:e.jsxs(u,{children:[e.jsx(l,{children:"Dataset"}),e.jsx(l,{className:"text-right",children:"Total"}),e.jsx(l,{className:"text-right",children:"Arabic"}),e.jsx(l,{className:"text-right",children:"Hand-edited"}),e.jsx(l,{className:"text-right",children:"Pending"})]})}),e.jsxs(P,{children:[i.map(t=>e.jsxs(u,{children:[e.jsx(r,{children:D[t.source_type]??t.source_type}),e.jsx(r,{className:"text-right",children:Number(t.total).toLocaleString()}),e.jsx(r,{className:"text-right",children:Number(t.translated).toLocaleString()}),e.jsx(r,{className:"text-right",children:Number(t.manual).toLocaleString()}),e.jsx(r,{className:"text-right",children:Number(t.pending).toLocaleString()})]},t.source_type)),i.length===0&&e.jsx(u,{children:e.jsx(r,{colSpan:5,className:"text-center text-muted-foreground",children:x.isLoading?"Loadingâ¦":"No knowledge entr
1ies yet."})})]})]})]})]})};export{Y 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.