2 lines
4.0 KiB
JavaScript
2 lines
4.0 KiB
JavaScript
import{an as A,aq as G,cG as q,r as I,G as Q,aG as E,cP as x,Q as p,cQ as W,cR as j}from"./An4wrKzt.js";import{f as _,a as P}from"./9FWOce6O.js";import{S as k,c as B}from"./DqGGc3Qn.js";import{a as H,b as N}from"./aTaMzsVn.js";import{b as U,l as R,i as w}from"./Qb-t-tqc.js";import{i as L}from"./BG1DSSUc.js";import{b as M}from"./BJh0B-b5.js";function O(o,r,t){for(var u=-1,g=o==null?0:o.length;++u<g;)if(t(r,o[u]))return!0;return!1}var Y=200;function z(o,r,t,u){var g=-1,c=H,f=!0,S=o.length,h=[],b=r.length;if(!S)return h;t&&(r=A(r,G(t))),u?(c=O,f=!1):r.length>=Y&&(c=B,f=!1,r=new k(r));e:for(;++g<S;){var s=o[g],e=t==null?s:t(s);if(s=u||s!==0?s:0,f&&e===e){for(var n=b;n--;)if(r[n]===e)continue e;h.push(s)}else c(r,e,u)||h.push(s)}return h}var Z=U(function(o,r){var t=R(r);return w(t)&&(t=void 0),w(o)?z(o,N(r,1,w,!0),M(t)):[]}),D=U(function(o,r){var t=R(r);return w(t)&&(t=void 0),w(o)?z(o,N(r,1,w,!0),void 0,t):[]});const ie=q("product",()=>{const o=I(),r=I([]),t=I(0),u=I(!1),g=I(!1),c=Q();let f=0;const S=async(s,e=-1)=>{u.value=!0,f=E(100/r.value.length+3),t.value=f,e!=-1?await b(s,e):await h(s)},h=async s=>{var i,v,y;let e=E(s);const n=await x(o.value.file);t.value=f;try{const a=r.value.map(async(l,m)=>{var C;const F=await x(l.file);return t.value=f*(m+1),{url:(C=F.data)==null?void 0:C.fullPath,type:l.file.type.includes("video")?"video":"image"}});e.original_image=(i=n.data)==null?void 0:i.fullPath,e.files.push({url:(v=n.data)==null?void 0:v.fullPath,type:o.value.file.type.includes("video")?"video":"image"});const d=await Promise.all(a);e.files.push(...d),e.price=e.price?parseInt(e.price):0,e.weight=e.weight?parseFloat(e.weight):0,e.percent_fee=e.percent_fee?parseFloat(e.percent_fee):0,e.rial_fee=e.rial_fee?parseInt(e.rial_fee):0,e.count=e.count?parseInt(e.count):void 0,e.discount=e.discount?parseInt(e.discount):void 0,e.box_size=parseInt(e.box_size),(y=e.variants)==null||y.forEach(l=>{l.discount=l.discount?parseInt(l.discount):void 0})}catch(a){throw p.error(c.useString("theProductImageDidNotLoadCorrectly")),t.value=0,console.log(a),new Error(c.useString("theProductImageDidNotLoadCorrectly"))}if(console.log(e,n.error),e.original_image&&!n.error)try{await W(e),t.value=100,p.success(c.useString("addedSuccessfully"))}catch(a){throw console.log(a),p.error(a),t.value=0,new Error(a)}finally{u.value=!1}else throw p.error(c.useString("theProductImageDidNotLoadCorrectly")),u.value=!1,new Error(c.useString("theProductImageDidNotLoadCorrectly"))},b=async(s,e)=>{var y;let n,i=E(s);if(_.value.length>=P.value.length)n=D(_.value,P.value,L);else{let a=Z(P.value,_.value,"index"),d=[];a.forEach(l=>{_.value.some(m=>m.index==l.index)||d.push(l)}),d.forEach(l=>{P.value.splice(l.index,1),i.files.splice(l.index,1,null)}),n=await D(_.value,P.value,L)}let v;if(n.length!=0){o.value&&r.value.splice(0,0,o.value);const a=r.value.map(async(d,l)=>{var F;const m=await x(d.file);if(t.value=f*(l+1),m.error)throw p.error(c.useString("theProductImageDidNotLoadCorrectly")),new Error(c.useString("theProductImageDidNotLoadCorrectly"));return{value:{url:(F=m.data)==null?void 0:F.fullPath,type:d.file.type.includes("video")?"video":"image"},id:n[l].index}});v=await Promise.all(a),i.files||(i.files=[]),v.forEach((d,l)=>{i.files[d.id]=d.value})}i.files=i.files.filter(a=>a!=null),i.original_image=i.files[0].url,i.price=i.price?parseInt(i.price):void 0,i.weight=i.weight?parseFloat(i.weight):void 0,i.percent_fee=i.weight?parseFloat(i.percent_fee):void 0,i.rial_fee=i.rial_fee?parseInt(i.rial_fee):0,i.count=i.count?parseInt(i.count):void 0,i.discount=i.discount?parseInt(i.discount):void 0,(y=i.variants)==null||y.forEach(a=>{a.discount=a.discount?parseInt(a.discount):void 0}),i.box_size=parseInt(i.box_size),i.discount==null&&(i.discount=void 0),console.log(i,v,r,n);try{t.value=99.5,await j(i,e),t.value=100,p.success(c.useString("updatedSuccessfully"))}catch(a){throw console.log(a),t.value=0,p.error(a),new Error(a)}finally{u.value=!1}};return{originalFile:o,percentUpload:t,mediaFiles:r,fileUpLoader:S,isFileChanged:g,loading:u}});export{Z as d,ie as u};
|