import { OnInit } from '@angular/core';
import { WebNotificationService } from '../auth/webNotification.service';
import { AuthService } from '../auth/auth.service';
import { OcBasedUnifiedNotificationService } from '../notification/OcBasedUnifiedNotification.service';
import * as fromRoot from '../auto-logout/reducers';
import * as ApplicationActions from '../auto-logout/actions';
import { MessageService as MessageServiceP } from 'node_modules/primeng/api';
import { Store } from '@ngrx/store';
import { RouteHandleService } from 'ekangularbase/src/route/RouteHandle.service';

export class AppComponentBase implements OnInit {

    msgs: any;
    menuActive: boolean;

    activeMenuId: string;

    notification = false;
    constructor(
        // private confirmationService: ConfirmationService,
        public webNotificationservice: WebNotificationService,
        // private connectionIndicationService: ConnectionIndicationService,
        public authService: AuthService, public messageService: MessageServiceP,
        // private router: Router,
        // private unifiedNotificationService : UnifiedNotificationService,
        public ocBasedUnifiedNotificationService: OcBasedUnifiedNotificationService,
        public store: Store<fromRoot.State>,
        public routehandleservice?: RouteHandleService) {
    }

    ngOnInit() {
        this.initListener();
        // this.connectionIndicationService.build();
        // this.connectionIndicationService.start();
        this.webNotificationservice.build();
        this.webNotificationservice.start();
        // this.unifiedNotificationService.build();
        // this.unifiedNotificationService.start();
        this.ocBasedUnifiedNotificationService.build();
        this.ocBasedUnifiedNotificationService.start();
        setTimeout(() => { this.notification = true; }, 3000);

        // const redirectDetails = this.routehandleservice.getRedirectDetails();
        // if (redirectDetails !== null) {
        //     console.log('redirect AppComponentBase');
        //     // this.routehandleservice.showblockUi();
        //     this.authService.ResetFlag();
        //     this.authService.isRedirect = true;
        //     location.assign(redirectDetails.fullUrl);
        // }
    }



    //   reset(actionType: string) {
    //     // console.log(actionType);
    //     this.store.dispatch(new ApplicationActions.ExtendLogoutTimer());
    //     // this.setLastAction(Date.now());
    //   }

    isLoggedIn(): boolean {
        return this.authService.isLoggedIn();
    }

    changeTheme(event: Event, theme: string) {
        const themeLink: HTMLLinkElement = <HTMLLinkElement>document.getElementById('theme-css');
        themeLink.href = 'assets/components/themes/' + theme + '/theme.css';
        event.preventDefault();
        // alert(themeLink.href);
    }

    onMenuButtonClick(event: Event) {
        this.menuActive = !this.menuActive;
        event.preventDefault();
    }

    closeNotification(event) {
        this.notification = false;
        event.preventDefault();
    }

    initListener() {
        document.body.addEventListener('click', () => this.reset('click'));
        document.body.addEventListener('mouseover', () => this.reset('mouseover'));
    }

    reset(actionType: string) {
        // console.log(actionType);
        this.store.dispatch(new ApplicationActions.ExtendLogoutTimer());
        this.authService.setLastActionTime();
        // this.setLastAction(Date.now());
    }

    onConfirm() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('alertDialog');
    }

    onReject() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('alertDialog');
    }

    onErrorConfirm() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('errorDialog');
    }

    onErrorReject() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('errorDialog');
    }

    onMultipleErrorConfirm() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('multipleErrorDialog');
    }

    onMultipleErrorReject() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('multipleErrorDialog');
    }

    onMultipleAlertConfirm() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('multipleAlertDialog');
    }

    onMultipleAlertReject() {
        this.authService.isToastDialogEnabled = false;
        this.messageService.clear('multipleAlertDialog');
    }

}
