function l(){const r=document.getElementById("sections-list"),s=document.getElementById("section-row-tpl");if(!r||!s||r.dataset.wired==="1")return;r.dataset.wired="1";const n=()=>{r.querySelectorAll("[data-section-row]").forEach((t,e)=>{t.querySelectorAll("[name]").forEach(o=>{o.name=o.name.replace(/sections\[[^\]]*\]/,`sections[${e}]`)})})},c=t=>{const e=t.querySelector("[data-preview]"),o=t.querySelector("[data-body]");if(!e||e.classList.contains("hidden"))return;const a=e.querySelector(".prose-body");a&&(a.innerHTML=o?o.value:"")},d=()=>{const t=s.content.cloneNode(!0);r.appendChild(t),n();const e=r.querySelectorAll("[data-section-row]");e[e.length-1]?.querySelector("[data-title]")?.focus()};document.querySelectorAll("[data-add-section]").forEach(t=>t.addEventListener("click",d)),r.addEventListener("click",t=>{const e=t.target.closest("[data-section-row]");if(e){if(t.target.closest("[data-remove]")){e.remove(),n();return}if(t.target.closest("[data-move-up]")){const o=e.previousElementSibling;o&&e.parentNode.insertBefore(e,o),n();return}if(t.target.closest("[data-move-down]")){const o=e.nextElementSibling;o&&e.parentNode.insertBefore(o,e),n();return}if(t.target.closest("[data-preview-toggle]")){const o=e.querySelector("[data-preview]"),a=t.target.closest("[data-preview-toggle]");if(o){o.classList.toggle("hidden");const i=!o.classList.contains("hidden");a.textContent=i?"Hide preview":"Preview",i&&c(e)}}}}),r.addEventListener("input",t=>{t.target.matches("[data-body]")&&c(t.target.closest("[data-section-row]"))}),n()}export{l as default};
