import {Component, OnInit} from '@angular/core';
import {MatTableDataSource} from '@angular/material';
import {CartService} from '../core/cart.service';
import {Router} from '@angular/router';

/**
 * @title Table with filtering
 */
@Component({
    templateUrl: 'specials.component.html',
})

export class SpecialsComponent implements OnInit {
    displayedColumns = ['name', 'quantity', 'order'];
    dataSource = new MatTableDataSource(ELEMENT_DATA);
    cartItems: number;

    constructor(private router: Router,
                private cartService: CartService) {
    }

    ngOnInit() {
        this.cartService.cartCount.subscribe(res => this.cartItems = res);
    }

    order() {
        // this.cartService.addItem();
    }

    applyFilter(filterValue: string) {
        filterValue = filterValue.trim(); // Remove whitespace
        filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
        this.dataSource.filter = filterValue;
    }

}

export interface Element {
    id: number;
    name: string;
    quantity: number;
    price: number;
}

const ELEMENT_DATA: Element[] = [
    {id: 1, name: 'ABC123', quantity: 1, price: 500.1},
    {id: 2, name: 'ABC456', quantity: 4, price: 200.5},
    {id: 3, name: 'ABC789', quantity: 6, price: 300.4}
];
