// Page Navigation System

// Mobile menu toggle
function toggleMobileMenu() {
    const navLinks = document.getElementById('navLinks');
    navLinks?.classList.toggle('active');
}

// Page content data
const pageContent = {
    home: `
        <div id="home" class="page active">
            <section class="hero">
                <div class="container">
                    <h1>Launch Your Business Dreams Into Reality</h1>
                    <p>Transform your entrepreneurial vision into a thriving business with our comprehensive guidance, proven strategies, and step-by-step roadmaps designed for modern entrepreneurs.</p>
                    <a href="#signup" class="cta-button" onclick="showPage('signup')">Start Your Journey Today</a>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <h2 class="section-title">Why Choose BizzEasiest?</h2>
                    <div class="features-grid">
                        <div class="feature-card">
                            <div class="feature-icon">💡</div>
                            <h3>Expert Business Guidance</h3>
                            <p>Access proven strategies and insights from successful entrepreneurs who've built thriving businesses from the ground up.</p>
                        </div>
                        <div class="feature-card">
                            <div class="feature-icon">📈</div>
                            <h3>Step-by-Step Roadmaps</h3>
                            <p>Follow our detailed action plans that break down complex business processes into manageable, achievable steps.</p>
                        </div>
                        <div class="feature-card">
                            <div class="feature-icon">🎯</div>
                            <h3>Personalized Support</h3>
                            <p>Receive tailored advice and resources based on your specific business goals, industry, and experience level.</p>
                        </div>
                        <div class="feature-card">
                            <div class="feature-icon">🚀</div>
                            <h3>Fast-Track Launch</h3>
                            <p>Accelerate your business launch with our streamlined processes and time-tested methods for rapid market entry.</p>
                        </div>
                        <div class="feature-card">
                            <div class="feature-icon">💰</div>
                            <h3>Cost-Effective Solutions</h3>
                            <p>Save thousands on business setup costs with our budget-friendly alternatives and insider tips for bootstrapping success.</p>
                        </div>
                        <div class="feature-card">
                            <div class="feature-icon">🌐</div>
                            <h3>Online & Offline Ready</h3>
                            <p>Whether you're starting an e-commerce store or brick-and-mortar business, we've got you covered with specialized guidance.</p>
                        </div>
                    </div>
                </div>
            </section>

            <section class="stats">
                <div class="container">
                    <div class="stats-grid">
                        <div class="stat-item">
                            <h3>15,000+</h3>
                            <p>Businesses Launched</p>
                        </div>
                        <div class="stat-item">
                            <h3>92%</h3>
                            <p>Success Rate</p>
                        </div>
                        <div class="stat-item">
                            <h3>50+</h3>
                            <p>Industries Covered</p>
                        </div>
                        <div class="stat-item">
                            <h3>24/7</h3>
                            <p>Support Available</p>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `,

    about: `
        <div id="about" class="page">
            <section class="hero" style="padding: 120px 0 80px;">
                <div class="container">
                    <h1>About BizzEasiest</h1>
                    <p>Empowering entrepreneurs to build successful businesses through proven strategies and expert guidance.</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div style="max-width: 800px; margin: 0 auto;">
                        <h2 class="section-title">Our Mission</h2>
                        <p style="font-size: 1.2rem; text-align: center; margin-bottom: 3rem;">
                            We believe that every entrepreneur deserves access to the tools, knowledge, and support needed to transform their business ideas into thriving enterprises. Our mission is to democratize business success by providing comprehensive, actionable guidance that removes barriers and accelerates growth.
                        </p>

                        <div class="features-grid" style="margin-top: 3rem;">
                            <div class="feature-card">
                                <h3>Founded in 2020</h3>
                                <p>Born from the vision of making business creation accessible to everyone, regardless of background or experience level.</p>
                            </div>
                            <div class="feature-card">
                                <h3>Expert Team</h3>
                                <p>Our advisors include successful entrepreneurs, business consultants, and industry veterans with decades of combined experience.</p>
                            </div>
                            <div class="feature-card">
                                <h3>Proven Methods</h3>
                                <p>Every strategy and recommendation is backed by real-world success stories and data-driven insights from thousands of businesses.</p>
                            </div>
                        </div>

                        <div style="text-align: center; margin-top: 3rem;">
                            <h3>Our Values</h3>
                            <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2rem; margin-top: 2rem;">
                                <div>
                                    <h4 style="color: #2563eb; margin-bottom: 1rem;">Transparency</h4>
                                    <p>Clear, honest guidance without hidden agendas or unrealistic promises.</p>
                                </div>
                                <div>
                                    <h4 style="color: #2563eb; margin-bottom: 1rem;">Innovation</h4>
                                    <p>Constantly evolving our methods to match modern business landscapes.</p>
                                </div>
                                <div>
                                    <h4 style="color: #2563eb; margin-bottom: 1rem;">Support</h4>
                                    <p>Committed to your success every step of your entrepreneurial journey.</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `,

    blog: `
        <div id="blog" class="page">
            <section class="hero" style="padding: 120px 0 80px;">
                <div class="container">
                    <h1>Business Insights & Resources</h1>
                    <p>Stay ahead with the latest strategies, tips, and trends in entrepreneurship and business development.</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div class="features-grid">
                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #667eea, #764ba2); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>10 Essential Steps to Launch Your Online Business in 2024</h3>
                            <p style="color: #666; margin-bottom: 1rem;">From market research to digital marketing strategies, discover the complete roadmap for online business success.</p>
                            <small style="color: #999;">December 15, 2024 | 8 min read</small>
                        </article>

                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #f093fb, #f5576c); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>Small Business Funding: 7 Creative Alternatives to Bank Loans</h3>
                            <p style="color: #666; margin-bottom: 1rem;">Explore innovative funding options that don't require perfect credit or extensive collateral.</p>
                            <small style="color: #999;">December 12, 2024 | 6 min read</small>
                        </article>

                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #4facfe, #00f2fe); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>The Psychology of Successful Entrepreneurs: 5 Mindset Shifts</h3>
                            <p style="color: #666; margin-bottom: 1rem;">Learn how top entrepreneurs think differently and how you can adopt their success-oriented mindset.</p>
                            <small style="color: #999;">December 10, 2024 | 7 min read</small>
                        </article>

                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #fa709a, #fee140); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>Digital Marketing on a Shoestring Budget: Maximum Impact Strategies</h3>
                            <p style="color: #666; margin-bottom: 1rem;">Proven tactics to build your brand and attract customers without breaking the bank.</p>
                            <small style="color: #999;">December 8, 2024 | 9 min read</small>
                        </article>

                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #a8edea, #fed6e3); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>Building a Remote Team: Best Practices for Small Business Owners</h3>
                            <p style="color: #666; margin-bottom: 1rem;">How to hire, manage, and scale a distributed workforce while maintaining productivity.</p>
                            <small style="color: #999;">December 5, 2024 | 10 min read</small>
                        </article>

                        <article class="feature-card" style="text-align: left;">
                            <div style="height: 200px; background: linear-gradient(45deg, #ff9a9e, #fecfef); border-radius: 10px; margin-bottom: 1rem;"></div>
                            <h3>Legal Essentials: Protecting Your Business from Day One</h3>
                            <p style="color: #666; margin-bottom: 1rem;">Critical legal considerations every new business owner must address to avoid costly mistakes.</p>
                            <small style="color: #999;">December 3, 2024 | 12 min read</small>
                        </article>
                    </div>

                    <div style="text-align: center; margin-top: 3rem;">
                        <a href="#signup" class="cta-button" onclick="showPage('signup')">Get More Business Insights</a>
                    </div>
                </div>
            </section>
        </div>
    `,

    signup: `
        <div id="signup" class="page">
            <section class="hero" style="padding: 120px 0 40px;">
                <div class="container">
                    <h1>Start Your Business Journey</h1>
                    <p>Get personalized guidance tailored to your entrepreneurial goals and experience level.</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div style="max-width: 600px; margin: 0 auto;">
                        <div class="multi-step-form">
                            <div class="progress-bar">
                                <div class="progress-step active" data-step="1">1</div>
                                <div class="progress-step" data-step="2">2</div>
                                <div class="progress-step" data-step="3">3</div>
                                <div class="progress-step" data-step="4">4</div>
                            </div>

                            <form id="signupForm" style="background: white; padding: 3rem; border-radius: 15px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);">
                                <!-- Step 1: First Name -->
                                <div class="form-step active" data-step="1">
                                    <h2 style="text-align: center; margin-bottom: 2rem;">What's your first name?</h2>
                                    <input type="text" id="firstName" name="firstName" placeholder="Enter your first name" required
                                           style="width: 100%; padding: 15px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 1.1rem; margin-bottom: 2rem;">
                                    <button type="button" onclick="nextStep()" class="form-btn">Continue</button>
                                </div>

                                <!-- Step 2: Last Name -->
                                <div class="form-step" data-step="2">
                                    <h2 style="text-align: center; margin-bottom: 2rem;">And your last name?</h2>
                                    <input type="text" id="lastName" name="lastName" placeholder="Enter your last name" required
                                           style="width: 100%; padding: 15px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 1.1rem; margin-bottom: 2rem;">
                                    <button type="button" onclick="prevStep()" class="form-btn secondary" style="margin-right: 1rem;">Back</button>
                                    <button type="button" onclick="nextStep()" class="form-btn">Continue</button>
                                </div>

                                <!-- Step 3: Email -->
                                <div class="form-step" data-step="3">
                                    <h2 style="text-align: center; margin-bottom: 2rem;">What's your email address?</h2>
                                    <input type="email" id="email" name="email" placeholder="Enter your email address" required
                                           style="width: 100%; padding: 15px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 1.1rem; margin-bottom: 2rem;">
                                    <button type="button" onclick="prevStep()" class="form-btn secondary" style="margin-right: 1rem;">Back</button>
                                    <button type="button" onclick="nextStep()" class="form-btn">Continue</button>
                                </div>

                                <!-- Step 4: Phone Number -->
                                <div class="form-step" data-step="4">
                                    <h2 style="text-align: center; margin-bottom: 2rem;">Phone number (optional)</h2>
                                    <input type="tel" id="phone" name="phone" placeholder="Enter your phone number"
                                           style="width: 100%; padding: 15px; border: 2px solid #e5e7eb; border-radius: 10px; font-size: 1.1rem; margin-bottom: 2rem;">
                                    <button type="button" onclick="prevStep()" class="form-btn secondary" style="margin-right: 1rem;">Back</button>
                                    <button type="submit" class="form-btn">Complete Registration</button>
                                </div>

                                <!-- Success Message -->
                                <div class="form-step" data-step="success" style="display: none;">
                                    <div style="text-align: center;">
                                        <div style="font-size: 4rem; margin-bottom: 1rem;">🎉</div>
                                        <h2 style="color: #10b981; margin-bottom: 2rem;">Welcome to BizzEasiest!</h2>
                                        <p style="font-size: 1.2rem; margin-bottom: 2rem;">
                                            Thank you for joining our community of entrepreneurs. Check your email for next steps and exclusive resources.
                                        </p>
                                        <button type="button" onclick="showPage('home')" class="form-btn">Return Home</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `,

    privacy: `
        <div id="privacy" class="page">
            <section class="hero" style="padding: 120px 0 40px;">
                <div class="container">
                    <h1>Privacy Policy</h1>
                    <p>Last updated: December 2024</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div style="max-width: 800px; margin: 0 auto; text-align: left;">
                        <div style="background: white; padding: 3rem; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);">
                            <h2>Information We Collect</h2>
                            <p>We collect information you provide directly to us, such as when you create an account, subscribe to our newsletter, or contact us for support. This may include your name, email address, phone number, and business information.</p>

                            <h2>How We Use Your Information</h2>
                            <p>We use the information we collect to:</p>
                            <ul>
                                <li>Provide, maintain, and improve our services</li>
                                <li>Send you updates, marketing communications, and other information</li>
                                <li>Respond to your comments, questions, and requests</li>
                                <li>Monitor and analyze trends, usage, and activities</li>
                            </ul>

                            <h2>Information Sharing and Disclosure</h2>
                            <p>We do not sell, trade, or otherwise transfer your personal information to third parties without your consent, except as described in this policy. We may share your information in the following circumstances:</p>
                            <ul>
                                <li>With service providers who assist us in operating our website</li>
                                <li>To comply with legal obligations</li>
                                <li>To protect our rights and prevent fraud</li>
                            </ul>

                            <h2>Data Security</h2>
                            <p>We implement appropriate technical and organizational measures to protect your personal information against unauthorized access, alteration, disclosure, or destruction.</p>

                            <h2>Your Rights</h2>
                            <p>You have the right to access, update, or delete your personal information. You may also opt out of certain communications from us.</p>

                            <h2>Contact Us</h2>
                            <p>If you have any questions about this Privacy Policy, please contact us at privacy@bizzeasiest.com</p>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `,

    terms: `
        <div id="terms" class="page">
            <section class="hero" style="padding: 120px 0 40px;">
                <div class="container">
                    <h1>Terms & Conditions</h1>
                    <p>Last updated: December 2024</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div style="max-width: 800px; margin: 0 auto; text-align: left;">
                        <div style="background: white; padding: 3rem; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);">
                            <h2>Acceptance of Terms</h2>
                            <p>By accessing and using BizzEasiest, you accept and agree to be bound by the terms and provision of this agreement.</p>

                            <h2>Use License</h2>
                            <p>Permission is granted to temporarily access the materials on BizzEasiest for personal, non-commercial transitory viewing only. This is the grant of a license, not a transfer of title, and under this license you may not:</p>
                            <ul>
                                <li>Modify or copy the materials</li>
                                <li>Use the materials for any commercial purpose or for any public display</li>
                                <li>Attempt to reverse engineer any software contained on the website</li>
                                <li>Remove any copyright or other proprietary notations from the materials</li>
                            </ul>

                            <h2>Disclaimer</h2>
                            <p>The materials on BizzEasiest are provided on an 'as is' basis. BizzEasiest makes no warranties, expressed or implied, and hereby disclaims and negates all other warranties including without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights.</p>

                            <h2>Limitations</h2>
                            <p>In no event shall BizzEasiest or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption) arising out of the use or inability to use the materials on BizzEasiest's website.</p>

                            <h2>Accuracy of Materials</h2>
                            <p>The materials appearing on BizzEasiest could include technical, typographical, or photographic errors. BizzEasiest does not warrant that any of the materials on its website are accurate, complete, or current.</p>

                            <h2>Modifications</h2>
                            <p>BizzEasiest may revise these terms of service for its website at any time without notice. By using this website, you are agreeing to be bound by the then current version of these terms of service.</p>

                            <h2>Contact Information</h2>
                            <p>If you have any questions about these Terms & Conditions, please contact us at legal@bizzeasiest.com</p>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `,

    'mobile-privacy': `
        <div id="mobile-privacy" class="page">
            <section class="hero" style="padding: 120px 0 40px;">
                <div class="container">
                    <h1>Mobile Privacy Policy</h1>
                    <p>Last updated: December 2024</p>
                </div>
            </section>

            <section class="features">
                <div class="container">
                    <div style="max-width: 800px; margin: 0 auto; text-align: left;">
                        <div style="background: white; padding: 3rem; border-radius: 15px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);">
                            <h2>Mobile Application Privacy</h2>
                            <p>This Mobile Privacy Policy applies specifically to any mobile application versions of BizzEasiest services and supplements our main Privacy Policy.</p>

                            <h2>Information Collection on Mobile</h2>
                            <p>When you use our mobile application, we may collect additional information including:</p>
                            <ul>
                                <li>Device information (model, operating system, unique device identifiers)</li>
                                <li>Location data (with your permission)</li>
                                <li>Push notification preferences</li>
                                <li>App usage statistics and crash reports</li>
                            </ul>

                            <h2>Location Services</h2>
                            <p>Our mobile app may request access to your device's location services to provide location-based features. You can control location sharing through your device settings at any time.</p>

                            <h2>Push Notifications</h2>
                            <p>We may send you push notifications with updates about your business journey, new resources, and important announcements. You can opt out of these notifications through your device settings.</p>

                            <h2>Mobile Analytics</h2>
                            <p>We use mobile analytics services to understand how users interact with our app, which helps us improve functionality and user experience.</p>

                            <h2>Third-Party SDKs</h2>
                            <p>Our mobile app may include third-party software development kits (SDKs) for analytics, crash reporting, and other services. These SDKs may collect information as described in their respective privacy policies.</p>

                            <h2>Data Storage</h2>
                            <p>Some data may be stored locally on your device for offline functionality and performance optimization. This data is secured and protected according to industry standards.</p>

                            <h2>Updates to Mobile Privacy Policy</h2>
                            <p>We may update this Mobile Privacy Policy from time to time. We will notify you of any material changes through the app or other communication methods.</p>

                            <h2>Contact Us</h2>
                            <p>For questions about mobile privacy, contact us at mobile-privacy@bizzeasiest.com</p>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    `
};

