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

<script src="{% static "js/plugins/metisMenu/jquery.metisMenu.3.0.7.js" %}"></script>

<script src="{% static "js/plugins/toastr/toastr.min.js" %}"></script>
<script src="{% static "js/inspinia.js" %}"></script>
<script src="{% static "js/jumpserver.js" %}?v=10"></script>
<script src="{% static 'js/plugins/select2/select2.full.min.js' %}"></script>
<script src="{% static 'js/plugins/select2/i18n/zh-CN.js' %}"></script>
<script src="{% static 'js/plugins/markdown-it.min.js' %}"></script>

{% if INTERFACE.footer_content %}
  <style>
    .markdown-footer{
      left: 50%;
      bottom: 0;
      max-width: 520px;
      width: calc(100% - 40px);
      padding: 8px 0;
      text-align: center;
      line-height: 1.4;
      color: inherit;
    }

    .markdown-footer p{ margin: 0; }
    .markdown-footer a{ color: #428bca; text-decoration: none; }
    .markdown-footer a:hover{ text-decoration: underline; }
  </style>
  <div id="markdown-output" class="markdown-footer" role="contentinfo" aria-label="{% trans 'Page footer' %}"></div>
{% endif %}

<script type="text/markdown"> {{ INTERFACE.footer_content }} </script>
<script>
  activeNav("{{ FORCE_SCRIPT_NAME }}");

  $(document).ready(function () {
      setAjaxCSRFToken();

      $('textarea').attr('rows', 5);

      if ($('.tooltip')[0]) {
          $('.tooltip').tooltip();
      }

      $.fn.select2.defaults.set('language', getUserLang());

      var md = window.markdownit({
        html: false,
        linkify: true,
        typographer: true,
        breaks: true
      });

      const markdownContent = `{{ INTERFACE.footer_content|default:''|escapejs }}`.replace(/\r\n?/g, '\n').trim();;
      const markdownRef = document.getElementById('markdown-output');

      if (markdownRef && markdownContent) {
          const renderedContent = md.render(markdownContent.trim());

          markdownRef.innerHTML = renderedContent;
          markdownRef.querySelectorAll('a').forEach(link => {
              link.setAttribute('target', '_blank');
              link.setAttribute('rel', 'noopener noreferrer');
          });
      }
  });
</script>