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

@section('content')
    <section class="lc-page-shell">
        <div class="section-heading">
            <div>
                <span>Voucher</span>
                <h1>{{ $voucher->exists ? 'تعديل كود شحن' : 'كود شحن جديد' }}</h1>
            </div>
            <a class="secondary-button" href="{{ route('admin.vouchers.index') }}">كل الأكواد</a>
        </div>

        <form method="POST" action="{{ $voucher->exists ? route('admin.vouchers.update', $voucher) : route('admin.vouchers.store') }}" class="surface mt-6 grid gap-4 p-5 md:grid-cols-2">
            @csrf
            @if($voucher->exists)
                @method('PATCH')
            @endif

            <label class="form-field">
                <span>الكود</span>
                <input name="code" value="{{ old('code', $voucher->code ?? 'QA100') }}" required>
            </label>
            <label class="form-field">
                <span>الاسم العربي</span>
                <input name="name_ar" value="{{ old('name_ar', $voucher->name_ar) }}" required>
            </label>
            <label class="form-field">
                <span>القيمة بالقرش</span>
                <input name="amount_minor" value="{{ old('amount_minor', $voucher->amount_minor ?? 10000) }}" type="number" min="1" required>
            </label>
            <label class="form-field">
                <span>عدد الاستخدامات</span>
                <input name="usage_limit" value="{{ old('usage_limit', $voucher->usage_limit) }}" type="number" min="1">
            </label>
            <label class="form-field">
                <span>يبدأ في</span>
                <input name="starts_at" value="{{ old('starts_at', optional($voucher->starts_at)->format('Y-m-d\TH:i')) }}" type="datetime-local">
            </label>
            <label class="form-field">
                <span>ينتهي في</span>
                <input name="ends_at" value="{{ old('ends_at', optional($voucher->ends_at)->format('Y-m-d\TH:i')) }}" type="datetime-local">
            </label>

            <div class="rounded-2xl bg-[#f7f8fb] p-4 md:col-span-2">
                <label class="me-5 font-bold"><input name="is_active" value="1" type="checkbox" @checked(old('is_active', $voucher->is_active ?? true))> مفعل</label>
                <label class="font-bold"><input name="once_per_user" value="1" type="checkbox" @checked(old('once_per_user', $voucher->once_per_user ?? true))> مرة لكل عميل</label>
            </div>

            <div class="md:col-span-2">
                <button class="primary-button" type="submit">حفظ الكود</button>
            </div>
        </form>
    </section>
@endsection