// Multi-step form functionality
let currentStep = 1;
const totalSteps = 4;

function nextStep() {
    const currentStepElement = document.querySelector(`.form-step[data-step="${currentStep}"]`);
    const input = currentStepElement?.querySelector('input[required]') as HTMLInputElement;

    if (input && !input.value.trim()) {
        input.style.borderColor = '#ef4444';
        input.focus();
        return;
    }

    if (input) {
        input.style.borderColor = '#e5e7eb';
    }

    if (currentStep < totalSteps) {
        currentStep++;
        updateFormDisplay();
    }
}

function prevStep() {
    if (currentStep > 1) {
        currentStep--;
        updateFormDisplay();
    }
}

function updateFormDisplay() {
    // Hide all steps
    document.querySelectorAll('.form-step').forEach(step => {
        step.classList.remove('active');
    });

    // Show current step
    const currentStepElement = document.querySelector(`.form-step[data-step="${currentStep}"]`);
    if (currentStepElement) {
        currentStepElement.classList.add('active');
    }

    // Update progress bar
    document.querySelectorAll('.progress-step').forEach((step, index) => {
        if (index < currentStep) {
            step.classList.add('active');
        } else {
            step.classList.remove('active');
        }
    });
}

// Form submission
function handleFormSubmit(event: Event) {
    event.preventDefault();

    const formData = new FormData(event.target as HTMLFormElement);
    const data = {
        firstName: formData.get('firstName'),
        lastName: formData.get('lastName'),
        email: formData.get('email'),
        phone: formData.get('phone')
    };

    // Simulate form submission
    console.log('Form submitted:', data);

    // Show success message
    document.querySelectorAll('.form-step').forEach(step => {
        (step as HTMLElement).style.display = 'none';
    });

    const successStep = document.querySelector('.form-step[data-step="success"]') as HTMLElement;
    if (successStep) {
        successStep.style.display = 'block';
    }
}

