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

<h3>Профиль</h3>
<hr />

{% include 'profile_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>

<backtotop-component></backtotop-component>

{% endblock content %}

{% 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: 'pages',
    raw_pages: [],
    pagination: {{ pagedata['pagination']|tojson|safe }},
});
Object.assign(root.methods, {
        filterApply: function() {},
        filterPage: function(page) {
            let vm = this;
            if ( vm.filter.length<1 ) {
                return true;
            }
            if ( page.title.toLowerCase().includes(vm.filter.toLowerCase()) ) {
                return true;
            }
            return false;
        },
        getPages: function() {
            /* Получить список статей */
            let vm = this;
            axios.post(
                '/api',
                {
                    "jsonrpc": "2.0",
                    "method": "pages",
                    "params": {
                        "page": vm.pagination.page
                    },
                    "id": 1
                }
            ).then(
                function(response) {
                    if ('result' in response.data) {
                        vm.raw_pages = response.data['result'];
                    }
                }
            );
        },
    },
    created: function() {
        let vm = this;
        axios.post(
            '/api',
            [
                {
                    "jsonrpc": "2.0",
                    "method": "profile.pages",
                    "params": {
                        "page": vm.pagination.page
                    },
                    "id": 1
                },
                {
                    "jsonrpc": "2.0",
                    "method": "profile.pages.count",
                    "params": {},
                    "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'];
                }
            }
        );
    },
    computed: {
        pages: function() {
            let vm = this;
            return vm.raw_pages;
        }
    },
})
</script>
{% endblock script %}
