from PIL import Image, ImageDraw, ImageFont

W, H = 1240, 1754  # A4 @150dpi
BG = (255, 255, 255)
BLUE = (30, 64, 175)      # #1E40AF studio blue
BLUE_DARK = (23, 48, 130)
GRAY = (100, 116, 139)
LIGHT = (241, 245, 249)
LINE = (203, 213, 225)

def font(name, size):
    return ImageFont.truetype(f"fonts/{name}.ttf", size)

img = Image.new("RGB", (W, H), BG)
d = ImageDraw.Draw(img)

# Header band
d.rectangle([0, 0, W, 220], fill=BLUE)
d.text((70, 60), "INVOICE", font=font("Poppins-Bold", 64), fill=(255, 255, 255))
d.text((70, 140), "No. INV/2026/0001", font=font("Poppins-Regular", 26), fill=(219, 234, 254))

# Logo / name studioSoft
d.text((W - 420, 52), "StudioSoft", font=font("Poppins-Bold", 44), fill=(255, 255, 255))
d.text((W - 420, 120), "Partner Pertumbuhan Bisnis Berbasis Data", font=font("Poppins-Regular", 20), fill=(219, 234, 254))

# From / Bill to
y = 300
d.text((70, y), "DARI", font=font("Poppins-Bold", 24), fill=GRAY)
d.text((70, y+40), "StudioSoft", font=font("Poppins-Bold", 32), fill=(15, 23, 42))
for i, t in enumerate(["Jl. Contoh Raya No. 88, Surabaya", "Email: halo@studiosoft.id", "WA: 0819-3500-0624"]):
    d.text((70, y+92+i*34), t, font=font("Poppins-Regular", 24), fill=(71, 85, 105))

d.text((W-700, y), "KEPADA", font=font("Poppins-Bold", 24), fill=GRAY)
d.text((W-700, y+40), "Nama Klien / Perusahaan", font=font("Poppins-Bold", 32), fill=(15, 23, 42))
for i, t in enumerate(["Alamat Klien", "Kota, Provinsi", "Telepon Klien"]):
    d.text((W-700, y+92+i*34), t, font=font("Poppins-Regular", 24), fill=(71, 85, 105))

# Table header
ty = 640
d.rectangle([70, ty, W-70, ty+70], fill=LIGHT)
cols = [(70, 120, "NO"), (200, 430, "DESKRIPSI"), (640, 200, "QTY"), (850, 170, "HARGA"), (1050, 120, "JUMLAH")]
for x, w, t in cols:
    d.text((x, ty+16), t, font=font("Poppins-Bold", 26), fill=(15, 23, 42))

items = [
    ("1", "Jasa Pembuatan Website Company Profile", "1", "Rp 5.000.000", "Rp 5.000.000"),
    ("2", "Desain Logo & Identitas Visual", "1", "Rp 1.500.000", "Rp 1.500.000"),
    ("3", "Optimasi SEO On-Page", "1", "Rp 1.000.000", "Rp 1.000.000"),
    ("4", "Maintenance Bulanan", "3", "Rp 500.000", "Rp 1.500.000"),
]
yy = ty + 70
for no, desc, qty, harga, jml in items:
    d.line([70, yy, W-70, yy], fill=LINE)
    d.text((80, yy+18), no, font=font("Poppins-Regular", 24), fill=(71, 85, 105))
    d.text((320, yy+18), desc, font=font("Poppins-Regular", 24), fill=(15, 23, 42))
    d.text((660, yy+18), qty, font=font("Poppins-Regular", 24), fill=(71, 85, 105))
    d.text((870, yy+18), harga, font=font("Poppins-Regular", 24), fill=(71, 85, 105))
    d.text((1080, yy+18), jml, font=font("Poppins-Bold", 24), fill=(15, 23, 42), anchor="ra")
    yy += 64
d.line([70, yy+4, W-70, yy+4], fill=LINE)

# Total
yy += 24
d.rectangle([W-470, yy, W-70, yy+90], fill=LIGHT)
d.text((W-450, yy+22), "TOTAL", font=font("Poppins-Bold", 28), fill=(15, 23, 42))
d.text((W-100, yy+20), "Rp 9.000.000", font=font("Poppins-Bold", 28), fill=BLUE, anchor="ra")

# Footer note + bank
fy = 1460
d.rectangle([70, fy, W-70, fy+150], fill=LIGHT)
d.text((90, fy+22), "Pembayaran via transfer ke:", font=font("Poppins-Bold", 24), fill=(15, 23, 42))
d.text((90, fy+66), "BCA 123-456-7890 a.n. StudioSoft", font=font("Poppins-Regular", 24), fill=(71, 85, 105))

# Signature
d.text((W-460, 1580), "Hormat kami,", font=font("Poppins-Regular", 24), fill=(71, 85, 105))
d.text((W-460, 1690), "StudioSoft", font=font("Poppins-Bold", 30), fill=(15, 23, 42))

img.save("contoh_invoice_studiosoft.png")
print("OK saved")
