
/**
 * SCALE IN 90 DAYS - Vanilla JS Engine
 */

// 1. MARQUEE CLONER (Social Proof Authority)
const initMarquee = () => {
    const marquee = document.getElementById('marquee');
    if (!marquee) return;

    const items = [
        "AGENCY GROWTH", "AI SYSTEMS", "FUNNEL MASTER", "E-COM ACCELERATOR", 
        "REAL ESTATE ELITE", "FITNESS SCALE", "LOCAL BUSINESS PRO", "MARKETING SECRETS"
    ];

    // Create spans
    const createContent = () => {
        return items.map(text => `
            <span class="text-gray-300 font-black text-2xl md:text-3xl tracking-tighter grayscale opacity-40 hover:opacity-100 hover:text-[#005e86] transition cursor-default">
                ${text}
            </span>
        `).join('');
    };

    // Double the content to ensure seamless loop
    marquee.innerHTML = createContent() + createContent() + createContent();
};

// 2. INTERACTIVE AI CALCULATOR
// Casting window to any to bypass TypeScript's check for startCalculator property on global object
(window as any).startCalculator = () => {
    const step1 = document.getElementById('calc-step-1');
    const loading = document.getElementById('calc-step-loading');
    const result = document.getElementById('calc-step-result');
    const progressBar = document.getElementById('progress-bar');
    const progressText = document.getElementById('progress-text');

    if (!step1 || !loading || !result || !progressBar || !progressText) return;

    step1.classList.add('hidden');
    loading.classList.remove('hidden');

    let progress = 0;
    const interval = setInterval(() => {
        progress += Math.floor(Math.random() * 5) + 2;
        if (progress > 100) progress = 100;
        
        progressBar.style.width = `${progress}%`;
        progressText.innerText = `${progress}%`;

        if (progress >= 100) {
            clearInterval(interval);
            setTimeout(() => {
                loading.classList.add('hidden');
                result.classList.remove('hidden');
            }, 500);
        }
    }, 150);
};

// 3. SMOOTH SCROLL ENHANCEMENT
const initSmoothScroll = () => {
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href')!);
            if (target) {
                window.scrollTo({
                    top: target.offsetTop - 80, // offset for sticky header
                    behavior: 'smooth'
                });
            }
        });
    });
};

// 4. BOOTSTRAP
document.addEventListener('DOMContentLoaded', () => {
    initMarquee();
    initSmoothScroll();
    
    // Add subtle reveal animations on scroll
    const observerOptions = { threshold: 0.1 };
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate-fadeIn');
                observer.unobserve(entry.target);
            }
        });
    }, observerOptions);

    document.querySelectorAll('.roadmap-card, .stack-item').forEach(el => observer.observe(el));
});
