{{$isAdmin := (eq .currentStaff.Rank 3) -}}
<table class="mgmt-table stafflist">
<tr><th>Username</th><th>Rank</th><th>Added on</th><th>Action</th></tr>
{{range $s, $staff := $.allstaff -}}
<tr>
	<td>{{$staff.Username}}</td>
	<td>{{$staff.RankTitle}}</td>
	<td>{{formatTimestamp $staff.AddedOn}}</td>
	<td>
		{{if or $isAdmin (eq $staff.Username $.currentStaff.Username) -}}
			<a href="{{webPath `/manage/staff`}}?update={{$staff.Username}}">Update</a>
		{{end}}{{if and $isAdmin (not (eq $staff.Username $.currentStaff.Username)) -}}
			<a
				href="{{webPath `/manage/staff`}}?do=del&username={{$staff.Username}}"
				title="Delete {{$staff.Username}}"
				onclick="return confirm('Are you sure you want to delete the staff account for \'{{$staff.Username}}\'?')"
				style="color:red;">Delete</a>
		{{- end}}
	</td>
</tr>
{{end}}
</table>

{{- if gt $.formMode 0 -}}
<hr />
<h2>{{$.formMode}}</h2>
{{- if eq $.formMode 2 -}}
<p>If the password fields are left blank, only the rank will be updated</p>
{{- end -}}
<form action="{{webPath `/manage/staff`}}" method="POST" autocomplete="off">
{{if lt $.formMode 3}}
<input type="hidden" name="update" value="{{.updateUsername}}">
<input type="hidden" name="do" value="update" />
{{else}}
<input type="hidden" name="do" value="add" />
{{end}}
<table>
	<tr><td>Username:</td><td><input name="username" type="text" autocomplete="new-password" value="{{if $isAdmin}}{{.updateUsername}}{{else}}{{.currentStaff.Username}}{{end}}" {{if lt $.formMode 3}}disabled{{end}}/></td></tr>
	<tr><td>Password:</td><td><input name="password" type="password" autocomplete="new-password" /></td></tr>
	<tr><td>Confirm password:</td><td><input id="passwordconfirm" name="passwordconfirm" type="password"/></td></tr>
	{{if gt $.formMode 1 -}}
	<tr><td>Rank:</td><td><select id="rank" name="rank">
		<option value="-1"{{if eq $.updateRank -1}}selected{{end}} disabled>Select one</option>
		<option value="3"{{if eq $.updateRank 3}}selected{{end}}>Admin</option>
		<option value="2"{{if eq $.updateRank 2}}selected{{end}}>Moderator</option>
		<option value="1"{{if eq $.updateRank 1}}selected{{end}}>Janitor</option>
	</select></td></tr>
	{{end -}}
	<tr><td>
		<input type="submit" value="{{if eq $.formMode 3}}Create{{else}}Update{{end}} User" />
		{{- if lt $.formMode 3 -}}
			<input type="button" name="docancel" value="Cancel" onclick="window.location = {{webPath `./manage/staff`}}; return false"/>
		{{- end -}}
	</td></tr>
</table>
</form>
{{end}}