<div class="ui simple dropdown item">
    {{$user->name}}
    <i class="dropdown icon"></i>
    <div class="menu">
        <a class="item" href="{{$urls->base}}/user/password/change">Cambiar Clave</a>
        @if ($user->isAdmin())
        <a class="item" href="{{$urls->base}}/admin">Administraci&oacute;n</a>
        @endif
        <div class="item" onclick="logout()">Salir</div>
    </div>
</div>

@push('page_scripts')
    <script type="text/javascript">
        function logout() {
            return fetch('{{$urls->base}}/logout').then(response => {
                if (response.ok) {
                    return response.json()
                }
            }).then(data => {
                if (data.logout === true) {
                    @if(isset($redirect_uri))
                        window.location = '{{$redirect_uri}}'
                    @else
                        window.location = '{{$urls->base}}'
                    @endif
                }
            })
        }
    </script>
@endpush
