/* Cached on Thu, 30 Jan 2025 19:41:56 */
(function(e){e.widget("ui.tlCombobox",{widget:this,options:{allowInvalid:false,newOptionName:"_new_",placeholder:"Выбрать",minLength:0},_create:function(){function u(){var r=new RegExp("^"+e.ui.autocomplete.escapeRegex(i.val())+"$","i"),s=false;f().each(function(e,t){if(r.test(t.innerText)){t.selected=s=true;l();return false}});if(s)return;if(t.options.allowInvalid){var o=n.children("[value="+t.options.newOptionName+"]"),u=o.length?o:e("<option>").val(t.options.newOptionName);u.text(i.val());if(!o.length)n.append(u);u[0].selected=true;l()}else{n.val("");c();l()}}function a(){var e=n.children("option:selected");return (e.length&&e.val().length)?e:null}function f(){return n.children("option")}function l(){n.trigger({type:"change",fromWidget:true})}function c(){var e=a();i.val(e?e.text():t.options.placeholder).data("ui-autocomplete").term=e?e.text():""}function h(){if(!t.options.allowInvalid)return;if(o!=null){o.remove();o=null}if(n.val()==t.options.newOptionName){o=e('<input type="hidden">').attr("name",t.options.newOptionName).insertBefore(n).val(a().text())}}var t=this,n=this.element.hide(),r=e('<div class="tl-combobox">').insertAfter(n),i=e('<input type="text" class="tl-combobox-input">').appendTo(r),s=e('<span class="tl-combobox-toggle">').appendTo(r).toggle(this.options.minLength==0),o=null;this.options.newOptionName+=Math.random().toString().substr(2,8);i.autocomplete({minLength:t.options.minLength,delay:0,position:{my:"left-2 top",at:"left bottom",collision:"none"},source:function(t,n){var r=new RegExp(e.ui.autocomplete.escapeRegex(t.term),"i");n(f().map(function(n,i){var s=e(i).text();if(i.value&&(!t.term||r.test(s)))return{label:s.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)("+e.ui.autocomplete.escapeRegex(t.term)+")(?![^<>]*>)(?![^&;]+;)","gi"),"<strong>$1</strong>"),value:s,option:this}}))},select:function(e,t){t.item.option.selected=true;l()},change:function(e,t){if(!t.item){if(i.val().length)u();else{n.val("");c();l()}}}}).on("focus",function(){r.addClass("tl-combobox-focus");if(t.options.minLength==0)i.autocomplete("search","");if(i.val()==t.options.placeholder)i.val("")}).on("blur",c).on("blur",function(){r.removeClass("tl-combobox-focus")}).data("ui-autocomplete")._renderItem=function(t,n){return e("<li>").append("<a>"+n.label+"</a>").appendTo(t)};s.css({height:r.height(),padding:"0 "+i.css("padding-left")}).on("mousedown",function(e){i.focus();e.preventDefault()});n.on("change",function(e){if(n.val()!=t.options.newOptionName)n.children("[value="+t.options.newOptionName+"]").remove();if(t.options.allowInvalid)h();if(e.fromWidget)return;c()});c()},disable:function(){e(this.element).next().addClass("tl-combobox-disabled").children("input").attr("disabled","disabled")},enable:function(){e(this.element).next().removeClass("tl-combobox-disabled").children("input").removeAttr("disabled")}})})(jQuery)