from lib import WIDTH
import dist
import macroharm
import svgutils.transform as sg
import textures
import timing
import xml.etree.ElementTree as et

TOTAL_HEIGHT = dist.HEIGHT + macroharm.HEIGHT + textures.HEIGHT + timing.HEIGHT


def main():
    fig = sg.SVGFigure(f"{WIDTH}px", f"{TOTAL_HEIGHT}px")

    textures_fig = sg.fromfile("textures.svg")
    dist_fig = sg.fromfile("dist.svg")
    macroharm_fig = sg.fromfile("macroharm.svg")
    timing_fig = sg.fromfile("timing.svg")

    textures_root = textures_fig.getroot()
    dist_root = dist_fig.getroot()
    macroharm_root = macroharm_fig.getroot()
    timing_root = timing_fig.getroot()

    dist_root.moveto(0, textures.HEIGHT)
    macroharm_root.moveto(0, textures.HEIGHT + dist.HEIGHT)
    timing_root.moveto(0, textures.HEIGHT + dist.HEIGHT + macroharm.HEIGHT)

    fig.append([textures_root, dist_root, macroharm_root, timing_root])

    fig.save("combined.svg")

    et.register_namespace("", "http://www.w3.org/2000/svg")
    tree = et.parse("combined.svg")
    root = tree.getroot()
    root.set("width", str(WIDTH))
    root.set("height", str(TOTAL_HEIGHT))
    tree.write("combined.svg")


if __name__ == "__main__":
    main()
