import { Component, OnInit } from '@angular/core';
import { SysService } from './sys.service';

@Component({
  selector: 'app-sessions',
  template: `


  <nz-page-header i18n-nzTitle nzTitle="SESSION管理">
    <nz-page-header-extra>
      <!--
      <button class="btn ">销毁所有</button>
      -->
    </nz-page-header-extra>
  </nz-page-header>


    <cg-pager
      remoteHeaderUrl="/napi/web/user/pager/headers"
      remoteUrl="/napi/web/user/session/list"
      [showOrder]="false"
      [showSearch]="false"
      [refresh]="trigger"
      [listTemplate]="listTpl"
    ></cg-pager>

  <ng-template #listTpl let-list="list" let-headers="headers" >
    <cg-pager-table  [headers]="headers" [enableSort]="false" [list]="list?.data" [cellRenders]="{disabled, tableOperations}"  > </cg-pager-table> 
  </ng-template>

  <ng-template #disabled let-item="item" >
    <span *ngIf="item.disabled" class="badge bg-warning text-dark" i18n>禁用</span>
    <span *ngIf="!item.disabled" class="badge bg-success" i18n>正常</span>
  </ng-template>


  <ng-template #tableOperations let-item="item"  >
    <button class="btn  btn-sm me-1"  
      cgOpButton
      i18n-confirmContent confirmContent="确定要销毁这个session? 用户将需要重新登陆才能使用系统"
      [operation]="sys.deleteSession(item.sesid)"
      (onSuccess)="refresh()"
    >
     <i class="fal fa-user-slash" ></i><ng-container i18n>销毁</ng-container></button>
  </ng-template>
    
  `,
  styles: [
  ]
})
export class SessionsComponent implements OnInit {

  trigger: boolean = false;
  refresh() {
    this.trigger = !this.trigger;
  }

  constructor(
    public sys: SysService,
  ) { }

  ngOnInit(): void {
  }

}
