<div fxLayout="column" *ngIf="selNode?.userPersona === userPersonaEnum.OPERATOR; else merchantDashboard">
  <div fxLayout="row" fxLayoutAlign="start start" class="page-title-container mb-0">
    <fa-icon [icon]="apiCallStatusNodeInfo.status === apiCallStatusEnum.ERROR ? faFrown : faSmile" class="page-title-img mr-1"></fa-icon>
    <span class="page-title">{{apiCallStatusNodeInfo.status === apiCallStatusEnum.COMPLETED ? 'Welcome ' + information.alias + '! Your node is up and running.' : apiCallStatusNodeInfo.status === apiCallStatusEnum.INITIATED ? 'Wait! Getting your node information...' : 'Error! Please check the server connection.'}}</span>
  </div>
  <mat-grid-list cols="10" [rowHeight]="operatorCardHeight">
    <mat-grid-tile *ngFor="let card of operatorCards" [colspan]="card.cols" [rowspan]="card.rows">
      <mat-card fxFlex="100" fxLayout="column" fxLayoutAlign="start stretch" class="h-100 dashboard-card mt-4">
        <mat-card-header>
          <mat-card-title fxLayoutAlign="space-between center">
            <div>
              <fa-icon [icon]="card.icon" class="mr-1"></fa-icon>
              <span>{{card.title}}</span>
            </div>
            <div>
              <button *ngIf="card.links[0]" mat-icon-button class="more-button" [matMenuTriggerFor]="menuOperator"
                aria-label="Toggle menu">
                <mat-icon>more_vert</mat-icon>
              </button>
              <mat-menu #menuOperator="matMenu" class="dashboard-vert-menu" xPosition="before">
                <button mat-menu-item *ngFor="let goToOption of card.goToOptions; index as i" (click)="onNavigateTo(card.links[i])">{{goToOption}}</button>
                <button *ngIf="card.id === 'capacity'" (click)="onsortChannelsBy()" mat-menu-item>Sort By
                  {{sortField === 'Balance Score' ? 'Capacity' : 'Balance Score'}}</button>
              </mat-menu>
            </div>
          </mat-card-title>
        </mat-card-header>
        <mat-card-content fxLayout="column" fxFlex="{{card.id === 'capacity' ? 90 : 70}}"
          [ngClass]="{'dashboard-card-content': true, 
          'error-border': (card.id === 'node' && apiCallStatusNodeInfo.status === apiCallStatusEnum.ERROR) ||
                          (card.id === 'balance' && (apiCallStatusAllChannels.status === apiCallStatusEnum.ERROR || apiCallStatusOCBal.status === apiCallStatusEnum.ERROR)) ||
                          ((card.id === 'capacity' || card.id === 'status') && apiCallStatusAllChannels.status === apiCallStatusEnum.ERROR) ||
                          (card.id === 'fee' && apiCallStatusFees.status === apiCallStatusEnum.ERROR)}">
          <mat-progress-bar mode="indeterminate"
            *ngIf="(card.id === 'node' && apiCallStatusNodeInfo.status === apiCallStatusEnum.INITIATED) ||
            (card.id === 'balance' && (apiCallStatusAllChannels.status === apiCallStatusEnum.INITIATED || apiCallStatusOCBal.status === apiCallStatusEnum.INITIATED)) ||
            ((card.id === 'capacity' || card.id === 'status') && apiCallStatusAllChannels.status === apiCallStatusEnum.INITIATED) ||
            (card.id === 'fee' && apiCallStatusFees.status === apiCallStatusEnum.INITIATED)"
          ></mat-progress-bar>
          <div [ngSwitch]="card.id" fxLayout="column" fxFlex="100">
            <rtl-ecl-node-info fxFlex="100" *ngSwitchCase="'node'" [information]="information" [showColorFieldSeparately]="false"></rtl-ecl-node-info>
            <rtl-ecl-balances-info fxFlex="100" *ngSwitchCase="'balance'" [balances]="balances" [errorMessage]="errorMessages[2] + ' ' + errorMessages[3]"></rtl-ecl-balances-info>
            <rtl-ecl-channel-capacity-info fxFlex="100" *ngSwitchCase="'capacity'" [sortBy]="sortField" [channelBalances]="channelBalances" [allChannels]="allChannelsCapacity" [errorMessage]="errorMessages[2]"></rtl-ecl-channel-capacity-info>
            <rtl-ecl-fee-info fxFlex="100" *ngSwitchCase="'fee'" [fees]="fees" [errorMessage]="errorMessages[1]"></rtl-ecl-fee-info>
            <rtl-ecl-channel-status-info fxFlex="100" *ngSwitchCase="'status'" [channelsStatus]="channelsStatus" [errorMessage]="errorMessages[2]"></rtl-ecl-channel-status-info>
            <h3 *ngSwitchDefault>Error! Unable to find information!</h3>
          </div>
        </mat-card-content>
      </mat-card>
    </mat-grid-tile>
  </mat-grid-list>
