<ng-container *transloco="let t; prefix: 'statsUser.completionRace'">
<div class="completion-race-container">
  <div class="chart-header">
    <div class="chart-title">
      <h3>
        <i class="pi pi-flag completion-race-icon"></i>
        {{ t('title') }}
        <i class="pi pi-question-circle chart-info-icon"
           [pTooltip]="t('tooltip')"
           tooltipPosition="bottom"
           tooltipStyleClass="chart-info-tooltip"
           [appendTo]="'body'"></i>
      </h3>
      <p class="chart-description">{{ t('description') }}</p>
    </div>
    <div class="year-selector">
      <button type="button"
              class="year-nav-btn"
              (click)="changeYear(-1)"
              [title]="t('previousYear')">
        <i class="pi pi-chevron-left"></i>
      </button>
      <span class="current-year">{{ currentYear }}</span>
      <button type="button"
              class="year-nav-btn"
              (click)="changeYear(1)"
              [title]="t('nextYear')">
        <i class="pi pi-chevron-right"></i>
      </button>
    </div>
  </div>

  @if (totalBooks > 0) {
    <div class="stats-row">
      <div class="stat-card">
        <span class="stat-value">{{ totalBooks }}</span>
        <span class="stat-label">{{ t('books') }}</span>
      </div>
      <div class="stat-card">
        <span class="stat-value">{{ totalSessions }}</span>
        <span class="stat-label">{{ t('sessions') }}</span>
      </div>
      <div class="stat-card">
        <span class="stat-value">{{ avgDaysToFinish }}d</span>
        <span class="stat-label">{{ t('avgDays') }}</span>
      </div>
      <div class="stat-card">
        <span class="stat-value">{{ medianDaysToFinish }}d</span>
        <span class="stat-label">{{ t('medianDays') }}</span>
      </div>
      <div class="stat-card fastest">
        <span class="stat-value">{{ fastestDays }}</span>
        <span class="stat-subtitle">{{ fastestTitle }}</span>
        <span class="stat-label">{{ t('fastest') }}</span>
      </div>
      <div class="stat-card slowest">
        <span class="stat-value">{{ slowestDays }}</span>
        <span class="stat-subtitle">{{ slowestTitle }}</span>
        <span class="stat-label">{{ t('slowest') }}</span>
      </div>
    </div>
  }

  <div class="chart-wrapper">
    <canvas baseChart
            [data]="(chartData$ | async) ?? {datasets: []}"
            [options]="chartOptions"
            [type]="chartType">
    </canvas>
  </div>

  @if (totalBooks === 0) {
    <div class="no-data-message">
      <i class="pi pi-info-circle"></i>
      <p>{{ t('noData', { year: currentYear }) }}</p>
      <small>{{ t('noDataHint') }}</small>
    </div>
  }
</div>
</ng-container>
