import './bootstrap';

const pageRoot = document.querySelector('[data-page]');

if (pageRoot) {
	const pageKey = pageRoot.getAttribute('data-page');

	const loaders = {
	'vineyard-map-index': () => import('./vineyard/map-index').then((module) => module.default?.()),
	'vineyard-map-edit': () => import('./vineyard/map-edit').then((module) => module.default?.()),
	'vineyard-add-plants': () => import('./vineyard/add-plants').then((module) => module.default?.()),
		'plan-watering': () => import('./planned-tasks/form').then((module) => module.init('watering')),
		'plan-pruning': () => import('./planned-tasks/form').then((module) => module.init('pruning')),
		'plan-fertilisation': () => import('./planned-tasks/form').then((module) => module.init('fertilization')),
		'plan-pesticide': () => import('./planned-tasks/form').then((module) => module.init('spraying')),
		'plan-harvest': () => import('./planned-tasks/form').then((module) => module.init('harvest')),
		'vineyard-overview': () => import('./vineyard/overview'),
	};

	const loader = loaders[pageKey];

	if (typeof loader === 'function') {
		Promise.resolve(loader()).catch((error) => console.error('Failed to initialize page module:', error));
	}
}
