{{define "users.html"}}
{{template "shell-start" .}}
<header class="page-head">
  <div><p class="eyebrow">ADMIN</p><h1>Teammates</h1><p>Create local accounts and see who has access.</p></div>
</header>
{{template "notice" .}}
<div class="two-column users-layout">
  <section class="card form-card">
    <p class="eyebrow">NEW ACCOUNT</p><h2>Add a teammate</h2>
    <form method="post" action="/admin/users" class="stack-form">
      <input type="hidden" name="csrf" value="{{.CSRF}}">
      <label>Full name<input name="display_name" required maxlength="100" placeholder="Navid Somthingi"></label>
      <div class="form-row">
        <label>Username<input name="username" required maxlength="40" autocomplete="off" placeholder="navid"></label>
        <label>Email <small>Optional</small><input type="email" name="email" maxlength="200" placeholder="navid@example.com"></label>
      </div>
      <label>Temporary password<input type="password" name="password" minlength="8" required autocomplete="new-password" placeholder="At least 8 characters"></label>
      <label>Access level
        <select name="role"><option value="member">Member</option><option value="admin">Admin</option></select>
      </label>
      <button class="button primary full">Create account</button>
    </form>
  </section>
  <section class="card">
    <header class="section-head"><div><p class="eyebrow">DIRECTORY</p><h2>{{len .Users}} teammates</h2></div></header>
    <div class="user-list">
      {{$current := .User}}
      {{range .Users}}
      <div class="user-row {{if not .Active}}inactive{{end}}">
        <span class="avatar">{{initial .DisplayName}}</span>
        <div><strong>{{.DisplayName}}</strong><small>@{{.Username}}{{if .Email}} · {{.Email}}{{end}}</small></div>
        <div class="user-badges">
          <span class="badge {{if eq .Role "admin"}}approved{{else}}kind{{end}}">{{.Role}}</span>
          {{if not .Active}}<span class="badge locked">Locked</span>{{end}}
        </div>
        {{if eq .ID $current.ID}}
        <small class="current-account">Current account</small>
        {{else}}
        <div class="account-actions">
        <form method="post" action="/admin/users/{{.ID}}/status" class="account-status-form">
          <input type="hidden" name="csrf" value="{{$.CSRF}}">
          {{if .Active}}
          <input type="hidden" name="action" value="lock">
          <button class="text-button lock-account" type="submit">Lock</button>
          {{else}}
          <input type="hidden" name="action" value="unlock">
          <button class="text-button unlock-account" type="submit">Unlock</button>
          {{end}}
        </form>
        <details class="account-manage">
          <summary class="text-button">Manage</summary>
          <form method="post" action="/admin/users/{{.ID}}/password" class="account-password-form">
            <input type="hidden" name="csrf" value="{{$.CSRF}}">
            <label>New password<input type="password" name="password" minlength="8" required autocomplete="new-password"></label>
            <label>Confirm password<input type="password" name="password_confirm" minlength="8" required autocomplete="new-password"></label>
            <button class="text-button" type="submit">Change password</button>
          </form>
          <form method="post" action="/admin/users/{{.ID}}/delete" class="account-delete-form">
            <input type="hidden" name="csrf" value="{{$.CSRF}}">
            <button class="text-button delete-account" type="submit">Delete account</button>
          </form>
        </details>
        </div>
        {{end}}
      </div>
      {{end}}
    </div>
  </section>
</div>
{{template "shell-end" .}}
{{end}}
