@extends('layouts.admin')

@section('title', 'Edit User')

@section('admin-content')
<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="d-flex align-items-center mb-4">
            <a href="{{ route('admin.users') }}" class="btn btn-light shadow-sm me-3 border rounded-3">
                <i class="bi bi-arrow-left"></i>
            </a>
            <h4 class="fw-bold mb-0">Edit User Details</h4>
        </div>

        <div class="card border-0 shadow-sm rounded-4">
            <div class="card-body p-4">
                <form action="{{ route('admin.users.update', $user->id) }}" method="POST">
                    @csrf
                    @method('PUT')
                    
                    <div class="row g-4 mb-4">
                        <div class="col-12">
                            <label class="form-label fw-bold small text-muted">Full Name <span class="text-danger">*</span></label>
                            <input type="text" name="name" class="form-control form-control-lg rounded-3" value="{{ old('name', $user->name) }}" required>
                        </div>
                        <div class="col-12">
                            <label class="form-label fw-bold small text-muted">Email Address <span class="text-danger">*</span></label>
                            <input type="email" name="email" class="form-control form-control-lg rounded-3" value="{{ old('email', $user->email) }}" required>
                        </div>
                        <div class="col-12">
                            <label class="form-label fw-bold small text-muted">Password <small>(Leave blank to keep current)</small></label>
                            <input type="password" name="password" class="form-control form-control-lg rounded-3" placeholder="New Password" minlength="8">
                        </div>
                    </div>

                    <div class="row g-4 mb-4">
                        <div class="col-md-6">
                            <label class="form-label fw-bold small text-muted">Role <span class="text-danger">*</span></label>
                            <select name="role" class="form-select form-select-lg rounded-3" required>
                                @foreach($roles as $role)
                                    <option value="{{ $role->name }}" {{ $user->hasRole($role->name) ? 'selected' : '' }}>
                                        {{ ucfirst($role->name) }}
                                    </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label fw-bold small text-muted">Status</label>
                            <select name="is_active" class="form-select form-select-lg rounded-3">
                                <option value="1" {{ $user->is_active ? 'selected' : '' }}>Active</option>
                                <option value="0" {{ !$user->is_active ? 'selected' : '' }}>Banned</option>
                            </select>
                        </div>
                    </div>

                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary btn-lg rounded-3 fw-bold">
                            Update User
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
