import { getCurrentInstance } from 'vue';

const filterAvailableInput = element => element.classList.contains('q-field__native') && !element.disabled
const filterAvailableText = element => element.__vueParentComponent.type.name === 'QInput' && element.__vueParentComponent?.attrs?.class !== 'vn-input-date';


export default {
    mounted: function () {
        const vm = getCurrentInstance();
        if (vm.type.name === 'QForm')
            if (!['searchbarForm','filterPanelForm'].includes(this.$el?.id)) {
                // AUTOFOCUS
                const elementsArray = Array.from(this.$el.elements);
                const firstInputElement = elementsArray.filter(filterAvailableInput).find(filterAvailableText);

                if (firstInputElement) {
                    firstInputElement.focus();
                }
            }
    },
};
