#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
將導航列改回原本的黑色主題
"""
import os
import re
from pathlib import Path

def revert_navbar_to_dark(file_path):
    """將導航列從淺色改回黑色主題"""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()

        original_content = content

        # 將淺色導航列改回黑色
        content = re.sub(
            r'<nav class="navbar navbar-expand-xl navbar-light bg-white([^"]*)"',
            r'<nav class="navbar navbar-expand-xl navbar-dark bg-dark\1"',
            content
        )

        # 移除淺色主題的自定義樣式
        # 找到 /* Navbar Custom Styles */ 開始到結束的區塊並移除
        content = re.sub(
            r'\s*/\* Navbar Custom Styles \*/.*?\.navbar-text \{[^}]*\}\s*',
            '\n',
            content,
            flags=re.DOTALL
        )

        # 只有內容改變時才寫入
        if content != original_content:
            with open(file_path, 'w', encoding='utf-8') as f:
                f.write(content)
            return True
        return False

    except Exception as e:
        print(f"處理 {file_path} 時發生錯誤: {e}")
        return False

def main():
    """主程序"""
    base_dir = Path(__file__).parent
    html_files = list(base_dir.glob("*.html"))

    updated_count = 0

    print(f"找到 {len(html_files)} 個 HTML 文件")
    print("=" * 60)

    for html_file in html_files:
        if revert_navbar_to_dark(html_file):
            print(f"✅ 已還原: {html_file.name}")
            updated_count += 1
        else:
            print(f"⏭️  跳過: {html_file.name}")

    print("=" * 60)
    print(f"✅ 完成！共還原 {updated_count} 個文件")

if __name__ == "__main__":
    main()
