import { Component, OnInit } from '@angular/core';
import { AppThemeConfig } from 'src/theme/app-theme-config';
import { App } from '@global/service/App';
import { AppNotification } from '@global/service/Notification';

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

  constructor(private $app: App,private $notification:AppNotification) { }

  ngOnInit() {
  }

  /**
   * 
   * 更换主题
   */
  public async changeAppTheme() {
    let appTheme = localStorage.getItem('app-theme');
    const result: string = await this.$app.openActionSheet({ items: AppThemeConfig });
    if (!Object.is(result, appTheme)) {
      localStorage.setItem('app-theme', result);
      document.getElementsByTagName('html')[0].className = result;
    }
  }

  /**
   * 
   * 退出登录
   */
  public async logout() {
    const judge: boolean = await this.$notification.confirm('退出', '确认退出当前用户?');
    if (judge) {
        this.$app.clearAccess();
        this.$app.login();
    }
  }

}
