#!/usr/bin/env python3
"""DMark FB Daily — 1 Slide Carousel, DMark BG Orange Template
Vertically centered, safe zone 20px, no boxes
"""
from PIL import Image, ImageDraw, ImageFont
import os

OUT_DIR = os.path.expanduser("~/.openclaw/workspace-atun/dmark_carousel_final")
os.makedirs(OUT_DIR, exist_ok=True)

W, H = 1080, 1350
ORANGE = (249, 115, 22)
WHITE = (255, 255, 255)
S20 = 20

FONT_DIR = os.path.expanduser("~/.fonts")

J170 = ImageFont.truetype(os.path.join(FONT_DIR, "Poppins-Bold.ttf"), 170)
SUB  = ImageFont.truetype(os.path.join(FONT_DIR, "Poppins-Regular.ttf"), 36)
B24  = ImageFont.truetype(os.path.join(FONT_DIR, "Poppins-Bold.ttf"), 24)
R20  = ImageFont.truetype(os.path.join(FONT_DIR, "Poppins-Regular.ttf"), 20)
R22  = ImageFont.truetype(os.path.join(FONT_DIR, "Poppins-Regular.ttf"), 22)

M = 65

def fh(drw, text, font):
    b = drw.textbbox((0,0), text, font=font)
    return b[3] - b[1]

def header(d, page="1/1"):
    d.text((M, S20), "DMARK", font=B24, fill=WHITE)
    d.text((W - M, S20), page, font=R22, fill=WHITE, anchor="rt")

def footer(d, left="www.dmark.id", right=""):
    d.text((M, H - S20 - 5), left, font=R20, fill=WHITE)
    if right:
        d.text((W - M, H - S20 - 5), right, font=R20, fill=WHITE, anchor="rt")

def divider(d, y, width=400):
    x = M
    while x < M + width:
        e = min(x + 14, M + width)
        d.line([(x, y), (e, y)], fill=WHITE, width=2)
        x += 24

# ============ SINGLE SLIDE ============
img = Image.new("RGB", (W, H), ORANGE)
d = ImageDraw.Draw(img)

titles = ["DIGITAL", "GUERILLA", "MARKETING"]
subs = ["Padukan strategi online & offline", "buat hasil yang maksimal!"]
items = [
    "\u2611 Aksi kreatif di dunia nyata x amplifikasi digital",
    "\u2611 Viral loop: create-share-user generated content",
    "\u2611 Geo-targeted stunt + geofencing ads",
    "\u2611 Real-time engagement & live streaming",
]
hashtag = "#DigitalMarketing #GuerillaMarketing #BrandingKreatif #DMARK"

hdr_bot = S20 + fh(d, "DMARK", B24) + 15
ftr_top = H - S20 - fh(d, "www.dmark.id", R20) - 15
area = ftr_top - hdr_bot

total_h = 0
for t in titles:
    total_h += int(fh(d, t, J170) * 1.2)
total_h += 30 + 5 + 30
for s in subs:
    total_h += int(fh(d, s, SUB) * 1.5)
total_h += 30
for item in items:
    total_h += int(fh(d, item, SUB) * 1.4)

start_y = hdr_bot + (area - total_h) // 2

header(d, "1/1")
footer(d, "www.dmark.id", hashtag)

ty = start_y
for t in titles:
    d.text((M, ty), t, font=J170, fill=WHITE)
    ty += int(fh(d, t, J170) * 1.2)

ty += 25
divider(d, ty)
ty += 25

for s in subs:
    d.text((M, ty), s, font=SUB, fill=WHITE)
    ty += int(fh(d, s, SUB) * 1.5)

ty += 20
for item in items:
    d.text((M, ty), item, font=SUB, fill=WHITE)
    ty += int(fh(d, item, SUB) * 1.4)

out_path = os.path.join(OUT_DIR, "dmark_fb_daily.png")
img.save(out_path)
print(f"✅ Saved: {out_path}")
