{% extends "aasrp/base.html" %}

{% load i18n %}
{% load static %}

{% block aasrp_body %}
    {% include "aasrp/partials/dashboard/srp-links.html" %}

    <!-- modals -->
    {% include "aasrp/modals/dashboard/enable-srp-link.html" %}
    {% include "aasrp/modals/dashboard/disable-srp-link.html" %}
    {% include "aasrp/modals/dashboard/delete-srp-link.html" %}
{% endblock %}

{% block extra_css %}
    {% include "bundles/datatables-css-bs5.html" %}
    {% include "aasrp/bundles/aa-srp-css.html" %}
    {% include "aasrp/bundles/aa-srp-form-css.html" %}
{% endblock %}

{% block extra_javascript %}
    {% translate "Ship" as translateShip %}
    {% translate "Request status" as translateRequestStatus %}
    {% translate "Character" as translateCharacter %}
    {% translate "SRP code" as translateSrpCode %}
    {% translate "Request code" as translateRequestCode %}
    {% translate "Are you sure you want to (re-)activate the following SRP link?" as translateEnableSrpLink %}
    {% translate "Are you sure you want to disable the following SRP link?" as translateDisableSrpLink %}
    {% translate "Are you sure you want to delete the following SRP link and all SRP requests tied to it?" as translateDeleteSrpLink %}

    <script>
        /**
         * Passing some setting to our JS
         */
        let urlAvailableSrpLinks = "{% url 'aasrp:ajax_dashboard_srp_links_data' %}";
        {% if show_all_links %}
            // Override for "view all"
            urlAvailableSrpLinks = "{% url 'aasrp:ajax_dashboard_srp_links_all_data' %}";
        {% endif %}

        const aaSrpJsSettingsOverride = {
            url: {
                availableSrpLinks: urlAvailableSrpLinks
            },
            dataTable: {
                paging: {{ show_all_links|yesno:"true,false" }}
            },
            translation: {
                filter: {
                    ship: '{{ translateShip|escapejs }}',
                    requestStatus: '{{ translateRequestStatus|escapejs }}',
                    character: '{{ translateCharacter|escapejs }}',
                },
                dataTable: {
                    content: {
                        srpCode: '{{ translateSrpCode|escapejs }}',
                        requestCode: '{{ translateRequestCode|escapejs }}',
                    }
                },
                modal: {
                    enableSrpLink: {
                        body: '<p>{{ translateEnableSrpLink|escapejs }}</p>'
                    },
                    disableSrpLink: {
                        body: '<p>{{ translateDisableSrpLink|escapejs }}</p>'
                    },
                    deleteSrpLink: {
                        body: '<p>{{ translateDeleteSrpLink|escapejs }}</p>'
                    },
                }
            }
        };
    </script>

    {% include "bundles/clipboard-js.html" %}
    {% include "aasrp/bundles/aa-srp-js.html" %}

    <script>
        new ClipboardJS('.copy-to-clipboard')
            .on('success', (e) => {
                e.clearSelection();
            })
            .on('error', (e) => {
                console.error('Action:', e.action);
                console.error('Trigger:', e.trigger);
            });
    </script>

    {% include "bundles/datatables-js-bs5.html" %}
    {% include "bundles/moment-js.html" with locale=True %}
    {% include "bundles/filterdropdown-js.html" %}
    {% include "aasrp/bundles/srp-links-js.html" %}
{% endblock %}
