1import{bB as w,cf as h,aY as v,aW as p,aZ as g,bc as $,bd as b,bE as C,bD as P,bO as S}from"./BKtmRkjI.js";import{B as y}from"./Zs51GdVf.js";import{u as A}from"./CIHGyirb.js";import{s as I}from"./x_rD_Ya3.js";function j(r,o,n){const{$api:c}=w(),a=h(r,()=>{}),s=h(`${r}-fetching`,()=>!1),l=h(`${r}-should-fetch`,()=>!0),u=async()=>{if(l.value&&!s.value){l.value=!1,s.value=!0;try{const i=typeof o=="function"?o():o;if(!i){a.value=n==null?void 0:n.defaultValue;return}const d=await c(i,n);a.value=n!=null&&n.transform?await n.transform(d):d}catch(i){throw console.error(`Error fetching ${r}:`,i),i}finally{s.value=!1}}},{error:e,refresh:t}=A(r,u,{lazy:!0,server:!1});function f(){l.value=!0,t()}return{data:a,pending:s,refresh:f,error:e}}const k=(r,o=5*60*1e3)=>{const n=v(()=>r.value.map(d=>d.id).join(",")),c=p(null),{data:a,pending:s,refresh:l}=j("cart-products",()=>{if(n.value!="")return`/products/ids/${n.value}`},{transform:y.array().parse,defaultValue:[]}),u=()=>c.value===null?!0:Date.now()-c.value>o,e=()=>{l(),c.value=Date.now()};g(r,()=>{a.value&&r.value.some(d=>!a.value.some(D=>D.id===d.id))&&e()},{immediate:!0});const t=p(null),f=()=>{t.value||(t.value=I(()=>{a.value&&u()&&e()},5*1e3))},i=()=>{t.value&&(clearInterval(t.value),t.value=null)};return $(f),b(i),{products:a,pending:s}},B=(r,o)=>{const n=C();g(r,c=>{if(!c)return;const a=[],s=[];if([...o.items].forEach(e=>{const t=c.find(f=>f.id===e.id);if(!t||!t.isEnabled||t.stock<=0){a.push((t==null?void 0:t.name)??""),o.remove({id:e.id,amount:0});return}t.stock>=e.amount||(s.push(`${t.name} (${t.stock} ÑÑ.)`),o.updateOne({id:e.id,amount:t.stock}))}),s.length&&o.saveLocally(),!a.length&&!s.length)return;const u=[];if(a.length){const e=a.filter(Boolean);u.push(e.length===a.length?`ÐÐµÐ¼Ð°Ñ Ð² наÑвноÑÑÑ, ÑÐ¾Ð¼Ñ Ð²Ð¸Ð»ÑÑено з коÑика: ${e.join(", ")}.`:"ÐеÑÐºÑ Ð¿Ð¾Ð·Ð¸ÑÑÑ Ð²Ð¸Ð»ÑÑено з коÑика, бо ÑÑ
Ð½ÐµÐ¼Ð°Ñ Ð² наÑвноÑÑÑ.")}s.length&&u.push(`ÐменÑено кÑлÑкÑÑÑÑ Ð´Ð¾ наÑвноÑ: ${s.join(", ")}.`),n.add({title:"ÐоÑик оновлено",description:u.join(" "),color:"error",icon:"ph:warning",duration:8e3})})},m=r=>Math.round(r),F=()=>{const r=P(),{items:o}=S(r),{products:n,pending:c}=k(o);B(n,r);const a=v(()=>n.value?o.value.flatMap(u=>{const e=n.value.find(t=>t.id===u.id);return e?[{cartItemDetailed:{amount:u.amount,calculatedNewPrice:m(+e.paperPriceReal*u.amount),calculatedOldPrice:m(+e.paperPrice*u.amount)},product:e}]:[]}):[]),s=v(()=>a.value.reduce((u,e)=>m(u+e.cartItemDetailed.calculatedNewPrice),0)),l=v(()=>a.value.reduce((u,e)=>u+e.cartItemDetailed.amount,0));return{cart:r,detailedCart:a,total:s,pending:c,count:l}};export{F as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.