<table mat-table [dataSource]="courseCounts" class="mat-elevation-z8 full-width-table">

    <!--- Note that these columns can be defined in any order.
          The actual rendered columns are set as a property on the row definition" -->
  
    <!-- Name Column -->
    <ng-container matColumnDef="name">
        <th mat-header-cell *matHeaderCellDef> Jméno a příjmení </th>
        <td mat-cell *matCellDef="let element"> {{getNameById(element.instructorId)}} </td>
    </ng-container>

    <!-- Link Column -->
    <ng-container matColumnDef="link">
        <th mat-header-cell *matHeaderCellDef> Profil </th>
        <td mat-cell *matCellDef="let element"><a mat-flat-button routerLink="/{{profileLink}}/{{element.ID}}"><mat-icon color="primary">account_box</mat-icon></a></td>
      </ng-container>

    <!-- Role 1 Column -->
    <ng-container matColumnDef="role1">
        <th mat-header-cell *matHeaderCellDef> {{courseRoleNames[1]}} </th>
        <td mat-cell *matCellDef="let element">
            <span *ngIf="element.count1 > 0">
                <span *ngIf="isValidNumber(rate1) == true">
                    {{element.count1 * rate1}} Kč 
                    <span class="course-count" #tooltip="matTooltip" matTooltip="Počet absolvovaných kurzů v daném měsíci v roli '{{courseRoleNames[1]}}'">
                        ({{element.count1}} {{wordShape(element.count1, 'kurz')}})
                    </span>
                </span>
                <span *ngIf="isValidNumber(rate1) == false" matTooltip="Pro výpočet nebyly zadány platné hodnoty"> 
                    <mat-icon aria-hidden="false" aria-label="Example home icon">error_outline</mat-icon>
                </span>
            </span>
            <span *ngIf="element.count1 == 0" class="course-count" #tooltip="matTooltip" matTooltip="Instruktor se v daném měsíci nezúčastnil kurzů v roli '{{courseRoleNames[1]}}'">---</span>
        </td>
    </ng-container>

    <!-- Role 1 Column -->
    <ng-container matColumnDef="role2">
        <th mat-header-cell *matHeaderCellDef> {{courseRoleNames[2]}} </th>
        <td mat-cell *matCellDef="let element"> 
            <span *ngIf="element.count2 > 0">
                <span *ngIf="isValidNumber(rate2) == true">
                    {{element.count2 * rate2}} Kč 
                    <span class="course-count" #tooltip="matTooltip" matTooltip="Počet absolvovaných kurzů v daném měsíci v roli '{{courseRoleNames[2]}}'">
                        ({{element.count2}} {{wordShape(element.count2, 'kurz')}})
                    </span>
                </span>
                <span *ngIf="isValidNumber(rate2) == false" matTooltip="Pro výpočet nebyly zadány platné hodnoty"> 
                    <mat-icon aria-hidden="false" aria-label="Example home icon">error_outline</mat-icon>
                </span>
            </span>
            <span *ngIf="element.count2 == 0" class="course-count" #tooltip="matTooltip" matTooltip="Instruktor se v daném měsíci nezúčastnil kurzů v roli '{{courseRoleNames[2]}}'">---</span>
        </td>
    </ng-container>

    <!-- Role 3 Column -->
    <ng-container matColumnDef="role3">
        <th mat-header-cell *matHeaderCellDef> {{courseRoleNames[3]}} </th>
        <td mat-cell *matCellDef="let element">
            <span *ngIf="element.count3 > 0">
                <span *ngIf="isValidNumber(rate3) == true">
                    {{element.count3 * rate3}} Kč 
                    <span class="course-count" #tooltip="matTooltip" matTooltip="Počet absolvovaných kurzů v daném měsíci v roli '{{courseRoleNames[3]}}'">
                        ({{element.count3}} {{wordShape(element.count3, 'kurz')}})
                    </span>
                </span>
                <span *ngIf="isValidNumber(rate3) == false" matTooltip="Pro výpočet nebyly zadány platné hodnoty"> 
                    <mat-icon aria-hidden="false" aria-label="Example home icon">error_outline</mat-icon>
                </span>
            </span> 
            <span *ngIf="element.count3 == 0" class="course-count" #tooltip="matTooltip" matTooltip="Instruktor se v daném měsíci nezúčastnil kurzů v roli '{{courseRoleNames[3]}}'">---</span>
        </td>
    </ng-container>

    <!-- Bonus Column -->
    <ng-container matColumnDef="bonus">
        <th mat-header-cell *matHeaderCellDef> Bonus </th>
        <td mat-cell *matCellDef="let element">
            <form class="bonus-form solo-mid">
                <mat-form-field appearance="outline">
                    <input matInput numberValue [(ngModel)]="element.bonus" #bonus="ngModel"> 
                    <span matSuffix>Kč</span>
                </mat-form-field>
                <span *ngIf="bonus.invalid && bonus.touched" class="form-error">
                    <span *ngIf="bonus.errors != null && bonus.errors.numberValue" matTooltip="Nebylo zadáno platné číslo" class="form-error-message">
                        <!-- <mat-icon aria-hidden="false" aria-label="Example home icon">error_outline</mat-icon> -->
                        neplatná hodnota
                    </span>
                </span>
            </form>              
        </td>
    </ng-container>

    <!-- Sum Column -->
    <ng-container matColumnDef="sum">
        <th mat-header-cell *matHeaderCellDef> Celkem </th>
        <td mat-cell *matCellDef="let element"> 
            <span *ngIf="allInputsValid(element) == true"> 
                {{ (element.count1 * rate1) + (element.count2 * rate2) + (element.count3 * rate3) + numberValue(element.bonus) }} Kč 
            </span>
            <span *ngIf="allInputsValid(element) == false" matTooltip="Pro výpočet nebyly zadány platné hodnoty"> 
                <mat-icon aria-hidden="false" aria-label="Example home icon">error_outline</mat-icon>
            </span>
        </td>
    </ng-container>
  
    <!-- Footer -->
    <ng-container matColumnDef="footer">
        <td mat-footer-cell *matFooterCellDef colspan="4" class="table-item-counter">
            Celkem instruktorů: {{courseCounts.length}}
        </td>
    </ng-container>
  
    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
    <tr mat-footer-row *matFooterRowDef="['footer']" class="footer-row"></tr>
</table>

