{% extends "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 %}

<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">
var app = new Vue({
    el: '#app',
    data: {
        tag: {{ pagedata['tag']|tojson|safe }},
        pages: [],
        pagination: {{ pagedata['pagination']|tojson|safe }},
    },
    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.pages = response.data['result'];
                    }
                }
            );
        },
    },
    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": 1
                }
            ]
        ).then(
            function(response) {
                if ('result' in response.data[0]) {
                    vm.pages = response.data[0]['result'];
                }
                if ('result' in response.data[1]) {
                    vm.pagination.size = response.data[1]['result'];
                }
            }
        );
    },
    computed: {
        filteredPages: function() {
            let vm = this;
            return vm.pages;
        }
    },
})
</script>
{% endblock %}
