{% load i18n %}
<script type="text/hyperscript">
behavior htmx_error_handler
  on htmx:responseError or htmx:afterRequest[detail.failed] or htmx:sendError queue none
    -- Check if the event detail contains the xhr object and the status is 403
    if event.detail.xhr.status == 403 then
      call Swal.fire({
        title: '{% trans "Access Denied" %}',
        text: '{% trans "You do not have permission to perform this action or access this resource." %}',
        icon: 'warning',
        customClass: {
          confirmButton: 'btn btn-warning' -- Optional: different button style
        },
        buttonsStyling: true
      })
    else
      call Swal.fire({
        title: '{% trans "Something went wrong loading your data" %}',
        text: '{% trans "Try reloading the page or check the console for more information." %}',
        icon: 'error',
        customClass: {
          confirmButton: 'btn btn-primary'
        },
        buttonsStyling: true
      })
    end
    then log event
    then halt the event
end
</script>
