<!--
  ~ Copyright (c) 2023 D2ArmorPicker by Mijago.
  ~
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU Affero General Public License as published
  ~ by the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU Affero General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Affero General Public License
  ~ along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->

<div>
  <div class="tooltip-container">
    <table>
      <tr>
        <td class="exotic-name" colspan="3">{{ ArmorStatNames[stat] }} at Tier {{ tier }}</td>
      </tr>
      <tr>
        <th style="min-width: 50px">Stat</th>
        <th style="min-width: 50px">Tier {{ tier }}</th>
        <th style="min-width: 50px" colspan="2" *ngIf="differenceTier !== tier"
          >∆ Tier {{ differenceTier }}</th
        >
      </tr>

      <ng-container *ngFor="let entry of entries">
        <tr
          *ngIf="
            entry.description === null ||
            entry.description === undefined ||
            !!entry.description[characterClass]
          ">
          <ng-container *ngVar="valueFunction(entry, tier) as currentTierValue">
            <td>
              <img src="https://www.bungie.net/{{ entry.icon }}" *ngIf="entry.icon" />
              {{ entry.name }}
            </td>
            <td>{{ formatEntry(entry, currentTierValue) }}</td>
            <ng-container *ngVar="valueFunction(entry, differenceTier) as selectedTierValue">
              <ng-container
                *ngVar="
                  getPercentageDifference(currentTierValue, selectedTierValue) as tierDifference
                ">
                <td *ngIf="differenceTier !== tier">
                  <span
                    [class.good]="differenceTier < tier"
                    [class.bad]="differenceTier > tier"
                    *ngVar="-(selectedTierValue - currentTierValue) as dif">
                    {{ dif > 0 ? "+" : "" }}{{ formatEntry(entry, dif) }}
                  </span>
                </td>
                <td *ngIf="differenceTier !== tier">
                  <span [class.good]="differenceTier < tier" [class.bad]="differenceTier > tier">
                    ({{ tierDifference > 0 ? "+" : ""
                    }}{{ tierDifference * 100 | number : "1.0-0" }}%)
                  </span>
                </td>
              </ng-container>
            </ng-container>
            <td>
              <ng-container *ngFor="let itemHash of entry.overrideIcons">
                <app-item-icon [itemHash]="itemHash"> </app-item-icon>
              </ng-container>

              {{ entry.description }}
            </td>
          </ng-container>
        </tr>
      </ng-container>
    </table>
  </div>
</div>
