<div fxLayout="column" fxLayout.gt-sm="row" fxLayoutAlign.gt-sm="space-between stretch">
  <div fxFlex="35" class="modal-qr-code-container padding-gap-large" [fxLayoutAlign]="invoice?.payment_request && invoice?.payment_request !== '' ? 'center start' : 'center center'" [ngClass]="{'display-none': screenSize === screenSizeEnum.XS || screenSize === screenSizeEnum.SM}">
    <qr-code *ngIf="invoice?.payment_request && invoice?.payment_request !== ''" [value]="invoice?.payment_request" [size]="qrWidth" [errorCorrectionLevel]="'L'" />
    <span *ngIf="!invoice?.payment_request || invoice?.payment_request === ''" class="font-size-300">N/A</span>
  </div>
  <div fxLayout="column" fxFlex="65">
    <mat-card-header fxLayout="row" fxLayoutAlign="space-between center" class="modal-info-header">
      <div fxFlex="95" fxLayoutAlign="start start">
        <fa-icon class="page-title-img mr-1" [icon]="faReceipt" />
        <span class="page-title">{{screenSize === screenSizeEnum.XS ?  (newlyAdded ? 'Created' : 'Invoice') : (newlyAdded ? 'Invoice Created' : 'Invoice Information')}}</span>
      </div>
      <button tabindex="3" fxFlex="5" fxLayoutAlign="center center" class="btn-close-x p-0" mat-button (click)="onClose()">X</button>
    </mat-card-header>
    <mat-card-content class="padding-gap-x-large" [ngClass]="{'xs-scroll-y': screenSize === screenSizeEnum.XS}">
      <div fxLayout="column">
        <div fxFlex="30" class="modal-qr-code-container padding-gap" [fxLayoutAlign]="invoice?.payment_request && invoice?.payment_request !== '' ? 'center start' : 'center center'" [ngClass]="{'display-none': screenSize !== screenSizeEnum.XS && screenSize !== screenSizeEnum.SM}">
          <qr-code *ngIf="invoice?.payment_request && invoice?.payment_request !== ''" [value]="invoice?.payment_request" [size]="qrWidth" [errorCorrectionLevel]="'L'" />
          <span *ngIf="!invoice?.payment_request || invoice?.payment_request === ''" class="font-size-120">QR Code Not Applicable</span>
        </div>
        <mat-divider *ngIf="screenSize === screenSizeEnum.XS || screenSize === screenSizeEnum.SM" class="my-1" [inset]="true" />
        <div #scrollContainer [ngClass]="{'h-50': invoice?.htlcs && invoice?.htlcs.length > 0 && showAdvanced}">
          <div fxLayout="row">
            <div fxFlex="50">
              <h4 fxLayoutAlign="start" class="font-bold-500">{{screenSize === screenSizeEnum.XS ? 'Amount' : 'Amount Requested'}}</h4>
              <span class="foreground-secondary-text">{{(invoice?.value || 0) | number}} Sats<ng-container *ngIf="!invoice?.value || invoice?.value === '0'"> (zero amount) </ng-container></span>
            </div>
            <div fxFlex="50">
              <h4 fxLayoutAlign="start" class="font-bold-500">Amount Settled</h4>
              <span class="foreground-secondary-text">
                <ng-container *ngIf="invoice?.amt_paid_sat && invoice?.state !== 'OPEN'">
                  <div *ngIf="flgInvoicePaid" class="invoice-animation-container">
                    <div class="invoice-animation-div">
                      <span class="wiggle">{{invoice?.amt_paid_sat | number}} Sats</span>
                      <span *ngFor="let i of [].constructor(35)" class="particles-circle"></span>
                    </div>
                  </div>
                  <div *ngIf="!flgInvoicePaid">{{invoice?.amt_paid_sat | number}} Sats</div>
                </ng-container>
                <ng-container *ngIf="(!invoice?.amt_paid_sat || invoice?.amt_paid_sat === '0')">
                  <span *ngIf="invoice?.state !== 'OPEN' || !flgVersionCompatible">-</span>
                  <mat-spinner *ngIf="invoice?.state === 'OPEN' && flgVersionCompatible" [diameter]="20" />
                </ng-container>
              </span>
            </div>
          </div>
          <mat-divider class="my-1" [inset]="true" />
          <div fxLayout="row">
            <div fxFlex="50">
              <h4 fxLayoutAlign="start" class="font-bold-500">Date Created</h4>
              <span class="foreground-secondary-text">{{invoice?.creation_date * 1000 | date:'dd/MMM/y HH:mm'}}</span>
            </div>
            <div fxFlex="50">
              <h4 fxLayoutAlign="start" class="font-bold-500">Date Settled</h4>
              <span class="foreground-secondary-text">{{(+invoice?.settle_date !== 0 ? ((+invoice?.settle_date * 1000) | date:'dd/MMM/y HH:mm') : '-')}}</span>
            </div>
          </div>
          <mat-divider class="my-1" [inset]="true" />
          <div fxLayout="row">
            <div fxFlex="100">
              <h4 fxLayoutAlign="start" class="font-bold-500">Memo</h4>
              <span class="foreground-secondary-text">{{invoice?.memo}}</span>
            </div>
          </div>
          <mat-divider class="my-1" [inset]="true" />
          <div fxLayout="row">
            <div fxFlex="100">
              <h4 fxLayoutAlign="start" class="font-bold-500">Payment Request</h4>
              <span class="overflow-wrap foreground-secondary-text">{{invoice?.payment_request || 'N/A'}}</span>
            </div>
          </div>
          <mat-divider class="my-1" [inset]="true" />
          <div fxLayout="row">
            <div fxFlex="100">
              <h4 fxLayoutAlign="start" class="font-bold-500">Payment Hash</h4>
              <span class="overflow-wrap foreground-secondary-text">{{invoice?.r_hash || ''}}</span>
            </div>
          </div>
          <div *ngIf="showAdvanced">
            <ng-container *ngTemplateOutlet="advancedBlock" />
          </div>
        </div>
      </div>
    </mat-card-content>
    <div *ngIf="invoice?.htlcs && invoice?.htlcs.length > 0 && showAdvanced && flgOpened" fxLayout="row" fxLayoutAlign="start end" class="btn-sticky-container padding-gap-x-large">
      <button mat-mini-fab aria-label="Scroll Down" fxLayoutAlign="center center" (click)="onScrollDown()">
        <mat-icon fxLayoutAlign="center center">arrow_downward</mat-icon>
      </button>
    </div>
    <div class="padding-gap-x-large padding-gap-bottom-large" fxLayout="row" fxLayoutAlign="end center" fxFlex="100">
      <button mat-button color="primary" type="reset" tabindex="1" class="mr-1" (click)="onShowAdvanced()">
        <p *ngIf="!showAdvanced; else hideAdvancedText">Show Advanced</p>
        <ng-template #hideAdvancedText><p>Hide Advanced</p></ng-template>
      </button>
      <button *ngIf="invoice?.payment_request && invoice?.payment_request !== ''" autoFocus mat-button color="primary" tabindex="2" type="submit" rtlClipboard [payload]="invoice?.payment_request" (copied)="onCopyPayment($event)">{{screenSize === screenSizeEnum.XS ? 'Copy Payment' : 'Copy Payment Request'}}</button>
      <button *ngIf="!invoice?.payment_request || invoice?.payment_request === ''" autoFocus mat-button color="primary" tabindex="2" type="button" (click)="onClose()">OK</button>
    </div>
  </div>
