<div class="pure-u-1">
    <div class="h-md-padding">
        <div class="overflow">

            {{ $E := .Error }}
            {{ if not (eq $E "") }}
                <div class="pure-form-group">
                    <p class="error-message">
                        {{ $E }}
                    </p>
                </div>
            {{ end }}

            <table class="pure-table pure-table-bordered">
                <thead>
                    <tr>
                        <th>
                            Username
                        </th>
                        <th>
                            Enabled
                        </th>
                        <th>
                            Has Password
                        </th>
                        <th>
                            Admin
                        </th>
                        <th>
                            Passcode (TOTP)
                        </th>
                        <th>
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {{ $csrf := .CSRF }}
                    {{ range .Users }}
                        <tr {{ if not .User.IsEnabled }}class="disabled"{{ end }}>
                            <td>
                                {{ .User.User }}
                            </td>
                            <td>
                                {{ .User.IsEnabled }}       
                            </td>
                            <td>
                                {{ .User.HasPassword }}
                            </td>
                            <td>
                                {{ .User.IsAdmin }}
                            </td>
                            <td>
                                {{ .User.IsTOTPEnabled }}
                            </td>
                            <td>
                                <div class="pure-button-group" role="group">
                                    <form action="/admin/users/toggleadmin" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button" value="{{ if .User.IsAdmin }}Remove Admin{{ else }} Make Admin{{ end }}">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/password" method="POST" class="pure-form pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="password" name="password" autocomplete="new-password"> &nbsp;
                                        <input type="submit" class="pure-button" value="Update Password">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/unsetpassword" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button" value="Unset Password">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/disable" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button" {{ if (not .User.IsEnabled) }}disabled{{ end }} value="Disable">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/disabletotp" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button" {{ if (not .User.IsTOTPEnabled) }}disabled{{ end }} value="Remove Passcode">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/delete" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button pure-button-danger" value="Delete">
                                        {{ $csrf }}
                                    </form>
                                    <form action="/admin/users/impersonate" method="POST" class="pure-form-group">
                                        <input type="hidden" name="user" value="{{ .User.User }}">
                                        <input type="submit" class="pure-button" {{ if (not .User.IsEnabled) }}disabled{{ end }} value="Impersonate">
                                        {{ $csrf }}
                                    </form>
                                </div>
                            </td>
                        </tr>
                    {{ end }}
                </tbody>
            </table>
        </div>
    </div>
</div>
