<div [class]="widget === false ? 'container-xl' : ''">

  <div *ngIf="widget">
    <div class="pool-distribution" *ngIf="(miningStatsObservable$ | async) as miningStats; else loadingReward">
      <div class="item">
        <h5 class="card-title" i18n="mining.miners-luck">Pools luck (1w)</h5>
        <p class="card-text">
          {{ miningStats['minersLuck'] }}%
        </p>
      </div>
      <div class="item">
        <h5 class="card-title" i18n="master-page.blocks">Blocks (1w)</h5>
        <p class="card-text">
          {{ miningStats.blockCount }}
        </p>
      </div>
      <div class="item">
        <h5 class="card-title" i18n="mining.miners-count">Pools count (1w)</h5>
        <p class="card-text">
          {{ miningStats.pools.length }}
        </p>
      </div>
    </div>
  </div>

  <div [class]="widget ? 'chart-widget' : 'chart'"
    echarts [initOpts]="chartInitOptions" [options]="chartOptions" (chartInit)="onChartInit($event)"></div>
  <div class="text-center loadingGraphs" *ngIf="isLoading">
    <div class="spinner-border text-light"></div>
  </div>

  <div class="card-header mb-0 mb-lg-4 mt-md-3" [style]="widget ? 'display:none' : ''">
    <form [formGroup]="radioGroupForm" class="formRadioGroup" *ngIf="(miningStatsObservable$ | async) as miningStats">
      <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" formControlName="dateSpan">
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 1">
          <input ngbButton type="radio" [value]="'24h'" fragment="24h"> 24h
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 3">
          <input ngbButton type="radio" [value]="'3d'" fragment="3d"> 3D
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 7">
          <input ngbButton type="radio" [value]="'1w'" fragment="1w"> 1W
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 30">
          <input ngbButton type="radio" [value]="'1m'" fragment="1m"> 1M
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 90">
          <input ngbButton type="radio" [value]="'3m'" fragment="3m"> 3M
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 180">
          <input ngbButton type="radio" [value]="'6m'" fragment="6m"> 6M
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 365">
          <input ngbButton type="radio" [value]="'1y'" fragment="1y"> 1Y
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 730">
          <input ngbButton type="radio" [value]="'2y'" fragment="2y"> 2Y
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm" *ngIf="miningStats.availableTimespanDay >= 1095">
          <input ngbButton type="radio" [value]="'3y'" fragment="3y"> 3Y
        </label>
        <label ngbButtonLabel class="btn-primary btn-sm">
          <input ngbButton type="radio" [value]="'all'" fragment="all"> ALL
        </label>
      </div>
    </form>
  </div>

  <table *ngIf="widget === false" class="table table-borderless text-center pools-table">
    <thead>
      <tr>
        <th class="d-none d-md-block" i18n="mining.rank">Rank</th>
        <th class=""></th>
        <th class="" i18n="mining.pool-name">Pool</th>
        <th class="" *ngIf="this.poolsWindowPreference === '24h'" i18n="mining.hashrate">Hashrate</th>
        <th class="" i18n="master-page.blocks">Blocks</th>
        <th class="d-none d-md-block" i18n="mining.empty-blocks">Empty Blocks</th>
      </tr>
    </thead>
    <tbody *ngIf="(miningStatsObservable$ | async) as miningStats">
      <tr *ngFor="let pool of miningStats.pools">
        <td class="d-none d-md-block">{{ pool.rank }}</td>
        <td class="text-right"><img width="25" height="25" src="{{ pool.logo }}" onError="this.src = './resources/mining-pools/default.svg'"></td>
        <td class=""><a [routerLink]="[('/mining/pool/' + pool.poolId) | relativeUrl]">{{ pool.name }}</a></td>
        <td class="" *ngIf="this.poolsWindowPreference === '24h' && !isLoading">{{ pool.lastEstimatedHashrate }} {{ miningStats.miningUnits.hashrateUnit }}</td>
        <td class="">{{ pool['blockText'] }}</td>
        <td class="d-none d-md-block">{{ pool.emptyBlocks }} ({{ pool.emptyBlockRatio }}%)</td>
      </tr>
      <tr style="border-top: 1px solid #555">
        <td class="d-none d-md-block"></td>
        <td class="text-right"></td>
        <td class="" i18n="mining.all-miners"><b>All miners</b></td>
        <td class="" *ngIf="this.poolsWindowPreference === '24h'"><b>{{ miningStats.lastEstimatedHashrate}} {{ miningStats.miningUnits.hashrateUnit }}</b></td>
        <td class=""><b>{{ miningStats.blockCount }}</b></td>
        <td class="d-none d-md-block"><b>{{ miningStats.totalEmptyBlock }} ({{ miningStats.totalEmptyBlockRatio }}%)</b></td>
      </tr>
    </tbody>
  </table>

</div>


<ng-template #loadingReward>
  <div class="pool-distribution">
    <div class="item">
      <h5 class="card-title" i18n="mining.miners-luck">Pools luck (1w)</h5>
      <p class="card-text">
        <span class="skeleton-loader skeleton-loader-big"></span>
      </p>
    </div>
    <div class="item">
      <h5 class="card-title" i18n="master-page.blocks">Blocks (1w)</h5>
      <p class="card-text">
        <span class="skeleton-loader skeleton-loader-big"></span>
      </p>
    </div>
    <div class="item">
      <h5 class="card-title" i18n="mining.miners-count">Pools count (1w)</h5>
      <p class="card-text">
        <span class="skeleton-loader skeleton-loader-big"></span>
      </p>
    </div>
  </div>
</ng-template>