import{c as a}from"./Modal-CdmBMJvd.js";import{a as n}from"./file-manager-BqTxa2JX.js";import{b as s}from"./select2-kdrdsacH.js";import{a as m}from"./toast-BolBYJGe.js";import{m as r}from"./module.esm-A8h-QRCZ.js";import{$ as d}from"./jquery-BJllTr_o.js";import"./helper-DH3MvDof.js";import"./moment-BxhnadHa.js";import"./mapbox-Cpj98o6Y.js";s("supported_currencies");s("field_type");n("image","image");d(".handle_add_new_extra_field").on("submit",function(e){e.preventDefault();const t={label:d(this).find('input[name="label"]').val(),field_type:d(this).find('select[name="field_type"]').val(),required:d(this).find('input[name="required"]').is(":checked")?1:0};!t.label||!t.field_type?m("Please fill all the required fields"):(window.AddNewField(t),a())});d(".handle_edit_extra_field").on("submit",function(e){e.preventDefault();const t={label:d(this).find('input[name="label"]').val(),field_type:d(this).find('select[name="field_type"]').val(),required:d(this).find('input[name="required"]').is(":checked")?1:0};window.updateItem(d(this).find('input[name="field_id"]').val(),t),a()});d("#copy_button").on("click",async function(){let e=d("#webhook_url").val();try{await navigator.clipboard.writeText(e),d("#copy_message").removeClass("hidden").fadeIn().delay(1500).fadeOut()}catch(t){console.error("Failed to copy text: ",t)}});r.data("metaAdd",()=>({page:null,selectedItems:[],draggedItem:null,draggedFrom:null,draggedIndex:null,isDragging:!1,startDrag(e,t,i){this.draggedItem=t==="selected"?this.selectedItems[i]:this.availableItems[i],this.draggedFrom=t,this.draggedIndex=i,this.isDragging=!0,e.dataTransfer.effectAllowed="move"},endDrag(){this.isDragging=!1},allowDrop(e){e.preventDefault()},handleDrop(e,t=null){e.preventDefault(),this.draggedFrom==="selected"&&(this.selectedItems.splice(this.draggedIndex,1),t!==null?this.selectedItems.splice(t,0,this.draggedItem):this.selectedItems.push(this.draggedItem)),this.resetDragState(),this.selectedItems.forEach((i,l)=>{i.order=l})},deleteItem(e){this.selectedItems.splice(e,1)},editItem(e){const t=this.selectedItems[e],i=document.getElementById("meta_extra_field_edit_modal");i.querySelector('input[name="label"]').value=t.label,i.querySelector('select[name="field_type"]').value=t.field_type,i.querySelector('input[name="required"]').checked=t.required===1?1:0,i.querySelector('input[name="field_id"]').value=e},updateItem(e,t){e=parseInt(e),this.selectedItems[e]={...this.selectedItems[e],...t},this.selectedItems.forEach((i,l)=>{i.order=l})},resetDragState(){this.draggedItem=null,this.draggedFrom=null,this.draggedIndex=null,this.isDragging=!1},addNewField(e){this.selectedItems.push({...e,order:this.selectedItems.length})},init(){window.AddNewField=this.addNewField.bind(this),window.updateItem=this.updateItem.bind(this)}}));r.start();
