import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { marker } from '@biesbjerg/ngx-translate-extract-marker';
import { AppDragDropService } from 'src/app/shared/drag/app-drag-drop.service';
import { AccountService } from 'src/app/shared/server-services/account.service';
import { AccountAvatarRecord } from 'src/app/shared/server-services/query-records/account-records';
import { SidebarResource } from 'src/app/shared/server-services/query-records/sidebar-records';

@Component({
  selector: 'app-sidebar-dialogue-drag-preview',
  templateUrl: './sidebar-dialogue-drag-preview.component.html',
  styleUrls: ['./sidebar-dialogue-drag-preview.component.scss'],
})
export class SidebarDialogueDragPreviewComponent implements OnInit {
  public data: SidebarResource;
  public name: string;
  public avatar: AccountAvatarRecord;
  public loaded: boolean = false;

  constructor(
    private appDragDropService: AppDragDropService,
    private accountService: AccountService,
    private changeDetectionRef: ChangeDetectorRef
  ) {}

  ngOnInit(): void {
    this.data = this.appDragDropService.getDraggedComponent().previewData;
    this.accountService.getAccount(this.data.id).then((account) => {
      this.avatar = account;
      this.name = account.avatarName;
      this.loaded = true;
      this.changeDetectionRef.detectChanges();
    });
  }
}
