(function () { function updateOrderLabels(list) { var items = list.querySelectorAll('.compose-asset'); items.forEach(function (item, index) { var badge = item.querySelector('.order-badge'); if (badge) { badge.textContent = 'Photo ' + (index + 1); } var upButton = item.querySelector('[data-move="up"]'); var downButton = item.querySelector('[data-move="down"]'); if (upButton) { upButton.disabled = index === 0; } if (downButton) { downButton.disabled = index === items.length - 1; } }); } document.addEventListener('DOMContentLoaded', function () { var list = document.querySelector('.compose-form .asset-list'); if (!list) { return; } list.addEventListener('click', function (event) { var button = event.target.closest('[data-move]'); if (!button) { return; } event.preventDefault(); var direction = button.getAttribute('data-move'); var item = button.closest('.compose-asset'); if (!item || !list.contains(item)) { return; } if (direction === 'up') { var prev = item.previousElementSibling; if (prev) { prev.before(item); } } else if (direction === 'down') { var next = item.nextElementSibling; if (next) { next.after(item); } } updateOrderLabels(list); }); updateOrderLabels(list); }); })();