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

@section('content')
    <section class="lc-page-shell">
        <div class="surface p-6">
            <div class="section-heading">
                <div><span>Catalog</span><h1>{{ $product->exists ? 'تعديل منتج' : 'منتج جديد' }}</h1></div>
                <a class="secondary-button" href="{{ route('admin.products.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="{{ $product->exists ? route('admin.products.update', $product) : route('admin.products.store') }}" class="mt-6 grid gap-4 md:grid-cols-3">
                @csrf
                @if($product->exists)
                    @method('PATCH')
                @endif
                <label class="form-field md:col-span-2">
                    <span>اللعبة</span>
                    <select name="game_id" required>
                        @foreach($games as $game)
                            <option value="{{ $game->id }}" @selected(old('game_id', $product->game_id) == $game->id)>{{ $game->name_ar }}</option>
                        @endforeach
                    </select>
                </label>
                <label class="form-field"><span>SKU</span><input name="sku" value="{{ old('sku', $product->sku) }}" required></label>
                <label class="form-field"><span>الاسم العربي</span><input name="name_ar" value="{{ old('name_ar', $product->name_ar) }}" required></label>
                <label class="form-field"><span>الاسم الإنجليزي</span><input name="name_en" value="{{ old('name_en', $product->name_en) }}" required></label>
                <label class="form-field">
                    <span>طريقة التسليم</span>
                    <select name="delivery_method">
                        @foreach(['manual' => 'Manual', 'api' => 'API', 'stored_code' => 'Stored Code', 'hybrid' => 'Hybrid'] as $value => $label)
                            <option value="{{ $value }}" @selected(old('delivery_method', $product->delivery_method) === $value)>{{ $label }}</option>
                        @endforeach
                    </select>
                </label>
                <label class="form-field"><span>الكمية</span><input name="quantity" value="{{ old('quantity', $product->quantity) }}" type="number" min="1" required></label>
                <label class="form-field"><span>الوحدة عربي</span><input name="unit_ar" value="{{ old('unit_ar', $product->unit_ar) }}" required></label>
                <label class="form-field"><span>Unit EN</span><input name="unit_en" value="{{ old('unit_en', $product->unit_en) }}" required></label>
                <label class="form-field"><span>التكلفة Minor</span><input name="cost_minor" value="{{ old('cost_minor', $product->cost_minor ?? 0) }}" type="number" min="0" required></label>
                <label class="form-field"><span>السعر Minor</span><input name="price_minor" value="{{ old('price_minor', $product->price_minor) }}" type="number" min="0" required></label>
                <label class="form-field"><span>سعر العرض Minor</span><input name="sale_price_minor" value="{{ old('sale_price_minor', $product->sale_price_minor) }}" type="number" min="0"></label>
                <label class="form-field"><span>العملة</span><input name="currency_code" value="{{ old('currency_code', $product->currency_code ?? 'EGP') }}" maxlength="3" required></label>
                <label class="form-field"><span>Cashback BPS</span><input name="cashback_basis_points" value="{{ old('cashback_basis_points', $product->cashback_basis_points ?? 0) }}" type="number" min="0" max="10000" required></label>
                <label class="form-field"><span>نقاط الولاء</span><input name="loyalty_points" value="{{ old('loyalty_points', $product->loyalty_points ?? 0) }}" type="number" min="0" required></label>
                <label class="form-field"><span>المخزون</span><input name="stock_available" value="{{ old('stock_available', $product->stock_available) }}" type="number" min="0" required></label>
                <label class="form-field"><span>تنبيه المخزون</span><input name="min_stock_alert" value="{{ old('min_stock_alert', $product->min_stock_alert) }}" type="number" min="0" required></label>
                <label class="form-field">
                    <span>الحالة</span>
                    <select name="status">
                        <option value="active" @selected(old('status', $product->status) === 'active')>active</option>
                        <option value="inactive" @selected(old('status', $product->status) === 'inactive')>inactive</option>
                    </select>
                </label>
                <label class="form-field md:col-span-3"><span>تعليمات عربي</span><input name="instructions_ar" value="{{ old('instructions_ar', $product->instructions_ar) }}"></label>
                <label class="form-field md:col-span-3"><span>Instructions EN</span><input name="instructions_en" value="{{ old('instructions_en', $product->instructions_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', $product->is_featured))> مميز</label>
                <label class="flex items-center gap-2 font-bold text-[#17264d]"><input name="is_best_seller" type="checkbox" value="1" @checked(old('is_best_seller', $product->is_best_seller))> الأكثر مبيعًا</label>
                <button class="primary-button md:col-span-3" type="submit">حفظ</button>
            </form>
        </div>
    </section>
@endsection
