<div fxLayout="column" fxFlex="100" fxLayoutAlign="space-between stretch" class="padding-gap-x">
  <div fxLayout="column" fxLayoutAlign="start stretch">
    <div fxLayout="column" fxLayoutAlign="start stretch" fxLayout.gt-sm="row wrap" class="page-sub-title-container mt-1">
      <div fxFlex="70"></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 start">
      <div fxLayout="column" class="table-container" fxFlex="100" [perfectScrollbar]>
        <table #table mat-table fxFlex="100" matSort class="overflow-auto" [matSortActive]="tableSetting.sortBy" [matSortDirection]="tableSetting.sortOrder" [dataSource]="transactions">
          <ng-container matColumnDef="date">
            <th *matHeaderCellDef mat-header-cell mat-sort-header>Date</th>
            <td *matCellDef="let transaction" mat-cell>{{transaction?.date | date:(dataRange === scrollRanges[1] ? 'MMM/yyyy' : 'dd/MMM/yyyy')}}</td>
          </ng-container>
          <ng-container matColumnDef="amount_paid">
            <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before">Amount Paid (Sats)</th>
            <td *matCellDef="let transaction" mat-cell><span fxLayoutAlign="end center">{{transaction?.amount_paid | number:'1.0-2'}}</span></td>
          </ng-container>
          <ng-container matColumnDef="num_payments">
            <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before"># Payments</th>
            <td *matCellDef="let transaction" mat-cell><span fxLayoutAlign="end center">{{transaction?.num_payments | number}}</span></td>
          </ng-container>
          <ng-container matColumnDef="amount_received">
            <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before">Amount Received (Sats)</th>
            <td *matCellDef="let transaction" mat-cell><span fxLayoutAlign="end center">{{transaction?.amount_received | number:'1.0-2'}}</span></td>
          </ng-container>
          <ng-container matColumnDef="num_invoices">
            <th *matHeaderCellDef mat-header-cell mat-sort-header arrowPosition="before"># Invoices</th>
            <td *matCellDef="let transaction" mat-cell><span fxLayoutAlign="end center">{{transaction?.num_invoices | number}}</span></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 transaction" mat-cell fxLayoutAlign="end center">
              <button mat-stroked-button color="primary" type="button" tabindex="4" class="table-actions-button" (click)="onTransactionClick(transaction)">View Info</button>
            </td>
          </ng-container>
          <ng-container matColumnDef="no_transaction">
            <td *matFooterCellDef  mat-footer-cell colspan="4">
              <p *ngIf="!transactions?.data || transactions?.data?.length<1">No transaction available.</p>
            </td>
          </ng-container>
          <tr *matFooterRowDef="['no_transaction']" mat-footer-row [ngClass]="{'display-none': transactions?.data && transactions?.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>
</div>
