jQuery(function(a){var c="This item must contain at least one choice";function r(){a(document).trigger("nrChoicesUpdate"),ConvertFormsBuilder.FieldsHelper.emitEvent("update")}a(document).on("change",".nr-choice-item input.nr-choice-default",function(e){var t=a(this);t.closest(".nr_choices").find("input[type=radio]").not(t).prop("checked",!1).trigger("update"),r()}),a(document).on("change",".nr-choice-settings .showvalues",function(e){var t=a(this),n=t.closest(".nr-choice-settings").prev(),t=t.is(":checked");n.find("input.nr-choice-value").css({display:t?"block":"none"})}),a(document).on("change",".nr-choice-settings .showcalcvalues",function(e){var t=a(this),n=t.closest(".nr-choice-settings").prev(),t=t.is(":checked");n.find("input.nr-choice-calc-value").css({display:t?"block":"none"})}),a(document).on("click",".nr-choice-remove",function(e){var t,n;e.preventDefault(),e=a(this),t=e.closest(".nr_choices"),n=parseInt(t.find(".nr-choice-item").length),t=parseInt(t.data("min")),n!=t?(e.closest(".nr-choice-item").remove(),r()):alert(c)}),a(document).on("click",".nr-choice-add",function(e){e.preventDefault();var t=(e=a(this)).closest(".nr-choice-item"),n=t.find("input[type=radio]").is(":checked"),e=e.closest(".nr_choices"),c=parseInt(e.attr("data-nextid")),i=e.attr("data-fieldname"),o=t.clone().insertAfter(t);(repeatableField=e.closest(".subform-repeatable-group")).length&&repeatableField[0].hasAttribute("data-new")&&(repeatableIndex=repeatableField.data("group"),i=i.replace("[fieldsX]","["+repeatableIndex+"]")),o.attr("data-id",c),o.find("input.nr-choice-label").val("").attr("name",i+"[choices]["+c+"][label]"),o.find("input.nr-choice-value").val("").attr("name",i+"[choices]["+c+"][value]"),o.find("input.nr-choice-default").attr("name",i+"[choices]["+c+"][default]").prop("checked",!1),1==n&&t.find("input[type=radio]").prop("checked",!0),c++,e.attr("data-nextid",c),r()}),document.querySelector(".nrEditor").addEventListener("fields.displayOptions",function(e){e=e.detail.el.querySelector(".nr_choices");e&&(ConvertFormsBuilder.loadStylesheet("media/com_convertforms/css/choices.css"),new Sortable(e,{animation:150,handle:".nr-choice-sort",onUpdate:function(){r()}}))})});

