@extends('layouts.app')

@section('title', 'Cambiar Contraseña')

@section('content')
<div class="bg-body-light">
    <div class="content content-full">
        <div class="d-flex align-items-center gap-2 py-2">
            <a href="{{ route('perfil.index') }}" class="btn btn-sm btn-alt-secondary">
                <i class="fa fa-arrow-left"></i>
            </a>
            <div>
                <h1 class="h4 fw-bold mb-0">Cambiar Contraseña</h1>
                <p class="text-muted mb-0" style="font-size:13px">
                    Modifica la contraseña de tu cuenta — se requiere la contraseña actual.
                </p>
            </div>
        </div>
    </div>
</div>

<div class="content">
    <div class="row justify-content-center">
        <div class="col-md-5">

            <div class="block block-rounded">
                <div class="block-header block-header-default">
                    <h3 class="block-title">
                        <i class="fa fa-key me-1 text-warning"></i> Nueva Contraseña
                    </h3>
                </div>
                <div class="block-content">

                    @if($errors->any())
                    <div class="alert alert-danger alert-dismissible" role="alert">
                        @foreach($errors->all() as $e)
                            <div><i class="fa fa-exclamation-circle me-1"></i>{{ $e }}</div>
                        @endforeach
                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                    </div>
                    @endif

                    <form method="POST" action="{{ route('perfil.password.update') }}">
                        @csrf
                        @method('PUT')

                        <div class="mb-4">
                            <label class="form-label fw-semibold" for="pass_anterior">
                                Contraseña actual <span class="text-danger">*</span>
                            </label>
                            <input type="password" name="pass_anterior" id="pass_anterior"
                                class="form-control form-control-alt @error('pass_anterior') is-invalid @enderror"
                                placeholder="Tu contraseña actual" autocomplete="current-password" required>
                            @error('pass_anterior')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <hr class="my-3">

                        <div class="mb-4">
                            <label class="form-label fw-semibold" for="pass1">
                                Nueva contraseña <span class="text-danger">*</span>
                            </label>
                            <input type="password" name="pass1" id="pass1"
                                class="form-control form-control-alt @error('pass1') is-invalid @enderror"
                                placeholder="Mínimo 4 caracteres" autocomplete="new-password" required>
                            @error('pass1')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-4">
                            <label class="form-label fw-semibold" for="pass2">
                                Confirmar nueva contraseña <span class="text-danger">*</span>
                            </label>
                            <input type="password" name="pass2" id="pass2"
                                class="form-control form-control-alt @error('pass2') is-invalid @enderror"
                                placeholder="Repetir nueva contraseña" autocomplete="new-password" required>
                            @error('pass2')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary flex-grow-1"
                                onclick="return confirm('¿Confirmar cambio de contraseña?')">
                                <i class="fa fa-save me-1"></i> Guardar nueva contraseña
                            </button>
                            <a href="{{ route('perfil.index') }}" class="btn btn-alt-secondary">
                                Cancelar
                            </a>
                        </div>
                    </form>

                </div>
            </div>

            <div class="alert alert-info d-flex align-items-start gap-2 fs-sm mt-3" role="alert">
                <i class="fa fa-info-circle mt-1 flex-shrink-0"></i>
                <div>
                    La contraseña debe tener entre <strong>4 y 30 caracteres</strong>.
                    Después de cambiarla tendrás que usarla en tu próximo inicio de sesión.
                </div>
            </div>

        </div>
    </div>
</div>
@endsection