let PaymentPageElementor_FormFields={elementorInstance:null,container:{},repeaterContainer:{},groupTemplateContainer:{},Init:function(e){this.elementorInstance=e,this.container=jQuery(e.el),this.repeaterContainer=this.container.find(".fields-repeater-container"),this.groupTemplateContainer=this.repeaterContainer.find(".field-group-template"),this.groupTemplateContainer.hide();let t=this,i=e.getControlValue(),n=[];jQuery.each(Object.values(i),(function(e,t){void 0!==t.order&&(t.order=parseInt(t.order)),n.push(t)})),console.log(i),n=_.sortBy(n,"order"),jQuery.each(n,(function(e,i){t._attachFieldRow(i)})),t.__bindFieldOrdering(),this.container.find(".add-more-options").off("click").on("click",(function(e){e.preventDefault(),t._attachFieldRow({name:"custom_field_"+Date.now(),type:"custom",size:6,size_mobile:0,order:t.repeaterContainer.find(".field-group").length}),t.__bindFieldOrdering(),t.syncToElementor()}))},_attachFieldRow:function(e){this.groupTemplateContainer.clone().appendTo(this.repeaterContainer);let t=this,i=this.repeaterContainer.find(".field-group-template:last");i.removeClass("field-group-template").show(),void 0!==e.name&&i.find('[data-setting="key"]').val(e.name),void 0!==e.type&&(i.find('[data-setting="type"]').val(e.type),-1===jQuery.inArray(e.type,["payment_method_card","payment_method_iban"])?void 0!==e.placeholder&&i.find('[data-setting="placeholder"]').val(e.placeholder):i.find('[data-setting-container="placeholder"]').remove(),"custom"===e.type?void 0!==e.is_required&&parseInt(e.is_required)&&i.find('[data-setting="is_required"]').prop("checked",1):(i.find(".remove-field-container").hide(),i.find('[data-setting-container="is_required"]').remove())),void 0!==e.is_hidden||void 0!==e.name&&"card_zip_code"===e.name?void 0!==e.is_hidden&&parseInt(e.is_hidden)&&i.find('[data-setting="is_hidden"]').prop("checked",1):i.find('[data-setting-container="is_hidden"]').remove(),void 0!==e.label&&i.find('[data-setting="label"]').val(e.label),void 0!==e.size&&i.find('[data-setting="size"]').val(e.size),void 0!==e.size_mobile&&i.find('[data-setting="size_mobile"]').val(e.size_mobile),i.find("[data-setting]").on("keyup change",(function(e){t.syncToElementor()})),i.find(".remove-field").off("click").on("click",(function(){jQuery(this).parents(".field-group:first").remove(),t.syncToElementor()}))},__bindFieldOrdering:function(){let e=this,t=this.repeaterContainer.find(".field-group").not(".field-group-template");this.repeaterContainer.data("sortable")&&this.repeaterContainer.sortable("destroy"),this.repeaterContainer.removeClass("ui-sortable"),this.repeaterContainer.sortable({handle:"> .payment-page-draggable-container > .payment-page-draggable",axis:"y",opacity:.7,tolerance:"pointer",revert:!0,stop:function(i,n){t.each((function(){jQuery(this).find('[data-setting="order"]').val(jQuery(this).index())})),e.syncToElementor()}})},syncToElementor:function(){let e={};this.repeaterContainer.find(".field-group").not(".field-group-template").each((function(){let t=jQuery(this).find('[data-setting="key"]').val(),i=jQuery(this).find('[data-setting="type"]').val(),n=jQuery(this).find('[data-setting="order"]').val(),a=jQuery(this).find('[data-setting="label"]').val(),r=jQuery(this).find('[data-setting="size"]').val(),o=jQuery(this).find('[data-setting="size_mobile"]').val(),d=jQuery(this).find('[data-setting="is_hidden"]'),s=jQuery(this).find('[data-setting="is_required"]'),l=jQuery(this).find('[data-setting="placeholder"]');e[t]={label:a,name:t,placeholder:l.length>0?l.val():"",is_required:s.length>0?s.is(":checked")?1:0:1,type:i,size:r,size_mobile:o,order:n},d.length>0&&(e[t].is_hidden=d.is(":checked")?1:0)})),this.elementorInstance.setValue(e)}};jQuery,jQuery(window).on("load",(function(){let e=window.elementor.modules.controls.BaseData.extend({_instance:null,onReady:function(){this._instance=jQuery.extend(!0,{},PaymentPageElementor_FormFields),this._instance.Init(this)},ui:function(){return{anySetting:"input[data-setting]"}},onFieldChange:function(e){this._instance.syncToElementor()},onApplyClicked:function(e){e.preventDefault(),this._instance.syncToElementor()}});window.elementor.addControlView("payment_page_form_fields",e)}));