;(function($,w){'use strict';if(!w.jQuery){throw 'Ideasoft: jQuery not found';}
w.IdeaApp[IdeaApp.helpers.getRouteGroup()]={init:function(){IdeaApp.helpers.initializePage();},filter:{triggerCount:0,choiceDelay:0,init:function(){this.choiceDelay=$('.filter-menu').attr('data-filter-menu-delay');this.checkFilterMenu();this.eventListener();},checkFilterMenu:function(){if(!IdeaApp.helpers.matchMedia('(max-width: 767px)')){$('.filter-options-title').parents('#filter-wrapper').removeClass('has-filter-option');return;}
if($('.filter-menu .filter-menu-groups').length>0||$('.horizontal-filter-menu .filter-menu-groups').length>0){$('.filter-options-title').parents('#filter-wrapper').addClass('has-filter-option');var selectedItemCount=$('.filter-menu-selected-item').length;if(selectedItemCount>0){$('.filter-options-title span').text('('+selectedItemCount+')');}}},makeSortingParamsUrl:function(locationHref){const formElement=$('#sorting-options-form');if(formElement.length==0){return "";}
const sortingOption=formElement.find('select[name="sort"]').val();const sortingParams=[];if(sortingOption.length>0){sortingParams.push('siralama='+sortingOption);}
if(formElement.find('input[name="stockOnly"]').is(':checked')){sortingParams.push('stoktakiler=1');}
return decodeURIComponent(sortingParams.length>0?(locationHref.indexOf('?')>-1?'&':'?')+sortingParams.join('&'):'');},submitSortingOptionForm:function(){var locationHref=window.location.href;locationHref=IdeaApp.helpers.removeURLParameter(locationHref,'siralama');locationHref=IdeaApp.helpers.removeURLParameter(locationHref,'stoktakiler');var locationSearch=locationHref.split('?')[1];if(typeof locationSearch==="undefined"||locationSearch==''){locationHref=location.origin+location.pathname;}
window.location=locationHref+this.makeSortingParamsUrl(locationHref);},changeFilterOption:function(element){var self=this;if(element.is('select')){window.location=element.val();}else{var itemUrl=element.attr('data-url');if(self.choiceDelay==0){window.location=itemUrl;}else{self.triggerCount++;if(self.triggerCount==1){setInterval(function(){self.sendFilterParams(itemUrl)},parseInt(self.choiceDelay*1000));}}}},makeVerticalFilterParams:function(){var filterParams={};$('[data-selector="filter-option"]').each(function(){if(!$(this).is(':checked')){return;}
var filterGroupSlug=$(this).parents('.filter-menu-group-content').attr('data-filter-group-slug');var filterOptionSlug=$(this).attr('data-slug');var filterOptionGroupSlug=$(this).attr('data-group-slug');if(filterOptionGroupSlug){if(typeof filterParams[filterGroupSlug]=='undefined'){filterParams[filterGroupSlug]={};}
if(typeof filterParams[filterGroupSlug][filterOptionGroupSlug]=='undefined'){filterParams[filterGroupSlug][filterOptionGroupSlug]=[];}
filterParams[filterGroupSlug][filterOptionGroupSlug].push(filterOptionSlug);}else{if(typeof filterParams[filterGroupSlug]=='undefined'){filterParams[filterGroupSlug]=[];}
filterParams[filterGroupSlug].push(filterOptionSlug);}});return filterParams;},sendFilterParams:function(itemUrl){var self=this;var filterParams=self.makeVerticalFilterParams();IdeaApp.helpers.ajaxRequest({url:IdeaApp.routing.generate('/menu/make_menu_url'),data:{'filter_params':filterParams},success:function(response){if(Object.keys(filterParams).length==0){window.location=itemUrl;return;}
window.location.href=response.url+self.makeSortingParamsUrl(window.location.href);}});},eventListener:function(){var self=this;$(document).on('change','[data-selector="sorting-option"]',function(){self.submitSortingOptionForm();});$(document).on('change','[data-selector="filter-option"]',function(){self.changeFilterOption($(this));});$(document).on('click tap','[data-selector="clear-filters"]',function(){window.location.href=window.location.pathname;});$(window).on('resize',function(){self.checkFilterMenu();});}},search:{init:function(){this.eventListener();},loadBrands:function(value){$('[name="brand"] option').each(function(){if($(this).val()!="0"){$(this).remove();}});$('[name="brand"]').prop("disabled",true);IdeaApp.helpers.ajaxRequest({type:'GET',url:IdeaApp.routing.generate('/marka-ara?categoryId='+value),async:false,success:function(data){$.each(data,function(index,item){var template='<option value="'+item.id+'">'+item.name+'</option>';$('[name="brand"]').append(template).prop("disabled",false);});}});},eventListener:function(){var self=this;$(document).on('change','[data-selector="change-category"]',function(){self.loadBrands($(this).val());});$(document).on('keydown','[name="minimumPrice"], [name="maximumPrice"]',function(){IdeaApp.helpers.controlDecimalOnly(event);});$(document).on('change','[data-selector="sorting-option"]',function(){$('#sorting-options-form').submit();});}}}}(jQuery,window));