var GFGenericMap=function(a){var b=this;return b.options=a,b.UI=jQuery("#gaddon-setting-row-"+b.options.fieldName),b.init=function(){b.bindEvents(),b.setupData(),b.setupRepeater()},b.bindEvents=function(){b.UI.on("change",'select[name="_gaddon_setting_'+b.options.keyFieldName+'"]',function(){var a=jQuery(this),b=a.data("chosen")?a.siblings(".chosen-container"):a.data("select2")?a.siblings(".select2-container"):a,c=a.siblings(".custom-key-container");"gf_custom"==a.val()&&b.fadeOut(function(){c.fadeIn().focus()})}),b.UI.on("change",'select[name="_gaddon_setting_'+b.options.valueFieldName+'"]',function(){var a=jQuery(this),b=a.data("chosen")?a.siblings(".chosen-container"):a.data("select2")?a.siblings(".select2-container"):a,c=a.siblings(".custom-value-container");"gf_custom"==a.val()&&b.fadeOut(function(){c.fadeIn().focus()})}),b.UI.on("click","a.custom-key-reset",function(a){a.preventDefault();var b=jQuery(this),c=b.parents(".custom-key-container"),d=c.siblings("select.key"),e=d.data("chosen")?d.siblings(".chosen-container"):d.data("select2")?d.siblings(".select2-container"):d;c.fadeOut(function(){c.find("input").val("").change(),d.val("").trigger("change"),e.fadeIn().focus()})}),b.UI.on("click","a.custom-value-reset",function(a){a.preventDefault();var b=jQuery(this),c=b.parents(".custom-value-container"),d=c.siblings("select.value"),e=d.data("chosen")?d.siblings(".chosen-container"):d.data("select2")?d.siblings(".select2-container"):d;c.fadeOut(function(){c.find("input").val("").change(),d.val("").trigger("change"),e.fadeIn().focus()})}),b.UI.closest("form").on("submit",function(a){jQuery('[name^="_gaddon_setting_'+b.options.fieldName+'_"]').each(function(a){jQuery(this).removeAttr("name")})})},b.setupData=function(){b.data=jQuery.parseJSON(jQuery("#"+b.options.fieldId).val()),b.data||(b.data=[{key:"",value:"",custom_key:"",custom_value:""}])},b.setupMergeTags=function(a){a.bind("keydown",function(a){var b=!(!jQuery(this).data("autocomplete")||!jQuery(this).data("autocomplete").menu)&&jQuery(this).data("autocomplete").menu.active;a.keyCode===jQuery.ui.keyCode.TAB&&b&&a.preventDefault()}),a.autocomplete({minLength:1,source:function(b,c){var d=gfMergeTags.extractLast(b.term);if(d.length<a.autocomplete("option","minLength"))return void c([]);c(jQuery.map(gfMergeTags.getAutoCompleteMergeTags(a),function(a){return gfMergeTags.startsWith(a,d)?a:null}))},focus:function(){return!1},select:function(b,c){var d=gfMergeTags.split(this.value);return d.pop(),d.push(c.item.value),this.value=d.join(" "),a.trigger("input").trigger("propertychange"),!1}})},b.setupRepeater=function(){var a=b.options.limit>0?b.options.limit:0;b.UI.find("tbody.repeater").repeater({limit:a,items:b.data,addButtonMarkup:"<span>+</span>",removeButtonMarkup:"<span>-</span>",callbacks:{add:function(a,c,d){var e=c.find('select[name="_gaddon_setting_'+b.options.keyFieldName+'"]');!d.custom_key&&e.length>0?c.find(".custom-key-container").hide():c.find(".key").hide();var f=c.find('select[name="_gaddon_setting_'+b.options.valueFieldName+'"]');!d.custom_value&&f.length>0?c.find(".custom-value-container").hide():c.find(".value").hide(),b.options.mergeTags&&b.setupMergeTags(c.find(".custom-value-container input")),window.hasOwnProperty("gform")&&gform.doAction("gform_fieldmap_add_row",a,c,d)},save:function(a,c){jQuery("#"+b.options.fieldId).val(JSON.stringify(c))}}})},b.init()};