import { Component, EventEmitter, Input, Output } from '@angular/core';
import { RiskItemModel } from '../../../../../classes/risk-item.model';
import { CommonNzModule } from '../../../../../common.nz.module';

@Component({
  selector: 'risk-item-table',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './risk-item-table.component.html',
  styleUrl: './risk-item-table.component.less',
})
export class RiskItemTableComponent extends RiskItemModel {
  @Input() pageConfig: IPageConfig = {
    page: 0,
    total: 0,
    size: 10,
  };
  @Input() loading = false;
  @Input() list: Knowledge.RiskItem[] = [];
  @Output() onPageConfigChange = new EventEmitter<IPageConfig>();
  @Output() onRemove = new EventEmitter<Knowledge.RiskItem>();
  @Output() onEdit = new EventEmitter<Knowledge.RiskItem>();
  @Output() onRecord = new EventEmitter<Knowledge.RiskItem>();

  onCurrentPageChange(page: number) {
    this.pageConfig.page = page;
    this.onPageConfigChange.emit(this.pageConfig);
  }

  handleEdit(data: Knowledge.RiskItem) {
    this.onEdit.emit(data);
  }
  handleRemove(data: Knowledge.RiskItem) {
    this.onRemove.emit(data);
  }

  toRecord(data: Knowledge.RiskItem) {
    this.onRecord.emit(data);
  }
  onView(url?: string) {
    if (url) {
      window.open(url, '_blank');
    }
  }
}
