<div class="stats-component">
    <div class="stats-header">
        <h3>📊 Live Statistics</h3>
        <div class="stats-controls">
            <button data-live-action="refresh" class="btn-refresh">
                🔄 Refresh
            </button>
            <button data-live-action="toggleCache" class="btn-toggle">
                <if condition="cache_enabled">🔒 Disable Cache</if>
                <if condition="!cache_enabled">🔓 Enable Cache</if>
            </button>
        </div>
    </div>

    <div class="stats-grid">
        <div class="stat-card">
            <div class="stat-value">{{stats.total_users}}</div>
            <div class="stat-label">Total Users</div>
        </div>

        <div class="stat-card">
            <div class="stat-value">{{stats.active_sessions}}</div>
            <div class="stat-label">Active Sessions</div>
        </div>

        <div class="stat-card">
            <div class="stat-value">{{stats.total_orders}}</div>
            <div class="stat-label">Total Orders</div>
        </div>

        <div class="stat-card">
            <div class="stat-value">${{stats.revenue}}</div>
            <div class="stat-label">Revenue</div>
        </div>
    </div>

    <div class="stats-footer">
        <div class="stats-info">
            <span>Cache: <if condition="cache_enabled">Enabled ✅</if><if condition="!cache_enabled">Disabled ❌</if></span>
            <span>Last Update: {{last_update}}</span>
            <span>Render Count: {{render_count}}</span>
        </div>
        <div class="stats-meta">
            <small style="color: #999;">Computed at: {{stats.computed_at}}</small>
        </div>
    </div>
</div>

<style>
.stats-component {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.stats-header h3 {
    margin: 0;
    color: #333;
}

.stats-controls {
    display: flex;
    gap: 0.5rem;
}

.stats-controls button {
    background: #2196F3;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-refresh {
    background: #4CAF50 !important;
}

.btn-refresh:hover {
    background: #45a049 !important;
}

.btn-toggle {
    background: #FF9800 !important;
}

.btn-toggle:hover {
    background: #F57C00 !important;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: #f5f5f5;
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: #2196F3;
    margin-bottom: 0.5rem;
}

.stat-label {
    color: #666;
    font-size: 0.875rem;
}

.stats-footer {
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

.stats-info {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.875rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.stats-meta {
    font-size: 0.75rem;
}
</style>
