<?php
require_once '../config/database.php';
require_once '../includes/functions.php';
$pageTitle = 'Task Approvals';
include 'side.php';
require_once 'admin_protect.php';

$conn = getConnection();

// Handle approval/rejection
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = $_POST['action'] ?? '';
    $completionId = intval($_POST['completion_id']);
    
    if ($action === 'approve' || $action === 'reject') {
        // Get completion details
        $stmt = $conn->prepare("SELECT * FROM task_completions WHERE id = ?");
        $stmt->bind_param("i", $completionId);
        $stmt->execute();
        $completion = $stmt->get_result()->fetch_assoc();
        
        if ($completion) {
            $conn->begin_transaction();
            
            try {
                if ($action === 'approve') {
                    // Add reward to wallet
                    $walletColumnMap = [
                        'video' => 'video_wallet',
                        'survey' => 'survey_wallet',
                        'chat' => 'chat_wallet',
                        'transcription' => 'transcription_wallet',
                        'trivia' => 'trivia_wallet',
                        'quiz' => 'trivia_wallet', // Quiz uses trivia wallet
                        'ads' => 'ads_wallet',
                        'spin' => 'spin_wallet',
                        'blog' => 'blog_wallet',
                        'meme' => 'meme_wallet',
                        'external' => 'main_wallet' // External tasks go to main wallet
                    ];
                    
                    $walletColumn = $walletColumnMap[$completion['task_type']] ?? 'main_wallet';
                    
                    $reward = floatval($completion['reward_earned']);
                    $userId = $completion['user_id'];
                    
                    // Update wallet
                    $stmt = $conn->prepare("UPDATE wallets SET $walletColumn = $walletColumn + ? WHERE user_id = ?");
                    $stmt->bind_param("di", $reward, $userId);
                    $stmt->execute();
                    
                    // Update task completion count
                    $stmt = $conn->prepare("UPDATE tasks SET total_completions = total_completions + 1 WHERE id = ?");
                    $stmt->bind_param("i", $completion['task_id']);
                    $stmt->execute();
                    
                    // Update completion status
                    $stmt = $conn->prepare("UPDATE task_completions SET status = 'completed' WHERE id = ?");
                    $stmt->bind_param("i", $completionId);
                    $stmt->execute();
                    
                    // Create transaction record
                    $stmt = $conn->prepare("
                        INSERT INTO transactions 
                        (user_id, amount, type, wallet_type, status, description, created_at) 
                        VALUES (?, ?, 'credit', ?, 'completed', ?, NOW())
                    ");
                    $walletType = str_replace('_wallet', '', $walletColumn);
                    $description = "Task reward: " . $completion['task_type'];
                    $stmt->bind_param("idss", $userId, $reward, $walletType, $description);
                    $stmt->execute();
                    
                    setFlash('success', '✅ Task approved! Ksh ' . number_format($reward, 2) . ' added to user wallet.');
                    
                } else {
                    // Reject - update status
                    $stmt = $conn->prepare("UPDATE task_completions SET status = 'rejected' WHERE id = ?");
                    $stmt->bind_param("i", $completionId);
                    $stmt->execute();
                    
                    setFlash('warning', '❌ Task rejected.');
                }
                
                $conn->commit();
                
            } catch (Exception $e) {
                $conn->rollback();
                setFlash('error', 'Error processing task: ' . $e->getMessage());
            }
        }
    }
    
    redirect('task-approvals.php');
}

// Get filter
$filterType = $_GET['type'] ?? '';
$filterStatus = $_GET['status'] ?? 'pending';
$whereClause = [];

if ($filterType) {
    $whereClause[] = "tc.task_type = '" . $conn->real_escape_string($filterType) . "'";
}

if ($filterStatus) {
    $whereClause[] = "tc.status = '" . $conn->real_escape_string($filterStatus) . "'";
}

$whereSQL = $whereClause ? 'WHERE ' . implode(' AND ', $whereClause) : '';

