<?php if (!defined('ABSPATH')) exit; ?>

<div class="linkfiliate-stats">
    <div class="linkfiliate-card">
        <h4>Last 24 Hours</h4>
        <div class="linkfiliate-metrics">
            <div class="metric">
                <strong><?php echo esc_html($data['total_24h'] ?? 0); ?></strong>
                <span>Total Clicks</span>
            </div>
            <div class="metric">
                <strong><?php echo esc_html($data['unique_24h'] ?? 0); ?></strong>
                <span>Unique Clicks</span>
            </div>
        </div>
    </div>

    <div class="linkfiliate-card">
        <h4>Last 7 Days</h4>
        <div class="linkfiliate-metrics">
            <div class="metric">
                <strong><?php echo esc_html($data['total_7d'] ?? 0); ?></strong>
                <span>Total Clicks</span>
            </div>
            <div class="metric">
                <strong><?php echo esc_html($data['unique_7d'] ?? 0); ?></strong>
                <span>Unique Clicks</span>
            </div>
        </div>
    </div>
</div>

<div class="linkfiliate-popular">
    <h4>🔥 Most Popular Links (7 Days)</h4>
    <table>
        <?php if (empty($data['popular_links'])): ?>
            <tr>
                <td colspan="2" style="text-align:center;padding:24px;color:#9ca3af;">
                    No clicks recorded yet. Start sharing your links!
                </td>
            </tr>
        <?php else: ?>
            <?php foreach ($data['popular_links'] as $link): ?>
                <tr>
                    <td>
                        <a href="<?php echo esc_url(admin_url('admin.php?page=linkfiliate#/campaign/edit/' . $link['id'])); ?>" target="_blank">
                            <?php echo esc_html($link['name'] ?: $link['slug']); ?>
                        </a>
                    </td>
                    <td style="text-align:right;">
                        <span class="click-count"><?php echo esc_html($link['total_clicks']); ?> clicks</span>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php endif; ?>
    </table>
</div>

<div class="linkfiliate-footer">
    <div class="button-group">
        <a href="<?php echo esc_url(admin_url('admin.php?page=linkfiliate')); ?>" class="linkfiliate-footer-btn linkfiliate-btn-primary">View Full Analytics</a>
        <a href="<?php echo esc_url(admin_url('admin.php?page=linkfiliate#/campaign/new')); ?>" class="linkfiliate-footer-btn linkfiliate-btn-secondary">+ Add New Link</a>
    </div>
</div>