<clr-datagrid (clrDgRefresh)="refresh($event)">
  <clr-dg-column>
    <ng-container *clrDgHideableColumn="showState['ID']">
      ID
    </ng-container>
  </clr-dg-column>
  <clr-dg-column [clrDgField]="'name'" style="min-width: 206px;">
    <ng-container *clrDgHideableColumn="showState['name']">
      {{'TITLE.NAME' | translate}}
    </ng-container>
  </clr-dg-column>
  <clr-dg-column>
    <ng-container *clrDgHideableColumn="showState['URL']">
      URL
    </ng-container>
  </clr-dg-column>
  <clr-dg-column>
    <ng-container *clrDgHideableColumn="showState['status']">
      {{'TITLE.START_STATUS' | translate}}
    </ng-container>
  </clr-dg-column>
  <clr-dg-column [clrDgField]="'user'">
    <ng-container *clrDgHideableColumn="showState['create_user']">
      {{'TITLE.CREATE_USER' | translate}}
    </ng-container>
  </clr-dg-column>
  <clr-dg-column>
    <ng-container *clrDgHideableColumn="showState['create_time']">
      {{'TITLE.CREATE_TIME' | translate}}
    </ng-container>
  </clr-dg-column>
  <clr-dg-column
    *ngIf="
      authService.currentNamespacePermission.webHook.update ||
      authService.currentAppPermission.webHook.update ||
      authService.currentNamespacePermission.webHook.delete ||
      authService.currentAppPermission.webHook.delete ||
      authService.currentUser.admin"
  >
    <ng-container *clrDgHideableColumn="showState['action']">
      {{'TITLE.ACTION' | translate}}
    </ng-container>
  </clr-dg-column>
  <clr-dg-row *ngFor="let w of webHooks; let i = index" [clrDgItem]="webHook">
    <clr-dg-cell>{{w.id}}</clr-dg-cell>
    <clr-dg-cell class="copy">{{w.name}}</clr-dg-cell>
    <clr-dg-cell>{{w.url}}</clr-dg-cell>
    <clr-dg-cell>
      <div class="toggle-switch">
        <input
          type="checkbox"
          id="webhook-toggle-{{i}}"
          (change)="toggleWebhook(w)"
          [checked]="w.enabled"
        >
        <label for="webhook-toggle-{{i}}"></label>
      </div>
    </clr-dg-cell>
    <clr-dg-cell>{{w.user}}</clr-dg-cell>
    <clr-dg-cell>{{w.createTime | date:"yyyy-MM-dd HH:mm"}}</clr-dg-cell>
    <clr-dg-cell
      *ngIf="
      authService.currentNamespacePermission.webHook.update ||
      authService.currentAppPermission.webHook.update ||
      authService.currentNamespacePermission.webHook.delete ||
      authService.currentAppPermission.webHook.delete ||
      authService.currentUser.admin"
    >
      <button class="wayne-button text"
              *ngIf="
        authService.currentNamespacePermission.webHook.update ||
        authService.currentAppPermission.webHook.update ||
        authService.currentUser.admin"
              (click)="editWebhook(w)">
        {{'ACTION.EDIT' | translate}}</button>
      <button class="wayne-button text"
              *ngIf="
        authService.currentNamespacePermission.webHook.delete ||
        authService.currentAppPermission.webHook.delete ||
        authService.currentUser.admin"
              (click)="deleteWebhook(w)">
        {{'ACTION.DELETE' | translate}}</button>
    </clr-dg-cell>
  </clr-dg-row>

  <clr-dg-footer>
    <wayne-paginate
      [(currentPage)]="currentPage"
      [total]="page.totalCount"
      [pageSizes]="[10, 20, 50]"
      (sizeChange)="pageSizeChange($event)"
    >
    </wayne-paginate>
  </clr-dg-footer>
</clr-datagrid>
