import {Component, inject} from '@angular/core'
import {AuthService} from './services/auth.service'
import {Observable, of} from 'rxjs'
import {IChannel} from '../models/IChannel'
import {DatabaseService} from './services/database.service'

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {

  readonly placeholder = '/assets/Portrait_Placeholder.png'
  authService = inject(AuthService)

  publicChannels: Observable<IChannel[]> = of([])
  privateChannels: Observable<IChannel[]> = of([])

  #dbService = inject(DatabaseService)

  constructor() {
    this.authService.currentUser.subscribe(u => {
      if (u) {
        this.publicChannels = this.#dbService.retrievePublicChannelList()
        this.privateChannels = this.#dbService.retrieveMyChannelList()
      } else {
        this.publicChannels = of([])
        this.privateChannels = of([])
      }
    })
  }
}
