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

{% load i18n %}

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

{% block aasrp_body %}
    {% include "aasrp/partials/view_requests/overview.html" %}
    {% include "aasrp/partials/view_requests/requests.html" %}
    {% include "aasrp/modals/view_requests/request_details.html" %}
    {% include "aasrp/modals/view_requests/mark_complete_modal.html" %}
    {% include "aasrp/modals/view_requests/accept_request.html" %}
    {% include "aasrp/modals/view_requests/accept_rejected_request.html" %}
    {% include "aasrp/modals/view_requests/reject_request.html" %}
    {% include "aasrp/modals/view_requests/remove_request.html" %}
{% endblock %}

{% block extra_css %}
    {% include "bundles/datatables-css.html" %}
    {% include "aasrp/bundles/x-editable-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 "aasrp/bundles/x-editable-js.html" %}
    {% include "bundles/moment-js.html" with locale=True %}
    {% include "bundles/datatables-js.html" %}
    {% include "bundles/filterdropdown-js.html" %}

    <script>
        /**
         * passing some settings to our JS
         */
        const urlRequestsForSrpLink = '{% url "aasrp:ajax_srp_link_view_requests_data" srp_link.srp_code %}';
        const urlChangeSrpAmount = '{% url "aasrp:ajax_srp_request_change_payout" srp_link.srp_code 'SRP_REQUEST_CODE' %}';

        const aaSrpSettings = {
            datetimeFormat: 'YYYY-MM-DD HH:mm',
            srpCode: '{{ srp_link.srp_code }}',
            csrfToken: '{{ csrf_token }}',
            url: {
                requestsForSrpLink: urlRequestsForSrpLink,
                changeSrpAmount: urlChangeSrpAmount
            },
            translation: {
                filter: {
                    requestStatus: '{% translate "Request Status" %}',
                    ship: '{% translate "Ship" %}',
                    character: '{% translate "Character" %}'
                },
                changeSrpPayoutAmount: '{% translate "Click here to change the payout amount for this SRP request." %}',
                changeSrpPayoutHeader: '{% translate "Enter SRP payout value" %}',
                editableValidate: '{% translate "Empty values are not allowed" %}',
                modal: {
                    srpDetails: {
                        body: {
                            requestor: '{% translate "Requestor" %}',
                            character: '{% translate "Character" %}',
                            ship: '{% translate "Ship" %}',
                            insurance: '{% translate "Insurance Payout" %}',
                            additionalInformation: '{% translate "Additional Information" %}',
                            rejectInformation: '{% translate "Reject Information" %}'
                        }
                    },
                    form: {
                        error: {
                            fieldRequired: '{% translate "This field is required." %}'
                        }
                    }
                }
            }
        };

        $(document).ready(() => {
            $('[data-tooltip="payout-hint"]').tooltip();
        });
    </script>

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