@extends('layouts.app')

<style>

    .panel-default{
        width: 100%;
    }

</style>
<?php $user= Auth::user() ?>
@section('content')

    <div class="container">
        <div class="row">
            <div class="col-sm-12" >
                <div class="panel panel-default" >
                    @if(isset($user_unit))
                        <div class="panel-heading" >
                            <h4 class="text-center text-info">Cambiar unidad de inicio</h4>
                        </div>
                    @else
                        <div class="panel-heading" >
                            <h4 class="text-center text-info">Panel de usuario</h4>
                        </div>
                    @endif

                    <div class="panel-body">

                        @if(session()->has('message'))
                            <div class="alert alert-success alert-dismissable">
                                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>

                                {{ session()->get('message') }}
                            </div>
                        @endif
                        @if (session()->has('error'))
                            <div class="alert alert-danger alert-dismissable">
                                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                                {{ session()->get('error') }}
                            </div>
                        @endif

                        @if(!isset($user_unit))
                            <h4 class="text-left text-muted font-weight-light">Ajustes:</h4>

                            <ul class="nav flex-column list-group">
                                <li class="nav-item list-group-item">
                                    <a class="nav-link active" href="{{ URL::to('/') }}/cambiarPass">Cambiar contraseña</a>
                                </li>
                                @if(!$user->isApplicant())
                                <li class="nav-item list-group-item">
                                    <a class="nav-link" href="{{ URL::to('/') }}/unit-init">Cambiar unidad de preferencia</a>
                                </li>
                                @endif

                            </ul>
                        @endif
                        @if(!$user->isApplicant())

                            @if(isset($user_unit))
                                <ul class="nav flex-column list-group">

                                    <li class="nav-item">
                                        <h5>Unidad inicio (default) :
                                           <i class="text-info"> {{$user_unit->name}}</i>
                                        </h5>
                                    </li>

                                    <hr>
                                    <li class="nav-item">
                                        <h5 class="text-left text-info">Cambiar unidad de inicio</h5>

                                        <form class="form-inline profile-form" role="form" method="POST" action="">
                                            {{ csrf_field() }}
                                            <div class="form-group mx-sm-3 mb-2" id="selectUnit" >
                                                <label for="inputPassword2" class="sr-only">Mis unidades</label>

                                                <select class="js-example-placeholder-single"  name="unit_id">

                                                    <option></option>
                                                    @foreach($allunits as $unt)
                                                        <option  value="{{$unt->unit->id}}">{{$unt->unit->name}}</option>
                                                    @endforeach

                                                </select>
                                            </div>
                                            <button type="submit" class="btn btn-secundary mb-2">seleccionar</button>

                                        </form>
                                    </li>

                                </ul>
                                <hr>
                                <ul class="nav flex-column ">
                                    <li class="nav-item ">
                                        <a class="nav-link active" href="{{ URL::to('/') }}/panelDeUsuario"><i>Regresar a panel de usuario</i></a>
                                    </li>
                                </ul>
                            @endif
                        @endif

                    </div>
                </div>
            </div>
        </div>

    </div>

@endsection

@section('scripts')
    @if(session()->has('message') )

        @if(session()->get('message') == 'Se cambió con éxito la contraseña')
            <script>
                $(document).ready(function(){
                    console.log('exito');

                    $('#logout-form').submit();

                })
            </script>
            @else
            <script>
                $(document).ready(function(){
                    console.log('fail');
                })
            </script>
        @endif


    @endif

    @if(isset($user_unit))
        <script>

            $(document).ready(function() {

                $('.js-example-placeholder-single').select2({
                    placeholder: 'Seleccione una unidad'
                });

            });
        </script>
    @endif
    @endsection



