(()=>{document.querySelectorAll('[data-dialog]').forEach(b=>b.onclick=()=>document.getElementById(b.dataset.dialog)?.showModal());document.querySelectorAll('[data-close]').forEach(b=>b.onclick=()=>b.closest('dialog')?.close());const box=document.getElementById('form-builder');let drag=null;if(box){box.querySelectorAll('[draggable]').forEach(el=>{el.addEventListener('dragstart',()=>drag=el);el.addEventListener('dragover',e=>{e.preventDefault();if(drag&&drag!==el)box.insertBefore(drag,el);});});document.getElementById('order-form')?.addEventListener('submit',()=>{document.getElementById('order-json').value=JSON.stringify([...box.children].map(x=>x.dataset.id));});}document.querySelectorAll('[data-device]').forEach(b=>b.onclick=()=>{document.querySelectorAll('[data-device]').forEach(x=>x.classList.remove('active'));b.classList.add('active');const d=b.dataset.device;document.getElementById('live-preview')?.querySelectorAll('label').forEach(el=>{el.className='span-'+el.dataset[d];});});})();
