import{b as F}from"./chunk-HYDOMSL4.js";import{a as V}from"./chunk-DAGMLKAT.js";import{a as j}from"./chunk-P3KIIKY4.js";import{b as w}from"./chunk-D2UNYCWT.js";import{a as P,b as R}from"./chunk-BQPO535K.js";import{b as O,c as T}from"./chunk-U5Y75IZ5.js";import{n as b,q as x}from"./chunk-TKVDP62Z.js";import{Ad as D,Bb as f,Db as _,Fa as S,Ib as p,Jb as s,Kb as d,Kd as E,Qc as y,Ub as C,Xb as m,Za as U,Zb as l,ba as h,d as g,ea as v,eb as a,ib as I,ob as M,va as c,wa as u}from"./chunk-GJDGQISV.js";function H(o,e){if(o&1){let t=C();s(0,"POS-uppy",3),m("fileUploaded",function(n){c(t);let r=l(2);return u(r.assignFile(n))}),d()}if(o&2){let t=l(2);p("sampleUrl",t.sampleUrl)}}function k(o,e){if(o&1){let t=C();s(0,"POS-uppy",3),m("fileUploaded",function(n){c(t);let r=l(2);return u(r.assignFile(n))}),d()}if(o&2){let t=l(2);p("sampleUrl",t.sampleUrl)}}function N(o,e){if(o&1&&(f(0,H,1,1,"POS-uppy",2),f(1,k,1,1,"POS-uppy",2)),o&2){let t=l();_(t.uploadState()===t.uploadStateEnum.Idle||t.uploadState()===t.uploadStateEnum.Uploading?0:-1),U(),_(t.uploadState()===t.uploadStateEnum.Success||t.uploadState()===t.uploadStateEnum.Error?1:-1)}}var A=class o{constructor(e,t,i,n,r){this.data=e;this.dialogRef=t;this.toastService=i;this.httpService=n;this.convertCsv=r}useUppy=!1;fileEndpoint="";modalConfig;sampleUrl;apiUploadCsv;outletID;fileInput;destroy$=new g;fileName;loadingVal$;uploadState=S(0);uploadStateEnum=j;timeoutID;ngOnInit(){this.initModalConfig(),this.initUpload()}initModalConfig(){this.modalConfig=new O,this.modalConfig.title="Import Items",this.modalConfig.customWidth=this.data.useUppy?"610px":"484px"}initUpload(){this.data&&(this.sampleUrl=this.data.sampleUrl,this.apiUploadCsv=this.data.API,this.outletID=this.data.outletID,this.useUppy=this.data.useUppy,this.fileEndpoint=this.data.fileEndpoint)}onOk(){if(this.fileInput)if(!this.useUppy)this.convertCsv.convert(this.fileInput).pipe(v(this.destroy$),h(e=>this.httpService.post(this.apiUploadCsv,this.outletID?{EntityID:this.outletID,CartItems:e}:e))).subscribe(e=>{this.dialogRef.close(e)});else{let e=new FormData;e.append("File",this.fileInput),e.append("EntityID",this.outletID),this.httpService.postFormData(this.fileEndpoint,e).subscribe({next:t=>{t&&(this.uploadState.set(2),this.dialogRef.close(t))},error:t=>{t instanceof E&&(console.error("error",t.error.Message),this.uploadState.set(3),this.timeoutID=setTimeout(()=>{this.uploadState.set(0)},100))}})}else this.uploadState.set(0),this.toastService.warning("Please drop a CSV file.","Warning")}onClose(){this.dialogRef.close()}ngOnDestroy(){this.destroy$.next(!0),this.destroy$.complete(),this.timeoutID&&clearTimeout(this.timeoutID)}assignFile(e){this.uploadState.set(1),this.fileInput=e}static \u0275fac=function(t){return new(t||o)(a(R),a(P),a(b),a(x),a(V))};static \u0275cmp=I({type:o,selectors:[["POS-modal-upload"]],decls:3,vars:1,consts:[["modalContent",""],[3,"onOk","onCancel","onClose","config"],[3,"sampleUrl"],[3,"fileUploaded","sampleUrl"]],template:function(t,i){t&1&&(s(0,"modal-material",1),m("onOk",function(){return i.onOk()})("onCancel",function(){return i.onClose()})("onClose",function(){return i.onClose()}),M(1,N,2,2,"ng-template",null,0,y),d()),t&2&&p("config",i.modalConfig)},dependencies:[D,T,F,w],encapsulation:2})};export{A as a};
