;(function($){"use strict";ips.controller.register('forums.front.forum.flow',{_ids:[],_button:null,_rootForum:null,urlParam:'forumId',initialize:function(){this.on('click','[data-node-id]',this.toggleFilters);this.setup();},setup:function(){var self=this;if(this.scope.attr('data-rootForum')!==undefined){this._rootForum=this.scope.attr('data-rootForum');}
if(this._rootForum){this.urlParam='forumId'+this._rootForum;}
var _ids=ips.utils.url.getParam(this.urlParam);if(_ids!==undefined){this._ids=decodeURIComponent(_ids).split(',');}else if(this._rootForum){var found=false;if(ips.utils.cookie.get('forums_flowIdsRoots')!==undefined){try{var _jsonIds=JSON.parse(ips.utils.cookie.get('forums_flowIdsRoots'))[this._rootForum];found=true;if(_jsonIds!==undefined){this._ids=_jsonIds;}}catch(exc){}}
if(!found){this.scope.find('[data-node-id]').each(function(i,node){var id=$(node).attr('data-node-id');self._ids.push(id);});}}else if(ips.utils.cookie.get('forums_flowIds')!==undefined){this._ids=ips.utils.cookie.get('forums_flowIds').split(',');}
if(this._ids&&typeof this._ids==='object'&&!Array.isArray(this._ids)&&Object.keys(this._ids).length){Object.entries(this._ids).forEach(([key,val])=>{if(val){self.childSelect(val,true);}});}
if(_ids===undefined&&this._ids.length&&this._rootForum===null){$(document).trigger('updateTableURL',{[this.urlParam]:[...new Set(Object.values(this._ids))].join(',')});}
this._button=$('body').find("[data-ipsDialog-content='#elFluidFormFilters']");this._buttonText=$('body').find('[data-role="fluidForumMobileDesc"]');this._updateButtonText();},toggleFilters:function(e){e.preventDefault();var link=$(e.currentTarget);var id=link.attr('data-node-id');var parentId=link.attr('data-parent-id');var hasChildren=link.attr('data-has-children');if((this._ids).indexOf(id)==-1){this.childSelect(id,false);}else{this.childUnselect(id);}
this._updateButtonText();$(document).trigger('updateTableURL',{[this.urlParam]:[...new Set(Object.values(this._ids))].join(',')});},isSelected:function(id){return this.scope.find('[data-node-id="'+id+'"]').hasClass('cForumMiniList__selected')?true:false;},childSelect:function(id,skipChildren){Debug.log("Select child: "+id);this._ids.push(id);var node=this.scope.find('[data-node-id="'+id+'"]');node.addClass('cForumMiniList__selected');var parentId=node.attr('data-parent-id');if(skipChildren===false&&(node.attr('data-has-children')||id==parentId)){var self=this;for(const[k,v]of this.scope.find('[data-parent-id="'+id+'"]').toArray().entries()){var _cId=$(v).attr('data-node-id');if(_cId!=id){self.childSelect(_cId,false);}};}
this.updateCookie();},childUnselect:function(id){Debug.log("UNselect child: "+id);this.scope.find('[data-node-id="'+id+'"]').removeClass('cForumMiniList__selected');this._ids=this._ids.filter(item=>item!==id);this.updateCookie();if(this._rootForum===null){var self=this;for(const[k,v]of(this.scope.find('[data-parent-id="'+id+'"]').toArray().entries())){var _cId=$(v).attr('data-node-id');if(_cId!=id){self.childUnselect(_cId);}};this.parentUnselect(this.scope.find('[data-node-id="'+id+'"]').closest('[data-category]').find('[data-node-id]').first().attr('data-node-id'));}},parentSelect:function(parentId){Debug.log("Select parent: "+parentId);this.scope.find('[data-node-id="'+parentId+'"]').addClass('cForumMiniList__selected');if(this._rootForum===null){var self=this;for(const[k,v]of(this.scope.find('[data-parent-id="'+parentId+'"]').toArray().entries())){var _cId=$(v).attr('data-node-id');if(_cId!=parentId){self.childUnselect(_cId);}};}else{this.updateCookie();}},parentUnselect:function(parentId){Debug.log("UNselect parent: "+parentId);var node=this.scope.find('[data-node-id="'+parentId+'"]');node.removeClass('cForumMiniList__selected');this._ids=this._ids.filter(id=>id!==parentId);this.updateCookie();Debug.log("Looking for parent ID "+node.attr('data-parent-id'));if(this._rootForum===null){var self=this;for(const[k,v]of(this.scope.find('[data-node-id="'+node.attr('data-parent-id')+'"]').toArray().entries())){var _cId=$(v).attr('data-node-id');if(_cId!=parentId){Debug.log("Found "+_cId);self.parentUnselect(_cId);}};}},updateCookie:function(id){var cookie=[...new Set(Object.values(this._ids))].join(',');Debug.log("Updating cookie: "+cookie);if(!this._rootForum){ips.utils.cookie.set('forums_flowIds',cookie,true);}else{var _json={};if(ips.utils.cookie.get('forums_flowIdsRoots')!==undefined){_json=JSON.parse(ips.utils.cookie.get('forums_flowIdsRoots'));}
_json[this._rootForum]=[...new Set(Object.values(this._ids))];ips.utils.cookie.set('forums_flowIdsRoots',JSON.stringify(_json),true);Debug.log("Updating cookie: "+JSON.stringify(_json));}},_updateButtonText:function(){var blobs=this.scope.find('.cForumMiniList__blob');var selectedBlobRows=blobs.filter(function(){if($(this).closest('.cForumMiniList__selected').length){return true;}
return false;});var text='',buttonClass='';if(blobs.length==selectedBlobRows.length||selectedBlobRows.length===0){text=ips.getString('topicsFromAllForums');buttonClass='ipsButton--inherit';}else{text=ips.pluralize(ips.getString('topicsFromXForums'),selectedBlobRows.length);buttonClass='ipsButton--secondary';}
this._buttonText.text(text);this._button.removeClass("ipsButton--inherit ipsButton--secondary").addClass(buttonClass);}});}(jQuery));;
;(function($,_){"use strict";ips.controller.register('forums.front.forum.forumList',{initialize(){this.on('ips:toggleForumCategory',this.toggleCategory);this.setup();},setup(){let hiddenCategories=ips.utils.db.get('hiddenCategories');if(hiddenCategories&&typeof hiddenCategories==='object'&&!Array.isArray(hiddenCategories)&&Object.keys(hiddenCategories).length){Object.entries(hiddenCategories).forEach(([key,val])=>{document.querySelector("[aria-controls='forum-category_"+key+"']")?.setAttribute('aria-expanded','false');document.getElementById('forum-category_'+key)?.setAttribute('hidden','');});}},toggleCategory(e){const category=e.target;const categoryID=category.closest('[data-categoryID]')?.dataset.categoryid;if(!category||!categoryID){Debug.warn(`The forum list got a category hidden toggle event but couldn't determine which category was toggled`);return;}
if(e.detail.hidden){ips.utils.db.set('hiddenCategories',categoryID,true);}else{ips.utils.db.remove('hiddenCategories',categoryID);}}});}(jQuery));;
;(function($){"use strict";ips.controller.register('forums.front.forum.forumPage',{initialize:function(){this.on('click','[data-action="markForumRead"]',this.markForumRead);},markForumRead(e){e.preventDefault();ips.ui.alert.show({type:'confirm',icon:'question',message:ips.getString('markForumAsReadConfirm'),subText:'',callbacks:{ok:()=>{const url=$(e.currentTarget).attr('href');ips.getAjax()(url,{showLoading:true,bypassRedirect:true}).done(()=>{this.triggerOn('core.global.core.table','markTableRead');ips.utils.anim.go('fadeOut',$(e.currentTarget));ips.ui.flashMsg.show(ips.getString('forumMarkedRead'));}).fail(function(jqXHR,textStatus,errorThrown){window.location=url;});}}});}});}(jQuery));;
;(function($){"use strict";ips.controller.register('forums.front.forum.hovercard',{initialize:function(){this.on('click','[data-action="markTopicRead"]',this.markTopicRead);},markTopicRead:function(e){e.preventDefault();if($(e.currentTarget).attr('data-disabled')){return;}
this.trigger('markTableRowRead',{tableID:'topics',rowID:this.scope.attr('data-topicID')});ips.ui.flashMsg.show(ips.getString('topicMarkedRead'));ips.getAjax()($(e.currentTarget).attr('href'),{bypassRedirect:true});$(e.currentTarget).addClass('i-opacity_4').attr('data-disabled');}});}(jQuery));;