</div>
<ng-template #merchantDashboard>
  <div fxLayout="row" fxLayoutAlign="start end" class="page-title-container mb-0">
    <fa-icon [icon]="faSmile" class="page-title-img mr-1"></fa-icon>
    <span class="page-title">Welcome {{information.alias}}! Your node is up and running.</span>
  </div>
  <mat-grid-list cols="6" [rowHeight]="merchantCardHeight">
    <mat-grid-tile *ngFor="let card of merchantCards" [colspan]="card.cols" [rowspan]="card.rows">
      <mat-card fxFlex="100" fxLayout="column" fxLayoutAlign="start stretch" class="h-100 dashboard-card mt-4" [ngClass]="{'p-0': card.id === 'transactions'}">
        <mat-card-header *ngIf="card.id !== 'transactions'">
          <mat-card-title fxLayoutAlign="space-between center">
            <div>
              <fa-icon [icon]="card.icon" class="mr-1"></fa-icon>
              <span>{{card.title}}</span>
            </div>
            <div>
              <button *ngIf="card.links[0]" mat-icon-button class="more-button" [matMenuTriggerFor]="menuMerchant"
                aria-label="Toggle menu">
                <mat-icon>more_vert</mat-icon>
              </button>
              <mat-menu #menuMerchant="matMenu" class="dashboard-vert-menu" xPosition="before">
                <button mat-menu-item *ngFor="let goToOption of card.goToOptions; index as i" (click)="onNavigateTo(card.links[i])">{{goToOption}}</button>
              </mat-menu>
            </div>
          </mat-card-title>
        </mat-card-header>
        <mat-card-content fxLayout="column" fxLayoutAlign="start stretch" fxFlex="{{card.id === 'transactions' ? 100 : card.id === 'balance' ? 70: 90}}"
          [ngClass]="{'dashboard-card-content': true, 
          'error-border': (card.id === 'node' && apiCallStatusNodeInfo.status === apiCallStatusEnum.ERROR) ||
                          (card.id === 'balance' && (apiCallStatusAllChannels.status === apiCallStatusEnum.ERROR || apiCallStatusOCBal.status === apiCallStatusEnum.ERROR)) ||
                          ((card.id === 'inboundLiq' || card.id === 'outboundLiq') && apiCallStatusAllChannels.status === apiCallStatusEnum.ERROR)}">
          <mat-progress-bar mode="indeterminate"
            *ngIf="(card.id === 'node' && apiCallStatusNodeInfo.status === apiCallStatusEnum.INITIATED) ||
            (card.id === 'balance' && (apiCallStatusAllChannels.status === apiCallStatusEnum.INITIATED || apiCallStatusOCBal.status === apiCallStatusEnum.INITIATED)) ||
            ((card.id === 'inboundLiq' || card.id === 'outboundLiq') && apiCallStatusAllChannels.status === apiCallStatusEnum.INITIATED)"
          ></mat-progress-bar>
          <div [ngSwitch]="card.id" fxLayout="column" fxFlex="100">
            <rtl-ecl-node-info fxFlex="100" *ngSwitchCase="'node'" [information]="information"></rtl-ecl-node-info>
            <rtl-ecl-balances-info fxFlex="100" *ngSwitchCase="'balance'" [balances]="balances" [errorMessage]="errorMessages[2] + ' ' + errorMessages[3]"></rtl-ecl-balances-info>
            <rtl-ecl-channel-liquidity-info fxFlex="100" *ngSwitchCase="'inboundLiq'" [direction]="'In'" [totalLiquidity]="totalInboundLiquidity" [allChannels]="allInboundChannels" [errorMessage]="errorMessages[2]"></rtl-ecl-channel-liquidity-info>
            <rtl-ecl-channel-liquidity-info fxFlex="100" *ngSwitchCase="'outboundLiq'" [direction]="'Out'" [totalLiquidity]="totalOutboundLiquidity" [allChannels]="allOutboundChannels" [errorMessage]="errorMessages[2]"></rtl-ecl-channel-liquidity-info>
            <span fxLayout="column" fxFlex="100" fxLayoutAlign="space-between start" *ngSwitchCase="'transactions'">
              <mat-tab-group fxLayout="column" class="w-100 dashboard-tabs-group">
                <mat-tab label="Receive">
                  <rtl-ecl-lightning-invoices class="h-100" [calledFrom]="'home'"></rtl-ecl-lightning-invoices>
                </mat-tab>
                <mat-tab label="Pay">
                  <rtl-ecl-lightning-payments [calledFrom]="'home'"></rtl-ecl-lightning-payments>
                </mat-tab>
                <mat-tab [disabled]="true">
                  <ng-template mat-tab-label>
                    <button mat-icon-button class="more-button" [matMenuTriggerFor]="menuTransactions" aria-label="Toggle menu">
                      <mat-icon>more_vert</mat-icon>
                    </button>
                    <mat-menu #menuTransactions="matMenu" class="dashboard-vert-menu" xPosition="before">
                      <button mat-menu-item *ngFor="let goToOption of card.goToOptions; index as i" (click)="onNavigateTo(card.links[i])">{{goToOption}}</button>
                    </mat-menu>
                  </ng-template>
                </mat-tab>
              </mat-tab-group>
            </span>
            <h3 *ngSwitchDefault>Error! Unable to find information!</h3>
          </div>
        </mat-card-content>
      </mat-card>
    </mat-grid-tile>
  </mat-grid-list>
</ng-template>
