"""Cuerpos de las tiles Salud (alta) y Canales (ancha) del Dashboard, según la spec §7."""
import sys, re, pathlib
sys.path.insert(0, str(pathlib.Path(__file__).parent)); from bentofy import find_close
p = pathlib.Path(sys.argv[1]); h = p.read_text(encoding="utf-8")
def replace_body(h, open_tag, body):
    i = h.find(open_tag); assert i >= 0, open_tag
    head_end = find_close(h, h.find('<div class="tile__head">', i))
    tile_end = find_close(h, i)
    assert h[tile_end - 4:tile_end] == "</a>"
    return h[:head_end] + body + h[tile_end - 4:]
salud = ('<div class="tile__figure"><span>3</span><span class="tile__unit">avisos</span></div>'
         '<div><span class="ds" data-ds="Badge" data-props=\'{"label": "1 URGENTE", "tone": "danger"}\'></span></div>'
         '<div class="tile__divider"></div>'
         '<p class="tile__text">Vendiste más y ganaste menos</p>'
         '<p class="tile__note">371 € de comisión · te quedaste 71 cts de cada euro, tu normal son 75</p>'
         '<div class="tile__divider tile__divider--push"></div>'
         '<p class="tile__note tile__note--light">2 avisos más · 2 para saber</p>')
canales = ('<div class="tile__row">'
           '<div class="tile__figure"><span>43 %</span><span class="tile__unit">por marketplace</span></div>'
           '<span class="grow"></span>'
           '<div class="tile__note--right"><p class="tile__note">mejor canal</p><p class="tile__body tile__body--regular">Webapp</p></div>'
           '</div>'
           '<div class="tile__bar" aria-hidden="true">'
           '<div style="width:45%;background:var(--channel-web);"></div>'
           '<div style="width:43%;background:var(--channel-uber-eats);"></div>'
           '<div style="width:12%;background:var(--app-chart-accent);"></div>'
           '</div>'
           '<div class="tile__row tile__row--tight">'
           '<span class="tile__legend"><span class="tile__dot" style="background:var(--channel-web);"></span>canal propio <span class="tile__strong">45 %</span></span>'
           '<span class="tile__legend"><span class="tile__dot" style="background:var(--channel-uber-eats);"></span>marketplace <span class="tile__strong">43 %</span></span>'
           '<span class="tile__legend"><span class="tile__dot" style="background:var(--app-chart-accent);"></span>directo <span class="tile__strong">12 %</span></span>'
           '</div>')
h = replace_body(h, '<a class="tile tile--tall" href="salud.html" style="--i:1;">', salud)
h = replace_body(h, '<a class="tile tile--wide" href="canales.html" style="--i:3;">', canales)
p.write_text(h, encoding="utf-8"); print("cuerpos de Salud y Canales aplicados")
