Files
appco_dist/.output/public/_nuxt/ShsZnF8h.js
T

2 lines
3.9 KiB
JavaScript

import{ap as U,as as R,cI as z,r as w,G as A,aI as F,cQ as P,Q as p,cR as G,cS as Q}from"./G_17LgpR.js";import{r as C,f as v,a as S}from"./uVfHkLEk.js";import{S as W,c as j}from"./DBmCMGoE.js";import{a as k,b as D}from"./CO4NYPx8.js";import{b as q}from"./Cj6r251q.js";import{b as L,l as x,i as m}from"./C-7vddbp.js";import{i as B}from"./xHelY-u9.js";function H(a,t,r){for(var n=-1,g=a==null?0:a.length;++n<g;)if(r(t,a[n]))return!0;return!1}var M=200;function N(a,t,r,n){var g=-1,u=k,d=!0,y=a.length,h=[],I=t.length;if(!y)return h;r&&(t=U(t,R(r))),n?(u=H,d=!1):t.length>=M&&(u=j,d=!1,t=new W(t));e:for(;++g<y;){var o=a[g],i=r==null?o:r(o);if(o=n||o!==0?o:0,d&&i===i){for(var s=I;s--;)if(t[s]===i)continue e;h.push(o)}else u(t,i,n)||h.push(o)}return h}var O=L(function(a,t){var r=x(t);return m(r)&&(r=void 0),m(a)?N(a,D(t,1,m,!0),q(r)):[]}),Y=L(function(a,t){var r=x(t);return m(r)&&(r=void 0),m(a)?N(a,D(t,1,m,!0),void 0,r):[]});const ee=z("product",()=>{const a=w(),t=w([]),r=w(0),n=w(!1),g=w(!1),u=A();let d=0;const y=async(o,i=-1)=>{n.value=!0,d=F(100/(t.value.length+3)),r.value=d,i!=-1?await I(o,i):await h(o)},h=async o=>{let i=F(o);const s=await P(a.value.file);r.value=d;try{const e=t.value.map(async(c,l)=>{const f=await P(c.file);return r.value=d*(l+1),{url:f.data?.fullPath,type:c.file.type.includes("video")?"video":"image"}});i.original_image=s.data?.fullPath,i.files.push({url:s.data?.fullPath,type:a.value.file.type.includes("video")?"video":"image"});const b=await Promise.all(e);i.files.push(...b),i.price=i.price?parseInt(i.price):0,i.weight=i.weight?parseFloat(i.weight):0,i.percent_fee=i.percent_fee?parseFloat(i.percent_fee):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,i.box_size=parseInt(i.box_size),i.variants?.forEach(c=>{c.discount=c.discount?parseInt(c.discount):void 0})}catch(e){throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),r.value=0,console.log(e),new Error(u.useString("theProductImageDidNotLoadCorrectly"))}if(console.log(i,s.error),i.original_image&&!s.error)try{await G(i),r.value=100,p.success(u.useString("addedSuccessfully"))}catch(e){throw console.log(e),p.error(e),r.value=0,new Error(e)}finally{n.value=!1}else throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),n.value=!1,r.value=0,new Error(u.useString("theProductImageDidNotLoadCorrectly"));C(),t.value=[],a.value=void 0},I=async(o,i)=>{let s,e=F(o);O(v.value,S.value,"index").forEach(l=>{v.value.splice(l.index,1,null),e.files.splice(l.index,1,null)}),v.value=v.value.filter(l=>l!=null),s=Y(S.value,v.value,B),console.log(e,s,v.value,S.value);let c;if(s.length!=0){a.value&&t.value.splice(0,0,a.value);const l=t.value.map(async(f,_)=>{const E=await P(f.file);if(r.value=d*(_+1),E.error)throw p.error(u.useString("theProductImageDidNotLoadCorrectly")),r.value=0,new Error(u.useString("theProductImageDidNotLoadCorrectly"));return{value:{url:E.data?.fullPath,type:f.file.type.includes("video")?"video":"image"},id:s[_]?.index}});c=await Promise.all(l),e.files||(e.files=[]),c.forEach((f,_)=>{e.files[f.id]=f.value})}e.files=e.files.filter(l=>l!=null),e.original_image=e.files[0].url,e.price=e.price?parseInt(e.price):void 0,e.weight=e.weight?parseFloat(e.weight):void 0,e.percent_fee=e.weight?parseFloat(e.percent_fee):void 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.variants?.forEach(l=>{l.discount=l.discount?parseInt(l.discount):void 0}),e.box_size=parseInt(e.box_size),e.discount==null&&(e.discount=void 0),console.log(e,c,t,s);try{r.value=99.5,await Q(e,i),r.value=100,p.success(u.useString("updatedSuccessfully"))}catch(l){throw console.log(l),r.value=0,p.error(l),new Error(l)}finally{n.value=!1}t.value=[],a.value=void 0,C()};return{originalFile:a,percentUpload:r,mediaFiles:t,fileUpLoader:y,isFileChanged:g,loading:n}});export{O as d,ee as u};