window.addEventListener('DOMContentLoaded', function () {
    new Swiper("#banners", {
        grabCursor: true,
        centeredSlides: false,
        a11y: true,
        loop: true,
        loopFillGroupWithBlank: false,
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev",
        },
        pagination: {
            el: ".swiper-pagination",
            clickable: true,
        },
    });
});

const trendingModal = document.getElementById('trendingModal');
trendingModal.addEventListener('show.bs.modal', function(e) {
    let btn = e.relatedTarget;
    let modal = e.target;

    $(".modal-title", modal).text(btn.dataset.title);
    $(".modal-body", modal).css({
        "background": "url(" + btn.dataset.background + ")",
        "background-size": "cover"
    });

    let dl = $(".modal-body dl", modal);

    document.getElementById("moviePosterSrc").src = btn.dataset.src;
    dl.find("dt").html("<h4>" + btn.dataset.title + "</h4>");
    dl.find("dd").eq(0).text("(" + btn.dataset.original + ")");
    dl.find("dd").eq(1).text(btn.dataset.overview);
    dl.find("dd").eq(2).text("개봉일: " + btn.dataset.releaseDate);
});

// 평점 표시
$(function() {
    let config = {
        spacing: "1px",
        multiColor: {
            "startColor": "#F39C12",
            "endColor": "#E74C3C"
        },
        rating: 0,
        maxValue: 10,
        numStars: 5,
        readOnly: true,
        starWidth: "17px"
    };

    $("var[data-rate]").each(function(index, item) {
        config.rating = (item.dataset.rate || 0);
        $(item).rateYo(config);
    });
});
