import { Component } from '@angular/core';
import { Book } from 'src/models/book';
import { BookService } from './services/book.service';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
export class AppComponent {
  title = 'TestEnvironmentAngular';

  constructor(private bookService : BookService) {}
  
  booksA: Book[] = [];
  booksAA: Book[] = [];

  activeComponent: string = ''; 

  toggleComponent(componentName: string): void {
    this.activeComponent = componentName;
  }

  letters: string[] = ['*', 'A', 'Ā', 'B', 'C', 'Č', 'D', 'E', 'Ē', 
                        'F', 'G', 'Ģ', 'H', 'I', 'Ī', 'J', 'K', 'Ķ', 
                        'L', 'Ļ', 'M', 'N', 'Ņ', 'O', 'P', 'R', 'S', 
                        'Š', 'T', 'U', 'Ū', 'V', 'Z', 'Ž'];

    ngOnInit() : void {
      this.booksStartingWithA();
      this.booksStartingWithAA();
    }

    public booksStartingWithA() {
      this.bookService
      .getBooksByTitleA()
      .subscribe((result: Book[]) => (this.booksA = result))
    }

    public booksStartingWithAA() {
      this.bookService
      .getBooksByTitleAA()
      .subscribe((result: Book[]) => (this.booksAA = result))
    }
}

