from PIL import Image, ImageDraw, ImageFont
import os

FONT_DIR = "/home/mantapman/.hermes/profiles/atun/workspace/fonts"

def get_font(name, size):
    path = os.path.join(FONT_DIR, name)
    if os.path.exists(path):
        return ImageFont.truetype(path, size)
    return ImageFont.load_default()

def create_story():
    W, H = 1080, 1920
    img = Image.new("RGB", (W, H), "#0D7C3F")
    draw = ImageDraw.Draw(img)

    # Gold accent bar atas
    draw.rectangle([0, 0, W, 12], fill="#D4AF37")
    draw.rectangle([0, H-12, W, H], fill="#D4AF37")

    # --- HEADER ---
    try:
        font_brand = get_font("Poppins-Bold.ttf", 64)
        font_tagline = get_font("Poppins-Regular.ttf", 36)
        font_services = get_font("Poppins-Regular.ttf", 40)
        font_contact = get_font("Poppins-Regular.ttf", 30)
        font_checklist = get_font("Poppins-Bold.ttf", 36)
    except:
        font_brand = ImageFont.load_default()
        font_tagline = ImageFont.load_default()
        font_services = ImageFont.load_default()
        font_contact = ImageFont.load_default()
        font_checklist = ImageFont.load_default()

    # Brand name
    draw.text((W//2, 200), "APOTEK AREK", fill="white", font=font_brand, anchor="mm")
    draw.text((W//2, 270), "LANCOR FARMA", fill="#D4AF37", font=font_brand, anchor="mm")

    # Tagline
    draw.text((W//2, 350), "Apotekne oreng Pamekasan", fill="white", font=font_tagline, anchor="mm")

    # Gold divider line
    draw.line([(W//4, 410), (3*W//4, 410)], fill="#D4AF37", width=3)

    # --- CENTER: Pharmacy cross icon (simple drawn) ---
    cross_size = 120
    cx, cy = W//2, 620
    # Vertical bar
    draw.rectangle([cx - 30, cy - cross_size, cx + 30, cy + cross_size], fill="white")
    # Horizontal bar
    draw.rectangle([cx - cross_size, cy - 30, cx + cross_size, cy + 30], fill="white")
    # Gold border
    draw.rectangle([cx - 36, cy - cross_size - 6, cx + 36, cy + cross_size + 6], outline="#D4AF37", width=6)
    draw.rectangle([cx - cross_size - 6, cy - 36, cx + cross_size + 6, cy + 36], outline="#D4AF37", width=6)

    # --- SERVICES ---
    services = [
        ("\u2713", "Obat-obatan Lengkap"),
        ("\u2713", "Vitamin & Suplemen"),
        ("\u2713", "Kesehatan Keluarga"),
        ("\u2713", "Konsultasi Gratis"),
    ]

    y_start = 820
    spacing = 65
    for i, (check, label) in enumerate(services):
        y = y_start + i * spacing
        draw.text((280, y), check, fill="#D4AF37", font=font_checklist)
        draw.text((340, y), label, fill="white", font=font_services)

    # --- FOOTER ---
    # Gold divider
    draw.line([(W//4, 1250), (3*W//4, 1250)], fill="#D4AF37", width=2)

    draw.text((W//2, 1350), "0852-1211-0314", fill="#D4AF37", font=font_contact, anchor="mm")
    draw.text((W//2, 1420), "www.apotekpamekasan.com", fill="white", font=font_contact, anchor="mm")

    # Bottom decorative pattern (simple batik motif using circles)
    for i in range(8):
        x = 120 + i * 120
        for j in range(2):
            yy = 1650 + j * 60
            draw.ellipse([x-15, yy-15, x+15, yy+15], outline="#D4AF37", width=2)

    # Save
    out_path = "/home/mantapman/.hermes/profiles/atun/workspace/apotek_arlan_story1.png"
    img.save(out_path, "PNG")
    print(f"Saved: {out_path}")
    return out_path

if __name__ == "__main__":
    create_story()
