import { ChangeDetectionStrategy, Component, computed, input, output } from '@angular/core'; import { CartItemAttribute, CartItemComponent } from '../cart-item/cart-item.component'; export interface CartItemMock { imageUrl: string | null; product: string; originalPrice: number | null; discountedPrice: number; discountPercentage: number | null; attributes: CartItemAttribute[]; quantity: number; } @Component({ selector: 'app-cart', standalone: true, imports: [CartItemComponent], templateUrl: './cart.component.html', styleUrl: './cart.component.scss', changeDetection: ChangeDetectionStrategy.OnPush }) export class CartComponent { readonly title = input('CARRITO'); readonly showClose = input(false); readonly items = input([]); readonly subtotal = input(0); readonly discount = input(0); readonly total = input(0); readonly backgroundColor = input('#ffffff'); readonly closed = output(); protected readonly formattedSubtotal = computed(() => this.formatCurrency(this.subtotal())); protected readonly formattedDiscount = computed(() => this.formatCurrency(this.discount())); protected readonly formattedTotal = computed(() => this.formatCurrency(this.total())); private formatCurrency(value: number): string { const rounded = Math.round(value); const parts = rounded.toString().split('.'); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, '.'); return `$ ${parts.join(',')}`; } }