// Dom7

var $ = Dom7;





// Theme

var theme = 'ios';

if (location.href.indexOf('theme=md') >= 0) theme = 'md';

if (location.href.indexOf('theme=aurora') >= 0) theme = 'aurora';

var plugin = {

    params: {

        theme: theme,

        root: '#app',

    }

};

if (Framework7.use) Framework7.use(plugin);

else if (Framework7.Class && Framework7.Class.use) Framework7.Class.use(plugin);





// Init App

var app = new Framework7({

    id: 'io.framework7.testapp',

    el: '#app',

    cache: false, /* disable caching */

    theme: theme,

    routes: routes,

    popup: {

        closeOnEscape: true,

    },

    sheet: {

        closeOnEscape: true,

    },

    popover: {

        closeOnEscape: true,

    },

    actions: {

        closeOnEscape: true,

    },

    vi: {

        placementId: 'pltd4o7ibb9rc653x14',

    },

});



app.on('pageBeforeIn', function(page) {

    

    var $$ = Dom7;

    

    // nav menu

    if (page.$el.hasClass('home-v1') || page.$el.hasClass('home-v2') || page.$el.hasClass('home-v3') || page.$el.hasClass('home-v4') || page.$el.hasClass('home-v5') || page.$el.hasClass('home-v6')) {

        $$('.toolbar-bottom .menuItem').removeClass('item-selected');

        $$('.toolbar-bottom .menuItem.item-home').addClass('item-selected');

    } else if (page.$el.hasClass('page-search') || page.$el.hasClass('search-2')) {

        $$('.toolbar-bottom .menuItem').removeClass('item-selected');

        $$('.toolbar-bottom .menuItem.item-search').addClass('item-selected');

    } else if (page.$el.hasClass('page-profile')) {

        $$('.toolbar-bottom .menuItem').removeClass('item-selected');

        $$('.toolbar-bottom .menuItem.item-profile').addClass('item-selected');

    } else if (page.$el.hasClass('page-all-pages')) {

        $$('.toolbar-bottom .menuItem').removeClass('item-selected');

        $$('.toolbar-bottom .menuItem.item-pages').addClass('item-selected');

    }



    $$('.theme-mode').on('click', function () {

        if($$('.view.view-main.view-init').hasClass('theme-dark')) {

            $$('.view.view-main.view-init').removeClass('theme-dark');

        } else {

            $$('.view.view-main.view-init').addClass('theme-dark');

        }

    });

});



