{{define "admin_settings.html"}}{{template "base" .}}{{end}}

{{define "content"}}
<section class="app-shell admin-shell" aria-labelledby="admin-settings-title">
  <aside class="app-sidebar">
    <nav class="sidebar-nav">
      <a class="sidebar-link" href="/admin">{{template "icon-dashboard" .}}<span>Overview</span></a>
      <a class="sidebar-link" href="/admin/files">{{template "icon-folder" .}}<span>Files</span></a>
      <a class="sidebar-link" href="/admin/users">{{template "icon-user-circle" .}}<span>Users</span></a>
      <a class="sidebar-link is-active" href="/admin/settings">{{template "icon-settings" .}}<span>Settings</span></a>
      <a class="sidebar-link" href="/admin/storage">{{template "icon-database" .}}<span>Storage</span></a>
      <a class="sidebar-link" href="/admin/logs">{{template "icon-database" .}}<span>Logs</span></a>
      <a class="sidebar-link" href="/admin/bans">{{template "icon-settings" .}}<span>Bans</span></a>
    </nav>
    <hr class="sidebar-sep">
    <nav class="sidebar-nav">
      <a class="sidebar-link" href="/app">{{template "icon-home-simple" .}}<span>My Files</span></a>
    </nav>
    <hr class="sidebar-sep">
    <form class="sidebar-logout" action="/admin/logout" method="post">
      <input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
      <button class="button button-outline" type="submit">{{template "icon-log-out" .}}<span>Sign out</span></button>
    </form>
  </aside>

  <div class="app-main">
    <div class="admin-header">
      <div>
        <p class="kicker">Operator console</p>
        <h1 id="admin-settings-title">{{.Data.PageTitle}}</h1>
      </div>
    </div>

    <div class="card admin-table-card">
      <div class="card-content">
        <div class="table-header">
          <div>
            <h2>Upload policy</h2>
            <p>Admin users bypass all upload caps. Values are in megabytes; use -1 for unlimited upload size or daily upload caps.</p>
          </div>
        </div>

        <form class="settings-form" action="/admin/settings" method="post">
          <input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
          <div class="settings-section">
            <h3 class="settings-section-title">Anonymous uploads</h3>
            <label class="checkbox-field">
              <input type="checkbox" name="anonymous_uploads_enabled" {{if .Data.Settings.AnonymousUploadsEnabled}}checked{{end}}>
              <span>Allow anonymous uploads</span>
            </label>
            <label>
              <span>Max upload size (MB)</span>
              <input name="anonymous_max_upload_mb" value="{{.Data.Settings.AnonymousMaxUploadMB}}" required>
            </label>
            <label>
              <span>Daily cap per IP (MB)</span>
              <input name="anonymous_daily_upload_mb" value="{{.Data.Settings.AnonymousDailyUploadMB}}" required>
            </label>
            <label>
              <span>Daily boxes per IP</span>
              <input type="number" name="anonymous_daily_boxes" min="1" value="{{.Data.Settings.AnonymousDailyBoxes}}" required>
            </label>
            <label>
              <span>Active boxes per IP</span>
              <input type="number" name="anonymous_active_boxes" min="1" value="{{.Data.Settings.AnonymousActiveBoxes}}" required>
            </label>
            <label>
              <span>Max expiration (days)</span>
              <input type="number" name="anonymous_max_days" min="1" value="{{.Data.Settings.AnonymousMaxDays}}" required>
            </label>
            <label>
              <span>Anonymous storage backend</span>
              <select name="anonymous_storage_backend" required>
                {{range .Data.Storage}}
                  {{if or .Config.Enabled (eq $.Data.Settings.AnonymousStorageBackend .Config.ID)}}<option value="{{.Config.ID}}" {{if eq $.Data.Settings.AnonymousStorageBackend .Config.ID}}selected{{end}}>{{.Config.Name}} ({{.Config.ID}})</option>{{end}}
                {{end}}
              </select>
            </label>
          </div>

          <div class="settings-section">
            <h3 class="settings-section-title">User limits</h3>
            <label>
              <span>Daily upload cap (MB)</span>
              <input name="user_daily_upload_mb" value="{{.Data.Settings.UserDailyUploadMB}}" required>
            </label>
            <label>
              <span>Default storage quota (MB)</span>
              <input name="default_user_storage_mb" value="{{.Data.Settings.DefaultUserStorageMB}}" required>
            </label>
            <label>
              <span>Usage retention (days)</span>
              <input type="number" name="usage_retention_days" min="1" value="{{.Data.Settings.UsageRetentionDays}}" required>
            </label>
            <label>
              <span>Daily boxes</span>
              <input type="number" name="user_daily_boxes" min="1" value="{{.Data.Settings.UserDailyBoxes}}" required>
            </label>
            <label>
              <span>Active boxes</span>
              <input type="number" name="user_active_boxes" min="1" value="{{.Data.Settings.UserActiveBoxes}}" required>
            </label>
            <label>
              <span>Max expiration (days)</span>
              <input type="number" name="user_max_days" min="1" value="{{.Data.Settings.UserMaxDays}}" required>
            </label>
            <label>
              <span>User storage backend</span>
              <select name="user_storage_backend" required>
                {{range .Data.Storage}}
                  {{if or .Config.Enabled (eq $.Data.Settings.UserStorageBackend .Config.ID)}}<option value="{{.Config.ID}}" {{if eq $.Data.Settings.UserStorageBackend .Config.ID}}selected{{end}}>{{.Config.Name}} ({{.Config.ID}})</option>{{end}}
                {{end}}
              </select>
            </label>
            <label>
              <span>Local storage max (GB)</span>
              <input name="local_storage_max_gb" value="{{.Data.Settings.LocalStorageMaxGB}}" required>
            </label>
            <label>
              <span>Short-window requests</span>
              <input type="number" name="short_window_requests" min="1" value="{{.Data.Settings.ShortWindowRequests}}" required>
            </label>
            <label>
              <span>Short-window seconds</span>
              <input type="number" name="short_window_seconds" min="1" value="{{.Data.Settings.ShortWindowSeconds}}" required>
            </label>
          </div>

          <button class="button button-primary" type="submit">Save settings</button>
        </form>
      </div>
    </div>
  </div>
</section>
{{end}}