// Page navigation function
function showPage(pageName: string) {
    const pageContentElement = document.getElementById('pageContent');
    if (pageContentElement && pageContent[pageName as keyof typeof pageContent]) {
        pageContentElement.innerHTML = pageContent[pageName as keyof typeof pageContent];

        // Update URL without page refresh
        window.history.pushState({page: pageName}, '', `#${pageName}`);

        // Close mobile menu if open
        const navLinks = document.getElementById('navLinks');
        navLinks?.classList.remove('active');

        // Scroll to top
        window.scrollTo(0, 0);

        // Re-initialize form if on signup page
        if (pageName === 'signup') {
            currentStep = 1;
            setTimeout(() => {
                const form = document.getElementById('signupForm');
                if (form) {
                    form.addEventListener('submit', handleFormSubmit);
                    updateFormDisplay();
                }
            }, 100);
        }
    }
}

// Initialize page on load
document.addEventListener('DOMContentLoaded', () => {
    // Handle initial page load
    const hash = window.location.hash.slice(1);
    if (hash && pageContent[hash as keyof typeof pageContent]) {
        showPage(hash);
    }

    // Handle browser back/forward
    window.addEventListener('popstate', (event) => {
        const page = event.state?.page || 'home';
        showPage(page);
    });

    // Add form styles
    const style = document.createElement('style');
    style.textContent = `
        .multi-step-form {
            position: relative;
        }

        .progress-bar {
            display: flex;
            justify-content: center;
            margin-bottom: 3rem;
            gap: 1rem;
        }

        .progress-step {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #e5e7eb;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            color: #6b7280;
            transition: all 0.3s ease;
        }

        .progress-step.active {
            background: #2563eb;
            color: white;
        }

        .form-step {
            display: none;
        }

        .form-step.active {
            display: block;
            animation: fadeInUp 0.5s ease;
        }

        .form-btn {
            background: #2563eb;
            color: white;
            border: none;
            padding: 15px 30px;
            border-radius: 10px;
            font-size: 1.1rem;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .form-btn:hover {
            background: #1d4ed8;
            transform: translateY(-2px);
        }

        .form-btn.secondary {
            background: #6b7280;
        }

        .form-btn.secondary:hover {
            background: #4b5563;
        }

        .page {
            display: none;
        }

        .page.active {
            display: block;
        }

        h2, h3, h4 {
            margin: 2rem 0 1rem 0;
        }

        ul {
            margin: 1rem 0;
            padding-left: 2rem;
        }

        li {
            margin-bottom: 0.5rem;
        }
    `;
    document.head.appendChild(style);
});

// Make functions globally available
(window as any).showPage = showPage;
(window as any).toggleMobileMenu = toggleMobileMenu;
(window as any).nextStep = nextStep;
(window as any).prevStep = prevStep;
