;(function($,_){"use strict";ips.controller.register('core.front.profile.main',{contentArea:null,lastType:null,initialize(){this.on('click','[data-action="goToProfile"]',this.changeType);this.on('click','[data-action="browseContent"]',this.changeType);this.on('click','[data-action="repLog"]',this.changeType);this.on('click','[data-action="badgeLog"]',this.changeType);this.on('click','[data-action="solutionLog"]',this.changeType);this.on(window,'historychange',this.stateChange);this.setup();},_getHistoryStateFromPage(){const elem=this.scope.get(0)
const selectorMap={browseContent:'#elUserContent',repLog:'#elUserReputation',badgeLog:'.cProfileBadgeGrid',solutionLog:'#elUserSolutions'}
for(const state in selectorMap){if(elem.querySelector(selectorMap[state])){return state}}
return"goToProfile"},setup(){this.contentArea=this.scope.find('[data-role="profileContent"]');this.contentHeader=this.scope.find('[data-role="profileHeader"]');if(!ips.utils.history.getState('profile')?.section){ips.utils.history.replaceState({section:this._getHistoryStateFromPage()},'profile',window.location.href);}},stateChange(e){if(e.detail?.type==='load'||e.detail?.type==='replace'){return}
const url=window.location.href
const data=ips.utils.history.getState('profile')
if(this._getHistoryStateFromPage()===data.section&&data.section){return}
this.lastType=data.section;e?.stopPropagation?.()
e?.stopImmediatePropagation?.()
switch(data?.section){case'goToProfile':this._showProfile(url);break;case'browseContent':this._showContent(url);break;case'repLog':case'solutionLog':case'badgeLog':this._showGenericLog(url);break;}},changeType(e){e.preventDefault();let target=$(e.currentTarget);if(!target.is('a')){target=target.find('a');}
ips.utils.history.pushState({section:$(e.currentTarget).attr('data-action')},'profile',target.attr('href'));document.title=target.attr('title')},_showGenericLog(url){this._changeContent(true,url).then(()=>{});},_showContent(url){this._changeContent(true,url).then(()=>{});},_showProfile(url){this._changeContent(false,url).then(()=>{});},async _changeContent(small,url){ips.controller.cleanContentsOf(this.contentArea);this.contentArea.css({height:String(this.contentArea.outerHeight())});this.contentArea.html($('<div/>').addClass('ipsLoading').css({height:'300px'}));this.contentHeader.find('#elProfileHeader').toggleClass('ipsCoverPhoto--minimal',small);url+=(url.includes('?')?'&':'?')+'entireSection=1';try{const response=await ips.fetch(url)
this.contentArea.hide().html(response).css({height:'auto'});ips.utils.anim.go('fadeIn fast',this.contentArea);$(document).trigger('contentChange',[this.contentArea]);}catch(e){window.location=url;}}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.front.profile.toggleBlock',{initialize:function(){this.on('click','[data-action="disable"]',this.toggleBlock);this.on('click','[data-action="enable"]',this.toggleBlock);},toggleBlock:function(e){e.preventDefault();var self=this;this.scope.css({opacity:"0.6"});ips.getAjax()($(e.currentTarget).attr('href'),{showLoading:true}).done(function(response){self.scope.html(response);$(document).trigger('contentChange',[self.scope]);}).fail(function(){window.location=$(e.currentTarget).attr('href');}).always(function(){self.scope.css({opacity:"1"});});}});}(jQuery));;
;(function($){"use strict";ips.controller.register('core.front.profile.followers',{_feedID:null,initialize:function(){this.on(document,'followingItem',this.followUser);this.on('menuItemSelected',"[data-role='followOption']",this.toggleFollowOption);this.setup();},setup:function(){this._feedID=this.scope.attr('data-feedID');},followUser:function(e,data){if(data.feedID!=this._feedID){return;}
var self=this;var memberID=data.feedID.replace('member-','');ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=core&module=members&controller=profile&do=followers&id='+parseInt(memberID)).done(function(response){self.scope.html(response);}).fail(function(){Debug.log('Error fetching follower HTML');});},toggleFollowOption:function(e,data=e.detail){data.originalEvent.preventDefault();var url=$(data.menuElem).find('[data-ipsMenuValue="'+data.selectedItemID+'"]').attr('href');ips.getAjax()(url).done(function(response){ips.ui.flashMsg.show(ips.getString('followerSettingToggled'));}).fail(function(){window.location=url;});}});}(jQuery));;