1import{c as fe,t as ce,r as m,s as p,u as je,j as e,B,y as X,aC as gt,m as q,a as at,F as ht,a7 as st,n as be,T as vt,a8 as ft,a9 as jt,aa as kt,ab as yt,ac as bt,ad as wt,ae as _t,af as Nt,w as nt,x as rt,$ as Ct,k as se,G as pe,H as xe,J as ge,K as St,N as Dt,I as Me,X as Et,E as zt}from"./index-MoAbC8_9.js";import{L as Be}from"./Layout-jB2m3rBw.js";import{B as ee}from"./badge-BHbYeRgi.js";import{P as it}from"./progress-CIau9pND.js";import{D as ze,a as Te,b as Ae,c as ie,f as Pe,C as ot,j as Tt}from"./Header-CnJGZ8vQ.js";import{D as At,a as Pt,b as It,c as Bt,d as Ft,e as Rt}from"./dialog-DrI7Oddz.js";import{S as Ne,a as Ce,b as Se,c as De,d as ye}from"./select-ChAxOmxm.js";import{_ as Vt,i as Mt,a as Ut,h as $t,R as Ue,S as lt,j as Ot,W as qe}from"./useCostCategories-Cao1SRG4.js";import{U as He,L as Kt}from"./upload-BH1HltYO.js";import{F as Ie}from"./file-text-Bif0RP8Y.js";import{C as me}from"./circle-check-big-_JLEBINb.js";import{A as Lt}from"./arrow-left-CZKmX_Y-.js";import{C as ct}from"./circle-check-7w5_oQMu.js";import{C as $e}from"./chevron-down-BDe4YKQW.js";import{T as Ge}from"./trash-2-DRJ_nWSl.js";import{D as ve}from"./database-yc2noHJi.js";import{S as dt}from"./shield-check-DViJUJ8V.js";import{L as Oe}from"./languages-DJ80weRR.js";import{D as Zt}from"./download-DXQgHLv7.js";import{d as qt,T as Ht}from"./de-Ihp2MKUo.js";import{c as Gt}from"./cs-DzBP63t1.js";import{e as Wt}from"./en-US-CQ3IMwMG.js";import{C as Qt}from"./confirm-dialog-DHYtbMdr.js";import{C as mt}from"./circle-alert-CI-iPm0z.js";import{P as Jt}from"./play-Dv41UmTM.js";import{C as Xt}from"./clipboard-check-BNBiN_o5.js";import{C as We}from"./checkbox-D2A7tWS7.js";import{T as Yt,a as ea,b as Fe,c as ae,d as ta,e as Y}from"./table-BNHSYido.js";import{E as aa}from"./ellipsis-BEOtFA2b.js";import{S as sa}from"./search-_fcwEKN-.js";import{F as na}from"./filter-DtRxSZ25.js";import{E as ra}from"./eye-DKrvAixa.js";import{S as Ee}from"./sparkles-OdPvYVOS.js";import{C as ia}from"./circle-help-BFmb_2uk.js";import{T as _e}from"./textarea-4z16PwID.js";import{S as Re}from"./separator-CQ84aZ0V.js";import{T as oa}from"./thumbs-up-jDPlFMTx.js";import{S as la}from"./save-DWdLHugL.js";import{S as Ve}from"./skeleton-ClxqB572.js";import{A as ca,a as da}from"./alert-B1M6s1_G.js";import"./mountain-BHfTfCFy.js";import"./user-Cvsz7Lm_.js";import"./index-BdQq_4o_.js";import"./index-D9-GACGG.js";import"./chevron-up-JyGCcpt9.js";import"./endOfMonth-D_4h-ZFk.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ma=fe("BookPlus",[["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ua=fe("Bookmark",[["path",{d:"m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z",key:"1fy3hk"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const pa=fe("CheckCheck",[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const xa=fe("FileWarning",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const ut=fe("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);/** 27 * @license lucide-react v0.462.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree.
31 */const ga=fe("ThumbsDown",[["path",{d:"M17 14V2",key:"8ymqnk"}],["path",{d:"M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z",key:"m61m77"}]]);function pt(){const{toast:t}=ce(),[j,k]=m.useState(!1),[b,P]=m.useState(0);return{translateBatch:async i=>{k(!0),P(0);try{const{data:l,error:w}=await p.functions.invoke("translate-labels",{body:{batch_id:i}});if(w)throw w;return P(100),l.success&&t({title:"PÅeklad dokonÄen",description:`PÅeloženo ${l.translated} položek.`}),l}catch(l){return console.error("Translation error:",l),t({variant:"destructive",title:"Chyba pÅekladu",description:l instanceof Error?l.message:"NepodaÅilo se pÅeložit položky."}),{success:!1,translated:0,failed:0,error:String(l)}}finally{k(!1)}},translateDocument:async i=>{k(!0),P(0);try{const{data:l,error:w}=await p.functions.invoke("translate-labels",{body:{document_id:i}});if(w)throw w;return P(100),l.success&&t({title:"PÅeklad dokonÄen",description:`PÅeloženo ${l.translated} položek.`}),l}catch(l){return console.error("Translation error:",l),t({variant:"destructive",title:"Chyba pÅekladu",description:l instanceof Error?l.message:"NepodaÅilo se pÅeložit položky."}),{success:!1,translated:0,failed:0,error:String(l)}}finally{k(!1)}},translateItems:async i=>{k(!0),P(0);try{const{data:l,error:w}=await p.functions.invoke("translate-labels",{body:{item_ids:i}});if(w)throw w;return P(100),l.success&&t({title:"PÅeklad dokonÄen",description:`PÅeloženo ${l.translated} položek.`}),l}catch(l){return console.error("Translation error:",l),t({variant:"destructive",title:"Chyba pÅekladu",description:l instanceof Error?l.message:"NepodaÅilo se pÅeložit položky."}),{success:!1,translated:0,failed:0,error:String(l)}}finally{k(!1)}},isTranslating:j,progress:b}}function xt(){const{toast:t}=ce(),[j,k]=m.useState(!1);return{commitBatch:async P=>{var c;k(!0);try{const{data:x,error:s}=await p.functions.invoke("commit-batch",{body:{batch_id:P}});if(s)throw s;if(x.success){const i=x.houseCostsCreated+x.reserveFundExpendituresCreated;t({title:"Import dokonÄen",description:`VytvoÅeno ${x.houseCostsCreated} kategorià nákladů a ${x.reserveFundExpendituresCreated} výdajů z fondu oprav.`})}else((c=x.errors)==null?void 0:c.length)>0&&t({variant:"destructive",title:"Import s chybami",description:x.errors[0]});return x}catch(x){console.error("Commit batch error:",x);const s=x instanceof Error?x.message:"NepodaÅilo se dokonÄit import.";return t({variant:"destructive",title:"Chyba importu",description:s}),{success:!1,houseCostsCreated:0,houseCostItemsCreated:0,reserveFundExpendituresCreated:0,errors:[s],error:s}}finally{k(!1)}},isCommitting:j}}Vt.workerSrc=`//unpkg.com/pdfjs-dist@${Mt}/build/pdf.worker.min.mjs`;const Qe={cs:{upload:"Nahrát PDF",uploadTitle:"Nahrát dokument",uploadDesc:"Nahrajte PDF dokument pro zpracovánÃ",selectFile:"Vybrat soubor",format:"Form
31át dokumentu",cancel:"ZruÅ¡it",confirm:"Nahrát",uploading:"Nahrávám...",success:"Dokument úspÄÅ¡nÄ nahrán",error:"Chyba pÅi nahrávánÃ",formatAltmann:"Altmann & Partner",formatBlackpoint:"BlackPoint",formatTechem:"Techem",formatUnknown:"Neznámý",existingDocs:"Dokumenty v batchi",noDocs:"ZatÃm žádné dokumenty"},en:{upload:"Upload PDF",uploadTitle:"Upload Document",uploadDesc:"Upload a PDF document for processing",selectFile:"Select file",format:"Document format",cancel:"Cancel",confirm:"Upload",uploading:"Uploading...",success:"Document uploaded successfully",error:"Upload error",formatAltmann:"Altmann & Partner",formatBlackpoint:"BlackPoint",formatTechem:"Techem",formatUnknown:"Unknown",existingDocs:"Documents in batch",noDocs:"No documents yet"},de:{upload:"PDF hochladen",uploadTitle:"Dokument hochladen",uploadDesc:"PDF-Dokument zur Verarbeitung hochladen",selectFile:"Datei auswählen",format:"Dokumentformat",cancel:"Abbrechen",confirm:"Hochladen",uploading:"Wird hochgeladen...",success:"Dokument erfolgreich hochgeladen",error:"Fehler beim Hochladen",formatAltmann:"Altmann & Partner",formatBlackpoint:"BlackPoint",formatTechem:"Techem",formatUnknown:"Unbekannt",existingDocs:"Dokumente im Batch",noDocs:"Noch keine Dokumente"}},ha=[{value:"altmann",label:"Altmann & Partner"},{value:"blackpoint",label:"BlackPoint"},{value:"techem",label:"Techem"}];function va({batchId:t,batchYear:j,existingDocuments:k,onDocumentsAdded:b}){const{language:P}=je(),{toast:c}=ce(),x=Qe[P]||Qe.cs,s=m.useRef(null),[i,l]=m.useState(!1),[w,u]=m.useState(!1),[o,N]=m.useState(null),[y,O]=m.useState("altmann"),[Z,T]=m.useState(0),[R,$]=m.useState(""),[d,S]=m.useState([]),V=C=>{const _=C.toLowerCase();return _.includes("altmann")||_.includes("partner")?"altmann":_.includes("blackpoint")?"blackpoint":_.includes("techem")?"techem":"altmann"},M=async C=>{const _=await C.arrayBuffer(),U=await Ut({data:_}).promise;let D="";const K=[];for(let F=1;F<=U.numPages;F++){const h=(await(await U.getPage(F)).getTextContent()).items.map(r=>r.str).join(" ");K.push({pageNumber:F,text:h}),D+=` 32--- Page ${F} --- 33${h}`}return{pageCount:U.numPages,format:V(D),fullText:D.trim(),pages:K}},z=async C=>{var U;const _=(U=C.target.files)==null?void 0:U[0];if(_){u(!1),N(_);try{const D=await M(_);T(D.pageCount),O(D.format),$(D.fullText),S(D.pages)}catch(D){console.error("Error parsing PDF:",D),T(0),$(""),S([])}l(!0),C.target.value=""}},G=async()=>{if(!o){console.log("[Upload] No file selected");return}console.log("[Upload] Starting upload...",{fileName:o.name,fileSize:o.size,batchId:t,batchYear:j}),c({title:"ð Upload started",description:`Uploading ${o.name}...`}),u(!0);try{const C=`${Date.now()}_${o.name}`,_=`imports/${j}/${C}`;console.log("[Upload] Step 1: Uploading to storage...",{bucket:"documents",filePath:_});const{data:U,error:D}=await p.storage.from("documents").upload(_,o);if(console.log("[Upload] Step 1 result:",{uploadData:U,uploadError:D}),D)throw c({variant:"destructive",title:"â Storage upload failed",description:D.message}),D;c({title:"â Step 1/5",description:"File uploaded to storage"}),console.log("[Upload] Step 3: Creating pdf_documents record...");const{data:K,error:F}=await p.from("pdf_documents").insert({file_name:o.name,file_path:_,document_type:"betriebskosten",page_count:Z,document_format:y,year:j,status:"parsed",raw_text:R,raw_pages:d,batch_id:t}).select().single();if(console.log("[Upload] Step 3 result:",{docData:K,docError:F}),F)throw c({variant:"destructive",title:"â DB insert failed",description:F.message}),F;c({title:"â Step 3/5",description:`Document record created: ${K.id}`}),console.log("[Upload] Step 4: Updating import_batches...");const{data:Q,error:a}=await p.from("import_batches").select("document_ids, document_formats").eq("id",t).single();if(console.log("[Upload] Step 4a fetch result:",{batchData:Q,batchFetchError:a}),a)throw c({variant:"destructive",title:"â Batch fetch failed",description:a.message}),a;const h=[...Q.document_ids||[],K.id],r=[...new Set([...Q.document_formats||[],y])],{error:v}=await p.from("import_batches").update({document_ids:h,document_formats:r}).eq("id",t);if(console.log("[Upload] Step 4b update result:",{updateError:v}),v)throw c({variant:"destructive",title:"â Batch update failed",description:v.message}),v;c({title:"â Step 4/5",description:"Batch updated with document"}),console.log("[Upload] Step 5: Invoking parse-and-extract edge function...");const{data:g,error:H}=await p.functions.invoke("parse-and-extract",{body:{documentId:K.id,batchId:t}});console.log("[Upload] Step 5 result:",{extractData:g,extractError:H}),c(H?{variant:"destructive",title:"â ï¸ Extraction trigger failed",description:H.message}:{title:"â Step 5/5",description:"Extraction started"}),c({title:x.success,description:o.name}),l(!1),N(null),b()}catch(C){console.error("[Upload] Error:",C),c({variant:"destructive",title:x.error,description:C instanceof Error?C.message:"Unknown error"})}
33finally{u(!1),console.log("[Upload] Finished")}};return e.jsxs("div",{className:"flex items-center",children:[e.jsxs(B,{variant:"outline",size:"sm",onClick:()=>{var C;return(C=s.current)==null?void 0:C.click()},className:"h-7 text-xs gap-1.5",children:[e.jsx(He,{className:"h-3.5 w-3.5"}),x.upload]}),e.jsx("input",{ref:s,type:"file",accept:".pdf",onChange:z,className:"hidden"}),e.jsx(At,{open:i,onOpenChange:l,children:e.jsxs(Pt,{children:[e.jsxs(It,{children:[e.jsx(Bt,{children:x.uploadTitle}),e.jsx(Ft,{children:x.uploadDesc})]}),o&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-muted rounded-lg",children:[e.jsx(Ie,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:o.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(o.size/1024/1024).toFixed(2)," MB ⢠",Z," stran"]})]}),e.jsx(me,{className:"h-5 w-5 text-green-500"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(X,{children:x.format}),e.jsxs(Ne,{value:y,onValueChange:O,children:[e.jsx(Ce,{children:e.jsx(Se,{})}),e.jsx(De,{children:ha.map(C=>e.jsx(ye,{value:C.value,children:C.label},C.value))})]})]})]}),e.jsxs(Rt,{children:[e.jsx(B,{type:"button",variant:"outline",onClick:()=>l(!1),disabled:w,children:x.cancel}),e.jsx("button",{type:"button",className:gt({size:"default",variant:"default",className:"h-9 px-3"}),onPointerDownCapture:()=>{console.log("[UI] Upload pointerDown")},onClick:()=>{console.log("[UI] Upload button clicked"),c({title:"[UI] Click received",description:"Starting uploadâ¦"}),G()},disabled:w||!o,children:w?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),x.uploading]}):e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"h-4 w-4"}),x.confirm]})})]})]})})]})}const Je={cs:{back:"ZpÄt",refresh:"Obnovit",export:"Export",translate:"PÅeložit",translating:"PÅekládám...",commit:"DokonÄit import",committing:"Importuji...",items:"položek",reextract:"Znovu extrahovat",reextractAll:"VÅ¡echny dokumenty",reextracting:"Extrahuji...",reextractSuccess:"Extrakce dokonÄena",reextractError:"Chyba extrakce",revalidate:"Znovu validovat",revalidating:"Validuji...",revalidateSuccess:"Validace dokonÄena",revalidateError:"Chyba validace",fixPages:"Opravit stránky",fixingPages:"Opravuji...",fixPagesSuccess:"Stránky opraveny",fixPagesError:"Chyba opravy stránek",noDocs:"Žádné dokumenty",deleteDoc:"Smazat dokument",deleteDocConfirm:"Opravdu chcete smazat tento dokument?",deleteDocDesc:"Budou smazány vÅ¡echny extrahované položky a soubor z úložiÅ¡tÄ.",cancel:"ZruÅ¡it",delete:"Smazat",deleting:"Mažu...",deleteSuccess:"Dokument smazán",deleteError:"Chyba pÅi mazánÃ",status:{created:"Nový",parsed:"Rozparsováno",extracted:"Extrahováno",validated:"Validováno",mapped:"Mapováno",translated:"PÅeloženo",reviewed:"Zkontrolováno",committed:"Importováno",failed:"Chyba"}},en:{back:"Back",refresh:"Refresh",export:"Export",translate:"Translate",translating:"Translating...",commit:"Commit Import",committing:"Committing...",items:"items",reextract:"Re-extract",reextractAll:"All documents",reextracting:"Extracting...",reextractSuccess:"Extraction complete",reextractError:"Extraction error",revalidate:"Re-validate",revalidating:"Validating...",revalidateSuccess:"Validation complete",revalidateError:"Validation error",fixPages:"Fix pages",fixingPages:"Fixing...",fixPagesSuccess:"Pages fixed",fixPagesError:"Fix pages error",noDocs:"No documents",deleteDoc:"Delete document",deleteDocConfirm:"Delete this document?",deleteDocDesc:"All extracted items and the file will be deleted.",cancel:"Cancel",delete:"Delete",deleting:"Deleting...",deleteSuccess:"Document deleted",deleteError:"Delete error",status:{created:"New",parsed:"Parsed",extracted:"Extracted",validated:"Validated",mapped:"Mapped",translated:"Translated",reviewed:"Reviewed",committed:"Committed",failed:"Failed"}},de:{back:"Zurück",refresh:"Aktualisieren",export:"Export",translate:"Ãbersetzen",translating:"Ãbersetze...",commit:"Import abschlieÃen",committing:"Importiere...",items:"Elemente",reextract:"Erneut extrahieren",reextractAll:"Alle Dokumente",reextracting:"Extrahiere...",reextractSuccess:"Extraktion abgeschlossen",reextractError:"Extraktionsfehler",revalidate:"Erneut validieren",revalidating:"Validiere...",revalidateSuccess:"Validierung abgeschlossen",revalidateError:"Validierungsfehler",fixPages:"Seiten reparieren",fixingPages:"Repariere...",fixPagesSuccess:"Seiten repariert",fixPagesError:"Fehler beim Reparieren",noDocs:"Keine Dokumente",deleteDoc:"Dokument löschen",deleteDocConfirm:"Dieses Dokument löschen?",deleteDocDesc:"Alle extrahierten Elemente und die Datei werden gelöscht.",cancel:"Abbrechen",delete:"Löschen",deleting:"Lösche...",deleteSuccess:"Dokument gelöscht",deleteError:"Löschfehler",status:{created:"Neu",parsed:"Geparst",extracted:"Extrahiert",validated:"Validiert",mapped:"Zugeordnet",translated:"Ãbersetzt",reviewed:"Ãberprüft",committed:"Importiert",failed:"Fehlgeschlagen"}}},fa={created:"secondary",parsed:"secondary",extracted:"secondary",validated:"secondary",mapped:"secondary",translated:"secondary",reviewed:"secondary",committed:"default",failed:"destructive"};function ja({batch:t,documents:j,onRefresh:k,itemStats:b,onExtractingChange:P}){const c=at(),{language:x}=je(),{toast:s}=ce(),i=Je[x]||Je.cs,{translateBatch:l,isTranslating:w,progress:u}=pt(),{commitBatch:o,isCommitting:N}=xt(),[y,O]=m.useState(null),[Z,T]=m.useState(!1),[R,$]=m.useState(!1),[d,S]=m.useState(null),[V,M]=m.useState(!1),z=x==="cs"?Gt:x==="de"?qt:Wt,G=$t(new Date(t.created_at),{addSuffix:!0,locale:z}),C=r=>{O(r),P==null||P(r!==null)},_=async()=>{(await l(t.id)).success&&k()},U=async()=>{(await o(t.id)).success&&k()},D=async r=>{C(r);try{await p.from("extracted_cost_items").delete().eq("document_id",r);const{data:v,error:g}=await p.functions.invoke("parse-and-extract",{body:{documentId:r,batchId:t.id}});if(g)throw g;s({title:i.reextractSuccess,description:`${(v==null?void 0:v.itemCount)||0} položek`}),k()}catch(v){s({variant:"destructive",title:i.reextractError,description:v instanceof Error?v.message:"Error"})}finally{C(null)}},K=async()=>{C("all");try{for(const r of j)await p.from("extracted_cost_items").delete().eq("document_id",r.id),await p.functions.invoke("parse-and-extract",{body:{documentId:r.id,batchId:t.id}});s({title:i.reextractSuccess,description:`${j.length} dokumentů`}),k()}catch{s({variant:"destructive",title:i.reextractError})}finally{C(null)}},F=async()=>{T(!0);try{const{data:r,error:v}=await p.functions.invoke("validate-evidence",{body:{batchId:t.id}});if(v)throw v;const g=r==null?void 0:r.summary;s({title:i.revalidateSuccess,description:`${(g==null?void 0:g.evidenceOkCount)||0} OK, ${(g==null?void 0:g.evidenceFailedCount)||0} chyb z ${(g==null?void 0:g.totalItems)||0} položek`}),k()}catch(r){s({variant:"destructive",title:i.revalidateError,description:r instanceof Error?r.message:"Error"})}finally{T(!1)}},Q=async()=>{var r,v;$(!0);try{const{data:g,error:H}=await p.functions.invoke("migrate-raw-pages",{body:{batchId:t.id}});if(H)throw H;s({title:i.fixPagesSuccess,description:`${(g==null?void 0:g.migrated)||0} dokumentů, validace: ${((r=g==null?void 0:g.validation)==null?void 0:r.passed)||0} OK, ${((v=g==null?void 0:g.validation)==null?void 0:v.failed)||0} chyb`}),k()}catch(g){s({variant:"destructive",title:i.fixPagesError,description:g instanceof Error?g.message:"Error"})}finally{$(!1)}},a=async()=>
33{if(d){M(!0);try{const r=d.id,{data:v}=await p.from("extracted_cost_items").select("id").eq("document_id",r),g=(v==null?void 0:v.map(E=>E.id))||[];g.length>0&&(await p.from("item_mappings").delete().in("staging_item_id",g),await p.from("item_translations").delete().in("staging_item_id",g)),await p.from("extracted_cost_items").delete().eq("document_id",r);const{data:H}=await p.from("pdf_documents").select("file_path").eq("id",r).single();H!=null&&H.file_path&&await p.storage.from("documents").remove([H.file_path]);const f=t.document_ids.filter(E=>E!==r);await p.from("import_batches").update({document_ids:f}).eq("id",t.id),await p.from("pdf_documents").delete().eq("id",r),s({title:i.deleteSuccess,description:d.file_name}),S(null),k()}catch(r){console.error("Delete error:",r),s({variant:"destructive",title:i.deleteError,description:r instanceof Error?r.message:"Error"})}finally{M(!1)}}},h=t.status!=="committed"&&!N&&!w;return e.jsxs("div",{className:"border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 h-14",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(B,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",onClick:()=>c("/admin"),children:e.jsx(Lt,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("h1",{className:"text-lg font-semibold",children:["Import ",t.year]}),e.jsx(ee,{variant:fa[t.status]||"secondary",className:"text-xs",children:i.status[t.status]||t.status})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground hidden sm:flex items-center gap-1.5",children:[e.jsx(ht,{className:"h-3.5 w-3.5"}),G]}),e.jsx("div",{className:"h-4 w-px bg-border hidden sm:block"}),e.jsx(B,{variant:"ghost",size:"sm",onClick:k,className:"h-8",children:e.jsx(st,{className:"h-4 w-4"})}),e.jsxs(B,{variant:t.status==="committed"?"outline":"default",size:"sm",onClick:U,disabled:!h,className:"h-8",children:[N?e.jsx(q,{className:"h-4 w-4 animate-spin"}):e.jsx(ct,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5 hidden sm:inline",children:N?i.committing:i.commit})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-t bg-muted/20",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:j.length})]}),j.length>0?e.jsx("div",{className:"flex items-center gap-1.5 flex-wrap",children:j.map(r=>e.jsxs(ze,{children:[e.jsx(Te,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs bg-background border rounded-md hover:bg-muted/50 transition-colors max-w-[180px]",children:[e.jsx("span",{className:"truncate",children:r.file_name}),e.jsx($e,{className:"h-3 w-3 shrink-0 opacity-50"})]})}),e.jsxs(Ae,{align:"start",className:"w-48",children:[e.jsxs(ie,{onClick:()=>D(r.id),disabled:y===r.id,children:[y===r.id?e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ue,{className:"h-4 w-4 mr-2"}),i.reextract]}),e.jsx(Pe,{}),e.jsxs(ie,{onClick:()=>S(r),className:"text-destructive focus:text-destructive",children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),i.deleteDoc]})]})]},r.id))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:i.noDocs}),e.jsx(va,{batchId:t.id,batchYear:t.year,existingDocuments:j,onDocumentsAdded:k})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[b&&e.jsxs("div",{className:"flex items-center gap-3 text-xs mr-3",children:[e.jsxs("span",{className:"text-muted-foreground",title:"Celkový poÄet extrahovaných položek v tomto batchi",children:["Celkem: ",e.jsx("span",{className:"font-medium",children:b.total})]}),e.jsx("div",{className:"h-3 w-px bg-border"}),e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 flex items-center gap-1",title:"Zmapováno celkem: Položky s pÅiÅazenou cÃlovou kategoriÃ",children:[e.jsx(Kt,{className:"h-3 w-3"}),b.mapped]}),b.dbMapped>
330&&e.jsxs("span",{className:"text-blue-600 dark:text-blue-400 flex items-center gap-1",title:"DB pravidla: Položky zmapované pomocà existujÃcÃch pravidel v databázi",children:[e.jsx(ve,{className:"h-3 w-3"}),b.dbMapped]}),b.aiMapped>0&&e.jsxs("span",{className:"text-violet-600 dark:text-violet-400 flex items-center gap-1",title:"AI mapovánÃ: Položky zmapované pomocà AI (fallback)",children:["⨠",b.aiMapped]}),b.userMapped>0&&e.jsxs("span",{className:"text-purple-600 dark:text-purple-400 flex items-center gap-1",title:"Uživatelsky zmapováno: Položky ruÄnÄ pÅiÅazené uživatelem",children:["ð¤ ",b.userMapped]}),b.total-b.mapped>0&&e.jsxs("span",{className:"text-orange-600 dark:text-orange-400 flex items-center gap-1",title:"Nezmapováno: Položky bez pÅiÅazené kategorie",children:[e.jsx(be,{className:"h-3 w-3"}),b.total-b.mapped]}),e.jsx("div",{className:"h-3 w-px bg-border"}),e.jsxs("span",{className:"text-green-600 dark:text-green-400 flex items-center gap-1",title:"Schváleno: Položky oznaÄené jako správné a pÅipravené k importu",children:[e.jsx(me,{className:"h-3 w-3"}),b.approved]}),b.needsReview>0&&e.jsxs("span",{className:"text-yellow-600 dark:text-yellow-400 flex items-center gap-1",title:"Ke kontrole: Položky vyžadujÃcà manuálnà ovÄÅenÃ",children:[e.jsx(vt,{className:"h-3 w-3"}),b.needsReview]})]}),!b&&e.jsxs("span",{className:"text-xs text-muted-foreground mr-2",children:[t.total_items," ",i.items]}),j.length>1&&e.jsx(B,{variant:"ghost",size:"sm",onClick:K,disabled:y!==null,className:"h-7 px-2",children:y==="all"?e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ue,{className:"h-3.5 w-3.5"})}),e.jsx(B,{variant:"ghost",size:"sm",onClick:Q,disabled:R||j.length===0,className:"h-7 px-2",title:i.fixPages,children:R?e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(xa,{className:"h-3.5 w-3.5"})}),e.jsx(B,{variant:"ghost",size:"sm",onClick:F,disabled:Z||t.total_items===0,className:"h-7 px-2",title:i.revalidate,children:Z?e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(dt,{className:"h-3.5 w-3.5"})}),e.jsx(B,{variant:"ghost",size:"sm",onClick:_,disabled:w,className:"h-7 px-2",title:i.translate,children:w?e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Oe,{className:"h-3.5 w-3.5"})}),e.jsx(B,{variant:"ghost",size:"sm",className:"h-7 px-2",children:e.jsx(Zt,{className:"h-3.5 w-3.5"})})]})]}),w&&e.jsxs("div",{className:"px-4 py-2 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-muted-foreground",children:i.translating}),e.jsxs("span",{className:"font-medium",children:[u,"%"]})]}),e.jsx(it,{value:u,className:"h-1.5"})]}),t.error_message&&e.jsx("div",{className:"mx-4 mb-3 p-2 bg-destructive/10 border border-destructive/20 rounded text-sm text-destructive",children:t.error_message}),e.jsx(ft,{open:!!d,onOpenChange:r=>!r&&S(null),children:e.jsxs(jt,{children:[e.jsxs(kt,{children:[e.jsx(yt,{children:i.deleteDocConfirm}),e.jsxs(bt,{children:[e.jsx("span",{className:"font-medium",children:d==null?void 0:d.file_name}),e.jsx("br",{}),i.deleteDocDesc]})]}),e.jsxs(wt,{children:[e.jsx(_t,{disabled:V,children:i.cancel}),e.jsx(Nt,{onClick:a,disabled:V,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:V?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}),i.deleting]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{className:"h-4 w-4 mr-2"}),i.delete]})})]})]})})]})}const he=[{key:"created",icon:Tt,action:null},{key:"extracted",icon:Ie,action:null},{key:"validated",icon:ct,action:"validate"},{key:"mapped",icon:ut,action:"map"},{key:"translated",icon:Oe,action:"translate"},{key:"reviewed",icon:Xt,action:null},{key:"committed",icon:ve,action:"commit"}],Xe={cs:{steps:{created:"VytvoÅeno",extracted:"Extrahováno",validated:"Validováno",mapped:"Mapováno",translated:"PÅeloženo",reviewed:"Zkontrolováno",committed:"Importováno"},tooltips:{created:"Batch vytvoÅen, Äeká na dokumenty",extracted:"Položky extrahovány z PDF",validated:"Evidence ovÄÅena proti zdrojovým datům",mapped:"Kategorie pÅiÅazeny pomocà DB pravidel a AI",translated:"Popisky pÅeloženy do CS a EN",reviewed:"Položky manuálnÄ zkontrolovány",committed:"Data importována do produkÄnÃch tabulek"},contextHelp:{created:"Nahrajte dokumenty pro zahájenà extrakce.",extracted:'Položky extrahovány. KliknÄte "Validovat" pro ovÄÅenà evidence.',validated:'Evidence ovÄÅena. KliknÄte "Mapovat" pro pÅiÅazenà kategoriÃ.',mapped:'Kategorie pÅiÅazeny. Zkontrolujte položky "Ke kontrole", pak kliknÄte "PÅeložit".',translated:"PÅeklady dokonÄeny. Schvalte položky ke kontrole.",reviewed:'VÅ¡e zkontrolováno. KliknÄte "Importovat" pro finálnà import.',committed:"Import dokonÄen. Data jsou v produkÄnà databázi."},actions:{validate:"Validovat",map:"Mapovat",translate:"PÅeložit",commit:"Importovat"},stepActions:{rerun:"Spustit znovu",revertTo:"Vrátit se na tento krok"},revertConfirm:{title:"Vrátit se zpÄt?",description:"Data z následujÃcÃch kroků budou smazána. Tato akce nelze vrátit.",confirm:"Ano, vrátit",cancel:"ZruÅ¡it"},nextStep:"Dalšà krok",running:"Zpracovávám...",stats:{evidenceOk:"Evidence OK",evidenceFailed:"Evidence chyba",mappingDb:"DB pravidla",mappingAi:"AI mapovánÃ",needsReview:"Ke kontrole",totalItems:"Položek celkem"},cannotCommit:"Nelze importovat - existujà položky ke kontrole"},en:{steps:{created:"Created",extracted:"Extracted",validated:"Validated",mapped:"Mapped",translated:"Translated",reviewed:"Reviewed",committed:"Committed"},tooltips:{created:"Batch created, waiting for documents",extracted:"Items extracted from PDF",validated:"Evidence verified against source data",mapped:"Categories assigned using DB rules and AI",translated:"Labels translated to CS and EN",reviewed:"Items manually reviewed",committed:"Data imported to production tables"},contextHelp:{created:"Upload documents to start extraction.",extracted:'Items extracted. Click "Validate" to verify evidence.',validated:'Evidence verified. Click "Map" to assign categories.',mapped:'Categories assigned. Review items marked "Needs Review", then click "Translate".',translated:"Translations complete. Approve items needing review.",reviewed:'All reviewed. Click "Commit" for final import.',committed:"Import complete. Data is in production database."},actions:{validate:"Validate",map:"Map",translate:"Translate",commit:"Commit"},stepActions:{rerun:"Re-run",revertTo:"Revert to this step"},revertConfirm:{title:"Revert back?",description:"Data from following steps will be deleted. This cannot be undone.",confirm:"Yes, revert",cancel:"Cancel"},nextStep:"Next step",running:"Processing...",stats:{evidenceOk:"Evidence OK",evidenceFailed:"Evidence Failed",mappingDb:"DB Rules",mappingAi:"AI Mapping",needsReview:"Needs Review",totalItems:"Total Items"},cannotCommit:"Cannot commit - items need review"},de:{steps:{created:"Erstellt",extracted:"Extrahiert",validated:"Validiert",mapped:"Zugeordnet",translated:"Ãbersetzt",reviewed:"Ãberprüft",committed:"Importiert"},tooltips:{created:"Batch erstellt, wartet auf Dokumente",extracted:"Elemente aus PDF extrahiert",validated:"Nachweis gegen Quelldaten verifiziert",mapped:"Kategorien mit DB-Regeln und KI zugeordnet",translated:"Bezeichnungen in CS und EN übersetzt",reviewed:"Elemente manuell überprüft",committed:"Daten in Produktionstabellen importiert"},contextHelp:{created:"Dokumente hochladen, um die Extraktion zu starten.",extracted:'Elemente extrahiert. Klicken Sie "Validieren" zur Nachweisprüfung.',validated:'Nachweis verifiziert. Klicken Sie "Zuordnen" für Kategorien.',mapped:'Kategorien zugeordnet. Ãberprüfen Sie Elemente mit "Ãberprüfung nötig".',translated:"Ãbersetzungen abgeschlossen. Genehmigen Sie Elemente zur Ãberprüfung.",reviewed:'Alles überprüft. Klicken Sie "Importieren" für den endgültigen Import.',committed:"Import abgeschlossen. Daten sind in der Produktionsdatenbank."},actions:{validate:"Validieren",map:"Zuordnen",translate:"Ãbersetzen",commit:"Importieren"},stepActions:{rerun:"Erneut ausführen",revertTo:"Zu diesem Schritt zurückkehren"},revertConfirm:{title:"Zurückkehren?",description:"Daten der folgenden Schritte werden gelöscht. Dies kann nicht rückgängig gemacht werden.",confirm:"Ja, zurück",cancel:"Abbrechen"},nextStep:"Nächster Schritt",running:"Verarbeite...",stats:{evidenceOk:"Nachweis OK",evidenceFailed:"Nac
33hweis fehlgeschlagen",mappingDb:"DB-Regeln",mappingAi:"KI-Zuordnung",needsReview:"Ãberprüfung nötig",totalItems:"Elemente gesamt"},cannotCommit:"Import nicht möglich - Elemente müssen überprüft werden"}};function ka({batch:t,onRunStep:j,onRevertStep:k,isRunning:b,runningStep:P,isExtracting:c}){const{language:x}=je(),s=Xe[x]||Xe.cs,[i,l]=m.useState(null),w=he.findIndex(d=>d.key===t.pipeline_step),u=t.pipeline_step==="failed",N=(()=>{if(t.pipeline_step==="committed")return null;const d=w+1;if(d>=he.length)return null;const S=he[d];if(!S.action){const V=he[d+1];return V!=null&&V.action?{step:V.key,action:V.action}:null}return{step:S.key,action:S.action}})(),y=t.needs_review_count===0&&t.evidence_failed_count===0,O=(N==null?void 0:N.action)==="commit"&&!y,Z=()=>{N&&!O&&j(N.action)},T=(d,S)=>{(S<w&&d.action||S===w&&d.action)&&j(d.action)},R=async()=>{i&&k&&(await k(i),l(null))},$=d=>d>0&&d<w&&k&&t.pipeline_step!=="committed";return e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"mx-4 mt-3",children:e.jsxs(rt,{className:"p-4",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx(Ct,{delayDuration:300,children:he.map((d,S)=>{const V=d.icon,M=S<w,z=S===w,G=S>w,_=d.key==="extracted"&&c||d.action!==null&&P===d.action,U=d.action!==null,D=(M||z)&&U&&!b&&!c,K=$(S);return e.jsxs("div",{className:"flex items-center",children:[M&&(U||K)?e.jsxs(ze,{children:[e.jsx(Te,{asChild:!0,children:e.jsxs("button",{className:"flex flex-col items-center focus:outline-none",disabled:b,children:[e.jsx("div",{className:se("w-10 h-10 rounded-full flex items-center justify-center transition-all","bg-green-100 dark:bg-green-900 text-green-600 dark:text-green-400","hover:ring-2 hover:ring-green-500/50 cursor-pointer"),children:_?e.jsx(q,{className:"h-5 w-5 animate-spin"}):e.jsx(me,{className:"h-5 w-5"})}),e.jsxs("span",{className:"text-xs mt-1 font-medium text-green-600 dark:text-green-400 flex items-center gap-0.5",children:[s.steps[d.key],e.jsx($e,{className:"h-3 w-3"})]})]})}),e.jsxs(Ae,{align:"center",className:"w-44",children:[U&&e.jsxs(ie,{onClick:()=>j(d.action),children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),s.stepActions.rerun]}),K&&e.jsxs(e.Fragment,{children:[U&&e.jsx(Pe,{}),e.jsxs(ie,{onClick:()=>l(d.key),className:"text-yellow-600 dark:text-yellow-400",children:[e.jsx(lt,{className:"h-4 w-4 mr-2 rotate-180"}),s.stepActions.revertTo]})]})]})]}):e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:se("flex flex-col items-center",D&&"cursor-pointer"),onClick:()=>D&&T(d,S),children:[e.jsx("div",{className:se("w-10 h-10 rounded-full flex items-center justify-center transition-colors",M&&!_&&"bg-green-100 dark:bg-green-900 text-green-600 dark:text-green-400",_&&"bg-blue-100 dark:bg-blue-900 text-blue-600 dark:text-blue-400 ring-2 ring-blue-500 animate-pulse",z&&!u&&!_&&"bg-blue-100 dark:bg-blue-900 text-blue-600 dark:text-blue-400 ring-2 ring-blue-500",z&&u&&"bg-red-100 dark:bg-red-900 text-red-600 dark:text-red-400 ring-2 ring-red-500",G&&!_&&"bg-muted text-muted-foreground",D&&"hover:scale-105 transition-transform"),children:_?e.jsx(q,{className:"h-5 w-5 animate-spin"}):M?e.jsx(me,{className:"h-5 w-5"}):z&&u?e.jsx(be,{className:"h-5 w-5"}):e.jsx(V,{className:"h-5 w-5"})}),e.jsx("span",{className:se("text-xs mt-1 font-medium",M&&"text-green-600 dark:text-green-400",z&&!u&&"text-blue-600 dark:text-blue-400",z&&u&&"text-red-600 dark:text-red-400",G&&"text-muted-foreground"),children:s.steps[d.key]})]})}),e.jsxs(ge,{side:"bottom",children:[e.jsx("p",{children:s.tooltips[d.key]}),D&&U&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:z?"KliknÄte pro spuÅ¡tÄnÃ":"KliknÄte pro opakovánÃ"})]})]}),S<he.length-1&&e.jsx("div",{className:se("h-0.5 w-8 mx-1",S<w?"bg-green-500":"bg-muted")})]},d.key)})})}),e.jsx("div",{className:"text-sm text-muted-foreground bg-muted/50 rounded-md px-3 py-2 mb-4",children:s.contextHelp[t.pipeline_step]||s.contextHelp.created}),t.pipeline_progress>0&&t.pipeline_progress<100&&e.jsx(it,{value:t.pipeline_progress,className:"mb-4"}),e.jsxs("div",{className:"flex items-center justify-between border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-muted-foreground",children:[s.stats.totalItems,":"]}),e.jsx("strong",{children:t.total_items})]}),t.evidence_ok_count>0&&e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-help",children:[e.jsx(me,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{children:t.evidence_ok_count})]})}),e.jsxs(ge,{children:[e.jsx("p",{className:"font-medium",children:s.stats.evidenceOk}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Položky s ovÄÅenou evidencà v PDF"})]})]}),t.evidence_failed_count>0&&e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-help",children:[e.jsx(be,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{children:t.evidence_failed_count})]})}),e.jsxs(ge,{children:[e.jsx("p",{className:"font-medium",children:s.stats.evidenceFailed}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Položky bez ovÄÅitelné evidence"})]})]}),(t.mapping_db_count>0||t.mapping_ai_count>0)&&e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-help",children:[e.jsx(ut,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{children:t.mapping_db_count+t.mapping_ai_count})]})}),e.jsxs(ge,{children:[e.jsx("p",{className:"font-medium",children:"Mapováno kategoriÃ"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsxs("p",{children:["DB pravidla: ",t.mapping_db_count]}),e.jsxs("p",{children:["AI mapovánÃ: ",t.mapping_ai_count]})]})]})]}),t.needs_review_count>0&&e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1.5 cursor-help",children:[e.jsx(mt,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{children:t.needs_review_count})]})}),e.jsxs(ge,{children:[e.jsx("p",{className:"font-medium",children:s.stats.needsReview}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Položky vyžadujÃcà manuálnà kontrolu"})]})]})]}),N&&e.jsxs(pe,{children:[e.jsx(xe,{asChild:!0,children:e.jsx("div",{children:e.jsx(B,{onClick:Z,disabled:b||O,size:"sm",className:"gap-2",children:b?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-4 w-4 animate-spin"}),s.running]}):e.jsxs(e.Fragment,{children:[e.jsx(Jt,{className:"h-4 w-4"}),s.actions[N.action],e.jsx(ot,{className:"h-4 w-4"})]})})})}),O&&e.jsx(ge,{side:"left",children:e.jsx("p",{children:s.cannotCommit})})]})]})]})}),e.jsx(Qt,{open:!!i,onOpenChange:d=>
33!d&&l(null),title:s.revertConfirm.title,description:s.revertConfirm.description,confirmText:s.revertConfirm.confirm,cancelText:s.revertConfirm.cancel,variant:"destructive",onConfirm:R})]})}const ya=t=>{const j=["all","needs_review"];return["extracted","validated","mapped","translated","reviewed","committed"].includes(t)&&j.push("approved","rejected"),["validated","mapped","translated","reviewed","committed"].includes(t)&&j.push("evidence_ok","evidence_failed"),["mapped","translated","reviewed","committed"].includes(t)&&j.push("unmapped"),j},ba=t=>({evidence:["validated","mapped","translated","reviewed","committed"].includes(t),category:["mapped","translated","reviewed","committed"].includes(t),confidence:["mapped","translated","reviewed","committed"].includes(t)}),Ye={cs:{title:"Položky",search:"Hledat...",filters:{all:"VÅ¡e",evidence_ok:"Evidence OK",evidence_failed:"Evidence chyba",needs_review:"Ke kontrole",unmapped:"Bez mapovánÃ",approved:"Schváleno",rejected:"ZamÃtnuto"},columns:{text:"Text (DE)",amount:"Äástka",category:"Kategorie",confidence:"Jistota",page:"Str.",evidence:"Evidence",status:"Stav",actions:"Akce"},status:{pending:"Äeká",approved:"Schváleno",rejected:"ZamÃtnuto"},mappingSource:{db_exact:"DB pÅesný",db_alias:"DB alias",db_contains:"DB obsahuje",db_fuzzy:"DB fuzzy",ai:"AI",unmapped:"Bez mapovánÃ"},noItems:"Žádné položky",showSnippet:"Zobrazit výÅatek",bulkActions:{selected:"vybraných",approve:"Schválit vybrané",revalidateAll:"Znovu validovat vÅ¡e",skip:"PÅeskoÄit vybrané",createRules:"VytvoÅit pravidla",selectAll:"Vybrat vÅ¡e",deselectAll:"ZruÅ¡it výbÄr"}},en:{title:"Items",search:"Search...",filters:{all:"All",evidence_ok:"Evidence OK",evidence_failed:"Evidence Failed",needs_review:"Needs Review",unmapped:"Unmapped",approved:"Approved",rejected:"Rejected"},columns:{text:"Text (DE)",amount:"Amount",category:"Category",confidence:"Confidence",page:"Page",evidence:"Evidence",status:"Status",actions:"Actions"},status:{pending:"Pending",approved:"Approved",rejected:"Rejected"},mappingSource:{db_exact:"DB Exact",db_alias:"DB Alias",db_contains:"DB Contains",db_fuzzy:"DB Fuzzy",ai:"AI",unmapped:"Unmapped"},noItems:"No items",showSnippet:"Show snippet",bulkActions:{selected:"selected",approve:"Approve selected",revalidateAll:"Re-validate all",skip:"Skip selected",createRules:"Create rules",selectAll:"Select all",deselectAll:"Deselect all"}},de:{title:"Elemente",search:"Suchen...",filters:{all:"Alle",evidence_ok:"Nachweis OK",evidence_failed:"Nachweis fehlgeschlagen",needs_review:"Ãberprüfung nötig",unmapped:"Nicht zugeordnet",approved:"Genehmigt",rejected:"Abgelehnt"},columns:{text:"Text (DE)",amount:"Betrag",category:"Kategorie",confidence:"Vertrauen",page:"Seite",evidence:"Nachweis",status:"Status",actions:"Aktionen"},status:{pending:"Ausstehend",approved:"Genehmigt",rejected:"Abgelehnt"},mappingSource:{db_exact:"DB Exakt",db_alias:"DB Alias",db_contains:"DB Enthält",db_fuzzy:"DB Fuzzy",ai:"KI",unmapped:"Nicht zugeordnet"},noItems:"Keine Elemente",showSnippet:"Auszug anzeigen",bulkActions:{selected:"ausgewählt",approve:"Ausgewählte genehmigen",revalidateAll:"Alle erneut validieren",skip:"Ausgewählte überspringen",createRules:"Regeln erstellen",selectAll:"Alle auswählen",deselectAll:"Auswahl aufheben"}}};function wa({items:t,batchId:j,pipelineStep:k,filter:b,onFilterChange:P,searchQuery:c,onSearchChange:x,selectedItemId:s,onSelectItem:i,onRefresh:l}){const{language:w}=je(),{toast:u}=ce(),o=Ye[w]||Ye.cs,N=ya(k),y=ba(k),[O,Z]=m.useState(new Set),[T,R]=m.useState(new Set),[$,d]=m.useState(!1),S=a=>a===null?"-":new Intl.NumberFormat(w==="cs"?"cs-CZ":w==="de"?"de-DE":"en-US",{style:"currency",currency:"EUR"}).format(a),V=a=>{const h=new Set(O);h.has(a)?h.delete(a):h.add(a),Z(h)},M=a=>{const h=new Set(T);h.has(a)?h.delete(a):h.add(a),R(h)},z=()=>{R(new Set(t.map(a=>a.id)))},G=()=>{R(new Set)},C=t.length>0&&T.size===t.length,_=a=>a>=.85?"text-green-600 dark:text-green-400":a>=.7?"text-yellow-600 dark:text-yellow-400":"text-red-600 dark:text-red-400",U=a=>
33a.startsWith("db_")?e.jsx(ve,{className:"h-3 w-3"}):a==="ai"?e.jsx(Ee,{className:"h-3 w-3"}):e.jsx(ia,{className:"h-3 w-3"}),D=async()=>{if(T.size!==0){d(!0);try{const a=Array.from(T);await Promise.all(a.map(h=>p.rpc("has_role",{_user_id:h,_role:"owner"}).then(()=>{})));for(const h of a)await p.from("extracted_cost_items").update({needs_review:!1,status:"approved"}).eq("id",h);u({title:"Položky schváleny",description:`${a.length} položek bylo schváleno.`}),R(new Set),l()}catch(a){console.error("Bulk approve error:",a),u({variant:"destructive",title:"Chyba",description:"NepodaÅilo se schválit položky."})}finally{d(!1)}}},K=async()=>{if(t.length===0){u({title:"Žádné položky",description:"Batch neobsahuje žádné položky k validaci."});return}d(!0);try{const{data:a,error:h}=await p.functions.invoke("validate-evidence",{body:{batchId:j}});if(h)throw h;const r=a==null?void 0:a.summary;u({title:"Validace dokonÄena",description:`${(r==null?void 0:r.evidenceOkCount)||0} OK, ${(r==null?void 0:r.evidenceFailedCount)||0} chyb z ${(r==null?void 0:r.totalItems)||0} položek`}),l()}catch(a){console.error("Revalidate all error:",a),u({variant:"destructive",title:"Chyba validace",description:a instanceof Error?a.message:"NepodaÅilo se validovat položky."})}finally{d(!1)}},F=async()=>{if(T.size!==0){d(!0);try{const a=Array.from(T);for(const h of a)await p.from("extracted_cost_items").update({status:"rejected",needs_review:!1}).eq("id",h);u({title:"Položky pÅeskoÄeny",description:`${a.length} položek bylo pÅeskoÄeno.`}),R(new Set),l()}catch(a){console.error("Bulk skip error:",a),u({variant:"destructive",title:"Chyba",description:"NepodaÅilo se pÅeskoÄit položky."})}finally{d(!1)}}},Q=async()=>{if(T.size!==0){d(!0);try{const a=Array.from(T),h=t.filter(v=>a.includes(v.id)&&v.mapping);if(h.length===0){u({variant:"destructive",title:"Žádné mapovánÃ",description:"Vybrané položky nemajà pÅiÅazenou kategorii."});return}let r=0;for(const v of h){if(!v.mapping||!v.source_category)continue;const{data:g}=await p.from("category_mappings").select("id").eq("source_category",v.source_category).maybeSingle();g||(await p.from("category_mappings").insert({source_category:v.source_category,target_category:v.mapping.target_category_key,target_subcategory:v.mapping.target_subcategory_key,item_type:v.mapping.item_type,usage_count:1}),r++)}u({title:"Pravidla vytvoÅena",description:`VytvoÅeno ${r} nových pravidel.`}),R(new Set)}catch(a){console.error("Bulk create rules error:",a),u({variant:"destructive",title:"Chyba",description:"NepodaÅilo se vytvoÅit pravidla."})}finally{d(!1)}}};return e.jsxs(nt,{className:"m-4 mt-3 flex-1 flex flex-col",children:[e.jsx(St,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Dt,{className:"text-lg",children:[o.title," (",t.length,")"]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(B,{variant:"default",size:"sm",onClick:D,disabled:$||T.size===0,className:"bg-green-600 hover:bg-green-700 text-white",children:[$?e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(pa,{className:"h-4 w-4 mr-2"}),o.bulkActions.approve," ",T.size>0&&`(${T.size})`]}),T.size>0&&e.jsxs(ze,{children:[e.jsx(Te,{asChild:!0,children:e.jsx(B,{variant:"outline",size:"sm",disabled:$,children:e.jsx(aa,{className:"h-4 w-4"})})}),e.jsxs(Ae,{align:"end",className:"bg-background border shadow-lg",children:[e.jsxs(ie,{onClick:F,children:[e.jsx(lt,{className:"h-4 w-4 mr-2 text-orange-500"}),o.bulkActions.skip]}),e.jsx(Pe,{}),e.jsxs(ie,{onClick:Q,children:[e.jsx(ma,{className:"h-4 w-4 mr-2 text-blue-500"}),o.bulkActions.createRules]}),e.jsx(Pe,{}),e.jsx(ie,{onClick:z,children:o.bulkActions.selectAll}),e.jsx(ie,{onClick:G,children:o.bulkActions.deselectAll})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(sa,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Me,{placeholder:o.search,value:c,onChange:a=>x(a.target.value),className:"pl-8 w-64"})]}),e.jsxs(ze,{children:[e.jsx(Te,{asChild:!0,children:e.jsxs(B,{variant:"outline",size:"sm",children:[e.jsx(na,{className:"h-4 w-4 mr-2"}),o.filters[b]]})}),e.jsx(Ae,{children:N.map(a=>e.jsx(ie,{onClick:()=>P(a),className:se(b===a&&"bg-muted"),children:o.filters[a]},a))})]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:K,disabled:$||t.length===0,className:"text-blue-600 hover:text-blue-700 hover:bg-blue-50",children:[$?e.jsx(q,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(dt,{className:"h-4 w-4 mr-2"}),o.bulkActions.revalidateAll]})]})]})}),e.jsx(rt,{className:"flex-1 overflow-auto p-0",children:t.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:o.noItems}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Yt,{className:"table-fixed w-full",children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-10"}),e.jsx("col",{className:"w-10"}),e.jsx("col",{}),e.jsx("col",{className:"w-28"}),e.jsx("col",{className:"w-12"}),y.evidence&&e.jsx("col",{className:"w-20"}),e.jsx("col",{className:"w-24"}),y.category&&e.jsx("col",{className:"w-40"}),y.confidence&&e.jsx("col",{className:"w-20"}),e.jsx("col",{className:"w-14"})]}),e.jsx(ea,{className:"bg-muted/50 sticky top-0 z-10 border-b border-border",children:e.jsxs(Fe,{className:"hover:bg-transparent",children:[e.jsx(ae,{className:"px-2 py-2",children:e.jsx(We,{checked:C,onCheckedChange:a=>{a?z():G()}})}),e.jsx(ae,{className:"px-1 py-2"}),e.jsx(ae,{className:"py-2 text-muted-foreground font-medium",children:o.columns.text}),e.jsx(ae,{className:"text-right py-2 text-muted-foreground font-medium",children:o.columns.amount}),e.jsx(ae,{className:"text-center py-2 text-muted-foreground font-medium",children:o.columns.page}),y.evidence&&e.jsx(ae,{className:"text-center py-2 text-muted-foreground font-medium",children:o.columns.evidence}),e.jsx(ae,{className:"text-center py-2 text-muted-foreground font-medium",children:o.columns.status}),y.category&&e.jsx(ae,{className:"py-2 text-muted-foreground font-medium",children:o.columns.category}
33),y.confidence&&e.jsx(ae,{className:"text-center py-2 text-muted-foreground font-medium",children:o.columns.confidence}),e.jsx(ae,{className:"text-center py-2 text-muted-foreground font-medium",children:o.columns.actions})]})}),e.jsx(ta,{children:t.map(a=>{var h,r,v;return e.jsxs(m.Fragment,{children:[e.jsxs(Fe,{className:se("cursor-pointer hover:bg-muted/50",s===a.id&&"bg-muted",T.has(a.id)&&"bg-primary/5",a.status==="rejected"&&"bg-red-50 dark:bg-red-950/30 opacity-60",a.status==="approved"&&"bg-green-50 dark:bg-green-950/20"),children:[e.jsx(Y,{className:"px-2 py-2",onClick:g=>g.stopPropagation(),children:e.jsx(We,{checked:T.has(a.id),onCheckedChange:()=>M(a.id)})}),e.jsx(Y,{className:"px-1 py-2",children:e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:g=>{g.stopPropagation(),V(a.id)},"aria-label":o.showSnippet,children:O.has(a.id)?e.jsx($e,{className:"h-4 w-4"}):e.jsx(ot,{className:"h-4 w-4"})})}),e.jsxs(Y,{className:"py-2",onClick:()=>i(a.id),children:[e.jsx("div",{className:se("max-w-md truncate",a.status==="rejected"&&"line-through text-muted-foreground"),title:a.german_text,children:a.german_text}),a.czech_translation&&e.jsx("div",{className:se("text-xs text-muted-foreground truncate",a.status==="rejected"&&"line-through"),children:a.czech_translation})]}),e.jsx(Y,{className:"py-2 text-right font-mono",onClick:()=>i(a.id),children:S(a.amount)}),e.jsx(Y,{className:"py-2 text-center",onClick:()=>i(a.id),children:a.page_number||"-"}),y.evidence&&e.jsx(Y,{className:"py-2 text-center",onClick:()=>i(a.id),children:a.evidence_ok?e.jsx(me,{className:"h-4 w-4 text-green-500 mx-auto"}):e.jsx(be,{className:"h-4 w-4 text-red-500 mx-auto"})}),e.jsx(Y,{className:"py-2 text-center",onClick:()=>i(a.id),children:a.status==="approved"?e.jsx(ee,{variant:"outline",className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 border-green-300 text-xs",children:((h=o.status)==null?void 0:h.approved)||"Approved"}):a.status==="rejected"?e.jsx(ee,{variant:"outline",className:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400 border-red-300 text-xs",children:((r=o.status)==null?void 0:r.rejected)||"Rejected"}):e.jsx(ee,{variant:"outline",className:"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400 border-yellow-300 text-xs",children:((v=o.status)==null?void 0:v.pending)||"Pending"})}),y.category&&e.jsx(Y,{className:"py-2",onClick:()=>i(a.id),children:a.mapping?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(ee,{variant:"outline",className:"text-xs",children:[U(a.mapping.mapping_source),e.jsx("span",{className:"ml-1",children:a.mapping.target_category_key})]}),a.mapping.target_subcategory_key&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["/ ",a.mapping.target_subcategory_key]})]}):e.jsx(ee,{variant:"destructive",className:"text-xs",children:o.mappingSource.unmapped})}),y.confidence&&e.jsx(Y,{className:"py-2 text-center",onClick:()=>i(a.id),children:a.mapping&&e.jsxs("span",{className:se("font-mono text-sm",_(a.mapping.confidence)),children:[Math.round(a.mapping.confidence*100),"%"]})}),e.jsx(Y,{className:"py-2 text-center",children:e.jsx(B,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>i(a.id),children:e.jsx(ra,{className:"h-4 w-4"})})})]}),O.has(a.id)&&e.jsx(Fe,{className:"bg-muted/30",children:e.jsx(Y,{colSpan:7+(y.evidence?1:0)+(y.category?1:0)+(y.confidence?1:0),className:"py-2",children:e.jsxs("div",{className:"pl-12 pr-4",children:[e.jsxs("div",{className:"text-xs font-medium text-muted-foreground mb-1",children:[o.showSnippet," (Str. ",a.page_number,"):"]}),e.jsx("div",{className:"text-sm bg-muted p-2 rounded font-mono whitespace-pre-wrap",children:a.page_snippet||"-"})]})})})]},a.id)})})]})})})]})}const _a=t=>({source:!0,evidence:["validated","mapped","translated","reviewed","committed"].includes(t),mapping:["mapped","translated","reviewed","committed"].includes(t),translation:["translated","reviewed","committed"].includes(t),canEdit:["mapped","translated","reviewed"].includes(t),canEditEvidence:t==="validated",canApproveReject:["validated","mapped","translated","reviewed"].includes(t),canSaveRule:["mapped","translated","reviewed","committed"].includes(t)}),Na=[{value:"operating",label:{cs:"ProvoznÃ",en:"Operating",de:"Betrieb"}},{value:"heating_aggregate",label:{cs:"TopenÃ",en:"Heating",de:"Heizung"}}
33,{value:"reserve_fund_expense",label:{cs:"Výdaj z fondu",en:"Fund Expense",de:"Fondsausgabe"}},{value:"reserve_fund_income",label:{cs:"PÅÃjem do fondu",en:"Fund Income",de:"Fondseinnahme"}}],et={cs:{title:"Detail položky",close:"ZavÅÃt",save:"Uložit",saveAsRule:"Uložit jako pravidlo",translate:"PÅeložit",revalidate:"Znovu validovat",approve:"Schválit",reject:"ZamÃtnout",approved:"Schváleno",rejected:"ZamÃtnuto",validationComplete:"Validace dokonÄena",sections:{source:"Zdrojový text",mapping:"Mapovánà kategorie",translation:"PÅeklady",evidence:"Evidence"},fields:{germanText:"NÄmecký text",sourceCategory:"Zdrojová kategorie",targetCategory:"CÃlová kategorie",subcategory:"Podkategorie",itemType:"Typ položky",confidence:"Jistota",mappingSource:"Zdroj mapovánÃ",czechText:"Äeský text",czechTranslation:"Äeský pÅeklad",englishTranslation:"Anglický pÅeklad",pageNumber:"ÄÃslo stránky",pageSnippet:"VýÅatek ze stránky",evidenceStatus:"Stav evidence"},mappingSource:{db_exact:"DB pÅesná shoda",db_alias:"DB alias",db_contains:"DB obsahuje",db_fuzzy:"DB fuzzy",ai:"AI mapovánÃ",unmapped:"Bez mapovánÃ"},evidenceOk:"Evidence OK",evidenceFailed:"Evidence chyba",saved:"Uloženo",ruleSaved:"Pravidlo uloženo",existingRules:"ExistujÃcà pravidla v DB",noExistingRules:"Žádná pravidla pro tuto kategorii",useRule:"PoužÃt",usages:"použitÃ",universal:"UniverzálnÃ"},en:{title:"Item Detail",close:"Close",save:"Save",saveAsRule:"Save as Rule",translate:"Translate",revalidate:"Re-validate",approve:"Approve",reject:"Reject",approved:"Approved",rejected:"Rejected",validationComplete:"Validation complete",sections:{source:"Source Text",mapping:"Category Mapping",translation:"Translations",evidence:"Evidence"},fields:{germanText:"German Text",sourceCategory:"Source Category",targetCategory:"Target Category",subcategory:"Subcategory",itemType:"Item Type",confidence:"Confidence",mappingSource:"Mapping Source",czechText:"Czech Text",czechTranslation:"Czech Translation",englishTranslation:"English Translation",pageNumber:"Page Number",pageSnippet:"Page Snippet",evidenceStatus:"Evidence Status"},mappingSource:{db_exact:"DB Exact Match",db_alias:"DB Alias",db_contains:"DB Contains",db_fuzzy:"DB Fuzzy",ai:"AI Mapping",unmapped:"Unmapped"},evidenceOk:"Evidence OK",evidenceFailed:"Evidence Failed",saved:"Saved",ruleSaved:"Rule saved",existingRules:"Existing rules in DB",noExistingRules:"No rules for this category",useRule:"Use",usages:"uses",universal:"Universal"},de:{title:"Elementdetails",close:"SchlieÃen",save:"Speichern",saveAsRule:"Als Regel speichern",translate:"Ãbersetzen",revalidate:"Erneut validieren",approve:"Genehmigen",reject:"Ablehnen",approved:"Genehmigt",rejected:"Abgelehnt",validationComplete:"Validierung abgeschlossen",sections:{source:"Quelltext",mapping:"Kategoriezuordnung",translation:"Ãbersetzungen",evidence:"Nachweis"},fields:{germanText:"Deutscher Text",sourceCategory:"Quellkategorie",targetCategory:"Zielkategorie",subcategory:"Unterkategorie",itemType:"Elementtyp",confidence:"Vertrauen",mappingSource:"Zuordnungsquelle",czechText:"Tschechischer Text",czechTranslation:"Tschechische Ãbersetzung",englishTranslation:"Englische Ãbersetzung",pageNumber:"Seitennummer",pageSnippet:"Seitenausschnitt",evidenceStatus:"Nachweisstatus"},mappingSource:{db_exact:"DB Exakte Ãbereinstimmung",db_alias:"DB Alias",db_contains:"DB Enthält",db_fuzzy:"DB Fuzzy",ai:"KI-Zuordnung",unmapped:"Nicht zugeordnet"},evidenceOk:"Nachweis OK",evidenceFailed:"Nachweis fehlgeschlagen",saved:"Gespeichert",ruleSaved:"Regel gespeichert",existingRules:"Bestehende Regeln in DB",noExistingRules:"Keine Regeln für diese Kategorie",useRule:"Verwenden",usages:"Verwendungen",universal:"Universal"}};function Ca({item:t,batchId:j,pipelineStep:k,documentFormat:b,onClose:P,onUpdate:c}){var le,ue,Ke,Le,Ze;const{language:x}=je(),s=et[x]||et.cs,{toast:i}=ce(),{data:l,isLoading:w}=Ot(!0),u=_a(k),[o,N]=m.useState(((le=t.mapping)==null?void 0:le.target_category_key)||""),[y,O]=m.useState(((ue=t.mapping)==null?void 0:ue.target_subcategory_key)||""),[Z,T]=m.useState(((Ke=t.mapping)==null?void 0:Ke.item_type)||"operating"),[R,$]=m.useState(t.czech_translation||((Le=t.translation)==null?void 0:Le.cs)||""),[d,S]=m.useState(((Ze=t.translation)==null?void 0:Ze.en)||""),[V,M]=m.useState(!1),[z,G]=m.useState(!1),[C,_]=m.useState("none"),[U,D]=m.useState(t.page_number),[K,F]=m.useState(t.page_snippet||""),[Q,a]=m.useState(!1),[h,r]=m.useState([]),[v,g]=m.useState(!1),H=m.useMemo(()=>l?l.filter(n=>n.level===1):[],[l]),f=m.useMemo(()=>
33{if(!l||!o)return[];const n=l.find(I=>I.name===o&&I.level===1);return n?l.filter(I=>I.parent_id===n.id&&I.level===2):[]},[l,o]);m.useEffect(()=>{y&&f.length>0&&(f.find(I=>I.name===y)||O(""))},[o,f]),m.useEffect(()=>{(async()=>{if(!t.source_category){r([]);return}g(!0);try{const{data:I,error:W}=await p.from("category_mappings").select("id, source_category, target_category, target_subcategory, item_type, document_format, usage_count, last_used_at, match_type").eq("source_category",t.source_category).order("usage_count",{ascending:!1,nullsFirst:!1});if(W)throw W;r(I||[])}catch(I){console.error("Error loading rules:",I),r([])}finally{g(!1)}})()},[t.source_category,t.id]),m.useEffect(()=>{var W,re;const n=t.czech_translation||((W=t.translation)==null?void 0:W.cs),I=(re=t.translation)==null?void 0:re.en;!n&&!I&&t.german_text?L():(n||I)&&_("ai")},[t.id]);const E=n=>{N(n.target_category),O(n.target_subcategory||""),T(n.item_type)},L=async()=>{var n,I,W;if(t.german_text){G(!0);try{const{data:re,error:de}=await p.functions.invoke("translate-labels",{body:{item_ids:[t.id]}});if(de)throw de;if((n=re==null?void 0:re.results)!=null&&n[0]){const ke=re.results[0];$(ke.cs||""),S(ke.en||""),_("ai"),i({title:x==="cs"?"PÅeloženo":"Translated"})}}catch(re){console.error("Translation error:",re);try{const de=await p.functions.invoke("translate",{body:{text:t.german_text,sourceLanguage:"de",targetLanguage:"cs"}}),ke=await p.functions.invoke("translate",{body:{text:t.german_text,sourceLanguage:"de",targetLanguage:"en"}});(I=de.data)!=null&&I.translatedText&&$(de.data.translatedText),(W=ke.data)!=null&&W.translatedText&&S(ke.data.translatedText),_("ai")}catch(de){console.error("Fallback translation error:",de),i({title:x==="cs"?"Chyba pÅekladu":"Translation error",variant:"destructive"})}}finally{G(!1)}}},J=async()=>{M(!0);try{await p.from("item_mappings").upsert({staging_item_id:t.id,batch_id:j,target_category_key:o,target_subcategory_key:y||null,item_type:Z,mapping_source:"user_override",confidence:1,needs_review:!1},{onConflict:"staging_item_id"}),await p.from("item_translations").upsert({staging_item_id:t.id,batch_id:j,cs:R||null,en:d||null,confidence:1,needs_review:!1},{onConflict:"staging_item_id"}),await p.from("extracted_cost_items").update({czech_translation:R||null,mapped_category:o||null,mapped_subcategory:y||null,mapping_source:"user_override",needs_review:!1}).eq("id",t.id),i({title:s.saved}),c()}catch(n){console.error("Save error:",n),i({title:"Error",variant:"destructive"})}finally{M(!1)}},ne=async()=>{if(!(!t.source_category||!o)){M(!0);try{let n=null;if(y&&l){const I=l.find(W=>W.name===y&&W.level===2);I&&(n=I.id)}if(!n&&l){const I=l.find(W=>W.name===o&&W.level===1);I&&(n=I.id)}await p.from("category_mappings").insert({source_category:t.source_category,target_category:o,target_subcategory:y||null,target_category_id:n,item_type:Z,is_repair_fund:o==="Fond Oprav",match_type:"exact",document_format:b}),await p.from("extracted_cost_items").update({mapped_category:o,mapped_subcategory:y||null,item_type:Z,mapping_source:"user_override",needs_review:!1,status:"approved"}).eq("id",t.id),await p.from("item_mappings").upsert({staging_item_id:t.id,batch_id:j,target_category_key:o,target_subcategory_key:y||null,item_type:Z,mapping_source:"user_override",confidence:1,needs_review:!1},{onConflict:"staging_item_id"}),i({title:s.ruleSaved}),c()}catch(n){console.error("Save rule error:",n),i({title:"Error",variant:"destructive"})}finally{M(!1)}}},A=async()=>{a(!0);try{await p.from("extracted_cost_items").update({page_number:U,page_snippet:K||null}).eq("id",t.id);const{data:n,error:I}=await p.functions.invoke("validate-evidence",{body:{documentIds:[t.document_id]}});if(I)throw I;i({title:s.validationComplete}),c()}catch(n){console.error("Revalidation error:",n),i({title:"Error",variant:"destructive"})}finally{a(!1)}},oe=async()=>{M(!0);try{await p.from("extracted_cost_items").update({evidence_ok:!0,needs_review:!1,status:"approved"}).eq("id",t.id),i({title:s.approved}),c()}catch(n){console.error("Approve error:",n),i({title:"Error",variant:"destructive"})}finally{M(!1)}},te=async()=>{M(!0);try{await p.from("extracted_cost_items").update({needs_review:!1,status:"rejected"}).eq("id",t.id),i({title:s.rejected}),c()}catch(n){console.error("Reject error:",n),i({title:"Error",variant:"destructive"})}finally{M(!1)}},we=n=>n===null?"-":new Intl.NumberFormat(x==="cs"?"cs-CZ":x==="de"?"de-DE":"en-US",{style:"currency",currency:"EUR"}).format(n);return e.jsxs("div",{className:"h-full flex flex-col bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",children:[e.jsx("h3",{className:"font-semibold",children:s.title}),e.jsx(B,{variant:"ghost",size:"icon",onClick:P,children:e.jsx(Et,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Ie,{className:"h-4 w-4"}),s.sections.source]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:s.fields.germanText}),e.jsx("div",{className:"mt-1 p-2 bg-muted rounded text-sm",children:t.german_text})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:s.fields.czechText}),e.jsxs(B,{variant:"ghost",size:"sm",onClick:L,disabled:z,className:"h-6 px-2 text-xs",children:[z?e.jsx(q,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(qe,{className:"h-3 w-3 mr-1"}),s.translate]})]}),e.jsx(_e,{value:R,onChange:n=>{$(n.target.value),_("manual")},className:"mt-1",rows:2,placeholder:z?x==="cs"?"PÅekládám...":"Translating...":"",disabled:z}),C==="ai"&&R&&e.jsx("div",{className:"flex items-center gap-1 mt-1",children:e.jsxs(ee,{variant:"secondary",className:"text-xs",children:[e.jsx(Ee,{className:"h-3 w-3 mr-1"}),"AI"]})})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:s.fields.sourceCategory}),e.jsx("div",{className:"mt-1 p-2 bg-muted rounded text-sm",children:t.source_category||"-"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:we(t.amount)}),t.amount_raw&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(raw: ",t.amount_raw,")"]})]})]})]}),u.evidence&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(ua,{className:"h-4 w-4"}),s.sections.evidence]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:t.evidence_ok?e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-sm text-green-600 dark:text-green-400",children:s.evidenceOk})]}):e.jsxs(e.Fragment,{children:[e.jsx(be,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:"text-sm text-red-600 dark:text-red-400",children:s.evidenceFailed})]})}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:s.fields.pageNumber}),u.canEditEvidence?e.jsx(Me,{type:"number",min:1,value:U??"",onChange:n=>D(n.target.value?parseInt(n.target.value):null),className:"mt-1"}):e.jsx("div",{className:"mt-1 text-sm",children:t.page_number||"-"})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs text-muted-foreground",children:s.fields.pageSnippet}),u.canEditEvidence?e.jsx(_e,{value:K,onChange:n=>F(n.target.value),className:"mt-1 font-mono text-xs",rows:3}):t.page_snippet&&e.jsx("div",{className:"mt-1 p-2 bg-muted rounded text-xs font-mono whitespace-pre-wrap",children:t.page_snippet})]}),u.canEditEvidence&&e.jsxs(B,{variant:"outline",size:"sm",onClick:A,disabled:Q,className:"w-full",children:[Q?e.jsx(q,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(st,{className:"h-4 w-4 mr-2"}),s.revalidate]}),u.canApproveReject&&e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(B,{variant:"outline",size:"sm",onClick:oe,disabled:V,className:"flex-1 text-green-600 border-green-300 hover:bg-green-50 dark:text-green-400 dark:border-green-700 dark:hover:bg-green-950",children:[e.jsx(oa,{className:"h-4 w-4 mr-2"}),s.approve]}),e.jsxs(B,{variant:"outline",size:"sm",onClick:te,disabled:V,className:"flex-1 text-red-600 border-red-300 hover:bg-red-50 dark:text-red-400 dark:border-red-700 dark:hover:bg-red-950",children:[e.jsx(ga,{className:"h-4 w-4 mr-2"}),s.reject]})]})]})]})]}),u.mapping&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Ht,{className:"h-4 w-4"}),s.sections.mapping]}),e.jsxs("div",{className:"space-y-3",children:[t.mapping&&e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsxs(ee,{variant:"outline",className:"text-xs",children:[t.mapping.mapping_source.startsWith("db_")?e.
33jsx(ve,{className:"h-3 w-3 mr-1"}):e.jsx(Ee,{className:"h-3 w-3 mr-1"}),s.mappingSource[t.mapping.mapping_source]]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[Math.round(t.mapping.confidence*100),"%"]})]}),t.source_category&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(X,{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(ve,{className:"h-3 w-3"}),s.existingRules]}),v?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground p-2",children:[e.jsx(q,{className:"h-3 w-3 animate-spin"}),"Loading..."]}):h.length>0?e.jsx("div",{className:"space-y-1.5",children:h.map(n=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted/50 rounded border text-xs",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:n.target_category}),n.target_subcategory&&e.jsxs("span",{className:"text-muted-foreground",children:["â ",n.target_subcategory]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 text-muted-foreground",children:[n.document_format?e.jsx(ee,{variant:"outline",className:"text-[10px] px-1 py-0",children:n.document_format}):e.jsx(ee,{variant:"secondary",className:"text-[10px] px-1 py-0",children:s.universal}),n.usage_count!==null&&n.usage_count>0&&e.jsxs("span",{children:[n.usage_count," ",s.usages]})]})]}),u.canEdit&&e.jsx(B,{variant:"ghost",size:"sm",onClick:()=>E(n),className:"h-6 px-2 text-xs shrink-0",children:s.useRule})]},n.id))}):e.jsx("p",{className:"text-xs text-muted-foreground italic p-2 bg-muted/30 rounded",children:s.noExistingRules})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:s.fields.targetCategory}),e.jsxs(Ne,{value:o,onValueChange:N,disabled:!u.canEdit||w,children:[e.jsx(Ce,{className:"mt-1",children:e.jsx(Se,{placeholder:w?"NaÄÃtám...":""})}),e.jsx(De,{children:H.map(n=>e.jsx(ye,{value:n.name,children:n.name},n.id))})]})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:s.fields.subcategory}),f.length>0?e.jsxs(Ne,{value:y||"__none__",onValueChange:n=>O(n==="__none__"?"":n),disabled:!u.canEdit,children:[e.jsx(Ce,{className:"mt-1",children:e.jsx(Se,{placeholder:x==="cs"?"Vyberte podkategorii...":"Select subcategory..."})}),e.jsxs(De,{children:[e.jsx(ye,{value:"__none__",children:x==="cs"?"-- Bez podkategorie --":"-- No subcategory --"}),f.map(n=>e.jsx(ye,{value:n.name,children:n.name},n.id))]})]}):e.jsx(Me,{value:y,onChange:n=>O(n.target.value),className:"mt-1",disabled:!u.canEdit,placeholder:x==="cs"?"VolitelnÄ zadejte podkategorii":"Optionally enter subcategory"})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:s.fields.itemType}),e.jsxs(Ne,{value:Z,onValueChange:T,disabled:!u.canEdit,children:[e.jsx(Ce,{className:"mt-1",children:e.jsx(Se,{})}),e.jsx(De,{children:Na.map(n=>e.jsx(ye,{value:n.value,children:n.label[x]||n.label.en},n.value))})]})]})]})]})]}),u.translation&&e.jsxs(e.Fragment,{children:[e.jsx(Re,{}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Oe,{className:"h-4 w-4"}),s.sections.translation]}),e.jsxs("div",{className:"flex items-center gap-2",children:[C==="ai"&&e.jsxs(ee,{variant:"secondary",className:"text-xs",children:[e.jsx(Ee,{className:"h-3 w-3 mr-1"}),"AI"]}),u.canEdit&&e.jsx(B,{variant:"ghost",size:"sm",onClick:L,disabled:z,className:"h-7 px-2",children:z?e.jsx(q,{className:"h-3 w-3 animate-spin"}):e.jsx(qe,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:s.fields.czechTranslation}),e.jsx(_e,{value:R,onChange:n=>{$(n.target.value),_("manual")},className:"mt-1",rows:2,placeholder:z?x==="cs"?"PÅekládám...":"Translating...":"",disabled:z||!u.canEdit})]}),e.jsxs("div",{children:[e.jsx(X,{className:"text-xs",children:s.fields.englishTranslation}),e.jsx(_e,{value:d,onChange:n=>{S(n.target.value),_("manual")},className:"mt-1",rows:2,placeholder:z?x==="cs"?"PÅekládám...":"Translating...":"",disabled:z||!u.canEdit})]})]})]})]})]}),u.canEdit&&e.jsxs("div",{className:"p-4 border-t space-y-2",children:[u.canSaveRule&&t.source_category&&o&&e.jsxs(B,{className:"w-full",onClick:ne,disabled:V,children:[e.jsx(ve,{className:"h-4 w-4 mr-2"}),s.saveAsRule]}),e.jsxs(B,{variant:"outline",className:"w-full",onClick:J,disabled:V,children:[e.jsx(la,{className:"h-4 w-4 mr-2"}),s.save]})]})]})}function Sa(){const{toast:t}=ce(),[j,k]=m.useState(!1);return{validateBatch:async P=>{k(!0);try{const{data:c,error:x}=await p.functions.invoke("validate-evidence",{body:{batchId:P}});if(x)throw x;return c.success&&t({title:"Validace dokonÄena",description:`${c.passed} OK, ${c.failed} chyb z ${c.validated} položek.`}),c}catch(c){return console.error("Validation error:",c),t({variant:"destructive",title:"Chyba validace",description:c instanceof Error?c.message:"NepodaÅilo se validovat položky."}),{success:!1,validated:0,passed:0,failed:0,error:String(c)}}finally{k(!1)}},isValidating:j}}function Da(){const{toast:t}=ce(),[j,k]=m.useState(!1);return{mapBatch:async P=>{k(!0);try{const{data:c,error:x}=await p.functions.invoke("map-categories",{body:{batchId:P}});if(x)throw x;return c.success&&t({title:"Mapovánà dokonÄeno",description:`Zmapováno ${c.mapped} položek (${c.dbMatches} DB, ${c.aiMatches} AI).`}),c}catch(c){return console.error("Mapping error:",c),t({variant:"destructive",title:"Chyba mapovánÃ",description:c instanceof Error?c.message:"NepodaÅilo se zmapovat položky."}),{success:!1,mapped:0,unmapped:0,dbMatches:0,aiMatches:0,error:String(c)}}finally{k(!1)}},isMapping:j}}const tt={cs:{title:"Detail importu",loading:"NaÄÃtánÃ...",notFound:"Batch nenalezen",backToList:"ZpÄt na seznam"},en:{title:"Import Detail",loading:"Loading...",notFound:"Batch not found",backToList:"Back to list"},de:{title:"Import-Details",loading:"Wird geladen...",notFound:"Batch nicht gefunden",backToList:"Zurück zur Liste"}};function ys(){var H;const{batchId:t}=zt();at();const{language:j}=je(),k=tt[j]||tt.cs,{validateBatch:b,isValidating:P}=Sa(),{mapBatch:c,isMapping:x}=Da(),{translateBatch:s,isTranslating:i}=pt(),{commitBatch:l,isCommitting:w}=xt(),[u,o]=m.useState(null),[N,y]=m.useState([]),[O,Z]=m.useState([]),[T,R]=m.useState(!0),[$,d]=m.useState(null),[S,V]=m.useState(null),[M,z]=m.useState(null),[G,C]=m.useState(!1),[_,U]=m.useState("all"),[D,K]=m.useState("");m.useEffect(()=>{t&&F()},[t]),m.useEffect(()=>{(async()=>
33{if(!t||!u||i||N.length===0)return;const E=N.filter(L=>{var J;return!L.czech_translation&&!((J=L.translation)!=null&&J.cs)});E.length>0&&(console.log(`Auto-translating ${E.length} items without Czech translation`),await s(t),await F())})()},[u==null?void 0:u.id,N.length]);const F=async()=>{var f;if(t){R(!0),d(null);try{const{data:E,error:L}=await p.from("import_batches").select("*").eq("id",t).maybeSingle();if(L)throw L;if(!E){d(k.notFound),R(!1);return}if(o(E),(f=E.document_ids)!=null&&f.length){const{data:le}=await p.from("pdf_documents").select("id, file_name, document_format").in("id",E.document_ids);Z(le||[])}const J=E.document_ids||[],{data:ne,error:A}=await p.from("extracted_cost_items").select(` 34 id, german_text, czech_translation, source_category, amount, amount_raw, 35 page_number, page_snippet, evidence_ok, needs_review, status, document_id 36 `).or(`batch_id.eq.${t}${J.length>0?`,document_id.in.(${J.join(",")})`:""}`).order("page_number",{ascending:!0});if(A)throw A;const{data:oe}=await p.from("item_mappings").select("staging_item_id, target_category_key, target_subcategory_key, item_type, confidence, mapping_source, needs_review").eq("batch_id",t),{data:te}=await p.from("item_translations").select("staging_item_id, cs, en, confidence").eq("batch_id",t),we=(ne||[]).map(le=>({...le,mapping:oe==null?void 0:oe.find(ue=>ue.staging_item_id===le.id),translation:te==null?void 0:te.find(ue=>ue.staging_item_id===le.id)}));y(we)}catch(E){console.error("Error loading batch:",E),d(E instanceof Error?E.message:"Failed to load batch")}finally{R(!1)}}},Q=m.useMemo(()=>{const f=N.filter(A=>!!A.mapping&&A.mapping.mapping_source!=="unmapped"&&!!A.mapping.target_category_key),E=["db_exact","db_alias","db_contains","db_fuzzy"],L=f.filter(A=>E.includes(A.mapping.mapping_source)).length,J=f.filter(A=>A.mapping.mapping_source==="ai").length,ne=f.filter(A=>A.mapping.mapping_source==="user_override").length;return{total:N.length,approved:N.filter(A=>A.status==="approved").length,rejected:N.filter(A=>A.status==="rejected").length,needsReview:N.filter(A=>A.needs_review).length,evidenceOk:N.filter(A=>A.evidence_ok).length,evidenceFailed:N.filter(A=>A.evidence_ok===!1).length,mapped:f.length,dbMapped:L,aiMapped:J,userMapped:ne,rulesCreated:ne}},[N]),a=N.filter(f=>{var E,L,J,ne,A,oe;if(D){const te=D.toLowerCase();if(!(((E=f.german_text)==null?void 0:E.toLowerCase().includes(te))||((L=f.czech_translation)==null?void 0:L.toLowerCase().includes(te))||((J=f.source_category)==null?void 0:J.toLowerCase().includes(te))||((A=(ne=f.mapping)==null?void 0:ne.target_category_key)==null?void 0:A.toLowerCase().includes(te))))return!1}switch(_){case"evidence_ok":return f.evidence_ok===!0;case"evidence_failed":return f.evidence_ok===!1;case"needs_review":return f.needs_review||((oe=f.mapping)==null?void 0:oe.needs_review);case"unmapped":return!f.mapping||f.mapping.mapping_source==="unmapped";case"approved":return f.status==="approved";case"rejected":return f.status==="rejected";default:return!0}}),h=S?N.find(f=>f.id===S):null,r=P||x||i||w,v=async f=>{if(t){z(f);try{switch(f){case"validate":await b(t);break;case"map":await c(t);break;case"translate":await s(t);break;case"commit":await l(t);break}await F()}finally{z(null)}}},g=async f=>{if(t)try{await p.from("import_batches").update({pipeline_step:f}).eq("id",t);const E=["validated","mapped","translated","reviewed"],L=E.indexOf(f);L>=0&&(L<E.indexOf("mapped")&&await p.from("item_mappings").delete().eq("batch_id",t),L<E.indexOf("translated")&&await p.from("item_translations").delete().eq("batch_id",t)),await F()}catch(E){console.error("Error reverting step:",E)}};return T?e.jsx(Be,{children:e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx(Ve,{className:"h-8 w-64"}),e.jsx(Ve,{className:"h-24 w-full"}),e.jsx(Ve,{className:"h-96 w-full"})]})}):$||!u?e.jsx(Be,{children:e.jsx("div",{className:"p-6",children:e.jsxs(ca,{variant:"destructive",children:[e.jsx(mt,{className:"h-4 w-4"}),e.jsx(da,{children:$||k.notFound})]})})}):e.jsx(Be,{children:e.jsxs("div",{className:"flex flex-col h-[calc(100vh-4rem)]",children:[e.jsx(ja,{batch:u,documents:O,onRefresh:F,itemStats:Q,onExtractingChange:C}),e.jsx(ka,{batch:u,onRunStep:v,onRevertStep:g,isRunning:r,runningStep:M,isExtracting:G}),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsx("div",{className:`flex-1 overflow-auto ${h?"w-2/3":"w-full"}`,children:e.jsx(wa,{items:a,batchId:u.id,pipelineStep:u.pipeline_step,filter:_,onFilterChange:U,searchQuery:D,onSearchChange:K,selectedItemId:S,onSelectItem:V,onRefresh:F})}),h&&e.jsx("div",{className:"w-1/3 border-l overflow-auto",children:e.jsx(Ca,{item:h,batchId:u.id,pipelineStep:u.pipeline_step,documentFormat:((H=O.find(f=>f.id===h.document_id))==null?void 0:H.document_format)||null,onClose:()=>V(null),onUpdate:F})})]})]})})}export{ys 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.