Files
appco_dist/.output/public/_nuxt/NRv3MX-3.js
T
2025-08-05 21:16:09 +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 x,cQ as C,Q as p,cR as W,cS as j}from"./l4qGU2QO.js";import{f as P,a as S}from"./TUJb10oW.js";import{S as k,c as q}from"./czBns-tA.js";import{a as B,b as N}from"./v94lLkr7.js";import{b as U,l as R,i as w}from"./aVaMyZdb.js";import{i as L}from"./DHL9hUbw.js";import{b as M}from"./CkttLTNt.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=B,f=!0,F=o.length,h=[],E=r.length;if(!F)return h;t&&(r=A(r,H(t))),u?(c=O,f=!1):r.length>=Y&&(c=q,f=!1,r=new k(r));e:for(;++g<F;){var s=o[g],e=t==null?s:t(s);if(s=u||s!==0?s:0,f&&e===e){for(var n=E;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=G("product",()=>{const o=_(),r=_([]),t=_(0),u=_(!1),g=_(!1),c=Q();let f=0;const F=async(s,e=-1)=>{u.value=!0,f=x(100/r.value.length+3),t.value=f,e!=-1?await E(s,e):await h(s)},h=async s=>{var i,v,y;let e=x(s);const n=await C(o.value.file);t.value=f;try{const a=r.value.map(async(l,m)=>{var I;const b=await C(l.file);return t.value=f*(m+1),{url:(I=b.data)==null?void 0:I.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"))},E=async(s,e)=>{var y;let n,i=x(s);if(P.value.length>=S.value.length)n=D(P.value,S.value,L);else{let a=Z(S.value,P.value,"index"),d=[];a.forEach(l=>{P.value.some(m=>m.index==l.index)||d.push(l)}),d.forEach(l=>{S.value.splice(l.index,1),i.files.splice(l.index,1,null)}),n=await D(P.value,S.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 b,I;const m=await C(d.file);if(t.value=f*(l+1),m.error)throw p.error(c.useString("theProductImageDidNotLoadCorrectly")),new Error(c.useString("theProductImageDidNotLoadCorrectly"));return{value:{url:(b=m.data)==null?void 0:b.fullPath,type:d.file.type.includes("video")?"video":"image"},id:(I=n[l])==null?void 0:I.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:F,isFileChanged:g,loading:u}});export{Z as d,ie as u};