$(document).ready(function () {

    $.fn.dropdown.settings.message.count = '{count} ausgewählt';



    var checkSelected = function () {
        var _el = $('#contact-form-special');
        var _item = $('.item.active.selected');
        if (_item.data('form') === 'contact') {
            if(_el.length) _el.collapse('show');
        }
    };



    $('.js-goToValue').on('change', function(e){
        var $target = $(e.target);
        var value = $target.val();
        if (value) {
            window.location.href = value;
        }
    });

    $('.selection.input--select').dropdown({
        onChange: function (value, text, $selectedItem) {
            var _el = $('#contact-form-special');
            if ($selectedItem.data('form') === 'contact') {
                if(_el.length) _el.collapse('show');
            } else {
                if(_el.length) _el.collapse('hide');
            }
        }
    });
    $('.selection.js-html-select').dropdown({
        onChange: function (value, text, $selectedItem) {
            if (value) {
                //window.location.href = value;
            }
        }
    });
    $('selection.js-html--select').dropdown('save defaults');

    $('.multiple.input--select').dropdown({
        useLabels: false
    });
    /*
    var multiSelectItems = $('.multiple.input--select.input--check-icon').find('.item');
    $(multiSelectItems).each(function () {
        $(this).prepend('<i class="check-icon--multiselect"><svg id="check" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2809.11 2809.11"> <title>i_check</title> <path class="cls-1" d="M1415.78,12.35C640.34,12.35,11.72,641,11.72,1416.41S640.34,2820.46,1415.78,2820.46s1404.06-628.62,1404.06-1404.06S2191.22,12.35,1415.78,12.35ZM2186,826c-286.86,398.81-648,804-759.5,1293.53-18.15,79.68-137.73,101.86-188.5,50.47-194.18-196.14-376.16-379.11-592-552-106-84.92,63.57-287.68,168.48-203.64,165.67,132.65,314.2,257,461.91,407.92,129.25-442.18,397.73-787.37,659.87-1151.77C2014.76,561.31,2265.54,715.49,2186,826Z" transform="translate(-11.22 -11.85)"/></svg></i>');
    });

    */

    var selectWithChecked = $('.input--select.input--check-icon').not($('.js-input--check-icon-services')).find('.item, .text');
    $(selectWithChecked).each(function () {
        var dontWrap = ($(this).hasClass('default') && $(this).hasClass('text'));
        if ($(this).html() !=''){
            if (!dontWrap) {
                $(this).prepend('<i class="check-icon--multiselect"><svg id="check" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2809.11 2809.11"> <title>i_check</title> <path class="checkicontest" d="M1415.78,12.35C640.34,12.35,11.72,641,11.72,1416.41S640.34,2820.46,1415.78,2820.46s1404.06-628.62,1404.06-1404.06S2191.22,12.35,1415.78,12.35ZM2186,826c-286.86,398.81-648,804-759.5,1293.53-18.15,79.68-137.73,101.86-188.5,50.47-194.18-196.14-376.16-379.11-592-552-106-84.92,63.57-287.68,168.48-203.64,165.67,132.65,314.2,257,461.91,407.92,129.25-442.18,397.73-787.37,659.87-1151.77C2014.76,561.31,2265.54,715.49,2186,826Z" transform="translate(-11.22 -11.85)"/></svg></i>');
            }

        }
    });

    var selectWithCheckedServices = $('.input--select.js-input--check-icon-services').find('.item, .text');
    $(selectWithCheckedServices).each(function () {
        var dontWrap = ($(this).hasClass('default') && $(this).hasClass('text'));
        if ($(this).html() !=''){
            if (!dontWrap) {
                $(this).prepend('<i class="check-icon--multiselect"><svg id="check" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2809.11 2809.11"> <title>i_check</title> <path class="checkicontest" d="M1415.78,12.35C640.34,12.35,11.72,641,11.72,1416.41S640.34,2820.46,1415.78,2820.46s1404.06-628.62,1404.06-1404.06S2191.22,12.35,1415.78,12.35ZM2186,826c-286.86,398.81-648,804-759.5,1293.53-18.15,79.68-137.73,101.86-188.5,50.47-194.18-196.14-376.16-379.11-592-552-106-84.92,63.57-287.68,168.48-203.64,165.67,132.65,314.2,257,461.91,407.92,129.25-442.18,397.73-787.37,659.87-1151.77C2014.76,561.31,2265.54,715.49,2186,826Z" transform="translate(-11.22 -11.85)"/></svg></i>');
                switch ($(this).data('value')) {
                    case 9:
                    case 11:
                        $(this).append('<span class="icon icon--de"></span>')
                        break;
                    case 10:
                    case 12:
                        $(this).append('<span class="icon icon--at"></span>')
                        break;
                }
            }

        }
    });


    $('.regional.modal').modal('attach events','.open-modal-regional','show');

    $('.nutrition.modal').modal('attach events','.open-modal-nutrition','show');
    $('.allergens.modal').modal('attach events','.open-modal-allergens','show');
    $('.coupons-special.modal').modal('attach events','.open-modal-coupons-special','show');
    $('.coupons-default.modal').modal('attach events','.open-modal-coupons-default','show');
    $('.mobile-infowindow.modal').modal('attach events','.open-modal-mobile-infowindow','show');

    checkSelected();

});


$(window).on('content.change', function(){
    $('.selection.input--select').dropdown({
        useLabels: false
    });
});