import codecs
import os
import re

files = [
    r'D:\cnf\chatbot-canifa-feedback\backend\static\social-inbox\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-composer\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-approval\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\content-calendar\index.html',
    r'D:\cnf\chatbot-canifa-feedback\backend\static\media-library\index.html'
]

# Pattern to match most emojis (simplistic emoji block ranges)
emoji_pattern = re.compile(r'[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F1E0-\U0001F1FF\U00002600-\U000026FF\U00002700-\U000027BF]+')

# Also handle the variant selectors and some specific unicode symbols that might be used as pseudo-emojis
specific_emojis = ['✨', '🔄', '📝', '🔍', '⚙️', '✅', '❌', '⏰', '🚀', '📭', '✍️', '📬', '📋', '👁️', '🪄', '✂️', '🏷️', '😊', '👆', '💾', '📅', '🗑️', '📦', '↩️', '❓', '❔', '📘', '📸', '🎵', '▶️', '🔵', '🟡', '🟢', '😠', '😐', '💬', '📣', '✉️', '⭐', '📦', '⏳', '📌', '✏️', '💥', '🚫']

for fpath in files:
    if not os.path.exists(fpath):
        continue
    with codecs.open(fpath, 'r', 'utf-8') as f:
        content = f.read()
    
    # Replace using regex
    content = emoji_pattern.sub('', content)
    
    # Replace using specific list
    for e in specific_emojis:
        content = content.replace(e, '')
    
    # Clean up double spaces caused by removing emojis (e.g. ">  " -> "> ")
    content = content.replace('  ', ' ')
    content = content.replace('> ', '>')
    
    with codecs.open(fpath, 'w', 'utf-8') as f:
        f.write(content)
    print(f"Removed emojis from {fpath}")

