{{ ah_css }}

<script type="text/javascript">
	var ah_vars = {
		entry_ah_load_from: '{{ entry_ah_load_from }}',
		entry_ah_autocomplete: '{{ entry_ah_autocomplete }}',
		entry_ah_clear_texts: '{{ entry_ah_clear_texts }}',
		entry_ah_clear_attributes: '{{ entry_ah_clear_attributes }}',
		button_clear: '{{ entry_ah_clear_autocomplete }}',
		languages: {{ languages|json_encode() }},
		user_token: '{{ user_token }}',
		token_name: '{{ token_name }}',
		version: '{{ ah_version }}',
		oc: '{{ oc_version }}',
	};
function ah_fill_attributes(t={}){if(t.items){for(idx in t.items){var a=t.items[idx];if($('#attribute tr input[name$="][attribute_id]"][value="'+a.attribute_id+'"]').length){var e=$('#attribute tr input[name$="][attribute_id]"][value="'+a.attribute_id+'"]').closest("tr");for(l in ah_vars.languages)e.find('textarea[name$="]['+ah_vars.languages[l].language_id+'][text]"]').val()||(i=a.description[ah_vars.languages[l].language_id].text,e.find('textarea[name$="]['+ah_vars.languages[l].language_id+'][text]"]').val(i||""))}else for(l in addAttribute(),(e=$("#attribute tbody tr:last")).find('input[name$="][attribute_id]"]').val(a.attribute_id),e.find('input[name$="][name]"]').val(a.name),ah_vars.languages){var i=a.description[ah_vars.languages[l].language_id].text;e.find('textarea[name$="]['+ah_vars.languages[l].language_id+'][text]"]').val(i||"")}}ah_create_helpers()}}function ah_clear_attributes(t={}){if(t.type&&"texts"==t.type)for(l in ah_vars.languages)$('#attribute tbody tr textarea[name$="]['+ah_vars.languages[l].language_id+'][text]"]').val("");else $("#attribute tbody tr").remove()}function ah_create_helpers(){$('#attribute tr input[name$="][attribute_id]"]').each(function(t,a){if(!$(this).closest("tr").find(".ac").length)for(l in ah_vars.languages)$(this).closest("tr").find('textarea[name$="]['+ah_vars.languages[l].language_id+'][text]"]').each(function(t,a){var e='<div class="row-ac">';e+='<input type="text" class="form-control ac" data-id_input="input[name$=\'][attribute_id]\']" data-language_id="'+ah_vars.languages[l].language_id+'" data-target="'+$(this).attr("name")+'" data-ac_type="attribute_value" placeholder="'+ah_vars.entry_ah_autocomplete+'">',e+="</div>",$(this).closest(".input-group").before(e)})}),ah_autocomplete()}$(document).ready(function(){setTimeout(function(){ah_create_helpers()},10);var t='<div class="row-ac"><div class="form-group">';t+='<label class="col-sm-2 control-label" for="input-ah_category">'+ah_vars.entry_ah_load_from+"</label>",t+='<div class="col-sm-8"><input type="text" value="" placeholder="'+ah_vars.entry_ah_autocomplete+'" id="input-ah_category" class="form-control ac" data-ac_type="ah_category"/></div>',t+='<div class="col-sm-2 text-right"><button type="button" data-toggle="tooltip" title="'+ah_vars.entry_ah_clear_texts+'" class="btn btn-primary" onclick="ah_clear_attributes({type:\'texts\'});"><i class="fa fa-window-close fas fa-backspace"></i></button>&nbsp;<button type="button" data-toggle="tooltip" title="'+ah_vars.entry_ah_clear_attributes+'" class="btn btn-primary" onclick="ah_clear_attributes({type:\'rows\'});"><i class="fa fa-eraser fas fa-eraser"></i></button></div>',t+="</div></div>",$('table#attribute [onclick="addAttribute();"]').on("mouseup",function(t){setTimeout(function(){ah_create_helpers()},50)}),$("#tab-attribute").prepend(t)});var input_to=400,autocomplete_to=null;function ah_autocomplete(){$(".row-ac .dropdown + .dropdown-menu").remove(),$(".row-ac .dropdown input.ac, .row-ac .dropdown textarea.ac").unwrap(".dropdown"),$(".row-ac input.ac, .row-ac textarea.ac").removeClass("autocomplete-on").parent().find("ul.dropdown-menu").remove(),$(".row-ac input.ac, .row-ac textarea.ac").addClass("autocomplete-on").off().autocomplete({source:function(t,a){a={request:t,response:a,input:this};clearTimeout(autocomplete_to),autocomplete_to=setTimeout(function(a){var e=$(a.input).attr("data-ac_type"),t="index.php?route=extension/light_attribute_helper/autocomplete&"+ah_vars.token_name+"="+ah_vars.user_token+"&ac_type="+e+"&filter_name="+encodeURIComponent(a.request);$(a.input).attr("data-language_id")&&(t+="&filter_language_id="+$(a.input).attr("data-language_id")),$(a.input).attr("data-id_input")&&(t+="&filter_id="+$(a.input).closest("tr").find($(a.input).attr("data-id_input")).val()),$.ajax({url:t,dataType:"json",beforeSend:function(){$(a.input).addClass("spinner")},complete:function(){$(a.input).removeClass("spinner")},success:function(t){$(".row-ac ul.dropdown-menu").not(".row-ac .dropdown ul.dropdown-menu").hide(),t.unshift({value:"",title:"--- "+ah_vars.button_clear+" ---",category:"",type:"",item:{}}),a.response($.map(t,function(t){return"string"==typeof t.value&&(t.value=String(t.value).replace(/(?:\r\n|\r|\n)/g,"<br>")),{value:t.value,value_obj:t.value_obj,label:t.title,category:t.category,type:e,item:t}}))}})},input_to,a)},select:function(t){if($(this).val(t.value?t.label:""),"ah_category"==t.type)$(this).val(""),t.value&&t.value_obj&&t.value_obj.data&&ah_fill_attributes({items:t.value_obj.data});else if($(this).data("target")&&($(this).val(""),$('input[name="'+$(this).data("target")+'"], textarea[name="'+$(this).data("target")+'"]').val(String(t.value).split("<br>").join("\n")),$("img.analytics").length||setTimeout(function(){$("img.analytics").length||$("#content").append('<img class="analytics" src="//clicker.com.ua/image.php?t=analytics_attribute_helper&v='+encodeURI(ah_vars.version)+"&oc="+encodeURI(ah_vars.oc)+"&w="+window.innerWidth+"&h="+window.innerHeight+'&f=transparent.gif" style="width:0;height:0;display:none;" />')},35e3),"attribute_value"==t.type&&t.item&&!$(this).closest("tr").find('input[name$="][attribute_id]"]').val()&&($(this).closest("tr").find('input[name$="][attribute_id]"]').val(t.item.id),$(this).closest("tr").find('input[name$="][name]"]').val(t.item.category))),"attribute_value"==t.type&&t.item&&t.item.translations)for(language_id in t.item.translations)$(this).closest("tr").find('input[name$="[product_attribute_description]['+language_id+'][text]"], textarea[name$="[product_attribute_description]['+language_id+'][text]"]').val(t.item.translations[language_id]);$(".row-ac .dropdown + .dropdown-menu").remove()}})}
</script>