<table mat-table matSort [dataSource]="profileFields" (matSortChange)="sortData($event)" matSortActive="index"
    matSortDirection="asc">

    <ng-container matColumnDef="name">
        <th mat-header-cell *matHeaderCellDef mat-sort-header="name"> {{'profileField.name' | i18n}} </th>
        <td mat-cell *matCellDef="let profileField"> {{'profileField.name.' + profileField.name | i18n}} </td>
    </ng-container>

    <ng-container matColumnDef="value">
        <th mat-header-cell *matHeaderCellDef mat-sort-header="value"> {{'profileField.value' | i18n}} </th>
        <td mat-cell *matCellDef="let profileField">
            <div [ngSwitch]="profileField.type">
                <span *ngSwitchCase="'TEXT'">{{profileField.value}}</span>
                <span *ngSwitchCase="'DATE'">{{profileField.value | date:datetimeformat}}</span>
                <a *ngSwitchCase="'URL'" href="{{profileField.value}}">{{profileField.value}}</a>
                <a *ngSwitchCase="'EMAIL'" href="mailto:{{profileField.value}}">{{profileField.value}}</a>
                <span *ngSwitchCase="'NUMBER'">{{profileField.value}}</span>
                <button *ngSwitchCase="'BLOB'" mat-raised-button
                    (click)="openBlob(profileField)">{{'profileField.openBlob' | i18n}}</button>
            </div>
        </td>
    </ng-container>

    <ng-container matColumnDef="visibility" *ngIf="edit">
        <th mat-header-cell *matHeaderCellDef mat-sort-header="visibility"> {{'profileField.visibility' | i18n}} </th>
        <td mat-cell *matCellDef="let profileField"> {{'profileField.visibility.' + profileField.visibility | i18n}}
        </td>
    </ng-container>

    <ng-container matColumnDef="edit" *ngIf="edit">
        <th mat-header-cell *matHeaderCellDef> {{'profileField.edit' | i18n}} </th>
        <td mat-cell *matCellDef="let profileField">
            <a mat-icon-button>
                <mat-icon (click)="openEdit(profileField)">edit</mat-icon>
            </a>
        </td>
    </ng-container>

    <ng-container matColumnDef="delete" *ngIf="edit">
        <th mat-header-cell *matHeaderCellDef> {{'profileField.delete' | i18n}} </th>
        <td mat-cell *matCellDef="let profileField">
            <a mat-icon-button>
                <mat-icon (click)="confirmDelete(profileField)">delete</mat-icon>
            </a>
        </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="profileFieldColumns"></tr>
    <tr mat-row *matRowDef="let myRowData; columns: profileFieldColumns"></tr>
</table>
<br>
<div *ngIf="edit" class="text-center">
    <button mat-raised-button color="primary" (click)="openCreate()">{{'profileField.create' |
        i18n}}</button>
</div>