import {
  Component,
  OnInit,
  ChangeDetectionStrategy,
  Input,
  OnDestroy,
  EventEmitter,
  Output,
  ChangeDetectorRef
} from '@angular/core';
import { RoomInfo, RoomType } from '@ucap/protocol-room';

@Component({
  selector: 'app-chat-list-item',
  templateUrl: './chat-list-item.component.html',
  styleUrls: ['./chat-list-item.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChatListItemComponent implements OnInit, OnDestroy {
  @Input()
  roomInfo: RoomInfo;

  @Input()
  profileImageRoot: string;

  @Input()
  defaultProfileImage: string;

  @Input()
  profileImage: string;

  @Input()
  roomName: string;

  @Input()
  checkable = false;

  @Input()
  checked = false;

  @Output()
  toggleItem = new EventEmitter<{
    checked: boolean;
    roomInfo: RoomInfo;
  }>();

  RoomType = RoomType;

  constructor(private changeDetectorRef: ChangeDetectorRef) {}

  ngOnInit(): void {}

  ngOnDestroy(): void {}

  onToggleItem(value: boolean): void {
    this.toggleItem.emit({
      checked: value,
      roomInfo: this.roomInfo
    });

    this.changeDetectorRef.detectChanges();
  }
}
