import re

with open("resources/js/components/admin/MarketingManager.tsx", "r", encoding="utf-8") as f:
    mm_lines = f.readlines()

# Find {editingItem ? (
leak_start = -1
for i, l in enumerate(mm_lines):
    if "{editingItem ? (" in l:
        leak_start = i
        break

if leak_start != -1:
    leak_block = mm_lines[leak_start:-3]
    mm_lines = mm_lines[:leak_start] + ["    </>\n", "  );\n", "}\n"]
    with open("resources/js/components/admin/MarketingManager.tsx", "w", encoding="utf-8") as f:
        f.writelines(mm_lines)
    print("MarketingManager.tsx fixed!")
    
    with open("resources/js/components/AdminDashboard.tsx", "r", encoding="utf-8") as f:
        ad_lines = f.readlines()
        
    insert_idx = -1
    for i, l in enumerate(ad_lines):
        if "<MarketingManager" in l:
            # find where it ends
            for j in range(i, len(ad_lines)):
                if "          )}\n" == ad_lines[j] or ")}\n" in ad_lines[j]:
                    insert_idx = j + 1
                    break
            break
            
    if insert_idx != -1:
        ad_lines = ad_lines[:insert_idx] + leak_block + ad_lines[insert_idx:]
        with open("resources/js/components/AdminDashboard.tsx", "w", encoding="utf-8") as f:
            f.writelines(ad_lines)
        print("AdminDashboard.tsx leak restored!")
