{{define "workspaces.html"}}
{{template "shell-start" .}}
<header class="page-head"><div><p class="eyebrow">ADMIN</p><h1>Workspaces</h1><p>Create separate spaces for teams and switch between them.</p></div></header>
{{template "notice" .}}
<div class="two-column users-layout">
  <section class="card form-card"><p class="eyebrow">NEW WORKSPACE</p><h2>Create a workspace</h2>
    <form method="post" action="/admin/workspaces" class="stack-form"><input type="hidden" name="csrf" value="{{.CSRF}}">
      <label>Workspace name<input name="name" required maxlength="100" placeholder="Product team"></label>
      <label>Workspace slug<input name="slug" required maxlength="60" pattern="[a-z0-9-]+" placeholder="product-team"><small>Lowercase letters, numbers, and hyphens.</small></label>
      <button class="button primary full">Create workspace</button>
    </form>
  </section>
  <section class="card"><header class="section-head"><div><p class="eyebrow">YOUR SPACES</p><h2>{{len .Workspaces}} workspaces</h2></div></header>
    <div class="user-list workspace-list">{{range .Workspaces}}<div class="user-row"><span class="avatar">▣</span><div><strong>{{.Name}}</strong><small>{{.Slug}}</small></div>{{if eq .ID $.Workspace.ID}}<span class="badge approved">Current</span>{{else}}<form method="post" action="/workspace/switch"><input type="hidden" name="csrf" value="{{$.CSRF}}"><input type="hidden" name="workspace_id" value="{{.ID}}"><button class="text-button" type="submit">Switch</button></form>{{end}}</div>{{end}}</div>
  </section>
  {{if .Workspace.ID}}<section class="card workspace-access-card"><p class="eyebrow">WORKSPACE ACCESS</p><h2>Manage members</h2><form method="get" action="/admin/workspaces" class="workspace-access-select"><label>Workspace<select name="workspace" data-workspace-access-switch>{{range .Workspaces}}<option value="{{.ID}}" {{if eq .ID $.Workspace.ID}}selected{{end}}>{{.Name}}</option>{{end}}</select></label></form><p class="muted">Select the people who should be able to open <strong>{{.Workspace.Name}}</strong>.</p><form method="post" action="/admin/workspaces/{{.Workspace.ID}}/members" class="workspace-members-form"><input type="hidden" name="csrf" value="{{.CSRF}}"><input type="hidden" name="workspace_id" value="{{.Workspace.ID}}">{{range .Users}}<label><input type="checkbox" name="user_ids" value="{{.ID}}" {{if index $.WorkspaceMembers .ID}}checked{{end}}><span class="avatar">{{initial .DisplayName}}</span><span>{{.DisplayName}}<small>@{{.Username}}</small></span></label>{{end}}<button class="button primary" type="submit">Save members</button></form></section>{{end}}
</div>
{{template "shell-end" .}}
{{end}}
