<!--
@since 2018/05/27
@modified 2021/05/16 23:44:33
-->

{% init key = "" %}
{% init parent_note = None %}

{% if key != None and key != "" %}
    <div class="card">
        <div class="search-tab">
            <a class="link" href="{{_server_home}}/search?key={{?key}}&category=default" 
                data-option="default" data-value="{{?category}}">默认</a>
            
            <a class="link" href="{{_server_home}}/search?key={{?key}}&search_type=note" 
                data-option="note" data-value="{{?category}}">笔记</a>

            <a class="link" href="{{_server_home}}/search?key={{?key}}&category=content" 
                data-option="content" data-value="{{?category}}">内容</a>

            <a class="link" href="{{_server_home}}/search?key={{?key}}&search_type=dict" 
                data-option="dict" data-value="{{?category}}">词典</a>
            
            <a class="link" href="{{_server_home}}/search?key={{?key}}&search_type=task"
                data-option="task" data-value="{{?category}}">待办</a>

            <a class="link" href="{{_server_home}}/search?key={{?key}}&search_type=message"
                data-option="message" data-value="{{?category}}">记事</a>

            <a class="link hide" href="{{_server_home}}/search?key={{?key}}&search_type=comment"
                data-option="comment" data-value="{{?category}}">评论</a>
        </div>
    </div>
{% end %}

{% if parent_note != None %}
    <div class="card btn-line-height">
        <span>搜索目录:</span>
        <a href="{{parent_note.url}}">{{parent_note.name}}</a>
        <div class="float-right">
            <a class="btn btn-default" href="{{_server_home}}/search?key={{key}}&search_type=note">搜索全站</a>
        </div>
    </div>
{% end %}

{% if len(relevant_words) > 0 %}
<div class="card">
    {% raw relevant_tab.render() %}
</div>
{% end %}

<script type="text/javascript">
$(function () {
    var searchType = getUrlParam("search_type");
    var category   = getUrlParam("category");

    function isEmpty(value) {
        return value === "" || value === undefined || value === null
    }

    if (!isEmpty(searchType)) {
        $("[data-option=" + searchType + "]").addClass("selected-link").removeClass("hide");
    } else if (!isEmpty(category)) {
        $("[data-option=" + category + "]").addClass("selected-link").removeClass("hide");
    } else {
        $("[data-option=default]").addClass("selected-link");
    }
})
</script>