/* Minification failed. Returning unminified contents.
(1,8): run-time error CSS1031: Expected selector, found '='
(1,8): run-time error CSS1025: Expected comma or open brace, found '='
(31,8): run-time error CSS1030: Expected identifier, found 'init('
(31,8): run-time error CSS1031: Expected selector, found 'init('
(31,8): run-time error CSS1025: Expected comma or open brace, found 'init('
 */
author = {
    init: function () {

        console.log("author");
        var addNews = document.getElementsByClassName("btn-add-news")[0];
        addNews.addEventListener("click", function (event) {
            var currentPage = parseInt(this.getAttribute('data-page'));
            var authorId = parseInt(this.getAttribute('data-id'));
            console.log(currentPage);
            fetch(`/Author/AddArticleInAuthor?authorid=${authorId}&pageIndex=${currentPage}`)
                .then(response => response.text())
                .then(data => {
                    if (data.trim().length > 60) {
                        currentPage++;
                        this.setAttribute('data-page', currentPage);
                        var newDiv = document.createElement('div');
                        newDiv.innerHTML = data;
                        document.querySelector('.content-news').appendChild(newDiv);
                    } else {
                        this.innerHTML = 'Danh sách trống';
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                });

        });
    },

}
author.init();
