import { Component, OnInit, ViewChild, inject } from '@angular/core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFDateWidgetSchema, SFSchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { SHARED_IMPORTS } from '@shared';
import { SysAuditLogDetlComponent } from './audit-log-detl/audit-log-detl.component';
import { BaseService } from 'src/app/core/utils/base.service';
import { NzNotificationService } from 'ng-zorro-antd/notification';

@Component({
  selector: 'app-sys-audit-log',
  standalone: true,
  imports: [...SHARED_IMPORTS],
  templateUrl: './audit-log.component.html'
})
export class SysAuditLogComponent implements OnInit {
  private readonly http = inject(_HttpClient);
  private readonly modal = inject(ModalHelper);
  private readonly baseService = inject(BaseService);
  private readonly notification = inject(NzNotificationService);

  url = `/api/main/audit-log`;

  searchSchema: SFSchema = {
    properties: {
      startTime: {
        type: 'string',
        ui: { widget: 'date', end: 'endTime', separator: '到' } as SFDateWidgetSchema,
        format: 'date',
        title: '日期',
        default: new Date()
      },
      endTime: {
        type: 'string',
        default: new Date()
      }
    }
  };
  @ViewChild('sf') private readonly sf!: SFComponent;
  @ViewChild('st') private readonly st!: STComponent;
  columns: STColumn[] = [
    {
      title: '操作',
      buttons: [{ text: '查看', click: (item: any) => this.detl(item) }]
    },
    { title: '应用程序', index: 'applicationName' },
    { title: 'URL', index: 'url' },
    { title: '用户名', index: 'userName' },
    { title: '创建时间', index: 'executionTime', type: 'date', dateFormat: 'yyyy-MM-dd HH:mm' },
    { title: '执行时间', index: 'executionDuration' },
    { title: 'IP地址', index: 'clientIpAddress' },
    { title: '请求的方法', index: 'httpMethod' },
    { title: '状态码.', index: 'httpStatusCode' }
  ];

  ngOnInit(): void { }

  detl(item: any): void {
    this.baseService.showModal({
      title: '审计日志',
      widthClass: 'xl',
      component: SysAuditLogDetlComponent,
      componentParams: item,
      footer: null,
      okCallBack: () => {
        //this.getConsultingList();
      }
    });
  }
}
