import {Component, inject, input, OnInit, signal} from '@angular/core';
import {ChatService} from '@chatenium/chatenium-sdk/services/chatService';
import {IndexedDB} from '../../storage/indexed-db';
import {Chat} from '@chatenium/chatenium-sdk/domain/chatService.schema';
import {TUI_BREAKPOINT, TuiButton} from '@taiga-ui/core';
import {Oimg} from '../elements/oimg/oimg';
import {Router, RouterLink} from '@angular/router';
import {TranslatePipe} from '@ngx-translate/core';
import {LoadStatus, ServiceManager} from '../../service-manager';

@Component({
  selector: 'app-picture-list',
  imports: [
    TuiButton,
    Oimg,
    RouterLink,
    TranslatePipe
  ],
  templateUrl: './picture-list.html',
  styleUrl: './picture-list.scss',
})
export class PictureList implements OnInit {
  userid = input<string>("")
  token = input<string>("")

  indexedDb = inject(IndexedDB)
  router = inject(Router)
  serviceManager = inject(ServiceManager)
  breakpoint = inject(TUI_BREAKPOINT)

  async ngOnInit() {
    this.serviceManager.chatService = new ChatService(this.userid(), this.token(), this.indexedDb.getApi(), () => {})
    try {
      this.serviceManager.chats.set(await this.serviceManager.chatService.get())
      this.serviceManager.chatsStatus.set(LoadStatus.loaded)
    } catch (e) {
      console.error(e)
      this.serviceManager.chatsStatus.set(LoadStatus.error)
    }
  }
}
