@extends('layouts.app')

@section('content')

    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="text-center text-info">Cambiar contraseña</h4></div>

                    <div class="panel-body">
                        @if (session('status'))
                            <div class="alert alert-success">
                                {{ session('status') }}
                            </div>
                        @endif

                        @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 ($errors->any())
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif

                        <form class="form-horizontal" role="form" method="POST" action="{{ URL::to('/') }}/cambiarPass">
                            {{ csrf_field() }}
                            <div class="form-group row">
                                <label for="staticEmail" class="col-sm-12 col-form-label">Usuario</label>
                                <div class="col-sm-10">
                                    <input type="text" readonly class="form-control-plaintext" id="staticEmail" name="user" value="{{$user->name}}">
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                                <label for="staticEmail" class="col-sm-12 col-form-label">Correo</label>
                                <div class="col-sm-10">
                                    <input type="email" readonly class="form-control-plaintext" id="staticEmail" name="email" value="{{ $user->email }}" autofocus>

                                </div>
                            </div>

                            <div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}row">
                                <label for="inputPassword" class="col-sm-12 col-form-label">Contraseña actual</label>
                                <div class="col-sm-12">
                                    <input id="password-confirm" type="password" class="form-control" name="password"  placeholder="Ingrese contraseña actual">
                                    @if ($errors->has('password'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                                <label for="inputPassword" class="col-sm-12 col-form-label">Nueva Contraseña</label>
                                <div class="col-sm-12">
                                    <input id="password" type="password" class="form-control" name="password_confirmation"  placeholder="Ingrese nueva contraseña">

                                    @if ($errors->has('password_confirmation'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('password_confirmation') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                                <label for="inputPassword" class="col-sm-12 col-form-label">Confirmar contraseña</label>
                                <div class="col-sm-12">
                                    <input id="password-confirm" type="password" class="form-control" name="password_confirmation2" placeholder="Confirme nueva contraseña">

                                    @if ($errors->has('password_confirmation'))
                                        <span class="help-block">
                                        <strong>{{ $errors->first('password_confirmation') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-10">
                                    <button type="submit" class="btn btn-primary">
                                        cambiar contraseña
                                    </button>
                                </div>
                            </div>
                        </form>
                            <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>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <form id="logout-form" action="http://guntref.dev/logout" method="POST" style="display: none;"></form>
@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
@endsection
