#!/usr/bin/env python3
"""Buat gambar unggulan TSC secara mandiri (tanpa stok foto) untuk artikel #10134.

Ukuran 1000x567 seperti gambar unggulan TSC lainnya. Gaya: bersih, medis, warna merek biru navy.
"""
import os
from PIL import Image, ImageDraw, ImageFont

WS = "/home/mantapman/.hermes/profiles/atun/workspace"
OUT = f"{WS}/tsc_feat_dokter-kulit-sidoarjo-panduan-berobat.webp"
FONTS = os.path.expanduser("~/.fonts")

NAVY = (11, 31, 58)
BIRU = (30, 64, 175)
BIRU_MUDA = (219, 234, 254)
ABU = (100, 116, 139)
PUTIH = (255, 255, 255)

W, H = 1000, 567
PAD = 62


def f(nama, ukuran):
    return ImageFont.truetype(os.path.join(FONTS, nama), ukuran)


def bungkus(teks, font, maks):
    kata, baris, kini = teks.split(), [], ""
    for k in kata:
        coba = (kini + " " + k).strip()
        if font.getlength(coba) <= maks:
            kini = coba
        else:
            if kini:
                baris.append(kini)
            kini = k
    if kini:
        baris.append(kini)
    return baris


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

# panel biru di kanan + motif lingkaran (kesan medis, bersih)
panel = int(W * 0.34)
d.rectangle([W - panel, 0, W, H], fill=BIRU)
for i, r in enumerate((150, 110, 70)):
    x, y = W - panel // 2, H // 2
    d.ellipse([x - r, y - r, x + r, y + r], outline=(255, 255, 255), width=3 if i == 2 else 2)
d.line([W - panel // 2, H // 2 - 46, W - panel // 2, H // 2 + 46], fill=PUTIH, width=10)
d.line([W - panel // 2 - 46, H // 2, W - panel // 2 + 46, H // 2], fill=PUTIH, width=10)

# garis aksen kiri
d.rectangle([0, 0, 10, H], fill=BIRU)

# kicker
d.text((PAD, PAD - 6), "THE SKIN CODE CLINIC", font=f("Poppins-SemiBold.ttf", 24), fill=BIRU)
d.text((PAD, PAD + 26), "Krian, Sidoarjo", font=f("Poppins-Regular.ttf", 20), fill=ABU)

# judul
maks = W - panel - PAD - 46
baris = bungkus("Dokter Kulit Sidoarjo", f("Poppins-Bold.ttf", 62), maks)
y = 168
for b in baris:
    d.text((PAD, y), b, font=f("Poppins-Bold.ttf", 62), fill=NAVY)
    y += 74
y += 6

sub = bungkus("Panduan berobat, layanan, dan cara buat janji", f("Poppins-Regular.ttf", 27), maks)
for b in sub:
    d.text((PAD, y), b, font=f("Poppins-Regular.ttf", 27), fill=ABU)
    y += 38

# kaki
d.rectangle([PAD, H - 96, PAD + 74, H - 92], fill=BIRU)
d.text((PAD, H - 78), "theskincodeclinic.com", font=f("Poppins-SemiBold.ttf", 23), fill=NAVY)
d.text((PAD, H - 46), "Konsultasi lewat WhatsApp · 0851-1744-4417", font=f("Poppins-Regular.ttf", 20), fill=ABU)

img.save(OUT, "WEBP", quality=92, method=6)
print(f"→ {OUT}")
print(f"   ukuran {img.size} · {os.path.getsize(OUT)//1024} KB")
