import re

with open(r'D:\Evolução categorias\sistema_dfe.html', 'r', encoding='utf-8') as f:
    html = f.read()

# 1. Textos e títulos
html = html.replace('2021\u20132025', '2021\u20132026')
html = html.replace('2021-2025', '2021-2026')
html = html.replace('&copy; 2025', '&copy; 2026')

# 2. Seletor de ano - inserir 2026 após opção 2025
html = re.sub(
    r'(<option value=["\']2025["\'](?:\s+selected)?[^>]*>2025</option>)',
    '<option value="2025">2025</option>\n          <option value="2026" selected>2026</option>',
    html
)

# 3. Array YEARS / ANOS no JS
html = re.sub(
    r"(const YEARS\s*=\s*\[)([^\]]*['\"]2025['\"])\]",
    r"\1\2,'2026']",
    html
)
html = re.sub(
    r"(const ANOS\s*=\s*\[)([^\]]*['\"]2025['\"])\]",
    r"\1\2,'2026']",
    html
)

# 4. labels de gráficos
html = re.sub(
    r"(labels\s*:\s*\[)([^\]]*['\"]2025['\"])(\s*\])",
    r"\1\2,'2026'\3",
    html
)

# 5. defaultYear
html = re.sub(r"(const defaultYear\s*=\s*)['\"]?2025['\"]?", r"\g<1>'2026'", html)
html = re.sub(r"(defaultYear\s*=\s*)['\"]?2025['\"]?", r"\g<1>'2026'", html)

# 6. KPI - ano padrão exibido nos cards
html = html.replace('>Faturamento\nBruto 2025<', '>Faturamento\nBruto 2026<')
html = html.replace('Faturamento Bruto 2025', 'Faturamento Bruto 2026')
html = html.replace('Lucro Bruto 2025', 'Lucro Bruto 2026')
html = html.replace('Total Despesas 2025', 'Total Despesas 2026')
html = html.replace('Resultado 2025', 'Resultado 2026')

with open(r'D:\Evolução categorias\sistema_dfe.html', 'w', encoding='utf-8') as f:
    f.write(html)

# Verificar
with open(r'D:\Evolução categorias\sistema_dfe.html', 'r', encoding='utf-8') as f:
    html2 = f.read()

print('Titulos OK:', '2021\u20132026' in html2)
print('2026 no seletor OK:', 'value="2026"' in html2 or "value='2026'" in html2)

anos_ok = re.search(r"const ANOS\s*=\s*\[[^\]]*2026", html2)
print('ANOS array OK:', bool(anos_ok))
if anos_ok:
    start = anos_ok.start()
    print('  ->', html2[start:start+60])

labels_ok = re.search(r"labels\s*:\s*\[[^\]]*2026", html2)
print('labels OK:', bool(labels_ok))
