<div>
    @if($showModal)
    <div class="fixed inset-0 z-50 overflow-y-auto" aria-modal="true">
        <div class="flex items-center justify-center min-h-screen px-4 py-6">
            {{-- Backdrop --}}
            <div class="fixed inset-0 bg-black/50 transition-opacity" wire:click="close"></div>

            {{-- Modal Content --}}
            <div class="relative bg-white rounded-2xl shadow-xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col">
                {{-- Header --}}
                <div class="px-6 py-4 border-b border-gray-200 bg-red-50">
                    <div class="flex items-center justify-between">
                        <div class="flex items-center gap-3">
                            <div class="w-10 h-10 rounded-full bg-red-100 flex items-center justify-center">
                                <svg class="w-5 h-5 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                </svg>
                            </div>
                            <div>
                                <h3 class="text-lg font-bold text-gray-900">{{ __('حذف مشترك') }}</h3>
                                <p class="text-sm text-gray-600">{{ $participantName }}</p>
                            </div>
                        </div>
                        <button wire:click="close" class="text-gray-400 hover:text-gray-600">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                        </button>
                    </div>
                </div>

                {{-- Body --}}
                <div class="px-6 py-4 overflow-y-auto flex-1">
                    {{-- Warning --}}
                    <div class="mb-4 p-3 bg-amber-50 border border-amber-200 rounded-lg">
                        <p class="text-sm text-amber-800 font-medium">{{ __('تحذير: سيتم إلغاء جميع الاشتراكات النشطة وحذف سجلات الحضور المستقبلية.') }}</p>
                    </div>

                    {{-- Invoices Section --}}
                    @if(count($paidInvoices) > 0)
                    <div class="mb-4">
                        <h4 class="text-sm font-bold text-gray-700 mb-3">{{ __('الفواتير المدفوعة') }} ({{ count($paidInvoices) }})</h4>
                        <p class="text-xs text-gray-500 mb-3">{{ __('يمكنك استرداد المبالغ المدفوعة لكل فاتورة على حدة قبل الحذف، أو المتابعة بدون استرداد.') }}</p>

                        <div class="space-y-2">
                            @foreach($paidInvoices as $invoice)
                            <div class="border border-gray-200 rounded-lg p-3 {{ in_array($invoice['id'], $refundedInvoiceIds) ? 'bg-green-50 border-green-200' : '' }}">
                                <div class="flex items-center justify-between gap-3">
                                    <div class="flex-1 min-w-0">
                                        <div class="flex items-center gap-2">
                                            <span class="text-sm font-mono text-gray-600" dir="ltr">{{ $invoice['number'] }}</span>
                                            @if(in_array($invoice['id'], $refundedInvoiceIds))
                                            <span class="px-2 py-0.5 text-[10px] bg-green-100 text-green-700 rounded-full">{{ __('تم الاسترداد') }}</span>
                                            @endif
                                        </div>
                                        <p class="text-xs text-gray-500 mt-0.5 truncate">{{ $invoice['description'] }}</p>
                                        <p class="text-xs text-gray-400 mt-0.5">{{ $invoice['issue_date'] }}</p>
                                    </div>
                                    <div class="text-start flex-shrink-0">
                                        <p class="text-sm font-bold text-gray-800">{{ number_format($invoice['paid_amount'] / 100, 2) }} {{ __('ج.م') }}</p>
                                        @if(!in_array($invoice['id'], $refundedInvoiceIds))
                                            @if($confirmingRefundInvoiceId === $invoice['id'])
                                            <div class="flex items-center gap-1 mt-1">
                                                <button wire:click="confirmRefund({{ $invoice['id'] }})"
                                                        wire:loading.attr="disabled"
                                                        class="px-2 py-1 text-[10px] bg-red-600 text-white rounded hover:bg-red-700 font-medium">
                                                    {{ __('تأكيد') }}
                                                </button>
                                                <button wire:click="cancelRefund"
                                                        class="px-2 py-1 text-[10px] bg-gray-200 text-gray-700 rounded hover:bg-gray-300">
                                                    {{ __('إلغاء') }}
                                                </button>
                                            </div>
                                            @else
                                            <button wire:click="askRefund({{ $invoice['id'] }})"
                                                    class="mt-1 px-2 py-1 text-[10px] bg-amber-100 text-amber-700 rounded hover:bg-amber-200 font-medium">
                                                {{ __('استرداد') }}
                                            </button>
                                            @endif
                                        @endif
                                    </div>
                                </div>
                            </div>
                            @endforeach
                        </div>
                    </div>
                    @else
                    <div class="mb-4 p-4 bg-gray-50 rounded-lg text-center">
                        <p class="text-sm text-gray-500">{{ __('لا توجد فواتير مدفوعة لهذا المشترك') }}</p>
                    </div>
                    @endif
                </div>

                {{-- Footer --}}
                <div class="px-6 py-4 border-t border-gray-200 bg-gray-50 flex items-center justify-between gap-3">
                    <button wire:click="close"
                            class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50">
                        {{ __('إلغاء') }}
                    </button>
                    <button wire:click="deleteParticipant"
                            wire:loading.attr="disabled"
                            wire:target="deleteParticipant"
                            class="px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-lg hover:bg-red-700 disabled:opacity-50">
                        <span wire:loading.remove wire:target="deleteParticipant">{{ __('حذف المشترك نهائياً') }}</span>
                        <span wire:loading wire:target="deleteParticipant">{{ __('جارٍ الحذف...') }}</span>
                    </button>
                </div>
            </div>
        </div>
    </div>
    @endif
</div>
