import { Component } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
import { KeycloakUser, ListingType } from '../../../../../../bizmatch-server/src/models/main.model';
import { ListingsService } from '../../../services/listings.service';
import { SelectOptionsService } from '../../../services/select-options.service';
import { SharedModule } from '../../../shared/shared/shared.module';
import { map2User } from '../../../utils/utils';

@Component({
  selector: 'app-favorites',
  standalone: true,
  imports: [SharedModule],
  templateUrl: './favorites.component.html',
  styleUrl: './favorites.component.scss',
})
export class FavoritesComponent {
  user: KeycloakUser;
  listings: Array<ListingType> = []; //= dataListings as unknown as Array<BusinessListing>;
  favorites: Array<ListingType>;
  constructor(public keycloakService: KeycloakService, private listingsService: ListingsService, public selectOptions: SelectOptionsService) {}
  async ngOnInit() {
    const token = await this.keycloakService.getToken();
    this.user = map2User(token);
    this.favorites = this.listings.filter(l => l.favoritesForUser?.includes(this.user.id));
  }
}
