import { Component, Input, ViewChild, OnInit } from '@angular/core'; import { NguCarousel, NguCarouselConfig } from '@ngu/carousel'; import { utils } from '../../constants/utils.constants'; @Component({ selector: 'product-carousel', templateUrl: './product-carousel.component.html', styleUrls: ['./product-carousel.component.scss'] }) export class ProductCarouselComponent implements OnInit { @ViewChild('myCarousel') myCarousel: NguCarousel; @Input() products: any[]; carouselConfig: NguCarouselConfig; carouselToken: string; totalPages: number; index: 0; constructor() { } ngOnInit() { this.carouselConfig = { grid: { xs: 2, sm: 4, md: 4, lg: 6, all: 0 }, slide: 6, speed: 400, point: { visible: true }, touch: true, loop: false }; this.totalPages = this.products ? this.products.length : 0; } goToPreviousSlide() { if (this.index !== 0) { this.index--; } } goToNextSlide() { if (this.index !== this.totalPages) { this.index++; } } getProductBoxCTAState(item: any, isAlwaysShownATC: boolean = true) { let showDetailCta = false; let showATCCta = (item.isOnlineOrStore === utils.STORE) || (item.isOnlineOrStore === utils.ONLINE); // online product check variant if (!item.variantOptions && (item.messageType === 0 || item.messageType === 4)) { showATCCta = true; } else { showATCCta = false; showDetailCta = true; } // check appliance if (item.articleType === utils.ARTICLE_TYPE.Z003 && item.depotDirect) { showATCCta = false; showDetailCta = true; } // product container showing `View Details` button if ((item.sellableIntent === utils.SELLABLE_INTENT.B || item.sellableIntent === utils.SELLABLE_INTENT.S) && (item.optimizedPrice != null && item.optimizedPrice.productStatus === utils.SELLABLE_INTENT.SS && !item.optimizedPrice.displayPrice) ) { showATCCta = false; showDetailCta = true; } else if (item.sellableIntent === utils.SELLABLE_INTENT.S && (item.optimizedPrice != null && item.optimizedPrice.productStatus === utils.SELLABLE_INTENT.LC) ) { showATCCta = false; showDetailCta = true; } showDetailCta = showDetailCta && item.url; if (isAlwaysShownATC) { showATCCta = false; showDetailCta = true; } return { showATCCTa: showATCCta, showDetailCta: showDetailCta }; } // TODO: implement the Add to Cart action addToCart(item: any) { // - add mini cart overlay modal } }