import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';

import { MatDrawer } from '@angular/material/sidenav';

import { Subscription } from 'rxjs';
import { QueryParams } from '../types/params.type';

@Component({
  selector: 'app-pages-chat-room',
  templateUrl: './chat-room.page.component.html',
  styleUrls: ['./chat-room.page.component.scss']
})
export class ChatRoomPageComponent implements OnInit, OnDestroy {
  private paramsSubscription: Subscription;
  isChatSearch = false;
  roomId: string;

  @ViewChild('chatRightDrawer', { static: false })
  chatRightDrawer: MatDrawer;

  constructor(private activatedRoute: ActivatedRoute) {}

  ngOnInit(): void {
    this.paramsSubscription = this.activatedRoute.queryParams.subscribe(
      (params: Params) => {
        const seqParam = params[QueryParams.ROOM_ID];
        this.roomId = !!seqParam ? seqParam : undefined;
      }
    );
  }

  ngOnDestroy(): void {
    if (!!this.paramsSubscription) {
      this.paramsSubscription.unsubscribe();
    }
  }
  onRightDrawerToggle(): void {
    this.chatRightDrawer.toggle();
  }
}