// Get approvals
$approvals = $conn->query("
    SELECT 
        tc.*,
        t.title as task_title,
        t.reward as task_reward,
        u.username,
        u.email
    FROM task_completions tc
    JOIN tasks t ON tc.task_id = t.id
    JOIN users u ON tc.user_id = u.id
    $whereSQL
    ORDER BY tc.created_at DESC
    LIMIT 100
");

// Get statistics
$statsResult = $conn->query("
    SELECT 
        COUNT(*) as total_pending,
        COALESCE(SUM(CASE WHEN task_type = 'video' THEN 1 ELSE 0 END), 0) as video_pending,
        COALESCE(SUM(CASE WHEN task_type = 'survey' THEN 1 ELSE 0 END), 0) as survey_pending,
        COALESCE(SUM(CASE WHEN task_type = 'quiz' THEN 1 ELSE 0 END), 0) as quiz_pending,
        COALESCE(SUM(CASE WHEN task_type = 'blog' THEN 1 ELSE 0 END), 0) as blog_pending,
        COALESCE(SUM(CASE WHEN task_type = 'meme' THEN 1 ELSE 0 END), 0) as meme_pending,
        COALESCE(SUM(reward_earned), 0) as total_rewards
    FROM task_completions
    WHERE status = 'pending'
");

$stats = $statsResult ? $statsResult->fetch_assoc() : [];

// Ensure all values have defaults
$stats = array_merge([
    'total_pending' => 0,
    'video_pending' => 0,
    'survey_pending' => 0,
    'quiz_pending' => 0,
    'blog_pending' => 0,
    'meme_pending' => 0,
    'total_rewards' => 0
], $stats ?? []);

// Get admin currency
$adminCountry = getSetting('admin_country', 'Kenya');
$stmt = $conn->prepare("SELECT currency_symbol FROM countries WHERE name = ? LIMIT 1");
$stmt->bind_param("s", $adminCountry);
$stmt->execute();
$currencyResult = $stmt->get_result();

if ($currencyResult && $currencyResult->num_rows > 0) {
    $currencyRow = $currencyResult->fetch_assoc();
    $defaultCurrency = $currencyRow['currency_symbol'];
} else {
    $defaultCurrency = 'Ksh';
}
?>

<style>
/* MODERN TASK APPROVALS PAGE */
.page-container {
    padding: clamp(12px, 3vw, 24px);
    max-width: 1400px;
    margin: 0 auto;
}

/* PAGE HEADER - THEME AWARE */
.page-header {
    margin-bottom: clamp(20px, 4vw, 32px);
    padding: clamp(16px, 3vw, 24px);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    border-radius: 16px;
    border-left: 4px solid var(--primary);
}

/* Dark mode enhancement */
[data-theme="dark"] .page-header {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-left-color: var(--primary);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    font-size: clamp(20px, 4vw, 28px);
    font-weight: 900;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, var(--primary) 0%, #ec4899 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-settings {
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary) 0%, #ec4899 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(var(--theme-rgb), 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-settings:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(var(--theme-rgb), 0.4);
}

/* MODERN STAT CARDS - THEME AWARE */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: clamp(12px, 2.5vw, 20px);
    margin-bottom: clamp(20px, 4vw, 32px);
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: clamp(16px, 3vw, 20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    border-color: rgba(var(--theme-rgb), 0.3);
}

.stat-card:hover::before {
    opacity: 1;
}

/* Dark mode enhancement */
[data-theme="dark"] .stat-card {
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(148, 163, 184, 0.15);
}

[data-theme="dark"] .stat-card:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    border-color: rgba(var(--theme-rgb), 0.4);
}

.stat-icon {
    width: clamp(44px, 8vw, 52px);
    height: clamp(44px, 8vw, 52px);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(18px, 4vw, 24px);
    color: white;
    margin-bottom: 14px;
}

