import { Component } from '@angular/core';
import {NzResultModule} from "ng-zorro-antd/result";
import {NzButtonComponent} from "ng-zorro-antd/button";
import {NzMessageService} from "ng-zorro-antd/message";
import {Router} from "@angular/router";
import {DATA, INIT_FLAG, LOGIN_DATA, USER_TOKEN} from "../../../data/login/localStorage.namespace";
import {LocalStorageService} from '../../../utils/localStorage.service';
import {LoginService} from '../../../services/login.service';


@Component({
  selector: 'app-error401',
  standalone: true,
  imports: [
    NzResultModule,
    NzButtonComponent
  ],
  templateUrl: './error401.component.html',
  styleUrl: './error401.component.less'
})
export class Error401Component {
  constructor(
    private storage: LocalStorageService,
    private message: NzMessageService,
    private router: Router,  // 路由
    private login: LoginService
  ) {}


  // 退出登录
  public loginOut(): void {
    this.login.loginOut( (data: any) => {
      if (data['return_code'] === '000000') {
        this.storage.removeItem(LOGIN_DATA);
        this.storage.removeItem(DATA);
        this.storage.removeItem(USER_TOKEN);
        this.storage.removeItem(INIT_FLAG);
        this.router.navigate(['/login']).then(r => console.log(r));

      } else {
        this.message.error(data['return_msg']);
      }
    });
  }
}
