from PIL import Image, ImageDraw

ICON_SIZE = 81
OUTPUT_DIR = "D:/work/绿水青山/清道夫App/src/static/tabbar"

# 颜色
NORMAL_BG = "#f3f4f6"
NORMAL_FG = "#9ca3af"
ACTIVE_BG = "#eff6ff"
ACTIVE_FG = "#3b82f6"

def draw_rounded_rect(draw, xy, radius, fill):
    x1, y1, x2, y2 = xy
    draw.rounded_rectangle(xy, radius=radius, fill=fill)

def draw_home(img, color):
    draw = ImageDraw.Draw(img)
    # 房子主体
    draw.polygon([(40, 20), (20, 40), (60, 40)], fill=color)
    draw.rectangle([25, 40, 55, 62], fill=color)
    # 门
    draw.rectangle([35, 50, 45, 62], fill="white")

def draw_task(img, color):
    draw = ImageDraw.Draw(img)
    # 旗帜
    draw.rectangle([38, 18, 42, 58], fill=color)
    draw.polygon([(42, 18), (58, 26), (42, 34)], fill=color)
    # 底座
    draw.ellipse([32, 58, 48, 62], fill=color)

def draw_my(img, color):
    draw = ImageDraw.Draw(img)
    # 头
    draw.ellipse([30, 18, 50, 38], fill=color)
    # 身体
    draw.rounded_rectangle([24, 40, 56, 66], radius=8, fill=color)

def create_icon(name, active=False):
    bg = ACTIVE_BG if active else NORMAL_BG
    fg = ACTIVE_FG if active else NORMAL_FG
    img = Image.new("RGBA", (ICON_SIZE, ICON_SIZE), (255, 255, 255, 0))
    draw = ImageDraw.Draw(img)
    # 背景圆角方块
    draw.rounded_rectangle([4, 4, ICON_SIZE-4, ICON_SIZE-4], radius=16, fill=bg)

    if name == "home":
        draw_home(img, fg)
    elif name == "task":
        draw_task(img, fg)
    elif name == "my":
        draw_my(img, fg)

    suffix = "-active" if active else ""
    img.save(f"{OUTPUT_DIR}/{name}{suffix}.png", "PNG")

if __name__ == "__main__":
    for name in ["home", "task", "my"]:
        create_icon(name, active=False)
        create_icon(name, active=True)
    print("tabBar icons generated.")
