<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>
      <mat-form-field fxFlex="30" fxLayoutAlign="start end">
        <input matInput [(ngModel)]="filterValue" (input)="applyFilter()" (keyup)="applyFilter()" name="filter" placeholder="Filter">
      </mat-form-field>
    </div>
    <div fxLayout="row" fxLayoutAlign="start start">
      <div [perfectScrollbar] fxLayout="column" class="table-container" fxFlex="100">
        <table mat-table #table fxFlex="100" [dataSource]="transactions" matSort class="overflow-auto">
          <ng-container matColumnDef="date">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
            <td mat-cell *matCellDef="let transaction">{{transaction?.date | date:(dataRange === scrollRanges[1] ? 'MMM/yyyy' : 'dd/MMM/yyyy')}}</td>
          </ng-container>
          <ng-container matColumnDef="amount_paid">
            <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before">Amount Paid (Sats)</th>
            <td mat-cell *matCellDef="let transaction"><span fxLayoutAlign="end center">{{transaction?.amount_paid | number:'1.0-2'}}</span></td>
          </ng-container>
          <ng-container matColumnDef="num_payments">
            <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"># Payments</th>
            <td mat-cell *matCellDef="let transaction"><span fxLayoutAlign="end center">{{transaction?.num_payments | number}}</span></td>
          </ng-container>
          <ng-container matColumnDef="amount_received">
            <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before">Amount Received (Sats)</th>
            <td mat-cell *matCellDef="let transaction"><span fxLayoutAlign="end center">{{transaction?.amount_received | number:'1.0-2'}}</span></td>
          </ng-container>
          <ng-container matColumnDef="num_invoices">
            <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"># Invoices</th>
            <td mat-cell *matCellDef="let transaction"><span fxLayoutAlign="end center">{{transaction?.num_invoices | 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 transaction" class="px-3" fxLayoutAlign="end center">
              <button mat-stroked-button color="primary" type="button" tabindex="4" (click)="onTransactionClick(transaction)">View Info</button>
            </td>
          </ng-container>
          <ng-container matColumnDef="no_transaction">
            <td mat-footer-cell *matFooterCellDef colspan="4">
              <p *ngIf="!transactions?.data || transactions?.data?.length<1">No transaction available.</p>
            </td>
          </ng-container>
          <tr mat-footer-row *matFooterRowDef="['no_transaction']" [ngClass]="{'display-none': transactions?.data && transactions?.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>
</div>
