@page "/settings"
@inherits DashboardPageBase

<PageTitle>Dashboard Settings</PageTitle>

@if (Snapshot is null)
{
    <div class="empty-state">Loading settings.</div>
}
else
{
    <div class="dashboard-page-header">
        <div>
            <h1>Settings</h1>
            <div class="text-secondary">Effective gateway configuration</div>
        </div>
    </div>

    <section class="dashboard-section">
        <div class="table-responsive">
            <table class="table table-sm dashboard-table details-table">
                <tbody>
                    <tr><th scope="row">Authentication mode</th><td>@Snapshot.Configuration.Authentication.Mode</td></tr>
                    <tr><th scope="row">Auth database</th><td><code>@Snapshot.Configuration.Authentication.SqlitePath</code></td></tr>
                    <tr><th scope="row">Pepper secret</th><td>@Snapshot.Configuration.Authentication.PepperSecretName</td></tr>
                    <tr><th scope="row">Run migrations</th><td>@Snapshot.Configuration.Authentication.RunMigrationsOnStartup</td></tr>
                    <tr><th scope="row">LDAP enabled</th><td>@Snapshot.Configuration.Ldap.Enabled</td></tr>
                    <tr><th scope="row">LDAP server</th><td>@Snapshot.Configuration.Ldap.Server:@Snapshot.Configuration.Ldap.Port</td></tr>
                    <tr>
                        <th scope="row">LDAP fallback servers</th>
                        @* Rendered even when empty: "none" is the operationally interesting answer
                           on a host someone believes has a backup DC configured. *@
                        <td>
                            @if (Snapshot.Configuration.Ldap.FallbackServers.Count == 0)
                            {
                                <span class="text-muted">none</span>
                            }
                            else
                            {
                                <code>@string.Join(", ", Snapshot.Configuration.Ldap.FallbackServers)</code>
                            }
                        </td>
                    </tr>
                    <tr><th scope="row">LDAP transport</th><td>@Snapshot.Configuration.Ldap.Transport</td></tr>
                    <tr><th scope="row">LDAP search base</th><td><code>@Snapshot.Configuration.Ldap.SearchBase</code></td></tr>
                    <tr><th scope="row">LDAP service account</th><td><code>@Snapshot.Configuration.Ldap.ServiceAccountDn</code></td></tr>
                    <tr><th scope="row">LDAP service password</th><td>@Snapshot.Configuration.Ldap.ServiceAccountPassword</td></tr>
                    <tr><th scope="row">LDAP username attribute</th><td>@Snapshot.Configuration.Ldap.UserNameAttribute</td></tr>
                    <tr><th scope="row">LDAP group attribute</th><td>@Snapshot.Configuration.Ldap.GroupAttribute</td></tr>
                    <tr>
                        <th scope="row">Dashboard role mapping</th>
                        <td>
                            @if (Snapshot.Configuration.Dashboard.GroupToRole.Count == 0)
                            {
                                <span class="text-muted">(none configured)</span>
                            }
                            else
                            {
                                <ul class="mb-0">
                                    @foreach (KeyValuePair<string, string> pair in Snapshot.Configuration.Dashboard.GroupToRole)
                                    {
                                        <li><code>@pair.Key</code> → @pair.Value</li>
                                    }
                                </ul>
                            }
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Dashboard tag mapping</th>
                        @* Group and tag NAMES are configuration, not tag values — the redaction
                           rule does not reach them, and an operator asking why a Viewer sees no
                           sessions needs this map as much as the role map above it. *@
                        <td>
                            @if (Snapshot.Configuration.Dashboard.GroupToTag.Count == 0)
                            {
                                <span class="text-muted">(none configured)</span>
                            }
                            else
                            {
                                <ul class="mb-0">
                                    @foreach (KeyValuePair<string, IReadOnlyList<string>> pair in Snapshot.Configuration.Dashboard.GroupToTag)
                                    {
                                        <li><code>@pair.Key</code> → @string.Join(", ", pair.Value)</li>
                                    }
                                </ul>
                            }
                        </td>
                    </tr>
                    <tr><th scope="row">Worker executable</th><td><code>@Snapshot.Configuration.Worker.ExecutablePath</code></td></tr>
                    <tr><th scope="row">Worker architecture</th><td>@Snapshot.Configuration.Worker.RequiredArchitecture</td></tr>
                    <tr><th scope="row">Startup timeout</th><td>@Snapshot.Configuration.Worker.StartupTimeoutSeconds seconds</td></tr>
                    <tr><th scope="row">Shutdown timeout</th><td>@Snapshot.Configuration.Worker.ShutdownTimeoutSeconds seconds</td></tr>
                    <tr><th scope="row">Heartbeat grace</th><td>@Snapshot.Configuration.Worker.HeartbeatGraceSeconds seconds</td></tr>
                    <tr><th scope="row">Default command timeout</th><td>@Snapshot.Configuration.Sessions.DefaultCommandTimeoutSeconds seconds</td></tr>
                    <tr><th scope="row">Max sessions</th><td>@Snapshot.Configuration.Sessions.MaxSessions</td></tr>
                    <tr><th scope="row">Event queue capacity</th><td>@Snapshot.Configuration.Events.QueueCapacity</td></tr>
                    <tr><th scope="row">Backpressure policy</th><td>@Snapshot.Configuration.Events.BackpressurePolicy</td></tr>
                    <tr><th scope="row">Dashboard enabled</th><td>@Snapshot.Configuration.Dashboard.Enabled</td></tr>
                    <tr><th scope="row">Anonymous localhost</th><td>@Snapshot.Configuration.Dashboard.AllowAnonymousLocalhost</td></tr>
                    <tr><th scope="row">Snapshot interval</th><td>@Snapshot.Configuration.Dashboard.SnapshotIntervalMilliseconds ms</td></tr>
                    <tr><th scope="row">Show tag values</th><td>@Snapshot.Configuration.Dashboard.ShowTagValues</td></tr>
                    <tr><th scope="row">Untagged session visibility</th><td>@Snapshot.Configuration.Dashboard.UntaggedSessionVisibility</td></tr>
                    <tr><th scope="row">Worker protocol</th><td>@Snapshot.Configuration.Protocol.WorkerProtocolVersion</td></tr>
                </tbody>
            </table>
        </div>
    </section>
}
