/*
 =======================================================================*\
|| ###################################################################### ||
|| # vBulletin 6.2.3
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2026 MH Sub I, LLC dba vBulletin. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
function vBulletin_Autocomplete(L,g){var e=$(L),M=g.apiClass||null,N=g.apiFunction||"getAutocomplete",O=g.delay||500,u=g.minLength||3,z=g.maxItems||!1,A=e.attr("name")||"autocompleteElements",P=g.containerClass||"entry-field",B=g.placeholderText,Q="undefined"!=typeof g.autoFocus?g.autoFocus:!1,R="undefined"!=typeof g.appendTo?g.appendTo:"body",C=g.delimiter||",",k=[],q=e.parent(".autocomplete-container"),h=q.find(".autocompleteHelper"),v=!1,w=!1,r=e.siblings(".autocomplete-box"),D=g.beforeAdd||!1,
E=g.afterAdd||!1,F=g.beforeDelete||!1,G=g.afterDelete||!1,H=this,t=g.editorContext||null,I=function(a,f,d){if(""==a||"function"==typeof D&&!D.call(this,a,f))return!1;var b=!0;$(k).each(function(n,p){p.label==a&&(b=!1)});if(!b||z&&k.length>=z)return!1;var c=$("<div />").addClass("element-x b-link").prop("title","x").html('<span class="b-icon-fa b-icon-fa--16 fa-solid fa-circle-xmark" aria-hidden="true"></span>'),l=$("<div />").addClass("element-text").text(a);$("<div />").addClass("autocomplete").append(l).append(c).appendTo(r);
k.push({label:a,value:f});x();"function"==typeof E&&E.call(this,a,f,d);r.show();return!0},y=function(a){var f=a.length,d;for(d=0;d<f;++d)I(a[d])},J=function(){r.html("");h.val("");k=[];x()},x=function(){var a=[];$(k).each(function(f,d){a.push(d.label)});e.val(a.join(C))},K=function(a,f,d){if(t)switch(t.type){case "tags":t.context.addTag(a)}else H.addElement(a,a),h.val("");if("undefined"!==typeof f&&"undefined"!==typeof d)return d.preventDefault(),!1};(function(){0==q.length&&(e.wrap('<div class="autocomplete-container b-form-input__input" />'),
q=e.parent(".autocomplete-container"),q.addClass(P).on("mousedown",function(b){var c=this;setTimeout(function(){var l=$(".autocompleteHelper:visible",c);0<l.length&&l[0].focus()},10);return!1}));0==r.length&&(r=$("<div />").addClass("autocomplete-box").insertBefore(e));0==h.length&&(h=$('<input type="text" name="autocompleteHelper" />').addClass("autocompleteHelper b-form-input__input b-form-input__input--hide-clear-button").attr("placeholder",function(){return B?B:null}).attr("maxlength",function(){return e.attr("maxlength")?
e.attr("maxlength"):null}).insertAfter(r));h.attr("tabindex",e.attr("tabindex")||0);h.off("keydown").on("keydown",function(b){if(13==b.which){var c=$(b.target).val();c.length>=u&&K(c,!0,b)}});h.off("blur").on("blur",function(b){v=window.setTimeout(function(){if(!w){var c=h.val();c.length>=u&&K(c,!0,b)}v=w=!1},200)});h.off("focus").on("focus",function(b){w=v?!0:!1;return!1});var a="font-family font-size font-weight font-style color line-height height".split(" "),f;for(f=0;f<a.length;++f)q.css(a[f],
e.css(a[f]));a='<input type="hidden" name="'+A+'"';e.attr("id")&&(a+=' id="'+e.attr("id")+'"');e.attr("class")&&(a+=' class="'+e.attr("class")+'"');if(e.attr("data-value"))var d=e.attr("data-value").split(C);e.replaceWith(a+" />");e=q.find('[name="'+A+'"]');h.autocomplete({classes:{"ui-autocomplete":"dialog-container"},autoFocus:Q,appendTo:R,delay:O,minLength:u,source:function(b,c){vBulletin.AJAX({call:"/ajax/api/"+M+"/"+N,data:{searchStr:b.term},success:function(l){if(l&&$.isArray(l.suggestions)){var n=
[];$.each(l.suggestions,function(p,m){p={label:m.title};t&&"tags"==t.type?p.value=pageData.userid:(p.value=m.value,"id"in m&&m.id&&(p.id=m.id),m.hasOwnProperty("htmllabel")&&(p.htmllabel=m.htmllabel));n.push(p)});c(n)}else vBulletin.error("error","error_getting_suggestions")},error_phrase:"error_getting_suggestions"})},select:function(b,c){H.addElement(c.item.label,c.item.value,c.item);h.val("");b.preventDefault()},focus:function(b,c){h.val(c.item.label);b.preventDefault()},open:function(b){b=$(b.target).autocomplete("instance").menu.element;
var c=parseInt($(".dialog-box").css("z-index"),10);b.css("z-index",c+1)}});if(a=h.data("ui-autocomplete"))a._renderItem=function(b,c){c=c.hasOwnProperty("htmllabel")?$("<div>").html(c.htmllabel):$("<div>").text(c.label);return $("<li>").append(c).appendTo(b)};r.on("click",".element-x",function(b){b=$(this).closest(".autocomplete");var c=b.find(".element-text").text().toLowerCase(),l=[],n=!1;$(k).each(function(p,m){m.label.toLowerCase()==c?n=m:l.push(m)});if("function"==typeof F&&!F.call(this,n.label,
n.data))return!1;k=l;b.remove();x();"function"==typeof G&&G.call(this,n.label,n.data)});q.off("click").on("click",function(b){$(b.target).hasClass("ui-autocomplete-input")||$(".ui-autocomplete-input",$(this)).trigger("focus");return!1});d&&y.call(this,d)}).call(this);this.addElement=function(a,f,d){return I.call(this,a,f,d)};this.addElements=function(a){y.call(this,a)};this.setElements=function(a){J();y(a)};this.getElements=function(){return k};this.getLabels=function(){var a=[];$(k).each(function(f,
d){a.push(d.label)});return a};this.getValues=function(){var a=[];$(k).each(function(f,d){a.push(d.value)});return a};this.getInputField=function(){return h};this.clearElements=function(){return J.call(this)};this.countElements=function(){return $(k).length};this.getMinLength=function(){return u};this.close=function(){h.val("");h.autocomplete("close")}};
