#!/usr/bin/env python3
"""
NexusOS battery-icon recolorizer.

xfce4-power-manager draws the panel battery from the icon theme's
`battery-*-charging-symbolic` icons. Papirus-Dark (which NexusOS
inherits from) paints the charging bolt/fill in its own material green
(#4caf50). This script copies every charging battery symbolic icon into
the NexusOS theme with that green swapped for brand_green (#8cc63f), so
the charging indicator matches the rest of the NexusOS accent.

Only the green is touched — the gray battery body (#dfdfdf) is left
alone (it already reads fine on the dark panel). Symlinked aliases
(good/low/medium/caution/empty-charging) are resolved and written as
real recolored files so every requested name overrides Papirus.

Run:    python3 build_battery.py
Then:   gtk-update-icon-cache -f -t ../NexusOS-icons
        xfce4-panel -r        # reload panel to pick up new icons
"""

from pathlib import Path

ROOT = Path(__file__).resolve().parent
OUT = ROOT.parent / "NexusOS-icons" / "scalable" / "status"
SRC = Path("/usr/share/icons/Papirus-Dark/symbolic/status")

PAPIRUS_GREEN = "#4caf50"
NEXUS_GREEN = "#8cc63f"   # brand_green


def main() -> None:
    OUT.mkdir(parents=True, exist_ok=True)
    # Every charging battery symbolic icon (charged-100 has no green, so
    # the replace is a harmless no-op there; we copy it too for a
    # consistent battery set under the NexusOS theme).
    sources = sorted(SRC.glob("battery-*charg*-symbolic.svg"))
    written = 0
    for src in sources:
        # read_text follows symlinks, so alias names get the real content
        content = src.read_text()
        if PAPIRUS_GREEN not in content:
            # charged/full icons with no green — skip; let them fall
            # through to Papirus unchanged.
            continue
        recolored = content.replace(PAPIRUS_GREEN, NEXUS_GREEN)
        (OUT / src.name).write_text(recolored)
        written += 1
    print(f"Recolored {written} charging battery icons "
          f"({PAPIRUS_GREEN} -> {NEXUS_GREEN}) into {OUT}")


if __name__ == "__main__":
    main()
