
{% load sri %}
{% load i18n %}

{% sri_static 'ledger/css/cards.css' %}
{% sri_static 'ledger/js/modal/delete-confirm.js' %}

{% include 'ledger/partials/modal/confirm.html' %}

<script type="application/javascript">
    let ledgersettings = {
        characterDashboardUrl: "{% url 'ledger:api:get_character_dashboard' character_id=character_id %}",
    };
</script>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        $('[data-tooltip-toggle="ledger-tooltip"]').tooltip({
            trigger: 'hover',
        });
    });
</script>

<script>
    /* global ledgersettings, bootstrap */
    $(document).ready(function() {
        // Dashboard-Info
        const manageDashboardVar = $('#dashboard-card');
        const manageDashboardTableVar = $('#character-dashboard');
        // Dashboard-Statistics
        const manageDashboardStatisticsVar = $('#dashboard-statistics-card');
        const manageDashboardStatisticsTableVar = $('#character-dashboard-statistics');

        $.ajax({
            url: ledgersettings.characterDashboardUrl,
            type: 'GET',
            success: function (data) {
                // Dashboard-Info
                $('#dashboard-info').html(data.dashboard);
                // Dashboard-Statistics
                $('#dashboard-info-statistics').html(data.statistics);
                $('#auth-characters').text(data.auth_characters);
                $('#active-characters').text(data.active_characters);
                $('#inactive-characters').text(data.inactive_characters);
                $('#missing-characters').text(data.missing_characters);

                if (data.status) {
                    $('#status').text(data.status);
                    $('#status-issues').text(data.status_issues);
                    $('#character-issues').removeClass('d-none');
                    manageDashboardVar.removeClass('d-none');
                    manageDashboardTableVar.removeClass('d-none');
                }

                manageDashboardStatisticsVar.removeClass('d-none');
                manageDashboardStatisticsTableVar.removeClass('d-none');

                // Show the ledger content after initialization
                $('#ledger-index').addClass('show');
            },
            error: function(xhr, status, error) {
                console.error('Error fetching data:', error);
            }
        });
    });
</script>
