jQuery(function(o){var n="This item must contain at least one choice";function r(){o(document).trigger("nrChoicesUpdate"),ConvertFormsBuilder.FieldsHelper.emitEvent("update")}o(document).on("change",".nr-choice-item input.nr-choice-default",function(e){var t=o(this);t.closest(".nr_choices").find("input[type=radio]").not(t).prop("checked",!1).trigger("update"),r()}),o(document).on("change",".nr-choice-settings .showvalues",function(e){var t=o(this),c=t.closest(".nr-choice-settings").prev(),t=t.is(":checked");c.find("input.nr-choice-value").css({display:t?"block":"none"})}),o(document).on("change",".nr-choice-settings .showcalcvalues",function(e){var t=o(this),c=t.closest(".nr-choice-settings").prev(),t=t.is(":checked");c.find("input.nr-choice-calc-value").css({display:t?"block":"none"})}),o(document).on("click",".nr-choice-remove",function(e){var t,c;e.preventDefault(),e=o(this),t=e.closest(".nr_choices"),c=parseInt(t.find(".nr-choice-item").length),t=parseInt(t.data("min")),c==t?alert(n):(e.closest(".nr-choice-item").remove(),r())}),o(document).on("click",".nr-choice-add",function(e){e.preventDefault();var t=(e=o(this)).closest(".nr-choice-item"),c=t.find("input[type=radio]").is(":checked"),e=e.closest(".nr_choices"),n=parseInt(e.attr("data-nextid")),i=e.attr("data-fieldname"),a=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+"]")),a.attr("data-id",n),a.find("input.nr-choice-label").val("").attr("name",i+"[choices]["+n+"][label]"),a.find("input.nr-choice-value").val("").attr("name",i+"[choices]["+n+"][value]"),a.find("input.nr-choice-calc-value").val("").attr("name",i+"[choices]["+n+"][calc-value]"),a.find("input.nr-choice-default").attr("name",i+"[choices]["+n+"][default]").prop("checked",!1),1==c&&t.find("input[type=radio]").prop("checked",!0),n++,e.attr("data-nextid",n),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()}}))})});

