import { Component, OnInit, OnChanges, SimpleChanges, Input, Output, ChangeDetectorRef, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';

@Component({
    selector: 'app-list-panel',
    templateUrl: './list-panel.component.html',
    styleUrls: ['./list-panel.component.scss'],
    encapsulation: ViewEncapsulation.None
})

export class ListPanelComponent implements OnInit, OnChanges {
    @Input() public carList;

    constructor(
        private router: Router,
        private ref: ChangeDetectorRef ) {
    }

    public ngOnInit(): void {
    }

    public ngOnChanges(changes: SimpleChanges) {
        if (changes['carList']) {
            this.carList = changes['carList'].currentValue;
            console.log('this.carList', this.carList);
        }
    }

    public carDetails(obj) {
        console.log("clicked", this);
        let carId = obj;
        localStorage.setItem("carObj", JSON.stringify(obj));
        this.router.navigate(['carDetails']);
    }
}
