<?php
// teacher/profile-content.php - محتوای پروفایل مدرس
?>

<?php if ($message): ?>
<div class="alert <?= strpos($message, 'خطا') !== false ? 'alert-danger' : 'alert-success' ?>">
    <i class="fas <?= strpos($message, 'خطا') !== false ? 'fa-exclamation-circle' : 'fa-check-circle' ?>"></i>
    <?= $message ?>
</div>
<?php endif; ?>

<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
    
    <!-- ===== اطلاعات شخصی ===== -->
    <div class="lg:col-span-1">
        <div class="bg-gradient-to-br from-blue-500 to-purple-600 rounded-2xl p-6 text-white">
            <div class="flex flex-col items-center">
                <h3 class="text-xl font-bold mb-1"><?= htmlspecialchars($user['name'] . ' ' . $user['family']) ?></h3>
                <p class="text-blue-200 text-sm"><?= htmlspecialchars($user['role_name']) ?></p>
                
                <div class="w-full mt-6 pt-6 border-t border-white/20">
                    <div class="flex justify-between py-2">
                        <span class="text-blue-200">کد ملی</span>
                        <span class="font-mono"><?= persianNumber($user['national_code']) ?></span>
                    </div>
                    <div class="flex justify-between py-2">
                        <span class="text-blue-200">موبایل</span>
                        <span><?= persianNumber($user['mobile']) ?></span>
                    </div>
                    <div class="flex justify-between py-2">
                        <span class="text-blue-200">وضعیت</span>
                        <?= getStatusBadge($user['is_active']) ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- ===== اطلاعات بانکی و فرم‌ها ===== -->
    <div class="lg:col-span-2 space-y-6">
        
        <!-- ===== شماره شبا ===== -->
        <div class="bg-white rounded-2xl p-6 shadow-sm border">
            <h4 class="font-bold text-gray-800 mb-4 flex items-center gap-2">
                <i class="fas fa-university text-green-500"></i>
                شماره شبا
            </h4>
            
            <?php if ($user['is_sheba_confirmed']): ?>
                <div class="bg-green-50 rounded-xl p-4 border border-green-200">
                    <div class="flex items-center gap-3">
                        <i class="fas fa-check-circle text-green-500 text-xl"></i>
                        <div>
                            <div class="font-mono text-gray-700"><?= $user['sheba_number'] ?></div>
                            <div class="text-sm text-green-600">✅ شماره شبا تأیید شده است</div>
                        </div>
                    </div>
                    <div class="mt-2 text-sm text-gray-500">
                        <i class="fas fa-info-circle"></i> شماره شبا پس از تأیید قابل تغییر نیست.
                    </div>
                </div>
            <?php else: ?>
                <form method="POST" class="space-y-4">
                    <input type="hidden" name="action" value="update_sheba">
                    <div class="form-group">
                        <label>شماره شبا</label>
                        <input type="text" name="sheba_number" value="<?= htmlspecialchars($user['sheba_number'] ?? '') ?>" 
                               placeholder="IR123456789012345678901234" maxlength="26" 
                               class="w-full px-4 py-3 border border-gray-300 rounded-xl font-mono">
                        <small class="text-gray-400 text-xs">شماره شبا باید ۲۶ رقم باشد</small>
                    </div>
                    <?php if (!empty($user['sheba_number']) && !$user['is_sheba_confirmed']): ?>
                        <div class="bg-yellow-50 rounded-xl p-3 border border-yellow-200">
                            <div class="flex items-center gap-2 text-yellow-700 text-sm">
                                <i class="fas fa-clock"></i>
                                شماره شبا در انتظار تأیید مدیر است.
                            </div>
                        </div>
                    <?php endif; ?>
                    <?php if (empty($user['sheba_number']) || !$user['is_sheba_confirmed']): ?>
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> ثبت/به‌روزرسانی
                        </button>
                    <?php endif; ?>
                </form>
            <?php endif; ?>
        </div>
        
        <!-- ===== تغییر موبایل ===== -->
        <div class="bg-white rounded-2xl p-6 shadow-sm border">
            <h4 class="font-bold text-gray-800 mb-4 flex items-center gap-2">
                <i class="fas fa-phone text-blue-500"></i>
                تغییر شماره موبایل
            </h4>
            <form method="POST" class="flex flex-col sm:flex-row gap-3">
                <input type="hidden" name="action" value="update_mobile">
                <input type="text" name="mobile" value="<?= htmlspecialchars($user['mobile']) ?>" 
                       class="flex-1 px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500"
                       pattern="09\d{9}" maxlength="11" required>
                <button type="submit" class="btn btn-primary whitespace-nowrap">
                    <i class="fas fa-save"></i> به‌روزرسانی
                </button>
            </form>
        </div>
        
        <!-- ===== تغییر رمز ===== -->
        <div class="bg-white rounded-2xl p-6 shadow-sm border">
            <h4 class="font-bold text-gray-800 mb-4 flex items-center gap-2">
                <i class="fas fa-lock text-red-500"></i>
                تغییر رمز عبور
            </h4>
            <form method="POST" class="space-y-3">
                <input type="hidden" name="action" value="update_password">
                <div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
                    <input type="password" name="current_password" placeholder="رمز فعلی" 
                           class="px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                    <input type="password" name="new_password" placeholder="رمز جدید" 
                           class="px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                    <input type="password" name="confirm_password" placeholder="تکرار رمز جدید" 
                           class="px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500" required>
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-key"></i> تغییر رمز عبور
                </button>
            </form>
        </div>
    </div>
