// Deprecated: navbar-fallback is no longer used. The standardized navbar is injected by navbar.js
document.addEventListener('DOMContentLoaded', function () {
    // Intentionally left blank to avoid conflicting with the standardized navbar
});

// Simple navbar with notification bell as a safety net when navbar.js fails to render
document.addEventListener('DOMContentLoaded', function () {
    const navbarContainer = document.getElementById('navbar-container');
    if (!navbarContainer || navbarContainer.innerHTML.trim() !== '') return;

    // If the real factory is available, render the full navbar (brings bells/approvals along)
    if (typeof createNavbar === 'function') {
        navbarContainer.innerHTML = createNavbar();
        if (typeof initNotificationSystem === 'function') {
            initNotificationSystem();
        }
        console.log('✅ Fallback used standard navbar renderer');
        return;
    }

    // Minimal fallback with notification bell so the icon never disappears
    navbarContainer.innerHTML = `
        <nav class="navbar navbar-expand-lg navbar-dark bg-primary fixed-top">
            <div class="container-fluid">
                <a class="navbar-brand fw-bold" href="/static/index.html">
                    <i class="bi bi-building me-2"></i>CNPERP ERP
                </a>

                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarContent">
                    <ul class="navbar-nav me-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="/static/index.html">
                                <i class="bi bi-speedometer2 me-1"></i>Dashboard
                            </a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="bi bi-cart me-1"></i>Sales
                            </a>
                            <ul class="dropdown-menu">
                                <li><a class="dropdown-item" href="/static/pos.html">POS</a></li>
                                <li><a class="dropdown-item" href="/static/sales.html">Sales</a></li>
                                <li><a class="dropdown-item" href="/static/customers.html">Customers</a></li>
                                <li><a class="dropdown-item" href="/static/invoices.html">Invoices</a></li>
                                <li><a class="dropdown-item" href="/static/credit-notes.html">Credit Notes</a></li>
                                <li><a class="dropdown-item" href="/static/receipts.html">Receipts</a></li>
                                <li><a class="dropdown-item" href="/static/quotations.html">Quotations</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><h6 class="dropdown-header">Jobs &amp; invoicing</h6></li>
                                <li><a class="dropdown-item" href="/static/job-sales-queue.html?tab=pending">Pending Jobs</a></li>
                                <li><a class="dropdown-item" href="/static/job-sales-queue.html?tab=ready">Jobs Ready to Invoice</a></li>
                                <li><a class="dropdown-item" href="/static/job-cards.html">All Job Cards</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="/static/sales-reports.html">Sales Reports</a></li>
                            </ul>
                        </li>
                    </ul>

                    <ul class="navbar-nav ms-auto">
                        <li class="nav-item dropdown me-2" id="notification-dropdown">
                            <a class="nav-link position-relative" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false" id="notificationBell" title="Notifications">
                                <i class="bi bi-bell fs-5"></i>
                                <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger" id="notification-badge" style="display: none; font-size: 0.65rem;">0</span>
                            </a>
                            <div class="dropdown-menu dropdown-menu-end shadow" style="min-width: 280px;" id="notification-menu">
                                <div class="px-3 py-2 border-bottom">
                                    <h6 class="mb-0"><i class="bi bi-bell me-1"></i>Notifications</h6>
                                </div>
                                <div class="text-center py-3 text-muted" id="notification-list">
                                    <i class="bi bi-inbox fs-4 d-block mb-2"></i>
                                    <small>Notifications unavailable (fallback)</small>
                                </div>
                                <div class="border-top px-3 py-2 text-center">
                                    <a href="/static/notifications.html" class="text-decoration-none small">Open notifications</a>
                                </div>
                            </div>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                                <i class="bi bi-person-circle me-1"></i>User
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end">
                                <li><a class="dropdown-item" href="#" onclick="window.location.href='/static/logout.html'; return false;"><i class="bi bi-box-arrow-right"></i>Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    `;
    console.log('✅ Fallback navbar with notification bell loaded');
});
