import{t as g,a as m}from"./toast-BolBYJGe.js";import{m as d}from"./module.esm-A8h-QRCZ.js";import{a as h}from"./index-B9ygI19o.js";import"./mapbox-Cpj98o6Y.js";import"./jquery-BJllTr_o.js";d.data("editPage",()=>({page:null,selectedItems:[],availableItems:[],draggedItem:null,draggedFrom:null,draggedIndex:null,isDragging:!1,isSaving:!1,startDrag(t,e,s){this.draggedItem=e==="selected"?this.selectedItems[s]:this.availableItems[s],this.draggedFrom=e,this.draggedIndex=s,this.isDragging=!0,t.dataTransfer.effectAllowed="move"},endDrag(){this.isDragging=!1},allowDrop(t){t.preventDefault()},handleDrop(t,e=null){t.preventDefault(),this.draggedFrom==="selected"?(this.selectedItems.splice(this.draggedIndex,1),e!==null?this.selectedItems.splice(e,0,this.draggedItem):(this.selectedItems.push(this.draggedItem),this.availableItems.splice(this.draggedIndex,1))):this.draggedFrom==="available"&&(this.selectedItems.includes(this.draggedItem)||(e!==null?this.selectedItems.splice(e,0,this.draggedItem):(this.selectedItems.push(this.draggedItem),this.availableItems.splice(this.draggedIndex,1)))),this.resetDragState()},deleteItem(t){this.selectedItems.splice(t,1)},resetDragState(){this.draggedItem=null,this.draggedFrom=null,this.draggedIndex=null,this.isDragging=!1},savePage(){var e;this.isSaving=!0;const t=this.selectedItems.map((s,a)=>({id:s.id,order:a}));h.post(`/admin/settings/theme/pages/${(e=this.page)==null?void 0:e.id}/update-section`,{sections:t}).then(s=>{var a;g((a=s==null?void 0:s.data)==null?void 0:a.message),this.isSaving=!1}).catch(s=>{var i,l;let a=(l=(i=s==null?void 0:s.response)==null?void 0:i.data)==null?void 0:l.message;m(a),this.isSaving=!1})},init(){if(this.selectedItems.length){const t=new Set(this.selectedItems.map(e=>e.slug));this.availableItems=this.availableItems.filter(e=>!t.has(e.slug))}}}));d.start();
