(function($) {
    "use strict";
    $(".mobile-toggle").click(function(){
        $(".nav-menus").toggleClass("open");
    });
    $(".mobile-toggle-left").click(function(){
        $(".left-header").toggleClass("open");
    });
    $(".mobile-search").click(function(){
       $(".form-control-plaintext").toggleClass("open");
   });
    $(".bookmark-search").click(function(){
        $(".form-control-search").toggleClass("open");
    })
    $(".filter-toggle").click(function(){
        $(".product-sidebar").toggleClass("open");
    });
    $(".toggle-data").click(function(){
        $(".product-wrapper").toggleClass("sidebaron");
    });
    $(".form-control-search").keyup(function(e){
        if(e.target.value) {
            $(".page-wrapper.horizontal-wrapper").addClass("offcanvas-bookmark");
        } else {
            $(".page-wrapper.horizontal-wrapper").removeClass("offcanvas-bookmark");
        }
    });
})(jQuery);

$('.loader-wrapper').fadeOut('slow', function() {
    $(this).remove();
});

$(window).on('scroll', function() {
    if ($(this).scrollTop() > 600) {
        $('.tap-top').fadeIn();
    } else {
        $('.tap-top').fadeOut();
    }
});


$('.media-size-email svg').on('click', function (e) {
    $(this).toggleClass("like");
});



$('.tap-top').click( function() {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
    return false;
});

function toggleFullScreen() {
    if ((document.fullScreenElement && document.fullScreenElement !== null) ||
        (!document.mozFullScreen && !document.webkitIsFullScreen)) {
        if (document.documentElement.requestFullScreen) {
            document.documentElement.requestFullScreen();
        } else if (document.documentElement.mozRequestFullScreen) {
            document.documentElement.mozRequestFullScreen();
        } else if (document.documentElement.webkitRequestFullScreen) {
            document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
        }
    } else {
        if (document.cancelFullScreen) {
            document.cancelFullScreen();
        } else if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } else if (document.webkitCancelFullScreen) {
            document.webkitCancelFullScreen();
        }
    }
}
(function($, window, document, undefined) {
    "use strict";
    var $ripple = $(".js-ripple");
    $ripple.on("click.ui.ripple", function(e) {
        var $this = $(this);
        var $offset = $this.parent().offset();
        var $circle = $this.find(".c-ripple__circle");
        var x = e.pageX - $offset.left;
        var y = e.pageY - $offset.top;
        $circle.css({
            top: y + "px",
            left: x + "px"
        });
        $this.addClass("is-active");
    });
    $ripple.on(
        "animationend webkitAnimationEnd oanimationend MSAnimationEnd",
        function(e) {
            $(this).removeClass("is-active");
        });
})(jQuery, window, document);


// active link
$(".chat-menu-icons .toogle-bar").click(function(){
    $(".chat-menu").toggleClass("show");
});


/*=====================
02. Background Image js
  ==========================*/
$(".bg-center").parent().addClass('b-center');
$(".bg-img-cover").parent().addClass('bg-size');
$('.bg-img-cover').each(function () {
    var el = $(this),
        src = el.attr('src'),
        parent = el.parent();
    parent.css({
        'background-image': 'url(' + src + ')',
        'background-size': 'cover',
        'background-position': 'center',
        'display': 'block'
    });
    el.hide();
});
$('.bg-img-contain').each(function () {
    var el = $(this),
        src = el.attr('src'),
        parent = el.parent();
    parent.css({
        'background-image': 'url(' + src + ')',
        'background-size': 'contain',
        'background-repeat': 'no-repeat',
        'background-position': 'center',
        'display': 'block'
    });
    el.hide();
});



/*----------------------------------------
passward show hide
----------------------------------------*/
$('.show-hide').show();
$('.show-hide span').addClass('show');

$('.show-hide span').click(function () {
if ($(this).hasClass('show')) {
    $('input[name="login[password]"]').attr('type', 'text');
    $(this).removeClass('show');
} else {
    $('input[name="login[password]"]').attr('type', 'password');
    $(this).addClass('show');
}
});
$('form button[type="submit"]').on('click', function () {
$('.show-hide span').addClass('show');
$('.show-hide').parent().find('input[name="login[password]"]').attr('type', 'password');
});



//landing header //
$(".toggle-menu").click(function(){
    $('.landing-menu').toggleClass('open');
});
$(".menu-back").click(function(){
    $('.landing-menu').toggleClass('open');
});

$('.product-size ul li ').on('click', function(e) {
    $(".product-size ul li ").removeClass("active");
    $(this).addClass("active");
});

$('.email-sidebar .email-aside-toggle ').on('click', function(e) {
    $(".email-sidebar .email-left-aside ").toggleClass("open");
});


$('.job-sidebar .job-toggle ').on('click', function(e) {
    $(".job-sidebar .job-left-aside ").toggleClass("open");
});

// check for saved 'darkMode' in localStorage
var darkMode = localStorage.getItem('darkMode');



const darkModeToggle = document.querySelector('#mode_toggle');
const darkModeToggleIcon = document.querySelector('#mode_toggle i');
const enableDarkMode = () => {
    // 1. Add the class to the body
    document.body.classList.add('dark-only');
    $("#mode_toggle i").removeClass("fa-lightbulb");
    $("#mode_toggle i").addClass("fa-moon");
    // 2. Update darkMode in localStorage
    localStorage.setItem('darkMode', 'enabled');
}

const disableDarkMode = () => {
    // 1. Remove the class from the body
    document.body.classList.remove('dark-only');
    $("#mode_toggle i").addClass("fa-lightbulb");
    $("#mode_toggle i").removeClass("fa-moon");
  // 2. Update darkMode in localStorage
    localStorage.setItem('darkMode', null);
}

// If the user already visited and enabled darkMode
// start things off with it on
if (darkMode === 'enabled') {
    enableDarkMode();
}

// When someone clicks the button
darkModeToggle.addEventListener('click', () => {
  // get their darkMode setting
    darkMode = localStorage.getItem('darkMode');

  // if it not current enabled, enable it
    if (darkMode !== 'enabled') {
        enableDarkMode();
  // if it has been enabled, turn it off
    } else {
        disableDarkMode();
    }
});


if (darkMode == null) {
    let isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; // preferencias de color de la pantalla del navegador
    if (isDarkMode) {
        enableDarkMode();
    } else {
        disableDarkMode();
    }
}

/*
$(".mode").on("click", function () {
        $('.mode i').toggleClass("fa-moon").toggleClass("fa-lightbulb");
        // $('.mode-sun').toggleClass("show")
        $('body').toggleClass("dark-only");
        var color = $(this).attr("data-attr");
        localStorage.setItem('body', 'dark-only');
    });
*/

/**notifications **/
const btn_notifications_show = document.querySelector('.onclick-dropdown-notification');
btn_notifications_show.addEventListener('click', () => {
    $('.notification-dropdown').toggleClass('onclick-show-div');
});

function noty(msg, option=1){
    Snackbar.show({
        text: msg.toUpperCase(),
        actionText: 'CERRAR',
        actionTextColor: '#fff',
        backgroundColor: option == 1 ? '#232323' : '#e7515a',
        pos: 'top-right'
    })
}


/** show / hide password **/

function togglePassword(el, icon) {
    var input = document.querySelector('#'+el);
    $('#'+icon+ ' i').toggleClass("fa-eye fa-eye-slash");
    if (input.type === "password") {
        input.type = "text";
    }
    else {
        input.type = "password";
    }
}

