import { beginTable } from '/plugin/begin/begin-util.js'
// import begin1 from '/plugin/begin/begin1.js'
// import begin2 from '/plugin/begin/begin2.js'
// import begin3 from '/plugin/begin/begin3.js'
// import begin4 from '/plugin/begin/begin4.js'

console.debug('begin lazy-loaded')

let mainState
onActivated(() => {
	// using keep-alive
	mainState.rec.in_form = 'begin'
})

onDeactivated(() => {
	mainState.rec.in_form = ''
})

onMounted(() => {
	mainState = nc.mainState()
	mainState.rec.in_form = 'begin'
})

onBeforeUnmount(() => {
	mainState.rec.in_form = ''
})

/*
onMounted(function () {
		window.addEventListener('keydown', event => {
		hoverBoxStyle.value = displayNoneStyle
		if (event.target === document.body) {
			keyEvent(event, rec.selected_node)
		} else {
			const area = event.target.closest('#nc-layout-area') // check if event is inside drawing area
			if (area) {
				const ret = keyEvent(event, rec.selected_node)
				if (ret === 'ok') {
					event.target.blur() // move focus away from input
				}
			}
		}
	})
})
*/

watch(beginTable, () => {
	if (beginTable.value.substring(0, 2) === 'd:') {
		// double click event
		rec.table = beginTable.value.substring(2)
		mainState.rec.table = rec.table
		nc.gotoUrl(mainState, '/list')
		return
	}
	rec.table = beginTable.value
	mainState.rec.table = rec.table
})
