/* Whanda Plugins v2.0.0 | Optional Features */ (()=>{var u={W100:"Bundle requiere id, name, y products",W101:"Bundle no encontrado",W102:"Season requiere id, name, start, y end",W103:"Downsell requiere un discount num\xE9rico positivo",W104:"Urgency requiere al menos uno de: lowStock, deadline, o badge",W105:"Las fechas de season deben ser v\xE1lidas y start debe ser anterior a end",W106:"Ya existe un elemento con ese ID"};function d(s){s.prototype.setDownsell=function(t){if(!t||typeof t.discount!="number"||t.discount<=0)throw new Error(u.W103);this.state.downsell=t},s.prototype.getDownsell=function(){return this.state.downsell?{...this.state.downsell}:null},s.prototype.clearDownsell=function(){this.state.downsell=null},s.prototype.createSeason=function(t){if(!t.id||!t.name||!t.start||!t.end)throw new Error(u.W102);let e=new Date(t.start),o=new Date(t.end);if(isNaN(e.getTime())||isNaN(o.getTime())||e>=o)throw new Error(u.W105);if(this.state.seasons.some(n=>n.id===t.id))throw new Error(u.W106);this.state.seasons.push(t)},s.prototype.getSeasons=function(){return[...this.state.seasons]},s.prototype.getActiveSeason=function(){let t=new Date;return this.state.seasons.find(e=>t>=new Date(e.start)&&t<=new Date(e.end))||null},s.prototype.isInSeason=function(t){let e=this.getActiveSeason();return e?e.products&&e.products.includes(t):!1},s.prototype.removeSeason=function(t){this.state.seasons=this.state.seasons.filter(e=>e.id!==t)},s.prototype.setProductUrgency=function(t,e){if(!e||!e.lowStock&&!e.deadline&&!e.badge)throw new Error(u.W104);this.state.urgency[t]=e},s.prototype.getUrgency=function(t){let e=this.state.urgency[t];if(!e)return null;let o=this.getProduct(t),n=o?o.stock:null,r=e.deadline?new Date<=new Date(e.deadline):!1,i=e.lowStock&&n!==null?n<=e.lowStock:!1,l=e.deadline?new Datet.lowStock).map(([t,e])=>{let o=this.getProduct(t);return o&&o.stock<=e.lowStock?o:null}).filter(Boolean)},s.prototype.createBundle=function(t){if(!t.id||!t.name||!t.products)throw new Error(u.W100);if(this.state.bundles.some(r=>r.id===t.id))throw new Error(u.W106);let e=0;t.products.forEach(r=>{let i=typeof r=="string"?r:r.productId,l=typeof r=="string"?1:r.quantity||1,c=this.getProduct(i);c&&(e+=c.price*l)});let o=t.discount?e*(1-t.discount):e,n=t.products.map(r=>typeof r=="string"?{productId:r,quantity:1}:{productId:r.productId,quantity:r.quantity||1});this.state.bundles.push({...t,products:n,originalPrice:e,bundlePrice:Math.max(0,o)})},s.prototype.getBundles=function(){return[...this.state.bundles]},s.prototype.getBundle=function(t){return this.state.bundles.find(e=>e.id===t)||null},s.prototype.addBundle=async function(t,e=1){let o=this.getBundle(t);if(!o)throw new Error(u.W101);for(let n of o.products)await this.addItem(n.productId,e*(n.quantity||1))},s.prototype.removeBundle=function(t){let e=this.getBundle(t);if(!e)throw new Error(u.W101);e.products.forEach(o=>{this.removeCartItem(o.productId)})},s.prototype.deleteBundle=function(t){this.state.bundles=this.state.bundles.filter(e=>e.id!==t)},s.prototype.setCRO=function(t){this.state.cro={...this.state.cro,...t}},s.prototype.getCROData=function(){return{freeShippingProgress:this.checkFreeShippingProgress(),lowStockProducts:this.getLowStockProducts(),recentlyViewed:this.getRecentlyViewed(),exitIntent:this.state.cro.exitIntent||null}},s.prototype.trackProductView=function(t){this.state.recentlyViewed||(this.state.recentlyViewed=[]),this.state.recentlyViewed=this.state.recentlyViewed.filter(e=>e!==t),this.state.recentlyViewed.unshift(t),this.state.recentlyViewed.length>10&&(this.state.recentlyViewed=this.state.recentlyViewed.slice(0,10))},s.prototype.getRecentlyViewed=function(){return this.state.recentlyViewed?this.state.recentlyViewed.map(t=>this.getProduct(t)).filter(Boolean):[]},s.prototype.getSocialProof=function(t){let e=t.split("").reduce((r,i)=>r+i.charCodeAt(0),0),o=e%20+5,n=e%15+2;return{productId:t,viewers:o,purchasers:n,message:`${o} people are viewing this right now`,recentPurchaseMessage:`${n} people bought this recently`}},s.prototype.checkFreeShippingProgress=function(){let t=this.state.cro.freeShippingGoal||this.config.shipping.freeFrom||0,o=(this.state.cart||[]).reduce((n,r)=>{let i=this.getProduct(r.productId);return n+(i?i.price*r.quantity:0)},0);return{current:o,goal:t,remaining:Math.max(0,t-o),qualifies:o>=t,progress:t>0?Math.min(1,o/t):1}}}typeof globalThis<"u"&&globalThis.Whanda&&d(globalThis.Whanda);var w=d;})();