#!/usr/bin/env python3
"""
플레이스홀더 스크린샷 이미지 생성
PIL을 사용하여 각 사이트의 플레이스홀더 이미지를 생성합니다.
"""

import os
from PIL import Image, ImageDraw, ImageFont

BASE_DIR = "/var/www/tkim.planitai.co.jp/blog/20260130-make-design-adv"
SCREENSHOTS_DIR = os.path.join(BASE_DIR, "screenshots")

# 사이트 정보
SITES = {
    "001": {"name": "Apple", "color": "#000000"},
    "002": {"name": "Stripe", "color": "#635BFF"},
    "003": {"name": "Linear", "color": "#584CFF"},
    "004": {"name": "Vercel", "color": "#000000"},
    "005": {"name": "Figma", "color": "#FF7262"},
    "006": {"name": "Notion", "color": "#000000"},
    "007": {"name": "Webflow", "color": "#425FFE"},
    "008": {"name": "Framer", "color": "#0099FF"},
    "009": {"name": "Airbnb", "color": "#FF5A5F"},
    "010": {"name": "Tesla", "color": "#171A20"},
}

def create_placeholder(num, site_info, width=1920, height=3000):
    """플레이스홀더 이미지 생성"""
    # 이미지 생성
    img = Image.new('RGB', (width, height), color='#F9FAFB')
    draw = ImageDraw.Draw(img)

    # 헤더 영역
    draw.rectangle([(0, 0), (width, 200)], fill=site_info['color'])

    # 텍스트 추가 (기본 폰트 사용)
    try:
        # 큰 폰트 시도
        font_large = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 80)
        font_small = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 40)
    except:
        # 기본 폰트 사용
        font_large = ImageFont.load_default()
        font_small = ImageFont.load_default()

    # 사이트 이름
    text = f"{num}. {site_info['name']}"
    bbox = draw.textbbox((0, 0), text, font=font_large)
    text_width = bbox[2] - bbox[0]
    text_height = bbox[3] - bbox[1]
    x = (width - text_width) // 2
    y = (200 - text_height) // 2
    draw.text((x, y), text, fill='white', font=font_large)

    # 플레이스홀더 메시지
    msg = "스크린샷 플레이스홀더"
    bbox_msg = draw.textbbox((0, 0), msg, font=font_small)
    msg_width = bbox_msg[2] - bbox_msg[0]
    x_msg = (width - msg_width) // 2
    draw.text((x_msg, height // 2), msg, fill='#9CA3AF', font=font_small)

    # 박스들 (콘텐츠 영역 시뮬레이션)
    margin = 100
    box_height = 400
    gap = 50

    for i in range(5):
        y_pos = 300 + (box_height + gap) * i
        draw.rectangle(
            [(margin, y_pos), (width - margin, y_pos + box_height)],
            fill='white',
            outline='#E5E7EB',
            width=2
        )

    return img

def main():
    """메인 실행 함수"""
    print("=" * 60)
    print("플레이스홀더 이미지 생성 시작")
    print("=" * 60)

    os.makedirs(SCREENSHOTS_DIR, exist_ok=True)

    for num, site_info in SITES.items():
        filename = os.path.join(SCREENSHOTS_DIR, f"{num}.png")
        print(f"생성 중: {num}. {site_info['name']} → {filename}")

        try:
            img = create_placeholder(num, site_info)
            img.save(filename, 'PNG')
            print(f"✓ 완료")
        except Exception as e:
            print(f"✗ 오류: {str(e)}")

    print("\n" + "=" * 60)
    print(f"완료: {len(SITES)}개 플레이스홀더 이미지 생성됨")
    print("=" * 60)
    print("\n참고: 실제 웹사이트 스크린샷으로 교체하려면")
    print("Playwright를 사용하여 수동으로 캡처하거나")
    print("온라인 스크린샷 서비스를 이용하세요.")

if __name__ == "__main__":
    main()
