import { Injectable, Inject, NgZone } from '@angular/core';

import { MatDialog } from '@angular/material/dialog';

import { Store } from '@ngrx/store';

import { LoginResponse } from '@ucap/protocol-authentication';

import { NativeService } from '@ucap/native';

import { UCAP_NATIVE_SERVICE } from '@ucap/ng-native';
import { SessionStorageService } from '@ucap/ng-web-storage';

import { AppKey } from '@app/types/app-key.type';

@Injectable({
  providedIn: 'root'
})
export class AppNativeService {
  constructor(
    @Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
    private sessionStorageService: SessionStorageService,
    private store: Store<any>,
    private matDialog: MatDialog,
    private ngZone: NgZone
  ) {}

  subscribe(): void {
    this.nativeService.logout().subscribe(() => {
      this.ngZone.run(() => {
        this.matDialog.closeAll();

        const loginRes = this.sessionStorageService.get<LoginResponse>(
          AppKey.LoginResponse
        );

        // this.store.dispatch(AuthenticationActions.logoutConfirmation());
      });
    });

    this.nativeService.changeStatus().subscribe(statusCode => {});

    this.nativeService.showSetting().subscribe(() => {
      this.ngZone.run(() => {
        // this.store.dispatch(SettingsStore.showDialog());
      });
    });
  }
}
