{% extends '__layout__.html' %}
{% block title %}Admin{% endblock %}
{% block head %}
<link href="/static/css/admin.css" rel="stylesheet"/> <!-- Its just easier to resuse this-->
<style>
    .show-on-hover {
        filter: blur(4px);
        transition: 0.2s;
    }
    .show-on-hover:hover {
        filter: blur(0px);
        transition: 0.2s;
    }
</style>
{% endblock %}
{% block content %}
<div id="main">
    <div class="container" style="min-width: 1100px;">
        <div class="d-flex">
            <a href="/admin/manage-users" class="btn border-success btn-sm mb-2">Back to User Manager</a>
            <a href="/users/{{userObj.id}}/profile" class="btn border-primary btn-sm mb-2 ms-3">View user profile</a>
        </div>
        {% with messages = get_flashed_messages() %}
        {% if messages %}
        <div>
        {% for message in messages %}
            <div class="alert alert-danger p-2 text-center">
                {{ message }}
            </div>
        {% endfor %}
        </div>
        {% endif %}
        {% endwith %}
        <div class="row">
            <div class="col-3">
                <div class="border rounded-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <div class="d-flex align-items-center">
                            <img width="30px" height="30px" class="rounded me-2" src="/Thumbs/Head.ashx?x=48&y=48&userId={{userObj.id}}" style="aspect-ratio: 1/1;">
                            <h5 class="m-0">{{userObj.username}}</h5>
                        </div>
                    </div>
                    <img width="100%" class="p-2" src="/Thumbs/Avatar.ashx?x=420&y=420&userId={{userObj.id}}" style="aspect-ratio: 1/1;">
                    {% if isAdministrator: %}
                    <div class="border-top" style="background-color: rgba(24, 220, 255,0.5);font-size:12px;padding:3px;">
                        <p class="m-0 fw-bold text-body text-center">Administrator</p>
                    </div>
                    {% endif %}
                    {% if userObj.accountstatus == 2: %}
                    <div class="border-top" style="background-color: rgba(255, 201, 24, 0.5);font-size:12px;padding:3px;">
                        <p class="m-0 fw-bold text-body text-center">This account is temporarily banned</p>
                    </div>
                    {% endif %}
                    {% if userObj.accountstatus == 3: %}
                    <div class="border-top" style="background-color: rgba(255, 24, 24, 0.5);font-size:12px;padding:3px;">
                        <p class="m-0 fw-bold text-body text-center">This account has been deleted</p>
                    </div>
                    {% endif %}
                    {% if userObj.accountstatus == 4: %}
                    <div class="border-top" style="background-color: rgba(255, 24, 243, 0.5);font-size:12px;padding:3px;">
                        <p class="m-0 fw-bold text-body text-center">This account is GDPR deleted</p>
                    </div>
                    {% endif %}
                    <div class="bg-surface p-2 rounded-2 rounded-top-0 border-top text-secondary" style="font-size: 13px;">
                        <span>Created: <span class="text-body">{{userObj.created}}</span></span>
                        <br>
                        <span>Last Online: <span class="text-body">{{userObj.lastonline}}</span></span>
                        <br>
                        <span>2FA Enabled: <span class="text-body">{{userObj.TOTPEnabled}}</span></span>
                        <br>
                        <span>Place Visits: <span class="text-body">{{TotalVisits}}</span></span>
                    </div>
                </div>
                <div class="border rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Economy</h5>
                    </div>
                    <div class="text-secondary p-2 pt-1" style="font-size: 13px;">
                        <span>Robux: <span class="text-success fw-bold">R${{UserEconomyObj.robux}}</span></span>
                        <br>
                        <span>Tickets: <span class="text-warning fw-bold">T${{UserEconomyObj.tix}}</span></span>
                    </div>
                </div>
            </div>
            <div class="col-7">
                {% if LastestUserBanObj != None: %}
                <div class="border rounded-2 mb-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Ban Information</h5>
                    </div>
                    <div class="p-2 text-secondary text-truncate" style="font-size: 14px;">
                        <span>Ban Type: <span class="text-body">{{LastestUserBanObj.ban_type.name}}</span></span>
                        <br>
                        <span>Banned On: <span class="text-body">{{LastestUserBanObj.created_at}}</span></span>
                        <br>
                        <span>Expires On: <span class="text-body">{{LastestUserBanObj.expires_at}}</span></span>
                        <br>
                        <span>Reason: <span class="text-body">{{LastestUserBanObj.reason}}</span></span>
                        <br>
                        <span>Moderator Note: <span class="text-body" style="word-break: break-all;white-space: normal;">{{LastestUserBanObj.moderator_note}}</span></span>
                        <br>
                        <span>Banned By: <a class="text-decoration-underline text-primary" href="/admin/manage-users/{{LastestUserBanObj.author_userid}}">{{LastestUserBanObj.author_userid}}</a></span>
                    </div>
                </div>
                {%endif%}
                <div class="border rounded-2" style="min-height: 150px;">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Description</h5>
                    </div>
                    <div class="p-2">
                        {% for line in DescriptionLines %}
                            <p class="text-body m-0">{{line}}</p>
                        {% endfor %}
                    </div>
                </div>
                {% if LastLogin != None: %}
                <div class="border rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Latest Login</h5>
                    </div>
                    <div class="p-2 text-secondary text-truncate" style="font-size: 14px;">
                        <span>User-Agent: <span class="text-body">{{LastLogin.useragent}}</span></span>
                        <br>
                        <span>Login Timestamp: <span class="text-body">{{LastLogin.timestamp}}</span></span>
                    </div>
                </div>
                {%endif%}
                {% if LinkedDiscordObj != None: %}
                <div class="border rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Discord Account</h5>
                    </div>
                    <div class="p-2 text-secondary text-truncate" style="font-size: 14px;">
                        <div class="row">
                            <div class="col-10">
                                <span>Discord ID: <span class="text-body">{{DiscordUserInfo.UserId}}</span></span>
                                <br>
                                <span>Username: <span class="text-body">{{DiscordUserInfo.Username}}</span></span>
                                <br>
                                <span>Discriminator: <span class="text-body">{{DiscordUserInfo.Discriminator}}</span></span>
                                <br>
                                <span>Linked On: <span class="text-body">{{LinkedDiscordObj.linked_on}}</span></span>
                                <br>
                                <span>Last Refresh: <span class="text-body">{{LinkedDiscordObj.last_updated}}</span></span>
                            </div>
                            <div class="col-2">
                                <img width="100%" style="aspect-ratio: 1/1;" class="border rounded" src="{{DiscordUserInfo.GetAvatarURL()}}">
                            </div>
                        </div>
                    </div>
                </div>
                {%endif%}
                {% if InviteKeyUsed != None: %}
                <div class="border rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0 border-bottom">
                        <h5 class="m-0">Invite Key Info</h5>
                    </div>
                    <div class="p-2 text-secondary text-truncate" style="font-size: 14px;">
                        <span>Invite Key: <span class="text-body show-on-hover">{{InviteKeyUsed.key}}</span></span>
                        <br>
                        <span>Creator: {% if InviteKeyUsed.created_by != None: %}<a class="text-decoration-none text-primary" href="/admin/manage-users/{{InviteKeyUsed.created_by}}">{{InviteKeyUsed.creator.username}}</a>{%else%}<span class="text-body">Unknown</span>{%endif%}</span>
                        <br>
                        <span>Created At: <span class="text-body">{{InviteKeyUsed.created_at}}</span></span>
                    </div>
                </div>
                {%endif%}
            </div>
            <div class="col-2">
                <div class="border rounded-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0">
                        <h5 class="m-0">Actions</h5>
                    </div>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/ban-user"><i class="bi bi-hammer"></i> Ban User</a>
                    <form method="post" action="/admin/manage-users/{{userObj.id}}/reset-username" class="m-0">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn border-top rounded-0 w-100 text-start text-body"><i class="bi bi-person-x"></i> Reset Username</button>
                    </form>
                    <form method="post" action="/admin/manage-users/{{userObj.id}}/reset-bio" class="m-0">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn border-top rounded-0 w-100 text-start text-body"><i class="bi bi-pencil-square"></i> Reset Bio</button>
                    </form>
                    <form method="post" action="/admin/manage-users/{{userObj.id}}/reset-password" class="m-0" onsubmit="return confirm('Reset the password for {{userObj.username}}? This will also log them out everywhere.');">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                        <button type="submit" class="btn border-top rounded-0 w-100 text-start text-body"><i class="bi bi-key"></i> Reset Password</button>
                    </form>
                    {% if HasAdminPermission("ManageAdminPermissions") %}<a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/manage-admin-permissions"><i class="bi bi-shield"></i> Manage Permissions</a>{%endif%}
                    {% if HasAdminPermission("ManageCurrency") %}<a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/manage-currency"><i class="bi bi-cash-stack"></i> Manage Robux & BC</a>{%endif%}
                    {% if HasAdminPermission("ManageInventory") %}<a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/manage-inventory"><i class="bi bi-box-seam"></i> Manage Inventory</a>{%endif%}

                </div>
                <div class="border rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0">
                        <h5 class="m-0">View</h5>
                    </div>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/moderator-notes"><i class="bi bi-journal-text"></i></i> Moderator Notes</a>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/login-history"><i class="bi bi-clock-history"></i></i> Login History</a>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/invite-keys"><i class="bi bi-key"></i></i> Invite Keys</a>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/game-sessions"><i class="bi bi-controller"></i></i> Game Sessions</a>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/transactions"><i class="bi bi-bank"></i></i> Transactions</a>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none" href="/admin/manage-users/{{userObj.id}}/ban-history"><i class="bi bi-exclamation-triangle"></i></i> Ban History</a>
                </div>
                {% if HasAdminPermission("GDPRDeleteUser") %}
                <div class="border border-danger rounded-2 mt-2">
                    <div class="bg-surface p-2 rounded-2 rounded-bottom-0">
                        <h5 class="m-0 text-danger">Danger Zone</h5>
                    </div>
                    <a class="btn border-top rounded-0 w-100 text-decoration-none text-danger" href="/admin/manage-users/{{userObj.id}}/gdpr-delete"><i class="bi bi-person-x-fill"></i> GDPR Erase User</a>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}