{{ template "_base.html" . }}
{{ define "title" }}User{{ end }}

{{ define "header"}}
<p>
    <a class="pure-button pure-button-primary" href="/user/">{{ .User.User }}</a>
</p>
<p>
    <a class="pure-button pure-button-small" href="/auth/logout/">Logout</a>
</p>
{{ end }}

{{ define "content" }}
<div class="pure-u-1">
    <p>
        <ul>
            {{ if .User.IsAdmin }}
                <li>Role: <b>Administrator</b></li>
            {{ else }}
                <li>Role: <b>Regular User</b></li>
            {{ end }}

            {{ if .User.IsTOTPEnabled }}
                <li>Passcode Enabled: <b>true</b></li>
            {{ else }}
                <li>Passcode Enabled: <b>false</b>  {{ if .User.IsAdmin }}<small>(some admin actions are disabled)</small>{{ end }}</li>
            {{ end }}
        </ul>
    </p>
    <div class="pure-button-group" role="group" role="Actions">
        <a class="pure-button" href="/user/password/">Change Password</a>
        {{ if .User.IsTOTPEnabled }}
            <a class="pure-button" href="/user/totp/disable/">Disable Passcode (TOTP)</a>
        {{ else }}
            <a class="pure-button" href="/user/totp/enable/">Enable Passcode (TOTP)</a>
        {{ end }}
    </div>
    <hr /> 
</div>

{{ if .User.IsAdmin }}
<div class="pure-u-1">
    {{ if (not .User.IsTOTPEnabled) }}
    <div>
        <p class="error-message">
            TOTP is required to access these.
        </p>
    </div>
    {{ end }}
    <div class="pure-button-group" role="group" role="Actions">
        <a class="pure-button" href="/admin/">Distillery Admin Page</a>
    </div>
    <hr />
</div>
{{ end }}

<div class="pure-u-1">
    <h2>Your WissKIs</h2>
    <p>
        This is a page of WissKIs you have access to.
        Click on the button containing the name to login.
    </p>
</div>
<div class="pure-u-1">
    <div class="padding">
        <div class="overflow">
            <table class="pure-table pure-table-bordered pure-form">
                <thead>
                    <tr>
                        <th>
                            WissKI Slug
                        </th>
                        <th>
                            Drupal Username
                        </th>
                        <th>
                            Admin
                        </th>
                    </tr>
                </thead>
                <tbody>
                    {{ range $id, $grant := .Grants }}
                    <tr>
                        <td>
                            <a href="{{ $grant.URL }}" class="pure-button" target="_blank" rel="noopener noreferer">
                                {{ $grant.Slug }}
                            </a>
                        </td>
                        <td>
                            {{ $grant.DrupalUsername }}
                        </td>
                        <td>
                            {{ $grant.DrupalAdminRole }}
                        </td>
                    </tr>
                    {{ end }}
                </tbody>
            </table>
        </div>
    </div>
</div>

{{ end }}