<div>
    {{-- Month/Year Selector --}}
    <div class="flex items-center justify-between mb-6">
        <button wire:click="previousMonth" class="w-11 h-11 rounded-xl bg-white border border-gray-200 flex items-center justify-center hover:bg-gray-50 transition-colors">
            <svg class="w-5 h-5 text-[#0F172A]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/>
            </svg>
        </button>
        <h2 class="text-base font-semibold text-[#0F172A]">{{ $monthLabel }}</h2>
        <button wire:click="nextMonth" class="w-11 h-11 rounded-xl bg-white border border-gray-200 flex items-center justify-center hover:bg-gray-50 transition-colors">
            <svg class="w-5 h-5 text-[#0F172A]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
            </svg>
        </button>
    </div>

    {{-- Warning Banner --}}
    @if(($attendanceRate ?? 0) < 75 && $attendanceRate !== null)
        <div class="mb-4 p-4 rounded-2xl border border-[#D97706]/20 bg-amber-50">
            <div class="flex items-center gap-3">
                <svg class="w-5 h-5 text-[#D97706] shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"/>
                </svg>
                <p class="text-sm font-medium text-[#D97706]">{{ __('نسبة الحضور أقل من 75% - يرجى الالتزام بمواعيد الحصص') }}</p>
            </div>
        </div>
    @endif

    {{-- Circular Progress Indicator --}}
    <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6 mb-6">
        <div class="flex justify-center mb-4">
            @php
                $rate = $attendanceRate ?? 0;
                $circumference = 2 * 3.14159 * 54;
                $offset = $circumference - ($rate / 100) * $circumference;
                $ringColor = $rate >= 75 ? '#059669' : ($rate >= 50 ? '#D97706' : '#DC2626');
            @endphp
            <div class="relative w-36 h-36">
                <svg class="w-36 h-36 transform -rotate-90" viewBox="0 0 120 120">
                    {{-- Background ring --}}
                    <circle cx="60" cy="60" r="54" fill="none" stroke="#E5E7EB" stroke-width="8"/>
                    {{-- Progress ring --}}
                    <circle cx="60" cy="60" r="54" fill="none"
                        stroke="{{ $ringColor }}"
                        stroke-width="8"
                        stroke-linecap="round"
                        stroke-dasharray="{{ $circumference }}"
                        stroke-dashoffset="{{ $offset }}"
                        class="transition-all duration-700"/>
                </svg>
                <div class="absolute inset-0 flex flex-col items-center justify-center">
                    <span class="text-3xl font-bold text-[#0F172A]" dir="ltr">{{ $attendanceRate !== null ? $rate . '%' : '--' }}</span>
                    <span class="text-xs text-[#64748B]">{{ __('نسبة الحضور') }}</span>
                </div>
            </div>
        </div>

        {{-- Breakdown Row --}}
        <div class="grid grid-cols-4 gap-2">
            <div class="text-center p-3 rounded-xl bg-green-50">
                <p class="text-lg font-bold text-[#059669]" dir="ltr">{{ $presentCount ?? 0 }}</p>
                <p class="text-[10px] text-[#059669] font-medium">{{ __('حضور') }}</p>
            </div>
            <div class="text-center p-3 rounded-xl bg-amber-50">
                <p class="text-lg font-bold text-[#D97706]" dir="ltr">{{ $lateCount ?? 0 }}</p>
                <p class="text-[10px] text-[#D97706] font-medium">{{ __('تأخير') }}</p>
            </div>
            <div class="text-center p-3 rounded-xl bg-red-50">
                <p class="text-lg font-bold text-[#DC2626]" dir="ltr">{{ $absentCount ?? 0 }}</p>
                <p class="text-[10px] text-[#DC2626] font-medium">{{ __('غياب') }}</p>
            </div>
            <div class="text-center p-3 rounded-xl bg-blue-50">
                <p class="text-lg font-bold text-[#2563EB]" dir="ltr">{{ $excusedCount ?? 0 }}</p>
                <p class="text-[10px] text-[#2563EB] font-medium">{{ __('عذر') }}</p>
            </div>
        </div>
    </div>

    {{-- Attendance Log --}}
    <div class="mb-6">
        <h3 class="text-base font-semibold text-[#0F172A] mb-3">{{ __('سجل الحضور') }}</h3>

        <div wire:loading.class="opacity-50 pointer-events-none">
            @if($records->isEmpty())
                <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-8 text-center">
                    <svg class="w-10 h-10 text-gray-200 mx-auto mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/>
                    </svg>
                    <p class="text-sm text-[#64748B]">{{ __('لا توجد سجلات حضور لهذا الشهر') }}</p>
                </div>
            @else
                <div class="space-y-2">
                    @php
                        $statusConfig = [
                            'present' => ['label' => 'حاضر', 'bg' => 'bg-green-100', 'text' => 'text-green-700'],
                            'late' => ['label' => 'متأخر', 'bg' => 'bg-amber-100', 'text' => 'text-amber-700'],
                            'absent' => ['label' => 'غائب', 'bg' => 'bg-red-100', 'text' => 'text-red-700'],
                            'excused' => ['label' => 'معذور', 'bg' => 'bg-blue-100', 'text' => 'text-blue-700'],
                            'no_show' => ['label' => 'لم يحضر', 'bg' => 'bg-red-100', 'text' => 'text-red-700'],
                            'left_early' => ['label' => 'انصرف مبكراً', 'bg' => 'bg-amber-100', 'text' => 'text-amber-700'],
                            'partial' => ['label' => 'جزئي', 'bg' => 'bg-amber-100', 'text' => 'text-amber-700'],
                        ];
                    @endphp

                    @foreach($records as $record)
                        @php $config = $statusConfig[$record->status ?? ''] ?? ['label' => $record->status ?? '', 'bg' => 'bg-gray-100', 'text' => 'text-gray-700']; @endphp
                        <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-4">
                            <div class="flex items-center justify-between">
                                <div>
                                    <p class="text-sm font-medium text-[#0F172A]">{{ $record->session?->group?->program?->name_ar ?? $record->session?->group?->name_ar ?? '' }}</p>
                                    <p class="text-xs text-[#64748B] mt-0.5" dir="ltr">{{ $record->session?->session_date ?? '' }} - {{ $record->session?->start_time ?? '' }}</p>
                                </div>
                                <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium {{ $config['bg'] }} {{ $config['text'] }}">
                                    {{ __($config['label']) }}
                                </span>
                            </div>
                        </div>
                    @endforeach
                </div>

                <div class="mt-4">
                    {{ $records->links() }}
                </div>
            @endif
        </div>
    </div>

    {{-- Submit Excuse Button --}}
    <div class="fixed bottom-20 start-4 end-4 sm:static sm:mt-4">
        <a href="{{ route('parent.excuses.create') }}" wire:navigate
           class="block w-full text-center bg-[#2563EB] text-white font-medium py-3.5 px-6 rounded-2xl hover:bg-blue-700 transition-colors min-h-[44px] shadow-lg sm:shadow-none">
            {{ __('تقديم عذر') }}
        </a>
    </div>
</div>
