<div fxLayout="row" fxLayoutAlign="start center" class="page-title-container">
  <fa-icon [icon]="faBullhorn" class="page-title-img mr-1"></fa-icon>
  <span class="page-title">Liquidity Ads</span>
</div>
<div fxLayout="column" class="padding-gap-x">
  <mat-card>
    <mat-card-content class="padding-gap-large">
      <div fxLayout="column" fxFlex="100" fxLayoutAlign="space-between stretch">
        <form fxLayout="column" fxLayoutAlign="space-between stretch" fxLayout.gt-sm="row wrap" #formAsk="ngForm">
          <div fxFlex="100" fxLayout="row" class="alert alert-warn">
            <fa-icon [icon]="faExclamationTriangle" class="mr-1 alert-icon"></fa-icon>
            <span>Ads should be suplemented with additional research of the nodes, before buying liquidity.</span>
          </div>
          <div fxLayout="column" fxLayout.gt-sm="row wrap" fxFlex="100" fxLayoutAlign.gt-sm="space-between center" fxLayoutAlign="start start" class="page-sub-title-container mt-1">
            <div fxFlex="30">
              <span class="page-title">
                Liquidity Ask
                <mat-icon [matTooltip]="askTooltipMsg" matTooltipPosition="above" matTooltipClass="pre-wrap" class="info-icon info-icon-primary">info_outline</mat-icon>
              </span>
            </div>
            <mat-form-field fxFlex="34">
              <input autoFocus matInput placeholder="Channel Amount (Sats)" name="channelAmount" [(ngModel)]="channelAmount" (keyup)="onCalculateOpeningFee()" tabindex="1" type="number" step="10000" required>
              <mat-error *ngIf="!channelAmount">Channel amount is required.</mat-error>
            </mat-form-field>
            <mat-form-field fxFlex="34">
              <input matInput placeholder="Channel Opening Fee Rate (Sats/vByte)" name="channelOpeningFeeRate" [(ngModel)]="channelOpeningFeeRate" (keyup)="onCalculateOpeningFee()" type="number" step="10" tabindex="2" required>
              <mat-error *ngIf="!channelOpeningFeeRate">Channel opening fee rate is required.</mat-error>
            </mat-form-field>
          </div>
        </form>
        <!-- <mat-divider [inset]="true" class="my-2"></mat-divider>
        <form fxLayout="column" fxLayoutAlign="space-between stretch" fxLayout.gt-sm="row wrap" #formFilter="ngForm">
          <div fxLayout="column" fxLayout.gt-sm="row wrap" fxFlex="100" fxLayoutAlign.gt-sm="space-between center" fxLayoutAlign="start start" class="page-sub-title-container mt-1">
            <div fxFlex="30">
              <span class="page-title">
                Nodes Advertising Liquidity
                <mat-icon [matTooltip]="nodesTooltipMsg" matTooltipPosition="above" matTooltipClass="pre-wrap" class="info-icon info-icon-primary">info_outline</mat-icon>
              </span>
            </div>
            <mat-form-field fxFlex="34">
              <input matInput placeholder="Node Capacity (Sats)" name="nodeCapacity" [(ngModel)]="nodeCapacity" (keyup)="onFilter()" tabindex="5" type="number" min="0" step="1000">
              <mat-error *ngIf="!nodeCapacity">Node capacity is required.</mat-error>
            </mat-form-field>
            <mat-form-field fxFlex="34">
              <input matInput placeholder="Channel Count" name="channelCount" [(ngModel)]="channelCount" (keyup)="onFilter()" type="number" step="1" min="0" tabindex="6">
            </mat-form-field>
          </div>
        </form> -->
        <div [perfectScrollbar] fxLayout="column" fxLayoutAlign="start center" fxFlex="100" class="table-container mt-2">
          <mat-progress-bar *ngIf="apiCallStatus.status === apiCallStatusEnum.INITIATED" mode="indeterminate"></mat-progress-bar>
          <table mat-table #table [dataSource]="liquidityNodes" matSort [ngClass]="{'overflow-auto error-border': errorMessage !== '','overflow-auto': true}">
            <ng-container matColumnDef="alias">
              <th mat-header-cell *matHeaderCellDef mat-sort-header> Alias </th>
              <td mat-cell *matCellDef="let lqNode" [ngStyle]="{'max-width': (screenSize === screenSizeEnum.XS) ? '10rem' : '40rem'}"> 
                {{lqNode?.alias}}<span *ngIf="lqNode.tor_node" matBadge="Tor Node" matBadgeOverlap="false" class="tab-badge"></span>
              </td>
            </ng-container>
            <ng-container matColumnDef="capacityChannels">
              <th mat-header-cell *matHeaderCellDef> Capacity/Channels </th>
              <td mat-cell *matCellDef="let lqNode">
                {{lqNode?.nodeCapacity/100000000 | number:'1.0-2'}} BTC / {{lqNode?.channelCount | number:'1.0-0'}} 
              </td>
            </ng-container>
            <ng-container matColumnDef="leaseFee">
              <th mat-header-cell *matHeaderCellDef> Lease Fee </th>
              <td mat-cell *matCellDef="let lqNode">
                {{lqNode?.option_will_fund?.lease_fee_base_msat/1000 | number:'1.0-0'}} Sats + {{(lqNode?.option_will_fund?.lease_fee_basis/100) | number:'1.2-2'}}%
              </td>
            </ng-container>
            <ng-container matColumnDef="routingFee">
              <th mat-header-cell *matHeaderCellDef> Routing Fee </th>
              <td mat-cell *matCellDef="let lqNode">
                {{lqNode?.option_will_fund?.channel_fee_max_base_msat/1000 | number:'1.0-0'}} Sats + {{lqNode?.option_will_fund?.channel_fee_max_proportional_thousandths * 1000 | number:'1.0-0'}} ppm
              </td>
            </ng-container>
            <ng-container matColumnDef="channelOpeningFee">
              <th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before"> Channel Opening Fee </th>
              <td mat-cell *matCellDef="let lqNode">
                <span fxLayoutAlign="end center">
                  {{lqNode.channelOpeningFee | number:'1.0-0'}} Sats
                </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 lqNode" fxLayoutAlign="end center" class="px-3">
                <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)="onViewLeaseInfo(lqNode)">View Info</mat-option>
                    <mat-option (click)="onOpenChannel(lqNode)">Open Channel</mat-option>
                    <mat-option (click)="viewLeaseOn(lqNode, 'LN')">View on Lnrouter</mat-option>
                    <mat-option (click)="viewLeaseOn(lqNode, 'AM')">View on Amboss</mat-option>
                  </mat-select>
                </div>
              </td>
            </ng-container>
            <ng-container matColumnDef="no_lqNode">
              <td mat-footer-cell *matFooterCellDef colspan="4">
                <p *ngIf="(!liquidityNodes?.data || liquidityNodes?.data?.length<1) && apiCallStatus.status === apiCallStatusEnum.COMPLETED">No node with liquidity.</p>
                <p *ngIf="(!liquidityNodes?.data || liquidityNodes?.data?.length<1) && apiCallStatus.status === apiCallStatusEnum.INITIATED">Getting nodes with liquidity...</p>
                <p *ngIf="(!liquidityNodes?.data || liquidityNodes?.data?.length<1) && apiCallStatus.status === apiCallStatusEnum.ERROR">{{errorMessage}}</p>
              </td>
            </ng-container>
            <tr mat-footer-row *matFooterRowDef="['no_lqNode']" [ngClass]="{'display-none': liquidityNodes?.data && liquidityNodes?.data?.length>0}"></tr>
            <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: flgSticky;"></tr>
            <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
          </table>
        </div>
        <mat-paginator [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" [showFirstLastButtons]="screenSize === screenSizeEnum.XS ? false : true" class="mb-1"></mat-paginator>
      </div>
    </mat-card-content>
  </mat-card>
</div>
