@extends('layouts.admin')
@section('title', 'Edit User')
@section('content')
<div class="page-header">
    <div>
        <p style="margin:0 0 0.35rem"><a href="{{ route('admin.users.show', $user) }}" style="color:var(--md-on-surface-variant);text-decoration:none">&larr; Back to user</a></p>
        <h1 style="margin:0">Edit User</h1>
        <p style="margin:0.35rem 0 0;color:var(--md-on-surface-variant)">{{ $user->email }}</p>
    </div>
</div>

<div class="md-card" style="max-width:640px">
    <div class="md-card-header">User Information</div>
    <div class="md-card-body">
        <form method="POST" action="{{ route('admin.users.update', $user) }}">
            @csrf
            @method('PUT')
            <div class="form-field">
                <label>Name</label>
                <input type="text" name="name" class="md-input" value="{{ old('name', $user->name) }}" required>
            </div>
            <div class="form-field">
                <label>Username</label>
                <input type="text" name="username" class="md-input" value="{{ old('username', $user->username) }}" required>
            </div>
            <div class="form-field">
                <label>Email</label>
                <input type="email" name="email" class="md-input" value="{{ old('email', $user->email) }}" required>
            </div>
            <div class="form-field">
                <label>Password <span style="font-weight:400;color:var(--md-on-surface-variant)">(leave blank to keep)</span></label>
                <input type="password" name="password" class="md-input">
            </div>
            <div class="form-field">
                <label>Confirm Password</label>
                <input type="password" name="password_confirmation" class="md-input">
            </div>
            <div class="form-grid">
                <div class="form-field">
                    <label>Balance ($)</label>
                    <input type="number" step="0.01" name="balance" class="md-input" value="{{ old('balance', $user->balance) }}" min="0">
                </div>
                <div class="form-field">
                    <label>Status</label>
                    <select name="status" class="md-select">
                        <option value="active" @selected(old('status', $user->status) === 'active')>Active</option>
                        <option value="suspended" @selected(old('status', $user->status) === 'suspended')>Deactivated</option>
                    </select>
                </div>
            </div>
            <div class="action-group" style="margin-top:1.25rem">
                <button type="submit" class="md-btn md-btn-filled">Update User</button>
                <a href="{{ route('admin.users.show', $user) }}" class="md-btn md-btn-tonal">Cancel</a>
            </div>
        </form>
    </div>
</div>
@endsection
