{% 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;
    }
    .bg-dark {
        background-color: var(--surface-alt) !important;
        box-shadow: 0px 0px 5px 0px rgb(0,0,0);
    }
    .text-tickets {
        color: rgb(224, 224, 60) !important;
        font-weight: 600;
    }
    .text-robux {
        color: rgb(26, 212, 103) !important;
        font-weight: 600;
    }
</style>
{% endblock %}
{% block content %}
<div id="main">
    <div class="container" style="max-width: 1000px;">
        <a class="mb-2" href="/admin/manage-users/{{userObj.id}}"> < Return to User Page</a>
        <div class="d-flex align-items-center">
            <img height="100px" style="aspect-ratio: 1/1;" class="rounded-2" src="/Thumbs/Avatar.ashx?userId={{userObj.id}}&x=100&y=100">
            <div>
                <h1 class="m-0 {% if userObj.accountstatus == 1 %}text-body{% elif userObj.accountstatus == 2 %}text-warning{% elif userObj.accountstatus == 3%}text-danger{% else %}text-decoration-line-through text-body{%endif%}">{{userObj.username}}<span class="text-secondary"> Transactions</span></h1>
                <p class="text-secondary m-0" style="font-size: 12px;">UserId: <span class="text-body">{{userObj.id}}</span></p>
            </div>
        </div>
        <div class="form-floating mb-2">
            <select class="form-control" id="change-category-select">
                <option value="purchase" {%if PageCategory == "purchase"%}selected{%endif%}>Purchases</option>
                <option value="sale" {%if PageCategory == "sale"%}selected{%endif%}>Sales</option>
                <option value="group-payout" {%if PageCategory == "group-payout"%}selected{%endif%}>Group Payouts</option>
                <option value="stipends" {%if PageCategory == "stipends"%}selected{%endif%}>Stipends</option>
            </select>
            <label for="change-category-select">Category</label>
        </div>
        <table class="table table-dark table-striped">
            <thead>
              <tr class="rounded-top">
                <th scope="col" style="width: 15%;">Date</th>
                <th scope="col" style="width: 20%;">Source</th>
                <th scope="col" style="width: 45%;">Description</th>
                <th scope="col" style="width: 20%;">Amount</th>
              </tr>
            </thead>
            <tbody class="table-group-divider" style="border-color: var(--linebreak);">
            {% for Transaction in TransactionInfo: %}
              <tr>
                <td>{{Transaction.created_at}}</td>
                <td>
                    {% if Transaction["source"]["type"] == 0: %}
                        <a href="/users/{{Transaction['source']['id']}}/profile" class="text-decoration-none text-body text-truncate">
                            <img class="rounded-5 overflow-hidden me-2" width="38" height="38" src="/Thumbs/Head.ashx?x=48&amp;y=48&amp;userId={{Transaction['source']['id']}}" alt="{{Transaction['source']['name']}}">
                            {{Transaction["source"]["name"]}}
                        </a>
                    {% else %}
                        <a href="/groups/{{Transaction['source']['id']}}/--" class="text-decoration-none text-body text-truncate">
                            <img class="rounded-5 overflow-hidden me-2" width="38" height="38" src="/Thumbs/GroupIcon.ashx?x=48&amp;y=48&amp;groupid={{Transaction['source']['id']}}" alt="{{Transaction['source']['name']}}">
                            {{Transaction["source"]["name"]}}
                        </a>
                    {% endif %}
                </td>
                <td>
                    {% if Transaction['custom_text'] != None %}
                        {{Transaction['custom_text']}}
                    {% else %}
                        {% if Transaction['asset'] != None: %}
                        <a href="/catalog/{{Transaction['asset']['id']}}/--" class="text-decoration-none text-body">
                            <img class="rounded-2 overflow-hidden me-2 border" width="38" height="38" src="/Thumbs/Asset.ashx?x=48&y=48&assetId={{Transaction['asset']['id']}}" alt="{{Transaction['asset']['name']}}">
                            {{Transaction['asset']['name']}}
                        </a>
                        {% else %}
                        Unknown
                        {%endif%}
                    {% endif %}
                </td>
                <td>
                    {% if Transaction['currency_type'] == 0 %}
                    <span class="text-robux">R$ {{Transaction['currency_amount']}}</span>
                    {% else %}
                    <span class="text-tickets">T$ {{Transaction['currency_amount']}}</span>
                    {% endif %}
                </td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
          {% if len(TransactionInfo) == 0: %}
            <div class="text-center">
                <p class="text-secondary">No transactions found</p>
            </div>
          {%endif%}
    
          <div class="align-items-center d-flex justify-content-center mt-2 mb-2">
            <a class="ms-auto m-0 text-decoration-none {% if not Pagination.has_prev %}text-secondary{%endif%}" {% if Pagination.has_prev %}href="/admin/manage-users/{{userObj.id}}/transactions?page={{Pagination.prev_num}}&category={{PageCategory}}"{%endif%}>Previous</a>
            <p class="ms-2 me-2 text-body m-0">Page {{Pagination.page}} of {{Pagination.pages}}</p>
            <a class="me-auto m-0 text-decoration-none {% if not Pagination.has_next %}text-secondary{%endif%}" {% if Pagination.has_next %}href="/admin/manage-users/{{userObj.id}}/transactions?page={{Pagination.next_num}}&category={{PageCategory}}"{%endif%}>Next</a>
        </div>
    </div>
</div>
<script>const s = document.getElementById("change-category-select");s.addEventListener("change", function() {var u = new URL(window.location.href);var sb = s.value;u.searchParams.set("category", sb);u.searchParams.set("page", 1);window.location.href = u;});</script>
{% endblock %}