<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>WarpBox Admin Settings</title>
        <link rel="icon" type="image/png" href="/static/WarpBoxLogo.png">
        <link rel="stylesheet" href="/static/css/app.css">
        <link rel="stylesheet" href="/static/css/window.css">
        <link rel="stylesheet" href="/static/css/admin.css">
    </head>
    <body>
        <main>
            <section class="win98-window admin-window" aria-labelledby="admin-settings-title">
                <header class="win98-titlebar">
                    <div class="win98-titlebar-label">
                        <img class="win98-titlebar-icon" src="/static/WarpBoxLogo.png" alt="" aria-hidden="true">
                        <h1 id="admin-settings-title">Settings</h1>
                    </div>
                </header>
                <div class="win98-panel admin-panel">
                    <nav class="admin-nav">
                        <a class="win98-button" href="/admin">Admin</a>
                        <a class="win98-button" href="/admin/boxes">Boxes</a>
                        <a class="win98-button" href="/admin/users">Users</a>
                        <a class="win98-button" href="/admin/tags">Tags</a>
                        <span class="admin-spacer"></span>
                        <span>{{ .CurrentUser }}</span>
                    </nav>
                    {{ if .Error }}
                        <p class="admin-error">{{ .Error }}</p>
					{{ end }}
					<form class="admin-form" action="/admin/settings" method="post">
						<input type="hidden" name="csrf_token" value="{{ .CSRFToken }}">
						<table class="admin-table">
                            <thead>
                                <tr>
                                    <th>Setting</th>
                                    <th>Value</th>
                                    <th>Source</th>
                                    <th>Env</th>
                                </tr>
                            </thead>
                            <tbody>
                                {{ range .Rows }}
                                    <tr>
                                        <td>{{ .Definition.Label }}{{ if .Definition.HardLimit }} (hard){{ end }}</td>
                                        <td>
                                            {{ if and $.OverridesAllowed .Definition.Editable }}
                                                {{ if eq .Definition.Type "bool" }}
                                                    <input type="checkbox" name="{{ .Definition.Key }}" value="true" {{ if eq .Value "true" }}checked{{ end }}>
                                                {{ else }}
                                                    <input name="{{ .Definition.Key }}" value="{{ .Value }}" inputmode="numeric">
                                                {{ end }}
                                            {{ else }}
                                                {{ .Value }}
                                            {{ end }}
                                        </td>
                                        <td>{{ .Source }}</td>
                                        <td>{{ .Definition.EnvName }}</td>
                                    </tr>
                                {{ end }}
                            </tbody>
                        </table>
                        {{ if .OverridesAllowed }}
                            <button class="win98-button" type="submit">Save Settings</button>
                        {{ end }}
                    </form>
                </div>
            </section>
        </main>
    </body>
</html>
