// Dropdown Sidebar Menu
let sidebarItems = document.querySelectorAll('.sidebar-item.has-sub');
for(var i = 0; i < sidebarItems.length; i++) {
    let sidebarItem = sidebarItems[i];
	sidebarItems[i].querySelector('.sidebar-link').addEventListener('click', function(e) {
        e.preventDefault();

        let submenu = sidebarItem.querySelector('.submenu');

        if(submenu.classList.contains('active')) submenu.classList.remove('active');
        else submenu.classList.add('active');
    })
}

// Navbar Toggler
let sidebarToggler = document.querySelectorAll(".sidebar-toggler");
for (var i = 0; i < sidebarToggler.length; i++) {
    let toggler = sidebarToggler[i];
    toggler.addEventListener('click', () => {
        let sidebar = document.getElementById('sidebar');
        if(sidebar.classList.contains('active')) sidebar.classList.remove('active');
        else sidebar.classList.add('active');
    });
}

// Perfect Scrollbar INit
if(typeof PerfectScrollbar == 'function') {
    const container = document.querySelector(".sidebar-wrapper");
    const ps = new PerfectScrollbar(container);
}

window.onload = function() {
    var w = window.innerWidth;
    if(w < 768) {
        document.getElementById('sidebar').classList.remove('active');
    }
}

feather.replace();

$('.daterangepicker').daterangepicker({
    "locale": date_locale
}, function(start, end, label) {
  console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')');
});

$('.datepicker').daterangepicker({
    singleDatePicker: true,
    showDropdowns: true,
    minYear: 1901,
    maxYear: parseInt(moment().format('YYYY'),10),
    "locale": date_locale
}, function(start, end, label) {
    var years = moment().diff(start, 'years');
});

$('.money').mask("#,##0.00", {reverse: true});

const Toast = Swal.mixin({
    toast: true,
    position: 'top',
    showConfirmButton: false,
    timer: 30000,
    timerProgressBar: true,
    didOpen: (toast) => {
    toast.addEventListener('mouseenter', Swal.stopTimer)
    toast.addEventListener('mouseleave', Swal.resumeTimer)
    }
});

