<div [ngClass]="{'container-xl': !widget, 'widget': widget}">

  <div *ngIf="!widget">
    <h1 i18n="liquid.recent-pegs">Recent Peg-In / Out's</h1>
    <app-recent-pegs-stats [pegsVolume$]="pegsVolume$"></app-recent-pegs-stats>
  </div>

  <div class="clearfix"></div>
  
  <div style="min-height: 295px">
    <table class="table table-borderless">
      <thead style="vertical-align: middle;">
        <th class="transaction text-start" [ngClass]="{'widget': widget}" i18n="shared.transaction">Transaction</th>
        <th class="timestamp text-start" i18n="shared.date" [ngClass]="{'widget': widget}">Date</th>
        <th class="amount text-end" [ngClass]="{'widget': widget}" i18n="shared.amount">Amount</th>
        <th class="output text-start" *ngIf="!widget" i18n="liquid.fund-redemption-tx">Fund / Redemption Tx</th>
        <th class="address text-start" *ngIf="!widget" i18n="liquid.bitcoin-address">BTC Address</th>
      </thead>
      <tbody *ngIf="recentPegsList$ | async as pegs; else skeleton" [style]="isLoading ? 'opacity: 0.75' : ''">
        <ng-container *ngIf="widget; else regularRows">
          <tr *ngFor="let peg of pegs | slice:0:6">
            <td class="transaction text-start widget">
              <ng-container *ngIf="peg.amount > 0">
                <a [routerLink]="['/tx' | relativeUrl, peg.txid]" [fragment]="'vin=' + peg.txindex">
                  <app-truncate [text]="peg.txid"></app-truncate>
                </a>
              </ng-container>
              <ng-container *ngIf="peg.amount < 0">
                <a [routerLink]="['/tx' | relativeUrl, peg.txid]" [fragment]="'vout=' + peg.txindex">
                  <app-truncate [text]="peg.txid"></app-truncate>
                </a>
              </ng-container>
            </td>
            <td class="timestamp text-start widget">
              <app-time kind="since" [time]="peg.blocktime" [showTooltip]="true"></app-time>
            </td>
            <td class="amount text-end widget" [ngClass]="{'credit': peg.amount > 0, 'debit': peg.amount < 0, 'glow-effect': peg.amount < 0 && peg.bitcoinaddress && !peg.bitcointxid}">
              <app-amount [satoshis]="peg.amount" [noFiat]="true" [forceBtc]="true" [addPlus]="true"></app-amount>
            </td>
          </tr>
        </ng-container>
        <ng-template #regularRows>
          <tr *ngFor="let peg of pegs;">
            <td class="transaction text-start">
              <ng-container *ngIf="peg.amount > 0">
                <a [routerLink]="['/tx' | relativeUrl, peg.txid]" [fragment]="'vin=' + peg.txindex">
                  <app-truncate [text]="peg.txid" [lastChars]="6"></app-truncate>
                </a>
              </ng-container>
              <ng-container *ngIf="peg.amount < 0">
                <a [routerLink]="['/tx' | relativeUrl, peg.txid]" [fragment]="'vout=' + peg.txindex">
                  <app-truncate [text]="peg.txid" [lastChars]="6"></app-truncate>
                </a>
              </ng-container>
            </td>
            <td class="timestamp text-start">
              <app-timestamp [customFormat]="'yyyy-MM-dd HH:mm'" [unixTime]="peg.blocktime"></app-timestamp>
            </td>
            <td class="amount text-end" [ngClass]="{'credit': peg.amount > 0, 'debit': peg.amount < 0, 'glow-effect': peg.amount < 0 && peg.bitcoinaddress && !peg.bitcointxid}">
              <app-amount [satoshis]="peg.amount" [noFiat]="true" [forceBtc]="true" [addPlus]="true"></app-amount>
            </td>
            <td class="output text-start">
              <ng-container *ngIf="peg.bitcointxid; else redeemInProgress">
                <a href="{{ env.MEMPOOL_WEBSITE_URL + '/tx/' + peg.bitcointxid + ':' + peg.bitcoinindex }}" target="_blank" style="color:var(--orange)">
                  <app-truncate [text]="peg.bitcointxid + ':' + peg.bitcoinindex" [lastChars]="6"></app-truncate>
                </a>
              </ng-container>
              <ng-template #redeemInProgress>
                <ng-container *ngIf="peg.bitcoinaddress; else noRedeem">
                  <i><span class="text-muted" i18n="liquid.redemption-in-progress">Peg out in progress...</span></i>
                </ng-container>
              </ng-template>
            </td>
            <td class="address text-start">
              <ng-container *ngIf="peg.bitcoinaddress; else noRedeem">
                <a href="{{ env.MEMPOOL_WEBSITE_URL + '/address/' + peg.bitcoinaddress }}" target="_blank" style="color:var(--orange)">
                  <app-truncate [text]="peg.bitcoinaddress" [lastChars]="6"></app-truncate>
                </a>
              </ng-container>
            </td>
          </tr>
        </ng-template>
      </tbody>
      <ng-template #skeleton>
        <tbody *ngIf="widget; else regularRowsSkeleton">
          <tr *ngFor="let item of skeletonLines">
            <td class="transaction text-start widget">
              <span class="skeleton-loader" style="max-width: 400px"></span>
            </td>
            <td class="timestamp text-start widget">
              <span class="skeleton-loader" style="max-width: 300px"></span>
            </td>
            <td class="amount text-end widget">
              <span class="skeleton-loader" style="max-width: 300px"></span>
            </td>
          </tr>
        </tbody>
        <ng-template #regularRowsSkeleton>
          <tr *ngFor="let item of skeletonLines">
            <td class="transaction text-start">
              <span class="skeleton-loader" style="max-width: 300px"></span>
            </td>
            <td class="timestamp text-start">
              <span class="skeleton-loader" style="max-width: 240px"></span>
            </td>
            <td class="amount text-end">
              <span class="skeleton-loader" style="max-width: 140px"></span>
            </td>
            <td class="output text-start">
              <span class="skeleton-loader" style="max-width: 300px"></span>
            </td>
            <td class="address text-start">
              <span class="skeleton-loader" style="max-width: 240px"></span>
            </td>
          </tr>
        </ng-template>
      </ng-template>
    </table>

    <ngb-pagination *ngIf="!widget && pegsCount$ | async as pegsCount" class="pagination-container float-end mt-2" [class]="isLoading || isPegCountLoading ? 'disabled' : ''"
      [collectionSize]="pegsCount" [rotate]="true" [maxSize]="maxSize" [pageSize]="15" [(page)]="page"
      (pageChange)="pageChange(page)" [boundaryLinks]="true" [ellipses]="false">
    </ngb-pagination>

    <ng-template [ngIf]="!widget">
      <div class="clearfix"></div>
      <br>
    </ng-template>
  </div>
  
</div>

<br>

<ng-template #noRedeem>
  <span class="text-muted">-</span>
</ng-template>