<table class="gf-table w-100" mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="account">
    <th *matHeaderCellDef class="px-1" i18n mat-header-cell>Name</th>
    <td *matCellDef="let element" class="px-1" mat-cell>
      <gf-symbol-icon
        *ngIf="element.Platform?.url"
        class="d-inline d-sm-none mr-1"
        [tooltip]="element.Platform?.name"
        [url]="element.Platform?.url"
      ></gf-symbol-icon>
      <span>{{ element.name }} </span>
      <span
        *ngIf="element.isDefault"
        class="d-lg-inline-block d-none text-muted"
        >(Default)</span
      >
    </td>
    <td *matFooterCellDef class="px-1" mat-footer-cell i18n>Total</td>
  </ng-container>

  <ng-container matColumnDef="currency">
    <th
      *matHeaderCellDef
      class="d-none d-lg-table-cell px-1"
      i18n
      mat-header-cell
    >
      Currency
    </th>
    <td *matCellDef="let element" class="d-none d-lg-table-cell px-1" mat-cell>
      {{ element.currency }}
    </td>
    <td *matFooterCellDef class="d-none d-lg-table-cell px-1" mat-footer-cell>
      {{ baseCurrency }}
    </td>
  </ng-container>

  <ng-container matColumnDef="platform">
    <th
      *matHeaderCellDef
      class="d-none d-lg-table-cell px-1"
      i18n
      mat-header-cell
    >
      Platform
    </th>
    <td *matCellDef="let element" class="d-none d-lg-table-cell px-1" mat-cell>
      <div class="d-flex">
        <gf-symbol-icon
          *ngIf="element.Platform?.url"
          class="mr-1"
          [tooltip]="element.Platform?.name"
          [url]="element.Platform?.url"
        ></gf-symbol-icon>
        <span>{{ element.Platform?.name }}</span>
      </div>
    </td>
    <td
      *matFooterCellDef
      class="d-none d-lg-table-cell px-1"
      mat-footer-cell
    ></td>
  </ng-container>

  <ng-container matColumnDef="transactions">
    <th *matHeaderCellDef class="px-1 text-right" mat-header-cell>
      <span class="d-block d-sm-none">#</span>
      <span class="d-none d-sm-block" i18n>Transactions</span>
    </th>
    <td *matCellDef="let element" class="px-1 text-right" mat-cell>
      <ng-container *ngIf="element.accountType === 'SECURITIES'">{{
        element.transactionCount
      }}</ng-container>
    </td>
    <td *matFooterCellDef class="px-1 text-right" mat-footer-cell>
      {{ transactionCount }}
    </td>
  </ng-container>

  <ng-container matColumnDef="balance">
    <th
      *matHeaderCellDef
      class="d-none d-lg-table-cell px-1 text-right"
      i18n
      mat-header-cell
    >
      Cash Balance
    </th>
    <td
      *matCellDef="let element"
      class="d-none d-lg-table-cell px-1 text-right"
      mat-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="element.balance"
      ></gf-value>
    </td>
    <td
      *matFooterCellDef
      class="d-none d-lg-table-cell px-1 text-right"
      mat-footer-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="totalBalanceInBaseCurrency"
      ></gf-value>
    </td>
  </ng-container>

  <ng-container matColumnDef="value">
    <th
      *matHeaderCellDef
      class="d-none d-lg-table-cell px-1 text-right"
      i18n
      mat-header-cell
    >
      Value
    </th>
    <td
      *matCellDef="let element"
      class="d-none d-lg-table-cell px-1 text-right"
      mat-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="element.value"
      ></gf-value>
    </td>
    <td
      *matFooterCellDef
      class="d-none d-lg-table-cell px-1 text-right"
      mat-footer-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="totalValueInBaseCurrency"
      ></gf-value>
    </td>
  </ng-container>

  <ng-container matColumnDef="valueInBaseCurrency">
    <th
      *matHeaderCellDef
      class="d-lg-none d-xl-none px-1 text-right"
      i18n
      mat-header-cell
    >
      Value
    </th>
    <td
      *matCellDef="let element"
      class="d-lg-none d-xl-none px-1 text-right"
      mat-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="element.valueInBaseCurrency"
      ></gf-value>
    </td>
    <td
      *matFooterCellDef
      class="d-lg-none d-xl-none px-1 text-right"
      mat-footer-cell
    >
      <gf-value
        class="d-inline-block justify-content-end"
        [isCurrency]="true"
        [locale]="locale"
        [value]="totalValueInBaseCurrency"
      ></gf-value>
    </td>
  </ng-container>

  <ng-container matColumnDef="actions">
    <th *matHeaderCellDef class="px-1 text-center" i18n mat-header-cell></th>
    <td *matCellDef="let element" class="px-1 text-center" mat-cell>
      <button
        class="mx-1 no-min-width px-2"
        mat-button
        [matMenuTriggerFor]="accountMenu"
        (click)="$event.stopPropagation()"
      >
        <ion-icon name="ellipsis-vertical"></ion-icon>
      </button>
      <mat-menu #accountMenu="matMenu" xPosition="before">
        <button mat-menu-item (click)="onUpdateAccount(element)">
          <ion-icon class="mr-2" name="create-outline"></ion-icon>
          <span i18n>Edit</span>
        </button>
        <button
          mat-menu-item
          [disabled]="element.isDefault || element.transactionCount > 0"
          (click)="onDeleteAccount(element.id)"
        >
          <ion-icon class="mr-2" name="trash-outline"></ion-icon>
          <span i18n>Delete</span>
        </button>
      </mat-menu>
    </td>
    <td *matFooterCellDef class="px-1" mat-footer-cell></td>
  </ng-container>

  <tr *matHeaderRowDef="displayedColumns" mat-header-row></tr>
  <tr *matRowDef="let row; columns: displayedColumns" mat-row></tr>
  <tr
    *matFooterRowDef="displayedColumns"
    mat-footer-row
    [ngClass]="{ 'd-none': isLoading }"
  ></tr>
</table>

<ngx-skeleton-loader
  *ngIf="isLoading"
  animation="pulse"
  class="px-4 py-3"
  [theme]="{
    height: '1.5rem',
    width: '100%'
  }"
></ngx-skeleton-loader>