</div>
<ng-template #advancedBlock>
  <mat-divider class="my-1" [inset]="true" />
  <div fxLayout="row">
    <div fxFlex="100">
      <h4 fxLayoutAlign="start" class="font-bold-500">Preimage</h4>
      <span class="overflow-wrap foreground-secondary-text">{{invoice?.r_preimage || '-'}}</span>
    </div>
  </div>
  <mat-divider class="my-1" [inset]="true" />
  <div fxLayout="row">
    <div fxFlex="50">
      <h4 fxLayoutAlign="start" class="font-bold-500">State</h4>
      <span class="overflow-wrap foreground-secondary-text">{{invoice?.state}}</span>
    </div>
    <div fxFlex="50">
      <h4 fxLayoutAlign="start" class="font-bold-500">Expiry</h4>
      <span class="overflow-wrap foreground-secondary-text">{{(+invoice?.creation_date + +invoice?.expiry) * 1000 | date:'dd/MMM/y HH:mm'}}</span>
    </div>
  </div>
  <mat-divider class="my-1" [inset]="true" />
  <div fxLayout="row">
    <div fxFlex="50">
      <h4 fxLayoutAlign="start" class="font-bold-500">Private Routing Hints</h4>
      <span class="overflow-wrap foreground-secondary-text">{{invoice?.private ? 'Yes' : 'No'}}</span>
    </div>
    <div fxFlex="50">
      <h4 fxLayoutAlign="start" class="font-bold-500">AMP Invoice</h4>
      <span class="overflow-wrap foreground-secondary-text">{{invoice?.is_amp ? 'Yes' : 'No'}}</span>
    </div>
  </div>  
  <mat-divider class="my-1" [inset]="true" />
  <div *ngIf="invoice?.htlcs && invoice?.htlcs.length > 0" fxLayout="row">
    <mat-expansion-panel class="flat-expansion-panel" fxLayout="column" fxLayoutAlign="start stretch" fxFlex="100" (opened)="flgOpened = true" (closed)="onExpansionClosed()">
      <mat-expansion-panel-header>
        <mat-panel-title>
          <h4 fxLayoutAlign="start center" fxFlex="100" class="font-bold-500">HTLCs</h4>
        </mat-panel-title>
      </mat-expansion-panel-header>
      <div fxLayout="column" fxLayoutAlign="start stretch" fxFlex="100">
        <div fxLayout="row" fxLayoutAlign="start start" fxFlex="100" class="mt-minus-1">
          <span fxFlex="60" class="foreground-secondary-text font-bold-500">Channel ID</span>
          <span fxFlex="40" class="foreground-secondary-text font-bold-500">Amount (Sats)</span>
        </div>
        <mat-divider class="my-1" [inset]="true" />
        <div *ngFor="let htlc of invoice?.htlcs" fxLayout="column" fxLayoutAlign="start stretch" fxFlex="100">
          <div fxLayout="row" fxLayoutAlign="start start" fxFlex="100">
            <span fxFlex="60" class="foreground-secondary-text">
              <span *ngIf="htlc.state === 'SETTLED'" class="dot green" matTooltip="Settled" matTooltipPosition="right" [ngClass]="{'mr-0': screenSize === screenSizeEnum.XS}"></span>
              <span *ngIf="htlc.state === 'ACCEPTED'" class="dot yellow" matTooltip="Accepted" matTooltipPosition="right" [ngClass]="{'mr-0': screenSize === screenSizeEnum.XS}"></span>
              <span *ngIf="htlc.state === 'CANCELED'" class="dot red" matTooltip="Cancelled" matTooltipPosition="right" [ngClass]="{'mr-0': screenSize === screenSizeEnum.XS}"></span>
              {{htlc.chan_id}}
            </span>
            <span fxFlex="40" class="foreground-secondary-text">{{((+htlc.amt_msat/1000) || 0) | number:getDecimalFormat(htlc)}}</span>
          </div>
          <mat-divider class="my-1" [inset]="true" />
        </div>
      </div>
    </mat-expansion-panel>
  </div>
  <mat-divider *ngIf="invoice?.htlcs && invoice?.htlcs.length > 0" class="my-1" [inset]="true" />
</ng-template>