<div class="piece" [ngStyle]="{'width': pieceWidth+'px'}" (mouseover)="displayMenu='show'" (mouseleave)="displayMenu='hide'; displaySymbolChoice='hide'" (click)="onClickPiece()"
    [style.background]="task.supplementaryRole ?
    'linear-gradient(140deg, var(--piece-background-color) 0%, var(--piece-background-color) 55%,'+task.supplementaryRole.color+' 55%,'+task.supplementaryRole.color+' 100%)'
    : 'var(--piece-background-color)'"
    [class]="pieceDetailsService.piece == task ? 'isActive' : 'border'">
    <div class="piece-attach piece-attach-left"></div>
    <div class="piece-attach piece-attach-right" [style.background]="task.supplementaryRole ? task.supplementaryRole.color : 'var(--piece-background-color)'"></div>

    <div class="piece-menu" [class]="displayMenu">
        <mat-icon fontIcon="backspace" (click)="onClickErase()"
        [matTooltip]="translate.instant('clearPiece_tooltip')"
        matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
        <mat-icon fontIcon="delete" (click)="onClickDelete()"
        [matTooltip]="translate.instant('deletePiece_tooltip')"
        matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
        <div class="piece-menu-directioncross">
            <div class="piece-menu-directioncross-left">
                <mat-icon style="transform: rotate(0turn) scale(0.6);" fontIcon="arrow_back_ios" (click)="moveTask('left'); editMoveTrace($event,'Task_moveLeft')"
                [matTooltip]="translate.instant('moveLeft_tooltip')"
                matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>                
            </div>
            <div class="piece-menu-directioncross-updownarrows">
                <div class="piece-menu-updownarrows-up">
                    <mat-icon style="transform: rotate(0.25turn) scale(0.6);" fontIcon="arrow_back_ios" (click)="moveTask('top'); editMoveTrace($event,'Task_moveTop')"
                    [matTooltip]="translate.instant('moveTop_tooltip')"
                    matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>                
                </div>
                <div class="piece-menu-directioncross-updownarrows-down">
                    <mat-icon style="transform: rotate(0.75turn) scale(0.6);" fontIcon="arrow_back_ios" (click)="moveTask('bottom'); editMoveTrace($event,'Task_moveBottom')"
                    [matTooltip]="translate.instant('moveBottom_tooltip')"
                    matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
                </div>
            </div>
            <div class="piece-menu-directioncross-right">
                <mat-icon style="transform: rotate(0.5turn) scale(0.6);" fontIcon="arrow_back_ios" (click)="moveTask('right'); editMoveTrace($event,'Task_moveRight')"
                [matTooltip]="translate.instant('moveRight_tooltip')"
                matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></mat-icon>
            </div>
        </div>
    </div>

    <div class="piece-symbolchoice" [class]="displaySymbolChoice">
        <div class="piece-symbolchoice-header">
            <label>{{'task_common_label' | translate}}</label>
            <div><mat-icon fontIcon="delete" (click)="setSymbol('','')"></mat-icon></div>
        </div>
        <div class="piece-symbolchoice-symbols">
            <mat-icon [style.color]="'#d79297'" fontIcon="favorite" (click)="canUseSymbol('favorite','#d79297') == 'enable' ? setSymbol('favorite','#d79297') : ''" [ngClass]="canUseSymbol('favorite','#d79297')"></mat-icon>
            <mat-icon [style.color]="'#9ad5ec'" fontIcon="diamond" (click)="canUseSymbol('diamond','#9ad5ec') == 'enable' ? setSymbol('diamond','#9ad5ec') : ''" [ngClass]="canUseSymbol('diamond','#9ad5ec')"></mat-icon>
            <mat-icon [style.color]="'#e9ec54'" fontIcon="star" (click)="canUseSymbol('star','#e9ec54') == 'enable' ? setSymbol('star','#e9ec54') : ''" [ngClass]="canUseSymbol('star','#e9ec54')"></mat-icon>
            <mat-icon [style.color]="'#f5cee3'" fontIcon="hexagon" (click)="canUseSymbol('hexagon','#f5cee3') == 'enable' ? setSymbol('hexagon','#f5cee3') : ''" [ngClass]="canUseSymbol('hexagon','#f5cee3')"></mat-icon>
            <mat-icon [style.color]="'#d3d2d2'" fontIcon="add" (click)="canUseSymbol('add','#d3d2d2') == 'enable' ? setSymbol('add','#d3d2d2') : ''" [ngClass]="canUseSymbol('add','#d3d2d2')"></mat-icon>
            <mat-icon [style.color]="'#9ad5ec'" fontIcon="circle" (click)="canUseSymbol('circle','#9ad5ec') == 'enable' ? setSymbol('circle','#9ad5ec') : ''" [ngClass]="canUseSymbol('circle','#9ad5ec')"></mat-icon>
            <mat-icon [style.color]="'#b6cc87'" fontIcon="eco" (click)="canUseSymbol('eco','#b6cc87') == 'enable' ? setSymbol('eco','#b6cc87') : ''" [ngClass]="canUseSymbol('eco','#b6cc87')"></mat-icon>
            <mat-icon [style.color]="'#d0bbdb'" fontIcon="play_arrow" (click)="canUseSymbol('play_arrow','#d0bbdb') == 'enable' ? setSymbol('play_arrow','#d0bbdb') : ''" [ngClass]="canUseSymbol('play_arrow','#d0bbdb')"></mat-icon>
            <mat-icon [style.color]="'#8b7e64'" fontIcon="remove" (click)="canUseSymbol('remove','#8b7e64') == 'enable' ? setSymbol('remove','#8b7e64') : ''" [ngClass]="canUseSymbol('remove','#8b7e64')"></mat-icon>
        </div>
        <div class="piece-symbolchoice-symbols">
            <mat-icon [style.color]="'#d79297'" fontIcon="square" (click)="canUseSymbol('square','#d79297') == 'enable' ? setSymbol('square','#d79297') : ''" [ngClass]="canUseSymbol('square','#d79297')"></mat-icon>
            <mat-icon [style.color]="'#9ad5ec'" fontIcon="square" (click)="canUseSymbol('square','#9ad5ec') == 'enable' ? setSymbol('square','#9ad5ec') : ''" [ngClass]="canUseSymbol('square','#9ad5ec')"></mat-icon>
            <mat-icon [style.color]="'#e9ec54'" fontIcon="square" (click)="canUseSymbol('square','#e9ec54') == 'enable' ? setSymbol('square','#e9ec54') : ''" [ngClass]="canUseSymbol('square','#e9ec54')"></mat-icon>
            <mat-icon [style.color]="'#f5cee3'" fontIcon="square" (click)="canUseSymbol('square','#f5cee3') == 'enable' ? setSymbol('square','#f5cee3') : ''" [ngClass]="canUseSymbol('square','#f5cee3')"></mat-icon>
            <mat-icon [style.color]="'#d3d2d2'" fontIcon="square" (click)="canUseSymbol('square','#d3d2d2') == 'enable' ? setSymbol('square','#d3d2d2') : ''" [ngClass]="canUseSymbol('square','#d3d2d2')"></mat-icon>
            <mat-icon [style.color]="'#9ad5ec'" fontIcon="square" (click)="canUseSymbol('square','#9ad5ec') == 'enable' ? setSymbol('square','#9ad5ec') : ''" [ngClass]="canUseSymbol('square','#9ad5ec')"></mat-icon>
            <mat-icon [style.color]="'#b6cc87'" fontIcon="square" (click)="canUseSymbol('square','#b6cc87') == 'enable' ? setSymbol('square','#b6cc87') : ''" [ngClass]="canUseSymbol('square','#b6cc87')"></mat-icon>
            <mat-icon [style.color]="'#d0bbdb'" fontIcon="square" (click)="canUseSymbol('square','#d0bbdb') == 'enable' ? setSymbol('square','#d0bbdb') : ''" [ngClass]="canUseSymbol('square','#d0bbdb')"></mat-icon>
            <mat-icon [style.color]="'#8b7e64'" fontIcon="square" (click)="canUseSymbol('square','#8b7e64') == 'enable' ? setSymbol('square','#8b7e64') : ''" [ngClass]="canUseSymbol('square','#8b7e64')"></mat-icon>
        </div>
    </div>

    <div class="piece-prerequires" [class]="pieceDetailsService.piece == task ? displayPrequires : 'hide'">
        <div class="piece-prerequires-prerequires">
            <label class="piece-prerequires-title">{{'task_prerequire_antecedents_title' | translate}}</label>
            <div class="piece-prerequires-form">
                <ng-container *ngIf="hasPossibleAntecedents()">
                    <ng-container *ngFor="let inlineTask of role.tasks">
                        <ng-container *ngFor="let element of inlineTask; let index = index">
                            <div class="piece-prerequires-prerequires-element" *ngIf="element?.identifier && (task.identifier != element?.identifier) && element?.type != 'annexe'">
                                <input name="antecedent" type="checkbox" [checked]="isCheckedTask(element)" (change)="checkboxChangedTask($event, element)"/>
                                <label for="antecedent">{{element?.identifier}}</label>
                            </div>
                        </ng-container>
                    </ng-container>
                </ng-container>
                <div style="text-align: center;" *ngIf="!hasPossibleAntecedents()">{{'task_prerequire_antecedents_err2' | translate}}</div>
            </div>
        </div>
        <div class="piece-prerequires-ressources">
            <label class="piece-prerequires-title">{{'task_prerequire_ressource_title' | translate}}</label>
            <div class="piece-prerequires-form">
                <ng-container *ngFor="let ressource of scenario.ressources">
                    <div class="piece-prerequires-ressources-element" *ngIf="ressource.name">
                        <div class="piece-prerequires-ressources-element-checkbox">
                            <input name="ressource" type="checkbox" (change)="checkboxChangedRessource($event, ressource)" [checked]="isCheckedRessource(ressource)"/>
                            <label for="ressource">{{ressource.name}}</label>   
                        </div>
                        <div class="piece-prerequires-ressources-element-quantity" *ngIf="isCheckedRessource(ressource)">
                            <select name="ressource" [(ngModel)]="getAssociatePrerequireRessource(ressource).operator">
                                <option><</option>
                                <option><=</option>
                                <option>=</option>
                                <option>>=</option>
                                <option>></option>
                            </select>
                            <input type="text" value="1" [(ngModel)]="getAssociatePrerequireRessource(ressource).quantity"/> 
                        </div>
                    </div>
                </ng-container>
                <ng-container *ngFor="let ressource of role.ressources">
                    <div class="piece-prerequires-ressources-element" *ngIf="ressource.name">
                        <div class="piece-prerequires-ressources-element-checkbox">
                            <input name="ressource" type="checkbox" (change)="checkboxChangedRessource($event, ressource)" [checked]="isCheckedRessource(ressource)"/>
                            <label for="ressource">{{ressource.name}}</label>   
                        </div>
                        <div class="piece-prerequires-ressources-element-quantity" *ngIf="isCheckedRessource(ressource)">
                            <select name="ressource" [(ngModel)]="getAssociatePrerequireRessource(ressource).operator">
                                <option><</option>
                                <option><=</option>
                                <option>=</option>
                                <option>>=</option>
                                <option>></option>
                            </select>
                            <input type="text" value="1" [(ngModel)]="getAssociatePrerequireRessource(ressource).quantity"/> 
                        </div>
                    </div>
                </ng-container>
            </div>
        </div>
    </div>

    <div class="piece-form">
        <div class="piece-form-top">
            <input class="piece-form-top-identifier" name="identifier" type="text" [(ngModel)]="task.identifier" (change)="changeIdentifier($event)" placeholder="A" min="1" maxlength="5"
            [matTooltip]="translate.instant('task_identifier_tooltip')"
            matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"/>
            <div class="piece-form-top-title">{{'randomEvent_title1' | translate}}<br>{{'randomEvent_title2' | translate}}</div>
            <mat-icon class="piece-form-top-comment" fontIcon="comment" *ngIf="task.comments.length > 0"></mat-icon>
            <mat-icon class="piece-form-top-repeat" fontIcon="refresh" *ngIf="task.repeat.iteration > 0 || task.repeat.while != ''"></mat-icon>
            <button mat-button class="piece-form-top-symbol" (click)="changeDisplaySymbolChoice()"
            [matTooltip]="translate.instant('task_common_tooltip')"
            matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips">
                <mat-icon *ngIf="task.symbol.symbol" [style.color]="task.symbol.color" [fontIcon]="task.symbol.symbol"></mat-icon>
            </button>    
        </div>
        <textarea class="piece-form-content" [(ngModel)]="task.objective" (change)="editTrace($event,'Task_action')" [style.background-image]="(i == findFirstIndexOfTaskType('event')[0] && j == findFirstIndexOfTaskType('event')[1]) ? urlIcon : ''"
            [placeholder]="translate.instant('randomEvent_action_placeholder')"
            [matTooltip]="translate.instant('task_action_tooltip')"
            matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips"></textarea>
        <div class="piece-form-bottom">
            <div class="piece-form-bottom-duration"
            [matTooltip]="translate.instant('task_duration_tooltip')"
            matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips">
                <input name="value" type="number" [(ngModel)]="task.duration" (input)="durationChange()" min="1" (change)="task.duration < 1 ? task.duration = 1 : ''; editTrace($event,'Task_duration')"/>
                <select name="unite" [(ngModel)]="task.durationUnit" (change)="durationChange(); editTrace($event,'Task_duration_unit')">
                    <option value="UT">{{'task_duration_ut' | translate}}</option>
                    <option value="min">{{'task_duration_min' | translate}}</option>
                    <option value="tours">{{'task_duration_turn' | translate}}</option> 
                </select>
            </div>
            <mat-icon class="piece-form-bottom-character" fontIcon="person" *ngIf="task.characters.length > 0"
            [style.color]="task.characters.length == 1 ? task.characters[0].color : 'black'"
            [style.background]="task.characters.length > 1 ? 'linear-gradient('+ task.characters[0].color +','+ task.characters[task.characters.length-1].color +')' : 'white'"></mat-icon>
            <mat-icon class="piece-form-bottom-interrupt" fontIcon="front_hand" *ngIf="task.interrupt != ''"></mat-icon>
            <button mat-button class="piece-form-bottom-prerequires" (click)="changeDisplayPrerequires()"
            [matTooltip]="translate.instant('task_prerequire_tooltip')"
            matTooltipPosition="above" [matTooltipDisabled]="!tooltipService.activatedTooltips">
                {{'task_prerequire_label' | translate}}
            </button>
        </div>
    </div>
</div>
