{% extends base.html %}
<!--
@author xupingmao
@since 2017/11/29
@modified 2021/12/04 21:13:05
-->

{% block body_left %}

{% init hot_logs = [] %}

    <div class="card">
        <div class="card-title">
            <span>搜索历史</span>

            <div class="float-right">
                <a class="btn btn-default" href="{{_server_home}}/system/settings?category=search">搜索设置</a>
                {% include common/button/back_button.html %}
            </div>
        </div>
    </div>

    <div class="card">
        {% if len(recent) == 0 %}
            {% include common/text/empty_text.html %}
        {% end %}

        {% if len(hot_logs) > 0 %}
            <h3 class="card-title">最近常搜</h3>
            {% for value, count in hot_logs %}
                <a class="tag-span" href="{{_server_home}}/search?key={{quote(value)}}">
                    <span>{{value}}</span>
                    <span class="black">{{count}}</span>
                </a>
            {% end %}
        {% end %}

        {% if len(recent) > 0 %}
            <h3 class="card-title">最近搜索</h3>
            {% for value in recent %}
                <a class="tag-span" href="{{_server_home}}/search?key={{quote(value)}}">{{value}}</a>
            {% end %}
        {% end %}

        {% if len(recent) > 0 %}
            <a class="tag-span-danger clear-history-link">清空历史记录</a>
        {% end %}
    </div>

<script type="text/javascript">
    $(".clear-history-link").click(function (e) {
        xnote.confirm("确定清空历史记录吗?", function (resp) {
            xnote.http.post("/search/history?p=clear", function(resp) {
                if (resp.code == "success") {
                    location.reload();
                } else {
                    xnote.alert(resp.message);
                }
            });
        });
    })
</script>
{% end %}

{% block body_right %}
    {% include search/component/search_sidebar.html %}
{% end %}