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

<h1>{{.App.App}}</h1>

<div class="card-grid">
    <!-- Infos générales -->
    <article>
        <header><strong>Informations</strong></header>
        <dl>
            <dt>Version</dt>
            <dd>{{if .App.Version}}{{.App.Version}}{{else}}<em>Non définie</em>{{end}}</dd>

            <dt>Base Path</dt>
            <dd><code>{{.App.BasePath}}</code></dd>

            <dt>Hosts</dt>
            <dd>
                {{range .App.Hosts}}
                <code>{{.}}</code><br>
                {{end}}
            </dd>
        </dl>
    </article>

    <!-- Database -->
    <article>
        <header><strong>Base de données</strong></header>
        <dl>
            <dt>Host</dt>
            <dd><code>{{.App.Database.Host}}:{{.App.Database.Port}}</code></dd>

            <dt>Database</dt>
            <dd><code>{{.App.Database.Name}}</code></dd>

            <dt>User</dt>
            <dd><code>{{.App.Database.User}}</code></dd>
        </dl>
        <form method="post" action="/admin/apps/{{.App.App}}/scan" style="margin-top: 1rem;">
            <input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
            <button type="submit" class="outline">Scanner la base</button>
        </form>
    </article>

    <!-- Stats -->
    <article>
        <header><strong>Configuration</strong></header>
        <dl>
            {{if .App.Schema}}
            <dt>Tables (schema)</dt>
            <dd>{{.App.SchemaTableCount}} tables</dd>
            {{end}}

            {{if .App.Queries}}
            <dt>Fichiers queries</dt>
            <dd>{{.App.QueriesCount}} fichiers</dd>
            {{end}}

            <dt>Routes</dt>
            <dd>{{.App.RoutesCount}} routes</dd>
        </dl>
    </article>
</div>

{{if .App.Schema}}
<!-- Schema / Tables -->
<article>
    <header><strong>Schema - Tables</strong></header>
    <table>
        <thead>
            <tr>
                <th>Table</th>
                <th>Colonnes</th>
                <th>PK</th>
                <th>Relations (FK)</th>
                <th>SD/C</th>
            </tr>
        </thead>
        <tbody>
            {{range .Tables}}
            <tr>
                <td><strong>{{.Name}}</strong></td>
                <td>{{.ColumnCount}}</td>
                <td><code>{{.PrimaryKey}}</code></td>
                <td>{{range .ForeignKeys}}<code>{{.}}</code><br>{{end}}</td>
                <td>{{if .SoftDelete}}*{{end}}{{if .Cascade}}↓{{end}}</td>
            </tr>
            {{end}}
        </tbody>
    </table>
    <footer>
        <small>PK = Clé primaire | FK = Clé étrangère | * = Soft Delete | ↓ = Cascade (supprime aussi les enfants)</small>
    </footer>
</article>
{{end}}

{{if .Routes}}
<!-- Routes -->
<article>
    <header><strong>Routes API</strong></header>
    <table>
        <thead>
            <tr>
                <th>Méthode</th>
                <th>Path</th>
                <th>Handler</th>
            </tr>
        </thead>
        <tbody>
            {{range .Routes}}
            <tr>
                <td><code>{{.Method}}</code></td>
                <td><code>{{.Path}}</code></td>
                <td>{{.Handler}}</td>
            </tr>
            {{end}}
        </tbody>
    </table>
</article>
{{end}}

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