@extends('layouts.admin', ['title' => 'أكواد الشحن | Admin'])

@section('content')
    <section class="lc-page-shell">
        <div class="section-heading">
            <div>
                <span>Vouchers</span>
                <h1>أكواد شحن الرصيد</h1>
            </div>
            <a class="primary-button" href="{{ route('admin.vouchers.create') }}">كود جديد</a>
        </div>

        <div class="surface mt-6 p-5">
            <div class="ac-voucher-grid">
                @forelse($vouchers as $voucher)
                    @php($usagePercent = $voucher->usage_limit ? min(100, round(($voucher->used_count / max(1, $voucher->usage_limit)) * 100)) : 0)
                    <article class="ac-voucher-card {{ $voucher->is_active ? 'active' : 'inactive' }}">
                        <div class="ac-voucher-code">{{ $voucher->code }}</div>
                        <div class="ac-voucher-main">
                            <h3>{{ $voucher->name_ar }}</h3>
                            <strong>{{ number_format($voucher->amount_minor / 100, 2) }} {{ $voucher->currency_code }}</strong>
                        </div>
                        <div class="ac-voucher-usage">
                            <span>الاستخدام {{ $voucher->used_count }} / {{ $voucher->usage_limit ?? '∞' }}</span>
                            <div><b style="width: {{ $voucher->usage_limit ? $usagePercent : 8 }}%"></b></div>
                        </div>
                        <div class="ac-actions">
                        <a class="secondary-button info" href="{{ route('admin.vouchers.edit', $voucher) }}">تعديل</a>
                        <form method="POST" action="{{ route('admin.vouchers.destroy', $voucher) }}">
                            @csrf
                            @method('DELETE')
                            <button class="secondary-button danger" type="submit">تعطيل</button>
                        </form>
                        </div>
                    </article>
                @empty
                    <div class="ac-empty">لا توجد أكواد شحن بعد.</div>
                @endforelse
            </div>
            <div class="mt-4">{{ $vouchers->links() }}</div>
        </div>
    </section>
@endsection