app.on('pageInit', function (page) {

    var $$ = Dom7;

    if ($$('.category-card-inner.selected').length > 0) {

        $$('.cate-count').html($$('.category-card-inner.selected').length + '+');

    } else if ($$('.selected').length == 0) {

        $$('.cate-count').html($$('.category-card-inner.selected').length + '');

    }

    $$('.category-card-inner').on('click', function () {

        if($$(this).hasClass('selected')) {

            $$(this).removeClass('selected');

        } else {

            $$(this).addClass('selected');

        }

        if ($$('.category-card-inner.selected').length > 0) {

            $$('.cate-count').html($$('.category-card-inner.selected').length + '+');

        } else if ($$('.selected').length == 0) {

            $$('.cate-count').html($$('.category-card-inner.selected').length + '');

        }

    });

    

    $$('.fav').on('click', function () {

        if($$(this).hasClass('faved')) {

            $$(this).removeClass('faved');

        } else {

            $$(this).addClass('faved');

        }

    });

    

    $$('#fav').on('click', function () {

        if ($$('.faved-course').hasClass('d-none')) {

            $$('.faved-course').removeClass('d-none');

            $$('.fav-course').addClass('d-none');

        } else {

            $$('.faved-course').addClass('d-none');

            $$('.fav-course').removeClass('d-none');

        }

    });

    

    $$('#fav2').on('click', function () {

        if ($$('.faved-course2').hasClass('d-none')) {

            $$('.faved-course2').removeClass('d-none');

            $$('.fav-course2').addClass('d-none');

        } else {

            $$('.faved-course2').addClass('d-none');

            $$('.fav-course2').removeClass('d-none');

        }

    });

    

    $$(".the-timeline .timeline-card").each(function(e) {

        $$(e).find(".progress-num").html($$(e).find(".progressbar").attr("data-progress") + '%');

    });

    

    $$('.top-search-slider .swiper-slide span').on('click', function () {

        $$('.top-search-slider .swiper-slide span').removeClass('selected');

        $$(this).addClass('selected');

    });

    

    $$('.plan, .plan-card').on('click', function () {

        $$('.plan, .plan-card').removeClass('selected');

        $$(this).addClass('selected');

    });

    

    $$('.class-type li').on('click', function () {

        $$('.class-type li').removeClass('selected');

        $$(this).addClass('selected');

    });

    

    $$('.time-frame span').on('click', function () {

        $$('.time-frame span').removeClass('selected');

        $$(this).addClass('selected');

    });

    

    for (let i = 0, len = $$('.swiper-slide').length; i < len; i++){

        $$('.swiper-slide')[i].setAttribute('tabindex', '0');

    }

    

    if (page.$el.hasClass('course-single-1')) {

        $$('#addNewFile').css('display', 'none');

        var courseSlider = app.swiper.get('.tabs-swipeable-wrap');

        courseSlider.on('slideChange', function () {

            if($$('#files').hasClass('tab-active')) {

                $$('#addNewFile').css('display', 'block');

            } else {

                $$('#addNewFile').css('display', 'none');

            }

        });

    }

    

    /* popup */

    var swipeToClosePopup = app.popup.create({

        el: '.course-video',

        swipeToClose: true,

        swipeHandler: '.swipe-to-close',

    });

    app.sheet.create({

        el: '.download-file-1',

        swipeToClose: true,

        backdrop: true,

    });

    app.sheet.create({

        el: '.download-file-2',

        swipeToClose: true,

        backdrop: true,

    });

    app.sheet.create({

        el: '.download-file-3',

        swipeToClose: true,

        backdrop: true,

    });

    app.sheet.create({

        el: '.share-profile',

        swipeToClose: true,

        backdrop: true,

    });

    app.sheet.create({

        el: '.the-filter',

        swipeToClose: true,

        backdrop: true,

    });

    

    // feedback 

    if (page.$el.hasClass('page-feedback')) {

        if ($$('#unsatisfied').parent().hasClass('rated')) {

            $$('#unsatisfied').attr("src","img/icons/unsatisfied-rated.svg");

        } else if($$('.view.view-main.view-init').hasClass('theme-dark')) {

            $$('#unsatisfied').attr("src","img/icons/unsatisfied-dark.svg");

        } else {

            $$('#unsatisfied').attr("src","img/icons/unsatisfied.svg");

        }

        if ($$('#neutral').parent().hasClass('rated')) {

            $$('#neutral').attr("src","img/icons/neutral-rated.svg");

        } else if($$('.view.view-main.view-init').hasClass('theme-dark')) {

            $$('#neutral').attr("src","img/icons/neutral-rating-dark.svg");

        } else {

            $$('#neutral').attr("src","img/icons/neutral-rating.svg");

        }

        if ($$('#satisfied').parent().hasClass('rated')) {

            $$('#satisfied').attr("src","img/icons/satisfied-rated.svg");

        } else if ($$('.view.view-main.view-init').hasClass('theme-dark')) {

            $$('#satisfied').attr("src","img/icons/satisfied-rating-dark.svg");

        } else {

            $$('#satisfied').attr("src","img/icons/satisfied-rating.svg");

        }

        if ($$('#verysatisfied').parent().hasClass('rated')) {

            $$('#verysatisfied').attr("src","img/icons/very-satisfied-rated.svg");

        } else if ($$('.view.view-main.view-init').hasClass('theme-dark')) {

            $$('#verysatisfied').attr("src","img/icons/very-satisfied-dark.svg");

        } else {

            $$('#verysatisfied').attr("src","img/icons/verysatisfied.svg");

        }

        $$('.rating-btns a').on('click', function () {

            $$('.rating-btns a').removeClass('rated');

            $$(this).addClass('rated');

            if ($$('#unsatisfied').parent().hasClass('rated')) {

                $$('#unsatisfied').attr("src","img/icons/unsatisfied-rated.svg");

            } else if($$('.view.view-main.view-init').hasClass('theme-dark')) {

                $$('#unsatisfied').attr("src","img/icons/unsatisfied-dark.svg");

            } else {

                $$('#unsatisfied').attr("src","img/icons/unsatisfied.svg");

            }

            if ($$('#neutral').parent().hasClass('rated')) {

                $$('#neutral').attr("src","img/icons/neutral-rated.svg");

            } else if($$('.view.view-main.view-init').hasClass('theme-dark')) {

                $$('#neutral').attr("src","img/icons/neutral-rating-dark.svg");

            } else {

                $$('#neutral').attr("src","img/icons/neutral-rating.svg");

            }

            if ($$('#satisfied').parent().hasClass('rated')) {

                $$('#satisfied').attr("src","img/icons/satisfied-rated.svg");

            } else if ($$('.view.view-main.view-init').hasClass('theme-dark')) {

                $$('#satisfied').attr("src","img/icons/satisfied-rating-dark.svg");

            } else {

                $$('#satisfied').attr("src","img/icons/satisfied-rating.svg");

            }

            if ($$('#verysatisfied').parent().hasClass('rated')) {

                $$('#verysatisfied').attr("src","img/icons/very-satisfied-rated.svg");

            } else if ($$('.view.view-main.view-init').hasClass('theme-dark')) {

                $$('#verysatisfied').attr("src","img/icons/very-satisfied-dark.svg");

            } else {

                $$('#verysatisfied').attr("src","img/icons/verysatisfied.svg");

            }

        });  

    }

    

    /* switch src for dark mode start */

    if ($$('.view.view-main.view-init').hasClass('theme-dark')) {

        $$('#walkthrough-1').attr("src","img/walkthrough/01-dark.svg");

        $$('#walkthrough-2').attr("src","img/walkthrough/02-dark.svg");

        $$('#walkthrough-4').attr("src","img/walkthrough/04-dark.svg");

        $$('#goBackDark').attr("src","img/icons/arrow-left-white.svg");

        $$('.page-header-icon-right img').attr("src","img/icons/bell-white.svg");

        $$('#close-member-page').attr("src","img/icons/close-white.svg");

        $$('.social-contacts a i img').attr("src","img/icons/social-angle-right-white.svg");

        $$('.course-coming img').attr("src","img/icons/lock-white.svg");

        $$('#goBackDark2').attr("src","img/icons/angle-left-white.svg");

        

    } else {

        $$('#walkthrough-1').attr("src","img/walkthrough/01.svg");

        $$('#walkthrough-2').attr("src","img/walkthrough/02.svg");

        $$('#walkthrough-4').attr("src","img/walkthrough/04.svg");

        $$('#goBackDark').attr("src","img/icons/arrow-left.svg");

        $$('.page-header-icon-right img').attr("src","img/icons/bell.svg");

        $$('#close-member-page').attr("src","img/icons/close.svg");

        $$('.social-contacts a i img').attr("src","img/icons/social-angle-right.svg");

        $$('.course-coming img').attr("src","img/icons/lock.svg");

        $$('#goBackDark2').attr("src","img/icons/angle-left-dark.svg");

    }

    /* switch src for dark mode end */

    

    /* follow button */

    $$('.course-single-1 .follow-btn').on('click', function () {

        if ($$(".course-single-1 .follow-btn").html() == `Follow <i class="f7-icons">plus</i>`){

            $$(".course-single-1 .follow-btn").html(`Following <i class="f7-icons">checkmark_alt</i>`);

        } else{

            $$(".course-single-1 .follow-btn").html(`Follow <i class="f7-icons">plus</i>`);

        }

    });

    $$('.course-single-2 .follow-btn').on('click', function () {

        if ($$(".course-single-2 .follow-btn").html() == `<i class="f7-icons">plus</i> Follow`){

            $$(".course-single-2 .follow-btn").html(`<i class="f7-icons">checkmark_alt</i> Following`);

        } else{

            $$(".course-single-2 .follow-btn").html(`<i class="f7-icons">plus</i> Follow`);

        }

    });

    $$('.page-teacher .follow-btn').on('click', function () {

        if ($$(".page-teacher .follow-btn").html() == `<i class="f7-icons">plus</i> Follow`){

            $$(".page-teacher .follow-btn").html(`<i class="f7-icons">checkmark_alt</i> Following`);

        } else{

            $$(".page-teacher .follow-btn").html(`<i class="f7-icons">plus</i> Follow`);

        }

    });

    

});



var delay=1500;

setTimeout(function() {

 $('.Cpreloader').addClass('loadedComplete');

}, delay);