1import{u as Ke,f as Xe,g as st,a as qe,r as h,R as m,w as C,j as e,B as P,b as be,d as ve,U as Ge,F as oe,X as Qe,A as Je,n as Ye,o as at,q as ot,D as lt}from"./index-Ckj1a2bl.js";import{A as $e}from"./Alert-KKWP5gta.js";import{u as rt}from"./apiService-hx4S0ngD.js";import{D as Ze}from"./Drawer-B5I6irUJ.js";import{S as Oe}from"./Selectui-RXnyk-hV.js";import{F as et}from"./folder-open-CfOdNgbU.js";import{I as nt}from"./Input-DE1NbaEv.js";import{S as it}from"./Switch-Klwekg83.js";import{u as ct,U as dt}from"./useUnsavedChangesWarning-Kpw1yQMI.js";import{L as ut}from"./loader-2-vvwnAoyA.js";import{M as ft}from"./mail-BvfQMkAJ.js";import"./check-circle-2-euYlbHQ3.js";import"./Dialog-C5PmpKXw.js";const mt=()=>{const{t:l}=Ke(),n=Xe(),k=st(),{billingEnabled:D,role:M,isSolutionEngineer:de,isSuperuser:I}=qe(),z=!!(I||de&&M!=="user"),Y=k.state&&typeof k.state.workflowId=="string"?k.state.workflowId:void 0,$=k.state&&(k.state.workflowKind==="extraction"||k.state.workflowKind==="classification")?k.state.workflowKind:void 0,[K,Z]=h.useState([]),[H,X]=h.useState(!1),[ye,le]=h.useState(!1),[je,He]=h.useState(null),[Te,j]=h.useState(!1),[N,ue]=h.useState([]),[fe,ee]=h.useState({}),[q,O]=h.useState({}),[w,me]=h.useState(""),[pe,W]=h.useState(""),[G,re]=h.useState(!1),[ne,ke]=h.useState(()=>$||"extraction"),te=m.useRef(null),[ge,se]=h.useState([]),[De,Ve]=h.useState(!1),[Pe,Ie]=h.useState(!1),[ie,A]=h.useState(""),[he,L]=h.useState(""),[U,R]=h.useState(null),[xe,Q]=h.useState(""),[Ne,_e]=h.useState(!1),[Se,Ae]=h.useState(!1),Ue=m.useRef(!1),We=s=>{var a;return!!(s&&((a=s==null?void 0:s.meta)==null?void 0:a.source)==="precheck-upload")},Le=h.useMemo(()=>{try{return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:4})}catch{return null}},[]),J=s=>{const a=typeof s=="number"?s:Number(s);return Number.isFinite(a)?Le?Le.format(a):`$${a.toFixed(4)}`:String(s??"")},Re=s=>{const a=typeof s=="number"?s:Number(s);return Number.isFinite(a)?a:0},ze=s=>{const a=s/1024/1024;return l("dashboardUpload.form.units.megabytes",{value:a.toFixed(2)})},we=h.useMemo(()=>{if(!w||N.length===0)return"";const s=N.map(a=>`${a.name}:${a.size}:${a.type||""}`).sort();return`${w}::${s.join("|")}`},[N,w]);h.useEffect(()=>{(async()=>{X(!1),Z([]);try{const a=await C.getWorkflowOptions(1e3,ne);Z(a)}catch(a){console.error("Failed to load workflows:",a)}finally{X(!0)}})()},[ne]),h.useEffect(()=>{if(!Y)return;if(te.current=Y,re(!0),$){ke($);return}let s=!1;return(async()=>{try{const a=await C.getWorkflow(Y);if(s)return;const d=a==null?void 0:a.kind;(d==="classification"||d==="extraction")&&ke(d)}catch{}})(),()=>{s=!0}},[Y,$]),h.useEffect(()=>{G||(me(""),W(""),R(null),A(""),L(""),Q(""))},[ne,G]);const Be=H&&K.length===0,T=s=>Be?(He(s),le(!0),!1):!0;h.useEffect(()=>{const s=te.current;if(!s)return;if(K.length===0){H&&(W(l("dashboardUpload.form.errors.preselectedNotAvailable")),te.current=null,re(!1));return}const a=K.find(d=>d.id===s);if(a){me(a.id),W(""),te.current=null;return}H&&(W(l("dashboardUpload.form.errors.preselectedNotAvailable")),te.current=null,re(!1))},[K,H,l]);const V=h.useMemo(()=>K.find(s=>s.id===w)||null,[K,w]),B=!!(V!=null&&V.batch_processing_enabled&&(V!=null&&V.batch_schedule_frequency)&&V.batch_schedule_frequency!=="disabled"),Ee=m.useCallback(async s=>{Ve(!0);try{const a=await C.getWorkflowExecutions(1,50,s,"scheduled",void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,{list:!0}),d=Array.isArray(a==null?void 0:a.results)?a.results:[];se(d.map(i=>{var _;return{id:String(i.id),title:String(((_=i.document)==null?void 0:_.title)||i.id),created_at:i.created_at}}))}catch(a){console.error("Failed to load scheduled batch queue:",a),se([])}finally{Ve(!1)}},[]);h.useEffect(()=>{if(!w||!B){se([]);return}Ee(w)},[w,B,Ee]);const Fe=s=>{if(!s)return"";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(s))}catch{return s}},t=s=>{s.preventDefault(),j(!0)},o=()=>{j(!1)},r=async s=>{if(s.preventDefault(),j(!1),!T("drop"))return;const a=s.dataTransfer.items;if(a&&a.length>0){const d=[],i=c=>new Promise(f=>{if(c.isFile&&typeof c.file=="function")c.file(g=>{d.push(g),f()});else if(c.isDirectory&&typeof c.createReader=="function"){const g=c.createReader();(async()=>new Promise(F=>{const ce=()=>{g.readEntries(async Ce=>{if(!Ce||Ce.length===0){F();return}for(const ae of Ce)await i(ae);ce()})};ce()}))().then(()=>
1f()).catch(()=>f())}else f()});if(await(async()=>{const c=[];for(let f=0;f<a.length;f++){const g=a[f],S=g.webkitGetAsEntry&&g.webkitGetAsEntry();S&&c.push(i(S))}await Promise.all(c)})(),d.length>0){y(d);return}}s.dataTransfer.files&&s.dataTransfer.files.length>0&&y(Array.from(s.dataTransfer.files))},u=(s,a="browse-files")=>{T(a)&&s.target.files&&s.target.files.length>0&&y(Array.from(s.target.files))},y=s=>{const a=s.filter(c=>{const f=c.type,g=c.name.toLowerCase();return f==="application/pdf"||f==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||f==="application/zip"||g.endsWith(".pdf")||g.endsWith(".docx")||g.endsWith(".zip")}),d=[...N,...a];ue(d),R(null),A(""),L(""),Q("");const i={...q},_={...fe};a.forEach(c=>{i[c.name]="pending",_[c.name]=0}),O(i),ee(_)},b=s=>{ue(N.filter(i=>i.name!==s)),R(null),A(""),L(""),Q("");const a={...q},d={...fe};delete a[s],delete d[s],O(a),ee(d)},p=async()=>{if(D&&T("preview")){if(!w){W(l("dashboardUpload.form.errors.selectWorkflowBeforePreview"));return}if(N.length===0){W(l("dashboardUpload.form.errors.selectFilesBeforePreview"));return}W(""),A(""),L(""),Ie(!0);try{const s=await C.precheckDocumentsUpload(N,w,{fallbackToHeuristicOn413:!0,concurrency:4});R(s),Q(we),L("")}catch(s){console.error("Precheck failed:",s),R(null),Q(""),L(""),A(l("dashboardUpload.form.errors.costEstimateFailed"))}finally{Ie(!1)}}},v=async()=>{var s;if(!Ue.current&&T("upload")){if(!w){W(l("dashboardUpload.form.errors.selectWorkflowBeforeUpload"));return}if(N.length===0){W(l("dashboardUpload.form.errors.selectFilesBeforeUpload"));return}W(""),Ue.current=!0,Ae(!0),_e(!0);try{let a=N;if(D){let i=U;if(!!!(i&&xe&&xe===we&&We(i)))try{i=await C.precheckDocumentsUpload(N,w,{fallbackToHeuristicOn413:!1,concurrency:3,adaptiveSplitOn413:!0}),R(i),Q(we),A(""),L("")}catch(f){console.error("Precheck failed:",f),A(l("dashboardUpload.form.alerts.precheckFailedBeforeUpload"));return}if(!i||i.accepted_count===0){A(l("dashboardUpload.form.alerts.insufficientBalance"));return}const c=new Set(i.accepted.map(f=>f.name));O(f=>{const g={...f};return i.rejected.forEach(S=>{g[S.name]="error"}),g}),i.rejected_count>0&&L(l("dashboardUpload.form.alerts.precheckSummary",{accepted:i.accepted_count,rejected:i.rejected_count,cost:i.total_estimated_cost,balanceAfter:i.balance_after})),a=N.filter(f=>c.has(f.name))}_e(!1);const d=[];for(const i of a){O(c=>({...c,[i.name]:"uploading"})),ee(c=>({...c,[i.name]:0}));let _;try{let c=0;_=setInterval(()=>{c+=Math.floor(Math.random()*10)+1,c<95&&ee(S=>({...S,[i.name]:c}))},100);const f=await rt(i,w);let g;f&&typeof f=="object"&&"document"in f&&f.document&&typeof f.document=="object"&&f.document!==null&&"id"in f.document&&typeof f.document.id=="string"?g=f.document.id:f&&typeof f=="object"&&"id"in f&&typeof f.id=="string"&&(g=f.id),typeof g=="string"&&d.push({id:g}),clearInterval(_),ee(S=>({...S,[i.name]:100})),O(S=>({...S,[i.name]:"success"})),B&&se(S=>[{id:g||`${i.name}-${Date.now()}`,title:i.name,created_at:new Date().toISOString()},...S.filter(F=>F.title!==i.name||F.id!==g)])}catch(c){console.error("Upload failed for file:",i.name,c),O(tt=>({...tt,[i.name]:"error"})),clearInterval(_);let f=l("dashboardUpload.form.uploadError.default"),g="",S="",F="",ce="";c&&typeof c=="object"&&("error"in c&&typeof c.error=="string"&&(f=c.error),"details"in c&&typeof c.details=="string"&&(g=c.details),"support_message"in c&&typeof c.support_message=="string"&&(S=c.support_message),"code"in c&&typeof c.code=="string"&&(F=c.code),"status"in c&&(typeof c.status=="string"||typeof c.status=="number")&&(ce=String(c.status)));const Ce=c&&typeof c=="object"&&("contact_support"in c&&c.contact_support||F==="INTERNAL_ERROR"||ce==="500");let ae=f,Me="";c instanceof TypeError||typeof c=="object"&&c!==null&&"message"in c&&typeof c.message=="string"&&c.message.includes("Failed to fetch")?(Me=l("dashboardUpload.form.uploadError.statusNetwork"),ae=l("dashboardUpload.form.uploadError.network")):ce?Me=l("dashboardUpload.form.uploadError.status",{status:ce}):Me=l("dashboardUpload.form.uploadError.statusNA"),ae+=` 2${Me}`,F&&(ae+=` 3${l("dashboardUpload.form.uploadError.errorCode",{code:F})}`),g&&(ae+=` 4${g}`),Ce&&(ae+=` 5${S||l("dashboardUpload.form.uploadError.contactSupport",{email:"[email protected]"})}`),W(ae)}}B&&w?Ee(w):d.length===1&&((s=d[0])!=null&&s.id)?setTimeout(()=>{n(`/dashboard/documents/${d[0].id}`)},1e3):d.length>1&&n("/dashboard/documents?filter=processing")}finally{Ue.current=!1,Ae(!1),_e(!1)}}},E=s=>{var d;const a=(d=s.split(".").pop())==null?void 0:d.toLowerCase();return a==="pdf"?e.jsx(oe,{className:"h-5 w-5 text-red-500"}):a==="docx"?e.jsx(oe,{className:"h-5 w-5 text-blue-500"}):e.jsx(oe,{className:"h-5 w-5 text-gray-500"})},x=s=>{switch(s){case"success":return e.jsx(Ye,{className:"h-5 w-5 text-green-500"});case"error":return e.jsx(Je,{className:"h-5 w-5 text-red-500"});case"uploading":return null;default:return null}};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Ze,{open:ye,placement:"center",title:l("dashboardUpload.form.noWorkflowsModal.title"),closeLabel:l("actions.close"),dialogClassName:"max-w-md",onClose:()=>le(!1),footer:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(P,{variant:"outline",type:"button",onClick:()=>le(!1),children:l("dashboardUpload.form.noWorkflowsModal.cancel")}),z&&e.jsx(P,{type:"button",onClick:()=>{le(!1),n("/dashboard/workflows/create",{state:{from:"upload",reason:"no-workflows",action:je,returnTo:`${k.pathname}${k.search}`}})},children:l("dashboardUpload.form.noWorkflowsModal.create")})]}),children:e.jsx("div",{className:"text-sm text-slate-700",children:l("dashboardUpload.form.noWorkflowsModal.body")})}),e.jsx(be,{children:e.jsxs(ve,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-medium text-slate-900 mb-4",children:l("dashboardUpload.form.config.title")}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"tour-workflow-kind",className:"block text-sm font-medium text-slate-700 mb-2",children:l("dashboardUpload.form.config.workflowKindLabel","Workflow type")}),e.jsx(Oe,{id:"tour-workflow-kind",value:ne,onChange:s=>ke(s),disabled:G,className:"w-full",options:[{value:"extraction",label:l("dashboardUpload.form.config.workflowKind.extraction","Extraction")},{value:"classification",label:l("dashboardUpload.form.config.workflowKind.classification","Classification")}]})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"tour-workflow-select",className:"block text-sm font-medium text-slate-700 mb-2",children:[l("dashboardUpload.form.config.workflowLabel")," ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Oe,{id:"workflow-select",value:w,onChange:s=>{me(s),s&&W(""),R(null),A(""),L(""),Q("")},disabled:G,className:"w-full min-w-0",placeholder:l("dashboardUpload.form.config.selectWorkflow"),onOpenAttempt:()=>T("select-workflow"),options:K.map(s=>({value:s.id,label:s.title}))}),G&&e.jsx(P,{type:"button",size:"sm",variant:"outline",className:"ml-2 whitespace-nowrap",onClick:()=>{T("select-workflow")&&re(!1)},children:l("dashboardUpload.form.config.changeWorkflow")})]}),G&&e.jsx("p",{className:"text-xs text-blue-600 mt-1",children:l("dashboardUpload.form.config.preselectedHint")})]}),pe&&e.jsx($e,{variant:"danger",className:"mt-3",children:pe})]})]})}),B&&w&&e.jsx(be,{children:e.jsxs(ve,{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:l("dashboardUpload.form.config.scheduledBatch.title")}),e.jsx("p",{className:"text-sm text-slate-600 mb-3",children:V!=null&&V.next_batch_at?l("dashboardUpload.form.config.scheduledBatch.hint",{when:Fe(V.next_batch_at)}):l("dashboardUpload.form.config.scheduledBatch.hintNoNext")}),De?e.jsx("p",{className:"text-sm text-slate-500",children:l("dashboardUpload.form.config.scheduledBatch.loading")}):ge.length===0?e.jsx("p",{className:"text-sm text-slate-500",children:l("dashboardUpload.form.config.scheduledBatch.empty")}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-slate-700",children:l("dashboardUpload.form.config.scheduledBatch.queuedCount",{count:ge.length})}),e.jsx("ul",{className:"max-h-48 overflow-y-auto divide-y divide-slate-100 rounded-md border border-slate-200",children:ge.map(s=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2 text-sm",children:[e.jsx("span",{className:"truncate text-slate-800",title:s.title,children:s.title}),s.created_at?e.jsx("span",{className:"shrink-0 text-xs text-slate-500",children:Fe(s.created_at)}):null]},s.id))})]})]})}),e.jsx("div",{id:"tour-upload-dropzone",className:`border-2 border-dashed rounded-lg p-8 text-center ${Te?"border-blue-500 bg-blue-50":"border-slate-300"}`,onDragOver:t,onDragLeave:o,onDrop:r,onPaste:s=>{T("paste")&&s.clipboardData&&s.clipboardData.files&&s.clipboardData.files.length>0&&y(Array.from(s.clipboardData.files))},tabIndex:0,onKeyDown:s=>{var a;if(s.key==="Enter"||s.key===" "){if(s.preventDefault(),!T("browse-files"))return;(a=document.getElementById("file-upload-files"))==null||a.click()}},children:e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx("div",{className:"rounded-full bg-blue-100 p-3",children:e.jsx(Ge,{className:"h-8 w-8 text-blue-600"})}),e.jsx("h3",{className:"text-lg font-medium text-slate-900",children:l("dashboardUpload.form.drop.title")}),e.jsxs("p",{className:"text-sm text-slate-600 max-w-md",children:[l("dashboardUpload.form.drop.supported"),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:l("dashboardUpload.form.drop.hint")})]}),e.jsxs("div",{className:"mt-2 flex gap-2 justify-center",children:[e.jsxs("label",{htmlFor:"file-upload-files",role:"button",tabIndex:0,className:"group relative inline-flex h-11 cursor-pointer items-center justify-center gap-2.5 rounded-xl border border-silver-tree-200/80 bg-silver-tree-50/60 px-5 text-sm font-semibold text-silver-tree-900 shadow-[0_2px_6px_-1px_rgba(24,77,55,0.08)] transition-all duration-200 ease-in-out hover:-translate-y-0.5 hover:border-silver-tree-300 hover:bg-silver-tree-100/80 hover:shadow-[0_4px_12px_-2px_rgba(24,77,55,0.12)] active:translate-y-0 active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-silver-tree-500/30 focus-visible:ring-offset-2",onKeyDown:s=>{var a;(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),(a=document.getElementById("file-upload-files"))==null||a.click())},children:[e.jsx(oe,{className:"h-4 w-4 text-silver-tree-600 transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-110 group-hover:text-silver-tree-700"}),l("dashboardUpload.form.buttons.browseFiles"),e.jsx("input",{id:"file-upload-files",type:"file",multiple:!0,accept:".pdf,.docx,.zip,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/zip",className:"hidden",onChange:s=>u(s,"browse-files")})]}),e.jsxs("label",{htmlFor:"file-upload-folder",role:"button",tabIndex:0,className:"group relative inline-flex h-11 cursor-pointer items-center justify-center gap-2.5 rounded-xl border border-slate-200/80 bg-white px-5 text-sm font-semibold text-slate-700 shadow-[0_2px_6px_-1px_rgba(15,23,42,0.05)] transition-all duration-200 ease-in-out hover:-translate-y-0.5 hover:border-biloba-flower-300 hover:bg-biloba-flower-50/50 hover:text-biloba-flower-900 hover:shadow-[0_4px_12px_-2px_rgba(91,58,157,0.08)] active:translate-y-0 active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-biloba-flower-500/30 focus-visible:ring-offset-2",onKeyDown:s=>{var a;(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),(a=document.getElementById("file-upload-folder"))==null||a.click())},children:[e.jsx(et,{className:"h-4 w-4 text-slate-400 transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-110 group-hover:text-biloba-flower-600"}),l("dashboardUpload.form.buttons.browseFolders"),e.jsx("input",{id:"file-upload-folder",type:"file",multiple:!0,accept:".pdf,.docx,.zip,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/zip",className:"hidden",onChange:s=>{u(s,"browse-folders")},webkitdirectory:"true",directory:"true"})]})]})]})}),e.jsxs("div",{id:"tour-upload-buttons",className:"mt-4 flex justify-end items-center gap-2",children:[D?e.jsx(P,{variant:"outline",onClick:p,disabled:!w||N.length===0||Ne||Se,isLoading:Pe,children:l("dashboardUpload.form.buttons.previewCost")}):null,e.jsx(P,{onClick:v,disabled:N.length===0||Se,isLoading:Se,children:Ne?D?l("dashboardUpload.form.buttons.checkingBalance"):l("dashboardUpload.form.buttons.uploading","Uploading..."):l("dashboardUpload.form.buttons.uploadFiles")})]}),N.length>0&&e.jsx(be,{children:e.jsx(ve,{className:"p-0",children:e.jsxs("div",{className:"divide-y divide-slate-200",children:[e.jsx("div",{className:"px-6 py-4 bg-slate-50",children:e.jsx("h3",{className:"font-medium text-slate-900",children:l("dashboardUpload.form.selectedFiles.title",{count:N.length})})}),D&&(ie||U)&&e.jsx("div",{className:"px-6 py-4 bg-white",children:e.jsxs("div",{className:"rounded-xl border border-slate-200 p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{children:e.jsx("p",{className:"text-sm font-semibold text-slate-900",children:l("dashboardUpload.form.costPreview.title")})}),xe&&xe===we&&U&&e.jsx("span",{className:"text-xs font-medium text-slate-500",children:l("dashboardUpload.form.costPreview.upToDate")})]}),ie&&e.jsx($e,{variant:"danger",className:"mt-3",children:ie}),he&&!ie&&e.jsx($e,{variant:"warning",className:"mt-3",children:e.jsx("span",{className:"whitespace-pre-line",children:he})}),U&&!ie&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 md:grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-600",children:l("dashboardUpload.form.costPreview.totalEstimatedCost")}),e.jsx("p",{className:"font-semibold text-slate-900",children:J(U.total_estimated_cost)})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-600",children:l("dashboardUpload.form.costPreview.balance")}),e.jsxs("div",{className:"mt-1 space-y-1",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-xs text-slate-500
5whitespace-nowrap",children:[l("dashboardUpload.form.costPreview.balanceNow"),":"]}),e.jsx("span",{className:"font-semibold text-slate-900",children:J(U.balance_before)})]}),(()=>{const s=Re(U.balance_before),d=Re(U.balance_after)-s,i=Math.abs(d),_=d<0,c=d>0,f=_?"bg-red-50 text-red-700 border-red-200":c?"bg-green-50 text-green-700 border-green-200":"bg-slate-50 text-slate-600 border-slate-200",g=`${c?"+":_?"-":""}${J(i)}`;return e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-xs text-slate-500 whitespace-nowrap",children:[l("dashboardUpload.form.costPreview.balanceAfter"),":"]}),e.jsx("span",{className:"font-semibold text-slate-900",children:J(U.balance_after)}),e.jsx("span",{className:`text-[11px] px-2 py-0.5 rounded-full border ${f}`,title:l("dashboardUpload.form.costPreview.balanceDelta"),children:g})]})})()]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-600",children:l("dashboardUpload.form.costPreview.accepted")}),e.jsx("p",{className:"font-semibold text-slate-900",children:l("dashboardUpload.form.costPreview.filesCount",{count:U.accepted_count})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-600",children:l("dashboardUpload.form.costPreview.rejected")}),e.jsx("p",{className:U.rejected_count>0?"font-semibold text-red-700":"font-semibold text-slate-900",children:l("dashboardUpload.form.costPreview.filesCount",{count:U.rejected_count})})]}),U.rejected_count>0&&e.jsxs("div",{className:"md:col-span-2 mt-2",children:[e.jsx("p",{className:"text-xs font-medium text-slate-700",children:l("dashboardUpload.form.costPreview.rejectedFiles")}),e.jsxs("ul",{className:"mt-1 list-disc list-inside text-xs text-slate-600 space-y-0.5",children:[U.rejected.slice(0,10).map(s=>e.jsxs("li",{children:[s.name," â ",l("dashboardUpload.form.costPreview.pagesCount",{count:s.page_count})," = ",J(s.estimated_cost)]},s.name)),U.rejected.length>10&&e.jsx("li",{children:l("dashboardUpload.form.costPreview.andMore",{count:U.rejected.length-10})})]})]})]})]})}),N.map((s,a)=>e.jsxs("div",{className:"px-6 py-4 flex items-center",children:[e.jsx("div",{className:"mr-3",children:E(s.name)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("p",{className:"text-sm font-medium text-slate-900 truncate",children:s.name}),e.jsx("p",{className:"text-sm text-slate-500",children:ze(s.size)})]}),q[s.name]==="uploading"&&e.jsx("div",{className:"w-full bg-slate-200 rounded-full h-1.5 mt-2",children:e.jsx("div",{className:"bg-blue-600 h-1.5 rounded-full transition-all duration-300",style:{width:`${fe[s.name]}%`}})}),q[s.name]==="error"&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:l("dashboardUpload.form.uploadError.inlineHelp")})]}),e.jsxs("div",{className:"ml-4 flex items-center space-x-2",children:[x(q[s.name]),q[s.name]!=="uploading"&&e.jsx("button",{onClick:()=>b(s.name),"aria-label":l("dashboardUpload.form.actions.removeFile",{defaultValue:"Remove file"}),title:l("dashboardUpload.form.actions.removeFile",{defaultValue:"Remove file"}),className:"text-slate-400 hover:text-slate-600",children:e.jsx(Qe,{className:"h-5 w-5"})})]})]},a))]})})})]})},pt=()=>Math.random().toString(36).slice(2,10),gt=()=>{const{t:l}=Ke(),n=m.useCallback((t,o)=>{const r=l(t,o);return typeof r=="string"?r:String(r)},[l]),[k,D]=m.useState(""),[M,de]=m.useState([]),[I,z]=m.useState([]),[Y,$]=m.useState(!1),[K,Z]=m.useState({}),[H,X]=m.useState({}),[ye,le]=m.useState(!1),je=m.useRef(!1),[He,Te]=m.useState([]),[j,N]=m.useState([]),[ue,fe]=m.useState(!1),[ee,q]=m.useState(!1),[O,w]=m.useState(!1),me=m.useRef(null),[pe,W]=m.useState(!1),[G,re]=m.useState(""),[ne,ke]=m.useState("csv"),[te,ge]=m.useState(!1),[se,De]=m.useState([]),[Ve,Pe]=m.useState(!1),[Ie,ie]=m.useState({}),A=m.useRef(0),he=m.useRef(!1),L=m.useCallback(async()=>{const t=await C.getSuggestWorkflowRouterWorkflow();D(t.router_workflow.id)},[]);m.useEffect(()=>{if(!O)return;const t=r=>{r.key==="Escape"&&w(!1)},o=r=>{const u=me.current;u&&r.target instanceof Node&&!u.contains(r.target)&&w(!1)};return window.addEventListener("keydown",t),window.addEventListener("mousedown",o),()=>{window.removeEventListener("keydown",t),window.removeEventListener("mousedown",o)}},[O]),m.useEffect(()=>{if(!pe)return;let t=!1;return Pe(!0),at.getOrganizationMembers().then(o=>{t||De(o||[])}).catch(o=>{console.warn("Failed to load organization members",o),t||De([])}).finally(()=>{t||Pe(!1)}),()=>{t=!0}},[pe]),m.useEffect(()=>{L().catch(t=>{if(console.error("Failed to init suggest-workflow router",t),t&&typeof t=="object"&&"status"in t&&Number(t.status)===404){alert(n("suggestWorkflow.errors.notEnabled",{defaultValue:"Suggest workflow is not enabled for your organization."}));return}alert(n("suggestWorkflow.errors.startFailed",{defaultValue:"Failed to start session"}))})},[L,l]),m.useEffect(()=>{C.getWorkflowOptions(2e3).then(t=>de(t)).catch(t=>
5{console.error("Failed to load workflow options",t)})},[]),m.useEffect(()=>{const t=(j||[]).some(p=>{var E;const v=!!((E=p==null?void 0:p.suggested_meta)!=null&&E.no_match);return!p.suggested_workflow&&!v});if(!(j.length>0&&t))return;const r=(j||[]).map(p=>p.ocr_execution_id).filter(Boolean);if(!r.length)return;let u=!1;const y=async()=>{if(u)return;try{const v=await C.getWorkflowExecutionProgressBatch(r,{includeSystem:!0});if(u)return;ie(E=>{const x={...E};for(const s of v||[])s!=null&&s.id&&(x[String(s.id)]=String(s.status||""));return x})}catch(v){console.warn("Failed to poll execution progress",v)}if(!t)return;const p=Date.now();if(!he.current&&!(p-A.current<3e3)){he.current=!0,A.current=p,fe(!0);try{const v=await C.suggestSuggestWorkflowBatch(r);if(u)return;const E=new Map((v||[]).map(x=>[String(x.execution_id),x]));N(x=>x.map(s=>{var _;if(!s.ocr_execution_id)return s;const a=E.get(String(s.ocr_execution_id));if(!a||String(a.status||"")!=="ok")return s;const d=a.suggested_workflow||null,i=!!((_=a==null?void 0:a.suggested_meta)!=null&&_.no_match);return{...s,suggested_workflow:d,suggested_confidence:typeof a.suggested_confidence=="number"?a.suggested_confidence:null,suggested_meta:a.suggested_meta,chosen_workflow_id:(s.chosen_workflow_id||(d&&!i?String(d.id):null))??null}}))}catch(v){console.warn("Auto-suggest failed",v)}finally{he.current=!1,u||fe(!1)}}};y().catch(()=>{});const b=window.setInterval(()=>{y().catch(()=>{})},2e3);return()=>{u=!0,window.clearInterval(b)}},[j]);const U=t=>{const o=t.type,r=t.name.toLowerCase();return o==="application/pdf"||o==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||o==="application/zip"||r.endsWith(".pdf")||r.endsWith(".docx")||r.endsWith(".zip")},R=t=>{const o=(t||[]).filter(r=>!!r&&U(r));o.length&&(z(r=>{const u=[...r,...o],y=p=>`${p.name}::${p.size}::${p.lastModified}`,b=new Map;for(const p of u)b.set(y(p),p);return Array.from(b.values())}),X(r=>{const u={...r};for(const y of o)u[y.name]=u[y.name]||"pending";return u}),Z(r=>{const u={...r};for(const y of o)u[y.name]=u[y.name]||0;return u}))},xe=t=>{z(o=>o.filter(r=>r.name!==t)),X(o=>{const r={...o};return delete r[t],r}),Z(o=>{const r={...o};return delete r[t],r})},Q=async t=>{t.preventDefault(),$(!1);const o=t.dataTransfer.items;if(o&&o.length>0){const r=[],u=b=>new Promise(p=>{if(b.isFile&&typeof b.file=="function")b.file(v=>{r.push(v),p()});else if(b.isDirectory&&typeof b.createReader=="function"){const v=b.createReader();(async()=>new Promise(x=>{const s=()=>{v.readEntries(async a=>{if(!a||a.length===0){x();return}for(const d of a)await u(d);s()})};s()}))().then(()=>p()).catch(()=>p())}else p()});if(await(async()=>{const b=[];for(let p=0;p<o.length;p++){const v=o[p],E=v.webkitGetAsEntry&&v.webkitGetAsEntry();E&&b.push(u(E))}await Promise.all(b)})(),r.length>0){R(r);return}}t.dataTransfer.files&&t.dataTransfer.files.length>0&&R(Array.from(t.dataTransfer.files))},Ne=t=>{const o=t.target.files?Array.from(t.target.files):[];o.length&&R(o)},_e=async()=>{var t,o,r,u,y;if(!je.current&&k&&I.length){je.current=!0,le(!0);try{const b=await C.precheckDocumentsUpload(I,k,{fallbackToHeuristicOn413:!1,concurrency:3,adaptiveSplitOn413:!0});if(!b.accepted_count){alert(n("suggestWorkflow.errors.insufficientBalance",{defaultValue:"Insufficient balance to upload these documents"}));return}const p=new Set(b.accepted.map(x=>x.name)),v=I.filter(x=>p.has(x.name));X(x=>{const s={...x};return(b.rejected||[]).forEach(a=>{a!=null&&a.name&&(s[a.name]="error")}),s});const E=[];for(const x of v){X(d=>({...d,[x.name]:"uploading"})),Z(d=>({...d,[x.name]:0}));let s;const a=new FormData;a.append("workflow",k),a.append("file",x,x.name);try{let d=0;s=setInterval(()=>{d+=Math.floor(Math.random()*10)+1,d<95&&Z(F=>({...F,[x.name]:d}))},100);const i=await C.uploadDocument(a),_=((t=i==null?void 0:i.document)==null?void 0:t.id)||(i==null?void 0:i.id),c=((o=i==null?void 0:i.execution)==null?void 0:o.id)||null,f=((r=i==null?void 0:i.document)==null?void 0:r.title)||x.name,g=((u=i==null?void 0:i.document)==null?void 0:u.file_type)||null,S=((y=i==null?void 0:i.document)==null?void 0:y.created_at)||null;_&&(E.push({document_id:String(_),ocr_execution_id:c?String(c):null,file:x}),N(F=>[...F,{id:pt(),document_id:String(_),document_title:String(f||""),file_type:g?String(g):null,uploaded_at:S?String(S):null,ocr_execution_id:c?String(c):null,suggested_
5workflow:null,suggested_confidence:null,suggested_meta:null,chosen_workflow_id:null,process:!0}])),clearInterval(s),Z(F=>({...F,[x.name]:100})),X(F=>({...F,[x.name]:"success"}))}catch(d){clearInterval(s),X(i=>({...i,[x.name]:"error"})),console.error("Upload failed",d)}}Te(E),z([])}finally{le(!1),je.current=!1}}},Se=async t=>{N(o=>o.map(r=>r.id===t.id?{...r,process:!r.process}:r))},Ae=async(t,o)=>{N(r=>r.map(u=>u.id===t.id?{...u,chosen_workflow_id:o}:u))},Ue=async()=>{if(j.length){q(!0);try{const t=j.filter(o=>o.process&&o.chosen_workflow_id).map(o=>({document_id:o.document_id,workflow_id:String(o.chosen_workflow_id)}));await C.processSuggestWorkflowBatch(t),alert(n("suggestWorkflow.messages.processingTriggered",{defaultValue:"Processing triggered for selected documents"}))}catch(t){console.error("Processing failed",t),alert(n("suggestWorkflow.errors.processingFailed",{defaultValue:"Failed to process documents"}))}finally{q(!1)}}},We=async t=>{try{const o=j.map(r=>{var b,p;const u=((b=r.suggested_workflow)==null?void 0:b.title)||"",y=((p=M.find(v=>v.id===r.chosen_workflow_id))==null?void 0:p.title)||"";return{file_name:r.document_title||"",uploaded_at:r.uploaded_at||"",suggested_workflow:u,chosen_workflow:y,confidence:typeof r.suggested_confidence=="number"?r.suggested_confidence:0}});await C.exportSuggestWorkflowReportV2(o,t)}catch(o){console.error("Export failed",o);const r=o&&typeof o=="object"&&"message"in o?String(o.message):"";alert(r||n("suggestWorkflow.errors.exportFailed",{defaultValue:"Export failed"}))}},Le=async()=>{if(!j.length)return;const t=(G||"").trim();if(!t){alert(n("suggestWorkflow.email.errors.missingRecipient",{defaultValue:"Recipient email is required"}));return}ge(!0);try{const o=j.map(u=>{var p,v;const y=((p=u.suggested_workflow)==null?void 0:p.title)||"",b=((v=M.find(E=>E.id===u.chosen_workflow_id))==null?void 0:v.title)||"";return{file_name:u.document_title||"",uploaded_at:u.uploaded_at||"",suggested_workflow:y,chosen_workflow:b,confidence:typeof u.suggested_confidence=="number"?u.suggested_confidence:0}}),r=n("suggestWorkflow.email.subject",{defaultValue:"results"});await C.emailSuggestWorkflowReportV2(o,ne,t,r),alert(n("suggestWorkflow.email.messages.sent",{defaultValue:"Email sent"})),W(!1)}catch(o){console.error("Email export failed",o);const r=o&&typeof o=="object"&&"message"in o?String(o.message):"";alert(r||n("suggestWorkflow.email.errors.sendFailed",{defaultValue:"Failed to send email"}))}finally{ge(!1)}},J=j.length?ue?"classifying":"ready":"draft",Re=n(`suggestWorkflow.sessionStatus.${J}`,{defaultValue:J}),ze=t=>{var r;const o=(r=t.split(".").pop())==null?void 0:r.toLowerCase();return o==="pdf"?e.jsx(oe,{className:"h-5 w-5 text-red-500"}):o==="docx"?e.jsx(oe,{className:"h-5 w-5 text-blue-500"}):e.jsx(oe,{className:"h-5 w-5 text-gray-500"})},we=t=>{switch(t){case"success":return e.jsx(Ye,{className:"h-5 w-5 text-green-500"});case"error":return e.jsx(Je,{className:"h-5 w-5 text-red-500"});default:return null}},Be=j.length>0,T=t=>{const o=t!=null&&t.ocr_execution_id&&Ie[t.ocr_execution_id]||"",r=String(o||"").toLowerCase();return r?r==="ocr_processing"?n("suggestWorkflow.itemStatus.analyzing",{defaultValue:"Analyzingâ¦"}):r==="extraction_in_progress"?n("suggestWorkflow.itemStatus.analyzing",{defaultValue:"Analyzingâ¦"}):r==="completed"?n("suggestWorkflow.itemStatus.ready",{defaultValue:"Ready"}):r==="failed"?n("suggestWorkflow.itemStatus.failed",{defaultValue:"Failed"}):n("suggestWorkflow.itemStatus.analyzing",{defaultValue:"Analyzingâ¦"}):null},V=!!(I.length>0||ye||ue||ee||j.length>0),{blocker:B,open:Ee,setOpen:Fe}=ct(V);return e.jsxs("div",{className:Be?"space-y-6 pb-24":"space-y-6",children:[e.jsx(dt,{open:Ee,onStay:()=>{var t;Fe(!1),(t=B.reset)==null||t.call(B)},onLeave:()=>{var t;Fe(!1),(t=B.proceed)==null||t.call(B)}}),e.jsx(be,{children:e.jsxs(ve,{className:"p-6 space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-slate-600",children:n("suggestWorkflow.title",{defaultValue:"Suggest workflow"})}),e.jsx("div",{className:"text-xs text-slate-700",children:n("suggestWorkflow.subtitle",{defaultValue:"Upload documents and we will automatically suggest workflows. You can change each one before processing."})})]})}),e.jsx("div",{className:`border-2 border-dashed rounded-lg p-8 text-center ${Y?"border-blue-500 bg-blue-50":"border-slate-300"}`,onDragOver:t=>{t.preventDefault(),$(!0)},onDragLeave:()=>$(!1),onDrop:t=>{Q(t).catch(()=>{})},onPaste:t=>{t.clipboardData&&t.clipboardData.files&&t.clipboardData.files.length>0&&R(Array.from(t.clipboardData.files))},tabIndex:0,onKeyDown:t=>{var o;(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),(o=document.getElementById("suggest-workflow-file-upload-files"))==null||o.click())},children:e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-4",children:[e.jsx("div",{className:"rounded-full bg-blue-100 p-3",children:e.jsx(Ge,{className:"h-8 w-8 text-blue-600"})}),e.jsx("h3",{className:"text-lg font-medium text-slate-900",children:n("suggestWorkflow.drop.title",{defaultValue:"Drop files here"})}),e.jsxs("p",{className:"text-sm text-slate-600 max-w-md",children:[n("suggestWorkflow.drop.supported",{defaultValue:"Supported: PDF, DOCX, ZIP"}),e.jsx("br",{}),e.jsx("span",{className:"font-medium",children:n("suggestWorkflow.drop.hint",{defaultValue:"Or browse files/folders"})})]}),e.jsxs("div",{className:"mt-2 flex gap-2 justify-center",children:[e.jsxs("label",{htmlFor:"suggest-workflow-file-upload-files",role:"button",tabIndex:0,className:"group relative inline-flex h-11 cursor-pointer items-center justify-center gap-2.5 rounded-xl border border-silver-tree-200/80 bg-silver-tree-50/60 px-5 text-sm font-semibold text-silver-tree-900 shadow-[0_2px_6px_-1px_rgba(24,77,55,0.08)] transition-all duration-200 ease-in-out hover:-translate-y-0.5 hover:border-silver-tree-300 hover:bg-silver-tree-100/80 hover:shadow-[0_4px_12px_-2px_rgba(24,77,55,0.12)] active:translate-y-0 active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-silver-tree-500/30 focus-visible:ring-offset-2",onKeyDown:t=>{var o;(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),(o=document.getElementById("suggest-workflow-file-upload-files"))==null||o.click())},children:[e.jsx(oe,{className:"h-4 w-4 text-silver-tree-600 transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-110 group-hover:text-silver-tree-700"}),l("dashboardUpload.form.buttons.browseFiles"),e.jsx("input",{id:"suggest-workflow-file-upload-files",type:"file",multiple:!0,accept:".pdf,.docx,.zip,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/zip",className:"hidden",onChange:Ne})]}),e.jsxs("label",{htmlFor:"suggest-workflow-file-upload-folder",role:"button",tabIndex:0,className:"group relative inline-flex h-11 cursor-pointer items-center justify-center gap-2.5 rounded-xl border border-slate-200/80 bg-white px-5 text-sm font-semibold text-slate-700 shadow-[0_2px_6px_-1px_rgba(15,23,42,0.05)] transition-all duration-200 ease-in-out hover:-translate-y-0.5 hover:border-biloba-flower-300 hover:bg-biloba-flower-50/50 hover:text-biloba-flower-900 hover:shadow-[0_4px_12px_-2px_rgba(91,58,157,0.08)] active:translate-y-0 active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-biloba-flower-500/30 focus-visible:ring-offset-2",onKeyDown:t=>{var o;(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),(o=document.getElementById("suggest-workflow-file-upload-folder"))==null||o.click())},children:[e.jsx(et,{className:"h-4 w-4 text-slate-400 transition-transform duration-200 ease-out group-hover:-translate-y-0.5 group-hover:scale-110 group-hover:text-biloba-flower-600"}),l("dashboardUpload.form.buttons.browseFolders"),e.jsx("input",{id:"suggest-workflow-file-upload-folder",type:"file",multiple:!0,accept:".pdf,.docx,.zip,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/zip",className:"hidden",onChange:Ne,webkitdirectory:"true",directory:"true"})]})]})]})}),I.length>0&&e.jsx(be,{children:e.jsx(ve,{className:"p-0",children:e.jsxs("div",{className:"divide-y divide-slate-200",children:[e.jsxs("div",{className:"px-6 py-4 bg-slate-50 flex justify-between items-center",children:[e.jsx("h3",{className:"font-medium text-slate-900",children:n("suggestWorkflow.selectedFiles",{defaultValue:"Selected files ({{count}})",count:I.length})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(P,{onClick:_e,isLoading:ye,disabled:!I.length||!k||ye,children:n("suggestWorkflow.actions.upload",{defaultValue:"Upload & analyze"})})})]}),I.map(t=>e.jsxs("div",{className:"px-6 py-4 flex items-center",children:[e.jsx("div",{className:"mr-3",children:ze(t.name)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"flex justify-between",children:e.jsx("p",{className:"text-sm font-medium text-slate-900 truncate",children:t.name})}),H[t.name]==="uploading"&&e.jsx("div",{className:"w-full bg-slate-200 rounded-full h-1.5 mt-2",children:e.jsx("div",{className:"bg-blue-600 h-1.5 rounded-full transition-all duration-300",style:{width:`${K[t.name]||0}%`}})}),H[t.name]==="error"&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:n("suggestWorkflow.uploadError",{defaultValue:"Upload failed"})})]}),e.jsxs("div",{className:"ml-4 flex items-center space-x-2",children:[we(H[t.name]||"pending"),H[t.name]!=="uploading"&&e.jsx("button",{onClick:()=>xe(t.name),className:"text-slate-400 hover:text-slate-600","aria-label":n("suggestWorkflow.actions.removeFile",{defaultValue:"Remove file"}),children:e.jsx(Qe,{className:"h-5 w-5"})})]})]},`${t.name}-${t.size}-${t.lastModified}`))]})})}),(ue||j.length>0&&J!=="ready")&&e.jsx("div",{className:"text-xs text-slate-600",children:n("suggestWorkflow.
5classifying",{defaultValue:"Analyzing documentsâ¦"})})]})}),e.jsx(be,{children:e.jsxs(ve,{className:"p-0",children:[e.jsxs("div",{className:"px-6 py-4 bg-slate-50 flex items-center justify-between",children:[e.jsx("div",{className:"font-medium text-slate-900",children:n("suggestWorkflow.table.title",{defaultValue:"Documents"})}),e.jsxs("div",{className:"text-xs text-slate-600",children:[n("suggestWorkflow.table.status",{defaultValue:"Status"}),": ",Re]})]}),e.jsxs("div",{className:"divide-y divide-slate-200",children:[j.length===0&&e.jsx("div",{className:"px-6 py-8 text-sm text-slate-600",children:n("suggestWorkflow.table.empty",{defaultValue:"Upload documents to start suggestions."})}),j.map(t=>{var o;return e.jsxs("div",{className:"px-6 py-4 grid grid-cols-1 md:grid-cols-12 gap-3 items-center",children:[e.jsxs("div",{className:"md:col-span-4",children:[e.jsx("div",{className:"text-sm font-medium text-slate-900 truncate",children:t.document_title}),e.jsx("div",{className:"text-xs text-slate-500",children:t.file_type})]}),e.jsxs("div",{className:"md:col-span-7",children:[e.jsx("div",{className:"text-xs text-slate-500",children:n("suggestWorkflow.table.workflow",{defaultValue:"Workflow"})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(Oe,{ariaLabel:n("suggestWorkflow.table.workflow",{defaultValue:"Workflow"}),className:"w-full",triggerClassName:"h-10 px-3 py-2 text-sm",value:t.chosen_workflow_id||"",onChange:r=>{const u=r.trim();Ae(t,u||null).catch(()=>{})},disabled:!M.length,options:[{value:"",label:n("suggestWorkflow.table.chooseWorkflow",{defaultValue:"Choose a workflow"})},...M.map(r=>({value:r.id,label:r.title}))]})}),e.jsx("div",{className:"text-[11px] text-slate-500 mt-1",children:t.suggested_workflow?n("suggestWorkflow.table.suggestedInline",{defaultValue:"Suggested automatically: {{title}}{{confidence}} â you can change it.",title:t.suggested_workflow.title,confidence:typeof t.suggested_confidence=="number"?` (${Math.round(t.suggested_confidence)}%)`:""}):(o=t==null?void 0:t.suggested_meta)!=null&&o.no_match?e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-slate-600",children:n("suggestWorkflow.table.noMatch",{defaultValue:"We couldnât find a matching workflow for this document."})}),e.jsx("div",{className:"text-slate-500",children:n("suggestWorkflow.table.noMatchHint",{defaultValue:"Choose a workflow above, or create a new workflow and try again."})})]}):e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ut,{className:"h-3.5 w-3.5 animate-spin"}),n("suggestWorkflow.table.analyzing",{defaultValue:"Analyzing documentâ¦"}),T(t)?e.jsxs("span",{className:"text-slate-400",children:["⢠",T(t)]}):null]})})]}),e.jsx("div",{className:"md:col-span-1 flex items-center justify-start md:justify-end gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{checked:!!t.process,onCheckedChange:()=>Se(t).catch(()=>{}),"aria-label":n("suggestWorkflow.table.process",{defaultValue:"Process"})}),e.jsx("span",{className:"text-xs text-slate-700",children:n("suggestWorkflow.table.process",{defaultValue:"Process"})})]})})]},t.id)})]})]})}),Be&&e.jsx("div",{className:"fixed bottom-0 left-0 right-0 border-t border-slate-200 bg-white/95 backdrop-blur z-40",children:e.jsxs("div",{className:"w-full px-6 py-4 flex flex-wrap items-center justify-end gap-2",children:[e.jsxs("div",{ref:me,className:"relative",children:[e.jsx(P,{variant:"outline",onClick:()=>w(t=>!t),disabled:!j.length,"aria-haspopup":"menu","aria-expanded":O,rightIcon:e.jsx(ot,{className:"h-4 w-4"}),children:n("suggestWorkflow.actions.export",{defaultValue:"Export"})}),O&&e.jsxs("div",{role:"menu",className:"absolute right-0 bottom-full mb-2 w-44 rounded-md border border-slate-200 bg-white shadow-lg overflow-hidden",children:[e.jsx("button",{type:"button",role:"menuitem",className:"w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-100",onClick:()=>{w(!1),W(!0)},children:n("suggestWorkflow.actions.sendEmail",{defaultValue:"Send via emailâ¦"})}),e.jsx("div",{className:"h-px bg-slate-200"}),e.jsx("button",{type:"button",role:"menuitem",className:"w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-100",onClick:()=>{w(!1),We("csv").catch(()=>{})},children:n("suggestWorkflow.actions.exportCsv",{defaultValue:"Export CSV"})}),e.jsx("button",{type:"button",role:"menuitem",className:"w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-100",onClick:()=>{w(!1),We("xlsx").catch(()=>{})},children:n("suggestWorkflow.actions.exportXlsx",{defaultValue:"Export XLSX"})}),e.jsx("button",{type:"button",role:"menuitem",className:"w-full text-left px-3 py-2 text-sm text-slate-700 hover:bg-slate-100",onClick:()=>
5{w(!1),We("json").catch(()=>{})},children:n("suggestWorkflow.actions.exportJson",{defaultValue:"Export JSON"})})]})]}),e.jsx(P,{onClick:Ue,isLoading:ee,disabled:!j.length,children:n("suggestWorkflow.actions.process",{defaultValue:"Process selected"})})]})}),e.jsx(Ze,{open:pe,placement:"center",title:n("suggestWorkflow.email.title",{defaultValue:"Send results"}),onClose:()=>W(!1),closeLabel:n("actions.close",{defaultValue:"Close"}),footer:e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx(P,{variant:"outline",onClick:()=>W(!1),disabled:te,children:n("actions.cancel",{defaultValue:"Cancel"})}),e.jsxs(P,{onClick:Le,isLoading:te,disabled:!j.length,children:[e.jsx(ft,{className:"h-4 w-4 mr-2"}),n("suggestWorkflow.email.actions.send",{defaultValue:"Send email"})]})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-recipient",className:"block text-sm font-medium text-slate-700 mb-1",children:n("suggestWorkflow.email.recipient",{defaultValue:"Recipient"})}),e.jsx(nt,{id:"email-recipient",type:"email",value:G,onChange:t=>re(t.target.value),placeholder:n("suggestWorkflow.email.recipientPlaceholder",{defaultValue:"[email protected]"})}),e.jsx("p",{className:"mt-2 text-xs text-slate-500",children:n("suggestWorkflow.email.hint",{defaultValue:"Weâll send the export as an email attachment."})})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-format",className:"block text-sm font-medium text-slate-700 mb-1",children:n("suggestWorkflow.email.format",{defaultValue:"Format"})}),e.jsx(Oe,{id:"email-format",ariaLabel:n("suggestWorkflow.email.format",{defaultValue:"Format"}),className:"w-full",triggerClassName:"h-10 px-4 py-2 text-sm",value:ne,onChange:t=>{(t==="csv"||t==="xlsx"||t==="json")&&ke(t)},options:[{value:"csv",label:n("suggestWorkflow.email.formats.csv",{defaultValue:"CSV"})},{value:"xlsx",label:n("suggestWorkflow.email.formats.xlsx",{defaultValue:"XLSX"})},{value:"json",label:n("suggestWorkflow.email.formats.json",{defaultValue:"JSON"})}]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-slate-700 mb-2",children:n("suggestWorkflow.email.suggestions",{defaultValue:"Suggestions"})}),Ve?e.jsx("div",{className:"text-sm text-slate-500",children:n("suggestWorkflow.email.loadingMembers",{defaultValue:"Loading membersâ¦"})}):e.jsxs("div",{className:"flex flex-wrap gap-2",children:[(se||[]).map(t=>{var o;return(o=t==null?void 0:t.user)==null?void 0:o.email}).filter(t=>!!t).slice(0,12).map(t=>e.jsx("button",{type:"button",className:"text-xs px-2 py-1 rounded-full border border-slate-200 text-slate-700 hover:bg-slate-50",onClick:()=>re(t),title:n("suggestWorkflow.email.useSuggestion",{defaultValue:"Use this email"}),children:t},t)),!se||se.length===0?e.jsx("div",{className:"text-xs text-slate-500",children:n("suggestWorkflow.email.noSuggestions",{defaultValue:"No org members found."})}):null]})]})]})})]})},Et=()=>{const{t:l}=Ke(),n=Xe(),{suggestWorkflowEnabled:k}=qe(),[D,M]=m.useState(()=>{try{return(new URLSearchParams(window.location.search).get("mode")||"").toLowerCase()==="suggest-workflow"&&k?"suggest-workflow":"standard"}catch{return"standard"}});m.useEffect(()=>{!k&&D==="suggest-workflow"&&M("standard")},[k,D]);const de=m.useRef(!1);m.useEffect(()=>{if(k&&!de.current)try{(new URLSearchParams(window.location.search).get("mode")||"").toLowerCase()==="suggest-workflow"&&(M("suggest-workflow"),de.current=!0)}catch{}},[k]);const I=()=>{const z=new URLSearchParams;z.set("filter","all"),n(`/dashboard/documents?${z.toString()}`,{state:{fromUploadHistory:!0,clearDates:!0,sort:{key:"created_at",direction:"desc"}}})};return e.jsxs("div",{children:[e.jsx(lt,{title:l("dashboardUpload.title"),subtitle:l("dashboardUpload.subtitle"),actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{variant:D==="standard"?"default":"outline",onClick:()=>M("standard"),children:l("dashboardUpload.modes.standard","Standard upload")}),k?e.jsx(P,{variant:D==="suggest-workflow"?"default":"outline",onClick:()=>M("suggest-workflow"),children:l("dashboardUpload.modes.suggestWorkflow","Suggest workflow")}):null,e.jsx(P,{onClick:I,children:l("dashboardUpload.actions.viewHistory")})]})}),e.jsx("div",{className:"p-6",children:D==="standard"?e.jsx(mt,{}):e.jsx(gt,{})})]})};export{Et 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.