"use strict";(globalThis.webpackChunk_kenyaemr_esm_stock_management_app=globalThis.webpackChunk_kenyaemr_esm_stock_management_app||[]).push([[760],{34760:(e,t,n)=>{n.r(t),n.d(t,{default:()=>f});var r=n(16072),o=n.n(r),l=n(53941),a=n(51082),i=n(15847);function c(e,t,n,r,o,l,a){try{var i=e[l](a),c=i.value}catch(e){return void n(e)}i.done?t(c):Promise.resolve(c).then(r,o)}function u(e){return(t=function(){var t;return function(e,t){var n,r,o,l={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=i(0),a.throw=i(1),a.return=i(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,i[0]&&(l=0)),l;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return l.label++,{value:i[1],done:!1};case 5:l.label++,r=i[1],i=[0];continue;case 7:i=l.ops.pop(),l.trys.pop();continue;default:if(!((o=(o=l.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){l=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){l.label=i[1];break}if(6===i[0]&&l.label<o[1]){l.label=o[1],o=i;break}if(o&&l.label<o[2]){l.label=o[2],l.ops.push(i);break}o[2]&&l.ops.pop(),l.trys.pop();continue}i=t.call(e,l)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}(this,function(n){return t=new AbortController,[2,(0,i.openmrsFetch)("".concat(i.restBaseUrl,"/stockmanagement/stockitemimport"),{method:"POST",signal:t.signal,body:e})]})},function(){var e=this,n=arguments;return new Promise(function(r,o){var l=t.apply(e,n);function a(e){c(l,r,o,a,i,"next",e)}function i(e){c(l,r,o,a,i,"throw",e)}a(void 0)})})();var t}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}const f=function(e){var t,n,c=e.closeModal,f=(0,l.useTranslation)().t,p=(t=(0,r.useState)(),n=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,l=[],a=!0,i=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(l.push(r.value),!t||l.length!==t);a=!0);}catch(e){i=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(i)throw o}}return l}}(t,n)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=p[0],d=p[1];return o().createElement("div",null,o().createElement(a.lVW,null,o().createElement(a.rQ0,{closeModal:c,title:f("importStockItems","Import stock items")}),o().createElement(a.cwr,null,o().createElement(a.l0C,{accept:[".csv"],buttonLabel:f("selectFile","Select file"),filenameStatus:"edit",labelDescription:f("onlyCsvFilesAt2mbOrLess","Only .csv files at 2MB or less"),labelTitle:"",multiple:!1,name:"file",onChange:function(e){var t,n,r=null==e||null===(n=e.target)||void 0===n||null===(t=n.files)||void 0===t?void 0:t[0];r?d(r):e.preventDefault()},size:"sm"})),o().createElement(a.jlY,null,o().createElement(a.$nd,{kind:"secondary",onClick:c},(0,i.getCoreTranslation)("cancel")),o().createElement(a.$nd,{type:"button",onClick:function(){if(m){var e=new FormData;m&&(e.append("file",m,"Import_Stock_Items.csv"),e.append("hasHeader","true")),u(e).then(function(){(0,i.showSnackbar)({kind:"success",title:f("stockItemsUploadedSuccessfully","Stock items uploaded successfully")}),c()},function(e){(0,i.showSnackbar)({kind:"error",isLowContrast:!1,subtitle:null==e?void 0:e.message,title:f("errorUploadingItems","An error occurred uploading stock items")})})}}},f("uploadStockItems","Upload stock items")))))}}}]);