from PIL import Image, ImageDraw, ImageFont
import os

width, height = 1080, 1350
img = Image.new('RGB', (width, height), '#FFFFFF')
draw = ImageDraw.Draw(img)

font_path = '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc'
font_title = ImageFont.truetype(font_path, 42)
font_subtitle = ImageFont.truetype(font_path, 24)
font_section = ImageFont.truetype(font_path, 28)
font_text = ImageFont.truetype(font_path, 24)
font_small = ImageFont.truetype(font_path, 20)
font_price = ImageFont.truetype(font_path, 48)

def draw_rounded_rect(draw, xy, fill, outline=None, width=1, radius=20):
    x1, y1, x2, y2 = xy
    draw.rounded_rectangle(xy, radius=radius, fill=fill, outline=outline, width=width)

blue = '#4a90e2'
red = '#e94b3c'
green = '#28a745'
yellow = '#ffc107'
gray = '#666666'
black = '#1a1a1a'
light_blue = '#e8f4fd'
light_yellow = '#fff3cd'
light_green = '#d4edda'
light_red = '#f8d7da'

y = 60
draw.text((width//2, y), '方案一：深圳 → 乳山（列车版本）', fill=black, font=font_title, anchor='mm')
y += 55
draw.text((width//2, y), '2026年8月出行 | 香港时间', fill=gray, font=font_subtitle, anchor='mm')

y = 180
draw_rounded_rect(draw, (60, y, 1020, y+80), fill='#f8f9fa', outline='#dee2e6', width=2)
points = [
    ('深圳 SZX', '06:15', '起飞'),
    ('济南 TNA', '08:00', '到达'),
    ('济南西站', '11:00+', '高铁出发'),
    ('乳山南站', '13:00+', '预计到达')
]
x_positions = [120, 400, 680, 960]
for i, ((loc, time, desc), x) in enumerate(zip(points, x_positions)):
    colors = [blue, red, green, green]
    color = colors[i]
    draw.ellipse([x-10, y+15, x+10, y+35], fill=color)
    draw.text((x, y+52), loc, fill=black, font=font_text, anchor='mm')
    draw.text((x, y+82), time, fill=color, font=font_section, anchor='mm')
    draw.text((x, y+112), desc, fill=gray, font=font_small, anchor='mm')
line_y = y + 25
draw.line([(x_positions[0], line_y), (x_positions[3], line_y)], fill=blue, width=6)
for i, x in enumerate(x_positions):
    color = [blue, red, green, green][i]
    draw.ellipse([x-10, line_y-10, x+10, line_y+10], fill=color)

y = 360
draw_rounded_rect(draw, (60, y, 1020, y+130), fill=light_blue, outline=blue, width=2)
draw.text((90, y+25), '✈️ 航班段', fill=black, font=font_section, anchor='lm')
draw.text((90, y+70), '深圳 06:15 → 济南 08:00', fill=black, font=font_text, anchor='lm')
draw.text((90, y+105), '飞行时间：约 1 小时 45 分', fill=gray, font=font_small, anchor='lm')

y = 520
draw_rounded_rect(draw, (60, y, 1020, y+130), fill=light_yellow, outline=yellow, width=2)
draw.text((90, y+25), '🚄 高铁段', fill=black, font=font_section, anchor='lm')
draw.text((90, y+70), '济南西站 → 乳山南站（约 11:00 出发）', fill=black, font=font_text, anchor='lm')
draw.text((90, y+105), '车程约 2 小时，票价约 219 元/人', fill=gray, font=font_small, anchor='lm')

y = 690
draw_rounded_rect(draw, (60, y, 1020, y+240), fill='#f8f9fa', outline='#dee2e6', width=1)
draw.text((90, y+30), '💰 价格明细', fill=black, font=font_section, anchor='lm')
items = [
    '机票：640 × 3 = 1,920 元',
    '机建/燃油：150 × 2 + 50 = 350 元',
    '济南西→乳山南高铁：219 × 3 = 657 元'
]
y_item = y + 80
for item in items:
    draw.text((90, y_item), item, fill=black, font=font_text, anchor='lm')
    y_item += 45
summary_x = 700
draw.text((summary_x, y+80), '方案一总价', fill=black, font=font_section, anchor='lm')
draw.text((summary_x, y+150), '2,927 元', fill=red, font=font_price, anchor='lm')

y = 970
h_box = 260
draw_rounded_rect(draw, (60, y, 490, y+h_box), fill=light_green, outline=green, width=2)
draw.text((90, y+30), '✅ 优点', fill='#155724', font=font_section, anchor='lm')
pros = [
    '• 总价最低，省 156 元',
    '• 高铁比高速出租车稳',
    '• 孩子可以在车上走动',
    '• 行李托运更便利'
]
y_p = y + 80
for p in pros:
    draw.text((90, y_p), p, fill='#155724', font=font_text, anchor='lm')
    y_p += 42

draw_rounded_rect(draw, (530, y, 1020, y+h_box), fill=light_red, outline=red, width=2)
draw.text((560, y+30), '⚠️ 注意', fill='#721c24', font=font_section, anchor='lm')
cons = [
    '• 06:15 起飞，需很早起床',
    '• 济南机场到西站需转场',
    '• 总换乘次数较多',
    '• 早班机容易疲劳'
]
y_c = y + 80
for c in cons:
    draw.text((560, y_c), c, fill='#721c24', font=font_text, anchor='lm')
    y_c += 42

y = 1270
draw_rounded_rect(draw, (80, y, 1000, y+60), fill='#fff9e6', outline=yellow, width=2)
draw.text((width//2, y+30), '适合：省钱、孩子能早起、愿意接受换乘的家庭 | 总花费：2,927 元', 
          fill=black, font=font_text, anchor='mm')

output_path = '/root/downloads/方案一_深圳飞济南高铁到乳山.png'
img.save(output_path, 'PNG')
print(f"已生成: {output_path}")
