{{define "dashboard.html"}}
{{template "partials/header.html" .}}

<h1>Dashboard</h1>

<p class="user-info">
    Connect&eacute; en tant que <strong>{{.User.Username}}</strong>
    {{if .IsSuperAdmin}}(Super Admin){{else}}(App Admin){{end}}
</p>

<div class="card-grid">
    {{if .IsSuperAdmin}}
    <!-- Services Status (super admin only) -->
    <article>
        <header>
            <strong>Services</strong>
            <span class="htmx-indicator" aria-busy="true"></span>
        </header>
        <div hx-get="/admin/api/services/health"
             hx-trigger="load, every 30s"
             hx-indicator=".htmx-indicator">
            Chargement...
        </div>
    </article>
    {{end}}

    <!-- Applications -->
    <article>
        <header>
            <strong>Applications</strong>
            {{if .IsSuperAdmin}}
            <small>({{len .Apps}} apps)</small>
            {{end}}
        </header>
        <div hx-get="/admin/api/apps"
             hx-trigger="load">
            Chargement...
        </div>
    </article>

    {{if .IsSuperAdmin}}
    <!-- Quick Stats -->
    <article>
        <header><strong>Statistiques</strong></header>
        <dl>
            <dt>Applications</dt>
            <dd>{{len .Apps}}</dd>
        </dl>
    </article>
    {{end}}
</div>

{{if .IsSuperAdmin}}
<!-- Jobs Cron (super admin only) -->
<article>
    <header>
        <strong>Jobs Cron</strong>
        <span class="htmx-indicator" aria-busy="true"></span>
    </header>
    <div hx-get="/admin/api/cron/jobs"
         hx-trigger="load"
         hx-indicator=".htmx-indicator">
        Chargement...
    </div>
</article>
{{end}}

{{if not .IsSuperAdmin}}
<!-- Permissions de l'utilisateur -->
<article>
    <header><strong>Vos permissions</strong></header>
    <ul>
        {{range .Permissions}}
        <li><code>{{.}}</code></li>
        {{end}}
    </ul>
</article>
{{end}}

{{template "partials/footer.html" .}}
{{end}}
