var TutorTimetable=function(n,t){var r=t,s=undefined,h=undefined,c=n,l=$("#user-timetable-template"),y=r.find(".jsTimetableContainer"),u=undefined,f=undefined,e=undefined,i=undefined,a={timetable_data_url:"/api/tutorsearch/timetable",timetable_template_url:"/Scripts/templates/user-timetable-template.html"},p=function(){u=$(".jsDataRangeHourItem");f=$(".data-range__hour-item.hidden");s=r.find(".jsDateRangeCalendarPrev");h=r.find(".jsDateRangeCalendarNext");e=r.find(".jsDateRangeHourExpand")},o=function(n){sendRequest({url:a.timetable_data_url,type:"POST",data:JSON.stringify({userid:c,datestart:n,languageid:LanguageId}),contentType:"application/json"}).then(function(n){loadTemplate(a.timetable_template_url,"#"+l.attr("id"),function(){var t=_.template(l.html());y.html(t({data:n.data}));v()})},function(){})},w=function(){var n=$(this).data("date");isEmpty(n)||o(n);typeof i=="function"&&i()},b=function(){var n=$(this).data("date");isEmpty(n)||o(n);typeof i=="function"&&i()},k=function(){var n=$(this),t;n.hasClass("disabled")||(u.removeClass("active"),n.addClass("active"),t=n.closest(".day-time").data("date")+" "+n.text(),typeof i=="function"&&i(t))},v=function(){p();s.click(w);h.click(b);u.click(k);f.length>0&&(e.removeClass("hidden"),e.click(function(){$(this).addClass("hidden");f.removeClass("hidden")}))};this.Init=function(n){c=n;v()};this.OnSelected=function(n){i=n};this.LoadDefault=function(){o()}},TutorSearchMobileFilter=function(n){var t={},c=n,l=$(".jsMobileFilterApply"),a=$(".jsMobileFilterReset"),f=$(".jsTutorPriceRangeFilter"),i=$(".jsMobileFilterTimetableItem"),e=$(".jsMobileFilterTargetAudienceItem"),r=$(".jsMobileFilterSpecializationItem"),o=$(".jsMobileFilterSortItem"),s=$(".jsTutorHasVideoFilter"),u=function(n){var t=n.filter(":checked"),i=n.closest(".accordion-item").find(".jsFilterMobileCounter");t.length>0?i.text(t.length):i.text("")},h;this.Init=function(n){t=n;l.click(function(){c(t)});a.click(function(){t.ServiceTagIds=undefined;t.Timetable=undefined;t.TargetAudience=undefined;t.HasVideo=undefined;t.SortField=undefined;s.prop("checked",!1);s.trigger("change");i.filter(":checked").prop("checked",!1);i.closest(".accordion-item").find(".jsFilterMobileCounter").text("");r.filter(":checked").prop("checked",!1);r.closest(".accordion-item").find(".jsFilterMobileCounter").text("");e.filter(":checked").prop("checked",!1);e.closest(".accordion-item").find(".jsFilterMobileCounter").text("");o.filter(":checked").prop("checked",!1);o.filter(":first").prop("checked",!0);t.PriceFrom=t.PriceFromDefault;t.PriceTo=t.PriceToDefault;f.closest(".accordion-item").find(".jsFilterMobileCounter").text("");h({from:t.PriceFrom||t.PriceFromDefault,to:t.PriceTo||t.PriceToDefault,min:t.PriceFromDefault,max:t.PriceToDefault})});s.change(function(){t.HasVideo=$(this).prop("checked")});i.click(function(){var n="";i.filter(":checked").each(function(){isEmpty(n)?n=$(this).val():n+=","+$(this).val()});t.Timetable=n;u(i)});u(i);r.click(function(){var n="";r.filter(":checked").each(function(){isEmpty(n)?n=$(this).val():n+=","+$(this).val()});t.ServiceTagIds=n;u(r)});u(r);e.click(function(){t.TargetAudience=$(this).val();u(e)});u(e);o.click(function(){t.SortField=$(this).val()});h({grid:!0,grid_num:Math.floor((t.PriceToDefault-t.PriceFromDefault)/50),skin:"round",type:"double",hide_min_max:!0,min:t.PriceFromDefault,max:t.PriceToDefault,from:t.PriceFrom||t.PriceFromDefault,to:t.PriceTo||t.PriceToDefault,from_max:(+t.PriceTo||+t.PriceToDefault)-50,to_min:(+t.PriceFrom||+t.PriceFromDefault)+50,step:50,onFinish:function(n){var i=f.closest(".accordion-item").find(".jsFilterMobileCounter");i.text("");(n.max!=n.to||n.min!=n.from)&&i.text("1");t.PriceTo=n.to;t.PriceFrom=n.from;tutorPriceRangeSlider.update({from_max:+n.to-50,to_min:+n.from+50})}})};h=function(n){typeof tutorPriceRangeSlider!="undefined"?tutorPriceRangeSlider.update(n):(f.ionRangeSlider(n),tutorPriceRangeSlider=f.data("ionRangeSlider"));var t=f.closest(".accordion-item").find(".jsFilterMobileCounter");n.from!=n.min||n.to!=n.max?t.text("1"):t.text("")}},TutorSearchDesktopFilter=function(n){var t={},i=n,d=$("#tutorSearchServiceDropDown"),tt=d.find('input[type="hidden"]'),u=$("#tutorSpecializationDropDown"),v=u.find('input[type="hidden"]'),r=$("#tutorSearchPriceRangeDropDown"),g=r.find('input[type="hidden"]'),f=$("#tutorTimetableDropDown"),y=f.find("#tutorTimetableDropDownValue"),s=$("#tutorSearchSortDropdown"),nt=s.find('input[type="hidden"]'),p=$(".jsTutorPriceRangeFilter"),e=$("#tutorSearchVideoDropdown"),it=e.find('input[type="hidden"]'),w=$(".jsTutorHasVideoFilter"),h=$("#tutorTargetAudienceDropDown"),b=h.find('input[type="hidden"]'),o=undefined,c=!1,l=!1,a=!1,k;this.Init=function(n){var p;t=n;customDropDownUtilsHelper.BindOnCloseCallback(r,function(){a&&i(t)});customDropDownUtilsHelper.BindOnMultiSelectClear(r,g,function(){t.PriceFrom="";t.PriceTo="";i(t)});customDropDownUtilsHelper.BindMultiSelect(f,y,function(n){customDropDownUtilsHelper.MultiDropdownSelectedGeneral(f,2,function(n){return FieldResources.Choose+" "+n});l=t.Timetable==n?!1:!0;t.Timetable=n});customDropDownUtilsHelper.BindOnCloseCallback(f,function(){l&&i(t)});customDropDownUtilsHelper.BindOnMultiSelectClear(f,y,function(){t.Timetable="";i(t)});customDropDownUtilsHelper.MultiDropdownSelectedGeneral(f,2,function(n){return FieldResources.Choose+" "+n});customDropDownUtilsHelper.BindMultiSelect(u,v,function(n){customDropDownUtilsHelper.MultiDropdownSelectedGeneral(u,2,function(n){return FieldResources.Choose+" "+n});c=t.ServiceTagId==n?!1:!0;t.ServiceTagIds=n});customDropDownUtilsHelper.BindOnCloseCallback(u,function(){c&&i(t)});customDropDownUtilsHelper.BindOnMultiSelectClear(u,v,function(){t.ServiceTagIds="";i(t)});customDropDownUtilsHelper.MultiDropdownSelectedGeneral(u,2,function(n){return FieldResources.Choose+" "+n});customDropDownUtilsHelper.BindSelect(s,nt,function(n){t.SortField=$(n).data("id");i(t)});t.SortField=="rnd"&&s.find(".jsDropdownLabel").removeClass("active");customDropDownUtilsHelper.BindSelect(h,b,function(n){t.TargetAudience=$(n).data("id");i(t)});customDropDownUtilsHelper.BindOnSelectClear(h,b,function(){t.TargetAudience=undefined;i(t)});customDropDownUtilsHelper.BindOnCloseCallback(e,function(){});w.change(function(){t.HasVideo=$(this).prop("checked");i(t)});w.prop("checked")?(p=e.find(".jsDropdownLabel"),p&&p.addClass("active")):(p=e.find(".jsDropdownLabel"),p&&p.removeClass("active"));k({grid:!0,grid_num:Math.floor((t.PriceToDefault-t.PriceFromDefault)/50),skin:"round",type:"double",hide_min_max:!0,min:t.PriceFromDefault,max:t.PriceToDefault,from:t.PriceFrom||t.PriceFromDefault,to:t.PriceTo||t.PriceToDefault,from_max:(+t.PriceTo||+t.PriceToDefault)-50,to_min:(+t.PriceFrom||+t.PriceFromDefault)+50,step:50,onFinish:function(n){t.PriceTo!=n.to&&(a=!0);t.PriceTo=n.to;t.PriceFrom!=n.from&&(a=!0);t.PriceFrom=n.from;o.update({from_max:+n.to-50,to_min:+n.from+50})}})};k=function(n){var i,t;typeof o!="undefined"?o.update(n):(p.ionRangeSlider(n),o=p.data("ionRangeSlider"));customDropDownUtilsHelper.SetLabelValue(r,n.from+" грн - "+n.to+" грн");n.from!=n.min||n.to!=n.max?(t=r.find(".jsDropdownClear"),i=r.find(".jsDropdownLabel"),i&&i.addClass("active"),t&&t.show()):(t=r.find(".jsDropdownClear"),t&&t.hide(),i&&i.removeClass("active"))}},TutorSearchFilter=function(){var n={tutor_search_url:"/tutorsearch/listurl",host_name:document.location.protocol+"//"+document.location.host+document.location.pathname},i=function(){return $("#tutorSearchDesktopfilter").val().bool()},t=function(t){var i=n.host_name;t.ServiceTagIds&&(i=addUrlParam(i,"ServiceTagIds",t.ServiceTagIds));t.Timetable&&(i=addUrlParam(i,"Timetable",t.Timetable));t.PriceFrom&&(i=addUrlParam(i,"PriceFrom",t.PriceFrom));t.PriceTo&&(i=addUrlParam(i,"PriceTo",t.PriceTo));t.SortField&&(i=addUrlParam(i,"SortField",t.SortField));t.HasVideo&&(i=addUrlParam(i,"HasVideo","true"));t.TargetAudience&&(i=addUrlParam(i,"TargetAudience",t.TargetAudience));sendRequest({url:n.tutor_search_url,type:"POST",data:JSON.stringify({filter:t,languageid:LanguageId}),contentType:"application/json"}).then(function(n){document.location.href=n.url+"#TutorsList"},function(){})};this.Init=function(n){var r,u;i()?(r=new TutorSearchDesktopFilter(t),r.Init(n)):(u=new TutorSearchMobileFilter(t),u.Init(n))}},UserVideo=function(){var n=$("#user-video-frame"),t=n.find(".jsUserVideoContainer"),i=$(".jsUserVideoPlay"),r='<iframe referrerpolicy="strict-origin-when-cross-origin" frameborder="0" allow="autoplay; encrypted-media; picture-in-picture; fullscreen" src="https://www.youtube-nocookie.com/embed/{Key}?autoplay=1&amp;mute=0&amp;playsinline=1&amp;rel=0&amp;controls=1&amp;showinfo=0" height="100%" width="100%"><\/iframe>',u=function(){i.click(function(){var n=$(this).data("key");$(this).parent().find(".jsUserVideoBoxContainer").html(r.format({Key:n}));$(this).hide();$(this).parent().find(".video-thumbnail").hide()});n.on("hide.bs.modal",function(){t.html("")})};this.Init=function(){u()}},ChatUser=function(){var n={chat_create_url:"/chat/create"};this.Create=function(t){sendRequest({url:n.chat_create_url,type:"POST",data:JSON.stringify({usertoid:t}),contentType:"application/json"}).then(function(n){n.success?document.location.href="/chat/messages/"+n.chatKey:n.message&&notificationManager.Show({Title:NotificationResources.ErrorTitle,Type:2,Text:n.message})})}},TutorSearchList=function(){var i=undefined,f=$(".jsTrialLessonClick"),r=$(".jsUserTimetable"),e=$(".jsTutorCardServiceMore"),o=new UserVideo,n=$("#user-timetable-range-template"),u=$("#mainSearchDropdown"),s=u.find('input[type="hidden"]'),t={timetable_range_url:"/api/tutorsearch/timetablerange",user_timetable_range_template_url:"/Scripts/templates/user-timetable-range-template.html"},h=function(n){var t=n.find(".findings_wrap"),r=t.find(".jsTutorCardReviewBody span"),i=t.find(".jsTutorCardReviewBody"),u=n.find(".jsTutorCardReviewOpen");i.length!==0&&r.length!==0&&setTimeout(function(){var f=t[0].offsetHeight,e=r[0].offsetHeight,o=i[0].scrollHeight>i[0].clientHeight+1,s=e>f+1,h=o||s;if(h){if(u.show(),!n.hasClass("jsReviewInitialized")){n.addClass("jsReviewInitialized");n.on("click",function(){$(this).toggleClass("active")})}}else u.hide()},100)},c=function(){phoneCountryCodeDropdownInit($("#phoneAddModalCountryCodeDropdown"));phoneCountryCodeDropdownInit($("#oAuthModalCountryCodeDropdown"));phoneCountryCodeDropdownInit($("#lessonOrderCancelCountryCodeDropdown"));loadTemplate(t.user_timetable_range_template_url,"#"+n.attr("id"),function(){});e.click(function(){$(this).parent().find(".jsTutorCardServiceItem").filter(".hidden").removeClass("hidden");$(this).remove()});r.click(function(){var i=$(this),r=$($(this).attr("href")),u=$(this).data("id"),f=$(this).data("loaded")||!1;f||sendRequest({url:t.timetable_range_url,type:"POST",data:JSON.stringify({userid:u,languageId:LanguageId}),contentType:"application/json"}).then(function(u){loadTemplate(t.user_timetable_range_template_url,"#"+n.attr("id"),function(){var t=_.template(n.html());r.html(t({data:u}));i.data("loaded","true")})},onJsErrorCallback)});f.click(function(){tryLessonOrderTrialBook({TutorAvatar:$(this).data("avatar"),UserId:$(this).data("userid"),ServiceId:$(this).data("serviceid"),SourceId:$(this).data("sourceid")})});$(".jsTutorCardReview").each(function(){var n=$(this);h(n)});$(".jsTutorVideoButton").click(function(n){n.preventDefault();var t=$(this).data("href");isEmpty(t)||(document.location.href=t)});$(".jsTutorDetailSendMessage").click(function(){tryLessonOrderChatOpen({TutorAvatar:$(this).data("avatar"),UserId:$(this).data("userid")})});customDropDownUtilsHelper.BindAjaxServiceList(u,s,function(n){var t=$(n).data("url");document.location.href=t});r.filter(".active").each(function(){$(this).trigger("click")})};this.Init=function(n,t,r,u,f,e,s,h,l,a,v,y){c();i=new TutorSearchFilter;i.Init({ServiceTagIds:n,Timetable:t,ServiceId:r,SortField:u,servicecategorynameid:f,servicenameid:e,languageid:LanguageId,PriceFrom:s,PriceFromDefault:h,PriceTo:l,PriceToDefault:a,TargetAudience:v,HasVideo:y});o.Init()}}