@extends('layouts.dashboard')
@section('title', 'Edit User')
@section('page-title', 'Edit User')
@section('content')
<div class="content-card" style="max-width:760px;">
    <form method="POST" action="{{ route('admin.users.update', $user) }}">
        @csrf @method('PUT')

        <div class="row">
            <div class="col-md-6 mb-3">
                <label class="form-label">Name</label>
                <input type="text" name="name" class="form-control" value="{{ old('name', $user->name) }}" required>
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label">Username</label>
                <input type="text" name="username" class="form-control" value="{{ old('username', $user->username) }}" required>
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label">Email</label>
                <input type="email" name="email" class="form-control" value="{{ old('email', $user->email) }}" required>
            </div>
            <div class="col-md-6 mb-3">
                <label class="form-label">Reset Password (optional)</label>
                <input type="password" name="password" class="form-control" placeholder="leave blank to keep current">
            </div>
            <div class="col-md-4 mb-3">
                <label class="form-label">Role</label>
                <select name="role" class="form-select">
                    <option value="user" {{ $user->role == 'user' ? 'selected' : '' }}>User</option>
                    <option value="reseller" {{ $user->role == 'reseller' ? 'selected' : '' }}>Reseller</option>
                    <option value="superadmin" {{ $user->role == 'superadmin' ? 'selected' : '' }}>Super Admin</option>
                </select>
            </div>
            <div class="col-md-4 mb-3">
                <label class="form-label">Status</label>
                <select name="status" class="form-select">
                    <option value="active" {{ $user->status == 'active' ? 'selected' : '' }}>Active</option>
                    <option value="inactive" {{ $user->status == 'inactive' ? 'selected' : '' }}>Inactive</option>
                    <option value="suspended" {{ $user->status == 'suspended' ? 'selected' : '' }}>Suspended</option>
                </select>
            </div>
            <div class="col-md-4 mb-3">
                <label class="form-label">Blogs Quota (resellers)</label>
                <input type="number" min="0" name="blogs_quota" class="form-control" value="{{ old('blogs_quota', $user->blogs_quota) }}">
                <small class="text-muted">Used: {{ $user->blogs_used }}</small>
            </div>
        </div>

        <div class="d-flex gap-2">
            <button class="btn btn-primary">Update User</button>
            <a href="{{ route('admin.users.index') }}" class="btn btn-outline-secondary">Cancel</a>
            @if($user->id !== auth()->id())
            <form action="{{ route('admin.users.destroy', $user) }}" method="POST" class="ms-auto" onsubmit="return confirm('Delete this user permanently?')">
                @csrf @method('DELETE')
                <button class="btn btn-outline-danger">Delete User</button>
            </form>
            @endif
        </div>
    </form>
</div>
@endsection
