{% extends 'admin-layout.html' %}
{% from 'macros.html' import modal %}
{% block title %}Action result{% endblock %}

{% block body %}

<div class="callout callout-{{out_type}}" role="alert">
    {{out_msg|safe}}
</div>

%if g.temp_admin_link
{% macro temp_link() -%}
<div class="btn-group">
  <a href='{{g.temp_admin_link}}' class="btn btn-secondary copy-link"><i class="fa-regular fa-copy"></i></a>
  <a target='_blank' href='{{g.temp_admin_link}}' class='btn btn-danger'>{{_('Temporary Link')}}</a>  
</div>
{%- endmacro -%}  

<div class="alert alert-warning">
  {{_("We have opened a temporary port (for 4 hours) to access the panel in case of any issues. Please copy this link.")}}
  {{temp_link()}}
  </div>
  

{{modal('save_emergency',_('Save Link'),_("Please copy the emergency link before leaving this page."),temp_link(),show=False)}}
%endif


% if log_path
<div>
<h1>{{_('log')}}</h1>
  <a href="{{log_path}}" target="_blank" >{{_('Click here to see the complete log')}}</a><br>
  <iframe id='ilog' src="{{log_path}}" style="width:100%;height:500px" ></iframe>
</div>

<script>
var x=document.getElementById("ilog");
var orig_log_url=x.src
function refresh(){
  x.contentWindow.location.replace(orig_log_url+"?random="+Math.random());
  //x.contentWindow.scrollTo( 0, 999999 );
}
setInterval(refresh,1000);
%if g.temp_admin_link
window.addEventListener('beforeunload', function (e) {
  // Cancel the event
  e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
  // Chrome requires returnValue to be set
  $("#save_emergency").modal()
  e.returnValue = 'Save';
  return "save"
});
%endif
</script>
% endif
{% endblock %}
