"use strict";(self.webpackChunkapp_lapieza=self.webpackChunkapp_lapieza||[]).push([[423],{2599:(C,p,r)=>{r.d(p,{K:()=>m});var u=r(8834),l=r(4909),t=r(8457),g=r(5721),d=r(7935),_=r(99);const v=a=>({wishlisted:a}),h=(a,I)=>({color:a,"font-weight":I});let m=(()=>{class a{TranslateService;loginService;wishlistService;router;product;productId;isWishlisted=!1;isAuthenticated=!1;TraductionText;TraduccionSuccess;TraduccionRemoved;constructor(s,o,i,e){this.TranslateService=s,this.loginService=o,this.wishlistService=i,this.router=e,this.TraductionText=this.TranslateService.instant("was_added_to_your_wishlist"),this.TraduccionSuccess=this.TranslateService.instant("success"),this.TraduccionRemoved=this.TranslateService.instant("was_removed_from_your_wishlist")}ngOnInit(){this.loginService.isAuthenticated()&&this.checkWishlistStatus(),this.wishlistService.getWishlistItems().subscribe(()=>{this.checkWishlistStatus()})}ngAfterViewInit(){this.loginService.getAuthStatus().subscribe(s=>{this.isAuthenticated=s,s&&this.checkWishlistStatus()})}checkWishlistStatus(){const s=this.productId||(this.product?this.product.id:null);s&&(this.isWishlisted=this.wishlistService.isInWishlist(s))}handleWishlistClick(){if(!this.isAuthenticated)return this.isWishlisted=!1,void this.router.navigate(["/login"])}onClickWishlist(){if(!this.isAuthenticated)return this.isWishlisted=!1,void this.router.navigate(["/login"]);const s=this.productId||(this.product?this.product.id:null);if(s)if(this.isWishlisted){const o=this.wishlistService.getWishlistItemId(s);o&&this.wishlistService.removeFromWishlist(o).subscribe({next:i=>{i&&i.success&&(this.isWishlisted=!1,this.showNotification(!1))},error:i=>{console.error("Error removing from wishlist:",i)}})}else this.wishlistService.addToWishlist(s).subscribe({next:o=>{o&&o.success&&(this.isWishlisted=!0,this.showNotification(!0))},error:o=>{console.error("Error adding to wishlist:",o)}});else console.error("No product ID available")}showNotification(s){$.notify({icon:"fa fa-check",title:`${this.TraduccionSuccess}`,message:`<b>${this.product?this.product.name:"Producto"}</b> ${s?this.TraductionText:this.TraduccionRemoved}`},{element:"body",position:null,type:"info",allow_dismiss:!0,newest_on_top:!1,showProgressbar:!1,placement:{from:"top",align:"right"},offset:20,spacing:10,z_index:1031,delay:5e3,animate:{enter:"animated fadeInDown",exit:"animated fadeOutUp"},icon_type:"class"})}static \u0275fac=function(o){return new(o||a)(t.rXU(l.c$),t.rXU(g.H),t.rXU(d.F),t.rXU(_.t))};static \u0275cmp=t.VBU({type:a,selectors:[["app-wishlist-button-icon"]],inputs:{product:"product",productId:"productId"},decls:3,vars:7,consts:[[1,"label-flex"],[1,"btn","p-0","wishlist","btn-wishlist",2,"cursor","pointer",3,"click","ngClass"],[1,"iconly-Heart","icli",3,"ngStyle"]],template:function(o,i){1&o&&(t.j41(0,"div",0)(1,"button",1),t.bIt("click",function(){return i.onClickWishlist(),i.handleWishlistClick()}),t.nrm(2,"i",2),t.k0s()()),2&o&&(t.R7$(),t.Y8G("ngClass",t.eq3(2,v,i.isWishlisted)),t.R7$(),t.Y8G("ngStyle",t.l_i(4,h,i.isWishlisted?"red":"inherit",i.isWishlisted?"bold":"normal")))},dependencies:[u.D,u.E,u.M,l.h],styles:[".wishlist[_ngcontent-%COMP%]{background-color:transparent;border:none}.wishlisted[_ngcontent-%COMP%]{color:red;font-weight:700}.iconly-Heart[_ngcontent-%COMP%]{transition:color .3s ease,font-weight .3s ease}.iconly-Heart[_ngcontent-%COMP%]:hover{color:red}"]})}return a})()},7935:(C,p,r)=>{r.d(p,{F:()=>I});var u=r(4412),l=r(7673),t=r(6354),g=r(980),d=r(9437),_=r(8141),v=r(5312),h=r(8041),m=r(8457),a=r(5721);let I=(()=>{class s{http;loginService;apiUrl=v.c.apiUrl;wishlistItemsSubject=new u.t([]);wishlistItems=[];isLoadingSubject=new u.t(!1);wishlistCountSubject=new u.t(0);wishlistCount$=this.wishlistCountSubject.asObservable();isLoading$=this.isLoadingSubject.asObservable();constructor(i,e){this.http=i,this.loginService=e,this.loginService.getAuthStatus().subscribe(n=>{n?this.loadWishlistItems():(this.wishlistItems=[],this.wishlistItemsSubject.next([]))}),this.loginService.isAuthenticated()&&this.loadWishlistItems()}getWishlistItems(){return this.wishlistItemsSubject.asObservable()}getWishlistCount(){return this.getWishlistItems().pipe((0,t.T)(i=>i.length))}loadWishlistItems(){this.loginService.isAuthenticated()&&(this.isLoadingSubject.next(!0),this.getWishlists().pipe((0,g.j)(()=>this.isLoadingSubject.next(!1))).subscribe({next:i=>{this.wishlistItems=i,this.wishlistItemsSubject.next(this.wishlistItems),localStorage.setItem("wishlistCount",i.length.toString())},error:i=>{console.error("Error cargando items de wishlist:",i)}}))}getWishlists(){const i=localStorage.getItem("authToken");if(!i)return(0,l.of)([]);const e=new h.b({Authorization:`Bearer ${i}`});return this.http.get(`${this.apiUrl}wishlists`,{headers:e}).pipe((0,t.T)(n=>n&&n.success&&Array.isArray(n.data)?n.data:(console.warn("Invalid API response format:",n),[])),(0,d.W)(n=>(console.error("Error fetching Wishlists:",n),(0,l.of)([]))))}addToWishlist(i){const e=localStorage.getItem("authToken");if(!e)return(0,l.of)({success:!1,error:"User not authenticated"});const n=new h.b({Authorization:`Bearer ${e}`,"Content-Type":"application/json"});return this.isLoadingSubject.next(!0),this.http.get(`${this.apiUrl}wishlists-add-product?product_id=${i}`,{headers:n}).pipe((0,_.M)(c=>{c&&c.success&&(this.loadWishlistItems(),this.updateWishlistCount(this.wishlistItems.length))}),(0,d.W)(c=>(console.error("Error adding product to wishlist:",c),(0,l.of)({success:!1,error:"Failed to add product to wishlist"}))),(0,g.j)(()=>this.isLoadingSubject.next(!1)))}removeFromWishlist(i){const e=localStorage.getItem("authToken");if(!e)return console.error("No auth token available"),(0,l.of)({success:!1,error:"User not authenticated"});const n=new h.b({Authorization:`Bearer ${e}`});this.isLoadingSubject.next(!0),this.updateWishlistCount(this.wishlistItems.length);const c=this.wishlistItems.find(f=>f.id===i);return c&&c.product?this.http.get(`${this.apiUrl}wishlists-remove-product?product_id=${c.product.id}`,{headers:n}).pipe((0,_.M)(f=>{f&&f.success&&(this.wishlistItems=this.wishlistItems.filter(b=>b.id!==i),this.wishlistItemsSubject.next(this.wishlistItems),localStorage.setItem("wishlistCount",this.wishlistItems.length.toString()))}),(0,d.W)(f=>(console.error("Detailed error removing product:",f),f.error&&console.error("Server error details:",f.error),this.isLoadingSubject.next(!1),(0,l.of)({success:!1,error:"Failed to remove product from wishlist"}))),(0,g.j)(()=>{this.isLoadingSubject.next(!1)})):(console.error("Wishlist item not found or missing product data"),this.isLoadingSubject.next(!1),(0,l.of)({success:!1,error:"Wishlist item not found"}))}isInWishlist(i){return this.wishlistItems.some(e=>e.product&&e.product.id===i)}checkIsInWishlist(i){const e=localStorage.getItem("authToken");if(!e)return(0,l.of)(!1);const n=new h.b({Authorization:`Bearer ${e}`});return this.http.get(`${this.apiUrl}wishlists-check-product?product_id=${i}`,{headers:n}).pipe((0,t.T)(c=>c&&c.success&&c.exists),(0,d.W)(c=>(console.error("Error checking product in wishlist:",c),(0,l.of)(!1))))}getWishlistItemId(i){const e=this.wishlistItems.find(n=>n.product&&n.product.id===i);return e?e.id:null}toggleWishlistItem(i){if(this.isInWishlist(i)){const e=this.getWishlistItemId(i);if(e)return this.removeFromWishlist(e)}return this.addToWishlist(i)}updateWishlistCount(i){this.wishlistCountSubject.next(i),localStorage.setItem("wishlistCount",i.toString())}static \u0275fac=function(e){return new(e||s)(m.KVO(h.a),m.KVO(a.H))};static \u0275prov=m.jDH({token:s,factory:s.\u0275fac,providedIn:"root"})}return s})()},9121:(C,p,r)=>{r.d(p,{X:()=>m});var u=r(8834),l=r(9417),t=r(8457),g=r(5721),d=r(99),_=r(8240);function v(a,I){if(1&a){const s=t.RV6();t.j41(0,"div",5)(1,"div",6)(2,"button",7),t.nrm(3,"i",8),t.k0s(),t.j41(4,"input",9),t.mxI("ngModelChange",function(i){t.eBV(s);const e=t.XpG();return t.DH7(e.quantity,i)||(e.quantity=i),t.Njj(i)}),t.k0s(),t.j41(5,"button",10),t.nrm(6,"i",11),t.k0s()()()}if(2&a){const s=t.XpG();t.R7$(4),t.R50("ngModel",s.quantity)}}function h(a,I){if(1&a&&(t.j41(0,"div"),t.EFF(1),t.k0s()),2&a){const s=t.XpG();t.R7$(),t.JRh(s.alertMessage)}}let m=(()=>{class a{elementRef;loginService;router;cartService;productId;variant;weight;initialQuantity=1;hideCartCounter=!1;isAuthenticated=!1;authSubscription;quantity=this.initialQuantity;alertMessage="";constructor(s,o,i,e){this.elementRef=s,this.loginService=o,this.router=i,this.cartService=e}ngAfterViewInit(){this.initAddToCartAnimation(),this.addDocumentReadyScripts(),this.initializeQuantityButtons(),this.authSubscription=this.loginService.getAuthStatus().subscribe(s=>{this.isAuthenticated=s})}initAddToCartAnimation(){$(".addcart-button").on("click",s=>{if(!this.isAuthenticated)return alert("You need to log in to add items to the cart."),void this.router.navigate(["/login"]);const o=$(window).width();let i;i=void 0!==o&&o>768?$(".button-item"):$(".mobile-cart ul li a .icli.fly-cate");const n=$(s.currentTarget).closest(".product-box-4, .deal-box").find(".product-image img, .category-image img").eq(0);!i||!i.offset()||(n.length&&n.clone().css({opacity:"0.5",position:"absolute",height:"130px",width:"130px","z-index":"100"}).offset({top:n.offset()?.top||0,left:n.offset()?.left||0}).appendTo($("body")).animate({top:(i.offset()?.top||0)+10,left:(i.offset()?.left||0)+10,width:75,height:75},1e3,"easeInOutExpo").animate({width:0,height:0},()=>{$(this).detach()}),setTimeout(()=>{$(".item-section").addClass("active")},1500),setTimeout(()=>{$(".item-section").removeClass("active")},5e3))})}addDocumentReadyScripts(){$(document).ready(function(){$(".button-item").on("click",function(){$(".item-section").addClass("active")}),$(".close-button").on("click",function(){$(".item-section").removeClass("active")}),$(".btn-cart").on("click",function(){setTimeout(function(){$(".item-section").addClass("active")},1500),setTimeout(function(){$(".item-section").removeClass("active")},5e3)})})}initializeQuantityButtons(){const s=this.elementRef.nativeElement;s.querySelectorAll(".qty-right-plus").forEach(e=>{e.addEventListener("click",()=>{if(!this.isAuthenticated)return;const n=e.previousElementSibling;if(n){const c=parseInt(n.value,10)||0;c<9&&(n.value=(c+1).toString())}})}),s.querySelectorAll(".qty-left-minus").forEach(e=>{e.addEventListener("click",()=>{if(!this.isAuthenticated)return;const n=e.nextElementSibling;if(n){const c=parseInt(n.value,10)||0;c>1&&(n.value=(c-1).toString())}})})}handleAddToCartClick(){if(!this.isAuthenticated)return this.alertMessage="You need to log in to add items to the cart.",void this.router.navigate(["/login"]);const s={id:this.productId,weight:this.weight,variant:this.variant,quantity:this.quantity.toString()};this.cartService.addToCart(s).subscribe({next:o=>{this.alertMessage="Item added to cart successfully"},error:o=>{this.alertMessage=`Error while adding item to cart: ${o}`}})}increaseQuantity(){this.quantity<9&&this.quantity++}decreaseQuantity(){this.quantity>1&&this.quantity--}ngOnDestroy(){this.authSubscription&&this.authSubscription.unsubscribe()}static \u0275fac=function(o){return new(o||a)(t.rXU(t.aKT),t.rXU(g.H),t.rXU(d.t),t.rXU(_.m))};static \u0275cmp=t.VBU({type:a,selectors:[["app-cart-button-icon"]],inputs:{productId:"productId",variant:"variant",weight:"weight",initialQuantity:"initialQuantity",hideCartCounter:"hideCartCounter"},decls:6,vars:2,consts:[[1,"price-qty"],["class","counter-number",4,"ngIf"],[1,"buy-button","buy-box","buy-button-2","btn","btn-cart","addcart-button",2,"background-color","#e63118",3,"click"],[1,"iconly-Buy","icli","text-white","m-0"],[4,"ngIf"],[1,"counter-number"],[1,"counter"],["title","Login required to adjust quantity",1,"qty-left-minus"],[1,"fa-solid","fa-minus"],["type","text","name","quantity","value","1","title","Login required to adjust quantity",1,"form-control","input-number","qty-input",3,"ngModelChange","ngModel"],["title","Login required to adjust quantity",1,"qty-right-plus"],[1,"fa-solid","fa-plus"]],template:function(o,i){1&o&&(t.j41(0,"div",0),t.DNE(1,v,7,1,"div",1),t.j41(2,"button",2),t.bIt("click",function(){return i.handleAddToCartClick()}),t.nrm(3,"i",3),t.k0s(),t.nrm(4,"br"),t.DNE(5,h,2,1,"div",4),t.k0s()),2&o&&(t.R7$(),t.Y8G("ngIf",!i.hideCartCounter),t.R7$(4),t.Y8G("ngIf",!i.alertMessage))},dependencies:[u.D,u.I,l.YN,l.me,l.BC,l.vS],styles:[".qty-right-plus[_ngcontent-%COMP%], .qty-left-minus[_ngcontent-%COMP%]{background:#fafafa!important}"]})}return a})()}}]); |