@extends('layouts.admin', ['title' => 'إدارة الكوبونات | RaseedNow'])

@section('content')
    <section class="lc-page-shell">
        <div class="section-heading">
            <div>
                <span>Promotions</span>
                <h1>الكوبونات والخصومات</h1>
            </div>
            <div class="flex flex-wrap gap-2">
                <a class="secondary-button" href="{{ route('admin.dashboard') }}">لوحة الإدارة</a>
                <a class="primary-button" href="{{ route('admin.coupons.create') }}">كوبون جديد</a>
            </div>
        </div>

        @if(session('status'))
            <div class="mt-4 rounded border border-green-200 bg-green-50 p-3 text-sm text-green-700">{{ session('status') }}</div>
        @endif

        <form class="mt-5 flex gap-2" method="GET">
            <input class="h-11 flex-1 rounded border border-[#dfe2ea] px-4" name="q" value="{{ $query }}" placeholder="بحث بالكود أو الاسم">
            <button class="secondary-button" type="submit">بحث</button>
        </form>

        <div class="mt-6 grid gap-4">
            @foreach($coupons as $coupon)
                <div class="surface grid gap-3 p-4 md:grid-cols-[1fr_120px_120px_120px_auto] md:items-center">
                    <div>
                        <span class="text-xs font-black text-[#ff8417]">{{ $coupon->code }} / {{ $coupon->type }}</span>
                        <h2 class="mt-1 text-lg font-black text-[#17264d]">{{ $coupon->name_ar }}</h2>
                    </div>
                    <div class="metric-card"><span>القيمة</span><strong>{{ $coupon->type === 'percent' ? $coupon->percent_off.'%' : number_format($coupon->value_minor / 100, 2) }}</strong></div>
                    <div class="metric-card"><span>الاستخدام</span><strong>{{ $coupon->used_count }}{{ $coupon->usage_limit ? '/'.$coupon->usage_limit : '' }}</strong></div>
                    <div class="metric-card"><span>الحالة</span><strong>{{ $coupon->is_active ? 'active' : 'inactive' }}</strong></div>
                    <div class="flex flex-wrap gap-2">
                        <a class="secondary-button" href="{{ route('admin.coupons.edit', $coupon) }}">تعديل</a>
                        <form method="POST" action="{{ route('admin.coupons.destroy', $coupon) }}">
                            @csrf
                            @method('DELETE')
                            <button class="secondary-button" type="submit">تعطيل</button>
                        </form>
                    </div>
                </div>
            @endforeach
        </div>
        <div class="mt-4">{{ $coupons->links() }}</div>
    </section>
@endsection
