<div class="page-title">
    <i class="bi bi-megaphone-fill page-icon"></i>
    <div>
        <h2>My Campaigns</h2>
    </div>
</div>

<div class="row">
    <?php if (!empty($campaigns)): ?>
        <?php foreach ($campaigns as $campaign): ?>
            <div class="col-md-6 mb-4">
                <div class="campaign-card">
                    <div class="card-top">
                        <div>
                            <div class="card-title">
                                <i class="bi bi-megaphone-fill"></i>
                                <?= htmlspecialchars($campaign->name) ?>
                            </div>
                            <div class="type-badge mt-2">
                                <i class="bi bi-<?= $campaign->type == 'WhatsApp' ? 'whatsapp' : ($campaign->type == 'SMS' ? 'chat-dots' : 'envelope') ?>"></i>
                                <?= htmlspecialchars($campaign->type) ?>
                            </div>
                        </div>
                        <div>
                            <?php
                            $badge_class = [
                                'active' => 'background: #059669;',
                                'paused' => 'background: #f59e0b;',
                                'stopped' => 'background: #ef4444;',
                                'completed' => 'background: #6b7280;'
                            ];
                            $status_style = isset($badge_class[$campaign->status]) ? $badge_class[$campaign->status] : 'background:#64748b;';
                            ?>
                            <span class="status-badge" style="<?= $status_style ?>"><?= ucfirst($campaign->status) ?></span>
                        </div>
                    </div>

                    <div class="metrics">
                        <div class="metric">
                            <div class="label">
                                <i class="bi bi-check2-square"></i>
                                Total Assigned
                            </div>
                            <div class="value"><?= number_format($campaign->my_assigned ?? 0) ?></div>
                        </div>
                        <div class="metric success">
                            <div class="label">
                                <i class="bi bi-check-circle-fill"></i>
                                Successfully Sent
                            </div>
                            <div class="value"><?= number_format($campaign->my_sent ?? 0) ?></div>
                        </div>
                        <div class="metric danger">
                            <div class="label">
                                <i class="bi bi-x-circle-fill"></i>
                                Send Failed
                            </div>
                            <div class="value"><?= number_format($campaign->my_failed ?? 0) ?></div>
                        </div>
                        <div class="metric">
                            <div class="label">
                                <i class="bi bi-hourglass-split"></i>
                                Pending
                            </div>
                            <div class="value"><?= number_format($campaign->my_remaining ?? 0) ?></div>
                        </div>
                    </div>

                    <div class="progress-wrap">
                        <div class="progress">
                            <?php
                            $assigned = (int)($campaign->my_assigned ?? 0);
                            $sent = (int)($campaign->my_sent ?? 0);
                            $percent = $assigned>0 ? min(100, round(($sent/$assigned)*100)) : 0;
                            ?>
                            <div class="progress-bar" role="progressbar" style="width:<?= $percent ?>%;"></div>
                        </div>
                    </div>

                    <div class="actions">
                        <a href="<?= base_url('user/campaign_view/' . $campaign->id) ?>" class="btn-gradient">
                            <i class="bi bi-eye-fill"></i>
                            Open Details
                        </a>
                        <!-- <a href="<?= base_url('user/send_logs/' . $campaign->id) ?>" class="btn-outline">
                            <i class="bi bi-clock-history"></i>
                            Activity History
                        </a> -->
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
    <?php else: ?>
        <div class="col-12">
            <p class="text-muted text-center py-5">
                <i class="bi bi-inbox" style="font-size: 64px; display: block; margin-bottom: 16px; opacity: 0.3;"></i>
                <strong style="display: block; font-size: 18px; margin-bottom: 8px;">No Campaigns Assigned</strong>
                No campaigns have been assigned to you yet. Please contact your administrator.
            </p>
        </div>
    <?php endif; ?>
</div>

<?php if ($pagination['total_pages'] > 1): ?>
    <nav>
        <ul class="pagination justify-content-center">
            <?php for ($i = 1; $i <= $pagination['total_pages']; $i++): ?>
                <li class="page-item <?= $i == $pagination['current_page'] ? 'active' : '' ?>">
                    <a class="page-link" href="<?= $pagination['base_url'] ?>?page=<?= $i ?>"><?= $i ?></a>
                </li>
            <?php endfor; ?>
        </ul>
    </nav>
<?php endif; ?>
