Files
appco_dist/.output/public/_nuxt/fu-mLsR8.js
T
2025-08-09 17:28:13 +03:30

2 lines
4.0 KiB
JavaScript

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