// src/app/pages/product-detail/product-detail.component.ts import { Component, inject, OnInit } from '@angular/core'; import { ActivatedRoute, Router, RouterLink } from '@angular/router'; import { PantryService } from '../../core/services/pantry.service'; import { Product, getExpiryStatus, EXPIRY_BADGE } from '../../core/models/product.model'; @Component({ selector: 'app-product-detail', standalone: true, imports: [RouterLink], template: ` @if (product) {

{{ product.name }}

{{ getBadge(product.expiry).text }}
Kategoria:
{{ product.category }}
Ilość:
{{ product.amount }} {{ product.unit }}
Data ważności:
{{ product.expiry }}
Stan:
{{ product.opened ? 'Otwarty' : 'Zamknięty' }}
@if (product.notes) {
Notatki:
{{ product.notes }}
}
} @else {
Produkt nie został znaleziony.
Wróć do spiżarni } ` }) export class ProductDetailComponent implements OnInit { private route = inject(ActivatedRoute); private router = inject(Router); private pantryService = inject(PantryService); product: Product | undefined; ngOnInit() { const id = Number(this.route.snapshot.paramMap.get('id')); this.product = this.pantryService.getById(id); } getBadge(expiry: string) { return EXPIRY_BADGE[getExpiryStatus(expiry)]; } deleteProduct() { if (this.product) { this.pantryService.removeProduct(this.product.id); this.router.navigate(['/pantry']); } } }