{% extends 'base_mobileui.html' %}

{% block title %}log{% endblock %}

{% block head %}
    <link rel="stylesheet" type="text/css" href="{{ static_css_utf8_mobileui }}">
    <style>
        h3 {word-break: break-all;}
    </style>
{% endblock %}

{% block loader %}
<div class="loader" style="display: block;" onclick="hideLoader();"></div>
{% endblock %}


{% block neck %}
<a class="button normal" href="javascript:;" onclick="forceLoader('{{ url_dashboard_mobile }}');">Dashboard</a>
<a class="button warning" href="javascript:;" onclick="forceLoader('{{ url_stats_mobile }}')">Stats</a>
{% endblock %}


{% block body %}
<div class="go-top">
    <div class="arrow"></div>
    <div class="stick"></div>
</div>
<div class="go-bottom">
    <div class="arrow"></div>
    <div class="stick"></div>
</div>


<div id="log" class="wrap" style="padding: 1px 12px;">
<h3>PROJECT ({{ project }})<br>SPIDER ({{ spider }})</h3>
<pre>{{ text }}</pre>

<h3>PROJECT ({{ project }})<br>SPIDER ({{ spider }})</h3>
{% if refresh_url_mobileui %}
<a id="refresh_button" class="button normal" href="javascript:;" onclick="forceLoader('{{ refresh_url_mobileui }}');">
Using cached version, press to refresh
</a>
<br>
<br>
{% endif %}
</div>


<script>
$(function() {
    //$(window).scroll(function() {
    $(document).ready(function() {
        {% if refresh_url_mobileui %}
        var kwargs = parseQueryString(location.search);
        history.pushState(null, '', window.location.pathname + ((kwargs.ui == 'mobile') ? "?ui=mobile" : ""));
        {% endif %}

        hideLoader();
        $('div.go-top').show();
        $('div.go-bottom').show();
        $('html, body').animate({scrollTop: $(document).height()}, 300);
    });

    $('div.go-top').click(function() {
        $('html, body').animate({scrollTop: 0}, 300);
    });
    $('div.go-bottom').click(function() {
        $('html, body').animate({scrollTop: $(document).height()}, 300);
    });
});
</script>


<script>
const LAST_REFRESH_TIMESTAMP = {{ last_refresh_timestamp }};
const LAST_LOG_ALERT_SECONDS = {{ LAST_LOG_ALERT_SECONDS }};

{% if refresh_url_mobileui %}
setInterval(function() {
    var now_timestamp = Date.now() / 1000;
    var seconds = Math.ceil(now_timestamp - LAST_REFRESH_TIMESTAMP);
    my$('#refresh_button').innerHTML = "Cached " + seconds + " seconds ago, press to refresh";
    if(seconds > LAST_LOG_ALERT_SECONDS) {
        my$('#refresh_button').className = "button danger";
    } else {
        my$('#refresh_button').className = "button safe";
    }
}, 1000);
{% endif %}
</script>
{% endblock %}
