import store from '@/Store'
import { wireDirectives } from '../util'
let cleanupStackByComponentId = {}
export default function () {
store.registerHook('element.initialized', (el, component) => {
let directives = wireDirectives(el)
if (directives.missing('submit')) return
el.addEventListener('submit', () => {
cleanupStackByComponentId[component.id] = []
component.walk(node => {
if (! el.contains(node)) return
if (node.hasAttribute('wire:ignore')) return false
if (
(node.tagName.toLowerCase() === 'button' &&
node.type === 'submit') ||
node.tagName.toLowerCase() === 'select' ||
(node.tagName.toLowerCase() === 'input' &&
(node.type === 'checkbox' || node.type === 'radio'))
) {
if (!node.disabled)
cleanupStackByComponentId[component.id].push(
() => (node.disabled = false)
)
node.disabled = true
} else if (
node.tagName.toLowerCase() === 'input' ||
node.tagName.toLowerCase() === 'textarea'
) {
if (!node.readOnly)