import {Component, Input} from '@angular/core';
import {ClaimEntity} from './claimHelper.class';
declare var UIkit: any;
@Component({
selector: 'claim-results',
template: `
0 " class="uk-margin-top">
=basketLimit)?'Basket reached the size limit':''">
`
})
export class ClaimResultsComponent {
@Input() results: ClaimEntity[];
@Input() selectedResults: ClaimEntity[];
@Input() localStoragePrefix: string = "";
@Input() basketLimit;
ngOnInit() {
}
public isSelected(item: ClaimEntity) {
return !!this.selectedResults.find(result => item.id === result.id);
}
add(item: ClaimEntity) {
let found: boolean = this.isSelected(item);
if (!found) {
this.selectedResults.push(item);
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
UIkit.notification(item.type + ' added in your basket!', {
status: 'success',
timeout: 4000,
pos: 'bottom-right'
});
}
}
remove(item: ClaimEntity) {
const index: number = this.selectedResults.findIndex(result => item.id === result.id);
if (index > -1) {
this.selectedResults.splice(index, 1);
if (this.selectedResults != null) {
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
}
UIkit.notification(item.type + ' removed from your basket!', {
status: 'warning',
timeout: 4000,
pos: 'bottom-right'
});
}
}
}