<?php
// admin/excel-export-content.php
?>

<div class="max-w-4xl mx-auto">
    
    <div class="bg-gray-50 rounded-xl p-6 mb-6">
        <h4 class="font-bold text-gray-700 mb-4">🔍 فیلترها</h4>
        <form method="GET" class="grid grid-cols-1 md:grid-cols-3 gap-4">
            <div>
                <label class="block text-sm text-gray-600 mb-1">ترم</label>
                <select name="term_id" class="w-full px-3 py-2 border rounded-lg">
                    <option value="0">همه ترم‌ها</option>
                    <?php foreach ($allTerms as $term): ?>
                    <option value="<?= $term['id'] ?>" <?= $term_id == $term['id'] ? 'selected' : '' ?>>
                        <?= htmlspecialchars($term['name']) ?>
                    </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div>
                <label class="block text-sm text-gray-600 mb-1">وضعیت شبا</label>
                <select name="status" class="w-full px-3 py-2 border rounded-lg">
                    <option value="all" <?= $status == 'all' ? 'selected' : '' ?>>همه</option>
                    <option value="with_sheba" <?= $status == 'with_sheba' ? 'selected' : '' ?>>دارای شبا</option>
                    <option value="without_sheba" <?= $status == 'without_sheba' ? 'selected' : '' ?>>بدون شبا</option>
                </select>
            </div>
            <div class="flex items-end">
                <button type="submit" class="btn btn-primary w-full">
                    <i class="fas fa-filter"></i> اعمال فیلتر
                </button>
            </div>
        </form>
    </div>
    
    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="bg-blue-50 rounded-xl p-4 border border-blue-100 text-center">
            <p class="text-blue-600 text-sm">تعداد کل مدرسین</p>
            <h3 class="text-2xl font-bold text-blue-700"><?= persianNumber(number_format(count($teachers))) ?></h3>
        </div>
        <div class="bg-green-50 rounded-xl p-4 border border-green-100 text-center">
            <p class="text-green-600 text-sm">دارای شماره شبا</p>
            <h3 class="text-2xl font-bold text-green-700">
                <?= persianNumber(number_format(array_filter($teachers, function($t) { return !empty($t['sheba_number']); }))) ?>
            </h3>
        </div>
        <div class="bg-amber-50 rounded-xl p-4 border border-amber-100 text-center">
            <p class="text-amber-600 text-sm">بدون شماره شبا</p>
            <h3 class="text-2xl font-bold text-amber-700">
                <?= persianNumber(number_format(array_filter($teachers, function($t) { return empty($t['sheba_number']); }))) ?>
            </h3>
        </div>
    </div>
    
    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
        <a href="export-excel.php?term_id=<?= $term_id ?>&status=<?= $status ?>" 
           class="bg-green-500 hover:bg-green-600 text-white rounded-xl p-6 text-center transition shadow-lg hover:shadow-xl">
            <i class="fas fa-file-excel text-3xl block mb-2"></i>
            <span class="text-lg font-bold">خروجی اکسل</span>
            <p class="text-green-100 text-sm">دانلود فایل CSV</p>
        </a>
        <a href="export-pdf.php?term_id=<?= $term_id ?>&status=<?= $status ?>" 
           class="bg-red-500 hover:bg-red-600 text-white rounded-xl p-6 text-center transition shadow-lg hover:shadow-xl">
            <i class="fas fa-file-pdf text-3xl block mb-2"></i>
            <span class="text-lg font-bold">خروجی PDF</span>
            <p class="text-red-100 text-sm">نمایش و پرینت</p>
        </a>
    </div>
    
    <div class="mt-6 bg-white rounded-xl overflow-hidden shadow border">
        <div class="px-4 py-3 bg-gray-50 border-b">
            <h5 class="font-bold text-gray-700">📋 لیست مدرسین</h5>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead>
                    <tr class="bg-gray-100">
                        <th class="text-right py-2 px-3 text-sm">#</th>
                        <th class="text-right py-2 px-3 text-sm">نام</th>
                        <th class="text-right py-2 px-3 text-sm">کد ملی</th>
                        <th class="text-right py-2 px-3 text-sm">موبایل</th>
                        <th class="text-right py-2 px-3 text-sm">شماره شبا</th>
                        <th class="text-right py-2 px-3 text-sm">وضعیت</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if (empty($teachers)): ?>
                    <tr><td colspan="6" class="text-center py-6 text-gray-400">مدرسی یافت نشد</td></tr>
                    <?php else: ?>
                    <?php $i = 1; foreach ($teachers as $teacher): ?>
                    <tr class="border-b hover:bg-gray-50">
                        <td class="py-2 px-3"><?= $i++ ?></td>
                        <td class="py-2 px-3"><?= htmlspecialchars($teacher['name'] . ' ' . $teacher['family']) ?></td>
                        <td class="py-2 px-3"><?= $teacher['national_code'] ?></td>
                        <td class="py-2 px-3"><?= $teacher['mobile'] ?></td>
                        <td class="py-2 px-3"><?= $teacher['sheba_number'] ?? 'ثبت نشده' ?></td>
                        <td class="py-2 px-3"><?= $teacher['is_active'] ? 'فعال' : 'غیرفعال' ?></td>
                    </tr>
                    <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
    
</div>