{#
    導航列組件

    注意：目前已停用登入驗證，所有選單項目對所有人可見。

    使用方式：
        {% include 'components/_navbar.html' %}
#}

<nav class="navbar navbar-expand-xl navbar-dark bg-custom-dark fixed-top shadow-sm">
    <div class="container">
        <!-- 品牌 Logo -->
        <a class="navbar-brand d-flex align-items-center" href="/">
            <span class="d-none d-sm-inline fw-bold" style="letter-spacing: 2px;">WOOO</span>
        </a>

        <!-- 手機版選單按鈕 -->
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <!-- 商品看板 - 所有人可見 -->
                <li class="nav-item">
                    <a class="nav-link {% if active_page == 'dashboard' %}active{% endif %}" href="/">
                        <i class="fas fa-chart-line me-1"></i>商品看板
                    </a>
                </li>

                <!-- 活動看板 - 所有人可見 -->
                <li class="nav-item">
                    <a class="nav-link {% if active_page == 'edm' %}active{% endif %}" href="/edm">
                        <i class="fas fa-bullhorn me-1"></i>活動看板
                    </a>
                </li>

                <!-- 分析報表 -->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle {% if active_page in ['sales', 'daily_sales', 'monthly', 'growth'] %}active{% endif %}"
                       href="#" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-chart-bar me-1"></i>分析報表
                    </a>
                    <ul class="dropdown-menu">
                        <li>
                            <a class="dropdown-item" href="/sales_analysis">
                                <i class="fas fa-chart-bar me-2"></i>業績分析
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/daily_sales">
                                <i class="fas fa-calendar-day me-2"></i>當日業績
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/growth_analysis">
                                <i class="fas fa-chart-line me-2"></i>成長分析
                            </a>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item" href="/monthly_summary_analysis">
                                <i class="fas fa-table me-2"></i>月份總表數據分析
                            </a>
                        </li>
                        {% if metabase_url %}
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item" href="{{ metabase_url }}" target="_blank">
                                <i class="fas fa-chart-pie me-2"></i>自訂圖表 (Metabase)
                                <i class="fas fa-external-link-alt ms-1 small text-muted"></i>
                            </a>
                        </li>
                        {% endif %}
                        {% if grist_url %}
                        <li>
                            <a class="dropdown-item" href="{{ grist_url }}" target="_blank">
                                <i class="fas fa-table me-2"></i>資料協作 (Grist)
                                <i class="fas fa-external-link-alt ms-1 small text-muted"></i>
                            </a>
                        </li>
                        {% endif %}
                    </ul>
                </li>

                <!-- 廠商缺貨 -->
                <li class="nav-item">
                    <a class="nav-link {% if active_page == 'vendor_stockout' %}active{% endif %}" href="/vendor-stockout">
                        <i class="fas fa-box-open me-1"></i>廠商缺貨
                    </a>
                </li>

                <!-- AI 助手 -->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle {% if active_page in ['ai_recommend', 'ai_history'] %}active{% endif %}"
                       href="#" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-robot me-1"></i>AI 助手
                    </a>
                    <ul class="dropdown-menu">
                        <li>
                            <a class="dropdown-item" href="/ai_recommend">
                                <i class="fas fa-magic me-2"></i>智慧文案生成
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/ai_history">
                                <i class="fas fa-history me-2"></i>生成歷史記錄
                            </a>
                        </li>
                    </ul>
                </li>

                <!-- 雲端匯入 -->
                <li class="nav-item">
                    <a class="nav-link {% if active_page == 'auto_import' %}active{% endif %}" href="/auto_import">
                        <i class="fas fa-cloud-download-alt me-1"></i>雲端匯入
                    </a>
                </li>

                <!-- 系統管理 -->
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle {% if active_page in ['settings', 'system_settings', 'logs', 'crawler', 'user_management', 'ai_automation_smoke'] %}active{% endif %}"
                       href="#" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-cog me-1"></i>系統管理
                    </a>
                    <ul class="dropdown-menu">
                        <li>
                            <a class="dropdown-item" href="/user_management">
                                <i class="fas fa-users-cog me-2"></i>用戶管理
                            </a>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item" href="/settings">
                                <i class="fas fa-robot me-2"></i>爬蟲管理
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/crawler_management">
                                <i class="fas fa-spider me-2"></i>爬蟲設定
                            </a>
                        </li>
                        <li><hr class="dropdown-divider"></li>
                        <li>
                            <a class="dropdown-item" href="/system_settings">
                                <i class="fas fa-sliders-h me-2"></i>系統設定
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/logs">
                                <i class="fas fa-file-alt me-2"></i>系統日誌
                            </a>
                        </li>
                        <li>
                            <a class="dropdown-item" href="/ai_automation_smoke">
                                <i class="fas fa-heartbeat me-2"></i>AI 自動化 Smoke
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>

            <!-- 右側區域 -->
            <div class="d-flex align-items-center">
                <!-- 時間顯示 -->
                <span class="navbar-text text-light small me-3">
                    <i class="fas fa-clock me-1"></i>
                    <span id="navbar-datetime">{{ datetime_now or '' }}</span>
                </span>
            </div>
        </div>
    </div>
</nav>

<!-- 導航列時間更新腳本 -->
<script>
(function() {
    function updateNavbarTime() {
        const now = new Date();
        const formatted = now.getFullYear() + '-' +
            String(now.getMonth() + 1).padStart(2, '0') + '-' +
            String(now.getDate()).padStart(2, '0') + ' ' +
            String(now.getHours()).padStart(2, '0') + ':' +
            String(now.getMinutes()).padStart(2, '0') + ':' +
            String(now.getSeconds()).padStart(2, '0');

        const el = document.getElementById('navbar-datetime');
        if (el) el.textContent = formatted;
    }

    // 每秒更新時間
    setInterval(updateNavbarTime, 1000);
})();
</script>
