

<?php $__env->startSection('title', 'প্রার্থী তালিকা'); ?>

<?php $__env->startSection('content'); ?>
    <div class="min-h-screen bg-gray-50 p-4 sm:p-6">
        <div class="max-w-7xl mx-auto">

            
            <div class="mb-6 flex items-center justify-between gap-3 flex-wrap">
                <div>
                    <h1 class="text-2xl font-bold text-gray-900">প্রার্থী তালিকা</h1>
                    <p class="text-sm text-gray-600">
                        মোট প্রার্থী: <span class="font-semibold"><?php echo e($candidates->total()); ?></span>
                    </p>
                </div>

                <div class="flex items-center gap-2">
                    
                    <div class="inline-flex rounded-lg border bg-white overflow-hidden">
                        <button type="button" id="btnList" class="px-3 py-2 text-sm font-semibold hover:bg-gray-50">
                            <i class="fas fa-list mr-1"></i> লিস্ট
                        </button>
                        <button type="button" id="btnGrid"
                            class="px-3 py-2 text-sm font-semibold hover:bg-gray-50 border-l">
                            <i class="fas fa-th-large mr-1"></i> গ্রিড
                        </button>
                    </div>

                    <a href="<?php echo e(route('candidates.create')); ?>"
                        class="px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 flex items-center gap-2">
                        <i class="fas fa-plus"></i> নতুন প্রার্থী
                    </a>
                </div>
            </div>

            
            <?php if(session('success')): ?>
                <div class="mb-4 p-3 rounded-lg bg-green-50 border border-green-200 text-green-800">
                    <i class="fas fa-check-circle mr-2"></i> <?php echo e(session('success')); ?>

                </div>
            <?php endif; ?>

            <?php if(session('error')): ?>
                <div class="mb-4 p-3 rounded-lg bg-red-50 border border-red-200 text-red-800">
                    <i class="fas fa-exclamation-circle mr-2"></i> <?php echo e(session('error')); ?>

                </div>
            <?php endif; ?>

            
            <div class="bg-white rounded-xl border mb-6 overflow-hidden">
                <div class="p-4">
                    <form method="GET" class="space-y-4">

                        
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">

                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">বিভাগ</label>
                                <select id="division_dd" name="division"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">সব বিভাগ</option>
                                    <?php $__currentLoopData = $divisions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $div): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($div->id); ?>"
                                            <?php echo e((string) request('division') === (string) $div->id ? 'selected' : ''); ?>>
                                            <?php echo e($div->name_bn ?? ($div->bn_name ?? ($div->name ?? 'Division #' . $div->id))); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>

                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">জেলা</label>
                                <select id="district_dd" name="district"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">প্রথমে বিভাগ নির্বাচন করুন</option>
                                </select>
                            </div>

                            
                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">উপজেলা</label>
                                <select id="upazila_dd" name="upazila_id"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">প্রথমে জেলা নির্বাচন করুন</option>
                                </select>
                            </div>


                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">সীট নির্বাচন করুন</label>
                                <select id="seat_dd" name="seat_id"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">সব সীট</option>
                                    <?php $__currentLoopData = $seats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($s->id); ?>"
                                            <?php echo e((string) request('seat_id') === (string) $s->id ? 'selected' : ''); ?>>
                                            <?php echo e($s->name_bn); ?> <?php echo e($s->seat_code ? '(' . $s->seat_code . ')' : ''); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>

                            </div>

                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">স্ট্যাটাস</label>
                                <select name="status"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">সব স্ট্যাটাস</option>
                                    <option value="active" <?php echo e(request('status') === 'active' ? 'selected' : ''); ?>>সক্রিয়
                                    </option>
                                    <option value="inactive" <?php echo e(request('status') === 'inactive' ? 'selected' : ''); ?>>
                                        নিষ্ক্রিয়</option>
                                    <option value="disqualified"
                                        <?php echo e(request('status') === 'disqualified' ? 'selected' : ''); ?>>অযোগ্য</option>
                                </select>
                            </div>

                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">এলাকা টাইপ</label>
                                <select name="area_type"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="">সব এলাকা</option>
                                    <option value="upazila" <?php echo e(request('area_type') === 'upazila' ? 'selected' : ''); ?>>উপজেলা
                                    </option>
                                    <option value="city" <?php echo e(request('area_type') === 'city' ? 'selected' : ''); ?>>
                                        সিটি/পৌরসভা</option>
                                </select>
                            </div>

                            
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">পৃষ্ঠায় ফলাফল</label>
                                <select name="per_page"
                                    class="w-full rounded-lg border border-gray-300 px-3 py-2 bg-white focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
                                    <option value="20" <?php echo e(request('per_page', 20) == 20 ? 'selected' : ''); ?>>২০টি
                                    </option>
                                    <option value="50" <?php echo e(request('per_page') == 50 ? 'selected' : ''); ?>>৫০টি</option>
                                    <option value="100" <?php echo e(request('per_page') == 100 ? 'selected' : ''); ?>>১০০টি
                                    </option>
                                </select>
                            </div>

                            <div></div>
                        </div>

                        
                        <div class="flex items-center justify-between pt-4 border-t">
                            <div class="text-sm text-gray-500">
                                <?php
                                    $filterCount = collect(
                                        request()->only([
                                            'seat_id',
                                            'status',
                                            'area_type',
                                            'division',
                                            'district',
                                            'upazila_or_city',
                                            'per_page',
                                        ]),
                                    )
                                        ->filter(fn($value) => !empty($value))
                                        ->count();
                                ?>
                                <?php if($filterCount > 0): ?>
                                    <span class="bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-xs">
                                        <?php echo e($filterCount); ?>টি ফিল্টার সক্রিয়
                                    </span>
                                <?php endif; ?>
                            </div>

                            <div class="flex items-center gap-3">
                                <a href="<?php echo e(route('candidates.index')); ?>"
                                    class="px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 flex items-center gap-2">
                                    <i class="fas fa-redo"></i> রিসেট
                                </a>
                                <button type="submit"
                                    class="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 flex items-center gap-2">
                                    <i class="fas fa-search"></i> ফলাফল দেখুন
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            
            <div id="listView" class="bg-white rounded-xl border overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="min-w-full text-sm">
                        <thead class="bg-gray-50 border-b">
                            <tr class="text-left">
                                <th class="p-3 w-16">ছবি</th>
                                <th class="p-3">প্রার্থী</th>
                                <th class="p-3">দল/প্রতীক</th>
                                <th class="p-3">সীট</th>
                                <th class="p-3">লোকেশন</th>
                                <th class="p-3">স্ট্যাটাস</th>
                                <th class="p-3 text-right">অ্যাকশন</th>
                            </tr>
                        </thead>

                        <tbody class="divide-y bg-white">
                            <?php $__empty_1 = true; $__currentLoopData = $candidates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <?php
                                    $seat = $c->seat;

                                    $seatTypeLabel = match ($seat?->seat_type) {
                                        'parliament' => 'জাতীয় সংসদ',
                                        'local' => 'স্থানীয়',
                                        'city_corp' => 'সিটি কর্পোরেশন',
                                        'pouroshova' => 'পৌরসভা',
                                        'union' => 'ইউনিয়ন',
                                        default => $seat?->seat_type,
                                    };

                                    $candAreaTypeLabel = match ($c->area_type) {
                                        'upazila' => 'উপজেলা',
                                        'city' => 'সিটি/পৌরসভা',
                                        default => $c->area_type,
                                    };

                                    $divName =
                                        $c->seat?->district?->division?->name_bn ??
                                        ($c->seat?->district?->division?->bn_name ??
                                            $c->seat?->district?->division?->name);

                                    $distName =
                                        $c->seat?->district?->name_bn ??
                                        ($c->seat?->district?->bn_name ?? $c->seat?->district?->name);
                                ?>

                                <tr class="hover:bg-gray-50">
                                    
                                    <td class="p-3">
                                        <?php if($c->photo): ?>
                                            <img src="<?php echo e(Storage::url($c->photo)); ?>" alt="<?php echo e($c->user?->name); ?>"
                                                class="w-12 h-12 rounded-full object-cover border">
                                        <?php else: ?>
                                            <div
                                                class="w-12 h-12 rounded-full bg-gray-200 flex items-center justify-center">
                                                <i class="fas fa-user text-gray-400"></i>
                                            </div>
                                        <?php endif; ?>
                                    </td>

                                    
                                    <td class="p-3">
                                        <div class="font-semibold text-gray-900">
                                            <?php echo e($c->user?->name ?? 'N/A'); ?>

                                        </div>
                                        <div class="text-xs text-gray-500">
                                            <?php echo e($c->email ?? '-'); ?> • <?php echo e($c->phone ?? '-'); ?>

                                        </div>
                                    </td>

                                    
                                    <td class="p-3">
                                        <div class="flex items-center gap-2">
                                            <?php if($c->symbol_photo): ?>
                                                <img src="<?php echo e(Storage::url($c->symbol_photo)); ?>"
                                                    alt="<?php echo e($c->symbol_name); ?>" class="w-8 h-8 object-contain">
                                            <?php elseif($c->symbol_name): ?>
                                                <div class="w-8 h-8 bg-blue-100 rounded flex items-center justify-center">
                                                    <span
                                                        class="text-xs font-bold text-blue-800"><?php echo e(\Illuminate\Support\Str::limit($c->symbol_name, 1)); ?></span>
                                                </div>
                                            <?php endif; ?>
                                            <div>
                                                <div class="text-gray-900"><?php echo e($c->party_name ?? '-'); ?></div>
                                                <div class="text-xs text-gray-500"><?php echo e($c->symbol_name ?? '-'); ?></div>
                                            </div>
                                        </div>
                                    </td>

                                    
                                    <td class="p-3">
                                        <div class="font-medium text-gray-900">
                                            <?php echo e($seat?->name_bn ?? '—'); ?>

                                            <?php if($seat?->seat_code): ?>
                                                <span class="text-xs text-gray-500">(<?php echo e($seat->seat_code); ?>)</span>
                                            <?php endif; ?>
                                        </div>
                                        <div class="text-xs text-gray-500">
                                            <?php echo e($seatTypeLabel ?: '—'); ?>

                                        </div>
                                    </td>

                                    
                                    <td class="p-3">
                                        <div class="text-gray-900">
                                            <span class="inline-flex items-center gap-1">
                                                <i class="fas fa-map-marker-alt text-red-500 text-xs"></i>
                                                <?php echo e($divName ?? '—'); ?>

                                                <?php if($distName): ?>
                                                    , <?php echo e($distName); ?>

                                                <?php endif; ?>
                                                <?php if($c->upazila_or_city): ?>
                                                    , <?php echo e($c->upazila_or_city); ?>

                                                <?php endif; ?>
                                            </span>
                                        </div>
                                        <div class="text-xs text-gray-500">
                                            <?php echo e($candAreaTypeLabel ?: '—'); ?>

                                            <?php if($c->ward_no): ?>
                                                • ওয়ার্ড: <?php echo e($c->ward_no); ?>

                                            <?php endif; ?>
                                        </div>
                                    </td>

                                    
                                    <td class="p-3">
                                        <?php if($c->status === 'active'): ?>
                                            <span
                                                class="px-2 py-1 rounded-full text-xs bg-green-100 text-green-800 flex items-center gap-1 w-fit">
                                                <i class="fas fa-check-circle"></i> সক্রিয়
                                            </span>
                                        <?php elseif($c->status === 'inactive'): ?>
                                            <span
                                                class="px-2 py-1 rounded-full text-xs bg-gray-100 text-gray-800 flex items-center gap-1 w-fit">
                                                <i class="fas fa-pause-circle"></i> নিষ্ক্রিয়
                                            </span>
                                        <?php else: ?>
                                            <span
                                                class="px-2 py-1 rounded-full text-xs bg-red-100 text-red-800 flex items-center gap-1 w-fit">
                                                <i class="fas fa-times-circle"></i> অযোগ্য
                                            </span>
                                        <?php endif; ?>
                                    </td>

                                    
                                    <td class="p-3 text-right whitespace-nowrap">
                                        <div class="inline-flex items-center gap-1">
                                            <a href="<?php echo e(route('candidates.show', $c)); ?>"
                                                class="px-3 py-1.5 border rounded-lg hover:bg-gray-50 text-sm flex items-center gap-1"
                                                title="দেখুন">
                                                View
                                            </a>

                                            <a href="<?php echo e(route('candidates.edit', $c)); ?>"
                                                class="px-3 py-1.5 border rounded-lg hover:bg-gray-50 text-sm flex items-center gap-1"
                                                title="এডিট">
                                                Edit
                                            </a>

                                            <form action="<?php echo e(route('candidates.destroy', $c)); ?>" method="POST"
                                                class="inline" onsubmit="return confirm('প্রার্থী ডিলিট করবেন?')">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="submit"
                                                    class="px-3 py-1.5 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm flex items-center gap-1"
                                                    title="ডিলিট">
                                                    Delete
                                                </button>
                                            </form>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="9" class="p-8 text-center text-gray-500">
                                        <div class="flex flex-col items-center justify-center py-8">
                                            <i class="fas fa-user-slash text-4xl text-gray-300 mb-3"></i>
                                            <p class="text-gray-500">কোনো প্রার্থী পাওয়া যায়নি</p>
                                            <?php if(request()->anyFilled(['seat_id', 'status', 'area_type', 'division', 'district', 'upazila_or_city'])): ?>
                                                <a href="<?php echo e(route('candidates.index')); ?>"
                                                    class="text-blue-600 hover:text-blue-800 text-sm mt-2">
                                                    ফিল্টার সরিয়ে সব প্রার্থী দেখুন
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>

                
                <div class="p-4 border-t">
                    <?php echo e($candidates->links()); ?>

                </div>
            </div>

            
            <div id="gridView" class="hidden">
    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
        <?php $__empty_1 = true; $__currentLoopData = $candidates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                $seat = $c->seat;

                $seatTypeLabel = match ($seat?->seat_type) {
                    'parliament' => 'জাতীয় সংসদ',
                    'local' => 'স্থানীয়',
                    'city_corp' => 'সিটি কর্পোরেশন',
                    'pouroshova' => 'পৌরসভা',
                    'union' => 'ইউনিয়ন',
                    default => $seat?->seat_type,
                };

                $candAreaTypeLabel = match ($c->area_type) {
                    'upazila' => 'উপজেলা',
                    'city' => 'সিটি/পৌরসভা',
                    default => $c->area_type,
                };

                $divName =
                    $c->seat?->district?->division?->name_bn ??
                    ($c->seat?->district?->division?->bn_name ?? $c->seat?->district?->division?->name);

                $distName =
                    $c->seat?->district?->name_bn ??
                    ($c->seat?->district?->bn_name ?? $c->seat?->district?->name);
            ?>

            <div class="group relative overflow-hidden rounded-2xl border bg-white shadow-sm hover:shadow-md transition">
                
                <div class="relative h-72 sm:h-80">
                    <?php if($c->photo): ?>
                        <img
                            src="<?php echo e(Storage::url($c->photo)); ?>"
                            alt="<?php echo e($c->user?->name); ?>"
                            class="absolute inset-0 h-full w-full object-cover"
                        >
                    <?php else: ?>
                        <div class="absolute inset-0 bg-gradient-to-br from-blue-50 via-white to-gray-100 flex items-center justify-center">
                            <i class="fas fa-user text-gray-300 text-7xl"></i>
                        </div>
                    <?php endif; ?>

                    
                    <div class="absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-black/0"></div>

                    
                    <div class="absolute top-3 right-3">
                        <?php if($c->status === 'active'): ?>
                            <span class="inline-flex items-center gap-1 rounded-full bg-emerald-500/90 text-white text-[11px] px-2 py-1 shadow">
                                <i class="fas fa-check-circle"></i> সক্রিয়
                            </span>
                        <?php elseif($c->status === 'inactive'): ?>
                            <span class="inline-flex items-center gap-1 rounded-full bg-slate-700/80 text-white text-[11px] px-2 py-1 shadow">
                                <i class="fas fa-pause-circle"></i> নিষ্ক্রিয়
                            </span>
                        <?php else: ?>
                            <span class="inline-flex items-center gap-1 rounded-full bg-rose-600/90 text-white text-[11px] px-2 py-1 shadow">
                                <i class="fas fa-times-circle"></i> অযোগ্য
                            </span>
                        <?php endif; ?>
                    </div>

                    
                    <div class="absolute top-3 left-3">
                        <?php if($c->symbol_photo): ?>
                            <div class="h-12 w-12 rounded-2xl bg-white/95 p-1 shadow border border-white/60">
                                <img
                                    src="<?php echo e(Storage::url($c->symbol_photo)); ?>"
                                    alt="<?php echo e($c->symbol_name); ?>"
                                    class="h-full w-full object-contain"
                                >
                            </div>
                        <?php elseif($c->symbol_name): ?>
                            <div class="h-12 w-12 rounded-2xl bg-white/95 shadow border border-white/60 flex items-center justify-center">
                                <span class="font-extrabold text-lg text-blue-700">
                                    <?php echo e(\Illuminate\Support\Str::limit($c->symbol_name, 1)); ?>

                                </span>
                            </div>
                        <?php endif; ?>
                    </div>

                    
                    <div class="absolute bottom-0 left-0 right-0 p-4">
                        <div class="flex items-end justify-between gap-3">
                            <div class="min-w-0">
                                <h3 class="text-white font-extrabold text-lg leading-tight truncate drop-shadow">
                                    <?php echo e($c->user?->name ?? 'N/A'); ?>

                                </h3>

                                <div class="mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-white/90">
                                    <?php if($c->party_name): ?>
                                        <span class="inline-flex items-center gap-1">
                                            <i class="fas fa-flag text-white/85"></i>
                                            <span class="truncate max-w-[220px]"><?php echo e($c->party_name); ?></span>
                                        </span>
                                    <?php endif; ?>

                                    <?php if($seat?->name_bn): ?>
                                        <span class="inline-flex items-center gap-1">
                                            <span class="text-white/60">•</span>
                                            <i class="fas fa-chair text-white/85"></i>
                                            <span class="truncate max-w-[220px]"><?php echo e($seat->name_bn); ?></span>
                                        </span>
                                    <?php endif; ?>
                                </div>
                            </div>

                            
                            <a href="<?php echo e(route('candidates.show', $c)); ?>"
                               class="shrink-0 inline-flex items-center gap-2 rounded-xl bg-white/95 px-3 py-2 text-xs font-semibold text-gray-900 shadow hover:bg-white">
                                <i class="fas fa-eye text-gray-700"></i>
                                দেখুন
                            </a>
                        </div>
                    </div>
                </div>

                
                <div class="p-4">
                    <div class="grid grid-cols-1 gap-2 text-[12px] text-gray-600">
                        
                        <?php if($c->symbol_name): ?>
                            <div class="flex items-start gap-2">
                                <i class="fas fa-tag text-gray-400 mt-0.5"></i>
                                <div class="min-w-0">
                                    <span class="text-gray-500">প্রতীক:</span>
                                    <span class="font-semibold text-gray-800"><?php echo e($c->symbol_name); ?></span>
                                </div>
                            </div>
                        <?php endif; ?>

                        
                        <div class="flex items-start gap-2">
                            <i class="fas fa-map-marker-alt text-gray-400 mt-0.5"></i>
                            <div class="min-w-0">
                                <div class="text-gray-800 truncate">
                                    <?php echo e($divName ?? '—'); ?>

                                    <?php if($distName): ?>, <?php echo e($distName); ?> <?php endif; ?>
                                    <?php if($c->upazila_or_city): ?>, <?php echo e($c->upazila_or_city); ?> <?php endif; ?>
                                </div>
                                <div class="text-[11px] text-gray-500">
                                    <?php echo e($candAreaTypeLabel ?: '—'); ?>

                                    <?php if($c->ward_no): ?>
                                        • ওয়ার্ড: <?php echo e($c->ward_no); ?>

                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>

                        
                        <?php if($seat?->name_bn): ?>
                            <div class="flex items-start gap-2">
                                <i class="fas fa-info-circle text-gray-400 mt-0.5"></i>
                                <div class="min-w-0">
                                    <span class="text-gray-700"><?php echo e($seatTypeLabel); ?></span>
                                    <?php if($seat->seat_code): ?>
                                        <span class="text-gray-400">(<?php echo e($seat->seat_code); ?>)</span>
                                    <?php endif; ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>

                    
                    <div class="mt-4 flex items-center gap-2">
                        <a href="<?php echo e(route('candidates.edit', $c)); ?>"
                           class="flex-1 inline-flex items-center justify-center gap-2 rounded-xl border bg-white px-3 py-2 text-xs font-semibold text-gray-800 hover:bg-gray-50">
                            <i class="fas fa-edit text-gray-600"></i> এডিট
                        </a>

                        <form action="<?php echo e(route('candidates.destroy', $c)); ?>" method="POST"
                              class="flex-1" onsubmit="return confirm('প্রার্থী ডিলিট করবেন?')">
                            <?php echo csrf_field(); ?>
                            <?php echo method_field('DELETE'); ?>
                            <button type="submit"
                                    class="w-full inline-flex items-center justify-center gap-2 rounded-xl bg-rose-600 px-3 py-2 text-xs font-semibold text-white hover:bg-rose-700">
                                <i class="fas fa-trash"></i> ডিলিট
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="sm:col-span-2 lg:col-span-3 xl:col-span-4">
                <div class="bg-white rounded-xl border p-8 text-center text-gray-500">
                    <div class="flex flex-col items-center justify-center py-8">
                        <i class="fas fa-user-slash text-4xl text-gray-300 mb-3"></i>
                        <p class="text-gray-500">কোনো প্রার্থী পাওয়া যায়নি</p>
                        <?php if(request()->anyFilled(['seat_id', 'status', 'area_type', 'division', 'district', 'upazila_or_city'])): ?>
                            <a href="<?php echo e(route('candidates.index')); ?>" class="text-blue-600 hover:text-blue-800 text-sm mt-2">
                                ফিল্টার সরিয়ে সব প্রার্থী দেখুন
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    </div>

    
    <div class="mt-4 bg-white rounded-xl border p-4">
        <?php echo e($candidates->links()); ?>

    </div>