</div>

<!-- ===== دروس و تراکنش‌ها ===== -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
    
    <!-- ===== دروس ===== -->
    <div class="bg-white rounded-2xl p-6 shadow-sm border">
        <h4 class="font-bold text-gray-800 mb-4 flex items-center gap-2">
            <i class="fas fa-book text-purple-500"></i>
            دروس من
        </h4>
        <?php if (empty($courses)): ?>
            <p class="text-gray-400 text-center py-4">هیچ درسی ثبت نشده است</p>
        <?php else: ?>
            <div class="space-y-3 max-h-[300px] overflow-y-auto">
                <?php foreach ($courses as $course): ?>
                    <div class="bg-gray-50 rounded-xl p-4 border border-gray-200">
                        <div class="flex justify-between items-start">
                            <div>
                                <div class="font-medium text-gray-800"><?= htmlspecialchars($course['name']) ?></div>
                                <div class="text-sm text-gray-500">
                                    <?= $course['units'] ?> واحد • <?= $course['hours'] ?> ساعت
                                    <?php if (!empty($course['term_name'])): ?>
                                        <span class="mx-1">|</span>
                                        <span class="text-xs text-blue-500"><?= htmlspecialchars($course['term_name']) ?></span>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="text-sm font-bold text-green-600">
                                <?= formatPrice($course['salary']) ?>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
    
    <!-- ===== تراکنش‌ها ===== -->
    <div class="bg-white rounded-2xl p-6 shadow-sm border">
        <h4 class="font-bold text-gray-800 mb-4 flex items-center gap-2">
            <i class="fas fa-coins text-amber-500"></i>
            تراکنش‌های مالی
        </h4>
        <?php if (empty($transactions)): ?>
            <p class="text-gray-400 text-center py-4">هیچ تراکنشی ثبت نشده است</p>
        <?php else: ?>
            <div class="space-y-3 max-h-[300px] overflow-y-auto">
                <?php foreach ($transactions as $transaction): ?>
                    <div class="bg-gray-50 rounded-xl p-4 border border-gray-200">
                        <div class="flex justify-between items-start">
                            <div>
                                <div class="font-medium text-gray-800"><?= formatPrice($transaction['amount']) ?></div>
                                <div class="text-sm text-gray-500">
                                    <?= jalaliDate($transaction['payment_date']) ?>
                                    <?php if (!empty($transaction['term_name'])): ?>
                                        <span class="mx-1">|</span>
                                        <span class="text-xs text-blue-500"><?= htmlspecialchars($transaction['term_name']) ?></span>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <span class="badge-success">
                                <i class="fas fa-check-circle"></i> واریز
                            </span>
                        </div>
                        <?php if (!empty($transaction['description'])): ?>
                            <div class="mt-1 text-sm text-gray-500"><?= htmlspecialchars($transaction['description']) ?></div>
                        <?php endif; ?>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</div>