jQuery(document).ready(function(){
    (($)=>{
        window.article_data = [];
        $.ajax({
            url: "https://api.maxaccess.io/wcag/article/",
        }).done( re => {
            for(let i = 0; i < re.length; i++){
                window.article_data[ re[i].ref ] = re[i];
                
                if( re[i].video.embed != "" ){
                    $("[data-article='"+re[i].ref + "'].available").show();
                }else{
                    $("[data-article='"+re[i].ref + "'].not-available").show();
                }
            }
        }).fail( re=>{console.log("failed", re);});

        $(".wcag-list").on("click", ".play-video", function(e){
            e.preventDefault();
            $(".player-modal-wrap").addClass("active");
            $("#player-modal").addClass(window.article_data[$(this).data("article")].video.source);
            $("#player-modal .embed").prepend(window.article_data[$(this).data("article")].video.embed);
            $("#player-modal.youtube .description").html(window.article_data[$(this).data("article")].video.transcript);
        });
        $(".wcag-content").on("click", "#player-modal button.close, .player-modal-wrap", function(e){
            e.preventDefault();
            $(".player-modal-wrap").removeClass("active");
            $("#player-modal").removeClass("youtube").removeClass("vimeo");
            $("#player-modal .embed iframe").remove();
            $("#player-modal.youtube .description").html();
        });
    })(jQuery);
});