</div>


        </div>
    </div>

    <script>
        (function() {
            const listView = document.getElementById('listView');
            const gridView = document.getElementById('gridView');
            const btnList = document.getElementById('btnList');
            const btnGrid = document.getElementById('btnGrid');

            function setActiveButton(view) {
                if (view === 'grid') {
                    btnGrid.classList.add('bg-gray-900', 'text-white');
                    btnGrid.classList.remove('bg-white', 'text-gray-900');
                    btnList.classList.remove('bg-gray-900', 'text-white');
                    btnList.classList.add('bg-white', 'text-gray-900');
                } else {
                    btnList.classList.add('bg-gray-900', 'text-white');
                    btnList.classList.remove('bg-white', 'text-gray-900');
                    btnGrid.classList.remove('bg-gray-900', 'text-white');
                    btnGrid.classList.add('bg-white', 'text-gray-900');
                }
            }

            function setView(view) {
                if (view === 'grid') {
                    listView?.classList.add('hidden');
                    gridView?.classList.remove('hidden');
                    setActiveButton('grid');
                } else {
                    gridView?.classList.add('hidden');
                    listView?.classList.remove('hidden');
                    setActiveButton('list');
                }
                localStorage.setItem('candidates_view', view);
            }

            const saved = localStorage.getItem('candidates_view') || 'list';
            setView(saved);

            btnList?.addEventListener('click', () => setView('list'));
            btnGrid?.addEventListener('click', () => setView('grid'));


            const divisionDD = document.getElementById('division_dd');
            const districtDD = document.getElementById('district_dd');
            const upazilaDD = document.getElementById('upazila_dd');
            const seatDD = document.getElementById('seat_dd');

            const divisions = <?php echo json_encode($divisions ?? [], 15, 512) ?>;
            const seatsForFilter = <?php echo json_encode($seatsForFilter ?? [], 15, 512) ?>;

            const oldDivision = <?php echo json_encode(request('division'), 15, 512) ?>;
            const oldDistrict = <?php echo json_encode(request('district'), 15, 512) ?>;
            const oldUpazila = <?php echo json_encode(request('upazila_id'), 15, 512) ?>;
            const oldSeat = <?php echo json_encode(request('seat_id'), 15, 512) ?>;

            function setOptions(selectEl, items, placeholder, selected = '', labelPrefix = '') {
                if (!selectEl) return;

                selectEl.innerHTML = '';
                const opt0 = document.createElement('option');
                opt0.value = '';
                opt0.textContent = placeholder;
                selectEl.appendChild(opt0);

                (items || []).forEach(item => {
                    const opt = document.createElement('option');
                    opt.value = item.id;

                    const label =
                        item.name_bn ||
                        item.bn_name ||
                        item.name_en ||
                        item.name ||
                        (labelPrefix ? (labelPrefix + ' #' + item.id) : ('#' + item.id));

                    opt.textContent = label;

                    if (selected && String(selected) === String(item.id)) opt.selected = true;
                    selectEl.appendChild(opt);
                });
            }

            function findDivision(divId) {
                return (divisions || []).find(d => String(d.id) === String(divId)) || null;
            }

            function findDistrict(divObj, distId) {
                return (divObj?.districts || []).find(x => String(x.id) === String(distId)) || null;
            }

            function fillDistricts(divId, selectedDistrict = '') {
                if (!divId) {
                    setOptions(districtDD, [], 'প্রথমে বিভাগ নির্বাচন করুন', '');
                    setOptions(upazilaDD, [], 'প্রথমে বিভাগ নির্বাচন করুন', '');
                    filterSeats(); // reset seats as well
                    return;
                }

                const divObj = findDivision(divId);
                const dists = divObj?.districts || [];

                setOptions(districtDD, dists, 'জেলা নির্বাচন করুন', selectedDistrict || '', 'District');
                setOptions(upazilaDD, [], 'প্রথমে জেলা নির্বাচন করুন', '');
                filterSeats(); // refresh seats when division changes
            }

            function fillUpazilas(divId, distId, selectedUpazila = '') {
                if (!divId) {
                    setOptions(upazilaDD, [], 'প্রথমে বিভাগ নির্বাচন করুন', '');
                    filterSeats();
                    return;
                }
                if (!distId) {
                    setOptions(upazilaDD, [], 'প্রথমে জেলা নির্বাচন করুন', '');
                    filterSeats();
                    return;
                }

                const divObj = findDivision(divId);
                const distObj = findDistrict(divObj, distId);
                const ups = distObj?.upazilas || [];

                setOptions(upazilaDD, ups, 'উপজেলা নির্বাচন করুন', selectedUpazila || '', 'Upazila');
                filterSeats();
            }

            // Seat filter logic
            function filterSeats(preserveSelected = true) {
                if (!seatDD) return;

                const divId = divisionDD?.value || '';
                const distId = districtDD?.value || '';
                const upaId = upazilaDD?.value || '';

                // keep current seat if possible
                const currentSeat = preserveSelected ? (seatDD.value || '') : '';

                // Filtering rules:
                // - If upazila selected => seats must match upazila_id
                // - Else if district selected => seats must match district_id
                // - Else if division selected => seats district must be in division districts
                // - Else show all seats
                let filtered = seatsForFilter.slice();

                if (upaId) {
                    filtered = filtered.filter(s => String(s.upazila_id || '') === String(upaId));
                } else if (distId) {
                    filtered = filtered.filter(s => String(s.district_id || '') === String(distId));
                } else if (divId) {
                    const divObj = findDivision(divId);
                    const distIds = (divObj?.districts || []).map(d => String(d.id));
                    filtered = filtered.filter(s => distIds.includes(String(s.district_id || '')));
                }

                // Build options with seat label
                seatDD.innerHTML = '';
                const opt0 = document.createElement('option');
                opt0.value = '';
                opt0.textContent = 'সব সীট';
                seatDD.appendChild(opt0);

                filtered.forEach(s => {
                    const opt = document.createElement('option');
                    opt.value = s.id;

                    const label =
                        `${s.name_bn || ('Seat #' + s.id)}${s.seat_code ? ' (' + s.seat_code + ')' : ''}`;
                    opt.textContent = label;

                    seatDD.appendChild(opt);
                });

                // restore selected seat if still available; otherwise clear
                const stillExists = filtered.some(s => String(s.id) === String(currentSeat));
                if (stillExists) {
                    seatDD.value = currentSeat;
                } else {
                    seatDD.value = '';
                }
            }

            divisionDD?.addEventListener('change', () => {
                fillDistricts(divisionDD.value, '');
            });

            districtDD?.addEventListener('change', () => {
                fillUpazilas(divisionDD.value, districtDD.value, '');
            });

            upazilaDD?.addEventListener('change', () => {
                filterSeats(true);
            });

            // Restore on load
            if (oldDivision) {
                // set division is already selected by blade, now fill deps
                fillDistricts(oldDivision, oldDistrict || '');
                if (oldDistrict) {
                    fillUpazilas(oldDivision, oldDistrict, oldUpazila || '');
                }
            } else {
                fillDistricts('', '');
            }

            // Finally, filter seats based on restored values and reselect old seat if possible
            filterSeats(false);
            if (oldSeat && seatDD) {
                // if exists in filtered list, select it
                const exists = Array.from(seatDD.options).some(o => String(o.value) === String(oldSeat));
                if (exists) seatDD.value = oldSeat;
            }
        })();
    </script>


<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Projects\election\resources\views/candidates/index.blade.php ENDPATH**/ ?>