(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9170],{80783:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/catalog-bulk-operations",function(){return n(21468)}])},21468:function(e,t,n){"use strict";n.r(t);var r=n(85893),a=n(67294),o=n(11057),l=n(15861),i=n(99226),s=n(98456),d=n(50135),c=n(90948),p=n(86886),u=n(1954),g=n(81406),m=n(86501);(0,c.ZP)(i.Z)(e=>{let{theme:t}=e;return{[t.breakpoints.down("md")]:{width:"90vw"}}}),(0,c.ZP)("img")(e=>{let{theme:t}=e;return{[t.breakpoints.down("lg")]:{height:450,marginTop:t.spacing(10)},[t.breakpoints.down("md")]:{height:400},[t.breakpoints.up("lg")]:{marginTop:t.spacing(20)}}});let f=(0,c.ZP)(i.Z)(e=>{let{theme:t,dragging:n}=e;return{maxWidth:600,margin:"0 auto",padding:t.spacing(4),textAlign:"center"}}),h=(0,c.ZP)(l.Z)(e=>{let{theme:t}=e;return{color:t.palette.error.main,marginTop:t.spacing(2),textAlign:"center"}});t.default=()=>{let[e,t]=(0,a.useState)(null),[n,c]=(0,a.useState)(!1),[x,w]=(0,a.useState)(!1),[b,y]=(0,a.useState)(""),handleSubmit=async()=>{if(!e){y("Please select a file.");return}let t=new FormData;t.append("file",e),w(!0),y("");try{let e=(0,g.W)(),n=await fetch("".concat(g.Ao,"/api/products/upload"),{method:"POST",headers:{...e.headers},body:t});await n,console.log(n,"resultsresults"),n.ok?(console.log(n,"response"),m.ZP.success("Uploaded Successfully!")):m.ZP.error("Something went wrong")}catch(e){console.log(e,"responseerror"),m.ZP.error("Error: "+e)}finally{w(!1)}},handleProductSampleImport=async()=>{w(!0),y("");try{let e=(0,g.W)(),t=await fetch("".concat(g.Ao,"/api/products/sample-excel"),{method:"GET",headers:{...e.headers}});if(t.ok){let e=await t.blob(),n=window.URL.createObjectURL(e),r=document.createElement("a");r.href=n,r.setAttribute("download","product-sample-import.xlsx"),document.body.appendChild(r),r.click(),r.parentNode.removeChild(r),m.ZP.success("Sample file downloaded!")}else{let e=await t.json();y("Error: "+(e.message||"Failed to download product sample file.")),m.ZP.error("Error in downloading product sample file")}}catch(e){y("Error: "+e.message),m.ZP.error("Something went wrong during the download")}finally{w(!1)}};return(0,r.jsx)(p.ZP,{container:!0,justifyContent:"center",alignItems:"center",direction:"column",style:{minHeight:"100%"},spacing:5,children:(0,r.jsx)(p.ZP,{item:!0,style:{boxShadow:"rgba(149, 157, 165, 0.2) 0px 8px 24px",padding:"3rem",backgroundColor:"#fff"},children:(0,r.jsxs)(f,{dragging:n,onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),c(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),c(!1)},onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.stopPropagation(),c(!1);let n=e.dataTransfer.files;n.length>0&&t(n[0])},children:[(0,r.jsxs)(i.Z,{sx:{display:"flex",alignItems:"center",justifyContent:"center",mb:4},children:[(0,r.jsx)(l.Z,{variant:"h4",sx:{mx:5},children:"Effortlessly Upload Your Product Inventory"}),(0,r.jsx)(u.JO,{icon:"fluent-mdl2:bulk-upload",style:{marginLeft:2,fontSize:20,color:"rgb(115, 103, 240)"}})]}),(0,r.jsx)(l.Z,{sx:{mb:4},children:"Simplify your product management by using our bulk upload feature. Upload your Excel file and let our system handle the rest—fast, efficient, and accurate."}),(0,r.jsx)(d.Z,{type:"file",onChange:e=>{t(e.target.files[0])},fullWidth:!0,sx:{mb:4},inputProps:{"aria-label":"Upload Excel File"}}),(0,r.jsxs)(i.Z,{sx:{display:"flex",flexDirection:"column",gap:"1rem"},children:[(0,r.jsxs)(o.Z,{variant:"contained",onClick:handleSubmit,disabled:x,endIcon:(0,r.jsx)(u.JO,{icon:"tabler:upload"}),children:["Upload Your Excel File",x&&(0,r.jsx)(s.Z,{size:14,sx:{marginLeft:2}})]}),(0,r.jsxs)(o.Z,{variant:"contained",onClick:handleProductSampleImport,disabled:x,endIcon:(0,r.jsx)(u.JO,{icon:"tabler:download"}),children:["Download Product Sample File",x&&(0,r.jsx)(s.Z,{size:14,sx:{marginLeft:2}})]})]}),b&&(0,r.jsx)(h,{children:b})]})})})}}},function(e){e.O(0,[9774,2888,179],function(){return e(e.s=80783)}),_N_E=e.O()}]);