/**
 * Auto-submit functionality for forms
 *
 * This script looks for forms with the 'auto-submit' attribute
 * and automatically submits them when any input, select, or textarea
 * within the form changes, useful for search/filter forms.
 */
document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('form[auto-submit]').forEach(form => {
        const formElements = form.querySelectorAll('input, select, textarea')

        formElements.forEach(element => {
            if (element.type === 'checkbox' || element.type === 'radio') {
                element.addEventListener('change', () => {
                    form.submit()
                })
            }
            else if (element.tagName.toLowerCase() === 'select') {
                element.addEventListener('change', () => {
                    form.submit()
                })
            }
        })
    })
})
