1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5130],{99427:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/_components/BulkRemovalModal",function(){return n(35480)}])},64017:function(e,t,n){"use strict";n.d(t,{F1:function(){return i},gt:function(){return r}});let o=(0,n(68969)._)("inventory-movements"),r=o.getAll;o.getOne;let i=o.create;o.update,o.delete},88976:function(e,t,n){"use strict";var o=n(87066),r=n(34155);let i="".concat("https://kindbox.herokuapp.com","/api");console.log("Initializing backend axios instance with URL:",i);let a=o.Z.create({baseURL:i});console.log("isProd",!0,"production"),a.interceptors.request.use(e=>{if(r.env.STRAPI_ADMIN_API_TOKEN){var t;null===(t=e.headers)||void 0===t||t.set("Authorization","Bearer ".concat(r.env.STRAPI_ADMIN_API_TOKEN))}return e},e=>Promise.reject(e)),a.interceptors.response.use(e=>(console.log("Received backend response:",e.status,e.config.url),e),e=>{if(console.error("Backend request error:",e),e.response)switch(console.error("Error response data:",e.response.data),console.error("Error response status:",e.response.status),console.error("Error response headers:",e.response.headers),e.response.status){case 401:case 403:console.error("Authentication error in backend call:",e.response.data);break;case 500:console.error("Backend server error:",e.response.data);break;default:console.error("Unhandled error status: ".concat(e.response.status))}else e.request?console.error("No response received:",e.request):console.error("Error setting up request:",e.message);return Promise.reject(e)}),t.Z=a},68969:function(e,t,n){"use strict";n.d(t,{_:function(){return v}});var o=n(88976),r=n(33299),i=n(34155);async function a(e,t){switch(t){case"user":return l(e);case"api":return s();case"auto":return await l(e)||s()}return null}async function l(e){let t=await (0,r.getSession)({req:e}),n=null==t?void 0:t.user;return n?{token:n.jwt,userId:n.user.id}:null}function s(){let e=i.env.API_AUTH_TOKEN;return e?{token:e}:null}var d=n(80129),u=n.n(d);function c(e){if(Array.isArray(e))return e.map(c);if(e&&"object"==typeof e){if("attributes"in e&&"id"in e)return{id:e.id,...c(e.attributes)};if("data"in e)return c(e.data);{let t={};for(let n in e)t[n]=c(e[n]);return t}}return e}let v=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"auto",n=e=>{let t=c(e.data);return Array.isArray(t)?t:[t]},r=e=>c(e.data),i=async()=>{let e=await a({},t);return e?{Authorization:"Bearer ".concat(e.token)}:{}},l=e=>u().stringify(e,{encodeValuesOnly:!0});return{getAll:async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=await i(),a=l(t);return n((await o.Z.get("/".concat(e,"?").concat(a),{headers:r})).data)},getOne:async function(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=await i(),s=l(n);return r((await o.Z.get("/".concat(e,"/").concat(t,"?").concat(s),{headers:a})).data)},create:async t=>{let n=await i();return r((await o.Z.post("/".concat(e),t,{headers:n})).data)},update:async(t,n)=>{let a=await i();return r((await o.Z.put("/".concat(e,"/").concat(t),n,{headers:a})).data)},delete:async t=>{let n=await i();await o.Z.delete("/".concat(e,"/").concat(t),{headers:n})}}}},35480:function(e,t,n){"use strict";n.r(t);var o=n(85893),r=n(67294),i=n(30354),a=n(92752),l=n(31963),s=n(31948),d=n(44504),u=n(55819),c=n(73793),v=n(91669),p=n(88911),h=n(28129),m=n(18691),f=n(39849),x=n(96272),g=n(23100),b=n(47018),j=n(64017);t.default=e=>{let{isOpen:t,onClose:n,products:y=[],locations:w=[],setLocalProducts:S,onInventoryUpdate:C}=e,[k,_]=(0,r.useState)(""),[A,I]=(0,r.useState)(null),[D,P]=(0,r.useState)([]),[z,R]=(0,r.useState)({}),[E,N]=(0,r.useState)(!1),[q,O]=(0,r.useState)(""),[T,W]=(0,r.useState)(""),[L,B]=(0,r.useState)(!1),[Z,M]=(0,r.useState)(""),U=(0,i.p)(),F=y.filter(e=>{var t,n,o,r,i,a,l,s,d,u,c,v;let p=e.name.toLowerCase(),h=null!==(c=null===(i=e.productDetails)||void 0===i?void 0:null===(r=i[0])||void 0===r?void 0:null===(o=r.boxContents)||void 0===o?void 0:null===(n=o[0])||void 0===n?void 0:null===(t=n.producer)||void 0===t?void 0:t.toLowerCase())&&void 0!==c?c:"",m=null!==(v=null===(u=e.productDetails)||void 0===u?void 0:null===(d=u[0])||void 0===d?void 0:null===(s=d.boxContents)||void 0===s?void 0:null===(l=s[0])||void 0===l?void 0:null===(a=l.upcPlu)||void 0===a?void 0:a.toString())&&void 0!==v?v:"";return p.includes(k.toLowerCase())||h.includes(k.toLowerCase())||m.includes(k.toLowerCase())}),K=e=>{D.find(t=>
1t.id===e.id)||(P(t=>[...t,e]),R(t=>({...t,[e.id]:{quantity:0,reason:q||"waste",date:"",notes:"",lot:""}})))},Q=e=>{P(t=>t.filter(t=>t.id!==e)),R(t=>{let n={...t};return delete n[e],n})},X=(e,t,n)=>{R(o=>{var r;let i=null!==(r=o[e])&&void 0!==r?r:{quantity:0,reason:"",date:"",notes:"",lot:""};return{...o,[e]:{...i,[t]:n}}})},Y=async()=>{var e,t,o,r,i;if(!L){if(B(!0),!Z.trim()){U({title:"Your name is required.",status:"warning",isClosable:!0}),B(!1);return}if(!A){U({title:"Select a location.",status:"warning",isClosable:!0}),B(!1);return}try{for(let n of D){let o=z[n.id];if(!o||!o.quantity||!o.reason)continue;let r="products removed by ".concat(Z),i=o.notes?"".concat(o.notes," | ").concat(r):r;await (0,j.F1)({data:{productDetail:null===(t=n.productDetails)||void 0===t?void 0:null===(e=t[0])||void 0===e?void 0:e.id,movementType:"out",reason:o.reason,quantity:o.quantity,location:A.id,sourceLocation:A.id,date:T||new Date().toISOString().split("T")[0],notes:i,lot:o.lot}})}S(e=>e.map(e=>{var t,n,o;if(!D.find(t=>t.id===e.id))return e;let r=z[e.id],i=(null==r?void 0:r.quantity)||0,a=(null===(n=e.productDetails)||void 0===n?void 0:null===(t=n[0])||void 0===t?void 0:t.inStock)||0;return{...e,productDetails:[{...null===(o=e.productDetails)||void 0===o?void 0:o[0],inStock:a-i}]}})),C&&C(),U({title:"Bulk Inventory Removed",description:"".concat(D.length," products removed."),status:"success",duration:5e3,isClosable:!0}),n(),P([]),R({}),I(null),_(""),M("")}catch(e){U({title:"Error removing inventory",description:(null==e?void 0:null===(i=e.response)||void 0===i?void 0:null===(r=i.data)||void 0===r?void 0:null===(o=r.error)||void 0===o?void 0:o.message)||"Unexpected error",status:"error",isClosable:!0})}finally{B(!1)}}};return(0,o.jsxs)(a.u_,{isOpen:t,onClose:n,size:"5xl",children:[(0,o.jsx)(l.Z,{}),(0,o.jsxs)(s.h,{children:[(0,o.jsx)(d.x,{children:"Bulk Remove Inventory"}),(0,o.jsx)(u.o,{}),(0,o.jsx)(c.f,{children:(0,o.jsxs)(v.g,{align:"stretch",spacing:4,children:[(0,o.jsx)(p.x,{fontSize:"md",fontWeight:"bold",children:"Your Name:"}),(0,o.jsx)(h.I,{placeholder:"Enter your name",value:Z,onChange:e=>M(e.target.value)}),(0,o.jsx)(p.x,{fontSize:"md",fontWeight:"bold",children:"Remove from location:"}),(0,o.jsx)(m.P,{placeholder:"Select a location",onChange:e=>{let t=w.find(t=>t.id===parseInt(e.target.value));t&&I(t)},value:(null==A?void 0:A.id)||"",children:w.map(e=>(0,o.jsx)("option",{value:e.id,children:e.name},e.id))}),(0,o.jsx)(p.x,{fontSize:"md",fontWeight:"bold",children:"Reason for removal:"}),(0,o.jsxs)(m.P,{placeholder:"Select a reason for removal",onChange:e=>O(e.target.value),value:q,children:[(0,o.jsx)("option",{value:"donated",children:"Donated"}),(0,o.jsx)("option",{value:"waste",children:"Waste"}),(0,o.jsx)("option",{value:"ordered",children:"Ordered"}),(0,o.jsx)("option",{value:"sold",children:"Sold"})]}),(0,o.jsx)(p.x,{fontSize:"md",fontWeight:"bold",children:"Date of Removal:"}),(0,o.jsx)(h.I,{type:"date",value:T,onChange:e=>W(e.target.value),maxW:{base:"full",md:"300px"}}),E?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(h.I,{placeholder:"Search by name, producer, or UPC",value:k,onChange:e=>_(e.target.value)}),""!==k.trim()&&F.length>0&&(0,o.jsx)(f.M,{columns:1,spacing:2,children:F.map(e=>{var t,n,r,i,a,l,s,d,u,c,v,h,m,f;return(0,o.jsxs)(x.z,{w:"full",justifySelf:"center",maxW:{base:"full",md:"50%"},onClick:()=>{K(e),_(""),N(!1)},size:"sm",colorScheme:"blue",variant:"outline",h:"auto",py:2,children:[(0,o.jsxs)(g.xu,{as:"span",flex:"1",whiteSpace:"normal",wordBreak:"break-word",textAlign:"left",children:[e.name," â"," ",null===(i=e.productDetails)||void 0===i?void 0:null===(r=i[0])||void 0===r?void 0:null===(n=r.boxContents)||void 0===n?void 0:null===(t=n[0])||void 0===t?void 0:t.producer," ","(stock: ".concat(null===(l=e.productDetails)||void 0===l?void 0:null===(a=l[0])||void 0===a?void 0:a.inStock,")")]}),(0,o.jsx)(p.x,{p:1,rounded:"md",ml:2,color:"white",bgColor:(null===(c=e.productDetails)||void 0===c?void 0:null===(u=c[0])||void 0===u?void 0:null===(d=u.boxContents)||void 0===d?void 0:null===(s=d[0])||void 0===s?void 0:s.availableForPurchase)?"green.500":"red.500",flexShrink:0,children:(null===(f=e.productDetails)||void 0===f?void 0:null===(m=f[0])||void 0===m?void 0:null===(h=m.boxContents)||void 0===h?void 0:null===(v=h[0])||void 0===v?void 0:v.availableForPurchase)?"A":"N/A"})]},e.id)})})]}):(0,o.jsx)(x.z,{onClick:()=>N(!0),colorScheme:"red",variant:"outline",alignSelf:"flex-start",children:"+ Remove Another Product"}),[...D].reverse().map(e=>(0,o.jsxs)(g.xu,{p:4,borderWidth:1,borderRadius:"md",bg:"gray.50",position:"relative",children:[(0,o.jsx)(x.z,{size:"md",colorScheme:"red",variant:"ghost",position:"absolute",top:"4px",right:"4px",onClick:()=>Q(e.id),children:"Cancel"}),(0,o.jsx)(p.x,{fontWeight:"bold",pr:6,children:e.name}),(0,o.jsxs)(f.M,{columns:{base:1,md:2},spacing:4,mt:2,children:[(0,o.jsxs)(g.xu,{children:[(0,o.jsx)(p.x,{mb:1,fontWeight:"medium",children:"Quantity to Remove"}),(0,o.jsx)(h.I,{inputMode:"numeric",onWheel:e=>e.currentTarget.blur(),min:0,type:"number",placeholder:"Quantity",onChange:t=>X(e.id,"quantity",parseInt(t.target.value))})]}),(0,o.jsxs)(g.xu,{gridColumn:{base:"span 1",md:"span 2"},children:[(0,o.jsx)(p.x,{mb:1,fontWeight:"medium",children:"Notes"}),(0,o.jsx)(h.I,{placeholder:"Optional notes",onChange:t=>X(e.id,"notes",t.target.value)})]})]})]},e.id))]})}),(0,o.jsxs)(b.m,{children:[(0,o.jsx)(x.z,{colorScheme:"red",onClick:Y,isDisabled:L||!A||!q||!T||!Z,loadingText:"Submitting...",isLoading:L,children:"Submit Removals"}),(0,o.jsx)(x.z,{ml:3,onClick:n,children:"Cancel"})]})]})]})}},47165:function(){}},function(e){e.O(0,[2458,8764,7066,129,1777,2888,9774,179],function(){return e(e.s=99427)}),_N_E=e.O()}]);
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.