import { Component, Prop, Event, EventEmitter, h, Element } from '@stencil/core'; import { formatCurrency } from '../../classes/helpers'; import { Product } from '../../classes/product'; @Component({ tag: 'product-line', styleUrl: 'product-line.css', scoped: true, }) export class ProductLine { @Prop() product!: Product; @Element() el: HTMLElement; removeEl: HTMLElement; @Event() productChanged: EventEmitter; removeProductHandler() { var updatedProduct = this.product; updatedProduct.quantity = 0; this.productChanged.emit(updatedProduct); } updateProductQuantityHandler(event) { // else, update the quantity var updatedProduct = this.product; updatedProduct.quantity = event.detail; this.productChanged.emit(updatedProduct); } requestDelete() { (async () => { await customElements.whenDefined('tooltip-confirm-delete'); const todoListElement = this.el.querySelector('tooltip-confirm-delete'); await todoListElement.init(this.removeEl); })(); } render() { var remove = ( this.removeProductHandler()}> ); return (
{this.product.name}

{formatCurrency(this.product.price)} each

{formatCurrency(this.product.price * this.product.quantity)}
{remove}
); } }