(function () {
    var base = (typeof window.DOC_BASE !== 'undefined') ? window.DOC_BASE : './';

    function makeLink(path, text) {
        return '<li class="nav-item"><a href="' + base + path + '" class="nav-link"><span>' + text + '</span></a></li>';
    }

    function makeGroup(title) {
        return '<li class="nav-item"><div class="nav-group-title">' + title + '</div></li>';
    }

    var html = '';
    html += makeLink('index.html', 'Documentation');
    html += makeLink('pages/introduction.html', 'Introduction');
    html += makeLink('pages/key-features.html', 'Key Features');

    html += makeGroup('Installation');
    html += makeLink('pages/installation/server-requirements.html', 'Server Requirements');
    html += makeLink('pages/installation/installation-steps.html', 'Installation Steps');
    // html += makeLink('pages/installation/docker-deployment.html', 'Docker &amp; VPS Deployment');
    // removed: Environment Setup
    html += makeLink('pages/installation/queue-and-cron.html', 'Queue &amp; Cron Setup');

    html += makeGroup('Features');
    html += makeLink('pages/features/inbox.html', 'Unified Inbox');
    html += makeLink('pages/features/contacts-crm.html', 'Contacts &amp; CRM');
    html += makeLink('pages/features/contact-groups.html', 'Contact Groups');
    html += makeLink('pages/features/deals-pipeline.html', 'Deals &amp; Pipeline');
    html += makeLink('pages/features/campaigns.html', 'Email Campaigns');
    html += makeLink('pages/features/workflows.html', 'Workflow Automation');
    html += makeLink('pages/features/email-templates.html', 'Email Templates');
    html += makeLink('pages/features/canned-responses.html', 'Canned Responses');
    html += makeLink('pages/features/analytics.html', 'Analytics &amp; Reports');
    html += makeLink('pages/features/team-management.html', 'Team &amp; Workspaces');
    html += makeLink('pages/features/billing.html', 'Billing &amp; Plans');
    html += makeLink('pages/features/temp-mail.html', 'Temp Mail');

    html += makeGroup('AI Features');
    html += makeLink('pages/ai/ai-replies.html', 'AI-Powered Replies');
    html += makeLink('pages/ai/knowledge-base.html', 'Knowledge Base');
    html += makeLink('pages/ai/ai-configuration.html', 'AI Settings');
    html += makeLink('pages/ai/ai-providers.html', 'AI Providers Setup');

    html += makeGroup('Channels');
    html += makeLink('pages/channels/whatsapp.html', 'WhatsApp');
    html += makeLink('pages/channels/sms-twilio.html', 'SMS (Twilio)');
    html += makeLink('pages/channels/telegram.html', 'Telegram');
    html += makeLink('pages/channels/slack.html', 'Slack');
    html += makeLink('pages/channels/live-chat.html', 'Live Chat Widget');

    html += makeGroup('Integrations');
    html += makeLink('pages/features/integrations.html', 'Overview');
    html += makeLink('pages/channels/slack.html', 'Slack');
    html += makeLink('pages/features/salesforce.html', 'Salesforce');
    html += makeLink('pages/features/hubspot.html', 'HubSpot');
    html += makeLink('pages/features/google-calendar.html', 'Google Calendar');
    html += makeLink('pages/features/zapier.html', 'Zapier');

    html += makeGroup('Admin Panel');
    html += makeLink('pages/admin-panel/dashboard.html', 'Admin Dashboard');
    html += makeLink('pages/admin-panel/user-management.html', 'User Management');
    html += makeLink('pages/admin-panel/plans-subscriptions.html', 'Plans &amp; Subscriptions');
    html += makeLink('pages/admin-panel/payment-gateways.html', 'Payment Gateways');
    html += makeLink('pages/admin-panel/system-settings.html', 'System Settings');
    html += makeLink('pages/admin-panel/temp-mail-management.html', 'Temp Mail Management');

    html += makeGroup('Security &amp; Privacy');
    html += makeLink('pages/security/overview.html', 'Security Overview');
    html += makeLink('pages/security/two-factor.html', 'Two-Factor Authentication');
    html += makeLink('pages/security/gdpr.html', 'Data Privacy &amp; GDPR');

    // html += makeGroup('API Reference');
    // html += makeLink('pages/api/overview.html', 'API Overview');
    // html += makeLink('pages/api/authentication.html', 'Authentication');
    // html += makeLink('pages/api/endpoints.html', 'API Endpoints');

    html += makeGroup('For Developers');
    html += makeLink('pages/developer-guide/architecture.html', 'Architecture');
    html += makeLink('pages/developer-guide/queue-system.html', 'Queue &amp; Jobs');
    html += makeLink('pages/developer-guide/customization.html', 'Customization');

    html += makeGroup('FAQs');
    html += makeLink('pages/faqs/general.html', 'General FAQs');
    html += makeLink('pages/faqs/installation-faqs.html', 'Installation FAQs');
    html += makeLink('pages/faqs/demo-limitations.html', 'Demo Limitations');
    html += makeLink('pages/faqs/disclaimer.html', 'Disclaimer');
    html += makeLink('pages/faqs/privacy-policy.html', 'Privacy Policy');

    html += makeGroup('Update Log');
    html += makeLink('pages/update-details/changelog.html', 'Change Log');
    html += makeLink('pages/update-details/update-process.html', 'Update Process');

    html += makeLink('pages/conclusion/support.html', 'Support');
    html += makeLink('pages/conclusion/source-credits.html', 'Source &amp; Credits');
    html += makeLink('pages/conclusion/conclusion.html', 'Conclusion');

    var navEl = document.querySelector('.sidebar-nav');
    if (navEl) {
        navEl.innerHTML = '<ul class="nav-list">' + html + '</ul>';
    }

    // Highlight active link
    var currentHref = window.location.href.split('?')[0].split('#')[0];
    var links = document.querySelectorAll('.sidebar-nav .nav-link');
    links.forEach(function (link) {
        var linkHref = link.href.split('?')[0].split('#')[0];
        if (linkHref === currentHref) {
            link.classList.add('active');
        }
    });
})();
