<?php
require_once 'config.php';
require_once 'includes/Database.php';
require_once 'includes/Auth.php';

Auth::requireLogin();

$pageTitle = 'Dashboard';
include 'includes/header.php';

$db = new Database();
$isAdmin = Auth::isAdmin();
$currentUserName = Auth::getFullName();

// Tarih aralığı - Bu ay
$startDate = date('Y-m-01');
$endDate = date('Y-m-d');
$currentMonth = date('Y-m');
$currentMonthName = [
    '01' => 'Ocak', '02' => 'Şubat', '03' => 'Mart', '04' => 'Nisan',
    '05' => 'Mayıs', '06' => 'Haziran', '07' => 'Temmuz', '08' => 'Ağustos',
    '09' => 'Eylül', '10' => 'Ekim', '11' => 'Kasım', '12' => 'Aralık'
][date('m')] . ' ' . date('Y');

// Genel İstatistikler
$totalUsers = $db->fetchOne("SELECT COUNT(*) as count FROM users WHERE is_active = 1")['count'] ?? 0;
$totalCriteria = $db->fetchOne("SELECT COUNT(*) as count FROM criteria WHERE is_active = 1")['count'] ?? 0;

// Bu Ay İstatistikleri
$monthStats = $db->fetchOne("
    SELECT
        (SELECT COUNT(DISTINCT user_id) FROM incoming_calls WHERE DATE(call_date) BETWEEN ? AND ?) as active_users,
        (SELECT COALESCE(SUM(answered_count), 0) FROM incoming_calls WHERE DATE(call_date) BETWEEN ? AND ?) as total_incoming,
        (SELECT COALESCE(SUM(answered_count), 0) FROM outgoing_calls WHERE DATE(call_date) BETWEEN ? AND ?) as total_outgoing,
        (SELECT COUNT(*) FROM training_completion WHERE DATE(training_completion_date) BETWEEN ? AND ?) as total_trainings
", [$startDate, $endDate, $startDate, $endDate, $startDate, $endDate, $startDate, $endDate]);

// Son 7 günlük aktivite
$recentActivity = $db->fetchAll("
    SELECT
        DATE(call_date) as date,
        COALESCE(SUM(answered_count), 0) as calls
    FROM incoming_calls
    WHERE call_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
    GROUP BY DATE(call_date)
    ORDER BY date ASC
    LIMIT 7
");

// En İyi Performans Gösterenler (Bu Ay) - Bonus.php'deki puanlama mantığı
if ($isAdmin) {
    // Aktif kriterleri al
    $activeCriteria = $db->fetchAll("SELECT code, point_value FROM criteria WHERE is_active = 1");
    $criteriaPoints = [];
    foreach ($activeCriteria as $crit) {
        $criteriaPoints[$crit['code']] = (float)$crit['point_value'];
    }

    // Tüm aktif kullanıcıların performans verilerini al
    $users = $db->fetchAll("
        SELECT id, full_name
        FROM users
        WHERE is_active = 1 AND full_name != 'Mustafa SÜLERYA'
    ");

    $performanceData = [];

    foreach ($users as $user) {
        // Gelen aramalar
        $incoming = $db->fetchOne("
            SELECT
                COALESCE(SUM(answered_count), 0) as calls,
                COALESCE(SUM(TIME_TO_SEC(total_duration)), 0) as duration
            FROM incoming_calls
            WHERE user_id = ? AND DATE(call_date) BETWEEN ? AND ?
        ", [$user['id'], $startDate, $endDate]);

        // Giden aramalar
        $outgoing = $db->fetchOne("
            SELECT
                COALESCE(SUM(answered_count), 0) as calls,
                COALESCE(SUM(TIME_TO_SEC(total_duration)), 0) as duration
            FROM outgoing_calls
            WHERE user_id = ? AND DATE(call_date) BETWEEN ? AND ?
        ", [$user['id'], $startDate, $endDate]);

        // Eğitimler
        $trainings = $db->fetchOne("
            SELECT COUNT(*) as count
            FROM training_completion
            WHERE support_representative = ? AND DATE(training_completion_date) BETWEEN ? AND ?
        ", [$user['full_name'], $startDate, $endDate]);

        $performanceData[] = [
            'full_name' => $user['full_name'],
            'incoming_calls' => $incoming['calls'] ?? 0,
            'incoming_duration' => $incoming['duration'] ?? 0,
            'outgoing_calls' => $outgoing['calls'] ?? 0,
            'outgoing_duration' => $outgoing['duration'] ?? 0,
            'trainings' => $trainings['count'] ?? 0
        ];
    }

    // Toplamları hesapla (oransal puanlama için)
    $totals = [
        'incoming_calls' => array_sum(array_column($performanceData, 'incoming_calls')),
        'incoming_duration' => array_sum(array_column($performanceData, 'incoming_duration')),
        'outgoing_calls' => array_sum(array_column($performanceData, 'outgoing_calls')),
        'outgoing_duration' => array_sum(array_column($performanceData, 'outgoing_duration')),
        'trainings' => array_sum(array_column($performanceData, 'trainings'))
    ];

    // Her kullanıcı için puan hesapla (bonus.php mantığı)
    foreach ($performanceData as &$data) {
        $data['score_incoming_calls'] = $totals['incoming_calls'] > 0
            ? ($data['incoming_calls'] / $totals['incoming_calls']) * ($criteriaPoints['gelen_arama_sayisi'] ?? 0)
            : 0;

        $data['score_incoming_duration'] = $totals['incoming_duration'] > 0
            ? ($data['incoming_duration'] / $totals['incoming_duration']) * ($criteriaPoints['gelen_arama_suresi'] ?? 0)
            : 0;

        $data['score_outgoing_calls'] = $totals['outgoing_calls'] > 0
            ? ($data['outgoing_calls'] / $totals['outgoing_calls']) * ($criteriaPoints['giden_arama_sayisi'] ?? 0)
            : 0;

        $data['score_outgoing_duration'] = $totals['outgoing_duration'] > 0
            ? ($data['outgoing_duration'] / $totals['outgoing_duration']) * ($criteriaPoints['giden_arama_suresi'] ?? 0)
            : 0;

        $data['score_training'] = $totals['trainings'] > 0
            ? ($data['trainings'] / $totals['trainings']) * ($criteriaPoints['egitim_tamamlama'] ?? 0)
            : 0;

        // Toplam puan (basitleştirilmiş - paket puanları hariç)
        $data['total_score'] =
            $data['score_incoming_calls'] +
            $data['score_incoming_duration'] +
            $data['score_outgoing_calls'] +
            $data['score_outgoing_duration'] +
            $data['score_training'];
    }
    unset($data);

    // Toplam puana göre sırala
    usort($performanceData, function($a, $b) {
        return $b['total_score'] <=> $a['total_score'];
    });

    // En iyi 5'i al
    $topPerformers = array_slice($performanceData, 0, 5);
}

// Kullanıcının kendi istatistikleri (eğer admin değilse)
$myStats = null;
if (!$isAdmin) {
    $user = $db->fetchOne("SELECT id FROM users WHERE full_name = ?", [$currentUserName]);
    if ($user) {
        $myStats = $db->fetchOne("
            SELECT
                COALESCE(SUM(ic.answered_count), 0) as my_incoming,
                COALESCE(SUM(oc.answered_count), 0) as my_outgoing,
                (SELECT COUNT(*) FROM training_completion WHERE support_representative = ? AND DATE(training_completion_date) BETWEEN ? AND ?) as my_trainings
            FROM incoming_calls ic
            LEFT JOIN outgoing_calls oc ON ic.user_id = oc.user_id AND DATE(oc.call_date) BETWEEN ? AND ?
            WHERE ic.user_id = ? AND DATE(ic.call_date) BETWEEN ? AND ?
        ", [$currentUserName, $startDate, $endDate, $startDate, $endDate, $user['id'], $startDate, $endDate]);
    }
}

// Kritik Bildirimler
$notifications = [];

// Tarihçe eklenmemiş aylara uyarı
if ($isAdmin) {
    $upcomingMonths = [];
    for ($i = 0; $i < 3; $i++) {
        $checkDate = date('Y-m-15', strtotime("+$i months"));
        $checkYear = date('Y', strtotime($checkDate));
        $checkMonth = date('n', strtotime($checkDate));

        // Bu ay için tarihçe var mı?
        $hasHistory = $db->fetchOne("
            SELECT COUNT(*) as count
            FROM criteria_history
            WHERE (start_date <= ? AND (end_date IS NULL OR end_date >= ?))
        ", [$checkDate, $checkDate]);

        if (!$hasHistory || $hasHistory['count'] == 0) {
            $monthName = [
                1 => 'Ocak', 2 => 'Şubat', 3 => 'Mart', 4 => 'Nisan',
                5 => 'Mayıs', 6 => 'Haziran', 7 => 'Temmuz', 8 => 'Ağustos',
                9 => 'Eylül', 10 => 'Ekim', 11 => 'Kasım', 12 => 'Aralık'
            ][$checkMonth];
            $upcomingMonths[] = "$monthName $checkYear";
        }
    }

    if (!empty($upcomingMonths) && count($upcomingMonths) > 0) {
        $notifications[] = [
            'type' => 'warning',
            'icon' => '⚠️',
            'message' => 'Şu aylar için kriter tarihçesi tanımlanmamış: ' . implode(', ', array_slice($upcomingMonths, 0, 2))
        ];
    }
}

// Bugün veri girişi yapılmış mı?
$todayData = $db->fetchOne("
    SELECT COUNT(*) as count
    FROM incoming_calls
    WHERE call_date = CURDATE()
");

if ($isAdmin && (!$todayData || $todayData['count'] == 0)) {
    $notifications[] = [
        'type' => 'info',
        'icon' => '📊',
        'message' => 'Bugün için henüz veri girişi yapılmamış.'
    ];
}
?>

<style>
    .dashboard-container {
        max-width: 1400px;
        margin: 0 auto;
    }

    /* Welcome Section */
    .welcome-section {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-radius: 20px;
        padding: 40px;
        color: white;
        margin-bottom: 30px;
        box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
        position: relative;
        overflow: hidden;
    }

    .welcome-section::before {
        content: '';
        position: absolute;
        top: -50%;
        right: -10%;
        width: 400px;
        height: 400px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 50%;
    }

    .welcome-content {
        position: relative;
        z-index: 1;
    }

    .welcome-content h1 {
        font-size: 32px;
        margin-bottom: 10px;
        font-weight: 700;
    }

    .welcome-content p {
        font-size: 16px;
        opacity: 0.95;
        margin-bottom: 20px;
    }

    .welcome-meta {
        display: flex;
        gap: 30px;
        font-size: 14px;
        opacity: 0.9;
    }

    .welcome-meta-item {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    /* Stats Grid */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 20px;
        margin-bottom: 30px;
    }

    .stat-card {
        background: white;
        border-radius: 15px;
        padding: 25px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
        transition: all 0.3s;
        position: relative;
        overflow: hidden;
    }

    .stat-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
    }

    .stat-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 4px;
        height: 100%;
        background: var(--card-color, #667eea);
    }

    .stat-card-content {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
    }

    .stat-info {
        flex: 1;
    }

    .stat-value {
        font-size: 36px;
        font-weight: 700;
        color: #2c3e50;
        margin-bottom: 8px;
        line-height: 1;
    }

    .stat-label {
        font-size: 14px;
        color: #7f8c8d;
        font-weight: 500;
    }

    .stat-change {
        font-size: 12px;
        margin-top: 8px;
        padding: 4px 8px;
        border-radius: 6px;
        display: inline-block;
    }

    .stat-change.positive {
        background: #d4edda;
        color: #155724;
    }

    .stat-change.negative {
        background: #f8d7da;
        color: #721c24;
    }

    .stat-icon {
        width: 60px;
        height: 60px;
        border-radius: 15px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 30px;
        background: var(--card-color, #667eea);
        opacity: 0.15;
    }

    /* Content Grid */
    .content-grid {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: 30px;
        margin-bottom: 30px;
    }

    @media (max-width: 1024px) {
        .content-grid {
            grid-template-columns: 1fr;
        }
    }

    /* Cards */
    .card {
        background: white;
        border-radius: 15px;
        padding: 25px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    }

    .card-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 2px solid #f0f0f0;
    }

    .card-title {
        font-size: 18px;
        font-weight: 700;
        color: #2c3e50;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .card-action {
        font-size: 13px;
        color: #667eea;
        text-decoration: none;
        font-weight: 600;
        transition: color 0.3s;
    }

    .card-action:hover {
        color: #764ba2;
    }

    /* Activity Chart */
    .activity-chart {
        display: flex;
        align-items: flex-end;
        justify-content: space-between;
        height: 200px;
        padding: 20px 0;
        gap: 10px;
    }

    .activity-bar {
        flex: 1;
        background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
        border-radius: 8px 8px 0 0;
        position: relative;
        transition: all 0.3s;
        cursor: pointer;
        min-height: 20px;
    }

    .activity-bar:hover {
        opacity: 0.8;
        transform: scaleY(1.05);
    }

    .activity-bar-label {
        position: absolute;
        bottom: -25px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 11px;
        color: #7f8c8d;
        white-space: nowrap;
    }

    .activity-bar-value {
        position: absolute;
        top: -25px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 12px;
        font-weight: 600;
        color: #2c3e50;
    }

    /* Top Performers */
    .performer-list {
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    .performer-item {
        display: flex;
        align-items: center;
        padding: 15px;
        background: #f8f9fa;
        border-radius: 12px;
        transition: all 0.3s;
    }

    .performer-item:hover {
        background: #e9ecef;
        transform: translateX(5px);
    }

    .performer-rank {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 18px;
        margin-right: 15px;
    }

    .performer-rank.rank-1 {
        background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
        color: white;
    }

    .performer-rank.rank-2 {
        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        color: white;
    }

    .performer-rank.rank-3 {
        background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
        color: white;
    }

    .performer-rank.rank-other {
        background: #e9ecef;
        color: #6c757d;
    }

    .performer-info {
        flex: 1;
    }

    .performer-name {
        font-weight: 600;
        color: #2c3e50;
        margin-bottom: 5px;
    }

    .performer-stats {
        font-size: 13px;
        color: #7f8c8d;
    }

    /* Notifications */
    .notification {
        display: flex;
        align-items: flex-start;
        gap: 15px;
        padding: 15px;
        border-radius: 12px;
        margin-bottom: 15px;
    }

    .notification.warning {
        background: #fff3cd;
        border-left: 4px solid #ffc107;
    }

    .notification.info {
        background: #cfe2ff;
        border-left: 4px solid #0d6efd;
    }

    .notification.success {
        background: #d1e7dd;
        border-left: 4px solid #198754;
    }

    .notification-icon {
        font-size: 24px;
    }

    .notification-content {
        flex: 1;
    }

    .notification-message {
        font-size: 14px;
        color: #2c3e50;
        line-height: 1.6;
    }

    /* Quick Actions */
    .quick-actions-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 15px;
    }

    .action-btn {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 18px 20px;
        background: white;
        border-radius: 12px;
        text-decoration: none;
        color: #2c3e50;
        font-weight: 600;
        transition: all 0.3s;
        border: 2px solid #e9ecef;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .action-btn:hover {
        border-color: #667eea;
        transform: translateY(-3px);
        box-shadow: 0 5px 15px rgba(102, 126, 234, 0.2);
    }

    .action-btn-icon {
        font-size: 28px;
    }

    .action-btn-text {
        flex: 1;
    }

    .action-btn-label {
        font-size: 14px;
        color: #2c3e50;
        display: block;
        margin-bottom: 3px;
    }

    .action-btn-desc {
        font-size: 11px;
        color: #7f8c8d;
        font-weight: 400;
    }

    /* Empty State */
    .empty-state {
        text-align: center;
        padding: 40px 20px;
        color: #7f8c8d;
    }

    .empty-state-icon {
        font-size: 48px;
        margin-bottom: 15px;
        opacity: 0.5;
    }

    .empty-state-text {
        font-size: 14px;
    }
</style>

<div class="dashboard-container">
    <!-- Welcome Section -->
    <div class="welcome-section">
        <div class="welcome-content">
            <h1>Hoş Geldiniz, <?php echo htmlspecialchars($currentUserName); ?>! 👋</h1>
            <p>Destek Performans Takip Sistemi - Güncel performans verileriniz ve ekip istatistikleriniz</p>
            <div class="welcome-meta">
                <div class="welcome-meta-item">
                    <span>📅</span>
                    <span><?php echo $currentMonthName; ?></span>
                </div>
                <div class="welcome-meta-item">
                    <span>🕐</span>
                    <span><?php echo date('H:i'); ?></span>
                </div>
                <div class="welcome-meta-item">
                    <span>👤</span>
                    <span><?php echo $isAdmin ? 'Yönetici' : 'Personel'; ?></span>
                </div>
            </div>
        </div>
    </div>

    <!-- Notifications -->
    <?php if (!empty($notifications)): ?>
    <div style="margin-bottom: 30px;">
        <?php foreach ($notifications as $notif): ?>
        <div class="notification <?php echo $notif['type']; ?>">
            <div class="notification-icon"><?php echo $notif['icon']; ?></div>
            <div class="notification-content">
                <div class="notification-message"><?php echo $notif['message']; ?></div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <!-- Stats Grid -->
    <div class="stats-grid">
        <div class="stat-card" style="--card-color: #667eea;">
            <div class="stat-card-content">
                <div class="stat-info">
                    <div class="stat-value"><?php echo number_format($monthStats['active_users'] ?? 0); ?></div>
                    <div class="stat-label">Aktif Personel</div>
                    <div class="stat-change positive">Bu Ay</div>
                </div>
                <div class="stat-icon">👥</div>
            </div>
        </div>

        <div class="stat-card" style="--card-color: #f093fb;">
            <div class="stat-card-content">
                <div class="stat-info">
                    <div class="stat-value"><?php echo number_format($monthStats['total_incoming'] ?? 0); ?></div>
                    <div class="stat-label">Gelen Aramalar</div>
                    <div class="stat-change positive">Bu Ay</div>
                </div>
                <div class="stat-icon">📥</div>
            </div>
        </div>

        <div class="stat-card" style="--card-color: #4facfe;">
            <div class="stat-card-content">
                <div class="stat-info">
                    <div class="stat-value"><?php echo number_format($monthStats['total_outgoing'] ?? 0); ?></div>
                    <div class="stat-label">Giden Aramalar</div>
                    <div class="stat-change positive">Bu Ay</div>
                </div>
                <div class="stat-icon">📤</div>
            </div>
        </div>

        <div class="stat-card" style="--card-color: #43e97b;">
            <div class="stat-card-content">
                <div class="stat-info">
                    <div class="stat-value"><?php echo number_format($monthStats['total_trainings'] ?? 0); ?></div>
                    <div class="stat-label">Eğitimler</div>
                    <div class="stat-change positive">Bu Ay</div>
                </div>
                <div class="stat-icon">🎓</div>
            </div>
        </div>
    </div>

    <!-- Content Grid -->
    <div class="content-grid">
        <!-- Son 7 Gün Aktivitesi -->
        <div class="card">
            <div class="card-header">
                <div class="card-title">
                    <span>📊</span>
                    <span>Son 7 Gün - Gelen Arama Aktivitesi</span>
                </div>
            </div>
            <div class="activity-chart">
                <?php
                if (!empty($recentActivity)) {
                    $maxCalls = max(array_column($recentActivity, 'calls'));
                    $maxCalls = $maxCalls > 0 ? $maxCalls : 1;
                    foreach ($recentActivity as $day):
                        $percentage = ($day['calls'] / $maxCalls) * 100;
                        $date = date('d/m', strtotime($day['date']));
                ?>
                <div class="activity-bar" style="height: <?php echo $percentage; ?>%;">
                    <div class="activity-bar-value"><?php echo $day['calls']; ?></div>
                    <div class="activity-bar-label"><?php echo $date; ?></div>
                </div>
                <?php
                    endforeach;
                } else {
                    echo '<div class="empty-state"><div class="empty-state-icon">📊</div><div class="empty-state-text">Son 7 günde veri bulunmuyor</div></div>';
                }
                ?>
            </div>
        </div>

        <!-- Top Performers / Kişisel Stats -->
        <div class="card">
            <div class="card-header">
                <div class="card-title">
                    <span><?php echo $isAdmin ? '🏆' : '📈'; ?></span>
                    <span><?php echo $isAdmin ? 'En İyi Performans' : 'Performansınız'; ?></span>
                </div>
                <?php if ($isAdmin): ?>
                <a href="bonus.php" class="card-action">Detaylı Rapor →</a>
                <?php endif; ?>
            </div>

            <?php if ($isAdmin && !empty($topPerformers)): ?>
            <div class="performer-list">
                <?php foreach ($topPerformers as $index => $performer): ?>
                <div class="performer-item">
                    <div class="performer-rank rank-<?php echo $index < 3 ? ($index + 1) : 'other'; ?>">
                        <?php echo $index + 1; ?>
                    </div>
                    <div class="performer-info">
                        <div class="performer-name"><?php echo htmlspecialchars($performer['full_name']); ?></div>
                        <div class="performer-stats">
                            <strong><?php echo number_format($performer['total_score'], 2); ?></strong> puan •
                            <?php echo number_format($performer['incoming_calls']); ?> gelen •
                            <?php echo number_format($performer['outgoing_calls']); ?> giden •
                            <?php echo number_format($performer['trainings']); ?> eğitim
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            <?php elseif (!$isAdmin && $myStats): ?>
            <div style="padding: 20px 0;">
                <div class="stats-grid" style="grid-template-columns: repeat(3, 1fr); gap: 15px;">
                    <div style="text-align: center;">
                        <div style="font-size: 28px; font-weight: 700; color: #667eea; margin-bottom: 5px;">
                            <?php echo number_format($myStats['my_incoming']); ?>
                        </div>
                        <div style="font-size: 12px; color: #7f8c8d;">Gelen Arama</div>
                    </div>
                    <div style="text-align: center;">
                        <div style="font-size: 28px; font-weight: 700; color: #4facfe; margin-bottom: 5px;">
                            <?php echo number_format($myStats['my_outgoing']); ?>
                        </div>
                        <div style="font-size: 12px; color: #7f8c8d;">Giden Arama</div>
                    </div>
                    <div style="text-align: center;">
                        <div style="font-size: 28px; font-weight: 700; color: #43e97b; margin-bottom: 5px;">
                            <?php echo number_format($myStats['my_trainings']); ?>
                        </div>
                        <div style="font-size: 12px; color: #7f8c8d;">Eğitim</div>
                    </div>
                </div>
                <div style="text-align: center; margin-top: 20px;">
                    <a href="bonus.php" class="btn btn-primary" style="display: inline-block; padding: 10px 24px; border-radius: 8px; text-decoration: none;">
                        Detaylı Performansım →
                    </a>
                </div>
            </div>
            <?php else: ?>
            <div class="empty-state">
                <div class="empty-state-icon">🏆</div>
                <div class="empty-state-text">Bu ay için henüz veri bulunmuyor</div>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="card">
        <div class="card-header">
            <div class="card-title">
                <span>⚡</span>
                <span>Hızlı İşlemler</span>
            </div>
        </div>
        <div class="quick-actions-grid">
            <?php if ($isAdmin): ?>
            <a href="accounts.php" class="action-btn">
                <div class="action-btn-icon">👤</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Hesaplar</span>
                    <span class="action-btn-desc">Kullanıcı yönetimi</span>
                </div>
            </a>
            <a href="criteria.php" class="action-btn">
                <div class="action-btn-icon">📋</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Kriterler</span>
                    <span class="action-btn-desc">Değerlendirme kriterleri</span>
                </div>
            </a>
            <a href="upload_incoming.php" class="action-btn">
                <div class="action-btn-icon">📥</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Gelen Arama</span>
                    <span class="action-btn-desc">Veri yükleme</span>
                </div>
            </a>
            <a href="upload_outgoing.php" class="action-btn">
                <div class="action-btn-icon">📤</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Giden Arama</span>
                    <span class="action-btn-desc">Veri yükleme</span>
                </div>
            </a>
            <a href="upload_training.php" class="action-btn">
                <div class="action-btn-icon">🎓</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Eğitimler</span>
                    <span class="action-btn-desc">Veri yükleme</span>
                </div>
            </a>
            <?php endif; ?>
            <a href="bonus.php" class="action-btn">
                <div class="action-btn-icon">💰</div>
                <div class="action-btn-text">
                    <span class="action-btn-label">Performans</span>
                    <span class="action-btn-desc">Prim hesaplama</span>
                </div>
            </a>
        </div>
    </div>
</div>

<?php include 'includes/footer.php'; ?>
