@extends('layouts.admin', ['title' => ($game->exists ? 'تعديل لعبة' : 'لعبة جديدة').' | RaseedNow'])

@section('content')
    <section class="lc-page-shell">
        <div class="surface p-6">
            <div class="section-heading">
                <div><span>Catalog</span><h1>{{ $game->exists ? 'تعديل لعبة' : 'لعبة جديدة' }}</h1></div>
                <a class="secondary-button" href="{{ route('admin.games.index') }}">الألعاب</a>
            </div>
            @if($errors->any())
                <div class="mt-4 rounded border border-red-200 bg-red-50 p-3 text-sm text-red-700">{{ $errors->first() }}</div>
            @endif
            <form method="POST" action="{{ $game->exists ? route('admin.games.update', $game) : route('admin.games.store') }}" enctype="multipart/form-data" class="mt-6 grid gap-4 md:grid-cols-2">
                @csrf
                @if($game->exists)
                    @method('PATCH')
                @endif
                <label class="form-field">
                    <span>الفئة</span>
                    <select name="category_id" required>
                        @foreach($categories as $category)
                            <option value="{{ $category->id }}" @selected(old('category_id', $game->category_id) == $category->id)>{{ $category->name_ar }}</option>
                        @endforeach
                    </select>
                </label>
                <label class="form-field"><span>المنصة</span><input name="platform" value="{{ old('platform', $game->platform ?? 'mobile') }}" required></label>
                <label class="form-field"><span>الاسم العربي</span><input name="name_ar" value="{{ old('name_ar', $game->name_ar) }}" required></label>
                <label class="form-field"><span>الاسم الإنجليزي</span><input name="name_en" value="{{ old('name_en', $game->name_en) }}" required></label>
                <label class="form-field"><span>Slug</span><input name="slug" value="{{ old('slug', $game->slug) }}"></label>
                <label class="form-field"><span>Publisher</span><input name="publisher" value="{{ old('publisher', $game->publisher) }}"></label>
                <label class="form-field"><span>لون الغلاف</span><input name="cover_color" value="{{ old('cover_color', $game->cover_color) }}" required></label>
                <label class="form-field">
                    <span>صورة الخدمة من الجهاز</span>
                    <input name="image" type="file" accept="image/*">
                </label>
                <label class="form-field">
                    <span>مسار صورة جاهزة اختياري</span>
                    <input name="image_path" value="{{ old('image_path', $game->image_path) }}" placeholder="images/services/tiktok.webp">
                </label>
                @if($game->image_path)
                    <div class="md:col-span-2 rounded-xl border border-[#dfe7e5] bg-white p-3">
                        <span class="mb-2 block text-sm font-bold text-[#475569]">الصورة الحالية</span>
                        <img src="{{ asset($game->image_path) }}" alt="{{ $game->name_ar }}" class="h-32 rounded-xl object-cover">
                    </div>
                @endif
                <label class="form-field md:col-span-2"><span>الوصف العربي</span><input name="description_ar" value="{{ old('description_ar', $game->description_ar) }}"></label>
                <label class="form-field md:col-span-2"><span>English Description</span><input name="description_en" value="{{ old('description_en', $game->description_en) }}"></label>
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_featured" type="checkbox" value="1" @checked(old('is_featured', $game->is_featured))> مميزة</label>
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_active" type="checkbox" value="1" @checked(old('is_active', $game->is_active))> نشطة</label>
                <button class="primary-button md:col-span-2" type="submit">حفظ</button>
            </form>
        </div>
    </section>
@endsection
