@extends('layouts.store', ['title' => 'Checkout السلة | RaseedNow'])

@section('content')
    <section class="lc-page-shell">
        <div class="lc-checkout-layout">
            <form method="POST" action="{{ route('cart.place-order') }}" class="surface lc-form-card">
                @csrf
                <span class="eyebrow dark">Cart Checkout</span>
                <h1>إكمال طلب السلة</h1>
                @if($errors->any())
                    <div class="mt-5 rounded border border-red-200 bg-red-50 p-4 text-sm text-red-700">{{ $errors->first() }}</div>
                @endif
                <div class="mt-6 grid gap-4 md:grid-cols-2">
                    <label class="form-field">
                        <span>الاسم</span>
                        <input name="customer_name" value="{{ old('customer_name', auth()->user()->name ?? '') }}" type="text" required>
                    </label>
                    <label class="form-field">
                        <span>البريد</span>
                        <input name="customer_email" value="{{ old('customer_email', auth()->user()->email ?? '') }}" type="email">
                    </label>
                    <label class="form-field md:col-span-2">
                        <span>Player ID / بيانات التسليم</span>
                        <input name="player_id" value="{{ old('player_id') }}" placeholder="اكتب Player ID أو بيانات التسليم الأساسية">
                    </label>
                    <label class="form-field">
                        <span>السيرفر / الدولة</span>
                        <input name="server" value="{{ old('server', 'مصر') }}">
                    </label>
                    <label class="form-field">
                        <span>طريقة الدفع</span>
                        <select name="payment_method">
                            <option value="manual">دفع يدوي</option>
                            <option value="mock_gateway">بوابة تجريبية</option>
                            <option value="online_gateway">بوابة دفع إلكترونية</option>
                            <option value="wallet">محفظة RaseedNow</option>
                        </select>
                    </label>
                    <label class="form-field md:col-span-2">
                        <span>ملاحظات</span>
                        <input name="notes" value="{{ old('notes') }}" placeholder="أي تفاصيل إضافية للموظف">
                    </label>
                    <label class="form-field md:col-span-2">
                        <span>كود الخصم</span>
                        <input name="coupon_code" value="{{ old('coupon_code', $couponCode) }}" placeholder="اختياري">
                    </label>
                </div>
                <button type="submit" class="primary-button mt-5">إنشاء الطلب</button>
            </form>

            <aside class="surface lc-buy-box">
                <h2>مراجعة الطلب</h2>
                <div class="mt-5 space-y-3">
                    @foreach($items as $item)
                        <div class="summary-row">
                            <span>{{ $item['product']->name_ar }} × {{ $item['quantity'] }}</span>
                            <strong>{{ number_format($item['line_total_minor'] / 100, 2) }}</strong>
                        </div>
                    @endforeach
                    @if($quote['discount_minor'] > 0)
                        <div class="summary-row"><span>خصم {{ $quote['code'] }}</span><strong>-{{ number_format($quote['discount_minor'] / 100, 2) }}</strong></div>
                    @endif
                    <div class="summary-row total"><span>الإجمالي</span><strong>{{ number_format($quote['total_minor'] / 100, 2) }} EGP</strong></div>
                </div>
            </aside>
        </div>
    </section>
@endsection
