<div fxLayout="column" fxFlex="100" fxLayoutAlign="start start" class="card-content-gap">
  <div fxLayout="column" fxLayout.gt-xs="row" fxLayoutAlign.gt-xs="start center" fxLayoutAlign="start stretch" fxFlex="100" class="page-sub-title-container w-100">
    <div fxFlex="70">
      <fa-icon [icon]="faHistory" class="page-title-img mr-1"></fa-icon>
      <span class="page-title">{{swapCaption}} History, {{flgLoading}}</span>
    </div>
    <mat-form-field fxFlex="30">
      <input matInput (keyup)="applyFilter()" [(ngModel)]="selFilter" placeholder="Filter">
    </mat-form-field>
  </div>
  <div fxLayout="row" fxLayoutAlign="start center" class="w-100">
    <div [perfectScrollbar] class="table-container" fxFlex="100">
      <mat-progress-bar *ngIf="flgLoading[0]===true" mode="indeterminate"></mat-progress-bar>
      <table mat-table #table [dataSource]="listSwaps" matSort [ngClass]="{'overflow-auto error-border': flgLoading[0]==='error','overflow-auto': true}">
        <ng-container matColumnDef="initiation_time">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> Initiation Time </th>
          <td mat-cell *matCellDef="let swap">{{(swap.initiation_time/1000000) | date:'dd/MMM/y HH:mm'}}</td>
        </ng-container>
        <ng-container matColumnDef="last_update_time">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> Last Update Time </th>
          <td mat-cell *matCellDef="let swap">{{(swap.last_update_time/1000000) | date:'dd/MMM/y HH:mm'}}</td>
        </ng-container>
        <ng-container matColumnDef="id">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> ID </th>
          <td mat-cell *matCellDef="let swap">{{swap.id}}</td>
        </ng-container>
        <ng-container matColumnDef="id_bytes">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> ID (Bytes) </th>
          <td mat-cell *matCellDef="let swap">{{swap.id_bytes}}</td>
        </ng-container>
        <ng-container matColumnDef="state">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> State </th>
          <td mat-cell *matCellDef="let swap">{{LoopStateEnum[swap.state]}}</td>
        </ng-container>
        <ng-container matColumnDef="htlc_address">
          <th mat-header-cell *matHeaderCellDef mat-sort-header> HTLC Address </th>
          <td mat-cell *matCellDef="let swap">{{swap.htlc_address}}</td>
        </ng-container>
        <ng-container matColumnDef="amt">
          <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"> Amount (Sats) </th>
          <td mat-cell *matCellDef="let swap">
            <span fxLayoutAlign="end center">{{swap.amt | number}}</span>
          </td>
        </ng-container>
        <ng-container matColumnDef="cost_server">
          <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"> Cost Server (Sats) </th>
          <td mat-cell *matCellDef="let swap"><span fxLayoutAlign="end center">{{swap.cost_server | number}}</span></td>
        </ng-container>
        <ng-container matColumnDef="cost_offchain">
          <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"> Cost Offchain (Sats) </th>
          <td mat-cell *matCellDef="let swap"><span fxLayoutAlign="end center">{{swap.cost_offchain | number}}</span></td>
        </ng-container>
        <ng-container matColumnDef="cost_onchain">
          <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"> Cost Onchain (Sats) </th>
          <td mat-cell *matCellDef="let swap"><span fxLayoutAlign="end center">
              {{swap?.cost_onchain | number}} </span></td>
        </ng-container>
        <ng-container matColumnDef="actions">
          <th mat-header-cell *matHeaderCellDef class="px-3">
            <div class="bordered-box table-actions-select">
              <mat-select placeholder="Actions" tabindex="1" class="mr-0">
                <mat-select-trigger></mat-select-trigger>
                <mat-option (click)="onDownloadCSV()">Download CSV</mat-option>
              </mat-select>
            </div>
          </th>
          <td mat-cell *matCellDef="let swap" class="pl-3" fxLayoutAlign="end center">
            <button mat-stroked-button color="primary" type="button" tabindex="4"
              (click)="onSwapClick(swap, $event)">View Info</button>
          </td>
        </ng-container>
        <ng-container matColumnDef="no_swap">
          <td mat-footer-cell *matFooterCellDef colspan="4">
            <p *ngIf="!listSwaps?.data || listSwaps?.data?.length<1">{{emptyTableMessage}}</p>
          </td>
        </ng-container>
        <tr mat-footer-row *matFooterRowDef="['no_swap']" [ngClass]="{'display-none': listSwaps?.data && listSwaps?.data?.length>0}"></tr>
        <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: flgSticky;"></tr>
        <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
      </table>
      <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" [showFirstLastButtons]="screenSize === screenSizeEnum.XS ? false : true" class="mb-1"></mat-paginator>
    </div>
  </div>
</div>
