import os
import glob

html_files = glob.glob(r"c:\Users\thiago.luna\Desktop\GitHub\sistema-eventos-front\*.html")

css_tag = '    <link rel="stylesheet" href="static/css/ui/notifications.css">\n'
js_tag = '    <script src="static/js/ui/notifications.js"></script>\n'

html_block = """    <!-- Componente de Notificações -->
    <div class="notifications-container" id="notificationsContainer">
        <button class="notification-bell-btn" id="notificationBellBtn" title="Notificações">
            <svg viewBox="0 0 24 24" fill="none" class="bell-icon" stroke="currentColor" stroke-width="2">
                <path d="M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"></path>
                <path d="M13.73 21a2 2 0 0 1-3.46 0"></path>
            </svg>
            <span class="notification-badge" id="notificationBadge" style="display: none;">0</span>
        </button>
        <div class="notifications-dropdown" id="notificationsDropdown">
            <div class="notifications-header">
                <h4>Notificações</h4>
                <button class="mark-all-read-btn" id="markAllReadBtn">Marcar todas como lidas</button>
            </div>
            <div class="notifications-list" id="notificationsList">
                <div class="notifications-empty">Nenhuma notificação nova.</div>
            </div>
        </div>
    </div>\n
"""

files_to_skip = ["login.html", "home.html", "clientes.html", "evento_form.html", "register.html", "index.html"]

for file in html_files:
    filename = os.path.basename(file)
    if filename in files_to_skip:
        continue
        
    with open(file, 'r', encoding='utf-8') as f:
        content = f.read()
        
    changed = False
    
    # Inject CSS
    if 'notifications.css' not in content:
        # Puts it before </head>
        content = content.replace('</head>', css_tag + '</head>')
        changed = True
        
    # Inject HTML
    if 'notificationsContainer' not in content:
        # Puts it before id="userProfile"
        content = content.replace('<div class="user-profile" id="userProfile">', html_block + '    <div class="user-profile" id="userProfile">')
        changed = True
        
    # Inject JS
    if 'notifications.js' not in content:
        # Puts it before </body> or after layout.js ... checking for </body> is safer
        content = content.replace('</body>', js_tag + '</body>')
        changed = True
        
    if changed:
        with open(file, 'w', encoding='utf-8') as f:
            f.write(content)
        print(f"Updated {filename}")
    else:
        print(f"No changes for {filename}")

print("Injection complete.")
