(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5085],{91912:function(e,t,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/bulk-operation/validation",function(){return r(33324)}])},33324:function(e,t,r){"use strict";r.r(t);var a=r(85893),i=r(67294),o=r(86886),n=r(66242),l=r(99226),s=r(15861),d=r(67720),c=r(11057),p=r(7504),h=r(63580),u=r(11163),m=r(42412),x=r(86501),f=r(81406),w=r(34386);t.default=()=>{let e=(0,u.useRouter)(),{id:t}=e.query,[r,g]=(0,i.useState)({}),[b,j]=(0,i.useState)({}),[y,k]=(0,i.useState)([]),[Z,S]=(0,i.useState)(!1),[_,v]=(0,i.useState)(""),[C,I]=(0,i.useState)({}),[P,A]=(0,i.useState)(!1),[O,T]=(0,i.useState)("");(0,i.useEffect)(()=>{if(!t)return;let fetchData=async()=>{let e=localStorage.getItem(m.Z.storageTokenKeyName);try{let r=await fetch("".concat(f.Ao,"/api/imports/").concat(t,"/data"),{headers:{Authorization:"Bearer ".concat(e)}}),i=await r.json(),o={},n={},l={};i.importListDTO.forEach((e,t)=>{if(e.title&&Array.isArray(e.map)){let r=e.map.map(e=>({...e,_rowId:e.productId||e.storeTempId||e.brandId||e.categoryId||e.typeId}));o[e.title]=r,n[e.title]=e.header.filter(e=>"Id"!==e[0].label&&"Status"!==e[0].label).map(e=>({field:e[0].value,headerName:e[0].label,...0===t?{minWidth:150}:{flex:1},editable:!0,renderCell:e=>(0,a.jsx)(TrimmedCell,{value:e.value})}))}l[e.title]={page:0,pageSize:50}}),g(o),j(n),I(l)}catch(e){console.error(e),x.ZP.error("Failed to load import data")}};fetchData()},[t]);let TrimmedCell=e=>{let{value:t}=e;if(null==t)return null;let r=Array.isArray(t)?t.join(", "):String(t);return(0,a.jsx)(w.Z,{title:r,arrow:!0,children:(0,a.jsx)("div",{style:{overflow:"hidden",display:"-webkit-box",WebkitLineClamp:4,WebkitBoxOrient:"vertical",whiteSpace:"normal",wordBreak:"break-word",lineHeight:"1.4"},children:r})})},handleProcessRowUpdate=e=>(k(t=>{let r=t.find(t=>t._rowId===e._rowId);return r?t.map(t=>t._rowId===e._rowId?e:t):[...t,e]}),e),normalizeStores=e=>Array.isArray(e)?e:"string"==typeof e&&""!==e.trim()?[e]:[],handleSubmit=async()=>{S(!0),v("Please wait for Sometimes, your approval is being processed...");let e=window.localStorage.getItem(m.Z.storageTokenKeyName),a={importId:t,importListDTO:Object.keys(r).map(e=>({title:e,header:[b[e].map(e=>({label:e.headerName,value:e.field}))],map:r[e].map(e=>{let t=y.find(t=>t._rowId===e._rowId),r=t||e;return{...r,stores:normalizeStores(r.stores)}})}))};try{let t=await fetch("".concat(f.Ao,"/api/imports/approve"),{method:"POST",headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},body:JSON.stringify(a)});if(!t.ok){let e=await t.text();throw Error(e)}let r=await t.text();v(r),x.ZP.success(r)}catch(e){console.log("Backend error:",e.message),x.ZP.error(e.message),v("Failed to Approve the data.")}};return(0,a.jsxs)(o.ZP,{container:!0,children:[(0,a.jsx)(o.ZP,{item:!0,xs:12,sx:{mt:2},children:(0,a.jsx)(n.Z,{children:(0,a.jsxs)(l.Z,{sx:{p:4},children:[(0,a.jsx)(s.Z,{variant:"h6",children:"Bulk Operations"}),(0,a.jsx)(d.Z,{sx:{my:2}}),Object.keys(r).map(e=>(0,a.jsxs)(l.Z,{sx:{mb:4},children:[(0,a.jsx)(s.Z,{variant:"h6",children:e}),(0,a.jsx)(h._,{autoHeight:!0,editMode:"row",rows:r[e],columns:b[e],getRowId:e=>e._rowId,processRowUpdate:handleProcessRowUpdate,disableRowSelectionOnClick:!0,pagination:!0,paginationModel:C[e],getRowHeight:()=>120,onPaginationModelChange:t=>I(r=>({...r,[e]:t})),sx:{"& .MuiDataGrid-cell":{whiteSpace:"normal",wordBreak:"break-word",lineHeight:"1.4",alignItems:"flex-center",py:1}},pageSizeOptions:[10,25,50]})]},e)),(0,a.jsxs)(l.Z,{sx:{display:"flex",justifyContent:"flex-end",mt:2},children:[(0,a.jsx)(c.Z,{variant:"outlined",sx:{mr:2},onClick:()=>e.push("/bulk-operation"),children:"Cancel"}),(0,a.jsx)(c.Z,{variant:"contained",onClick:handleSubmit,children:"Approve"})]})]})})}),(0,a.jsx)(p.Z,{open:Z,children:(0,a.jsxs)(l.Z,{sx:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:500,bgcolor:"background.paper",borderRadius:2,p:4,textAlign:"center"},children:[(0,a.jsx)(s.Z,{variant:"h6",sx:{mb:2},children:_}),(0,a.jsx)(c.Z,{variant:"contained",onClick:()=>{S(!1),e.push({pathname:"/bulk-operation",query:{refresh:"true"}})},children:"OK"})]})}),(0,a.jsx)(p.Z,{open:P,onClose:()=>A(!1),"aria-labelledby":"error-modal-title","aria-describedby":"error-modal-description",BackdropProps:{onClick:e=>e.stopPropagation()},children:(0,a.jsxs)(l.Z,{sx:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",width:500,bgcolor:"background.paper",borderRadius:2,p:4,textAlign:"center"},children:[(0,a.jsx)(o.ZP,{container:!0,spacing:2,sx:{marginTop:5,justifyContent:"center"},children:(0,a.jsx)(o.ZP,{item:!0,xs:12,children:(0,a.jsx)(s.Z,{align:"center",children:O})})}),(0,a.jsx)(l.Z,{sx:{display:"flex",justifyContent:"flex-end",marginTop:4},children:(0,a.jsx)(c.Z,{variant:"contained",onClick:()=>A(!1),children:"OK"})})]})})]})}}},function(e){e.O(0,[6125,3580,9774,2888,179],function(){return e(e.s=91912)}),_N_E=e.O()}]);