import{j as e,U as W,R as v,V as M,W as X,Z as k,X as x,H as D,Y as H,E as R}from"./vendor-mui-69397583.js";import{A as I}from"./AdaptableCard-df7695d6.js";import{r as f}from"./vendor-react-ece1c85f.js";import{I as Y,B as L,E as Z,O as U,Q as S,V as G}from"./index-c62ac197.js";import"./Alert-7dfbd254.js";import"./index-6b6d0f06.js";import"./index-c2088808.js";import{D as Q}from"./Drawer-949c18c6.js";import"./FormContainer-91c2b0e4.js";import"./Switcher-c8648037.js";import"./index-36228db5.js";import{U as J}from"./Upload-fb34ce03.js";import{c as K,i as ee,a as te,F as se,b as ae,d as O,E as ie}from"./index.esm-70ab539c.js";import{S as le}from"./StickyFooter-5b934274.js";import{d as T}from"./FolderOpen-88bfcc74.js";import{A as ne,T as z}from"./actioncell-17e12e21.js";import{l as E,m as re,n as oe,o as ce,p as de}from"./DocumemtManagementService-6501a5c1.js";import{C as me}from"./ConfirmDialog-3202eb3d.js";import{N as pe}from"./NoData-8c485a3a.js";import"./vendor-redux-a1f00e6b.js";import"./vendor-pdf-b2a5d8b1.js";import"./vendor-devex-33a39e11.js";import"./vendor-i18n-2fcb1983.js";import"./vendor-msal-9caa1ed1.js";import"./vendor-charts-eccea5d1.js";import"./useControllableState-d0909575.js";import"./useDidUpdate-25c4d4ed.js";import"./createSvgIcon-c5fc0d04.js";const B=1,fe=5e5,he=K({files:ee().min(1,"Please upload at least one file").required("File upload is required"),fileName:te().required("File Name is required")}),xe=({initialData:c={files:[],fileName:""},onSubmit:y,onCancel:u,footerWidth:j})=>{const w=(r,a)=>{let o=!0;if(a.length>=B)return`You can only upload ${B} file(s)`;if(r)for(const d of r)d.size>=fe&&(o="Upload file cannot more then 500kb!");return o};return e.jsx(se,{initialValues:c,validationSchema:he,onSubmit:(r,{setSubmitting:a})=>{y(r,a)},children:({values:r,touched:a,errors:o,isSubmitting:d})=>e.jsx(ae,{children:e.jsxs("div",{className:"grid grid-cols-1 gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Upload File"}),e.jsx(O,{name:"files",children:({field:m,form:b})=>e.jsx(J,{draggable:!0,beforeUpload:w,fileList:r.files||[],onChange:i=>{var t;b.setFieldValue(m.name,i),b.setFieldValue("fileName",(t=i==null?void 0:i[0])==null?void 0:t.name)},onFileRemove:i=>b.setFieldValue(m.name,i)})}),o.files&&a.files&&e.jsx("div",{className:"text-red-500 text-sm mt-1",children:o.files})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"File Name"}),e.jsx(O,{name:"fileName",children:({field:m})=>e.jsx(Y,{...m,placeholder:"File Name"})}),e.jsx(ie,{name:"fileName",component:"div",className:"text-red-600"})]})]}),e.jsx(le,{className:`px-8 flex items-center justify-between py-4 ${j}`,stickyClass:"bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"md:flex items-center justify-between w-full",children:[e.jsx(L,{size:"sm",className:"mr-2",type:"button",onClick:u,children:"Cancel"}),e.jsx(L,{size:"sm",variant:"solid",type:"submit",loading:d,children:"Save"})]})})]})})})};const ye=({files:c,fetchData:y,setType:u,setSelectedFile:j,setDrawerOpen:w,loading:r=!1})=>{const[a,o]=f.useState(!1),[d,m]=f.useState(""),[b,i]=f.useState(!1),t=(s,l)=>{l===z.edit&&(w(!0),u("Edit"),j(s)),l===z.delete&&(m(s==null?void 0:s.fileId),o(!0)),l===z.compareFiles&&N(s.fileId,s.analyzedFileId)},n=async s=>{try{i(!0);const l=await E(s),p=l.headers["content-type"],A=new Blob([l.data],{type:p}),F=URL.createObjectURL(A);if(p.startsWith("image/")||p==="application/pdf"||p==="text/html")window.open(F,"_blank");else{const h=document.createElement("a");h.href=F,h.download=`file-${s}`,document.body.appendChild(h),h.click(),document.body.removeChild(h)}}catch{i(!1)}finally{i(!1)}},N=async(s,l)=>{try{i(!0);const p=await E(s),A=new Blob([p.data],{type:p.headers["content-type"]}),F=URL.createObjectURL(A),h=await E(l),$=new Blob([h.data],{type:h.headers["content-type"]}),V=URL.createObjectURL($),_=`
                <html>
                <head>
                    <title>Compare Documents</title>
                    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                    <style>
                        body {
                            display: flex;
                            justify-content: space-between;
                            gap: 10px;
                            margin: 0;
                            padding: 0;
                            overflow: hidden;
                        }
                        iframe {
                            height: 100vh;
                            border: none;
                        }
                        iframe.pdf-content {
                            width: 50%;
                        }
                        iframe.html-content {
                            width: 50%;
                            transform: scale(1.0);
                            transform-origin: top left;
                        }
                    </style>
                </head>
                <body>
                    <iframe class="pdf-content" src="${F}" title="Original Document"></iframe>
                    <iframe class="html-content" src="${V}" title="Analyzed Document"></iframe>
                </body>
                </html>
            `,P=new Blob([_],{type:"text/html"}),q=URL.createObjectURL(P);window.open(q,"_blank")||console.error("Popup was blocked by the browser.")}catch(p){console.error("Error fetching documents:",p)}finally{i(!1)}},g=()=>{m(null),o(!1)},C=async()=>{await re(d??"")&&U.push(e.jsx(S,{title:"Deleted",type:"success",duration:2500,children:"File Successfully Deleted"}),{placement:"top-center"}),y(),g()};return e.jsx(e.Fragment,{children:e.jsxs(W,{component:v,className:"file-items-table",children:[e.jsxs(M,{children:[e.jsx(X,{children:e.jsxs(k,{className:"dark:bg-[#292f3c] dark:text-white",children:[e.jsx(x,{width:"10%"}),e.jsx(x,{width:"45%",children:e.jsx(D,{className:"text-md font-bold",children:"Original Files"})}),e.jsx(x,{width:"45%",children:e.jsx(D,{className:"text-md font-bold",children:"Analyzed Results"})})]})}),e.jsx(H,{children:b?e.jsx(k,{children:e.jsx(x,{colSpan:4,children:e.jsx(R,{className:"flex justify-center items-center py-8",children:e.jsx(Z,{loading:!0,type:"cover"})})})}):(c==null?void 0:c.length)>0?c.map((s,l)=>e.jsxs(k,{className:"dark:bg-[#292f3c] dark:text-white",children:[e.jsx(x,{className:"dark:bg-[#292f3c] dark:text-white",children:e.jsx(ne,{row:s,actions:{edit:!0,delete:!0,compareFiles:!0},buttonClick:t})}),e.jsx(x,{className:"dark:bg-[#292f3c] dark:text-white",children:e.jsxs(R,{display:"flex",alignItems:"center",children:[e.jsx(T,{sx:{color:"var(--custom-600)"}}),e.jsx(D,{className:"text-sm",sx:{ml:1,cursor:"pointer"},onClick:()=>n(s.fileId),children:s.fileName})]})}),e.jsx(x,{className:"dark:bg-[#292f3c] dark:text-white",children:e.jsxs(R,{display:"flex",alignItems:"center",children:[e.jsx(T,{sx:{color:"#1C74F3"}}),e.jsx(D,{variant:"body1",className:"text-sm",sx:{ml:1,cursor:"pointer"},onClick:()=>n(s.analyzedFileId),children:s.fileName})]})})]},l)):e.jsx(k,{children:e.jsx(x,{colSpan:4,children:e.jsx(pe,{})})})})]}),e.jsx(me,{isOpen:a,type:"danger",title:"Delete file",confirmButtonColor:"red-600",onClose:g,onCancel:g,onConfirm:C,children:e.jsx("p",{children:"Are you sure you want to delete this File?"})})]})})},ue=()=>{const[c,y]=f.useState(!1),[u,j]=f.useState("Add"),[w,r]=f.useState([]),[a,o]=f.useState(null),d=()=>{j("Add"),y(!c)},m=()=>{d()},b=async(t,n)=>{var N,g,C,s;try{const l=u==="Edit"?await ce((a==null?void 0:a.fileId)??"",t==null?void 0:t.fileName,(g=(N=t==null?void 0:t.files)==null?void 0:N[0])!=null&&g.isViewOnly||(C=t==null?void 0:t.files)==null?void 0:C[0]):await de(t==null?void 0:t.fileName,(s=t==null?void 0:t.files)==null?void 0:s[0]);l.success?(i(),U.push(e.jsx(S,{title:"Success",type:"success",duration:2500,children:`File ${u==="Edit"?"Updated":"Uploaded"} Successfully`}),{placement:"top-center"})):U.push(e.jsx(S,{title:"Error",type:"danger",duration:2500,children:l.message}),{placement:"top-center"})}catch{U.push(e.jsx(S,{title:"Error",type:"danger",duration:2500,children:"Something went Wrong"}),{placement:"top-center"})}n(!1),d()},i=f.useCallback(async()=>{var t;try{const n=await oe();n!=null&&n.data&&r((t=n==null?void 0:n.data)==null?void 0:t.$values)}catch{r([])}},[]);return f.useEffect(()=>{i()},[i]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"topbar py-4 px-6 border-gray-200 border-b",children:e.jsxs("div",{className:"lg:flex items-center justify-between",children:[e.jsx("h3",{className:"mb-4 lg:mb-0",children:"OCR"}),e.jsx(L,{size:"sm",variant:"solid",icon:e.jsx(G,{}),onClick:()=>y(!0),children:"Add File"})]})}),e.jsx(I,{className:"m-6 h-full py-4 px-6 bg-transparent",bodyClass:"h-full",children:e.jsxs(I,{className:"h-full borderless",bodyClass:"h-full",children:[e.jsx("div",{className:"lg:flex items-center justify-between",children:e.jsx("div",{className:"flex flex-col lg:flex-row lg:items-center gap-3",children:e.jsx(Q,{title:"File",isOpen:c,portalClassName:"w30",onClose:()=>d(),children:e.jsx(xe,{footerWidth:"w30",initialData:u==="Add"?{files:[],fileName:""}:{files:[{name:(a==null?void 0:a.fileName)??"",type:"application/zip",size:26775,isViewOnly:!0}],fileName:(a==null?void 0:a.fileName)??""},onSubmit:b,onCancel:m})})})}),e.jsx(ye,{files:w,fetchData:i,setType:j,setSelectedFile:o,setDrawerOpen:y})]})})]})},He=ue;export{He as default};
