<layout name="admin" />
<!-- Cache invalidation: 2025-01-20 16:11 -->
<div class="section">
    <h2>{{ title }}</h2>

    <div class="admin-card">
        <div class="admin-card__header">
            <h3 class="admin-card__title">System Overview</h3>
        </div>
        <div class="admin-card__content">
            <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-md); margin-bottom: var(--space-lg);">
                <div class="metric-card">
                    <div class="metric-card__value" style="color: var(--success);">
                        {{ overall_status }}
                    </div>
                    <div class="metric-card__label">Overall Status</div>
                </div>
                <div class="metric-card">
                    <div class="metric-card__value">{{ total_checks }}</div>
                    <div class="metric-card__label">Total Checks</div>
                </div>
                <div class="metric-card">
                    <div class="metric-card__value" style="color: var(--success);">{{ healthy_checks }}</div>
                    <div class="metric-card__label">Healthy</div>
                </div>
                <div class="metric-card">
                    <div class="metric-card__value" style="color: var(--warning);">{{ warning_checks }}</div>
                    <div class="metric-card__label">Warnings</div>
                </div>
                <div class="metric-card">
                    <div class="metric-card__value" style="color: var(--error);">{{ failed_checks }}</div>
                    <div class="metric-card__label">Failed</div>
                </div>
            </div>
        </div>
    </div>

    <div class="admin-card" style="margin-top: var(--space-lg);">
        <div class="admin-card__header">
            <h3 class="admin-card__title">Health Check Details</h3>
            <button class="admin-button admin-button--small" onclick="refreshHealthChecks()" style="margin-left: auto;">
                🔄 Refresh
            </button>
        </div>
        <table-data source="health_check_table" container-class="admin-card" />
    </div>
</div>

<script>
function toggleDetails(id) {
    const element = document.getElementById(id);
    if (element) {
        element.style.display = element.style.display === 'none' ? 'table-row' : 'none';
    }
}

function refreshHealthChecks() {
    window.location.reload();
}

// Auto-refresh health status every 60 seconds
setInterval(function() {
    window.location.reload();
}, 60000);
</script>

<style>
.metric-card {
    text-align: center;
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-alt);
}

.metric-card__value {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.metric-card__label {
    color: var(--muted);
    font-size: 0.875rem;
}

.admin-table__action {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: opacity 0.2s;
}

.admin-table__action:hover {
    opacity: 0.8;
}

.admin-table__status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

.admin-table__status--success {
    background-color: rgba(16, 185, 129, 0.1);
    color: rgb(16, 185, 129);
}

.admin-table__status--warning {
    background-color: rgba(245, 158, 11, 0.1);
    color: rgb(245, 158, 11);
}

.admin-table__status--error {
    background-color: rgba(239, 68, 68, 0.1);
    color: rgb(239, 68, 68);
}

.admin-table__status--unknown {
    background-color: rgba(107, 114, 128, 0.1);
    color: rgb(107, 114, 128);
}
</style>
