import re

with open("app/static/bim/index.html", "r", encoding="utf-8") as f:
    content = f.read()

# Replace SEG_PLAN and PLAN_MANHOLE/PLAN_PULL
new_seg_plan = """    // Kế hoạch hình học theo phân đoạn
    const SEG_PLAN = [
      { dyke_excav: ['2026-10-11', '2026-10-25'], bamboo: ['2026-10-26', '2026-11-05'], pile: ['2026-11-06', '2026-11-15'], strut: ['2026-11-16', '2026-11-20'], lean: ['2026-11-21', '2026-11-25'], wall: ['2026-11-26', '2026-12-05'], slab: ['2026-12-06', '2026-12-15'], pull: ['2026-12-16', '2026-12-20'] },
      { dyke_excav: ['2026-12-21', '2027-01-05'], bamboo: ['2027-01-06', '2027-01-15'], pile: ['2027-01-16', '2027-01-25'], strut: ['2027-01-26', '2027-01-31'], lean: ['2027-02-01', '2027-02-05'], wall: ['2027-02-06', '2027-02-20'], slab: ['2027-02-21', '2027-02-28'], pull: ['2027-03-01', '2027-03-15'] },
      { dyke_excav: ['2027-03-16', '2027-03-31'], bamboo: ['2027-04-01', '2027-04-10'], pile: ['2027-04-11', '2027-04-20'], strut: ['2027-04-21', '2027-04-25'], lean: ['2027-04-26', '2027-04-30'], wall: ['2027-05-01', '2027-05-15'], slab: ['2027-05-16', '2027-05-30'], pull: ['2027-06-01', '2027-06-15'] }
    ].map(p => Object.fromEntries(Object.entries(p).map(([k, [s, e]]) => [k, [dayOf(s), dayOf(e)]])));
    const PLAN_MANHOLE = [dayOf('2027-05-20'), dayOf('2027-05-30')];
"""

# We'll use a very forgiving regex to replace the block
pattern = re.compile(r'// Kế hoạch hình học theo phân đoạn \([^\n]*\n\s*const SEG_PLAN = \[.*?const PLAN_PULL = \[.*?\];', re.DOTALL | re.IGNORECASE)
content = pattern.sub(new_seg_plan, content)

with open("app/static/bim/index.html", "w", encoding="utf-8") as f:
    f.write(content)
print("Fixed SEG_PLAN!")
