{% extends "private/skeleton.html" %}
{% block content %}

{% raw %}
<h3>
<a class="btn btn-outline-secondary" href="/tags"><i class="fa fa-chevron-left"></i></a>
Тег {{ tag.name }}</h3>
<hr />
{% endraw %}
{% include '/user/tag_menu.html' %}

<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>

{% include '/inc/pages.html' %}

<pagination-component v-bind:pagination="pagination" v-bind:click-handler="getPages"></pagination-component>

{% endblock %}

{% block breadcrumb %}
{% raw %}
<ol class="breadcrumb mt-3">
    <li class="breadcrumb-item"><a href="/"><i class="fa fa-home"></i></a></li>
    <li class="breadcrumb-item"><a href="/tags">Список тегов</a></li>
    <li class="breadcrumb-item">{{ tag.name }}</li>
</ol>
{% endraw %}
{% endblock %}

{% block script %}
<script type="text/javascript" src="/static/components/backtotop.js"></script>
<link rel="stylesheet" href="/static/components/backtotop.css"></link>
<script type="text/javascript" src="/static/components/pagination.js"></script>

<script type="text/javascript">
Object.assign(root.data, {
    menuitem: null,
    tag: {{ pagedata['tag']|tojson|safe }},
    raw_pages: [],
    pagination: {{ pagedata['pagination']|tojson|safe }},
});
Object.assign(root.methods, {
    getPages: function() {
        /* Получить список статей */
        let vm = this;
        axios.post(
            '/api',
            {
                "jsonrpc": "2.0",
                "method": "tag.pages",
                "params": {
                    "id": vm.tag.id,
                    "page": vm.pagination.page
                },
                "id": 1
            }
        ).then(
            function(response) {
                if ('result' in response.data) {
                    vm.raw_pages = response.data['result'];
                }
            }
        );
    },
});
root.created = function() {
    let vm = this;
    axios.post(
        '/api',
        [
            {
                "jsonrpc": "2.0",
                "method": "tag.pages",
                "params": {
                    "id": vm.tag.id,
                    "page": vm.pagination.page
                },
                "id": 1
            },
            {
                "jsonrpc": "2.0",
                "method": "tag.pages.count",
                "params": {
                    "id": vm.tag.id
                },
                "id": 1
            }
        ]
    ).then(
        function(response) {
            if ('result' in response.data[0]) {
                vm.raw_pages = response.data[0]['result'];
            }
            if ('result' in response.data[1]) {
                vm.pagination.size = response.data[1]['result'];
            }
        }
    );
},
Object.assign(root.computed, {
    pages: function() {
        let vm = this;
        return vm.raw_pages;
    }
});
</script>
{% endblock %}