.stat-label {
    font-size: clamp(10px, 2vw, 12px);
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.stat-value {
    font-size: clamp(22px, 5vw, 28px);
    font-weight: 900;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* MODERN FILTERS BAR - THEME AWARE */
.filters-bar {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: clamp(20px, 4vw, 32px);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Dark mode enhancement */
[data-theme="dark"] .filters-bar {
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(148, 163, 184, 0.15);
}

.filter-btn {
    padding: 10px 20px;
    background: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-btn:hover {
    background: rgba(var(--theme-rgb), 0.1);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: linear-gradient(135deg, var(--primary) 0%, #ec4899 100%);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(var(--theme-rgb), 0.3);
}

/* Dark mode enhancement for filter buttons */
[data-theme="dark"] .filter-btn {
    background: rgba(15, 23, 42, 0.6);
    border-color: rgba(148, 163, 184, 0.2);
}

[data-theme="dark"] .filter-btn:hover {
    background: rgba(var(--theme-rgb), 0.15);
    border-color: var(--primary);
}

/* MODERN APPROVAL CARDS - THEME AWARE */
.approvals-grid {
    display: grid;
    gap: clamp(16px, 3vw, 20px);
}

.approval-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: clamp(18px, 3vw, 24px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.approval-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    opacity: 0;
    transition: opacity 0.3s;
}

.approval-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
    border-color: rgba(var(--theme-rgb), 0.2);
}

.approval-card:hover::before {
    opacity: 1;
}

/* Dark mode enhancement */
[data-theme="dark"] .approval-card {
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(148, 163, 184, 0.15);
}

[data-theme="dark"] .approval-card:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    border-color: rgba(var(--theme-rgb), 0.3);
}

.approval-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 16px;
    gap: 12px;
}

.approval-info {
    flex: 1;
    min-width: 0;
}

.task-title {
    font-size: clamp(16px, 3vw, 18px);
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-info {
    font-size: clamp(12px, 2.5vw, 13px);
    color: var(--text-secondary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.type-badge {
    padding: 8px 16px;
    border-radius: 10px;
    font-size: clamp(10px, 2vw, 12px);
    font-weight: 800;
    text-transform: uppercase;
    color: white;
    letter-spacing: 0.5px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.approval-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
    padding: 16px;
    background: var(--darker-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* Dark mode enhancement */
[data-theme="dark"] .approval-details {
    background: rgba(15, 23, 42, 0.6);
    border-color: rgba(148, 163, 184, 0.15);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-label {
    font-size: clamp(9px, 2vw, 10px);
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: clamp(12px, 2.5vw, 14px);
    color: var(--text-primary);
    font-weight: 800;
}

.detail-value a {
    color: var(--primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.3s;
}

.detail-value a:hover {
    transform: translateX(2px);
}

/* MODERN ACTION BUTTONS */
.action-buttons {
    display: flex;
    gap: 12px;
}

.action-buttons form {
    flex: 1;
}

.btn-action {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-approve {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-approve:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

.btn-reject {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-reject:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(239, 68, 68, 0.4);
}

/* EMPTY STATE */
.empty-state {
    text-align: center;
    padding: clamp(48px, 10vw, 80px) 20px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: clamp(56px, 12vw, 72px);
    opacity: 0.15;
    margin-bottom: 20px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.empty-state p {
    font-size: clamp(14px, 3vw, 16px);
    margin-top: 12px;
    font-weight: 600;
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .header-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn-settings {
        width: 100%;
        justify-content: center;
    }
    
    .approval-header {
        flex-direction: column;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .action-buttons form {
        width: 100%;
    }
}

/* SMOOTH TRANSITIONS FOR DARK MODE */
* {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}
</style>

<div class="page-container">
    <div class="page-header">
        <div class="header-row">
            <h1 class="page-title">
                <i class="fas fa-clock"></i> Task Approvals
            </h1>
            <a href="manage-tasks.php" class="btn-settings">
                <i class="fas fa-cog"></i> Manage Tasks
            </a>
        </div>
    </div>

    <!-- STATS GRID -->
    <div class="stats-grid">
        <div class="stat-card">
            <div class="stat-icon" style="background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);">
                <i class="fas fa-hourglass-half"></i>
            </div>
            <div class="stat-label">Total Pending</div>
            <div class="stat-value"><?php echo number_format($stats['total_pending']); ?></div>
        </div>
        
        <div class="stat-card">
            <div class="stat-icon" style="background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);">
                <i class="fas fa-poll"></i>
            </div>
            <div class="stat-label">Survey Pending</div>
            <div class="stat-value"><?php echo number_format($stats['survey_pending']); ?></div>
        </div>
        
        <div class="stat-card">
            <div class="stat-icon" style="background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);">
                <i class="fas fa-question-circle"></i>
            </div>
            <div class="stat-label">Quiz Pending</div>
            <div class="stat-value"><?php echo number_format($stats['quiz_pending']); ?></div>
        </div>
        
        <div class="stat-card">
            <div class="stat-icon" style="background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);">
                <i class="fas fa-images"></i>
            </div>
            <div class="stat-label">Meme Pending</div>
            <div class="stat-value"><?php echo number_format($stats['meme_pending']); ?></div>
        </div>
        
        <div class="stat-card">
            <div class="stat-icon" style="background: linear-gradient(135deg, #10b981 0%, #059669 100%);">
                <i class="fas fa-coins"></i>
            </div>
            <div class="stat-label">Total Rewards</div>
            <div class="stat-value"><?php echo $defaultCurrency; ?> <?php echo number_format($stats['total_rewards'], 2); ?></div>
        </div>
    </div>

    <!-- FILTERS BAR -->
    <div class="filters-bar">
        <a href="task-approvals.php" class="filter-btn <?php echo empty($filterType) ? 'active' : ''; ?>">
            <i class="fas fa-list"></i> All Pending
        </a>
        <a href="?type=survey" class="filter-btn <?php echo $filterType === 'survey' ? 'active' : ''; ?>">
            <i class="fas fa-poll"></i> Surveys
        </a>
        <a href="?type=quiz" class="filter-btn <?php echo $filterType === 'quiz' ? 'active' : ''; ?>">
            <i class="fas fa-question-circle"></i> Quizzes
        </a>
        <a href="?type=blog" class="filter-btn <?php echo $filterType === 'blog' ? 'active' : ''; ?>">
            <i class="fas fa-blog"></i> Blogs
        </a>
        <a href="?type=meme" class="filter-btn <?php echo $filterType === 'meme' ? 'active' : ''; ?>">
            <i class="fas fa-images"></i> Memes
        </a>
        <a href="?type=transcription" class="filter-btn <?php echo $filterType === 'transcription' ? 'active' : ''; ?>">
            <i class="fas fa-keyboard"></i> Transcription
        </a>
        <a href="?type=chat" class="filter-btn <?php echo $filterType === 'chat' ? 'active' : ''; ?>">
            <i class="fas fa-comments"></i> Chat
        </a>
    </div>

    <!-- APPROVALS GRID -->
    <div class="approvals-grid">
        <?php if ($approvals && $approvals->num_rows > 0): ?>
            <?php while ($approval = $approvals->fetch_assoc()): ?>
            <div class="approval-card">
                <div class="approval-header">
                    <div class="approval-info">
                        <div class="task-title"><?php echo htmlspecialchars($approval['task_title']); ?></div>
                        <div class="user-info">
                            <i class="fas fa-user"></i> <?php echo htmlspecialchars($approval['username']); ?> 
                            (<?php echo htmlspecialchars($approval['email']); ?>)
                        </div>
                    </div>
                    <span class="type-badge" style="background: <?php 
                        $colors = [
                            'video' => 'linear-gradient(135deg, #f59e0b, #d97706)',
                            'survey' => 'linear-gradient(135deg, #06b6d4, #0891b2)',
                            'quiz' => 'linear-gradient(135deg, #8b5cf6, #7c3aed)',
                            'trivia' => 'linear-gradient(135deg, #ec4899, #db2777)',
                            'meme' => 'linear-gradient(135deg, #ef4444, #dc2626)',
                            'chat' => 'linear-gradient(135deg, #8b5cf6, #7c3aed)',
                            'blog' => 'linear-gradient(135deg, #10b981, #059669)',
                            'transcription' => 'linear-gradient(135deg, #3b82f6, #2563eb)',
                            'external' => 'linear-gradient(135deg, #6b7280, #4b5563)'
                        ];
                        echo $colors[$approval['task_type']] ?? 'linear-gradient(135deg, #6b7280, #4b5563)';
                    ?>;">
                        <i class="fas fa-<?php 
                            $icons = [
                                'video' => 'video',
                                'survey' => 'poll',
                                'quiz' => 'question-circle',
                                'trivia' => 'question-circle',
                                'meme' => 'images',
                                'chat' => 'comments',
                                'blog' => 'blog',
                                'transcription' => 'keyboard',
                                'external' => 'link'
                            ];
                            echo $icons[$approval['task_type']] ?? 'tasks';
                        ?>"></i>
                        <?php echo htmlspecialchars($approval['task_type']); ?>
                    </span>
                </div>
                
                <div class="approval-details">
                    <div class="detail-item">
                        <span class="detail-label">Reward</span>
                        <span class="detail-value" style="color: #10b981;">
                            <?php echo $defaultCurrency; ?> <?php echo number_format($approval['reward_earned'], 2); ?>
                        </span>
                    </div>
                    <div class="detail-item">
                        <span class="detail-label">Submitted</span>
                        <span class="detail-value"><?php echo date('M j, Y', strtotime($approval['created_at'])); ?></span>
                    </div>
                    <div class="detail-item">
                        <span class="detail-label">Time</span>
                        <span class="detail-value"><?php echo date('h:i A', strtotime($approval['created_at'])); ?></span>
                    </div>
                    <?php if (!empty($approval['screenshot'])): ?>
                    <div class="detail-item">
                        <span class="detail-label">Screenshot</span>
                        <span class="detail-value">
                            <a href="<?php echo htmlspecialchars($approval['screenshot']); ?>" target="_blank">
                                <i class="fas fa-external-link-alt"></i> View
                            </a>
                        </span>
                    </div>
                    <?php endif; ?>
                </div>
                
                <div class="action-buttons">
                    <form method="POST">
                        <input type="hidden" name="action" value="approve">
                        <input type="hidden" name="completion_id" value="<?php echo $approval['id']; ?>">
                        <button type="submit" class="btn-action btn-approve">
                            <i class="fas fa-check"></i> Approve
                        </button>
                    </form>
                    <form method="POST">
                        <input type="hidden" name="action" value="reject">
                        <input type="hidden" name="completion_id" value="<?php echo $approval['id']; ?>">
                        <button type="submit" class="btn-action btn-reject" onclick="return confirm('❌ Reject this task submission?')">
                            <i class="fas fa-times"></i> Reject
                        </button>
                    </form>
                </div>
            </div>
            <?php endwhile; ?>
        <?php else: ?>
            <div class="empty-state">
                <i class="fas fa-check-circle"></i>
                <p><strong>No <?php echo $filterType ? htmlspecialchars($filterType) : 'pending'; ?> approvals</strong></p>
                <p>All tasks have been processed! 🎉</p>
            </div>
        <?php endif; ?>
    </div>
</div>

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