<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 class="page-title-img mr-1" [icon]="faHistory"></fa-icon>
      <span class="page-title">{{swapCaption}} History</span>
    </div>
    <div fxFlex.gt-xs="30" fxLayoutAlign.gt-xs="space-between center" fxLayout="row" fxLayoutAlign="space-between stretch">
      <mat-form-field fxLayout="column" fxFlex="49">
        <mat-label>Filter By</mat-label>
        <mat-select tabindex="1" name="filterBy" [(ngModel)]="selFilterBy" (selectionChange)="selFilter=''; applyFilter()">
          <perfect-scrollbar><mat-option *ngFor="let column of ['all'].concat(displayedColumns.slice(0, -1))" [value]="column">{{getLabel(column)}}</mat-option></perfect-scrollbar>
        </mat-select>
      </mat-form-field>
      <mat-form-field fxLayout="column" fxFlex="49">
        <mat-label>Filter</mat-label>
        <input matInput name="filter" [(ngModel)]="selFilter" (input)="applyFilter()" (keyup)="applyFilter()">
      </mat-form-field>
    </div>
  </div>
  <div fxLayout="row" fxLayoutAlign="start center" class="w-100">
    <div class="table-container" fxFlex="100" [perfectScrollbar]>
      <mat-progress-bar *ngIf="flgLoading[0]===true" mode="indeterminate"></mat-progress-bar>
      <table #table mat-table matSort [matSortActive]="selectedSwapType === swapTypeEnum.SWAP_IN ? tableSettingSwapIn.sortBy : tableSettingSwapOut.sortBy" [matSortDirection]="selectedSwapType === swapTypeEnum.SWAP_IN ? tableSettingSwapIn.sortOrder : tableSettingSwapOut.sortOrder" [dataSource]="listSwaps" [ngClass]="{'overflow-auto error-border': flgLoading[0]==='error','overflow-auto': true}">
        <ng-container matColumnDef="status">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Status</th>
          <td *matCellDef="let swap" mat-cell>{{swapStateEnum[swap?.status]}}</td>
        </ng-container>
        <ng-container matColumnDef="id">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Swap ID</th>
          <td *matCellDef="let swap" mat-cell>{{swap?.id}}</td>
        </ng-container>
        <ng-container matColumnDef="claimAddress">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Claim Address</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.claimAddress}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="lockupAddress">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Lockup Address</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.lockupAddress}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="onchainAmount">
          <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before">Onchain Amount (Sats)</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayoutAlign="end center">{{swap?.onchainAmount | number}}</span>
          </td>
        </ng-container>
        <ng-container matColumnDef="expectedAmount">
          <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before">Expected Amount (Sats)</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayoutAlign="end center">{{swap?.expectedAmount | number}}</span>
          </td>
        </ng-container>
        <ng-container matColumnDef="error">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Error</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.error}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="privateKey">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Private Key</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.privateKey}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="preimage">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Preimage</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.preimage}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="redeemScript">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Redeem Script</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.redeemScript}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="invoice">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Invoice</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayout.gt-xs="row" class="ellipsis-parent" [ngStyle]="{'width': (screenSize === screenSizeEnum.XS) ? '6rem' : colWidth}">
              <span class="ellipsis-child">{{swap?.invoice}}</span>
            </span>
          </td>
        </ng-container>
        <ng-container matColumnDef="timeoutBlockHeight">
          <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before">Timeout Block Height</th>
          <td *matCellDef="let swap" mat-cell>
            <span fxLayoutAlign="end center">{{swap?.timeoutBlockHeight | number}}</span>
          </td>
        </ng-container>
        <ng-container matColumnDef="lockupTransactionId">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Lockup Tx ID</th>
          <td *matCellDef="let swap" mat-cell>{{swap?.lockupTransactionId}}</td>
        </ng-container>
        <ng-container matColumnDef="claimTransactionId">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Claim Tx ID</th>
          <td *matCellDef="let swap" mat-cell>{{swap?.claimTransactionId}}</td>
        </ng-container>
        <ng-container matColumnDef="refundTransactionId">
          <th *matHeaderCellDef mat-header-cell mat-sort-header>Refund Tx ID</th>
          <td *matCellDef="let swap" mat-cell>{{swap?.refundTransactionId}}</td>
        </ng-container>
        <ng-container matColumnDef="actions">
          <th *matHeaderCellDef mat-header-cell>
            <div class="bordered-box table-actions-select" fxLayoutAlign="center center">
              <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 *matCellDef="let swap" mat-cell fxLayoutAlign="end center">
            <button mat-stroked-button color="primary" type="button" tabindex="4"
              class="table-actions-button" (click)="onSwapClick(swap, $event)">View Info</button>
          </td>
        </ng-container>
        <ng-container matColumnDef="no_swap">
          <td *matFooterCellDef  mat-footer-cell colspan="4">
            <p *ngIf="!listSwaps?.data || listSwaps?.data?.length<1">{{emptyTableMessage}}</p>
          </td>
        </ng-container>
        <tr *matFooterRowDef="['no_swap']" mat-footer-row [ngClass]="{'display-none': listSwaps?.data && listSwaps?.data?.length>0}"></tr>
        <tr *matHeaderRowDef="displayedColumns" mat-header-row></tr>
        <tr *matRowDef="let row; columns: displayedColumns;" mat-row></tr>
      </table>
      <mat-paginator class="mb-1" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" [showFirstLastButtons]="screenSize === screenSizeEnum.XS ? false : true"></mat-paginator>
    </div>
  </div>
</div>
