<form action="{{ $action }}" method="POST" class="row g-3">
    @csrf
    @if($method !== 'POST')
        @method($method)
    @endif

    <div class="col-md-6">
        <label class="form-label">Name</label>
        <input type="text" name="name" value="{{ old('name', $game->name) }}" class="form-control @error('name') is-invalid @enderror" required>
        @error('name')<div class="invalid-feedback">{{ $message }}</div>@enderror
    </div>

    <div class="col-md-6">
        <label class="form-label">Slug</label>
        <input type="text" name="slug" value="{{ old('slug', $game->slug) }}" class="form-control @error('slug') is-invalid @enderror" required>
        @error('slug')<div class="invalid-feedback">{{ $message }}</div>@enderror
    </div>

    <div class="col-md-4">
        <label class="form-label">Short Name</label>
        <input type="text" name="short_name" value="{{ old('short_name', $game->short_name) }}" class="form-control">
    </div>

    <div class="col-md-4">
        <label class="form-label">Publisher</label>
        <input type="text" name="publisher" value="{{ old('publisher', $game->publisher) }}" class="form-control">
    </div>

    <div class="col-md-4">
        <label class="form-label">Sort Order</label>
        <input type="number" name="sort_order" value="{{ old('sort_order', $game->sort_order) }}" class="form-control" min="0">
    </div>

    <div class="col-md-6">
        <label class="form-label">Game Type</label>
        <select name="game_type" class="form-select">
            @foreach(\App\Enums\GameType::cases() as $type)
                <option value="{{ $type->value }}" @selected(old('game_type', $game->game_type?->value) === $type->value)>{{ $type->label() }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-md-6">
        <label class="form-label">Status</label>
        <select name="status" class="form-select">
            @foreach(\App\Enums\GameStatus::cases() as $status)
                <option value="{{ $status->value }}" @selected(old('status', $game->status?->value) === $status->value)>{{ $status->label() }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-12">
        <label class="form-label">Description</label>
        <textarea name="description" rows="4" class="form-control">{{ old('description', $game->description) }}</textarea>
    </div>

    <div class="col-md-6">
        <label class="form-label">Logo Path</label>
        <input type="text" name="logo_path" value="{{ old('logo_path', $game->logo_path) }}" class="form-control">
    </div>

    <div class="col-md-6">
        <label class="form-label">Cover Path</label>
        <input type="text" name="cover_path" value="{{ old('cover_path', $game->cover_path) }}" class="form-control">
    </div>

    <div class="col-12 d-flex flex-wrap gap-3">
        @foreach(['supports_ranks' => 'Ranks', 'supports_roles' => 'Roles', 'supports_characters' => 'Characters', 'supports_regions' => 'Regions', 'supports_servers' => 'Servers'] as $field => $label)
            <div class="form-check">
                <input class="form-check-input" type="checkbox" name="{{ $field }}" value="1" id="{{ $field }}" @checked(old($field, $game->{$field}))>
                <label class="form-check-label" for="{{ $field }}">{{ $label }}</label>
            </div>
        @endforeach
    </div>

    <div class="col-12">
        <button type="submit" class="btn btn-primary">Save</button>
        <a href="{{ route('admin.games.index') }}" class="btn btn-outline-secondary">Cancel</a>
    </div>
</form>
