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

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

{% block aasrp_header %}
    {% translate "Ship Replacement" as translated_header %}
    {% include "aasrp/partials/header/h1.html" with header_text=translated_header %}
{% endblock %}

{% block aasrp_body %}
    {% include "aasrp/partials/dashboard/buttons.html" %}
    {% include "aasrp/partials/dashboard/table.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" %}
    {% include "aasrp/modals/view_requests/request_details.html" %}
{% endblock %}

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

{% block extra_javascript %}
    {% include "bundles/clipboard-js.html" %}

    <script>
        const clipboard = new ClipboardJS('.copy-text-fa-icon');

        clipboard.on('success', function (e) {
            e.clearSelection();
        });

        clipboard.on('error', function (e) {
            console.error('Action:', e.action);
            console.error('Trigger:', e.trigger);
        });
    </script>

    {% include "bundles/datatables-js.html" %}
    {% include "bundles/moment-js.html" with locale=True %}
    {% include "bundles/filterdropdown-js.html" %}

    <script>
        /**
         * Passing some setting to our JS
         */
        const urlUserSrpRequests = "{% url 'aasrp:ajax_dashboard_user_srp_requests_data' %}";
        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 aaSrpSettings = {
            datetimeFormat: 'YYYY-MM-DD HH:mm',
            url: {
                availableSrpLinks: urlAvailableSrpLinks,
                userSrpRequests: urlUserSrpRequests
            },
            dataTable: {
                paging: {{ show_all_links|yesno:"true,false" }}
            },
            translation: {
                filter: {
                    ship: "{% translate 'Ship' %}",
                    requestStatus: "{% translate 'Request Status' %}",
                    character: "{% translate 'Character' %}",
                },
                modal: {
                    enableSrpLink: {
                        body: "{% translate 'Are you sure you want to (re-)activate the following SRP Link?' %}"
                    },
                    disableSrpLink: {
                        body: "{% translate 'Are you sure you want to disable the following SRP Link?' %}"
                    },
                    deleteSrpLink: {
                        body: "{% translate 'Are you sure you want to delete the following SRP Link and all SRP requests tied to it?' %}"
                    },
                    srpDetails: {
                        body: {
                            requestor: '{% translate "Requestor" %}',
                            character: '{% translate "Character" %}',
                            ship: '{% translate "Ship" %}',
                            additionalInformation: '{% translate "Additional Information" %}',
                            rejectInformation: '{% translate "Reject Information" %}'
                        }
                    }
                }
            }
        };
    </script>

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