$(function() {

    $('select').selectpicker();

  $('#modals-load-content').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        if (!button.data('id')) {
            return;
        }
        var data = {};
        $.each(button.data(), function(index, value){
            if(index !== 'bs.tooltip'){
                data[index] = value;
            }
        });
        console.log(data);

        loadModalInner(this, data);

    });

function loadModalInner(self, data){
    var url = data.route,
        contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
    $.ajax({
        url: url,
        data: data,
        type: "POST",
        dataType: "json",
        cache: false,
        contentType: contentType,
        encode: true,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        success: function(data) {
            console.log(data);
            if(data.response.modal){
                $(data.response.target).find('.modal-dialog').addClass(data.response.modal);
            }
            $(data.response.target).find('.modal-dialog').html(data.html);
            //$(data.response.target).find('.selectpicker').selectpicker('refresh');
        },
        error: function(xhr, status, errorThrown) {
            console.log(xhr);
            console.log(xhr.responseText);
            console.log(errorThrown);
            console.log("Sorry, there was a problem!");
        }
    });
    return false;
}  
});

function _scrollTo(to, offset) {
    $('html,body').animate({scrollTop: $(to).offset().top - offset}, 800);
}

$(document).on('click', '.open-icon-menu', function () {
    $("#side-bar").addClass("show");
    $("#anywhere-home").addClass("bgshow");
  });
  $(document).on('click', '.close-icon-menu', function () {
    $("#side-bar").removeClass("show");
    $("#anywhere-home").removeClass("bgshow");
  });
  $(document).on('click', '#anywhere-home', function () {
    $("#side-bar").removeClass("show");
    $("#anywhere-home").removeClass("bgshow");
  });

  $(document).on('click', '.scroll-to-top', function () {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
  });

  $(document).on('click', '.scroll-to-basket', function () {
    _scrollTo('#user_cart_holder', 10)
  });
  



