import './bootstrap';
import Alpine from 'alpinejs';
import AOS from 'aos';
import { createIcons, icons } from 'lucide';
import 'aos/dist/aos.css';

window.Alpine = window.Alpine || Alpine;

if (!window.__hillcrestAlpineStarted) {
    window.Alpine.start();
    window.__hillcrestAlpineStarted = true;
}

const initializeSiteEffects = () => {
    createIcons({ icons });

    AOS.init({
        duration: 850,
        once: false,
        offset: 70,
        easing: 'ease-out-cubic',
        disable: false,
    });
    AOS.refreshHard();

    const setScrollProgress = () => {
        const scrollable = document.documentElement.scrollHeight - window.innerHeight;
        const progress = scrollable > 0 ? (window.scrollY / scrollable) * 100 : 0;

        document.documentElement.style.setProperty('--scroll-progress', `${progress}%`);
    };

    setScrollProgress();
    window.addEventListener('scroll', setScrollProgress, { passive: true });
};

if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', initializeSiteEffects, { once: true });
} else {
    initializeSiteEffects();
}
