{namespace v=FluidTYPO3\Vhs\ViewHelpers}
{namespace ot=Opentalent\OtTemplating\ViewHelpers}

<f:comment><!-- Panneau d'authentification ou espace utilisateur --></f:comment>

<div class="user-toolbar">
    <f:security.ifAuthenticated>
        <f:then>
            <v:variable.set name="feuser" value="{ot:request.getFeUser()}"/>

            <div class="dropdown">
                <a href="#" class="user-toolbar-username">
                    <i class="fa fa-user"></i>
                    {feuser.username}
                    <i class="fa fa-caret-down"></i>
                </a>

                <ul class="dropdown-menu">
                    <li>
                        <a href="{ot:request.getOtEnvVar(argument: 'DASHBOARD_URL')}" target="_blank">
                            <!-- La valeur par défaut est rendue nécessaire par un bug
                            inexpliqué (cf. https://assistance.opentalent.fr/browse/REQ-153625) -->
                            <f:translate key="member-area-of-my-structure" default="Espace adhérent" />
                        </a>
                    </li>
                    <li>
                        <f:link.page additionalParams="{logintype:'logout'}">
                            <!-- cf. commentaire ci-dessus -->
                            <f:translate key="log-out" default="Se déconnecter" />
                        </f:link.page>
                    </li>
                </ul>
            </div>

        </f:then>
        <f:else>

            <f:if condition="{ot:request.isCustomDomain()}">
                <f:then>
                    <f:comment><!-- Because crossdomain auth could not be achieved properly until now,
                                    the login popup is shown for websites with custom domains --></f:comment>
                    <f:comment><!-- Popup de login --></f:comment>

                    <a href="#" id="login-btn">
                        <i class="fas fa-power-off"></i> Se connecter
                    </a>

                    <div id="login-popup" class="<f:if condition='{ot:loginFailed()}==1' then='show'></f:if>">
                        <form id="login_form" class="popup-form" action="" method="POST" enctype="multipart/form-data" >

                            <f:comment><!-- Just for typo3 to indentify it as a login request --></f:comment>
                            <input type="hidden" name="logintype" value="login" />

                            <input type="text"
                                   class="form-control {f:if(then: 'is-invalid', condition: '{usernameErrors}')}"
                                   placeholder="Nom d'utilisateur"
                                   name="user"
                                   required="1" />

                            <input type="password"
                                   class="form-control {f:if(then: 'is-invalid', condition: '{passwordErrors}')}"
                                   name="pass"
                                   placeholder="Mot de passe"
                                   required="1" />

                            <input type="submit" id="login-button" value="Se connecter" />

                            <f:if condition="{ot:loginFailed()}==1">
                                <f:then>
                                    <div class="login-errormsg alert">
                                        La tentative de connexion a échoué...<br/>
                                        Êtes-vous sûr d'avoir bien renseigné vos identifiants?
                                    </div>
                                </f:then>
                            </f:if>
                        </form>
                    </div>

                </f:then>
                <f:else>
                    <a href="{ot:request.getOtEnvVar(argument: 'LOGIN_PAGE_URL')}" target="_blank">
                        <i class="fas fa-power-off"></i> <f:translate key="login"/>
                    </a>
                </f:else>
            </f:if>

        </f:else>

    </f:security.ifAuthenticated>
</div>
