// jQuery(document).ready(function ($){

// $(".btn-nav-kurv").hover(function(){
//     $(".dropdown-cart-content").toggleClass("dropdown-active");
// });

// $(".dropdown-cart-content").hover(function(){
//     $(".dropdown-cart-content").toggleClass("dropdown-active");
// });

// });



// jQuery(document).ready(function ($){

//     $(".btn-nav-kurv").hover(function(){

//         $(".dropdown-cart-content").addClass("dropdown-active");
//     }, function () {
//         $(".dropdown-cart-content").removeClass("dropdown-active");
//     });
  
// });

$( document ).ready(function() {

    $(".front-page-hero").removeClass("preload");

    var mobileView = window.matchMedia("(min-width: 850px)")

    if (mobileView.matches) { // If media query matches
        $( ".btn-nav-kurv, .dropdown-cart-content" ).hover(
            function() {
                $(".dropdown-cart-content").show(0);
            }, function() {
                $(".dropdown-cart-content").delay(300).hide(0);
            }
        );
    }

    var acc = document.getElementsByClassName("accordion");
    var i;

    for (i = 0; i < acc.length; i++) {
    acc[i].addEventListener("click", function() {
        this.classList.toggle("active");
        var panel = this.querySelector('.panel');
        if (panel.style.maxHeight) {
        panel.style.maxHeight = null;
        } else {
        panel.style.maxHeight = panel.scrollHeight + "px";
        } 
    });
    }

    $( "#menu-toggle-open" ).click(function() {
        $('.main-navigation-mobile').addClass("menu-active");
        $('#menu-overlay').show();
        $('body').addClass("lock-scroll");
        $('.menu-primary-menu-mobile-container').addClass("reset-margin");
        $('.dropdown-search-mobile').addClass("reset-margin");
        $('#menu-toggle-close').addClass("reset-margin");
    });

    $( "#menu-toggle-close" ).click(function() {
        $('.main-navigation-mobile').removeClass("menu-active");
        $('#menu-overlay').hide();
        $('body').removeClass("lock-scroll");
        $('.menu-primary-menu-mobile-container').removeClass("reset-margin");
        $('.dropdown-search-mobile').removeClass("reset-margin");
        $('#menu-toggle-close').removeClass("reset-margin");
    });

    $( "#menu-overlay" ).click(function() {
        $('.main-navigation-mobile').removeClass("menu-active");
        $('#menu-overlay').hide();
        $('body').removeClass("lock-scroll");
        $('.menu-primary-menu-mobile-container').removeClass("reset-margin");
        $('.dropdown-search-mobile').removeClass("reset-margin");
        $('#menu-toggle-close').removeClass("reset-margin");
    });

    $( "#cart-toggle-open" ).click(function() {
        $('.dropdown-cart-content').addClass("cart-active");
        $('#cart-overlay').show();
        $('body').addClass("lock-scroll");
    });
  
    $( "#cart-overlay" ).click(function() {
        $('.dropdown-cart-content').removeClass("cart-active");
        $('#cart-overlay').hide();
        $('body').removeClass("lock-scroll");
        $('.dropdown-search-desktop').removeClass("dropdown-search-desktop-active");
    });

    $( ".search-menu-wrapper" ).click(function() {
        $('.dropdown-search-desktop').toggleClass("dropdown-search-desktop-active");
        $('#cart-overlay').toggle();
        $('.aws-search-field').focus();
        $('body').toggleClass("lock-scroll");
    });

    $("#aws-search-result-1").appendTo(".main-navigation-mobile");

    document.getElementById("billing_first_name").value = getSavedValue("billing_first_name");    // set the value to this input
    document.getElementById("billing_last_name").value = getSavedValue("billing_last_name");   // set the value to this input
    document.getElementById("billing_company").value = getSavedValue("billing_company");   // set the value to this input
    document.getElementById("billing_address_1").value = getSavedValue("billing_address_1");   // set the value to this input
    document.getElementById("billing_address_2").value = getSavedValue("billing_address_2");   // set the value to this input
    document.getElementById("billing_postcode").value = getSavedValue("billing_postcode");   // set the value to this input
    document.getElementById("billing_city").value = getSavedValue("billing_city");   // set the value to this input
    document.getElementById("billing_phone").value = getSavedValue("billing_phone");   // set the value to this input
    document.getElementById("billing_email").value = getSavedValue("billing_email");   // set the value to this input
    /* Here you can add more inputs to set value. if it's saved */

    //get the saved value function - return the value of "v" from localStorage. 
    function getSavedValue  (v){
        if (!localStorage.getItem(v)) {
            return "";// You can change this to your defualt value. 
        }
        return localStorage.getItem(v);
    }





    jQuery( document.body ).on( 'applied_coupon_in_checkout removed_coupon_in_checkout', function () {
        location.reload();
    } );
    
    jQuery(document).ready(function(){
        //Save the value function - save it to localStorage as (ID, VALUE)
        function saveValue(){
            var id = 'billing_first_name';  // get the sender's id to save it . 
            var val = document.getElementById("billing_first_name").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_last_name';  // get the sender's id to save it . 
            var val = document.getElementById("billing_last_name").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_company';  // get the sender's id to save it . 
            var val = document.getElementById("billing_company").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_address_1';  // get the sender's id to save it . 
            var val = document.getElementById("billing_address_1").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_address_2';  // get the sender's id to save it . 
            var val = document.getElementById("billing_address_2").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_postcode';  // get the sender's id to save it . 
            var val = document.getElementById("billing_postcode").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_city';  // get the sender's id to save it . 
            var val = document.getElementById("billing_city").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_phone';  // get the sender's id to save it . 
            var val = document.getElementById("billing_phone").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
            var id = 'billing_email';  // get the sender's id to save it . 
            var val = document.getElementById("billing_email").value; // get the value. 
            localStorage.setItem(id, val);// Every time user writing something, the localStorage's value will override . 
        }
    
        jQuery('body').click(function(){
            saveValue();
        });
    });
});
