import { Component, HostBinding, OnInit } from '@angular/core';

import { SettingsService } from './core/settings/settings.service';
import {ToasterConfig, ToasterService} from 'angular2-toaster';
import {MsgService} from './core/msg/msg.service';
import {AjaxService} from './core/ajax/ajax.service';
import {FrameService} from './core/frame/frame.service';
import {DomSanitizer} from '@angular/platform-browser';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

    @HostBinding('class.layout-fixed') get isFixed() { return this.settings.getLayoutSetting('isFixed'); };
    @HostBinding('class.aside-collapsed') get isCollapsed() { return this.settings.getLayoutSetting('isCollapsed'); };
    @HostBinding('class.layout-boxed') get isBoxed() { return this.settings.getLayoutSetting('isBoxed'); };
    @HostBinding('class.layout-fs') get useFullLayout() { return this.settings.getLayoutSetting('useFullLayout'); };
    @HostBinding('class.hidden-footer') get hiddenFooter() { return this.settings.getLayoutSetting('hiddenFooter'); };
    @HostBinding('class.layout-h') get horizontal() { return this.settings.getLayoutSetting('horizontal'); };
    @HostBinding('class.aside-float') get isFloat() { return this.settings.getLayoutSetting('isFloat'); };
    @HostBinding('class.offsidebar-open') get offsidebarOpen() { return this.settings.getLayoutSetting('offsidebarOpen'); };
    @HostBinding('class.aside-toggled') get asideToggled() { return this.settings.getLayoutSetting('asideToggled'); };
    @HostBinding('class.aside-collapsed-text') get isCollapsedText() { return this.settings.getLayoutSetting('isCollapsedText'); };

    // 显示正在加载的框
    isLoading: boolean = false;

    // 右下角提示框
    toasterconfig: ToasterConfig = new ToasterConfig({
      positionClass: 'toast-bottom-right',
      showCloseButton: true,
      mouseoverTimerStop: true,
      limit: 3
    });

    constructor(public settings: SettingsService, private toaster: ToasterService) {
      MsgService.TOASTER = this.toaster;
      MsgService.APP_COMPONENT = this;
    }

    ngOnInit() {
        // 禁用所有的a超链接，所有超链接必须通过js代码打开新窗口
        document.addEventListener('click', e => {
            const target = e.target as HTMLElement;
            if (target.tagName === 'A' || target.tagName === 'a') {
              e.preventDefault();
            };
        });

        // 禁止F5 刷新
      document.addEventListener('keydown', e => {
        if (e.key === 'F5')
          e.preventDefault();
          return false;
      });
    }
}
